Skip to content

Commit 5a3cab8

Browse files
authored
chore: modernise build and tests for Java 17 baseline (#42)
Companion to the BanManager Java 17 modernisation sweep. Build - Stonecutter 0.7.11 -> 0.8.3 (settings.gradle.kts uses the renamed shared.version() API instead of vers()). - Foojay toolchain resolver 0.9.0 -> 1.0.0. - Add com.vanniktech.maven.publish to buildSrc so libs/sub-projects can publish consistently with BanManager. - Set Libs source/target compatibility and TargetJvmVersion attribute to 17 (matches the Java 17 baseline already in use by other modules). - Lombok 1.18.36 -> 1.18.38. - bStats Bukkit/Bungee/Velocity bumped to 3.2.1, Sponge to 3.2.1 (was a mix of 2.2.1 / 3.0.0 / 3.0.2). - Guava 17.0 -> 33.4.8-jre and dropped the unused bcpkix-jdk15on shade (only bcprov is referenced by the encoder). - Append -XX:+UseStringDeduplication to the Gradle JVM args. Tests - Migrate the three remaining tests (PlayerPinDataTest, CommonPlayerDeniedListenerTest, Argon2PasswordEncoderTest) from JUnit 4 + PowerMock + Mockito 4 to JUnit 5 + Mockito 5 (mockito-junit-jupiter 5.14.2). PowerMock dropped. - mariaDB4j 2.6.0 -> 3.3.1, awaitility 4.0.1 -> 4.3.0, jacoco 0.8.11 -> 0.8.12. - Refresh the forkEvery=1 inline comment to point at the BanManager common build for full rationale (JDBC drivers and native fixtures leak across runs). Verification - ./gradlew :BanManagerWebEnhancerCommon:test - 22 tests, 0 skipped, 0 failures, 0 errors. - Sequential ./gradlew build -x test produces every artifact across Bukkit, Bungee, Velocity, Sponge, and all 4 Fabric variants.
1 parent 5eb683e commit 5a3cab8

14 files changed

Lines changed: 73 additions & 78 deletions

File tree

buildSrc/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ dependencies {
2222
implementation("org.jfrog.buildinfo:build-info-extractor-gradle:5.2.5")
2323
implementation("org.spongepowered:spongegradle-plugin-development:2.3.0")
2424
implementation("fabric-loom:fabric-loom.gradle.plugin:1.15.3")
25+
implementation("com.vanniktech:gradle-maven-publish-plugin:0.35.0")
2526
}

buildSrc/src/main/kotlin/CommonConfig.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ fun Project.applyCommonConfiguration() {
1717
}
1818

1919
dependencies {
20-
"compileOnly"("org.projectlombok:lombok:1.18.36")
21-
"annotationProcessor"("org.projectlombok:lombok:1.18.36")
20+
"compileOnly"("org.projectlombok:lombok:1.18.38")
21+
"annotationProcessor"("org.projectlombok:lombok:1.18.38")
2222

23-
"testCompileOnly"("org.projectlombok:lombok:1.18.36")
24-
"testAnnotationProcessor"("org.projectlombok:lombok:1.18.36")
23+
"testCompileOnly"("org.projectlombok:lombok:1.18.38")
24+
"testAnnotationProcessor"("org.projectlombok:lombok:1.18.38")
2525
}
2626

2727
configurations.all {

buildSrc/src/main/kotlin/PlatformConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fun Project.applyPlatformAndCoreConfiguration() {
2525

2626
ext["internalVersion"] = "$version"
2727

28-
// Java 8 turns on doclint which we fail
28+
// Suppress doclint to keep javadoc builds green; tags below document supported custom tags.
2929
tasks.withType<Javadoc>().configureEach {
3030
(options as StandardJavadocDocletOptions).apply {
3131
addStringOption("Xdoclint:none", "-quiet")

bukkit/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies {
3232
exclude("junit", "junit")
3333
}
3434
compileOnly("org.apache.logging.log4j:log4j-core:2.17.0")
35-
"shadeOnly"("org.bstats:bstats-bukkit:2.2.1")
35+
"shadeOnly"("org.bstats:bstats-bukkit:3.2.1")
3636
}
3737

3838
tasks.named<Copy>("processResources") {

bungee/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ dependencies {
2929
compileOnly("me.confuser.banmanager:BanManagerBungee:8.0.0-SNAPSHOT")
3030

3131
compileOnly("net.md-5:bungeecord-api:1.21-R0.4")
32-
"shadeOnly"("org.bstats:bstats-bungeecord:2.2.1")
32+
"shadeOnly"("org.bstats:bstats-bungeecord:3.2.1")
3333
}
3434

3535
tasks.named<Copy>("processResources") {

common/build.gradle.kts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,26 @@ dependencies {
1111
api("me.confuser.banmanager:BanManagerCommon:8.0.0-SNAPSHOT")
1212
api("me.confuser.banmanager.BanManagerLibs:BanManagerLibs:8.0.0-SNAPSHOT")
1313

14-
// Test dependencies
15-
testImplementation("junit:junit:4.13")
16-
testImplementation("org.mockito:mockito-core:4.0.0")
17-
testImplementation("org.powermock:powermock-module-junit4:2.0.2")
18-
testImplementation("org.powermock:powermock-api-mockito2:2.0.2")
19-
testImplementation("ch.vorburger.mariaDB4j:mariaDB4j:2.6.0")
20-
testImplementation("org.awaitility:awaitility:4.0.1")
14+
testImplementation(platform("org.junit:junit-bom:5.11.4"))
15+
testImplementation("org.junit.jupiter:junit-jupiter")
16+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
17+
testImplementation("org.mockito:mockito-core:5.14.2")
18+
testImplementation("org.mockito:mockito-junit-jupiter:5.14.2")
19+
testImplementation("ch.vorburger.mariaDB4j:mariaDB4j:3.3.1")
20+
testImplementation("org.awaitility:awaitility:4.3.0")
2121
}
2222

2323
tasks.withType<Test>().configureEach {
24-
useJUnit()
24+
useJUnitPlatform()
2525
maxHeapSize = "512m"
26-
forkEvery = 1 // Fork a new JVM for each test class to prevent memory accumulation
26+
// Fork a new JVM per test class - tests share JDBC/native fixtures that otherwise
27+
// accumulate state across runs and hang the suite. See BanManager/common build.
28+
forkEvery = 1
2729
finalizedBy(tasks.jacocoTestReport)
2830
}
2931

3032
jacoco {
31-
toolVersion = "0.8.11"
33+
toolVersion = "0.8.12"
3234
}
3335

3436
tasks.jacocoTestReport {

common/src/test/java/me/confuser/banmanager/webenhancer/common/data/PlayerPinDataTest.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package me.confuser.banmanager.webenhancer.common.data;
22

33
import me.confuser.banmanager.common.data.PlayerData;
4-
import org.junit.Test;
4+
import org.junit.jupiter.api.Test;
55

66
import java.security.NoSuchAlgorithmException;
77
import java.util.UUID;
88

9-
import static org.junit.Assert.*;
9+
import static org.junit.jupiter.api.Assertions.*;
1010
import static org.mockito.Mockito.*;
1111

1212
/**
@@ -23,8 +23,8 @@ public void shouldGenerateSixDigitPin() throws NoSuchAlgorithmException {
2323
int pin = pinData.getGeneratedPin();
2424

2525
// 6 digit pin: 100000-999999
26-
assertTrue("Pin should be at least 100000", pin >= 100000);
27-
assertTrue("Pin should be at most 999999", pin <= 999999);
26+
assertTrue(pin >= 100000, "Pin should be at least 100000");
27+
assertTrue(pin <= 999999, "Pin should be at most 999999");
2828
}
2929

3030
@Test
@@ -35,8 +35,8 @@ public void shouldHashPinWithArgon2() throws NoSuchAlgorithmException {
3535
PlayerPinData pinData = new PlayerPinData(player);
3636
String hashedPin = pinData.getPin();
3737

38-
assertNotNull("Hashed pin should not be null", hashedPin);
39-
assertTrue("Pin should be hashed with Argon2i", hashedPin.startsWith("$argon2i$"));
38+
assertNotNull(hashedPin, "Hashed pin should not be null");
39+
assertTrue(hashedPin.startsWith("$argon2i$"), "Pin should be hashed with Argon2i");
4040
}
4141

4242
@Test
@@ -52,8 +52,7 @@ public void shouldSetExpiryFiveMinutesFromNow() throws NoSuchAlgorithmException
5252
long expires = pinData.getExpires();
5353

5454
// Allow 1 second tolerance for test execution
55-
assertTrue("Expiry should be ~300 seconds from creation",
56-
expires >= beforeCreate + 299 && expires <= afterCreate + 301);
55+
assertTrue(expires >= beforeCreate + 299 && expires <= afterCreate + 301, "Expiry should be ~300 seconds from creation");
5756
}
5857

5958
@Test
@@ -66,9 +65,8 @@ public void shouldStoreGeneratedPinForDisplay() throws NoSuchAlgorithmException
6665
int generatedPin = pinData.getGeneratedPin();
6766
String hashedPin = pinData.getPin();
6867

69-
assertNotEquals("Generated pin should not be 0", 0, generatedPin);
70-
assertFalse("Hashed pin should not equal plaintext",
71-
hashedPin.equals(String.valueOf(generatedPin)));
68+
assertNotEquals(0, generatedPin, "Generated pin should not be 0");
69+
assertFalse(hashedPin.equals(String.valueOf(generatedPin)), "Hashed pin should not equal plaintext");
7270
}
7371

7472
@Test
@@ -78,7 +76,7 @@ public void shouldStorePlayerReference() throws NoSuchAlgorithmException {
7876

7977
PlayerPinData pinData = new PlayerPinData(player);
8078

81-
assertSame("Player reference should be stored", player, pinData.getPlayer());
79+
assertSame(player, pinData.getPlayer(), "Player reference should be stored");
8280
}
8381

8482
@Test
@@ -88,7 +86,7 @@ public void shouldHaveZeroIdBeforePersistence() throws NoSuchAlgorithmException
8886

8987
PlayerPinData pinData = new PlayerPinData(player);
9088

91-
assertEquals("ID should be 0 before persistence", 0, pinData.getId());
89+
assertEquals(0, pinData.getId(), "ID should be 0 before persistence");
9290
}
9391

9492
@Test
@@ -105,7 +103,7 @@ public void shouldGenerateRandomPins() throws NoSuchAlgorithmException {
105103
pin1.getGeneratedPin() != pin3.getGeneratedPin() ||
106104
pin2.getGeneratedPin() != pin3.getGeneratedPin();
107105

108-
assertTrue("At least two of three pins should differ", atLeastTwoDifferent);
106+
assertTrue(atLeastTwoDifferent, "At least two of three pins should differ");
109107
}
110108

111109
@Test
@@ -118,8 +116,7 @@ public void shouldGenerateUniqueHashesForSamePin() throws NoSuchAlgorithmExcepti
118116

119117
// Even if by chance the generated pins are the same, the hashes should differ
120118
// due to unique random salts in Argon2
121-
assertNotEquals("Hashes should differ due to random salts",
122-
pin1.getPin(), pin2.getPin());
119+
assertNotEquals(pin1.getPin(), pin2.getPin(), "Hashes should differ due to random salts");
123120
}
124121

125122
@Test
@@ -130,6 +127,6 @@ public void generatedPinShouldBeSettable() throws NoSuchAlgorithmException {
130127
PlayerPinData pinData = new PlayerPinData(player);
131128
pinData.setGeneratedPin(999999);
132129

133-
assertEquals("Generated pin should be settable", 999999, pinData.getGeneratedPin());
130+
assertEquals(999999, pinData.getGeneratedPin(), "Generated pin should be settable");
134131
}
135132
}

common/src/test/java/me/confuser/banmanager/webenhancer/common/listeners/CommonPlayerDeniedListenerTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
import me.confuser.banmanager.webenhancer.common.WebEnhancerPlugin;
66
import me.confuser.banmanager.webenhancer.common.data.PlayerPinData;
77
import me.confuser.banmanager.webenhancer.common.storage.PlayerPinStorage;
8-
import org.junit.Before;
9-
import org.junit.Test;
10-
import org.junit.runner.RunWith;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
10+
import org.junit.jupiter.api.extension.ExtendWith;
1111
import org.mockito.Mock;
12-
import org.mockito.junit.MockitoJUnitRunner;
12+
import org.mockito.junit.jupiter.MockitoExtension;
1313

14-
import static org.junit.Assert.*;
1514
import static org.mockito.Mockito.*;
1615

17-
@RunWith(MockitoJUnitRunner.class)
16+
@ExtendWith(MockitoExtension.class)
1817
public class CommonPlayerDeniedListenerTest {
1918

2019
@Mock
@@ -31,9 +30,9 @@ public class CommonPlayerDeniedListenerTest {
3130

3231
private CommonPlayerDeniedListener listener;
3332

34-
@Before
33+
@BeforeEach
3534
public void setUp() {
36-
when(plugin.getPlayerPinStorage()).thenReturn(playerPinStorage);
35+
lenient().when(plugin.getPlayerPinStorage()).thenReturn(playerPinStorage);
3736
listener = new CommonPlayerDeniedListener(plugin);
3837
}
3938

common/src/test/java/me/confuser/banmanager/webenhancer/common/security/Argon2PasswordEncoderTest.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package me.confuser.banmanager.webenhancer.common.security;
22

3-
import org.junit.Before;
4-
import org.junit.Test;
3+
import org.junit.jupiter.api.BeforeEach;
4+
import org.junit.jupiter.api.Test;
55

6-
import static org.junit.Assert.*;
6+
import static org.junit.jupiter.api.Assertions.*;
77

88
/**
99
* Unit tests for Argon2PasswordEncoder.
@@ -12,7 +12,7 @@ public class Argon2PasswordEncoderTest {
1212

1313
private Argon2PasswordEncoder encoder;
1414

15-
@Before
15+
@BeforeEach
1616
public void setUp() {
1717
encoder = new Argon2PasswordEncoder();
1818
}
@@ -23,8 +23,8 @@ public void shouldEncodePassword() {
2323

2424
String encoded = encoder.encode(password);
2525

26-
assertNotNull("Encoded password should not be null", encoded);
27-
assertNotEquals("Encoded password should differ from original", password, encoded);
26+
assertNotNull(encoded, "Encoded password should not be null");
27+
assertNotEquals(password, encoded, "Encoded password should differ from original");
2828
}
2929

3030
@Test
@@ -34,7 +34,7 @@ public void shouldProduceArgon2iFormat() {
3434
String encoded = encoder.encode(password);
3535

3636
// Argon2i format starts with $argon2i$
37-
assertTrue("Hash should use Argon2i format", encoded.startsWith("$argon2i$"));
37+
assertTrue(encoded.startsWith("$argon2i$"), "Hash should use Argon2i format");
3838
}
3939

4040
@Test
@@ -44,7 +44,7 @@ public void shouldGenerateUniqueSaltsForSameInput() {
4444
String encoded1 = encoder.encode(password);
4545
String encoded2 = encoder.encode(password);
4646

47-
assertNotEquals("Hashes should differ due to unique salts", encoded1, encoded2);
47+
assertNotEquals(encoded1, encoded2, "Hashes should differ due to unique salts");
4848
}
4949

5050
@Test
@@ -53,7 +53,7 @@ public void shouldProduceCorrectHashLength() {
5353

5454
String encoded = encoder.encode(password);
5555

56-
assertTrue("Hash string should be substantial", encoded.length() > 50);
56+
assertTrue(encoded.length() > 50, "Hash string should be substantial");
5757
}
5858

5959
@Test
@@ -62,8 +62,8 @@ public void shouldHandleEmptyPassword() {
6262

6363
String encoded = encoder.encode(password);
6464

65-
assertNotNull("Should handle empty password", encoded);
66-
assertTrue("Should still produce Argon2i format", encoded.startsWith("$argon2i$"));
65+
assertNotNull(encoded, "Should handle empty password");
66+
assertTrue(encoded.startsWith("$argon2i$"), "Should still produce Argon2i format");
6767
}
6868

6969
@Test
@@ -75,8 +75,8 @@ public void shouldHandleLongPassword() {
7575

7676
String encoded = encoder.encode(longPassword.toString());
7777

78-
assertNotNull("Should handle long password", encoded);
79-
assertTrue("Should still produce Argon2i format", encoded.startsWith("$argon2i$"));
78+
assertNotNull(encoded, "Should handle long password");
79+
assertTrue(encoded.startsWith("$argon2i$"), "Should still produce Argon2i format");
8080
}
8181

8282
@Test
@@ -85,8 +85,8 @@ public void shouldHandleSpecialCharacters() {
8585

8686
String encoded = encoder.encode(password);
8787

88-
assertNotNull("Should handle special characters", encoded);
89-
assertTrue("Should still produce Argon2i format", encoded.startsWith("$argon2i$"));
88+
assertNotNull(encoded, "Should handle special characters");
89+
assertTrue(encoded.startsWith("$argon2i$"), "Should still produce Argon2i format");
9090
}
9191

9292
@Test
@@ -96,14 +96,14 @@ public void shouldHandleNumericPin() {
9696

9797
String encoded = encoder.encode(pin);
9898

99-
assertNotNull("Should handle numeric PIN", encoded);
100-
assertTrue("Should produce Argon2i format", encoded.startsWith("$argon2i$"));
99+
assertNotNull(encoded, "Should handle numeric PIN");
100+
assertTrue(encoded.startsWith("$argon2i$"), "Should produce Argon2i format");
101101

102102
// Verify format contains expected parameters
103-
assertTrue("Should contain version", encoded.contains("v="));
104-
assertTrue("Should contain memory parameter", encoded.contains("m="));
105-
assertTrue("Should contain time parameter", encoded.contains("t="));
106-
assertTrue("Should contain parallelism parameter", encoded.contains("p="));
103+
assertTrue(encoded.contains("v="), "Should contain version");
104+
assertTrue(encoded.contains("m="), "Should contain memory parameter");
105+
assertTrue(encoded.contains("t="), "Should contain time parameter");
106+
assertTrue(encoded.contains("p="), "Should contain parallelism parameter");
107107
}
108108

109109
@Test
@@ -117,6 +117,6 @@ public void shouldProduceConsistentFormatAcrossMultipleCalls() {
117117

118118
String format2 = encoded2.substring(0, encoded2.indexOf("$", 9));
119119

120-
assertEquals("Both instances should produce same format", format1, format2);
120+
assertEquals(format1, format2, "Both instances should produce same format");
121121
}
122122
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ group=me.confuser.banmanager.webenhancer
22
version=8.0.0-SNAPSHOT
33
org.gradle.parallel=true
44

5-
org.gradle.jvmargs=-Xmx2G -XX:+UseG1GC -XX:MaxGCPauseMillis=200
5+
org.gradle.jvmargs=-Xmx2G -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+UseStringDeduplication

0 commit comments

Comments
 (0)