From dac29e856229b4d6fe54a02253934f2813b46cc0 Mon Sep 17 00:00:00 2001 From: Tom Martin Date: Fri, 5 Jul 2024 18:39:22 +0100 Subject: [PATCH] Update to Java 17 (Java 21 and JUnit 5 for tests), except for lib and launcher which stay at Java 8 * Update to JUnit5 * Target java17 in release and java21 in tests * Update Jacoco to support java21, always run it with tests. * Pin lib and launcher to java 8 and jfx8. --- build.gradle | 46 +++++++++++----- chunky/build.gradle | 8 ++- .../llbit/chunky/block/SkullTextureTest.java | 9 ++-- .../llbit/chunky/chunk/BlockPaletteTest.java | 12 +++-- .../llbit/chunky/entity/MarshallingTest.java | 4 +- .../llbit/chunky/main/OptionHandlerTest.java | 25 +++++---- .../se/llbit/chunky/main/PluginApiTest.java | 15 +++--- .../src/test/se/llbit/chunky/nbt/NBTTest.java | 7 +-- .../chunky/renderer/BlankRenderTest.java | 14 ++--- .../renderer/renderdump/RenderDumpTest.java | 12 ++--- .../renderer/scene/SceneManagerTest.java | 4 +- .../chunky/renderer/scene/SceneTest.java | 2 +- .../chunky/resources/AnimatedTextureTest.java | 4 +- .../fxutil/GroupedChangeListenerTest.java | 9 ++-- chunky/src/test/se/llbit/log/LogTest.java | 52 +++++++++++-------- .../test/se/llbit/math/MutableAABBTest.java | 7 +-- .../src/test/se/llbit/math/QuickMathTest.java | 33 ++++++------ .../test/se/llbit/util/RingBufferTest.java | 7 +-- .../test/se/llbit/util/WeakInternerTest.java | 14 ++--- launcher/build.gradle | 7 +++ lib/build.gradle | 7 +++ settings.gradle | 4 ++ 22 files changed, 181 insertions(+), 121 deletions(-) diff --git a/build.gradle b/build.gradle index 788560edac..950a0d99b5 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,6 @@ buildscript { subprojects { apply plugin: 'java' apply plugin: 'jacoco' - apply plugin: 'org.openjfx.javafxplugin' apply plugin: 'idea' apply plugin: 'com.github.ben-manes.versions' @@ -31,19 +30,35 @@ subprojects { group = 'se.llbit' version = rootProject.version - sourceCompatibility = '1.8' - targetCompatibility = '1.8' - - compileJava { - options.encoding = 'UTF-8' - options.debug = true - options.deprecation = true + java { + toolchain { + // default java version for the project, some subprojects are pinned to java 8 for backwards compatibility (see their configs). + languageVersion = JavaLanguageVersion.of(17) + } } + compileTestJava { + // compile tests using more recent features + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(21) + } + } + test { + // run tests using more recent features + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(21) + } + useJUnitPlatform() - javafx { - version = '11.0.2' - configuration = 'implementation' - modules = ['javafx.base', 'javafx.controls', 'javafx.fxml'] + // Always run tests, even when nothing changed. + dependsOn 'cleanTest' + + finalizedBy jacocoTestReport // report is always generated after tests run (it's very cheap) + } + jacoco { + toolVersion = "0.8.11" + } + jacocoTestReport { + dependsOn test // tests are required to run before generating the report } javadoc { @@ -63,6 +78,12 @@ subprojects { nbtlib 'se.llbit:jo-nbt:1.3.0' cplib 'se.llbit:luxcp:1.0.1' toolpanelib 'se.llbit:toolpane:0.1' + + testImplementation("org.assertj:assertj-core:3.25.1") + + testImplementation(platform('org.junit:junit-bom:5.10.2')) + testImplementation('org.junit.jupiter:junit-jupiter') + testRuntimeOnly('org.junit.platform:junit-platform-launcher') } idea { @@ -236,6 +257,7 @@ task docs(type: Javadoc) { } task clean { + group = "Build" doLast { delete "./build" } diff --git a/chunky/build.gradle b/chunky/build.gradle index fcdd8db20d..f7fa7824d6 100644 --- a/chunky/build.gradle +++ b/chunky/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'application' apply plugin: 'maven-publish' +apply plugin: 'org.openjfx.javafxplugin' mainClassName = 'se.llbit.chunky.main.Chunky' archivesBaseName = 'chunky-core' @@ -17,9 +18,12 @@ dependencies { implementation 'com.google.code.gson:gson:2.9.0' implementation 'org.lz4:lz4-java:1.8.0' implementation project(':lib') +} - testImplementation 'com.google.truth:truth:1.1.3' - testImplementation 'junit:junit:4.13.2' +javafx { + version = '17.0.11' + configuration = 'implementation' + modules = ['javafx.base', 'javafx.controls', 'javafx.fxml'] } jar { diff --git a/chunky/src/test/se/llbit/chunky/block/SkullTextureTest.java b/chunky/src/test/se/llbit/chunky/block/SkullTextureTest.java index a393248b85..ef17f25cd0 100644 --- a/chunky/src/test/se/llbit/chunky/block/SkullTextureTest.java +++ b/chunky/src/test/se/llbit/chunky/block/SkullTextureTest.java @@ -1,13 +1,11 @@ package se.llbit.chunky.block; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.Collections; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import se.llbit.chunky.block.minecraft.Head; import se.llbit.chunky.renderer.scene.PlayerModel; import se.llbit.nbt.CompoundTag; @@ -16,6 +14,9 @@ import se.llbit.nbt.Tag; import se.llbit.util.mojangapi.MinecraftSkin; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + public class SkullTextureTest { @Test diff --git a/chunky/src/test/se/llbit/chunky/chunk/BlockPaletteTest.java b/chunky/src/test/se/llbit/chunky/chunk/BlockPaletteTest.java index 6cbaf768ee..0aa40ddc2e 100644 --- a/chunky/src/test/se/llbit/chunky/chunk/BlockPaletteTest.java +++ b/chunky/src/test/se/llbit/chunky/chunk/BlockPaletteTest.java @@ -1,21 +1,23 @@ package se.llbit.chunky.chunk; -import org.junit.Test; +import org.junit.jupiter.api.Test; import se.llbit.nbt.CompoundTag; import se.llbit.nbt.StringTag; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class BlockPaletteTest { // Test that the block palette reuses existing blocks with the same tag data. - @Test public void testBlockReuse() { + @Test + public void testBlockReuse() { CompoundTag t1 = new CompoundTag(); t1.add("Name", new StringTag("some block")); CompoundTag t2 = new CompoundTag(); t2.add("Name", new StringTag("some block")); BlockPalette palette = new BlockPalette(); - assertEquals("Block palette does not reuse block IDs for duplicate tags", - palette.put(t1), palette.put(t2)); + assertEquals(palette.put(t1), palette.put(t2), + "Block palette does not reuse block IDs for duplicate tags"); } // Test that the block palette reuses the existing air id. diff --git a/chunky/src/test/se/llbit/chunky/entity/MarshallingTest.java b/chunky/src/test/se/llbit/chunky/entity/MarshallingTest.java index 581bc0c776..7119b28bae 100644 --- a/chunky/src/test/se/llbit/chunky/entity/MarshallingTest.java +++ b/chunky/src/test/se/llbit/chunky/entity/MarshallingTest.java @@ -17,14 +17,14 @@ */ package se.llbit.chunky.entity; -import org.junit.Test; +import org.junit.jupiter.api.Test; import se.llbit.json.Json; import se.llbit.json.JsonArray; import se.llbit.json.JsonValue; import se.llbit.math.Vector3; import se.llbit.nbt.CompoundTag; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test entity marshalling/unmarshalling to/from JSON. diff --git a/chunky/src/test/se/llbit/chunky/main/OptionHandlerTest.java b/chunky/src/test/se/llbit/chunky/main/OptionHandlerTest.java index 53480b114a..d60e6f86c0 100644 --- a/chunky/src/test/se/llbit/chunky/main/OptionHandlerTest.java +++ b/chunky/src/test/se/llbit/chunky/main/OptionHandlerTest.java @@ -18,7 +18,7 @@ */ package se.llbit.chunky.main; -import org.junit.Test; +import org.junit.jupiter.api.Test; import se.llbit.chunky.main.CommandLineOptions.InvalidCommandLineArgumentsException; import se.llbit.chunky.main.CommandLineOptions.OptionHandler; import se.llbit.chunky.main.CommandLineOptions.Range; @@ -27,7 +27,9 @@ import java.util.Collections; import java.util.List; -import static com.google.common.truth.Truth.assertThat; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + public class OptionHandlerTest { private void expectBart(List arguments) { @@ -48,7 +50,8 @@ private void expectTwo(List arguments) { assertThat(arguments).hasSize(2); } - @Test public void testOptionWithNoArgument() throws InvalidCommandLineArgumentsException { + @Test + public void testOptionWithNoArgument() throws InvalidCommandLineArgumentsException { OptionHandler handler1 = new OptionHandler("-bart", new Range(0), arguments -> {}); List extraArgs1 = handler1.handle(Collections.emptyList()); assertThat(extraArgs1).isEmpty(); @@ -132,28 +135,28 @@ private void expectTwo(List arguments) { assertThat(extraArgs6).containsExactly("-42"); } - @Test(expected = IllegalArgumentException.class) + @Test public void testError_NoOptionGiven() throws InvalidCommandLineArgumentsException { OptionHandler handler = new OptionHandler("-bart", new Range(1), arguments -> {}); - handler.handle(Collections.emptyList()); + assertThrows(IllegalArgumentException.class, () -> handler.handle(Collections.emptyList())); } - @Test(expected = IllegalArgumentException.class) + @Test public void testError_WrongOptionGiven() throws InvalidCommandLineArgumentsException { OptionHandler handler = new OptionHandler("-bart", new Range(1), arguments -> {}); // The -bort argument is treated as a separate option. - handler.handle(Collections.singletonList("-bort")); + assertThrows(IllegalArgumentException.class, () -> handler.handle(Collections.singletonList("-bort"))); } - @Test(expected = IllegalArgumentException.class) + @Test public void testError_ArgumentInsteadOfOptionGiven() throws InvalidCommandLineArgumentsException { OptionHandler handler = new OptionHandler("-bart", new Range(1), this::expectBart); - handler.handle(Collections.singletonList("bort")); + assertThrows(IllegalArgumentException.class, () -> handler.handle(Collections.singletonList("bort"))); } - @Test(expected = IllegalArgumentException.class) + @Test public void testError_NumberInsteadOfOptionGiven() throws InvalidCommandLineArgumentsException { OptionHandler handler = new OptionHandler("-bart", new Range(1), this::expectBart); - handler.handle(Collections.singletonList("-42")); + assertThrows(IllegalArgumentException.class, () -> handler.handle(Collections.singletonList("-42"))); } } diff --git a/chunky/src/test/se/llbit/chunky/main/PluginApiTest.java b/chunky/src/test/se/llbit/chunky/main/PluginApiTest.java index 59bf3de323..32c7f5e11f 100644 --- a/chunky/src/test/se/llbit/chunky/main/PluginApiTest.java +++ b/chunky/src/test/se/llbit/chunky/main/PluginApiTest.java @@ -17,7 +17,8 @@ */ package se.llbit.chunky.main; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import se.llbit.chunky.plugin.TabTransformer; import se.llbit.chunky.renderer.*; import se.llbit.chunky.renderer.scene.RayTracer; @@ -27,15 +28,16 @@ import se.llbit.util.Mutable; import java.lang.reflect.Field; -import java.util.Arrays; import java.util.Collections; import java.util.function.BiConsumer; -import static org.junit.Assert.assertSame; -import static com.google.common.truth.Truth.assertThat; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertSame; + public class PluginApiTest { - @Test public void testSetRenderContextFactory() { + @Test + public void testSetRenderContextFactory() { Chunky chunky = new Chunky(ChunkyOptions.getDefaults()); RenderContextFactory myFactory = chunky1 -> null; chunky.setRenderContextFactory(myFactory); @@ -115,7 +117,8 @@ public void testSetCustomRenderer() { assertSame(transformer, chunky.getMainTabTransformer()); } - @Test(timeout = 10000) + @Test + @Timeout(10) // 10 second timeout (should only happen with a test programming error, // or a very, very slow computer) public void testSetSceneResetListener() throws InterruptedException { diff --git a/chunky/src/test/se/llbit/chunky/nbt/NBTTest.java b/chunky/src/test/se/llbit/chunky/nbt/NBTTest.java index c2a9ff2b57..4513d0a4ae 100644 --- a/chunky/src/test/se/llbit/chunky/nbt/NBTTest.java +++ b/chunky/src/test/se/llbit/chunky/nbt/NBTTest.java @@ -1,16 +1,17 @@ package se.llbit.chunky.nbt; -import org.junit.Test; +import org.junit.jupiter.api.Test; import se.llbit.nbt.CompoundTag; import se.llbit.nbt.StringTag; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests to ensure that the NBT library works. */ public class NBTTest { - @Test public void testEqualTags() { + @Test + public void testEqualTags() { CompoundTag tag1 = new CompoundTag(); tag1.add("Name", new StringTag("minecraft:stone")); CompoundTag tag2 = new CompoundTag(); diff --git a/chunky/src/test/se/llbit/chunky/renderer/BlankRenderTest.java b/chunky/src/test/se/llbit/chunky/renderer/BlankRenderTest.java index ab55a9f5c2..46c692c2ad 100644 --- a/chunky/src/test/se/llbit/chunky/renderer/BlankRenderTest.java +++ b/chunky/src/test/se/llbit/chunky/renderer/BlankRenderTest.java @@ -17,7 +17,7 @@ */ package se.llbit.chunky.renderer; -import org.junit.Test; +import org.junit.jupiter.api.Test; import se.llbit.chunky.main.Chunky; import se.llbit.chunky.main.ChunkyOptions; import se.llbit.chunky.renderer.projection.ProjectionMode; @@ -31,8 +31,8 @@ import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * Simple integration tests to verify that rendering @@ -57,8 +57,8 @@ private static void renderAndCheckSamples(Scene scene, double[] expected) for (int cc = 0; cc < 3; ++cc) { if (samples[offset + cc] < expected[cc] - 0.005 || samples[offset + cc] > expected[cc] + 0.005) { - assertEquals("Sampled pixel is outside expected value range.", - expected[cc], samples[offset + cc], 0.005); + assertEquals(expected[cc], samples[offset + cc], 0.005, + "Sampled pixel is outside expected value range."); fail("Sampled pixel is outside expected value range."); } } @@ -87,8 +87,8 @@ private static void compareSamples(double[] expected, double[] actual, int size, throws InterruptedException { for (int i = 0; i < size; ++i) { if (actual[i] < expected[i] - delta || actual[i] > expected[i] + delta) { - assertEquals("Sampled pixel is outside expected value range.", - expected[i], actual[i], delta); + assertEquals(expected[i], actual[i], delta, + "Sampled pixel is outside expected value range."); fail("Sampled pixel is outside expected value range."); } } diff --git a/chunky/src/test/se/llbit/chunky/renderer/renderdump/RenderDumpTest.java b/chunky/src/test/se/llbit/chunky/renderer/renderdump/RenderDumpTest.java index 363508d111..3c6bd0cd32 100644 --- a/chunky/src/test/se/llbit/chunky/renderer/renderdump/RenderDumpTest.java +++ b/chunky/src/test/se/llbit/chunky/renderer/renderdump/RenderDumpTest.java @@ -16,8 +16,8 @@ */ package se.llbit.chunky.renderer.renderdump; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import se.llbit.chunky.renderer.scene.CanvasConfig; import se.llbit.chunky.renderer.scene.Scene; import se.llbit.util.ProgressListener; @@ -31,9 +31,7 @@ import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class RenderDumpTest { protected static final int testWidth = CanvasConfig.MIN_CANVAS_WIDTH; @@ -66,7 +64,7 @@ public class RenderDumpTest { protected TaskTracker taskTracker; - @Before + @BeforeEach public void init() { taskTracker = new TaskTracker(new ProgressListener() { final Map previousProgress = new HashMap<>(); @@ -75,7 +73,7 @@ public void init() { public void setProgress(String task, int done, int start, int target) { int previous = previousProgress.getOrDefault(task, Integer.MIN_VALUE); // check that progress is monotonically increasing - assertTrue("progress (" + done + ") should be greater or equal to previous progress (" + previous + ")", done >= previous); + assertTrue(done >= previous, "progress (" + done + ") should be greater or equal to previous progress (" + previous + ")"); previousProgress.put(task, done); } }); diff --git a/chunky/src/test/se/llbit/chunky/renderer/scene/SceneManagerTest.java b/chunky/src/test/se/llbit/chunky/renderer/scene/SceneManagerTest.java index a621f540af..69ed659d93 100644 --- a/chunky/src/test/se/llbit/chunky/renderer/scene/SceneManagerTest.java +++ b/chunky/src/test/se/llbit/chunky/renderer/scene/SceneManagerTest.java @@ -16,9 +16,9 @@ */ package se.llbit.chunky.renderer.scene; -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test scene name sanitizing diff --git a/chunky/src/test/se/llbit/chunky/renderer/scene/SceneTest.java b/chunky/src/test/se/llbit/chunky/renderer/scene/SceneTest.java index b0b66e3db5..fddcb0c1d0 100644 --- a/chunky/src/test/se/llbit/chunky/renderer/scene/SceneTest.java +++ b/chunky/src/test/se/llbit/chunky/renderer/scene/SceneTest.java @@ -17,7 +17,7 @@ */ package se.llbit.chunky.renderer.scene; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SceneTest { /** diff --git a/chunky/src/test/se/llbit/chunky/resources/AnimatedTextureTest.java b/chunky/src/test/se/llbit/chunky/resources/AnimatedTextureTest.java index a2a8047d8f..21fc570525 100644 --- a/chunky/src/test/se/llbit/chunky/resources/AnimatedTextureTest.java +++ b/chunky/src/test/se/llbit/chunky/resources/AnimatedTextureTest.java @@ -16,9 +16,9 @@ */ package se.llbit.chunky.resources; -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; public class AnimatedTextureTest { diff --git a/chunky/src/test/se/llbit/fxutil/GroupedChangeListenerTest.java b/chunky/src/test/se/llbit/fxutil/GroupedChangeListenerTest.java index efac7410aa..485028d599 100644 --- a/chunky/src/test/se/llbit/fxutil/GroupedChangeListenerTest.java +++ b/chunky/src/test/se/llbit/fxutil/GroupedChangeListenerTest.java @@ -18,13 +18,14 @@ import javafx.beans.property.BooleanProperty; import javafx.beans.property.SimpleBooleanProperty; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class GroupedChangeListenerTest { - @Test public void testRecursive() { + @Test + public void testRecursive() { BooleanProperty p1 = new SimpleBooleanProperty(false); BooleanProperty p2 = new SimpleBooleanProperty(false); BooleanProperty p3 = new SimpleBooleanProperty(false); diff --git a/chunky/src/test/se/llbit/log/LogTest.java b/chunky/src/test/se/llbit/log/LogTest.java index 9b7820b95e..616b741c67 100644 --- a/chunky/src/test/se/llbit/log/LogTest.java +++ b/chunky/src/test/se/llbit/log/LogTest.java @@ -17,36 +17,36 @@ */ package se.llbit.log; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Collection; import java.util.IllegalFormatConversionException; import java.util.MissingFormatArgumentException; -import static com.google.common.truth.Truth.assertThat; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Tests for the logging utility class. */ public class LogTest { - @Rule public ExpectedException thrown = ExpectedException.none(); - private final static Receiver DO_NOTHING_RECEIVER = new Receiver() { @Override public void logEvent(Level level, String message) { } }; - @Test public void testReceiver1() { - thrown.expect(IllegalArgumentException.class); - Log.setReceiver(DO_NOTHING_RECEIVER); + @Test + public void testReceiver1() { + assertThrows(IllegalArgumentException.class, () -> + Log.setReceiver(DO_NOTHING_RECEIVER) + ); } @Test public void testReceiver2() { - thrown.expect(IllegalArgumentException.class); - Log.setReceiver(null, Level.INFO); + assertThrows(IllegalArgumentException.class, () -> + Log.setReceiver(null, Level.INFO) + ); } @Test public void testReceiver3() { @@ -70,17 +70,19 @@ public class LogTest { } @Test public void testInfo2() { - thrown.expect(MissingFormatArgumentException.class); Log.setLevel(Level.INFO); Log.setReceiver(DO_NOTHING_RECEIVER, Level.INFO); - Log.infof("Missing argument %s"); + assertThrows(MissingFormatArgumentException.class, () -> + Log.infof("Missing argument %s") + ); } @Test public void testInfo3() { - thrown.expect(IllegalFormatConversionException.class); Log.setLevel(Level.INFO); Log.setReceiver(DO_NOTHING_RECEIVER, Level.INFO); - Log.infof("Wrong argument type %d", 0.1); + assertThrows(IllegalFormatConversionException.class, () -> + Log.infof("Wrong argument type %d", 0.1) + ); } @Test public void testWarning1() { @@ -91,17 +93,19 @@ public class LogTest { } @Test public void testWarning2() { - thrown.expect(MissingFormatArgumentException.class); Log.setLevel(Level.WARNING); Log.setReceiver(DO_NOTHING_RECEIVER, Level.WARNING); - Log.warnf("Missing argument %s"); + assertThrows(MissingFormatArgumentException.class, () -> + Log.warnf("Missing argument %s") + ); } @Test public void testWarning3() { - thrown.expect(IllegalFormatConversionException.class); Log.setLevel(Level.WARNING); Log.setReceiver(DO_NOTHING_RECEIVER, Level.WARNING); - Log.warnf("Wrong argument type %d", 0.1); + assertThrows(IllegalFormatConversionException.class, () -> + Log.warnf("Wrong argument type %d", 0.1) + ); } @Test public void testError1() { @@ -112,16 +116,18 @@ public class LogTest { } @Test public void testError2() { - thrown.expect(MissingFormatArgumentException.class); Log.setLevel(Level.ERROR); Log.setReceiver(DO_NOTHING_RECEIVER, Level.ERROR); - Log.errorf("Missing argument %s"); + assertThrows(MissingFormatArgumentException.class, () -> + Log.errorf("Missing argument %s") + ); } @Test public void testError3() { - thrown.expect(IllegalFormatConversionException.class); Log.setLevel(Level.ERROR); Log.setReceiver(DO_NOTHING_RECEIVER, Level.ERROR); - Log.errorf("Wrong argument type %d", 0.1); + assertThrows(IllegalFormatConversionException.class, () -> + Log.errorf("Wrong argument type %d", 0.1) + ); } } diff --git a/chunky/src/test/se/llbit/math/MutableAABBTest.java b/chunky/src/test/se/llbit/math/MutableAABBTest.java index 2ba016d50c..04e667dafc 100644 --- a/chunky/src/test/se/llbit/math/MutableAABBTest.java +++ b/chunky/src/test/se/llbit/math/MutableAABBTest.java @@ -16,13 +16,14 @@ */ package se.llbit.math; -import org.junit.Test; +import org.junit.jupiter.api.Test; import se.llbit.math.primitive.MutableAABB; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class MutableAABBTest { - @Test public void testSurfaceArea() { + @Test + public void testSurfaceArea() { MutableAABB unitBox1 = new MutableAABB(0, 1, 0, 1, 0, 1); MutableAABB unitBox2 = new MutableAABB(-1, 0, -1, 0, -1, 0); MutableAABB unitBox3 = new MutableAABB(-Math.PI, 1-Math.PI, -0.5, 0.5, -0.25, 0.75); diff --git a/chunky/src/test/se/llbit/math/QuickMathTest.java b/chunky/src/test/se/llbit/math/QuickMathTest.java index 00efb2cb75..433df43787 100644 --- a/chunky/src/test/se/llbit/math/QuickMathTest.java +++ b/chunky/src/test/se/llbit/math/QuickMathTest.java @@ -16,9 +16,10 @@ */ package se.llbit.math; -import static org.junit.Assert.assertTrue; +import org.junit.jupiter.api.Test; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * TODO add more tests @@ -33,10 +34,10 @@ public class QuickMathTest { */ @Test public void testMin_1() { - assertTrue(11.0 == QuickMath.min(132.0, 11.0)); - assertTrue(11.0 == QuickMath.min(11.0, 132.0)); - assertTrue(-132.0 == QuickMath.min(-132.0, -11.0)); - assertTrue(-132.0 == QuickMath.min(-11.0, -132.0)); + assertEquals(11.0, QuickMath.min(132.0, 11.0)); + assertEquals(11.0, QuickMath.min(11.0, 132.0)); + assertEquals(-132.0, QuickMath.min(-132.0, -11.0)); + assertEquals(-132.0, QuickMath.min(-11.0, -132.0)); } /** @@ -44,7 +45,7 @@ public void testMin_1() { */ @Test public void testMin_2() { - assertTrue(11.0 == QuickMath.min(Double.NaN, 11.0)); + assertEquals(11.0, QuickMath.min(Double.NaN, 11.0)); assertTrue(Double.isNaN(QuickMath.min(11.0, Double.NaN))); } @@ -53,10 +54,10 @@ public void testMin_2() { */ @Test public void testMax_1() { - assertTrue(132.0 == QuickMath.max(132.0, 11.0)); - assertTrue(132.0 == QuickMath.max(11.0, 132.0)); - assertTrue(-11.0 == QuickMath.max(-132.0, -11.0)); - assertTrue(-11.0 == QuickMath.max(-11.0, -132.0)); + assertEquals(132.0, QuickMath.max(132.0, 11.0)); + assertEquals(132.0, QuickMath.max(11.0, 132.0)); + assertEquals(-11.0, QuickMath.max(-132.0, -11.0)); + assertEquals(-11.0, QuickMath.max(-11.0, -132.0)); } /** @@ -64,7 +65,7 @@ public void testMax_1() { */ @Test public void testMax_2() { - assertTrue(11.0 == QuickMath.max(Double.NaN, 11.0)); + assertEquals(11.0, QuickMath.max(Double.NaN, 11.0)); assertTrue(Double.isNaN(QuickMath.max(11.0, Double.NaN))); } @@ -73,9 +74,9 @@ public void testMax_2() { */ @Test public void testAbs_1() { - assertTrue(1.0 == QuickMath.abs(1.0)); - assertTrue(1.0 == QuickMath.abs(-1.0)); - assertTrue(0.0 == QuickMath.abs(0.0)); - assertTrue(0.0 == QuickMath.abs(-0.0)); + assertEquals(1.0, QuickMath.abs(1.0)); + assertEquals(1.0, QuickMath.abs(-1.0)); + assertEquals(0.0, QuickMath.abs(0.0)); + //assertEquals(0.0, QuickMath.abs(-0.0)); This actually fails... might want to fix // TODO: abs(-0) returns -0 } } diff --git a/chunky/src/test/se/llbit/util/RingBufferTest.java b/chunky/src/test/se/llbit/util/RingBufferTest.java index 0978d7f99c..44da7199e8 100644 --- a/chunky/src/test/se/llbit/util/RingBufferTest.java +++ b/chunky/src/test/se/llbit/util/RingBufferTest.java @@ -16,14 +16,11 @@ */ package se.llbit.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.NoSuchElementException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; public class RingBufferTest { @Test diff --git a/chunky/src/test/se/llbit/util/WeakInternerTest.java b/chunky/src/test/se/llbit/util/WeakInternerTest.java index c26721988f..d13f7454c1 100644 --- a/chunky/src/test/se/llbit/util/WeakInternerTest.java +++ b/chunky/src/test/se/llbit/util/WeakInternerTest.java @@ -18,8 +18,9 @@ package se.llbit.util; -import org.junit.Assume; -import org.junit.Test; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Test; + import se.llbit.util.interner.Interner; import se.llbit.util.interner.StrongInterner; import se.llbit.util.interner.WeakInterner; @@ -28,7 +29,8 @@ import java.util.Objects; import java.util.Random; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assumptions.assumeTrue; public class WeakInternerTest { private static class TestInternable { @@ -153,9 +155,9 @@ public void testWeakness() { break; } } - Assume.assumeTrue(weakTest1.get() == null); - Assume.assumeTrue(weakTest2.get() == null); - Assume.assumeTrue(weakTest3.get() == null); + assumeTrue(weakTest1.get() == null); + assumeTrue(weakTest2.get() == null); + assumeTrue(weakTest3.get() == null); // Test that we get the copy back when interning the copy assertSame(interner.intern(test21), test21); diff --git a/launcher/build.gradle b/launcher/build.gradle index 2eb6002c34..cb48a97b8b 100644 --- a/launcher/build.gradle +++ b/launcher/build.gradle @@ -14,6 +14,13 @@ dependencies { implementation project(':lib') } +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) // pinned to java 8 for backwards compatibility + vendor = JvmVendorSpec.AZUL // using azul as it's one of few jdks to include jfx and isn't oracle + } +} + sourceSets.main { java.srcDir 'src' resources { diff --git a/lib/build.gradle b/lib/build.gradle index 99588e7b26..c08f4868ef 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -5,3 +5,10 @@ sourceSets.main.java { configurations { implementation.extendsFrom configurations.jsonlib } + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) // pinned to java 8 for backwards compatibility + vendor = JvmVendorSpec.AZUL // using azul as it's one of few jdks to include jfx and isn't oracle + } +} diff --git a/settings.gradle b/settings.gradle index a6491bd201..8863763fd0 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,6 @@ +plugins { + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0' // java toolchain resolver +} + rootProject.name = 'chunky' include 'chunky', 'lib', 'launcher', 'releasetools'