Skip to content

Commit 216adbf

Browse files
authored
upgrade from JUnit 4 to JUnit 5 (#140)
1 parent 74f3ab3 commit 216adbf

File tree

10 files changed

+132
-113
lines changed

10 files changed

+132
-113
lines changed

imagetool/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
<artifactId>json</artifactId>
3636
</dependency>
3737
<dependency>
38-
<groupId>junit</groupId>
39-
<artifactId>junit</artifactId>
38+
<groupId>org.junit.jupiter</groupId>
39+
<artifactId>junit-jupiter-engine</artifactId>
4040
<scope>test</scope>
4141
</dependency>
4242
<dependency>

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/WLSCommandLine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static <C extends Callable<T>, T> T call(C callable, PrintStream out, Pri
3939
new CommandLine.DefaultExceptionHandler<List<Object>>().useErr(err).useAnsi(ansi), args);
4040
@SuppressWarnings("unchecked") T result = results == null || results.isEmpty() ? null : (T) results.get(0);
4141
if (result == null) {
42-
CommandLine.usage(callable, System.out);
42+
CommandLine.usage(callable, out);
4343
// System.exit(-1);
4444
}
4545
return result;

imagetool/src/test/java/com/oracle/weblogic/imagetool/cachestore/meta/FileCacheStoreTest.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,45 @@
55

66
import com.oracle.weblogic.imagetool.cachestore.CacheStore;
77
import com.oracle.weblogic.imagetool.cachestore.CacheStoreFactory;
8-
import org.junit.FixMethodOrder;
9-
import org.junit.Test;
10-
import org.junit.runners.MethodSorters;
8+
import org.junit.jupiter.api.MethodOrderer.Alphanumeric;
9+
import org.junit.jupiter.api.Tag;
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.TestMethodOrder;
1112

12-
import static org.junit.Assert.assertEquals;
13-
import static org.junit.Assert.assertNotNull;
14-
import static org.junit.Assert.assertNull;
15-
import static org.junit.Assert.assertTrue;
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
import static org.junit.jupiter.api.Assertions.assertNotNull;
15+
import static org.junit.jupiter.api.Assertions.assertNull;
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
1617

17-
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
18-
public class FileCacheStoreTest {
18+
@Tag("unit")
19+
@TestMethodOrder(Alphanumeric.class)
20+
class FileCacheStoreTest {
1921

2022
private CacheStore cacheStore = new CacheStoreFactory().get();
2123

2224
@Test
23-
public void a3addToCache() {
25+
void a3addToCache() {
2426
assertTrue(cacheStore.addToCache("abc_xyz_123", "this_is_a_test"));
2527
}
2628

2729
@Test
28-
public void a4getValueFromCache() {
30+
void a4getValueFromCache() {
2931
assertEquals("this_is_a_test", cacheStore.getValueFromCache("abc_xyz_123"));
3032
}
3133

3234
@Test
33-
public void a5hasMatchingKeyValue() {
35+
void a5hasMatchingKeyValue() {
3436
assertTrue(cacheStore.hasMatchingKeyValue("abc_xyz_123", "this_is_a_test"));
3537
}
3638

3739
@Test
38-
public void a6deleteFromCache() {
40+
void a6deleteFromCache() {
3941
assertNull(cacheStore.deleteFromCache("non_existent_key"));
4042
assertEquals("this_is_a_test", cacheStore.deleteFromCache("abc_xyz_123"));
4143
}
4244

4345
@Test
44-
public void a7getCacheItems() {
46+
void a7getCacheItems() {
4547
assertNotNull(cacheStore.getCacheItems());
4648
}
4749
}

imagetool/src/test/java/com/oracle/weblogic/imagetool/cli/cache/AddEntryTest.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,57 @@
88

99
import com.oracle.weblogic.imagetool.api.model.CommandResponse;
1010
import com.oracle.weblogic.imagetool.cli.WLSCommandLine;
11-
import org.junit.After;
12-
import org.junit.Before;
13-
import org.junit.Test;
11+
import org.junit.jupiter.api.AfterEach;
12+
import org.junit.jupiter.api.BeforeEach;
13+
import org.junit.jupiter.api.Tag;
14+
import org.junit.jupiter.api.Test;
1415
import picocli.CommandLine;
1516

16-
import static org.junit.Assert.assertEquals;
17-
import static org.junit.Assert.assertTrue;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertTrue;
1819

19-
public class AddEntryTest {
20+
@Tag("unit")
21+
class AddEntryTest {
2022

2123
private ByteArrayOutputStream byteArrayOutputStream = null;
2224
private PrintStream printStream = null;
2325

24-
@Before
25-
public void setup() {
26+
@BeforeEach
27+
void setup() {
2628
byteArrayOutputStream = new ByteArrayOutputStream();
2729
printStream = new PrintStream(byteArrayOutputStream);
2830
}
2931

30-
@After
31-
public void teardown() {
32+
@AfterEach
33+
void teardown() {
3234
if (printStream != null) {
3335
printStream.close();
3436
}
3537
}
3638

3739
@Test
38-
public void testMissingParameters() {
40+
void testMissingParameters() {
3941
WLSCommandLine.call(new AddEntry(), printStream, printStream, CommandLine.Help.Ansi.AUTO, true);
4042
assertTrue(new String(byteArrayOutputStream.toByteArray()).contains("Missing required options"));
4143
}
4244

4345
@Test
44-
public void testMissingKey() {
46+
void testMissingKey() {
4547
WLSCommandLine.call(new AddEntry(), printStream, printStream, CommandLine.Help.Ansi.AUTO, true,
4648
"--value", "some_value");
4749
assertTrue(new String(byteArrayOutputStream.toByteArray()).contains("Missing required option '--key=<key>'"));
4850
}
4951

5052
@Test
51-
public void testMissingValue() {
53+
void testMissingValue() {
5254
WLSCommandLine.call(new AddEntry(), printStream, printStream, CommandLine.Help.Ansi.AUTO, true,
5355
"--key", "some_key");
5456
assertTrue(new String(byteArrayOutputStream.toByteArray())
5557
.contains("Missing required option '--value=<location>'"));
5658
}
5759

5860
@Test
59-
public void testInvalidParameters() {
61+
void testInvalidParameters() {
6062
CommandResponse response = WLSCommandLine.call(new AddEntry(), "--key", "", "--value", "");
6163
assertEquals(-1, response.getStatus());
6264
}

imagetool/src/test/java/com/oracle/weblogic/imagetool/cli/cache/AddInstallerEntryTest.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,58 @@
99
import com.oracle.weblogic.imagetool.api.model.CommandResponse;
1010
import com.oracle.weblogic.imagetool.cli.WLSCommandLine;
1111
import com.oracle.weblogic.imagetool.installer.InstallerType;
12-
import org.junit.After;
13-
import org.junit.Before;
14-
import org.junit.Test;
12+
import org.junit.jupiter.api.AfterEach;
13+
import org.junit.jupiter.api.BeforeEach;
14+
import org.junit.jupiter.api.Tag;
15+
import org.junit.jupiter.api.Test;
1516
import picocli.CommandLine;
1617

17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.assertTrue;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
1920

20-
public class AddInstallerEntryTest {
21+
@Tag("unit")
22+
class AddInstallerEntryTest {
2123

2224
private ByteArrayOutputStream byteArrayOutputStream = null;
2325
private PrintStream printStream = null;
2426

25-
@Before
26-
public void setup() {
27+
@BeforeEach
28+
void setup() {
2729
byteArrayOutputStream = new ByteArrayOutputStream();
2830
printStream = new PrintStream(byteArrayOutputStream);
2931
}
3032

31-
@After
32-
public void teardown() {
33+
@AfterEach
34+
void teardown() {
3335
if (printStream != null) {
3436
printStream.close();
3537
}
3638
}
3739

3840
@Test
39-
public void testMissingParameters() {
41+
void testMissingParameters() {
4042
WLSCommandLine.call(new AddInstallerEntry(), printStream, printStream, CommandLine.Help.Ansi.AUTO, true);
4143
assertTrue(new String(byteArrayOutputStream.toByteArray()).contains("Missing required options"));
4244
}
4345

4446
@Test
45-
public void testWrongType() {
47+
void testWrongType() {
4648
WLSCommandLine.call(new AddInstallerEntry(), printStream, printStream, CommandLine.Help.Ansi.AUTO, true,
4749
"--type", "a2z", "--version", "some_value", "--path", "/path/to/a/file");
4850
assertTrue(new String(byteArrayOutputStream.toByteArray()).contains(
4951
"Invalid value for option '--type'"));
5052
}
5153

5254
@Test
53-
public void testMissingVersion() {
55+
void testMissingVersion() {
5456
WLSCommandLine.call(new AddInstallerEntry(), printStream, printStream, CommandLine.Help.Ansi.AUTO, true,
5557
"--type", InstallerType.WLS.toString(), "--path", "/path/to/a/file");
5658
assertTrue(new String(byteArrayOutputStream.toByteArray()).contains(
5759
"Missing required option '--version=<version>'"));
5860
}
5961

6062
@Test
61-
public void testInvalidParameters() {
63+
void testInvalidParameters() {
6264
CommandResponse response = WLSCommandLine.call(new AddInstallerEntry(), "--type",
6365
InstallerType.WLS.toString(), "--version", "", "--path", "/path/to/non/existent/file");
6466
assertEquals(-1, response.getStatus());

0 commit comments

Comments
 (0)