Skip to content

Commit 4d26d36

Browse files
committed
Convert tests to JUnit 5
1 parent 54d4972 commit 4d26d36

27 files changed

Lines changed: 1419 additions & 1621 deletions

pom.xml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,6 @@
6666
<mavenVersion>3.2.5</mavenVersion>
6767
</properties>
6868

69-
<dependencyManagement>
70-
<dependencies>
71-
<dependency>
72-
<groupId>org.hamcrest</groupId>
73-
<artifactId>hamcrest-core</artifactId>
74-
<version>3.0</version>
75-
</dependency>
76-
</dependencies>
77-
</dependencyManagement>
78-
7969
<dependencies>
8070
<dependency>
8171
<groupId>org.slf4j</groupId>
@@ -95,12 +85,6 @@
9585
<artifactId>commons-io</artifactId>
9686
<version>2.21.0</version>
9787
</dependency>
98-
<dependency>
99-
<groupId>org.hamcrest</groupId>
100-
<artifactId>hamcrest</artifactId>
101-
<version>3.0</version>
102-
<scope>test</scope>
103-
</dependency>
10488
<dependency>
10589
<groupId>org.junit.jupiter</groupId>
10690
<artifactId>junit-jupiter-api</artifactId>

src/main/java/org/apache/maven/shared/utils/cli/CommandLineUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,15 @@ public static String[] translateCommandline(String toProcess) throws CommandLine
386386
final int inDoubleQuote = 2;
387387
boolean inEscape = false;
388388
int state = normal;
389-
final StringTokenizer tok = new StringTokenizer(toProcess, "\"\' \\", true);
389+
final StringTokenizer tok = new StringTokenizer(toProcess, "\"' \\", true);
390390
List<String> tokens = new ArrayList<>();
391391
StringBuilder current = new StringBuilder();
392392

