Update to JUnit 5

Also display test results within the Gradle build
This commit is contained in:
SquidDev 2019-03-01 23:48:32 +00:00
parent 62760e371e
commit eaf24a3ceb
9 changed files with 112 additions and 99 deletions

View File

@ -73,7 +73,8 @@
shade 'org.squiddev:Cobalt:0.5.0-SNAPSHOT'
testCompile 'junit:junit:4.11'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.1.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.1.0'
deployerJars "org.apache.maven.wagon:wagon-ssh:3.0.0"
}
@ -286,6 +287,13 @@ task compressJson(dependsOn: extractAnnotationsJar) {
}
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint"

View File

@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip

View File

@ -8,12 +8,12 @@
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.core.apis.ObjectWrapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
public class BinaryReadableHandleTest
{

View File

@ -8,13 +8,13 @@
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.core.apis.ObjectWrapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.BufferedReader;
import java.io.CharArrayReader;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class EncodedReadableHandleTest
{

View File

@ -14,7 +14,7 @@
import dan200.computercraft.core.filesystem.MemoryMount;
import dan200.computercraft.core.terminal.Terminal;
import org.apache.logging.log4j.LogManager;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -63,7 +63,7 @@ public static void run( String program, int shutdownAfter )
{
ComputerCraft.log.debug( "Shutting down due to error" );
computer.shutdown();
Assert.fail( api.message );
Assertions.fail( api.message );
return;
}
@ -95,7 +95,7 @@ public static void run( String program, int shutdownAfter )
}
computer.shutdown();
Assert.fail( builder.toString() );
Assertions.fail( builder.toString() );
}
}
catch( InterruptedException ignored )

View File

@ -6,24 +6,29 @@
package dan200.computercraft.core.computer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static java.time.Duration.ofSeconds;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
public class ComputerTest
{
@Test( timeout = 20_000 )
@Test
public void testTimeout()
{
try
{
ComputerBootstrap.run( "print('Hello') while true do end" );
}
catch( AssertionError e )
{
if( e.getMessage().equals( "test.lua:1: Too long without yielding" ) ) return;
throw e;
}
assertTimeoutPreemptively( ofSeconds( 20 ), () -> {
try
{
ComputerBootstrap.run( "print('Hello') while true do end" );
}
catch( AssertionError e )
{
if( e.getMessage().equals( "test.lua:1: Too long without yielding" ) ) return;
throw e;
}
Assert.fail( "Expected computer to timeout" );
Assertions.fail( "Expected computer to timeout" );
} );
}
}

View File

@ -11,14 +11,14 @@
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.core.apis.ObjectWrapper;
import dan200.computercraft.core.apis.handles.EncodedWritableHandle;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class FileSystemTest
{

View File

@ -8,8 +8,8 @@
import com.google.common.io.ByteStreams;
import dan200.computercraft.api.filesystem.IMount;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.FileOutputStream;
@ -19,14 +19,14 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
@SuppressWarnings( "deprecation" )
public class JarMountTest
{
private static final File ZIP_FILE = new File( "test-files/jar-mount.zip" );
@BeforeClass
@BeforeAll
public static void before() throws IOException
{
if( ZIP_FILE.exists() ) return;
@ -47,16 +47,16 @@ public static void before() throws IOException
public void mountsDir() throws IOException
{
IMount mount = new JarMount( ZIP_FILE, "dir" );
assertTrue( "Root should be directory", mount.isDirectory( "" ) );
assertTrue( "File should exist", mount.exists( "file.lua" ) );
assertTrue( mount.isDirectory( "" ), "Root should be directory" );
assertTrue( mount.exists( "file.lua" ), "File should exist" );
}
@Test
public void mountsFile() throws IOException
{
IMount mount = new JarMount( ZIP_FILE, "dir/file.lua" );
assertTrue( "Root should exist", mount.exists( "" ) );
assertFalse( "Root should be a file", mount.isDirectory( "" ) );
assertTrue( mount.exists( "" ), "Root should exist" );
assertFalse( mount.isDirectory( "" ), "Root should be a file" );
}
@Test
@ -69,7 +69,7 @@ public void opensFileFromFile() throws IOException
contents = ByteStreams.toByteArray( stream );
}
assertEquals( "print('testing')", new String( contents, StandardCharsets.UTF_8 ) );
assertEquals( new String( contents, StandardCharsets.UTF_8 ), "print('testing')" );
}
@Test
@ -82,6 +82,6 @@ public void opensFileFromDir() throws IOException
contents = ByteStreams.toByteArray( stream );
}
assertEquals( "print('testing')", new String( contents, StandardCharsets.UTF_8 ) );
assertEquals( new String( contents, StandardCharsets.UTF_8 ), "print('testing')" );
}
}

