diff --git a/build.gradle b/build.gradle index a05f6eb..45ade2e 100644 --- a/build.gradle +++ b/build.gradle @@ -4,16 +4,16 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent plugins { id 'java-library' - id "io.github.themrmilchmann.ecj" version "0.2.0" // Eclipse compiler as it's much faster than javac - id "org.sonarqube" version "3.0" + id "io.github.themrmilchmann.ecj" version "$ecj_plugin_version" // Eclipse compiler as it's much faster than javac + id "org.sonarqube" version "$sonarqube_plugin_version" id "jacoco" - id 'org.barfuin.gradle.jacocolog' version '3.1.0' + id 'org.barfuin.gradle.jacocolog' version "$jacocolog_plugin_version" id 'maven-publish' } allprojects { group = "de.se_rwth.commons" - buildDir = file("$projectDir/target") + layout.buildDirectory = file("$projectDir/target") repositories { if(("true").equals(getProperty('useLocalRepo'))){ @@ -33,10 +33,10 @@ subprojects { apply plugin : 'io.github.themrmilchmann.ecj' tasks.withType(Test).configureEach { - useJUnit() + useJUnitPlatform() testLogging { // controls whether test output is shown - showStandardStreams= ("false").equals(getProperty('showTestOutput'))? false : true + showStandardStreams= !("false").equals(getProperty('showTestOutput')) showExceptions true showCauses true showStackTraces true diff --git a/gradle.properties b/gradle.properties index fb18e63..82bc236 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,14 +6,23 @@ useLocalRepo=false showTestOutput=false version=7.9.0-SNAPSHOT -guava_version = 33.4.8-jre -javax_inject_version = 1 -slf4j_version = 1.7.10 -hamcrest_version = 1.3 -junit_version = 4.13.1 +guava_version = 33.5.0-jre +jakarta_inject_version = 2.0.1 +slf4j_version = 2.0.17 +hamcrest_version = 3.0 +junit_version = 5.14.1 +junit_platform_version = 1.14.1 groovy_version = 4.0.2 -logback_version = 1.5.18 -jline_version = 2.12 -commons_io_version = 2.19.0 -commons_cli_version = 1.9.0 -spotbugs_annotation_version = 4.7.3 \ No newline at end of file +logback_version = 1.5.22 +jline_version = 3.30.6 +gson_version = 2.13.2 +commons_io_version = 2.21.0 +commons_cli_version = 1.11.0 +commons_lang3_version = 3.20.0 +spotbugs_annotation_version = 4.9.8 +sonarqube_plugin_version = 3.0 +ecj_plugin_version = 0.2.0 +jacocolog_plugin_version = 3.1.0 + +# newer versions require JDK 17+ +spotless_plugin_version = 7.2.1 \ No newline at end of file diff --git a/se-commons-codestyle/build.gradle b/se-commons-codestyle/build.gradle index 44dff7c..c918a8b 100644 --- a/se-commons-codestyle/build.gradle +++ b/se-commons-codestyle/build.gradle @@ -9,7 +9,7 @@ description = 'se-commons: codestyle' dependencies { implementation gradleApi() - implementation "com.diffplug.spotless:spotless-plugin-gradle:6.25.0" + implementation "com.diffplug.spotless:spotless-plugin-gradle:$spotless_plugin_version" } repositories { diff --git a/se-commons-gradle/build.gradle b/se-commons-gradle/build.gradle index 542bf72..97f81d1 100644 --- a/se-commons-gradle/build.gradle +++ b/se-commons-gradle/build.gradle @@ -10,10 +10,11 @@ dependencies { implementation gradleApi() implementation project(":se-commons-utilities") implementation project(":se-commons-logging") - implementation 'com.google.code.gson:gson:2.13.2' + implementation "com.google.code.gson:gson:$gson_version" - implementation "org.apache.commons:commons-lang3:3.8.1" - implementation "com.google.guava:guava:33.1.0-jre" + implementation "org.apache.commons:commons-lang3:$commons_lang3_version" + implementation "com.google.guava:guava:$guava_version" + implementation "com.github.spotbugs:spotbugs-annotations:$spotbugs_annotation_version" } @@ -32,9 +33,10 @@ configurations { dependencies { testPluginImplementation gradleApi() testImplementation gradleTestKit() - testImplementation("org.junit.jupiter:junit-jupiter:5.7.1") - testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.0") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") + testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_version" + testImplementation "org.junit.jupiter:junit-jupiter-params:$junit_version" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_version" + testRuntimeOnly "org.junit.platform:junit-platform-launcher:$junit_platform_version" } tasks.named('test', Test) { useJUnitPlatform() diff --git a/se-commons-gradle/src/main/java/de/monticore/gradle/queue/CachedQueueServicePlugin.java b/se-commons-gradle/src/main/java/de/monticore/gradle/queue/CachedQueueServicePlugin.java index 9196d94..19f5170 100644 --- a/se-commons-gradle/src/main/java/de/monticore/gradle/queue/CachedQueueServicePlugin.java +++ b/se-commons-gradle/src/main/java/de/monticore/gradle/queue/CachedQueueServicePlugin.java @@ -1,7 +1,7 @@ /* (c) https://github.com/MontiCore/monticore */ package de.monticore.gradle.queue; -import org.checkerframework.checker.nullness.qual.NonNull; +import edu.umd.cs.findbugs.annotations.NonNull; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.tasks.TaskProvider; diff --git a/se-commons-gradle/src/main/java/de/monticore/gradle/queue/InternalCachedQueueSetupSettingsPlugin.java b/se-commons-gradle/src/main/java/de/monticore/gradle/queue/InternalCachedQueueSetupSettingsPlugin.java index b62f02f..212ee9c 100644 --- a/se-commons-gradle/src/main/java/de/monticore/gradle/queue/InternalCachedQueueSetupSettingsPlugin.java +++ b/se-commons-gradle/src/main/java/de/monticore/gradle/queue/InternalCachedQueueSetupSettingsPlugin.java @@ -1,7 +1,7 @@ /* (c) https://github.com/MontiCore/monticore */ package de.monticore.gradle.queue; -import org.checkerframework.checker.nullness.qual.NonNull; +import edu.umd.cs.findbugs.annotations.NonNull; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.invocation.Gradle; diff --git a/se-commons-gradle/src/testPlugin/java/se/rwth/example/TestPlugin.java b/se-commons-gradle/src/testPlugin/java/se/rwth/example/TestPlugin.java index 25fdd09..889bcba 100644 --- a/se-commons-gradle/src/testPlugin/java/se/rwth/example/TestPlugin.java +++ b/se-commons-gradle/src/testPlugin/java/se/rwth/example/TestPlugin.java @@ -4,7 +4,7 @@ import de.monticore.gradle.internal.ProgressLoggerService; import de.monticore.gradle.queue.CachedQueueServicePlugin; -import org.checkerframework.checker.nullness.qual.NonNull; +import edu.umd.cs.findbugs.annotations.NonNull; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.provider.Provider; diff --git a/se-commons-groovy/build.gradle b/se-commons-groovy/build.gradle index 6e31e27..7066657 100644 --- a/se-commons-groovy/build.gradle +++ b/se-commons-groovy/build.gradle @@ -10,12 +10,14 @@ description = 'se-commons: groovy' dependencies { api project(":se-commons-utilities") api project(":se-commons-logging") - implementation "jline:jline:$jline_version" + implementation "org.jline:jline:$jline_version:jdk8" implementation "com.google.guava:guava:$guava_version" implementation "org.apache.groovy:groovy:$groovy_version" - testImplementation "org.hamcrest:hamcrest-core:$hamcrest_version" - testImplementation "org.hamcrest:hamcrest-library:$hamcrest_version" - testImplementation "junit:junit:$junit_version" + testImplementation "org.hamcrest:hamcrest:$hamcrest_version" + testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_version" + testImplementation "org.junit.jupiter:junit-jupiter-params:$junit_version" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_version" + testRuntimeOnly "org.junit.platform:junit-platform-launcher:$junit_platform_version" } gradlePlugin.plugins { diff --git a/se-commons-groovy/src/main/java/de/se_rwth/commons/groovy/InteractiveGroovyShell.java b/se-commons-groovy/src/main/java/de/se_rwth/commons/groovy/InteractiveGroovyShell.java index 057f889..8135d4a 100644 --- a/se-commons-groovy/src/main/java/de/se_rwth/commons/groovy/InteractiveGroovyShell.java +++ b/se-commons-groovy/src/main/java/de/se_rwth/commons/groovy/InteractiveGroovyShell.java @@ -1,8 +1,11 @@ /* (c) https://github.com/MontiCore/monticore */ package de.se_rwth.commons.groovy; -import jline.console.ConsoleReader; import org.codehaus.groovy.GroovyException; +import org.jline.reader.LineReader; +import org.jline.reader.LineReaderBuilder; +import org.jline.terminal.Terminal; +import org.jline.terminal.TerminalBuilder; import java.io.IOException; import java.io.PrintWriter; @@ -37,22 +40,21 @@ public static final InteractiveGroovyShell forInterpreter(GroovyInterpreter groo public void tryRun() throws IOException { - ConsoleReader reader = new ConsoleReader(); - PrintWriter writer = new PrintWriter(reader.getOutput()); - - reader.setPrompt(PROMPT); - - String line; - while ((line = reader.readLine()) != null) { - try { - groovy.tryEvaluate(line); - } - catch (GroovyException e) { - writer.append("[ERROR] Could not parse command."); - writer.flush(); + try (Terminal terminal = TerminalBuilder.builder().build()) { + LineReader reader = LineReaderBuilder.builder().terminal(terminal).build(); + PrintWriter writer = new PrintWriter(terminal.output()); + + String line; + while ((line = reader.readLine(PROMPT)) != null) { + try { + groovy.tryEvaluate(line); + } + catch (GroovyException e) { + writer.append("[ERROR] Could not parse command."); + writer.flush(); + } } } - } } diff --git a/se-commons-groovy/src/test/java/de/se_rwth/commons/groovy/GroovyInterpreterTest.java b/se-commons-groovy/src/test/java/de/se_rwth/commons/groovy/GroovyInterpreterTest.java index cb324f9..2bf1ea6 100644 --- a/se-commons-groovy/src/test/java/de/se_rwth/commons/groovy/GroovyInterpreterTest.java +++ b/se-commons-groovy/src/test/java/de/se_rwth/commons/groovy/GroovyInterpreterTest.java @@ -2,12 +2,13 @@ package de.se_rwth.commons.groovy; import org.codehaus.groovy.GroovyException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.atomic.AtomicInteger; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Test for {@link GroovyInterpreter}. @@ -54,35 +55,32 @@ public void test__multipleVariablesWithSameName() { } - @Test(expected = RuntimeException.class) + @Test public void test__evaluate_scriptWithSyntaxError() { GroovyInterpreter groovy = GroovyInterpreter.newInterpreter().build(); - groovy.evaluate("if(}{)"); - + assertThrows(RuntimeException.class, () -> groovy.evaluate("if(}{)")); } - @Test(expected = GroovyException.class) + @Test public void test__tryEvaluate_scriptWithSyntaxError() throws GroovyException { GroovyInterpreter groovy = GroovyInterpreter.newInterpreter().build(); - groovy.tryEvaluate("if(}{)"); - + assertThrows(GroovyException.class, () -> groovy.tryEvaluate("if(}{)")); } - @Test(expected = GroovyException.class) + @Test public void test__tryEvaluate_nonExistentVariable() throws GroovyException { GroovyInterpreter groovy = GroovyInterpreter.newInterpreter().build(); - groovy.tryEvaluate("o.toString()"); - + assertThrows(GroovyException.class, () -> groovy.tryEvaluate("o.toString()")); } - @Test(expected = GroovyException.class) + @Test public void test__tryEvaluate_nonExistentMethod() throws GroovyException { GroovyInterpreter groovy = GroovyInterpreter.newInterpreter().build(); - groovy.tryEvaluate("foo()"); + assertThrows(GroovyException.class, () -> groovy.tryEvaluate("foo()")); } diff --git a/se-commons-logging/build.gradle b/se-commons-logging/build.gradle index 60eb568..95d92b5 100644 --- a/se-commons-logging/build.gradle +++ b/se-commons-logging/build.gradle @@ -5,7 +5,10 @@ dependencies { api project(":se-commons-utilities") testImplementation "ch.qos.logback:logback-classic:$logback_version" testImplementation "ch.qos.logback:logback-core:$logback_version" - testImplementation "junit:junit:$junit_version" + testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_version" + testImplementation "org.junit.jupiter:junit-jupiter-params:$junit_version" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_version" + testRuntimeOnly "org.junit.platform:junit-platform-launcher:$junit_platform_version" } publishing { diff --git a/se-commons-logging/src/test/java/de/se_rwth/commons/logging/FindingTest.java b/se-commons-logging/src/test/java/de/se_rwth/commons/logging/FindingTest.java index 39e123b..7f2e6b4 100644 --- a/se-commons-logging/src/test/java/de/se_rwth/commons/logging/FindingTest.java +++ b/se-commons-logging/src/test/java/de/se_rwth/commons/logging/FindingTest.java @@ -3,8 +3,10 @@ import de.se_rwth.commons.SourcePosition; import de.se_rwth.commons.SourcePositionBuilder; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; @SuppressWarnings({"SimplifiableAssertion", "EqualsWithItself"}) public class FindingTest { @@ -19,7 +21,7 @@ public void testShouldEqualItself1() { Finding f = new Finding(Finding.Type.ERROR, "A"); // When && Then - Assert.assertTrue(f.equals(f)); + assertTrue(f.equals(f)); } @Test @@ -29,7 +31,7 @@ public void testShouldEqualItself2() { Finding f = new Finding(Finding.Type.ERROR, "E", sp); // When && Then - Assert.assertTrue(f.equals(f)); + assertTrue(f.equals(f)); } @Test @@ -39,7 +41,7 @@ public void testShouldEqualItself3() { Finding f = new Finding(Finding.Type.WARNING, "E", sp); // When && Then - Assert.assertTrue(f.equals(f)); + assertTrue(f.equals(f)); } @Test @@ -49,7 +51,7 @@ public void testShouldEqualItself4() { Finding f = new Finding(Finding.Type.USER_ERROR, "E", sp); // When && Then - Assert.assertTrue(f.equals(f)); + assertTrue(f.equals(f)); } @Test @@ -60,7 +62,7 @@ public void testShouldEqualItself5() { Finding f = new Finding(Finding.Type.ERROR, "E", sp, spe); // When && Then - Assert.assertTrue(f.equals(f)); + assertTrue(f.equals(f)); } @Test @@ -70,7 +72,7 @@ public void testShouldEqual1() { Finding f2 = new Finding(Finding.Type.ERROR, "A"); // When && Then - Assert.assertTrue(f1.equals(f2)); + assertTrue(f1.equals(f2)); } @Test @@ -80,7 +82,7 @@ public void testShouldEqual2() { Finding f2 = new Finding(Finding.Type.WARNING, "A"); // When && Then - Assert.assertTrue(f1.equals(f2)); + assertTrue(f1.equals(f2)); } @Test @@ -90,7 +92,7 @@ public void testShouldEqual3() { Finding f2 = new Finding(Finding.Type.USER_ERROR, "A"); // When && Then - Assert.assertTrue(f1.equals(f2)); + assertTrue(f1.equals(f2)); } @Test @@ -102,7 +104,7 @@ public void testShouldEqual4() { Finding f2 = new Finding(Finding.Type.ERROR, "E", sp2); // When && Then - Assert.assertTrue(f1.equals(f2)); + assertTrue(f1.equals(f2)); } @Test @@ -116,7 +118,7 @@ public void testShouldEqual5() { Finding f2 = new Finding(Finding.Type.ERROR, "E", sp2, spe2); // When && Then - Assert.assertTrue(f1.equals(f2)); + assertTrue(f1.equals(f2)); } @Test @@ -126,7 +128,7 @@ public void testShouldNotEqual1() { Finding f2 = new Finding(Finding.Type.ERROR, "B"); // When && Then - Assert.assertFalse(f1.equals(f2)); + assertFalse(f1.equals(f2)); } @Test @@ -136,7 +138,7 @@ public void testShouldNotEqual2() { Finding f2 = new Finding(Finding.Type.WARNING, "A"); // When && Then - Assert.assertFalse(f1.equals(f2)); + assertFalse(f1.equals(f2)); } @Test @@ -146,7 +148,7 @@ public void testShouldNotEqual3() { Finding f2 = new Finding(Finding.Type.WARNING, "B"); // When && Then - Assert.assertFalse(f1.equals(f2)); + assertFalse(f1.equals(f2)); } @Test @@ -158,7 +160,7 @@ public void testShouldNotEqual4() { Finding f2 = new Finding(Finding.Type.ERROR, "E", sp2); // When && Then - Assert.assertFalse(f1.equals(f2)); + assertFalse(f1.equals(f2)); } @Test @@ -170,7 +172,7 @@ public void testShouldNotEqual5() { Finding f2 = new Finding(Finding.Type.ERROR, "E", sp2); // When && Then - Assert.assertFalse(f1.equals(f2)); + assertFalse(f1.equals(f2)); } @Test @@ -182,7 +184,7 @@ public void testShouldNotEqual6() { Finding f2 = new Finding(Finding.Type.ERROR, "E", sp2); // When && Then - Assert.assertFalse(f1.equals(f2)); + assertFalse(f1.equals(f2)); } @Test @@ -196,7 +198,7 @@ public void testShouldEqual7() { Finding f2 = new Finding(Finding.Type.ERROR, "E", sp2, spe2); // When && Then - Assert.assertFalse(f1.equals(f2)); + assertFalse(f1.equals(f2)); } @Test @@ -210,6 +212,6 @@ public void testShouldEqual8() { Finding f2 = new Finding(Finding.Type.ERROR, "E", sp2, spe2); // When && Then - Assert.assertFalse(f1.equals(f2)); + assertFalse(f1.equals(f2)); } } diff --git a/se-commons-logging/src/test/java/de/se_rwth/commons/logging/InteractiveLogTest.java b/se-commons-logging/src/test/java/de/se_rwth/commons/logging/InteractiveLogTest.java index 0e51e12..1dfd2d6 100644 --- a/se-commons-logging/src/test/java/de/se_rwth/commons/logging/InteractiveLogTest.java +++ b/se-commons-logging/src/test/java/de/se_rwth/commons/logging/InteractiveLogTest.java @@ -1,9 +1,9 @@ /* (c) https://github.com/MontiCore/monticore */ package de.se_rwth.commons.logging; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * This is a test of interactive mode of the Logger. @@ -30,23 +30,23 @@ public void testInteractiveLogging() { Log.warn(f4); // check entries - assertEquals(Log.getFindings().size(),5); - assertEquals(Log.getErrorCount(),3); + assertEquals(5, Log.getFindings().size()); + assertEquals(3, Log.getErrorCount()); - assertEquals(Log.getFindings().get(0).getType() , Finding.Type.ERROR); - assertEquals(Log.getFindings().get(0).getMsg() , f0); + assertEquals(Finding.Type.ERROR, Log.getFindings().get(0).getType()); + assertEquals(f0, Log.getFindings().get(0).getMsg()); - assertEquals(Log.getFindings().get(1).getType(), Finding.Type.USER_ERROR); - assertEquals(Log.getFindings().get(1).getMsg() , f1); + assertEquals(Finding.Type.USER_ERROR, Log.getFindings().get(1).getType()); + assertEquals(f1, Log.getFindings().get(1).getMsg()); - assertEquals(Log.getFindings().get(2).getType(), Finding.Type.WARNING); - assertEquals(Log.getFindings().get(2).getMsg() , f2); + assertEquals(Finding.Type.WARNING, Log.getFindings().get(2).getType()); + assertEquals(f2, Log.getFindings().get(2).getMsg()); - assertEquals(Log.getFindings().get(3).getType(), Finding.Type.ERROR); - assertEquals(Log.getFindings().get(3).getMsg() , f3); + assertEquals(Finding.Type.ERROR, Log.getFindings().get(3).getType()); + assertEquals(f3, Log.getFindings().get(3).getMsg()); - assertEquals(Log.getFindings().get(4).getType(), Finding.Type.WARNING); - assertEquals(Log.getFindings().get(4).getMsg() , f4); + assertEquals(Finding.Type.WARNING, Log.getFindings().get(4).getType()); + assertEquals(f4, Log.getFindings().get(4).getMsg()); } @Test @@ -63,22 +63,22 @@ public void testInteractiveLoggingInBatchMode() { Log.warn(f4); // check entries - assertEquals(Log.getFindings().size(),5); - assertEquals(Log.getErrorCount(),3); + assertEquals(5, Log.getFindings().size()); + assertEquals(3, Log.getErrorCount()); - assertEquals(Log.getFindings().get(0).getType() , Finding.Type.ERROR); - assertEquals(Log.getFindings().get(0).getMsg() , f0); + assertEquals(Finding.Type.ERROR, Log.getFindings().get(0).getType()); + assertEquals(f0, Log.getFindings().get(0).getMsg()); - assertEquals(Log.getFindings().get(1).getType(), Finding.Type.ERROR); - assertEquals(Log.getFindings().get(1).getMsg() , f1); + assertEquals(Finding.Type.ERROR, Log.getFindings().get(1).getType()); + assertEquals(f1, Log.getFindings().get(1).getMsg()); - assertEquals(Log.getFindings().get(2).getType(), Finding.Type.WARNING); - assertEquals(Log.getFindings().get(2).getMsg() , f2); + assertEquals(Finding.Type.WARNING, Log.getFindings().get(2).getType()); + assertEquals(f2, Log.getFindings().get(2).getMsg()); - assertEquals(Log.getFindings().get(3).getType(), Finding.Type.ERROR); - assertEquals(Log.getFindings().get(3).getMsg() , f3); + assertEquals(Finding.Type.ERROR, Log.getFindings().get(3).getType()); + assertEquals(f3, Log.getFindings().get(3).getMsg()); - assertEquals(Log.getFindings().get(4).getType(), Finding.Type.WARNING); - assertEquals(Log.getFindings().get(4).getMsg() , f4); + assertEquals(Finding.Type.WARNING, Log.getFindings().get(4).getType()); + assertEquals(f4, Log.getFindings().get(4).getMsg()); } } diff --git a/se-commons-logging/src/test/java/de/se_rwth/commons/logging/LogTest.java b/se-commons-logging/src/test/java/de/se_rwth/commons/logging/LogTest.java index 8a4a950..a9e9b60 100755 --- a/se-commons-logging/src/test/java/de/se_rwth/commons/logging/LogTest.java +++ b/se-commons-logging/src/test/java/de/se_rwth/commons/logging/LogTest.java @@ -4,15 +4,13 @@ import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.joran.JoranConfigurator; import ch.qos.logback.core.joran.spi.JoranException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.LoggerFactory; import java.io.File; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * This is a very basic test of the new centralized logging mechanism. The main @@ -108,17 +106,17 @@ public void testAndDemonstrateLogStubForDeveloper() { Log.println("line 2"); Log.print("line 3\n"); List r1 = LogStub.getPrints(); - assertEquals(r1.size(),3); - assertEquals(r1.get(0),"line 1"); - assertEquals(r1.get(1),"line 2" + System.lineSeparator()); - assertEquals(r1.get(2),"line 3\n"); + assertEquals(3, r1.size()); + assertEquals("line 1", r1.get(0)); + assertEquals("line 2" + System.lineSeparator(), r1.get(1)); + assertEquals("line 3\n", r1.get(2)); LogStub.clearPrints(); Log.print("line 4"); Log.println("line 5"); List r2 = LogStub.getPrints(); - assertEquals(r2.size(),2); - assertEquals(r2.get(0),"line 4"); + assertEquals(2, r2.size()); + assertEquals("line 4", r2.get(0)); } @Test diff --git a/se-commons-utilities/build.gradle b/se-commons-utilities/build.gradle index 5fb504d..84609d3 100644 --- a/se-commons-utilities/build.gradle +++ b/se-commons-utilities/build.gradle @@ -3,15 +3,17 @@ description = 'se-commons: utilities' dependencies { api "commons-io:commons-io:$commons_io_version" - implementation "jline:jline:$jline_version" api "org.slf4j:slf4j-api:$slf4j_version" + implementation "org.jline:jline:$jline_version:jdk8" implementation "com.google.guava:guava:$guava_version" - implementation "javax.inject:javax.inject:$javax_inject_version" + implementation "jakarta.inject:jakarta.inject-api:$jakarta_inject_version" implementation "commons-cli:commons-cli:$commons_cli_version" implementation "com.github.spotbugs:spotbugs-annotations:$spotbugs_annotation_version" - testImplementation "org.hamcrest:hamcrest-core:$hamcrest_version" - testImplementation "org.hamcrest:hamcrest-library:$hamcrest_version" - testImplementation "junit:junit:$junit_version" + testImplementation "org.hamcrest:hamcrest:$hamcrest_version" + testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_version" + testImplementation "org.junit.jupiter:junit-jupiter-params:$junit_version" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_version" + testRuntimeOnly "org.junit.platform:junit-platform-launcher:$junit_platform_version" } publishing { diff --git a/se-commons-utilities/src/main/java/de/se_rwth/commons/cli/CLIArguments.java b/se-commons-utilities/src/main/java/de/se_rwth/commons/cli/CLIArguments.java index 5a15965..4c8410e 100644 --- a/se-commons-utilities/src/main/java/de/se_rwth/commons/cli/CLIArguments.java +++ b/se-commons-utilities/src/main/java/de/se_rwth/commons/cli/CLIArguments.java @@ -5,7 +5,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterators; -import javax.inject.Named; +import jakarta.inject.Named; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Iterator; diff --git a/se-commons-utilities/src/main/java/de/se_rwth/commons/configuration/Configuration.java b/se-commons-utilities/src/main/java/de/se_rwth/commons/configuration/Configuration.java index 34f8190..90c487f 100644 --- a/se-commons-utilities/src/main/java/de/se_rwth/commons/configuration/Configuration.java +++ b/se-commons-utilities/src/main/java/de/se_rwth/commons/configuration/Configuration.java @@ -3,9 +3,9 @@ import com.google.common.primitives.Doubles; import com.google.common.primitives.Ints; -import jline.internal.Log; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; +import org.jline.utils.Log; import java.util.ArrayList; import java.util.Arrays; diff --git a/se-commons-utilities/src/test/java/de/se_rwth/commons/DeltaFileSetTest.java b/se-commons-utilities/src/test/java/de/se_rwth/commons/DeltaFileSetTest.java index 5ac091a..a42863b 100644 --- a/se-commons-utilities/src/test/java/de/se_rwth/commons/DeltaFileSetTest.java +++ b/se-commons-utilities/src/test/java/de/se_rwth/commons/DeltaFileSetTest.java @@ -1,17 +1,19 @@ /* (c) https://github.com/MontiCore/monticore */ package de.se_rwth.commons; -import com.google.common.base.Charsets; -import com.google.common.io.Files; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import static com.google.common.io.Files.asCharSink; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * TODO: Write me! @@ -21,29 +23,28 @@ public class DeltaFileSetTest { @Test - public void test() throws IOException { - - TemporaryFolder modelFolder = new TemporaryFolder(); - modelFolder.create(); - File f1 = modelFolder.newFile("blubb"); - File f2 = modelFolder.newFile("blabb"); - Files.write("Blubb", f1, Charsets.ISO_8859_1); - Files.write("Blabb", f2, Charsets.ISO_8859_1); + public void test(@TempDir Path modelFolder) throws IOException { + File f1 = modelFolder.resolve("blubb").toFile(); + assertTrue(f1.createNewFile()); + File f2 = modelFolder.resolve("blabb").toFile(); + assertTrue(f2.createNewFile()); + asCharSink(f1, StandardCharsets.ISO_8859_1).write("Blubb"); + asCharSink(f2, StandardCharsets.ISO_8859_1).write("Blabb"); File traceLog = File.createTempFile(".delta", ""); DeltaFileSet deltaFileSet = DeltaFileSet.newDeltaFileSet(traceLog) - .fromFile(modelFolder.getRoot()) + .fromFile(modelFolder.toFile()) .build(); assertNotNull(deltaFileSet); assertNotNull(deltaFileSet.getFiles()); assertThat(deltaFileSet.getFiles(), hasSize(2)); - - Files.write("Blabb + Update!", f2, Charsets.ISO_8859_1); + + asCharSink(f2, StandardCharsets.ISO_8859_1).write("Blabb + Update!"); DeltaFileSet deltaFileSet2 = DeltaFileSet.newDeltaFileSet(traceLog) - .fromFile(modelFolder.getRoot()) + .fromFile(modelFolder.toFile()) .build(); assertNotNull(deltaFileSet2); @@ -51,29 +52,29 @@ public void test() throws IOException { assertThat(deltaFileSet2.getFiles(), hasSize(1)); DeltaFileSet deltaFileSet3 = DeltaFileSet.newDeltaFileSet(traceLog) - .fromFile(modelFolder.getRoot()) + .fromFile(modelFolder.toFile()) .build(); assertNotNull(deltaFileSet3); assertNotNull(deltaFileSet3.getFiles()); assertThat(deltaFileSet3.getFiles(), hasSize(0)); - - Files.write("Blabb + Update!", f1, Charsets.ISO_8859_1); - Files.write("Blabb + Update Again!", f2, Charsets.ISO_8859_1); + + asCharSink(f1, StandardCharsets.ISO_8859_1).write("Blabb + Update!"); + asCharSink(f2, StandardCharsets.ISO_8859_1).write("Blabb + Update Again!"); DeltaFileSet deltaFileSet4 = DeltaFileSet.newDeltaFileSet(traceLog) - .fromFile(modelFolder.getRoot()) + .fromFile(modelFolder.toFile()) .build(); assertNotNull(deltaFileSet4); assertNotNull(deltaFileSet4.getFiles()); assertThat(deltaFileSet4.getFiles(), hasSize(2)); - - Files.write("Blabb + Update!", f1, Charsets.ISO_8859_1); - Files.write("Blabb + Update Again!", f2, Charsets.ISO_8859_1); + + asCharSink(f1, StandardCharsets.ISO_8859_1).write("Blabb + Update!"); + asCharSink(f2, StandardCharsets.ISO_8859_1).write("Blabb + Update Again!"); DeltaFileSet deltaFileSet5 = DeltaFileSet.newDeltaFileSet(traceLog) - .fromFile(modelFolder.getRoot()) + .fromFile(modelFolder.toFile()) .build(); assertNotNull(deltaFileSet5); diff --git a/se-commons-utilities/src/test/java/de/se_rwth/commons/DirectoriesTest.java b/se-commons-utilities/src/test/java/de/se_rwth/commons/DirectoriesTest.java index d7ea05b..c35858f 100644 --- a/se-commons-utilities/src/test/java/de/se_rwth/commons/DirectoriesTest.java +++ b/se-commons-utilities/src/test/java/de/se_rwth/commons/DirectoriesTest.java @@ -1,17 +1,18 @@ /* (c) https://github.com/MontiCore/monticore */ package de.se_rwth.commons; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.File; import java.io.IOException; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Unit tests for {@link Directories} @@ -19,24 +20,17 @@ * */ public class DirectoriesTest { - - @Rule - public TemporaryFolder folder = new TemporaryFolder(); - /** * Tests a copy operation on two flat directories. */ @Test - public void testCopy__flatDirectoryToDirectory() throws IOException { - - this.folder.create(); - File sourceDirectory = this.folder.newFolder(); - File targetDirectory = this.folder.newFolder(); + public void testCopy__flatDirectoryToDirectory(@TempDir File sourceDirectory, @TempDir File targetDirectory) throws IOException { File someFile = new File(sourceDirectory, "foo"); - someFile.createNewFile(); + assertTrue(someFile.createNewFile()); Directories.copy(sourceDirectory, targetDirectory); + assertNotNull(targetDirectory.listFiles()); assertThat(targetDirectory.listFiles().length, is(1)); assertThat(targetDirectory.listFiles()[0].getName(), equalTo(someFile.getName())); @@ -46,19 +40,16 @@ public void testCopy__flatDirectoryToDirectory() throws IOException { * Tests a copy operation on two nested directories. */ @Test - public void testCopy__nestedDirectoryToDirectory() throws IOException { - - this.folder.create(); - File sourceDirectory = this.folder.newFolder(); - File targetDirectory = this.folder.newFolder(); + public void testCopy__nestedDirectoryToDirectory(@TempDir File sourceDirectory, @TempDir File targetDirectory) throws IOException { File sourceSubDirectory = new File(sourceDirectory, "a/b/c"); - sourceSubDirectory.mkdirs(); + assertTrue(sourceSubDirectory.mkdirs()); File someFile = new File(sourceSubDirectory, "foo"); - someFile.createNewFile(); + assertTrue(someFile.createNewFile()); Directories.copy(sourceDirectory, targetDirectory); File targetSubDirectory = new File(targetDirectory, "a/b/c"); + assertNotNull(targetSubDirectory.listFiles()); assertThat(targetDirectory.listFiles().length, is(1)); assertThat(targetSubDirectory.listFiles().length, is(1)); assertThat(targetSubDirectory.listFiles()[0].getName(), equalTo(someFile.getName())); diff --git a/se-commons-utilities/src/test/java/de/se_rwth/commons/FilesTest.java b/se-commons-utilities/src/test/java/de/se_rwth/commons/FilesTest.java index 33ea261..e7f6250 100644 --- a/se-commons-utilities/src/test/java/de/se_rwth/commons/FilesTest.java +++ b/se-commons-utilities/src/test/java/de/se_rwth/commons/FilesTest.java @@ -1,17 +1,14 @@ /* (c) https://github.com/MontiCore/monticore */ package de.se_rwth.commons; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - +import static org.junit.jupiter.api.Assertions.*; /** * Unit tests for {@link Files} @@ -23,7 +20,7 @@ public class FilesTest { @Test public void unzipAttack() throws URISyntaxException { URL zipFile = getClass().getResource("/directoryTraversal.zip"); - assertNotNull("Test file missing", zipFile); + assertNotNull(zipFile, "Test file missing"); File tmp = Files.createTempDir(); @@ -33,7 +30,7 @@ public void unzipAttack() throws URISyntaxException { fail(); } catch (IOException e) { - assertEquals(e.getMessage(), "Zip file entry contains ../ which leads to directory traversal"); + assertEquals("Zip file entry contains ../ which leads to directory traversal", e.getMessage()); } Files.deleteFiles(tmp); @@ -42,12 +39,12 @@ public void unzipAttack() throws URISyntaxException { @Test public void unzipFunctionality() throws URISyntaxException, IOException { URL zipFile = getClass().getResource("/test.zip"); - assertNotNull("Test file missing", zipFile); + assertNotNull(zipFile, "Test file missing"); File tmp = Files.createTempDir(); for (File entry : Files.unzip(new File(zipFile.toURI()), tmp)) { - assertEquals(entry.getName(), "test"); + assertEquals("test", entry.getName()); } Files.deleteFiles(tmp); diff --git a/se-commons-utilities/src/test/java/de/se_rwth/commons/NamesUnitTest.java b/se-commons-utilities/src/test/java/de/se_rwth/commons/NamesUnitTest.java index d394672..a9e42ce 100644 --- a/se-commons-utilities/src/test/java/de/se_rwth/commons/NamesUnitTest.java +++ b/se-commons-utilities/src/test/java/de/se_rwth/commons/NamesUnitTest.java @@ -2,12 +2,13 @@ package de.se_rwth.commons; import com.google.common.collect.ImmutableList; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Unit test for {@link Names}. @@ -100,12 +101,10 @@ public void test__getQualifiedName() { } - @Test(expected = IllegalArgumentException.class) + @Test public void test__getQualifiedName_invalidArguments() { - - Names.getQualifiedName("", ""); - Names.getQualifiedName("cc.blubb", ""); - + assertThrows(IllegalArgumentException.class, () -> Names.getQualifiedName("", "")); + assertThrows(IllegalArgumentException.class, () -> Names.getQualifiedName("cc.blubb", "")); } @Test diff --git a/se-commons-utilities/src/test/java/de/se_rwth/commons/ProtectedSpaceSplitterUnitTest.java b/se-commons-utilities/src/test/java/de/se_rwth/commons/ProtectedSpaceSplitterUnitTest.java index b54fdee..ef55886 100644 --- a/se-commons-utilities/src/test/java/de/se_rwth/commons/ProtectedSpaceSplitterUnitTest.java +++ b/se-commons-utilities/src/test/java/de/se_rwth/commons/ProtectedSpaceSplitterUnitTest.java @@ -2,10 +2,10 @@ package de.se_rwth.commons; import com.google.common.collect.Iterables; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; /** * Unit test for {@link ProtectedSpaceSplitter}. diff --git a/se-commons-utilities/src/test/java/de/se_rwth/commons/SourcePositionTest.java b/se-commons-utilities/src/test/java/de/se_rwth/commons/SourcePositionTest.java index 6b68850..0432ef7 100644 --- a/se-commons-utilities/src/test/java/de/se_rwth/commons/SourcePositionTest.java +++ b/se-commons-utilities/src/test/java/de/se_rwth/commons/SourcePositionTest.java @@ -1,12 +1,12 @@ package de.se_rwth.commons; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class SourcePositionTest { diff --git a/se-commons-utilities/src/test/java/de/se_rwth/commons/StringMatchersUnitTest.java b/se-commons-utilities/src/test/java/de/se_rwth/commons/StringMatchersUnitTest.java index 65ee948..0fde7b6 100644 --- a/se-commons-utilities/src/test/java/de/se_rwth/commons/StringMatchersUnitTest.java +++ b/se-commons-utilities/src/test/java/de/se_rwth/commons/StringMatchersUnitTest.java @@ -1,12 +1,13 @@ /* (c) https://github.com/MontiCore/monticore */ package de.se_rwth.commons; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Unit test for {@link StringMatchers} diff --git a/se-commons-utilities/src/test/java/de/se_rwth/commons/StringTransformationsUnitTest.java b/se-commons-utilities/src/test/java/de/se_rwth/commons/StringTransformationsUnitTest.java index 2d807a0..c7dc9df 100644 --- a/se-commons-utilities/src/test/java/de/se_rwth/commons/StringTransformationsUnitTest.java +++ b/se-commons-utilities/src/test/java/de/se_rwth/commons/StringTransformationsUnitTest.java @@ -1,10 +1,11 @@ /* (c) https://github.com/MontiCore/monticore */ package de.se_rwth.commons; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Unit test for {@link StringTransformations}. @@ -14,7 +15,7 @@ public class StringTransformationsUnitTest { /** - * Test for {@link StringMatchers.Transformations#CAPITALIZE} + * Test for {@link StringTransformations#CAPITALIZE} */ @Test public void test__Transformations_CAPITALIZE() { @@ -36,7 +37,7 @@ public void test__Transformations_CAPITALIZE() { } /** - * Test for {@link StringMatchers.Transformations#ESCAPE_JAVA} + * Test for {@link StringTransformations#ESCAPE_JAVA} */ @Test public void test__Transformations_ESCAPE_JAVA() { @@ -58,12 +59,12 @@ public void test__Transformations_ESCAPE_JAVA() { } /** - * Test for {@link StringMatchers.Transformations#CAPITALIZE} + * Test for {@link StringTransformations#CAPITALIZE} */ - @Test(expected = NullPointerException.class) + @Test public void test__Transformations_CAPITALIZE_null() { - StringTransformations.CAPITALIZE.apply(null); + assertThrows(NullPointerException.class, () -> StringTransformations.CAPITALIZE.apply(null)); } diff --git a/se-commons-utilities/src/test/java/de/se_rwth/commons/UtilTest.java b/se-commons-utilities/src/test/java/de/se_rwth/commons/UtilTest.java index 49fd845..57ae20f 100644 --- a/se-commons-utilities/src/test/java/de/se_rwth/commons/UtilTest.java +++ b/se-commons-utilities/src/test/java/de/se_rwth/commons/UtilTest.java @@ -2,14 +2,15 @@ package de.se_rwth.commons; -import org.junit.Before; -import org.junit.Test; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Collection; import java.util.stream.Collectors; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** */ @@ -50,7 +51,7 @@ private TestNode(String content) { * * with the alphabetic order corresponding to a preorder traversal. */ - @Before + @BeforeEach public void setupTree() { A = new TestNode("A"); B = new TestNode("B"); diff --git a/se-commons-utilities/src/test/java/de/se_rwth/commons/cli/CLIArgumentsTest.java b/se-commons-utilities/src/test/java/de/se_rwth/commons/cli/CLIArgumentsTest.java index c5907ae..7a05b7d 100644 --- a/se-commons-utilities/src/test/java/de/se_rwth/commons/cli/CLIArgumentsTest.java +++ b/se-commons-utilities/src/test/java/de/se_rwth/commons/cli/CLIArgumentsTest.java @@ -2,14 +2,11 @@ package de.se_rwth.commons.cli; import com.google.common.collect.Iterables; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Couple of basic unit tests for {@link CLIArguments}.