Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ tasks {
// engine errors (e.g. "Unable to stop thread") on slow/loaded CI machines.
// Retry failed tests a few times so such flakiness does not fail the build.
withType<Test> {
useJUnitPlatform()
retry {
maxRetries.set(2)
maxFailures.set(20)
Expand Down
8 changes: 6 additions & 2 deletions gradle/test-libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
[versions]

junit = "4.13.2"
junit = "5.14.4"
junit-platform = "1.14.4"
hamcrest = "3.0"

[libraries]

junit = { module = "junit:junit", version.ref = "junit" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
hamcrest = { module = "org.hamcrest:hamcrest", version.ref = "hamcrest" }
junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junit-platform" }

[bundles]

Expand Down
3 changes: 2 additions & 1 deletion robocode.core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ dependencies {
implementation(project(":robocode.api"))
implementation(libs.picocontainer)

testImplementation(testLibs.junit)
testImplementation(testLibs.junit.jupiter)
testRuntimeOnly(testLibs.junit.platform.launcher)
}

description = "Robocode Core"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import net.sf.robocode.robotpaint.Graphics2DSerialized;
import net.sf.robocode.security.HiddenAccess;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import robocode.util.Utils;

Expand All @@ -39,7 +39,7 @@ public class RbSerializerTest {

Exception exception = null;

@BeforeClass
@BeforeAll
public static void init() {
if (!new File("").getAbsolutePath().endsWith("robocode.core")) {
throw new Error("Please run test with current directory in 'robocode.core'");
Expand All @@ -51,7 +51,7 @@ public static void init() {
HiddenAccess.initContainer();
}

@AfterClass
@AfterAll
public static void cleanup() {
System.setProperty("NOSECURITY", "false");
}
Expand All @@ -72,7 +72,7 @@ public void empty() throws IOException {
ExecCommands ec2 = (ExecCommands) rbs.deserialize(in);

assertNear(ec2.getBodyTurnRemaining(), ec.getBodyTurnRemaining());
Assert.assertTrue(ec2.isTryingToPaint());
Assertions.assertTrue(ec2.isTryingToPaint());
}

@Test
Expand All @@ -93,9 +93,9 @@ public void withBullets() throws IOException {

assertNear(ec2.getBodyTurnRemaining(), ec.getBodyTurnRemaining());
assertNear(ec2.getBullets().get(0).getPower(), 1.0);
Assert.assertFalse(ec2.getBullets().get(1).isFireAssistValid());
Assert.assertTrue(ec2.getBullets().get(2).isFireAssistValid());
Assert.assertEquals(ec2.getBullets().get(2).getBulletId(), -128);
Assertions.assertFalse(ec2.getBullets().get(1).isFireAssistValid());
Assertions.assertTrue(ec2.getBullets().get(2).isFireAssistValid());
Assertions.assertEquals(ec2.getBullets().get(2).getBulletId(), -128);
}

@Test
Expand All @@ -117,11 +117,11 @@ public void withMessages() throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
ExecCommands ec2 = (ExecCommands) rbs.deserialize(in);

Assert.assertEquals(ec2.getTeamMessages().get(0).message[0], 0);
Assert.assertEquals(ec2.getTeamMessages().get(0).message[10], 10);
Assert.assertEquals(ec2.getTeamMessages().get(0).sender, "Foo");
Assert.assertEquals(ec2.getTeamMessages().get(0).recipient, "Bar");
Assert.assertNull(ec2.getTeamMessages().get(1).message);
Assertions.assertEquals(ec2.getTeamMessages().get(0).message[0], 0);
Assertions.assertEquals(ec2.getTeamMessages().get(0).message[10], 10);
Assertions.assertEquals(ec2.getTeamMessages().get(0).sender, "Foo");
Assertions.assertEquals(ec2.getTeamMessages().get(0).recipient, "Bar");
Assertions.assertNull(ec2.getTeamMessages().get(1).message);
}

@Test
Expand All @@ -141,8 +141,8 @@ public void withProperties() throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
ExecCommands ec2 = (ExecCommands) rbs.deserialize(in);

Assert.assertEquals(ec2.getDebugProperties().get(0).getKey(), "UTF8 Native characters");
Assert.assertEquals(ec2.getDebugProperties().get(0).getValue(), "Příliš žluťoučký kůň úpěl ďábelské ódy.");
Assertions.assertEquals(ec2.getDebugProperties().get(0).getKey(), "UTF8 Native characters");
Assertions.assertEquals(ec2.getDebugProperties().get(0).getValue(), "Příliš žluťoučký kůň úpěl ďábelské ódy.");
}

// @Test
Expand All @@ -169,7 +169,7 @@ public void speed() throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
ExecCommands ec2 = (ExecCommands) rbs.deserialize(in);

Assert.assertEquals(ec2.getGunColor(), i);
Assertions.assertEquals(ec2.getGunColor(), i);
}
}

Expand All @@ -192,7 +192,7 @@ public void speed2() {
ec.setGunColor(i);
ExecCommands ec2 = (ExecCommands) ObjectCloner.deepCopy(ec);

Assert.assertEquals(ec2.getGunColor(), i);
Assertions.assertEquals(ec2.getGunColor(), i);
}
}

Expand Down Expand Up @@ -258,10 +258,10 @@ public void paint(Graphics g) {
f.setVisible(false);
}

Assert.assertNull("Exception occured: " + exception, exception);
Assertions.assertNull(exception, "Exception occured: " + exception);
}

public static void assertNear(double v1, double v2) {
org.junit.Assert.assertEquals(v1, v2, Utils.NEAR_DELTA);
Assertions.assertEquals(v1, v2, Utils.NEAR_DELTA);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
package net.sf.robocode.version;


import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.File;

Expand All @@ -26,117 +26,117 @@ public class VersionTest {

@Test
public void same() {
Assert.assertEquals(0, Version.compare("1.1.3", "1.1.3"));
Assertions.assertEquals(0, Version.compare("1.1.3", "1.1.3"));
}

@Test
public void equalVersion() {
Assert.assertEquals(0, Version.compare("1.1", "1.1.0.0"));
Assertions.assertEquals(0, Version.compare("1.1", "1.1.0.0"));
}

@Test
public void equalAlphas() {
Assert.assertEquals(0, Version.compare(" 1.2 Alpha", "1.2.0.0alpha1 "));
Assertions.assertEquals(0, Version.compare(" 1.2 Alpha", "1.2.0.0alpha1 "));
}

@Test
public void equalBetas() {
Assert.assertEquals(0, Version.compare("4.2.1Beta2 ", " 4.2.1.0 beta 2"));
Assertions.assertEquals(0, Version.compare("4.2.1Beta2 ", " 4.2.1.0 beta 2"));
}

@Test
public void greater() {
Assert.assertTrue(Version.compare("1.1.4", "1.1.3") > 0);
Assertions.assertTrue(Version.compare("1.1.4", "1.1.3") > 0);
}

@Test
public void greaterShort() {
Assert.assertTrue(Version.compare("1.4", "1.1.3") > 0);
Assertions.assertTrue(Version.compare("1.4", "1.1.3") > 0);
}

@Test
public void greaterShort2() {
Assert.assertTrue(Version.compare("1.4", "1.1") > 0);
Assertions.assertTrue(Version.compare("1.4", "1.1") > 0);
}

@Test
public void greaterShortBeta() {
Assert.assertTrue(Version.compare("1.4 Beta", "1.1.3") > 0);
Assertions.assertTrue(Version.compare("1.4 Beta", "1.1.3") > 0);
}

@Test
public void greaterShortBeta3() {
Assert.assertTrue(Version.compare("1.4 Beta", "1.1") > 0);
Assertions.assertTrue(Version.compare("1.4 Beta", "1.1") > 0);
}

@Test
public void greaterShortBeta2() {
Assert.assertTrue(Version.compare("1.4", "1.1.3") > 0);
Assertions.assertTrue(Version.compare("1.4", "1.1.3") > 0);
}

@Test
public void greaterLong() {
Assert.assertTrue(Version.compare("1.4.1", "1.1") > 0);
Assertions.assertTrue(Version.compare("1.4.1", "1.1") > 0);
}

@Test
public void smaller() {
Assert.assertTrue(Version.compare("1.1.2", "1.1.3") < 0);
Assertions.assertTrue(Version.compare("1.1.2", "1.1.3") < 0);
}

@Test
public void greaterToo() {
Assert.assertTrue(Version.compare("4.1.2", "1.1.3") > 0);
Assertions.assertTrue(Version.compare("4.1.2", "1.1.3") > 0);
}

@Test
public void greaterThanBeta() {
Assert.assertTrue(Version.compare("1.1.3", "1.1.3 Beta") > 0);
Assertions.assertTrue(Version.compare("1.1.3", "1.1.3 Beta") > 0);
}

@Test
public void smallerThanBeta() {
Assert.assertTrue(Version.compare("1.1.2", "1.1.3 Beta") < 0);
Assertions.assertTrue(Version.compare("1.1.2", "1.1.3 Beta") < 0);
}

@Test
public void smallerThanAlpha() {
Assert.assertTrue(Version.compare("1.1.3 Alpha", "1.1.3 Beta") < 0);
Assertions.assertTrue(Version.compare("1.1.3 Alpha", "1.1.3 Beta") < 0);
}

@Test
public void compareBetas() {
// we can't name versions Beta 2
Assert.assertTrue(Version.compare("1.1.3 Beta", "1.1.3 Beta 2") < 0);
Assertions.assertTrue(Version.compare("1.1.3 Beta", "1.1.3 Beta 2") < 0);
}

@Test
public void compareBetas2() {
// we can't name versions Beta 2
Assert.assertTrue(Version.compare("1.1.3 Beta 2 ", "1.1.3 Beta 3") < 0);
Assertions.assertTrue(Version.compare("1.1.3 Beta 2 ", "1.1.3 Beta 3") < 0);
}

@Test
public void compareBetas3() {
// we can't name versions Beta 2
Assert.assertTrue(Version.compare("1.1.3 Beta2 ", "1.1.3 Beta 3") < 0);
Assertions.assertTrue(Version.compare("1.1.3 Beta2 ", "1.1.3 Beta 3") < 0);
}

@Test
public void compareBetas4() {
// we can't name versions Beta 2
Assert.assertTrue(Version.compare("1.1.3Beta2", "1.1.3 Beta 3") < 0);
Assertions.assertTrue(Version.compare("1.1.3Beta2", "1.1.3 Beta 3") < 0);
}

@Test
public void compareBetasShort() {
// we can't name versions Beta 2
Assert.assertTrue(Version.compare("1.7 Beta", "1.1") > 0);
Assertions.assertTrue(Version.compare("1.7 Beta", "1.1") > 0);
}

@Test
public void compareBetasShort2() {
// we can't name versions Beta 2
Assert.assertTrue(Version.compare("1.7 Beta", "1.8") < 0);
Assertions.assertTrue(Version.compare("1.7 Beta", "1.8") < 0);
}
}
3 changes: 2 additions & 1 deletion robocode.host/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ dependencies {
implementation(project(":robocode.core"))
implementation(libs.picocontainer)

testImplementation(testLibs.junit)
testImplementation(testLibs.junit.jupiter)
testRuntimeOnly(testLibs.junit.platform.launcher)
}

description = "Robocode Host"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
package net.sf.robocode.host.jarjar;


import org.junit.Test;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;

import java.io.File;
import java.net.URL;
Expand Down Expand Up @@ -50,12 +50,12 @@ public void run() throws IOException {

int len = isr.read(c);

Assert.assertEquals(len, 4);
Assert.assertEquals('T', c[0]);
Assert.assertEquals('e', c[1]);
Assert.assertEquals('s', c[2]);
Assert.assertEquals('t', c[3]);
Assert.assertFalse(isr.ready());
Assertions.assertEquals(len, 4);
Assertions.assertEquals('T', c[0]);
Assertions.assertEquals('e', c[1]);
Assertions.assertEquals('s', c[2]);
Assertions.assertEquals('t', c[3]);
Assertions.assertFalse(isr.ready());
isr.close();
inputStream.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
import net.sf.robocode.host.io.RobotFileSystemManager;
import net.sf.robocode.repository.IRobotItem;
import net.sf.robocode.security.HiddenAccess;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import robocode.control.RobotSpecification;

import java.io.File;
Expand All @@ -32,13 +31,15 @@
*/
public class ThreadManagerTest {

@Rule
public TemporaryFolder folder = new TemporaryFolder();
@TempDir
File folder;

// The thread would keep the whole robot in memory, and Java 24+ has no SecurityManager to remove it
@Test
public void aThreadIsNotKeptAfterItOpensAFile() throws IOException {
File root = folder.newFolder("data");
File root = new File(folder, "data");

Assertions.assertTrue(root.mkdir());
IHostedThread robot = createAdvancedRobot(root);
ThreadManager manager = new ThreadManager();

Expand All @@ -48,7 +49,7 @@ public void aThreadIsNotKeptAfterItOpensAFile() throws IOException {

stream.close();

Assert.assertFalse(manager.checkRobotFileStream());
Assertions.assertFalse(manager.checkRobotFileStream());
}

private static IHostedThread createAdvancedRobot(final File root) {
Expand Down
3 changes: 2 additions & 1 deletion robocode.roborumble/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ dependencies {
runtimeOnly(project(":robocode.core"))
runtimeOnly(project(":robocode.battle"))
runtimeOnly(libs.codesize)
testImplementation(testLibs.junit)
testImplementation(testLibs.junit.jupiter)
testRuntimeOnly(testLibs.junit.platform.launcher)
}

description = "Roborumble Client"
Expand Down
Loading
Loading