Skip to content

Commit

Permalink
Update to Java 17 (Java 21 and JUnit 5 for tests), except for lib and…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
NotStirred authored Jul 5, 2024
1 parent f691d42 commit dac29e8
Show file tree
Hide file tree
Showing 22 changed files with 181 additions and 121 deletions.
46 changes: 34 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,42 @@ buildscript {
subprojects {
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'org.openjfx.javafxplugin'

apply plugin: 'idea'
apply plugin: 'com.github.ben-manes.versions'

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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -236,6 +257,7 @@ task docs(type: Javadoc) {
}

task clean {
group = "Build"
doLast {
delete "./build"
}
Expand Down
8 changes: 6 additions & 2 deletions chunky/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions chunky/src/test/se/llbit/chunky/block/SkullTextureTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions chunky/src/test/se/llbit/chunky/chunk/BlockPaletteTest.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions chunky/src/test/se/llbit/chunky/entity/MarshallingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 14 additions & 11 deletions chunky/src/test/se/llbit/chunky/main/OptionHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> arguments) {
Expand All @@ -48,7 +50,8 @@ private void expectTwo(List<String> 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<String> extraArgs1 = handler1.handle(Collections.emptyList());
assertThat(extraArgs1).isEmpty();
Expand Down Expand Up @@ -132,28 +135,28 @@ private void expectTwo(List<String> 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")));
}
}
15 changes: 9 additions & 6 deletions chunky/src/test/se/llbit/chunky/main/PluginApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions chunky/src/test/se/llbit/chunky/nbt/NBTTest.java
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
14 changes: 7 additions & 7 deletions chunky/src/test/se/llbit/chunky/renderer/BlankRenderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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.");
}
}
Expand Down Expand Up @@ -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.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -66,7 +64,7 @@ public class RenderDumpTest {

protected TaskTracker taskTracker;

@Before
@BeforeEach
public void init() {
taskTracker = new TaskTracker(new ProgressListener() {
final Map<String, Integer> previousProgress = new HashMap<>();
Expand All @@ -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);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit dac29e8

Please sign in to comment.