Skip to content

Commit d05db9b

Browse files
authored
#431: Added JavaDoc for test utils. (#456)
* #431: Added JavaDoc for test utils. * #431: Replaced deprecated MD link checker. Excluded `testutils` from coverage check.
1 parent 94b2c24 commit d05db9b

20 files changed

+401
-45
lines changed

.github/workflows/broken_links_checker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
run: |
1717
mkdir -p ./target
1818
echo '{ "aliveStatusCodes": [429, 200] }' > ./target/broken_links_checker.json
19-
- uses: gaurav-nelson/github-action-markdown-link-check@v1
19+
- uses: tcort/github-action-markdown-link-check@v1
2020
with:
2121
use-quiet-mode: "yes"
2222
use-verbose-mode: "yes"

doc/changes/changes_4.2.0.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Code name: Markdown code blocks
44

55
## Summary
66

7-
In this release we changed the behavior of the Markdown importer, so that if we are inside a code block, no OFT specification items are found. This is a corner case, but we think that this behavior is what users would expect (#480).
7+
In this release we changed the behavior of the Markdown importer so that if we are inside a code block, no OFT specification items are found. This is a corner case, but we think that this behavior is what users would expect (#480).
88

99
We also added a whole section about understanding and fixing broken links between specification items to the user guide.
1010

@@ -23,11 +23,11 @@ Finally, we updated test dependencies and Maven plugins.
2323

2424
* #427: Removed old `CHANGELOG.md` file and merged missing parts into release history.
2525
* #431: Documented "unwanted coverage" in user guide.
26-
* #449: Fix parsing past end of "needs" paragraph.
26+
* #449: Fix parsing past the end of a "needs" paragraph.
2727
* #440: Added Tag importer support for TOML files.
28-
* #442: Added support for javascript file extensions `.cjs`, `.mjs` and `.ejs`
28+
* #442: Added support for JavaScript file extensions `.cjs`, `.mjs` and `.ejs`
2929

3030
## Refactoring
3131

32-
* #452: Migrated Deployment to new Central Repository mechanism
32+
* #452: Migrated Deployment to the new "Central Repository" mechanism
3333
* #454: Fixed deployment to Maven Central

testutil/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
</parent>
1414
<properties>
1515
<project.build.outputTimestamp>${reproducible.build.timestamp}</project.build.outputTimestamp>
16+
<!-- This is a test module. We don't need code coverage here. -->
17+
<sonar.coverage.exclusions>**/*</sonar.coverage.exclusions>
1618
</properties>
1719
<dependencies>
1820
<dependency>

testutil/src/main/java/org/itsallcode/openfasttrace/testutil/CompareAssertions.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,49 @@ private CompareAssertions()
1717
// Not instantiable
1818
}
1919

20+
/**
21+
* Test that a comparator is consistent with equals and follows the {@link Comparator} contract.
22+
*
23+
* @param <T>
24+
* type of objects that may be compared by the comparator
25+
* @param comparator
26+
* comparator to test
27+
* @param o
28+
* reference object
29+
* @param smaller
30+
* an object that is smaller than the reference object
31+
* @param equal
32+
* an object that is equal to the reference object
33+
* @param greater
34+
* an object that is greater than the reference object
35+
* @param nullValueSupported
36+
* {@code true} if the comparator supports null values
37+
*/
2038
public static <T> void testComparatorConsistentWithEquals(Comparator<? super T> comparator, T o,
2139
T smaller, T equal, T greater, boolean nullValueSupported)
2240
{
2341
testComparator(comparator, o, smaller, equal, greater, nullValueSupported);
2442
testConsistencyWithEquals(comparator, o, smaller, equal, greater);
2543
}
2644

45+
/**
46+
* Test that a comparator follows the {@link Comparator} contract.
47+
*
48+
* @param <T>
49+
* type of objects that may be compared by the comparator
50+
* @param comparator
51+
* comparator to test
52+
* @param o
53+
* reference object
54+
* @param smaller
55+
* an object that is smaller than the reference object
56+
* @param equal
57+
* an object that is equal to the reference object
58+
* @param greater
59+
* an object that is greater than the reference object
60+
* @param nullValueSupported
61+
* {@code true} if the comparator supports null values
62+
*/
2763
public static <T> void testComparator(Comparator<? super T> comparator, T o, T smaller, T equal,
2864
T greater, boolean nullValueSupported)
2965
{
@@ -101,13 +137,41 @@ private static <T> void testConsistencyWithEquals(Comparator<? super T> comparat
101137
assertEquals(o.equals(greater), comparator.compare(o, greater) == 0);
102138
}
103139

140+
/**
141+
* Test that a comparable is consistent with equals and follows the {@link Comparable} contract.
142+
*
143+
* @param <T>
144+
* type of objects that may be compared
145+
* @param o
146+
* reference object
147+
* @param smaller
148+
* an object that is smaller than the reference object
149+
* @param equal
150+
* an object that is equal to the reference object
151+
* @param greater
152+
* an object that is greater than the reference object
153+
*/
104154
public static <T extends Comparable<? super T>> void testComparableConsistentWithEquals(T o,
105155
T smaller, T equal, T greater)
106156
{
107157
testComparatorConsistentWithEquals(Comparator.naturalOrder(), o, smaller, equal, greater,
108158
false);
109159
}
110160

161+
/**
162+
* Test that a comparable follows the {@link Comparable} contract.
163+
*
164+
* @param <T>
165+
* type of objects that may be compared
166+
* @param o
167+
* reference object
168+
* @param smaller
169+
* an object that is smaller than the reference object
170+
* @param equal
171+
* an object that is equal to the reference object
172+
* @param greater
173+
* an object that is greater than the reference object
174+
*/
111175
public static <T extends Comparable<? super T>> void testComparable(T o, T smaller, T equal,
112176
T greater)
113177
{

testutil/src/main/java/org/itsallcode/openfasttrace/testutil/OsCheck.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@
44

55
/**
66
* Helper class to check the operating system this Java VM runs in.
7-
*
7+
* <p>
88
* please keep the notes below as a pseudo-license:
9-
*
9+
* </p>
10+
* <p>
1011
* http://stackoverflow.com/questions/228477/how-do-i-programmatically-determine-operating-system-in-java
11-
* compare to
12-
* http://svn.terracotta.org/svn/tc/dso/tags/2.6.4/code/base/common/src/com/tc/util/runtime/Os.java
13-
* http://www.docjar.com/html/api/org/apache/commons/lang/SystemUtils.java.html
12+
* </p>
13+
* <p>
14+
* compare to:
15+
* </p>
16+
* <ul>
17+
* <li>http://svn.terracotta.org/svn/tc/dso/tags/2.6.4/code/base/common/src/com/tc/util/runtime/Os.java</li>
18+
* <li>http://www.docjar.com/html/api/org/apache/commons/lang/SystemUtils.java.html</li>
19+
* </ul>
1420
*/
1521
public class OsCheck
1622
{
23+
/**
24+
* Create a new instance of the operating system check.
25+
*/
1726
public OsCheck()
1827
{
1928
// Default constructor to fix compiler warning "missing-explicit-ctor"
@@ -41,15 +50,15 @@ public OSType getOperatingSystemType()
4150
private static OSType detectOperatingSystemType()
4251
{
4352
final String os = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
44-
if ((os.indexOf("mac") >= 0) || (os.indexOf("darwin") >= 0))
53+
if (os.contains("mac") || os.contains("darwin"))
4554
{
4655
return OSType.MACOS;
4756
}
48-
else if (os.indexOf("win") >= 0)
57+
else if (os.contains("win"))
4958
{
5059
return OSType.WINDOWS;
5160
}
52-
else if (os.indexOf("linux") >= 0)
61+
else if (os.contains("linux"))
5362
{
5463
return OSType.LINUX;
5564
}

testutil/src/main/java/org/itsallcode/openfasttrace/testutil/OsDetector.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
import org.itsallcode.openfasttrace.testutil.OsCheck.OSType;
77

8+
/**
9+
* Helper class to detect the operating system. Contains assumption methods for
10+
* JUnit.
11+
*/
812
public class OsDetector
913
{
1014
private static final OsCheck OS_CHECK = new OsCheck();
@@ -14,21 +18,41 @@ private OsDetector()
1418
// not instantiable
1519
}
1620

21+
/**
22+
* Assumes that the current operating system is Windows. If the application
23+
* is not running on Windows, the assumption will fail, and the test will be
24+
* aborted.
25+
*/
1726
public static void assumeRunningOnWindows()
1827
{
1928
assumeTrue(OsDetector::runningOnWindows, "not running on windows");
2029
}
2130

31+
/**
32+
* Assumes that the current operating system is Unix-like OS. If the
33+
* application is not running on a Unix-like OS, the assumption will fail,
34+
* and the test will be aborted.
35+
*/
2236
public static void assumeRunningOnUnix()
2337
{
2438
assumeFalse(OsDetector::runningOnWindows, "not running on unix");
2539
}
2640

41+
/**
42+
* Assumes that the current operating system is Linux. If the application
43+
* is not running on Linux, the assumption will fail, and the test will be
44+
* aborted.
45+
*/
2746
public static void assumeRunningOnLinux()
2847
{
2948
assumeTrue(OsDetector::runningOnLinux, "not running on linux");
3049
}
3150

51+
/**
52+
* Assumes that the current operating system is macOS. If the application
53+
* is not running on macOS, the assumption will fail, and the test will be
54+
* aborted.
55+
*/
3256
public static void assumeRunningOnMacOs()
3357
{
3458
assumeTrue(OsDetector::runningOnMac, "not running on macOS");

testutil/src/main/java/org/itsallcode/openfasttrace/testutil/TestAssumptions.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.opentest4j.TestAbortedException;
77

88
/**
9-
* Assumptions for unit and integration tests, see {@link TestAbortedException}.
9+
* Assumptions for unit and integration tests.
1010
*/
1111
public class TestAssumptions
1212
{
@@ -16,12 +16,11 @@ private TestAssumptions()
1616
}
1717

1818
/**
19-
* This ensures that the current JDK supports using the
20-
* {@link SecurityManager}. Starting with Java 19 the security manager is
21-
* not supported any more.
19+
* This ensures that the current JDK supports using Java's security manager.
20+
* Starting with Java 19, the security manager is not supported anymore.
2221
*
2322
* @throws TestAbortedException
24-
* if the JVM does not support {@link SecurityManager}.
23+
* if the JVM does not support Java's security manager.
2524
*/
2625
public static void assumeSecurityManagerSupported() throws TestAbortedException
2726
{

testutil/src/main/java/org/itsallcode/openfasttrace/testutil/cli/FakeDirectoryService.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,36 @@
22

33
import org.itsallcode.openfasttrace.api.cli.DirectoryService;
44

5+
/**
6+
* A fake implementation of {@link DirectoryService} that returns a predefined
7+
* directory path.
8+
* <p>
9+
* Normally, the directory service provides the current directory path. This
10+
* fake implementation can be used in tests to inject a predefined directory
11+
* path.
12+
* </p>
13+
*/
514
public class FakeDirectoryService implements DirectoryService
615
{
716
private final String fakeCurrentDir;
817

18+
/**
19+
* Create a new {@link FakeDirectoryService} that returns a predefined
20+
* directory path.
21+
*
22+
* @param fakeCurrentDir
23+
* the directory path to be returned by {@link #getCurrent()}
24+
*/
925
public FakeDirectoryService(final String fakeCurrentDir)
1026
{
1127
this.fakeCurrentDir = fakeCurrentDir;
1228
}
1329

30+
/**
31+
* Get the predefined current directory path.
32+
*
33+
* @return the predefined directory path
34+
*/
1435
@Override
1536
public String getCurrent()
1637
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
package org.itsallcode.openfasttrace.testutil.core;
22

3+
/**
4+
* Constants for sample artifact types used in tests.
5+
*/
36
public class SampleArtifactTypes
47
{
58
private SampleArtifactTypes()
69
{
710
// Not instantiable
811
}
912

13+
/** Architecture artifact type. */
1014
public static final String ARCH = "arch";
15+
/** Design artifact type. */
1116
public static final String DSN = "dsn";
17+
/** Implementation artifact type. */
1218
public static final String IMPL = "impl";
19+
/** Integration test artifact type. */
1320
public static final String ITEST = "itest";
21+
/** Operator manual artifact type. */
1422
public static final String OMAN = "oman";
23+
/** Requirement artifact type. */
1524
public static final String REQ = "req";
25+
/** Unit test artifact type. */
1626
public static final String UTEST = "utest";
27+
/** User manual artifact type. */
1728
public static final String UMAN = "uman";
1829
}

0 commit comments

Comments
 (0)