Merge pull request #504 from EngineHub/feature/junit-5

Switch to JUnit 5
This commit is contained in:
Kenzie Togami 2019-07-16 04:21:06 -07:00 committed by GitHub
commit 6e90c59136
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 131 additions and 122 deletions

View File

@ -6,9 +6,11 @@ import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.plugins.quality.CheckstyleExtension import org.gradle.api.plugins.quality.CheckstyleExtension
import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.javadoc.Javadoc import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.api.tasks.testing.Test
import org.gradle.external.javadoc.CoreJavadocOptions import org.gradle.external.javadoc.CoreJavadocOptions
import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.get import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getByName import org.gradle.kotlin.dsl.getByName
import org.gradle.kotlin.dsl.named import org.gradle.kotlin.dsl.named
@ -38,6 +40,15 @@ fun Project.applyPlatformAndCoreConfiguration() {
toolVersion = "7.6.1" toolVersion = "7.6.1"
} }
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
dependencies {
"testImplementation"("org.junit.jupiter:junit-jupiter-api:${Versions.JUNIT}")
"testRuntime"("org.junit.jupiter:junit-jupiter-engine:${Versions.JUNIT}")
}
// Java 8 turns on doclint which we fail // Java 8 turns on doclint which we fail
tasks.withType<Javadoc>().configureEach { tasks.withType<Javadoc>().configureEach {
(options as CoreJavadocOptions).addStringOption("Xdoclint:none", "-quiet") (options as CoreJavadocOptions).addStringOption("Xdoclint:none", "-quiet")

View File

@ -3,4 +3,5 @@ object Versions {
const val TEXT_EXTRAS = "3.0.2" const val TEXT_EXTRAS = "3.0.2"
const val PISTON = "0.4.2" const val PISTON = "0.4.2"
const val AUTO_VALUE = "1.6.5" const val AUTO_VALUE = "1.6.5"
const val JUNIT = "5.5.0"
} }

View File

@ -22,7 +22,9 @@ configurations.all {
dependencies { dependencies {
"api"(project(":worldedit-core")) "api"(project(":worldedit-core"))
"api"(project(":worldedit-libs:bukkit")) "api"(project(":worldedit-libs:bukkit"))
"api"("org.bukkit:bukkit:1.13.2-R0.1-SNAPSHOT") "api"("org.bukkit:bukkit:1.13.2-R0.1-SNAPSHOT") {
exclude("junit", "junit")
}
"compileOnly"("com.destroystokyo.paper:paper-api:1.13.2-R0.1-SNAPSHOT") "compileOnly"("com.destroystokyo.paper:paper-api:1.13.2-R0.1-SNAPSHOT")
"implementation"("io.papermc:paperlib:1.0.2") "implementation"("io.papermc:paperlib:1.0.2")
"compileOnly"("com.sk89q:dummypermscompat:1.10") "compileOnly"("com.sk89q:dummypermscompat:1.10")

View File

@ -19,20 +19,20 @@
package com.sk89q.wepif; package com.sk89q.wepif;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class DinnerPermsResolverTest { public class DinnerPermsResolverTest {
private DinnerPermsResolver resolver; private DinnerPermsResolver resolver;
@Before @BeforeEach
public void setUp() { public void setUp() {
Server server = mock(Server.class); Server server = mock(Server.class);
when(server.getPluginManager()).thenReturn(mock(PluginManager.class)); when(server.getPluginManager()).thenReturn(mock(PluginManager.class));

View File

@ -20,15 +20,16 @@
package com.sk89q.worldedit.bukkit; package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.TreeGenerator;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class BukkitWorldTest { public class BukkitWorldTest {
@Test @Test
public void testTreeTypeMapping() { public void testTreeTypeMapping() {
for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) { for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {
Assert.assertNotNull("No mapping for: " + type, BukkitWorld.toBukkitTreeType(type)); assertNotNull(BukkitWorld.toBukkitTreeType(type), "No mapping for: " + type);
} }
} }

View File

@ -20,7 +20,6 @@ dependencies {
"compile"("com.google.guava:guava:21.0") "compile"("com.google.guava:guava:21.0")
"compile"("com.google.code.findbugs:jsr305:1.3.9") "compile"("com.google.code.findbugs:jsr305:1.3.9")
"compile"("com.google.code.gson:gson:2.8.0") "compile"("com.google.code.gson:gson:2.8.0")
"compile"("com.googlecode.json-simple:json-simple:1.1.1")
"compile"("org.slf4j:slf4j-api:1.7.26") "compile"("org.slf4j:slf4j-api:1.7.26")
"compileOnly"(project(":worldedit-libs:core:ap")) "compileOnly"(project(":worldedit-libs:core:ap"))

View File

@ -19,8 +19,9 @@
package com.sk89q.worldedit.util.paste; package com.sk89q.worldedit.util.paste;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.sk89q.worldedit.util.net.HttpRequest; import com.sk89q.worldedit.util.net.HttpRequest;
import org.json.simple.JSONValue;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
@ -33,6 +34,8 @@ public class EngineHubPaste implements Paster {
private static final Pattern URL_PATTERN = Pattern.compile("https?://.+$"); private static final Pattern URL_PATTERN = Pattern.compile("https?://.+$");
private static final Gson GSON = new Gson();
@Override @Override
public Callable<URL> paste(String content) { public Callable<URL> paste(String content) {
return new PasteTask(content); return new PasteTask(content);
@ -59,10 +62,10 @@ public class EngineHubPaste implements Paster {
.returnContent() .returnContent()
.asString("UTF-8").trim(); .asString("UTF-8").trim();
Object object = JSONValue.parse(result); Map<Object, Object> object = GSON.fromJson(result, new TypeToken<Map<Object, Object>>() {
if (object instanceof Map) { }.getType());
@SuppressWarnings("unchecked") if (object != null) {
String urlString = String.valueOf(((Map<Object, Object>) object).get("url")); String urlString = String.valueOf(object.get("url"));
Matcher m = URL_PATTERN.matcher(urlString); Matcher m = URL_PATTERN.matcher(urlString);
if (m.matches()) { if (m.matches()) {

View File

@ -19,19 +19,20 @@
package com.sk89q.minecraft.util.commands; package com.sk89q.minecraft.util.commands;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import static org.junit.Assert.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class CommandContextTest { public class CommandContextTest {
@ -39,7 +40,7 @@ public class CommandContextTest {
private static final String firstCmdString = "herpderp -opw testers \"mani world\" 'another thing' because something"; private static final String firstCmdString = "herpderp -opw testers \"mani world\" 'another thing' because something";
CommandContext firstCommand; CommandContext firstCommand;
@Before @BeforeEach
public void setUpTest() { public void setUpTest() {
try { try {
firstCommand = new CommandContext(firstCmdString, new HashSet<>(Arrays.asList('o', 'w'))); firstCommand = new CommandContext(firstCmdString, new HashSet<>(Arrays.asList('o', 'w')));
@ -49,10 +50,12 @@ public class CommandContextTest {
} }
} }
@Test(expected = CommandException.class) @Test
public void testInvalidFlags() throws CommandException { public void testInvalidFlags() {
final String failingCommand = "herpderp -opw testers"; final String failingCommand = "herpderp -opw testers";
new CommandContext(failingCommand, new HashSet<>(Arrays.asList('o', 'w'))); assertThrows(CommandException.class, () -> {
new CommandContext(failingCommand, new HashSet<>(Arrays.asList('o', 'w')));
});
} }
@Test @Test

View File

@ -19,33 +19,33 @@
package com.sk89q.worldedit.extent.transform; package com.sk89q.worldedit.extent.transform;
import static org.junit.Assert.assertEquals;
import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@Ignore("A platform is currently required to get properties, preventing this test.") import static org.junit.jupiter.api.Assertions.assertEquals;
@Disabled("A platform is currently required to get properties, preventing this test.")
public class BlockTransformExtentTest { public class BlockTransformExtentTest {
private static final Transform ROTATE_90 = new AffineTransform().rotateY(-90); private static final Transform ROTATE_90 = new AffineTransform().rotateY(-90);
private static final Transform ROTATE_NEG_90 = new AffineTransform().rotateY(90); private static final Transform ROTATE_NEG_90 = new AffineTransform().rotateY(90);
private final Set<BlockType> ignored = new HashSet<>(); private final Set<BlockType> ignored = new HashSet<>();
@Before @BeforeEach
public void setUp() throws Exception { public void setUp() {
BlockType.REGISTRY.register("worldedit:test", new BlockType("worldedit:test")); BlockType.REGISTRY.register("worldedit:test", new BlockType("worldedit:test"));
} }
@Test @Test
public void testTransform() throws Exception { public void testTransform() {
for (BlockType type : BlockType.REGISTRY.values()) { for (BlockType type : BlockType.REGISTRY.values()) {
if (ignored.contains(type)) { if (ignored.contains(type)) {
continue; continue;

View File

@ -21,10 +21,10 @@ package com.sk89q.worldedit.internal.command;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.internal.util.Substring; import com.sk89q.worldedit.internal.util.Substring;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static com.sk89q.worldedit.internal.command.CommandArgParser.spaceSplit; import static com.sk89q.worldedit.internal.command.CommandArgParser.spaceSplit;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class CommandArgParserTest { public class CommandArgParserTest {
@Test @Test

View File

@ -19,16 +19,6 @@
package com.sk89q.worldedit.internal.expression; package com.sk89q.worldedit.internal.expression;
import static java.lang.Math.atan2;
import static java.lang.Math.sin;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extension.platform.Platform;
@ -36,9 +26,20 @@ import com.sk89q.worldedit.internal.expression.lexer.LexerException;
import com.sk89q.worldedit.internal.expression.parser.ParserException; import com.sk89q.worldedit.internal.expression.parser.ParserException;
import com.sk89q.worldedit.internal.expression.runtime.EvaluationException; import com.sk89q.worldedit.internal.expression.runtime.EvaluationException;
import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment; import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment;
import com.sk89q.worldedit.internal.expression.runtime.ExpressionTimeoutException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static java.lang.Math.atan2;
import static java.lang.Math.sin;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ExpressionTest { public class ExpressionTest {
@Before @BeforeEach
public void setup() { public void setup() {
Platform mockPlat = Mockito.mock(Platform.class); Platform mockPlat = Mockito.mock(Platform.class);
Mockito.when(mockPlat.getConfiguration()).thenReturn(new LocalConfiguration() { Mockito.when(mockPlat.getConfiguration()).thenReturn(new LocalConfiguration() {
@ -68,56 +69,46 @@ public class ExpressionTest {
} }
@Test @Test
public void testErrors() throws ExpressionException { public void testErrors() {
// test lexer errors assertAll(
try { // test lexer errors
compile("#"); () -> {
fail("Error expected"); LexerException e = assertThrows(LexerException.class,
} catch (LexerException e) { () -> compile("#"));
assertEquals("Error position", 0, e.getPosition()); assertEquals(0, e.getPosition(), "Error position");
} },
// test parser errors
// test parser errors () -> {
try { ParserException e = assertThrows(ParserException.class,
compile("x"); () -> compile("x"));
fail("Error expected"); assertEquals(0, e.getPosition(), "Error position");
} catch (ParserException e) { },
assertEquals("Error position", 0, e.getPosition()); () -> {
} ParserException e = assertThrows(ParserException.class,
try { () -> compile("x()"));
compile("x()"); assertEquals(0, e.getPosition(), "Error position");
fail("Error expected"); },
} catch (ParserException e) { () -> assertThrows(ParserException.class,
assertEquals("Error position", 0, e.getPosition()); () -> compile("(")),
} () -> assertThrows(ParserException.class,
try { () -> compile("x(")),
compile("("); // test overloader errors
fail("Error expected"); () -> {
} catch (ParserException ignored) {} ParserException e = assertThrows(ParserException.class,
try { () -> compile("atan2(1)"));
compile("x("); assertEquals(0, e.getPosition(), "Error position");
fail("Error expected"); },
} catch (ParserException ignored) {} () -> {
ParserException e = assertThrows(ParserException.class,
// test overloader errors () -> compile("atan2(1, 2, 3)"));
try { assertEquals(0, e.getPosition(), "Error position");
compile("atan2(1)"); },
fail("Error expected"); () -> {
} catch (ParserException e) { ParserException e = assertThrows(ParserException.class,
assertEquals("Error position", 0, e.getPosition()); () -> compile("rotate(1, 2, 3)"));
} assertEquals(0, e.getPosition(), "Error position");
try { }
compile("atan2(1, 2, 3)"); );
fail("Error expected");
} catch (ParserException e) {
assertEquals("Error position", 0, e.getPosition());
}
try {
compile("rotate(1, 2, 3)");
fail("Error expected");
} catch (ParserException e) {
assertEquals("Error position", 0, e.getPosition());
}
} }
@Test @Test
@ -181,13 +172,11 @@ public class ExpressionTest {
} }
@Test @Test
public void testTimeout() throws Exception { public void testTimeout() {
try { ExpressionTimeoutException e = assertThrows(ExpressionTimeoutException.class,
simpleEval("for(i=0;i<256;i++){for(j=0;j<256;j++){for(k=0;k<256;k++){for(l=0;l<256;l++){ln(pi)}}}}"); () -> simpleEval("for(i=0;i<256;i++){for(j=0;j<256;j++){for(k=0;k<256;k++){for(l=0;l<256;l++){ln(pi)}}}}"),
fail("Loop was not stopped."); "Loop was not stopped.");
} catch (EvaluationException e) { assertTrue(e.getMessage().contains("Calculations exceeded time limit"));
assertTrue(e.getMessage().contains("Calculations exceeded time limit"));
}
} }
private double simpleEval(String expressionString) throws ExpressionException { private double simpleEval(String expressionString) throws ExpressionException {

View File

@ -19,12 +19,12 @@
package com.sk89q.worldedit.util; package com.sk89q.worldedit.util;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
/** /**
* Tests {@link Location}. * Tests {@link Location}.

View File

@ -19,14 +19,14 @@
package com.sk89q.worldedit.util.eventbus; package com.sk89q.worldedit.util.eventbus;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class EventBusTest { public class EventBusTest {