View File

@ -23,9 +23,10 @@
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -34,12 +35,11 @@
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
public class NetworkTest
{
@Before
@BeforeEach
public void setup()
{
ComputerCraft.log = LogManager.getLogger();
@ -58,32 +58,32 @@ public void testConnect()
bN = bE.getNode(),
cN = cE.getNode();
assertNotEquals( "A's and B's network must be different", aN.getNetwork(), bN.getNetwork() );
assertNotEquals( "A's and C's network must be different", aN.getNetwork(), cN.getNetwork() );
assertNotEquals( "B's and C's network must be different", bN.getNetwork(), cN.getNetwork() );
assertNotEquals( aN.getNetwork(), bN.getNetwork(), "A's and B's network must be different" );
assertNotEquals( aN.getNetwork(), cN.getNetwork(), "A's and C's network must be different" );
assertNotEquals( bN.getNetwork(), cN.getNetwork(), "B's and C's network must be different" );
assertTrue( "Must be able to add connection", aN.getNetwork().connect( aN, bN ) );
assertFalse( "Cannot add connection twice", aN.getNetwork().connect( aN, bN ) );
assertTrue( aN.getNetwork().connect( aN, bN ), "Must be able to add connection" );
assertFalse( aN.getNetwork().connect( aN, bN ), "Cannot add connection twice" );
assertEquals( "A's and B's network must be equal", aN.getNetwork(), bN.getNetwork() );
assertEquals( "A's network should be A and B", Sets.newHashSet( aN, bN ), nodes( aN.getNetwork() ) );
assertEquals( aN.getNetwork(), bN.getNetwork(), "A's and B's network must be equal" );
assertEquals( Sets.newHashSet( aN, bN ), nodes( aN.getNetwork() ), "A's network should be A and B" );
assertEquals( "A's peripheral set should be A, B", Sets.newHashSet( "a", "b" ), aE.allPeripherals().keySet() );
assertEquals( "B's peripheral set should be A, B", Sets.newHashSet( "a", "b" ), bE.allPeripherals().keySet() );
assertEquals( Sets.newHashSet( "a", "b" ), aE.allPeripherals().keySet(), "A's peripheral set should be A, B" );
assertEquals( Sets.newHashSet( "a", "b" ), bE.allPeripherals().keySet(), "B's peripheral set should be A, B" );
aN.getNetwork().connect( aN, cN );
assertEquals( "A's and B's network must be equal", aN.getNetwork(), bN.getNetwork() );
assertEquals( "A's and C's network must be equal", aN.getNetwork(), cN.getNetwork() );
assertEquals( "A's network should be A, B and C", Sets.newHashSet( aN, bN, cN ), nodes( aN.getNetwork() ) );
assertEquals( aN.getNetwork(), bN.getNetwork(), "A's and B's network must be equal" );
assertEquals( aN.getNetwork(), cN.getNetwork(), "A's and C's network must be equal" );
assertEquals( Sets.newHashSet( aN, bN, cN ), nodes( aN.getNetwork() ), "A's network should be A, B and C" );
assertEquals( "A's neighbour set should be B, C", Sets.newHashSet( bN, cN ), neighbours( aN ) );
assertEquals( "B's neighbour set should be A", Sets.newHashSet( aN ), neighbours( bN ) );
assertEquals( "C's neighbour set should be A", Sets.newHashSet( aN ), neighbours( cN ) );
assertEquals( Sets.newHashSet( bN, cN ), neighbours( aN ), "A's neighbour set should be B, C" );
assertEquals( Sets.newHashSet( aN ), neighbours( bN ), "B's neighbour set should be A" );
assertEquals( Sets.newHashSet( aN ), neighbours( cN ), "C's neighbour set should be A" );
assertEquals( "A's peripheral set should be A, B, C", Sets.newHashSet( "a", "b", "c" ), aE.allPeripherals().keySet() );
assertEquals( "B's peripheral set should be A, B, C", Sets.newHashSet( "a", "b", "c" ), bE.allPeripherals().keySet() );
assertEquals( "C's peripheral set should be A, B, C", Sets.newHashSet( "a", "b", "c" ), cE.allPeripherals().keySet() );
assertEquals( Sets.newHashSet( "a", "b", "c" ), aE.allPeripherals().keySet(), "A's peripheral set should be A, B, C" );
assertEquals( Sets.newHashSet( "a", "b", "c" ), bE.allPeripherals().keySet(), "B's peripheral set should be A, B, C" );
assertEquals( Sets.newHashSet( "a", "b", "c" ), cE.allPeripherals().keySet(), "C's peripheral set should be A, B, C" );
}
@Test
@ -105,13 +105,13 @@ public void testDisconnectNoChange()
aN.getNetwork().disconnect( aN, bN );
assertEquals( "A's and B's network must be equal", aN.getNetwork(), bN.getNetwork() );
assertEquals( "A's and C's network must be equal", aN.getNetwork(), cN.getNetwork() );
assertEquals( "A's network should be A, B and C", Sets.newHashSet( aN, bN, cN ), nodes( aN.getNetwork() ) );
assertEquals( aN.getNetwork(), bN.getNetwork(), "A's and B's network must be equal" );
assertEquals( aN.getNetwork(), cN.getNetwork(), "A's and C's network must be equal" );
assertEquals( Sets.newHashSet( aN, bN, cN ), nodes( aN.getNetwork() ), "A's network should be A, B and C" );
assertEquals( "A's peripheral set should be A, B, C", Sets.newHashSet( "a", "b", "c" ), aE.allPeripherals().keySet() );
assertEquals( "B's peripheral set should be A, B, C", Sets.newHashSet( "a", "b", "c" ), bE.allPeripherals().keySet() );
assertEquals( "C's peripheral set should be A, B, C", Sets.newHashSet( "a", "b", "c" ), cE.allPeripherals().keySet() );
assertEquals( Sets.newHashSet( "a", "b", "c" ), aE.allPeripherals().keySet(), "A's peripheral set should be A, B, C" );
assertEquals( Sets.newHashSet( "a", "b", "c" ), bE.allPeripherals().keySet(), "B's peripheral set should be A, B, C" );
assertEquals( Sets.newHashSet( "a", "b", "c" ), cE.allPeripherals().keySet(), "C's peripheral set should be A, B, C" );
}
@Test
@ -132,14 +132,14 @@ public void testDisconnectLeaf()
aN.getNetwork().disconnect( aN, bN );
assertNotEquals( "A's and B's network must not be equal", aN.getNetwork(), bN.getNetwork() );
assertEquals( "A's and C's network must be equal", aN.getNetwork(), cN.getNetwork() );
assertEquals( "A's network should be A and C", Sets.newHashSet( aN, cN ), nodes( aN.getNetwork() ) );
assertEquals( "B's network should be B", Sets.newHashSet( bN ), nodes( bN.getNetwork() ) );
assertNotEquals( aN.getNetwork(), bN.getNetwork(), "A's and B's network must not be equal" );
assertEquals( aN.getNetwork(), cN.getNetwork(), "A's and C's network must be equal" );
assertEquals( Sets.newHashSet( aN, cN ), nodes( aN.getNetwork() ), "A's network should be A and C" );
assertEquals( Sets.newHashSet( bN ), nodes( bN.getNetwork() ), "B's network should be B" );
assertEquals( "A's peripheral set should be A, C", Sets.newHashSet( "a", "c" ), aE.allPeripherals().keySet() );
assertEquals( "B's peripheral set should be B", Sets.newHashSet( "b" ), bE.allPeripherals().keySet() );
assertEquals( "C's peripheral set should be A, C", Sets.newHashSet( "a", "c" ), cE.allPeripherals().keySet() );
assertEquals( Sets.newHashSet( "a", "c" ), aE.allPeripherals().keySet(), "A's peripheral set should be A, C" );
assertEquals( Sets.newHashSet( "b" ), bE.allPeripherals().keySet(), "B's peripheral set should be B" );
assertEquals( Sets.newHashSet( "a", "c" ), cE.allPeripherals().keySet(), "C's peripheral set should be A, C" );
}
@Test
@ -164,15 +164,15 @@ public void testDisconnectSplit()
aN.getNetwork().disconnect( aN, bN );
assertNotEquals( "A's and B's network must not be equal", aN.getNetwork(), bN.getNetwork() );
assertEquals( "A's and A_'s network must be equal", aN.getNetwork(), aaN.getNetwork() );
assertEquals( "B's and B_'s network must be equal", bN.getNetwork(), bbN.getNetwork() );
assertNotEquals( aN.getNetwork(), bN.getNetwork(), "A's and B's network must not be equal" );
assertEquals( aN.getNetwork(), aaN.getNetwork(), "A's and A_'s network must be equal" );
assertEquals( bN.getNetwork(), bbN.getNetwork(), "B's and B_'s network must be equal" );
assertEquals( "A's network should be A and A_", Sets.newHashSet( aN, aaN ), nodes( aN.getNetwork() ) );
assertEquals( "B's network should be B and B_", Sets.newHashSet( bN, bbN ), nodes( bN.getNetwork() ) );
assertEquals( Sets.newHashSet( aN, aaN ), nodes( aN.getNetwork() ), "A's network should be A and A_" );
assertEquals( Sets.newHashSet( bN, bbN ), nodes( bN.getNetwork() ), "B's network should be B and B_" );
assertEquals( "A's peripheral set should be A and A_", Sets.newHashSet( "a", "a_" ), aE.allPeripherals().keySet() );
assertEquals( "B's peripheral set should be B and B_", Sets.newHashSet( "b", "b_" ), bE.allPeripherals().keySet() );
assertEquals( Sets.newHashSet( "a", "a_" ), aE.allPeripherals().keySet(), "A's peripheral set should be A and A_" );
assertEquals( Sets.newHashSet( "b", "b_" ), bE.allPeripherals().keySet(), "B's peripheral set should be B and B_" );
}
@Test
@ -182,8 +182,8 @@ public void testRemoveSingle()
IWiredNode aN = aE.getNode();
IWiredNetwork network = aN.getNetwork();
assertFalse( "Cannot remove node from an empty network", aN.remove() );
assertEquals( "Networks are same before and after", network, aN.getNetwork() );
assertFalse( aN.remove(), "Cannot remove node from an empty network" );
assertEquals( network, aN.getNetwork(), "Networks are same before and after" );
}
@Test
@ -202,18 +202,18 @@ public void testRemoveLeaf()
aN.getNetwork().connect( aN, bN );
aN.getNetwork().connect( aN, cN );
assertTrue( "Must be able to remove node", aN.getNetwork().remove( bN ) );
assertFalse( "Cannot remove a second time", aN.getNetwork().remove( bN ) );
assertTrue( aN.getNetwork().remove( bN ), "Must be able to remove node" );
assertFalse( aN.getNetwork().remove( bN ), "Cannot remove a second time" );
assertNotEquals( "A's and B's network must not be equal", aN.getNetwork(), bN.getNetwork() );
assertEquals( "A's and C's network must be equal", aN.getNetwork(), cN.getNetwork() );
assertNotEquals( aN.getNetwork(), bN.getNetwork(), "A's and B's network must not be equal" );
assertEquals( aN.getNetwork(), cN.getNetwork(), "A's and C's network must be equal" );
assertEquals( "A's network should be A and C", Sets.newHashSet( aN, cN ), nodes( aN.getNetwork() ) );
assertEquals( "B's network should be B", Sets.newHashSet( bN ), nodes( bN.getNetwork() ) );
assertEquals( Sets.newHashSet( aN, cN ), nodes( aN.getNetwork() ), "A's network should be A and C" );
assertEquals( Sets.newHashSet( bN ), nodes( bN.getNetwork() ), "B's network should be B" );
assertEquals( "A's peripheral set should be A, C", Sets.newHashSet( "a", "c" ), aE.allPeripherals().keySet() );
assertEquals( "B's peripheral set should be empty", Sets.newHashSet(), bE.allPeripherals().keySet() );
assertEquals( "C's peripheral set should be A, C", Sets.newHashSet( "a", "c" ), cE.allPeripherals().keySet() );
assertEquals( Sets.newHashSet( "a", "c" ), aE.allPeripherals().keySet(), "A's peripheral set should be A, C" );
assertEquals( Sets.newHashSet(), bE.allPeripherals().keySet(), "B's peripheral set should be empty" );
assertEquals( Sets.newHashSet( "a", "c" ), cE.allPeripherals().keySet(), "C's peripheral set should be A, C" );
}
@Test
@ -241,21 +241,21 @@ public void testRemoveSplit()
cN.getNetwork().remove( cN );
assertNotEquals( "A's and B's network must not be equal", aN.getNetwork(), bN.getNetwork() );
assertEquals( "A's and A_'s network must be equal", aN.getNetwork(), aaN.getNetwork() );
assertEquals( "B's and B_'s network must be equal", bN.getNetwork(), bbN.getNetwork() );
assertNotEquals( aN.getNetwork(), bN.getNetwork(), "A's and B's network must not be equal" );
assertEquals( aN.getNetwork(), aaN.getNetwork(), "A's and A_'s network must be equal" );
assertEquals( bN.getNetwork(), bbN.getNetwork(), "B's and B_'s network must be equal" );
assertEquals( "A's network should be A and A_", Sets.newHashSet( aN, aaN ), nodes( aN.getNetwork() ) );
assertEquals( "B's network should be B and B_", Sets.newHashSet( bN, bbN ), nodes( bN.getNetwork() ) );
assertEquals( "C's network should be C", Sets.newHashSet( cN ), nodes( cN.getNetwork() ) );
assertEquals( Sets.newHashSet( aN, aaN ), nodes( aN.getNetwork() ), "A's network should be A and A_" );
assertEquals( Sets.newHashSet( bN, bbN ), nodes( bN.getNetwork() ), "B's network should be B and B_" );
assertEquals( Sets.newHashSet( cN ), nodes( cN.getNetwork() ), "C's network should be C" );
assertEquals( "A's peripheral set should be A and A_", Sets.newHashSet( "a", "a_" ), aE.allPeripherals().keySet() );
assertEquals( "B's peripheral set should be B and B_", Sets.newHashSet( "b", "b_" ), bE.allPeripherals().keySet() );
assertEquals( "C's peripheral set should be empty", Sets.newHashSet(), cE.allPeripherals().keySet() );
assertEquals( Sets.newHashSet( "a", "a_" ), aE.allPeripherals().keySet(), "A's peripheral set should be A and A_" );
assertEquals( Sets.newHashSet( "b", "b_" ), bE.allPeripherals().keySet(), "B's peripheral set should be B and B_" );
assertEquals( Sets.newHashSet(), cE.allPeripherals().keySet(), "C's peripheral set should be empty" );
}
@Test
@Ignore( "Takes a long time to run, mostly for stress testing" )
@Disabled( "Takes a long time to run, mostly for stress testing" )
public void testLarge()
{
final int BRUTE_SIZE = 16;