Skip to content

Commit 1ddfd9e

Browse files
author
crushingismybusiness
committed
Update to JUnit 5 and Hamcrest 3
1 parent f6b22e4 commit 1ddfd9e

File tree

13 files changed

+206
-196
lines changed

13 files changed

+206
-196
lines changed

build.gradle

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ test {
153153
dependsOn kb_sdk_plusScript // tests use script to compile sdk modules
154154
dependsOn pythonTest
155155

156+
useJUnitPlatform()
157+
156158
testLogging {
157159
exceptionFormat = 'full'
158160
showStandardStreams = true
@@ -302,8 +304,8 @@ configurations.all {
302304
dependencies {
303305

304306
// required for GraalVM native compilation
305-
annotationProcessor 'info.picocli:picocli-codegen:4.7.7'
306-
compileOnly 'javax.servlet:servlet-api:2.5'
307+
annotationProcessor('info.picocli:picocli-codegen:4.7.7')
308+
compileOnly('javax.servlet:servlet-api:2.5')
307309

308310
implementation('com.github.kbase:auth2_client_java:0.5.0') {
309311
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
@@ -312,79 +314,80 @@ dependencies {
312314
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
313315
exclude group: 'net.java.dev.jna' // don't include in runtime path
314316
}
315-
implementation 'com.github.kbase:java_kidl:0.2.0'
317+
implementation('com.github.kbase:java_kidl:0.2.0')
316318
// TODO DEPS see if this can be removed after switching to the python callback server
317319
// Provenance classes are used in various callback server related classes and tests
318320
implementation('com.github.kbase.workspace_deluxe:workspace-client:0.15.0') {
319321
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
320322
exclude group: 'net.java.dev.jna' // don't include in runtime path
321323
}
322-
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.2.3'
323-
implementation 'com.fasterxml.jackson.core:jackson-databind:2.2.3'
324-
implementation 'com.google.guava:guava:18.0'
325-
implementation 'com.googlecode.jsonschema2pojo:jsonschema2pojo-core:0.3.6'
324+
implementation('com.fasterxml.jackson.core:jackson-annotations:2.2.3')
325+
implementation('com.fasterxml.jackson.core:jackson-databind:2.2.3')
326+
implementation('com.google.guava:guava:18.0')
327+
implementation('com.googlecode.jsonschema2pojo:jsonschema2pojo-core:0.3.6')
326328
implementation('com.j2html:j2html:0.7') {
327329
exclude group: 'junit', module: 'junit' // bro
328330
}
329-
implementation 'commons-io:commons-io:2.4'
330-
implementation 'info.picocli:picocli:4.7.7'
331-
implementation 'org.apache.commons:commons-lang3:3.1'
332-
implementation 'org.apache.velocity:velocity:1.7'
333-
implementation 'org.ini4j:ini4j:0.5.2'
334-
implementation 'com.sun.codemodel:codemodel:2.4.1'
335-
implementation 'org.yaml:snakeyaml:1.11'
331+
implementation('commons-io:commons-io:2.4')
332+
implementation('info.picocli:picocli:4.7.7')
333+
implementation('org.apache.commons:commons-lang3:3.1')
334+
implementation('org.apache.velocity:velocity:1.7')
335+
implementation('org.ini4j:ini4j:0.5.2')
336+
implementation('com.sun.codemodel:codemodel:2.4.1')
337+
implementation('org.yaml:snakeyaml:1.11')
336338

337339
// TODO DEPS the deps below are required due to a) the callback server code, b)
338340
// tests that mock service wizard and the callback service and
339341
// c) java modules created by tests. See if they can be
340342
// moved to a test implementation if we swap the callback service for the
341343
// python docker image
342-
implementation 'ch.qos.logback:logback-classic:1.1.2'
343-
implementation 'org.slf4j:slf4j-api:1.7.7'
344+
implementation('ch.qos.logback:logback-classic:1.1.2')
345+
implementation('org.slf4j:slf4j-api:1.7.7')
344346
// TODO DEPS the annotation api is also needed for
345347
// a couple of SDK compiled classes in mobu/runner that should be factored out
346-
implementation 'javax.annotation:javax.annotation-api:1.3.2'
347-
implementation 'joda-time:joda-time:2.2'
348+
implementation('javax.annotation:javax.annotation-api:1.3.2')
349+
implementation('joda-time:joda-time:2.2')
348350
// this is OOOOOOLD. But that probably means updating java_common
349-
implementation 'org.eclipse.jetty.aggregate:jetty-all:7.0.0.v20091005'
351+
implementation('org.eclipse.jetty.aggregate:jetty-all:7.0.0.v20091005')
350352
// TODO DEPS Need to rework the java common logger to not use syslog4j at all since it's
351353
// abandonware and has a ton of CVEs, even in the newer versions.
352354
// Note that the java SDK modules use syslog4j, so we'll need to figure something out
353355
// there. I doubt any of the apps actually use the logging code that triggers it though
354-
implementation 'org.syslog4j:syslog4j:0.9.46'
356+
implementation('org.syslog4j:syslog4j:0.9.46')
355357

356358
// needed for syslog4j. Used in java test modules and JsonServerServlet subclasses in tests
357359
// but not in SDK code proper.
358-
testImplementation 'net.java.dev.jna:jna:3.4.0'
360+
testImplementation('net.java.dev.jna:jna:3.4.0')
359361

360362
testImplementation ('com.github.kbase:java_test_utilities:0.1.0') {
361363
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
364+
exclude group: 'junit', module: 'junit'
362365
}
363-
testImplementation 'junit:junit:4.12'
364-
testImplementation 'org.hamcrest:hamcrest-core:1.3'
366+
testImplementation('org.junit.jupiter:junit-jupiter:5.13.1')
367+
testImplementation('org.hamcrest:hamcrest:3.0')
365368

366369
// isolate the sdk generated code dependencies from the standard dependencies
367370

368-
generatedCodeClasspath 'ch.qos.logback:logback-classic:1.1.2'
369-
generatedCodeClasspath 'com.fasterxml.jackson.core:jackson-annotations:2.2.3'
370-
generatedCodeClasspath 'com.fasterxml.jackson.core:jackson-databind:2.2.3'
371+
generatedCodeClasspath('ch.qos.logback:logback-classic:1.1.2')
372+
generatedCodeClasspath('com.fasterxml.jackson.core:jackson-annotations:2.2.3')
373+
generatedCodeClasspath('com.fasterxml.jackson.core:jackson-databind:2.2.3')
371374
generatedCodeClasspath('com.github.kbase:auth2_client_java:0.5.0') {
372375
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
373376
}
374377
generatedCodeClasspath('com.github.kbase:java_common:0.3.1') {
375378
exclude group: 'com.fasterxml.jackson.core' // don't upgrade yet, breaks tests
376379
exclude group: 'net.java.dev.jna' // don't include in test path
377380
}
378-
generatedCodeClasspath 'javax.annotation:javax.annotation-api:1.3.2'
379-
generatedCodeClasspath 'javax.servlet:servlet-api:2.5'
380-
generatedCodeClasspath 'joda-time:joda-time:2.2'
381-
generatedCodeClasspath 'junit:junit:4.12'
382-
generatedCodeClasspath 'net.java.dev.jna:jna:3.4.0'
383-
generatedCodeClasspath 'org.eclipse.jetty.aggregate:jetty-all:7.0.0.v20091005'
384-
generatedCodeClasspath 'org.hamcrest:hamcrest-core:1.3'
385-
generatedCodeClasspath 'org.ini4j:ini4j:0.5.2'
386-
generatedCodeClasspath 'org.syslog4j:syslog4j:0.9.46'
387-
generatedCodeClasspath 'org.slf4j:slf4j-api:1.7.7'
381+
generatedCodeClasspath('javax.annotation:javax.annotation-api:1.3.2')
382+
generatedCodeClasspath('javax.servlet:servlet-api:2.5')
383+
generatedCodeClasspath('joda-time:joda-time:2.2')
384+
generatedCodeClasspath('junit:junit:4.12')
385+
generatedCodeClasspath('net.java.dev.jna:jna:3.4.0')
386+
generatedCodeClasspath('org.eclipse.jetty.aggregate:jetty-all:7.0.0.v20091005')
387+
generatedCodeClasspath('org.hamcrest:hamcrest-core:1.3')
388+
generatedCodeClasspath('org.ini4j:ini4j:0.5.2')
389+
generatedCodeClasspath('org.syslog4j:syslog4j:0.9.46')
390+
generatedCodeClasspath('org.slf4j:slf4j-api:1.7.7')
388391
}
389392

390393
task showTestClassPath {

src/test/java/us/kbase/test/sdk/compiler/CompileReporterTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package us.kbase.test.sdk.compiler;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
35
import java.io.StringReader;
46
import java.util.ArrayList;
57
import java.util.List;
68
import java.util.Map;
79

8-
import org.junit.Assert;
9-
10-
import org.junit.Test;
10+
import org.junit.jupiter.api.Test;
1111

1212
import us.kbase.kidl.KbModule;
1313
import us.kbase.kidl.KbService;
@@ -48,13 +48,13 @@ public void testLines() throws Exception {
4848
"#", server);
4949
//System.out.println(UObject.transformObjectToString(rpt));
5050
Map<String, FunctionPlace> pos = rpt.functionPlaces;
51-
Assert.assertEquals(1, pos.size());
52-
Assert.assertEquals(4, (int)pos.get(methodName).startLine);
53-
Assert.assertEquals(6, (int)pos.get(methodName).endLine);
51+
assertEquals(1, pos.size());
52+
assertEquals(4, (int)pos.get(methodName).startLine);
53+
assertEquals(6, (int)pos.get(methodName).endLine);
5454
Function f = rpt.functions.get(methodName);
55-
Assert.assertEquals("Super func!", f.comment);
56-
Assert.assertEquals(4, f.input.size());
57-
Assert.assertEquals(2, f.output.size());
58-
Assert.assertEquals("Test that!", f.output.get(1).comment);
55+
assertEquals("Super func!", f.comment);
56+
assertEquals(4, f.input.size());
57+
assertEquals(2, f.output.size());
58+
assertEquals("Test that!", f.output.get(1).comment);
5959
}
6060
}

src/test/java/us/kbase/test/sdk/compiler/html/HTMLGenTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package us.kbase.test.sdk.compiler.html;
22

3-
import static org.hamcrest.CoreMatchers.is;
4-
import static org.junit.Assert.assertThat;
5-
import static org.junit.Assert.fail;
3+
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.Matchers.is;
5+
import static org.junit.jupiter.api.Assertions.fail;
66

77
import java.io.File;
88
import java.io.IOException;
@@ -25,14 +25,13 @@
2525
import java.util.stream.Collectors;
2626
import java.util.stream.Stream;
2727

28+
import org.apache.commons.io.IOUtils;
29+
import org.junit.jupiter.api.BeforeAll;
30+
import org.junit.jupiter.api.Test;
31+
2832
import name.fraser.neil.plaintext.diff_match_patch;
2933
import name.fraser.neil.plaintext.diff_match_patch.Diff;
3034
import name.fraser.neil.plaintext.diff_match_patch.Operation;
31-
32-
import org.apache.commons.io.IOUtils;
33-
import org.junit.BeforeClass;
34-
import org.junit.Test;
35-
3635
import us.kbase.jkidl.IncludeProvider;
3736
import us.kbase.jkidl.ParseException;
3837
import us.kbase.jkidl.SpecParser;
@@ -48,7 +47,7 @@ public class HTMLGenTest {
4847
private static String CSS = "KIDLspec.css";
4948
private static String CSS_FILE;
5049

51-
@BeforeClass
50+
@BeforeAll
5251
public static void beforeClass() throws Exception {
5352
CSS_FILE = getFile(CSS);
5453
HTML_FILES = listFiles();

src/test/java/us/kbase/test/sdk/initializer/AsyncDockerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import org.eclipse.jetty.server.Server;
66
import org.eclipse.jetty.servlet.ServletContextHandler;
77
import org.eclipse.jetty.servlet.ServletHolder;
8-
import org.junit.AfterClass;
9-
import org.junit.BeforeClass;
10-
import org.junit.Test;
8+
import org.junit.jupiter.api.AfterAll;
9+
import org.junit.jupiter.api.BeforeAll;
10+
import org.junit.jupiter.api.Test;
1111

1212
import us.kbase.test.sdk.scripts.TestConfigHelper;
1313
import us.kbase.test.sdk.scripts.TypeGeneratorTest;
@@ -20,7 +20,7 @@ public class AsyncDockerTest extends DockerClientServerTester {
2020
private static Server execEngineJettyServer;
2121
private static CallbackServerMock cbsMock;
2222

23-
@BeforeClass
23+
@BeforeAll
2424
public static void beforeClass() throws Exception {
2525
execEnginePort = TypeGeneratorTest.findFreePort();
2626
execEngineJettyServer = new Server(execEnginePort);
@@ -32,7 +32,7 @@ public static void beforeClass() throws Exception {
3232
execEngineJettyServer.start();
3333
}
3434

35-
@AfterClass
35+
@AfterAll
3636
public static void tearDownModule() throws Exception {
3737
cbsMock.waitAndCleanAllJobs();
3838
if (execEngineJettyServer != null)

src/test/java/us/kbase/test/sdk/initializer/DockerClientServerTester.java

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package us.kbase.test.sdk.initializer;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertNotNull;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
37
import java.io.File;
48
import java.io.FileWriter;
59
import java.lang.reflect.InvocationTargetException;
@@ -15,10 +19,9 @@
1519
import java.util.Map;
1620

1721
import org.apache.commons.io.FileUtils;
18-
import org.junit.After;
19-
import org.junit.AfterClass;
20-
import org.junit.Assert;
21-
import org.junit.BeforeClass;
22+
import org.junit.jupiter.api.AfterAll;
23+
import org.junit.jupiter.api.AfterEach;
24+
import org.junit.jupiter.api.BeforeAll;
2225

2326
import us.kbase.auth.AuthToken;
2427
import us.kbase.common.service.ServerException;
@@ -41,15 +44,15 @@ public class DockerClientServerTester {
4144
protected static List<Path> CREATED_MODULES = new ArrayList<Path>();
4245
protected static AuthToken token;
4346

44-
@BeforeClass
47+
@BeforeAll
4548
public static void beforeTesterClass() throws Exception {
4649
token = TestConfigHelper.getToken();
4750
TypeGeneratorTest.suppressJettyLogging();
4851
}
4952

5053
// TODO TEST CODE pretty sure a lot of this stuff is duplicated in multiple places elsewhere
5154
// also needs to be updated to more modern code
52-
@AfterClass
55+
@AfterAll
5356
public static void afterTesterClass() throws Exception {
5457
if (cleanupAfterTests)
5558
for (final Path moduleName: CREATED_MODULES)
@@ -61,7 +64,7 @@ public static void afterTesterClass() throws Exception {
6164
}
6265
}
6366

64-
@After
67+
@AfterEach
6568
public void afterText() {
6669
System.out.println();
6770
}
@@ -275,9 +278,9 @@ else if (!data.contains(input)) {
275278
System.out.println("(" + time + " ms)");
276279
if (error != null)
277280
throw error;
278-
Assert.assertNotNull(obj);
279-
Assert.assertTrue(obj instanceof String);
280-
Assert.assertEquals(input, obj);
281+
assertNotNull(obj);
282+
assertTrue(obj instanceof String);
283+
assertEquals(input, obj);
281284
}
282285
// Common non-java preparation
283286
// Note 24/12/13: No longer common, just python
@@ -323,7 +326,7 @@ else if (!data.contains(input)) {
323326
if (!err.isEmpty())
324327
System.err.println("Python client errors:\n" + err);
325328
}
326-
Assert.assertEquals("Python client exit code should be 0", 0, exitCode);
329+
assertEquals(0, exitCode, "Python client exit code should be 0");
327330
}
328331
}
329332

@@ -422,7 +425,7 @@ protected static void testStatus(
422425
String err = ph.getSavedErrors();
423426
if (!err.isEmpty())
424427
System.err.println("Python client runner errors:\n" + err);
425-
Assert.assertEquals("Python client runner exit code should be 0", 0, exitCode);
428+
assertEquals(0, exitCode, "Python client runner exit code should be 0");
426429
} else {
427430
checkStatusResponse(outputFile, errorFile);
428431
}
@@ -439,20 +442,20 @@ private static void checkStatusResponse(File output, File error) throws Exceptio
439442
}
440443

441444
private static void checkStatusResponse(Object obj) throws Exception {
442-
Assert.assertNotNull(obj);
445+
assertNotNull(obj);
443446
String errMsg = "Unexpected response: " + UObject.transformObjectToString(obj);
444447
if (obj instanceof List) {
445448
@SuppressWarnings("rawtypes")
446449
List<?> list = (List)obj;
447-
Assert.assertEquals(errMsg, 1, list.size());
450+
assertEquals(1, list.size(), errMsg);
448451
obj = list.get(0);
449452
}
450-
Assert.assertTrue(obj instanceof Map);
453+
assertTrue(obj instanceof Map);
451454
@SuppressWarnings("unchecked")
452455
Map<String, String> map = (Map<String, String>)obj;
453-
Assert.assertEquals(errMsg, "OK", map.get("state"));
454-
Assert.assertTrue(errMsg, map.containsKey("version"));
455-
Assert.assertTrue(errMsg, map.containsKey("git_url"));
456-
Assert.assertTrue(errMsg, map.containsKey("git_commit_hash"));
456+
assertEquals("OK", map.get("state"), errMsg);
457+
assertTrue(map.containsKey("version"), errMsg);
458+
assertTrue(map.containsKey("git_url"), errMsg);
459+
assertTrue(map.containsKey("git_commit_hash"), errMsg);
457460
}
458461
}

src/test/java/us/kbase/test/sdk/initializer/DynamicServiceTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
import org.eclipse.jetty.server.Server;
1313
import org.eclipse.jetty.servlet.ServletContextHandler;
1414
import org.eclipse.jetty.servlet.ServletHolder;
15-
import org.junit.AfterClass;
16-
import org.junit.BeforeClass;
17-
import org.junit.Test;
15+
import org.junit.jupiter.api.AfterAll;
16+
import org.junit.jupiter.api.BeforeAll;
17+
import org.junit.jupiter.api.Test;
1818

1919
import us.kbase.common.service.JsonClientException;
2020
import us.kbase.common.service.JsonServerMethod;
@@ -33,7 +33,7 @@ public class DynamicServiceTest extends DockerClientServerTester {
3333
private static Server serviceWizardJettyServer;
3434
private static ServiceWizardMock serviceWizard;
3535

36-
@BeforeClass
36+
@BeforeAll
3737
public static void beforeClass() throws Exception {
3838
// TODO TEST CLEANUP delete this directory
3939
final Path workDir = Paths.get(
@@ -54,7 +54,7 @@ public static void beforeClass() throws Exception {
5454
serviceWizardJettyServer.start();
5555
}
5656

57-
@AfterClass
57+
@AfterAll
5858
public static void tearDownModule() throws Exception {
5959
if (serviceWizardJettyServer != null)
6060
serviceWizardJettyServer.stop();

0 commit comments

Comments
 (0)