393393
while (tok.hasMoreTokens()) {
394394
String nextTok = tok.nextToken();
395395
switch (state) {
396396
case inQuote:
397-
if ("\'".equals(nextTok)) {
397+
if ("'".equals(nextTok)) {
398398
if (inEscape) {
399399
current.append(nextTok);
400400
inEscape = false;
@@ -420,7 +420,7 @@ public static String[] translateCommandline(String toProcess) throws CommandLine
420420
}
421421
break;
422422
default:
423-
if ("\'".equals(nextTok)) {
423+
if ("'".equals(nextTok)) {
424424
if (inEscape) {
425425
inEscape = false;
426426
current.append(nextTok);

src/main/java/org/apache/maven/shared/utils/io/FileUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ public static void fileWriteArray(@Nonnull File file, @Nullable String encoding,
443443
@Deprecated
444444
public static void fileDelete(@Nonnull String fileName) {
445445
File file = new File(fileName);
446-
//noinspection ResultOfMethodCallIgnored
447446
deleteLegacyStyle(file);
448447
}
449448

src/main/java/org/apache/maven/shared/utils/logging/MessageUtils.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,13 @@ public static String stripAnsiCodes(String msg) {
171171
public static void registerShutdownHook() {
172172
if (JANSI && shutdownHook == null) {
173173
// No shutdown hook registered yet.
174-
shutdownHook = new Thread() {
175-
@Override
176-
public void run() {
177-
synchronized (STARTUP_SHUTDOWN_MONITOR) {
178-
while (AnsiConsole.isInstalled()) {
179-
doSystemUninstall();
180-
}
174+
shutdownHook = new Thread(() -> {
175+
synchronized (STARTUP_SHUTDOWN_MONITOR) {
176+
while (AnsiConsole.isInstalled()) {
177+
doSystemUninstall();
181178
}
182179
}
183-
};
180+
});
184181
Runtime.getRuntime().addShutdownHook(shutdownHook);
185182
}
186183
}

src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ public void characters(char[] ch, int start, int length) throws SAXException {
219219
}
220220

221221
private void appendToTopValue(String toAppend) {
222-
// noinspection MismatchedQueryAndUpdateOfStringBuilder
223222
StringBuilder stringBuilder = values.get(values.size() - 1);
224223
stringBuilder.append(toAppend);
225224
}

src/site/site.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ under the License.
2828
<item name="Source Xref" href="xref/index.html"/>
2929
<!--item name="FAQ" href="faq.html"/-->
3030
<!-- According to https://issues.apache.org/jira/browse/MNGSITE-152 -->
31-
<item name="License" href="http://www.apache.org/licenses/"/>
31+
<item name="License" href="https://www.apache.org/licenses/"/>
3232
<item name="Download" href="download.html"/>
3333
</menu>
3434

src/test/java/org/apache/maven/shared/utils/CaseTest.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ public class CaseTest {
4040

4141
/** common ASCII 'i' */
4242
@SuppressWarnings("ConstantName")
43-
private static final char DOTTED_i = '\u0069';
43+
private static final char DOTTED_i = 'i';
4444

4545
/** common ASCII 'I' */
4646
@SuppressWarnings("ConstantName")
47-
private static final char DOTLESS_I = '\u0049';
47+
private static final char DOTLESS_I = 'I';
4848

4949
/** turkish dotless i = ı */
5050
@SuppressWarnings("ConstantName")
51-
private static final char DOTLESS_i = '\u0131';
51+
private static final char DOTLESS_i = 'ı';
5252

5353
/** turkish dotted I = İ */
54-
private static final char DOTTED_I = '\u0130';
54+
private static final char DOTTED_I = 'İ';
5555

5656
/** http://en.wikipedia.org/wiki/Dot_(diacritic) */
5757
private static final char COMBINING_DOT_ABOVE = '\u0307';
@@ -136,13 +136,9 @@ public void testAsciiAvailableLocales() {
136136
}
137137

138138
assertEquals(
139-
expectedToUpperCase,
140-
lower.toUpperCase(locale),
141-
"'" + lower + "'.toUpperCase('" + locale.toString() + "')");
139+
expectedToUpperCase, lower.toUpperCase(locale), "'" + lower + "'.toUpperCase('" + locale + "')");
142140
assertEquals(
143-
expectedToLowerCase,
144-
upper.toLowerCase(locale),
145-
"'" + upper + "'.toLowerCase('" + locale.toString() + "')");
141+
expectedToLowerCase, upper.toLowerCase(locale), "'" + upper + "'.toLowerCase('" + locale + "')");
146142

147143
// check that toLowerCase on lower and toUpperCase on upper don't cause harm
148144
assertEquals(lower, lower.toLowerCase(locale), "'" + lower + "'.toLowerCase('" + locale + "')");

src/test/java/org/apache/maven/shared/utils/OsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
*
3434
* @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
3535
*/
36+
@SuppressWarnings("deprecation")
3637
public class OsTest {
3738
private String origOsName;
3839
private String origOsArch;

src/test/java/org/apache/maven/shared/utils/PathToolTest.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,26 @@
1818
*/
1919
package org.apache.maven.shared.utils;
2020

21-
import java.io.File;
22-
2321
import org.junit.jupiter.api.Test;
24-
import org.junit.jupiter.api.io.TempDir;
22+
import org.junit.jupiter.api.condition.DisabledOnOs;
23+
import org.junit.jupiter.api.condition.EnabledOnOs;
24+
import org.junit.jupiter.api.condition.OS;
2525

2626
import static org.junit.jupiter.api.Assertions.assertEquals;
2727
import static org.junit.jupiter.api.Assertions.assertNull;
28-
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2928

3029
/**
3130
* Test the {@link PathTool} class.
3231
*
3332
* @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
3433
*/
34+
@SuppressWarnings("deprecation")
3535
public class PathToolTest {
3636

37-
@TempDir
38-
private File tempFolder;
39-
4037
@Test
4138
// Keep in sync with testGetRelativeFilePathWindows()
39+
@DisabledOnOs(OS.WINDOWS)
4240
public void testGetRelativeFilePathNonWindows() {
43-
assumeTrue(File.separatorChar == '/');
44-
4541
assertEquals("", PathTool.getRelativeFilePath(null, null));
4642

4743
assertEquals("", PathTool.getRelativeFilePath(null, "/usr/local/java/bin"));
@@ -65,9 +61,8 @@ public void testGetRelativeFilePathNonWindows() {
6561

6662
@Test
6763
// Keep in sync with testGetRelativeFilePathNonWindows()
64+
@EnabledOnOs(OS.WINDOWS)
6865
public void testGetRelativeFilePathWindows() {
69-
assumeTrue(File.separatorChar == '\\');
70-
7166
assertEquals("", PathTool.getRelativeFilePath(null, null));
7267

7368
assertEquals("", PathTool.getRelativeFilePath(null, "c:\\usr\\local\\java\\bin"));

src/test/java/org/apache/maven/shared/utils/PropertyUtilsTest.java

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.io.ByteArrayInputStream;
2222
import java.io.File;
23-
import java.io.FileOutputStream;
2423
import java.io.IOException;
2524
import java.io.InputStream;
2625
import java.io.OutputStream;
@@ -30,14 +29,15 @@
3029
import java.lang.annotation.RetentionPolicy;
3130
import java.lang.annotation.Target;
3231
import java.net.URL;
32+
import java.nio.file.Files;
3333
import java.util.Properties;
3434

3535
import org.junit.jupiter.api.Test;
3636
import org.junit.jupiter.api.io.TempDir;
3737

38-
import static org.hamcrest.CoreMatchers.is;
39-
import static org.hamcrest.CoreMatchers.nullValue;
40-
import static org.hamcrest.MatcherAssert.assertThat;
38+
import static java.nio.charset.StandardCharsets.ISO_8859_1;
39+
import static org.junit.jupiter.api.Assertions.assertEquals;
40+
import static org.junit.jupiter.api.Assertions.assertNull;
4141

4242
public class PropertyUtilsTest {
4343

@@ -51,72 +51,72 @@ public class PropertyUtilsTest {
5151
@Test
5252
@SuppressWarnings("deprecation")
5353
// @ReproducesPlexusBug( "Should return null on error like url and file do" )
54-
public void loadNullInputStream() throws Exception {
55-
assertThat(PropertyUtils.loadProperties((InputStream) null), is(new Properties()));
54+
public void loadNullInputStream() {
55+
assertEquals(new Properties(), PropertyUtils.loadProperties((InputStream) null));
5656
}
5757

5858
@Test
59-
public void loadOptionalNullInputStream() throws Exception {
60-
assertThat(PropertyUtils.loadOptionalProperties((InputStream) null), is(new Properties()));
59+
public void loadOptionalNullInputStream() {
60+
assertEquals(new Properties(), PropertyUtils.loadOptionalProperties((InputStream) null));
6161
}
6262

6363
@Test
6464
public void loadOptionalPropertiesIoException() throws Exception {
6565
URL url = new URL("https://nonesuch12344.foo.bar.com");
66-
assertThat(PropertyUtils.loadOptionalProperties(url), is(new Properties()));
66+
assertEquals(new Properties(), PropertyUtils.loadOptionalProperties(url));
6767
}
6868

6969
@Test
70-
@SuppressWarnings("deprecation")
71-
public void loadNullURL() throws Exception {
72-
assertThat(PropertyUtils.loadProperties((URL) null), nullValue(Properties.class));
70+
@SuppressWarnings({"deprecation", "DataFlowIssue"})
71+
public void loadNullURL() {
72+
assertNull(PropertyUtils.loadProperties((URL) null));
7373
}
7474

7575
@Test
76-
public void loadOptionalNullURL() throws Exception {
77-
assertThat(PropertyUtils.loadOptionalProperties((URL) null), is(new Properties()));
76+
public void loadOptionalNullURL() {
77+
assertEquals(new Properties(), PropertyUtils.loadOptionalProperties((URL) null));
7878
}
7979

8080
@Test
81-
@SuppressWarnings("deprecation")
82-
public void loadNullFile() throws Exception {
83-
assertThat(PropertyUtils.loadProperties((File) null), nullValue(Properties.class));
81+
@SuppressWarnings({"deprecation", "DataFlowIssue"})
82+
public void loadNullFile() {
83+
assertNull(PropertyUtils.loadProperties((File) null));
8484
}
8585

8686
@Test
87-
public void loadOptionalNullFile() throws Exception {
88-
assertThat(PropertyUtils.loadOptionalProperties((File) null), is(new Properties()));
87+
public void loadOptionalNullFile() {
88+
assertEquals(new Properties(), PropertyUtils.loadOptionalProperties((File) null));
8989
}
9090

9191
@Test
9292
@SuppressWarnings("deprecation")
93-
public void loadEmptyInputStream() throws Exception {
94-
assertThat(PropertyUtils.loadProperties(new ByteArrayInputStream(new byte[0])), is(new Properties()));
93+
public void loadEmptyInputStream() {
94+
assertEquals(new Properties(), PropertyUtils.loadProperties(new ByteArrayInputStream(new byte[0])));
9595

96-
assertThat(PropertyUtils.loadOptionalProperties(new ByteArrayInputStream(new byte[0])), is(new Properties()));
96+
assertEquals(new Properties(), PropertyUtils.loadOptionalProperties(new ByteArrayInputStream(new byte[0])));
9797
}
9898

9999
@Test
100100
@NeedsTemporaryFolder
101101
@SuppressWarnings("deprecation")
102102
public void loadEmptyFile() throws Exception {
103-
assertThat(PropertyUtils.loadProperties(newFile(tempFolder, "empty")), is(new Properties()));
104-
assertThat(PropertyUtils.loadOptionalProperties(newFile(tempFolder, "optional")), is(new Properties()));
103+
assertEquals(new Properties(), PropertyUtils.loadProperties(newFile(tempFolder, "empty")));
104+
assertEquals(new Properties(), PropertyUtils.loadOptionalProperties(newFile(tempFolder, "optional")));
105105
}
106106

107107
@Test
108108
@NeedsTemporaryFolder
109109
@SuppressWarnings("deprecation")
110110
public void loadEmptyURL() throws Exception {
111-
assertThat(
111+
assertEquals(
112+
new Properties(),
112113
PropertyUtils.loadProperties(
113-
newFile(tempFolder, "empty").toURI().toURL()),
114-
is(new Properties()));
114+
newFile(tempFolder, "empty").toURI().toURL()));
115115

116-
assertThat(
116+
assertEquals(
117+
new Properties(),
117118
PropertyUtils.loadOptionalProperties(
118-
newFile(tempFolder, "optional").toURI().toURL()),
119-
is(new Properties()));
119+
newFile(tempFolder, "optional").toURI().toURL()));
120120
}
121121

122122
@Test
@@ -125,11 +125,9 @@ public void loadValidInputStream() throws UnsupportedEncodingException {
125125
Properties value = new Properties();
126126
value.setProperty("a", "b");
127127

128-
assertThat(PropertyUtils.loadProperties(new ByteArrayInputStream("a=b".getBytes("ISO-8859-1"))), is(value));
128+
assertEquals(value, PropertyUtils.loadProperties(new ByteArrayInputStream("a=b".getBytes(ISO_8859_1))));
129129

130-
assertThat(
131-
PropertyUtils.loadOptionalProperties(new ByteArrayInputStream("a=b".getBytes("ISO-8859-1"))),
132-
is(value));
130+
assertEquals(value, PropertyUtils.loadOptionalProperties(new ByteArrayInputStream("a=b".getBytes(ISO_8859_1))));
133131
}
134132

135133
@Test
@@ -139,10 +137,10 @@ public void loadValidFile() throws IOException {
139137
File valid = newFile(tempFolder, "valid");
140138
Properties value = new Properties();
141139
value.setProperty("a", "b");
142-
try (OutputStream out = new FileOutputStream(valid)) {
140+
try (OutputStream out = Files.newOutputStream(valid.toPath())) {
143141
value.store(out, "a test");
144-
assertThat(PropertyUtils.loadProperties(valid), is(value));
145-
assertThat(PropertyUtils.loadOptionalProperties(valid), is(value));
142+
assertEquals(value, PropertyUtils.loadProperties(valid));
143+
assertEquals(value, PropertyUtils.loadOptionalProperties(valid));
146144
}
147145
}
148146

@@ -153,10 +151,11 @@ public void loadValidURL() throws IOException {
153151
File valid = newFile(tempFolder, "valid");
154152
Properties value = new Properties();
155153
value.setProperty("a", "b");
156-
try (OutputStream out = new FileOutputStream(valid)) {
154+
try (OutputStream out = Files.newOutputStream(valid.toPath())) {
157155
value.store(out, "a test");
158-
assertThat(PropertyUtils.loadProperties(valid.toURI().toURL()), is(value));
159-
assertThat(PropertyUtils.loadOptionalProperties(valid.toURI().toURL()), is(value));
156+
assertEquals(value, PropertyUtils.loadProperties(valid.toURI().toURL()));
157+
assertEquals(
158+
value, PropertyUtils.loadOptionalProperties(valid.toURI().toURL()));
160159
}
161160
}
162161

0 commit comments

Comments
 (0)