Skip to content

Commit a6d01ef

Browse files
Move to JUnit 5
- first step simple tests
1 parent 88d5961 commit a6d01ef

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,16 @@
221221
<artifactId>junit</artifactId>
222222
<scope>test</scope>
223223
</dependency>
224+
<dependency>
225+
<groupId>org.junit.jupiter</groupId>
226+
<artifactId>junit-jupiter-api</artifactId>
227+
<scope>test</scope>
228+
</dependency>
229+
<dependency>
230+
<groupId>org.junit.vintage</groupId>
231+
<artifactId>junit-vintage-engine</artifactId>
232+
<scope>test</scope>
233+
</dependency>
224234
<dependency>
225235
<groupId>org.apache.maven.plugin-testing</groupId>
226236
<artifactId>maven-plugin-testing-harness</artifactId>

src/test/java/org/codehaus/mojo/exec/LineRedirectOutputStreamTest.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import java.nio.charset.StandardCharsets;
66
import java.util.function.Function;
77

8-
import org.junit.Assert;
9-
import org.junit.Assume;
10-
import org.junit.Test;
8+
import org.junit.jupiter.api.Test;
9+
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
import static org.junit.jupiter.api.Assertions.assertThrows;
12+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
1113

1214
public class LineRedirectOutputStreamTest {
1315

@@ -26,9 +28,9 @@ public void givenExtendedUnicodeCharacterOutput_whenRedirectingWithIso8859Charse
2628
@Test
2729
public void givenExtendedUnicodeCharacterOutput_whenRedirectingWithCp1252_thenShouldDecodeProperly()
2830
throws IOException {
29-
Assume.assumeTrue(
30-
"The JVM does not contain the cp-1252 charset",
31-
Charset.availableCharsets().containsKey("windows-1252"));
31+
assumeTrue(
32+
Charset.availableCharsets().containsKey("windows-1252"),
33+
"The JVM does not contain the cp-1252 charset");
3234
internalTestForCharset(Charset.forName("windows-1252"));
3335
}
3436

@@ -44,14 +46,14 @@ public void givenExtendedUnicodeCharacterOutput_whenRedirectingWithCharsetUnspec
4446
internalTestForCharset(sb -> new LineRedirectOutputStream(sb::append), Charset.defaultCharset());
4547
}
4648

47-
@Test(expected = NullPointerException.class)
49+
@Test
4850
public void givenNullCharset_whenInstantiating_thenShouldThrow() {
49-
new LineRedirectOutputStream(new StringBuilder()::append, null);
51+
assertThrows(NullPointerException.class, () -> new LineRedirectOutputStream(new StringBuilder()::append, null));
5052
}
5153

52-
@Test(expected = NullPointerException.class)
54+
@Test
5355
public void givenNullStringConsumer_whenInstantiating_thenShouldThrow() {
54-
new LineRedirectOutputStream(null, Charset.defaultCharset());
56+
assertThrows(NullPointerException.class, () -> new LineRedirectOutputStream(null, Charset.defaultCharset()));
5557
}
5658

5759
private void internalTestForCharset(Charset charset) throws IOException {
@@ -72,6 +74,6 @@ private void internalTestForCharset(
7274

7375
// The String to bytes to String is required here because StringCoding uses the Charset.defaultCharset()
7476
// internally so it would make the test fail when testing for different charsets.
75-
Assert.assertEquals(new String(expectedString.getBytes(charset), charset), sb.toString());
77+
assertEquals(new String(expectedString.getBytes(charset), charset), sb.toString());
7678
}
7779
}

src/test/java/org/codehaus/mojo/exec/URLClassLoaderBuilderTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
import java.nio.charset.StandardCharsets;
2626
import java.nio.file.Paths;
2727

28-
import org.junit.Test;
28+
import org.junit.jupiter.api.Test;
2929

3030
import static java.util.Arrays.asList;
31-
import static org.junit.Assert.assertEquals;
31+
import static org.junit.jupiter.api.Assertions.assertEquals;
3232

3333
/**
3434
* Basic tests about the custom classloader we set to execute the project.
@@ -47,7 +47,7 @@ public void childFirst() throws Exception {
4747
.build();
4848
PrintStream tmpStderr = new PrintStream(stderr)) {
4949
System.setErr(tmpStderr);
50-
assertEquals(tmpStderr, System.err);
50+
assertEquals(System.err, tmpStderr);
5151
thread.setContextClassLoader(loader);
5252
Class<?> lf = loader.loadClass("org.slf4j.LoggerFactory");
5353
Object logger = lf.getMethod("getLogger", Class.class).invoke(null, String.class);

0 commit comments

Comments
 (0)