diff --git a/paper-api/README.md b/paper-api/README.md index 2f8abbb9d..c97e2e5d7 100644 --- a/paper-api/README.md +++ b/paper-api/README.md @@ -88,7 +88,7 @@ Code Requirements * [`@ApiStatus.Experimental`](https://javadoc.io/doc/org.jetbrains/annotations-java5/23.0.0/org/jetbrains/annotations/ApiStatus.Experimental.html) for API that is subject to change * [`@ApiStatus.Internal`](https://javadoc.io/doc/org.jetbrains/annotations-java5/23.0.0/org/jetbrains/annotations/ApiStatus.Internal.html) for API that is intended only for internal use in the Bukkit project and will not adhere to Bukkit's API contract -Bukkit/CraftBukkit employs [JUnit 4](https://www.vogella.com/tutorials/JUnit4/article.html) for testing. Pull Requests(PR) should attempt to integrate within that framework as appropriate. +Bukkit/CraftBukkit employs [JUnit 5](https://www.vogella.com/tutorials/JUnit/article.html) for testing. Pull Requests(PR) should attempt to integrate within that framework as appropriate. Bukkit is a large project and what seems simple to a PR author at the time of writing may easily be overlooked by other authors and updates. Including unit tests with your PR will help to ensure the PR can be easily maintained over time and encourage the Spigot team to pull the PR. diff --git a/paper-api/pom.xml b/paper-api/pom.xml index 1c911797a..771732401 100644 --- a/paper-api/pom.xml +++ b/paper-api/pom.xml @@ -86,15 +86,15 @@ - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter + 5.10.0 test org.hamcrest - hamcrest-library - 1.3 + hamcrest + 2.2 test diff --git a/paper-api/src/test/java/org/bukkit/AnnotationTest.java b/paper-api/src/test/java/org/bukkit/AnnotationTest.java index 4ac3dd977..64e7aef62 100644 --- a/paper-api/src/test/java/org/bukkit/AnnotationTest.java +++ b/paper-api/src/test/java/org/bukkit/AnnotationTest.java @@ -1,5 +1,6 @@ package org.bukkit; +import static org.junit.jupiter.api.Assertions.*; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -13,8 +14,7 @@ import java.util.List; import java.util.Map; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.objectweb.asm.ClassReader; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; @@ -49,7 +49,7 @@ public class AnnotationTest { File file = new File(loc.toURI()); // Running from jar is not supported yet - Assert.assertTrue("code must be in a directory", file.isDirectory()); + assertTrue(file.isDirectory(), "code must be in a directory"); final HashMap foundClasses = new HashMap<>(); collectClasses(file, foundClasses); @@ -97,7 +97,7 @@ public class AnnotationTest { System.out.println(message); } - Assert.fail("There " + errors.size() + " are missing annotation(s)"); + fail("There " + errors.size() + " are missing annotation(s)"); } private static void collectClasses(@NotNull File from, @NotNull Map to) throws IOException { diff --git a/paper-api/src/test/java/org/bukkit/ArtTest.java b/paper-api/src/test/java/org/bukkit/ArtTest.java index 2e9249a6d..102f4705f 100644 --- a/paper-api/src/test/java/org/bukkit/ArtTest.java +++ b/paper-api/src/test/java/org/bukkit/ArtTest.java @@ -1,14 +1,15 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class ArtTest { - @Test(expected = IllegalArgumentException.class) + @Test public void getByNullName() { - Art.getByName(null); + assertThrows(IllegalArgumentException.class, () -> Art.getByName(null)); } @Test diff --git a/paper-api/src/test/java/org/bukkit/BukkitMirrorTest.java b/paper-api/src/test/java/org/bukkit/BukkitMirrorTest.java index 2dfada660..89ca06ebe 100644 --- a/paper-api/src/test/java/org/bukkit/BukkitMirrorTest.java +++ b/paper-api/src/test/java/org/bukkit/BukkitMirrorTest.java @@ -1,72 +1,59 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import com.google.common.base.Function; -import com.google.common.collect.Lists; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.Arrays; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class BukkitMirrorTest { - @Parameters(name = "{index}: {1}") - public static List data() { - return Lists.transform(Arrays.asList(Server.class.getDeclaredMethods()), new Function() { - @Override - public Object[] apply(Method input) { - return new Object[] { - input, - input.toGenericString().substring("public abstract ".length()).replace("(", "{").replace(")", "}") - }; - } - }); + public static Stream data() { + return Stream.of(Server.class.getDeclaredMethods()) + .map(method -> { + try { + return Arguments.of( + method, + method.toGenericString().substring("public abstract ".length()).replace("(", "{").replace(")", "}"), + Bukkit.class.getDeclaredMethod(method.getName(), method.getParameterTypes()) + ); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + }); } - @Parameter(0) - public Method server; - - @Parameter(1) - public String name; - - private Method bukkit; - - @Before - public void makeBukkit() throws Throwable { - bukkit = Bukkit.class.getDeclaredMethod(server.getName(), server.getParameterTypes()); - } - - @Test - public void isStatic() throws Throwable { + @ParameterizedTest + @MethodSource("data") + public void isStatic(Method server, String name, Method bukkit) throws Throwable { assertThat(Modifier.isStatic(bukkit.getModifiers()), is(true)); } - @Test - public void isDeprecated() throws Throwable { + @ParameterizedTest + @MethodSource("data") + public void isDeprecated(Method server, String name, Method bukkit) throws Throwable { assertThat(bukkit.isAnnotationPresent(Deprecated.class), is(server.isAnnotationPresent(Deprecated.class))); } - @Test - public void returnType() throws Throwable { + @ParameterizedTest + @MethodSource("data") + public void returnType(Method server, String name, Method bukkit) throws Throwable { assertThat(bukkit.getReturnType(), is((Object) server.getReturnType())); // assertThat(bukkit.getGenericReturnType(), is(server.getGenericReturnType())); // too strict on type generics } - @Test - public void parameterTypes() throws Throwable { + @ParameterizedTest + @MethodSource("data") + public void parameterTypes(Method server, String name, Method bukkit) throws Throwable { // assertThat(bukkit.getGenericParameterTypes(), is(server.getGenericParameterTypes())); // too strict on type generics } - @Test - public void declaredException() throws Throwable { + @ParameterizedTest + @MethodSource("data") + public void declaredException(Method server, String name, Method bukkit) throws Throwable { assertThat(bukkit.getGenericExceptionTypes(), is(server.getGenericExceptionTypes())); } } diff --git a/paper-api/src/test/java/org/bukkit/ChatColorTest.java b/paper-api/src/test/java/org/bukkit/ChatColorTest.java index fc4e80853..11c0f8689 100644 --- a/paper-api/src/test/java/org/bukkit/ChatColorTest.java +++ b/paper-api/src/test/java/org/bukkit/ChatColorTest.java @@ -1,8 +1,9 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class ChatColorTest { @@ -13,14 +14,14 @@ public class ChatColorTest { } } - @Test(expected = IllegalArgumentException.class) + @Test public void getByStringWithNull() { - ChatColor.getByChar((String) null); + assertThrows(IllegalArgumentException.class, () -> ChatColor.getByChar((String) null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void getByStringWithEmpty() { - ChatColor.getByChar(""); + assertThrows(IllegalArgumentException.class, () -> ChatColor.getByChar("")); } @Test diff --git a/paper-api/src/test/java/org/bukkit/ChatPaginatorTest.java b/paper-api/src/test/java/org/bukkit/ChatPaginatorTest.java index b0384b12e..2d7c54593 100644 --- a/paper-api/src/test/java/org/bukkit/ChatPaginatorTest.java +++ b/paper-api/src/test/java/org/bukkit/ChatPaginatorTest.java @@ -1,9 +1,9 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; import org.bukkit.util.ChatPaginator; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ChatPaginatorTest { @Test diff --git a/paper-api/src/test/java/org/bukkit/CoalTypeTest.java b/paper-api/src/test/java/org/bukkit/CoalTypeTest.java index b90f10c4e..9373bfd2b 100644 --- a/paper-api/src/test/java/org/bukkit/CoalTypeTest.java +++ b/paper-api/src/test/java/org/bukkit/CoalTypeTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CoalTypeTest { @Test diff --git a/paper-api/src/test/java/org/bukkit/ColorTest.java b/paper-api/src/test/java/org/bukkit/ColorTest.java index 1f722fb24..f29fd7bc6 100644 --- a/paper-api/src/test/java/org/bukkit/ColorTest.java +++ b/paper-api/src/test/java/org/bukkit/ColorTest.java @@ -1,9 +1,10 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.configuration.file.YamlConfiguration; -import org.junit.Test; +import org.junit.jupiter.api.Test; @SuppressWarnings("javadoc") public class ColorTest { @@ -58,7 +59,7 @@ public class ColorTest { YamlConfiguration deserialized = new YamlConfiguration(); deserialized.loadFromString(serialized); - assertThat(testColor.name + " on " + serialized, base, is(deserialized.getColor("color"))); + assertThat(base, is(deserialized.getColor("color")), testColor.name + " on " + serialized); } } @@ -73,14 +74,14 @@ public class ColorTest { Color fromRGBs = Color.fromRGB(testColor.r, testColor.g, testColor.b); Color fromBGRs = Color.fromBGR(testColor.b, testColor.g, testColor.r); - assertThat(testColor.name, fromARGB, is(fromARGB)); - assertThat(testColor.name, fromARGBs, is(fromARGBs)); - assertThat(testColor.name, fromRGB, is(fromRGBs)); - assertThat(testColor.name, fromRGB, is(fromBGR)); - assertThat(testColor.name, fromRGB, is(fromBGRs)); - assertThat(testColor.name, fromRGBs, is(fromBGR)); - assertThat(testColor.name, fromRGBs, is(fromBGRs)); - assertThat(testColor.name, fromBGR, is(fromBGRs)); + assertThat(fromARGB, is(fromARGB), testColor.name); + assertThat(fromARGBs, is(fromARGBs), testColor.name); + assertThat(fromRGB, is(fromRGBs), testColor.name); + assertThat(fromRGB, is(fromBGR), testColor.name); + assertThat(fromRGB, is(fromBGRs), testColor.name); + assertThat(fromRGBs, is(fromBGR), testColor.name); + assertThat(fromRGBs, is(fromBGRs), testColor.name); + assertThat(fromBGR, is(fromBGRs), testColor.name); } } @@ -93,11 +94,11 @@ public class ColorTest { TestColor testTo = examples[j]; Color to = Color.fromARGB(testTo.argb); String name = testFrom.name + " to " + testTo.name; - assertThat(name, from, is(not(to))); + assertThat(from, is(not(to)), name); Color transform = from.setAlpha(testTo.a).setRed(testTo.r).setBlue(testTo.b).setGreen(testTo.g); - assertThat(name, transform, is(not(sameInstance(from)))); - assertThat(name, transform, is(to)); + assertThat(transform, is(not(sameInstance(from))), name); + assertThat(transform, is(to), name); } } } @@ -106,8 +107,8 @@ public class ColorTest { @Test public void testARGB() { for (TestColor testColor : examples) { - assertThat(testColor.name, Color.fromARGB(testColor.argb).asARGB(), is(testColor.argb)); - assertThat(testColor.name, Color.fromARGB(testColor.a, testColor.r, testColor.g, testColor.b).asARGB(), is(testColor.argb)); + assertThat(Color.fromARGB(testColor.argb).asARGB(), is(testColor.argb), testColor.name); + assertThat(Color.fromARGB(testColor.a, testColor.r, testColor.g, testColor.b).asARGB(), is(testColor.argb), testColor.name); } } @@ -115,342 +116,342 @@ public class ColorTest { @Test public void testRGB() { for (TestColor testColor : examples) { - assertThat(testColor.name, Color.fromRGB(testColor.rgb).asRGB(), is(testColor.rgb)); - assertThat(testColor.name, Color.fromBGR(testColor.bgr).asRGB(), is(testColor.rgb)); - assertThat(testColor.name, Color.fromRGB(testColor.r, testColor.g, testColor.b).asRGB(), is(testColor.rgb)); - assertThat(testColor.name, Color.fromBGR(testColor.b, testColor.g, testColor.r).asRGB(), is(testColor.rgb)); + assertThat(Color.fromRGB(testColor.rgb).asRGB(), is(testColor.rgb), testColor.name); + assertThat(Color.fromBGR(testColor.bgr).asRGB(), is(testColor.rgb), testColor.name); + assertThat(Color.fromRGB(testColor.r, testColor.g, testColor.b).asRGB(), is(testColor.rgb), testColor.name); + assertThat(Color.fromBGR(testColor.b, testColor.g, testColor.r).asRGB(), is(testColor.rgb), testColor.name); } } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidRGB1() { - Color.fromRGB(0x01000000); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x01000000)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidRGB2() { - Color.fromRGB(Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidRGB3() { - Color.fromRGB(Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidRGB4() { - Color.fromRGB(-1); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(-1)); } // BGR tests @Test public void testBGR() { for (TestColor testColor : examples) { - assertThat(testColor.name, Color.fromRGB(testColor.rgb).asBGR(), is(testColor.bgr)); - assertThat(testColor.name, Color.fromBGR(testColor.bgr).asBGR(), is(testColor.bgr)); - assertThat(testColor.name, Color.fromRGB(testColor.r, testColor.g, testColor.b).asBGR(), is(testColor.bgr)); - assertThat(testColor.name, Color.fromBGR(testColor.b, testColor.g, testColor.r).asBGR(), is(testColor.bgr)); + assertThat(Color.fromRGB(testColor.rgb).asBGR(), is(testColor.bgr), testColor.name); + assertThat(Color.fromBGR(testColor.bgr).asBGR(), is(testColor.bgr), testColor.name); + assertThat(Color.fromRGB(testColor.r, testColor.g, testColor.b).asBGR(), is(testColor.bgr), testColor.name); + assertThat(Color.fromBGR(testColor.b, testColor.g, testColor.r).asBGR(), is(testColor.bgr), testColor.name); } } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidBGR1() { - Color.fromBGR(0x01000000); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x01000000)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidBGR2() { - Color.fromBGR(Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidBGR3() { - Color.fromBGR(Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidBGR4() { - Color.fromBGR(-1); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(-1)); } // Alpha tests @Test public void testAlpha() { for (TestColor testColor : examples) { - assertThat(testColor.name, Color.fromARGB(testColor.argb).getAlpha(), is(testColor.a)); + assertThat(Color.fromARGB(testColor.argb).getAlpha(), is(testColor.a), testColor.name); } } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA01() { - Color.fromARGB(-1, 0x00, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromARGB(-1, 0x00, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA02() { - Color.fromARGB(Integer.MAX_VALUE, 0x00, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromARGB(Integer.MAX_VALUE, 0x00, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA03() { - Color.fromARGB(Integer.MIN_VALUE, 0x00, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromARGB(Integer.MIN_VALUE, 0x00, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA04() { - Color.fromARGB(0x100, 0x00, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromARGB(0x100, 0x00, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA05() { - Color.fromBGR(0x00, 0x00, 0x00).setAlpha(-1); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, 0x00).setAlpha(-1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA06() { - Color.fromBGR(0x00, 0x00, 0x00).setAlpha(Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, 0x00).setAlpha(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA07() { - Color.fromBGR(0x00, 0x00, 0x00).setAlpha(Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, 0x00).setAlpha(Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA08() { - Color.fromBGR(0x00, 0x00, 0x00).setAlpha(0x100); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, 0x00).setAlpha(0x100)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA09() { - Color.WHITE.setAlpha(-1); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setAlpha(-1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA10() { - Color.WHITE.setAlpha(Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setAlpha(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA11() { - Color.WHITE.setAlpha(Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setAlpha(Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA12() { - Color.WHITE.setAlpha(0x100); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setAlpha(0x100)); } // Red tests @Test public void testRed() { for (TestColor testColor : examples) { - assertThat(testColor.name, Color.fromRGB(testColor.rgb).getRed(), is(testColor.r)); - assertThat(testColor.name, Color.fromBGR(testColor.bgr).getRed(), is(testColor.r)); - assertThat(testColor.name, Color.fromRGB(testColor.r, testColor.g, testColor.b).getRed(), is(testColor.r)); - assertThat(testColor.name, Color.fromBGR(testColor.b, testColor.g, testColor.r).getRed(), is(testColor.r)); + assertThat(Color.fromRGB(testColor.rgb).getRed(), is(testColor.r), testColor.name); + assertThat(Color.fromBGR(testColor.bgr).getRed(), is(testColor.r), testColor.name); + assertThat(Color.fromRGB(testColor.r, testColor.g, testColor.b).getRed(), is(testColor.r), testColor.name); + assertThat(Color.fromBGR(testColor.b, testColor.g, testColor.r).getRed(), is(testColor.r), testColor.name); } } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR01() { - Color.fromRGB(-1, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(-1, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR02() { - Color.fromRGB(Integer.MAX_VALUE, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(Integer.MAX_VALUE, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR03() { - Color.fromRGB(Integer.MIN_VALUE, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(Integer.MIN_VALUE, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR04() { - Color.fromRGB(0x100, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x100, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR05() { - Color.fromBGR(0x00, 0x00, -1); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, -1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR06() { - Color.fromBGR(0x00, 0x00, Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR07() { - Color.fromBGR(0x00, 0x00, Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR08() { - Color.fromBGR(0x00, 0x00, 0x100); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, 0x100)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR09() { - Color.WHITE.setRed(-1); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setRed(-1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR10() { - Color.WHITE.setRed(Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setRed(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR11() { - Color.WHITE.setRed(Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setRed(Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR12() { - Color.WHITE.setRed(0x100); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setRed(0x100)); } // Blue tests @Test public void testBlue() { for (TestColor testColor : examples) { - assertThat(testColor.name, Color.fromRGB(testColor.rgb).getBlue(), is(testColor.b)); - assertThat(testColor.name, Color.fromBGR(testColor.bgr).getBlue(), is(testColor.b)); - assertThat(testColor.name, Color.fromRGB(testColor.r, testColor.g, testColor.b).getBlue(), is(testColor.b)); - assertThat(testColor.name, Color.fromBGR(testColor.b, testColor.g, testColor.r).getBlue(), is(testColor.b)); + assertThat(Color.fromRGB(testColor.rgb).getBlue(), is(testColor.b), testColor.name); + assertThat(Color.fromBGR(testColor.bgr).getBlue(), is(testColor.b), testColor.name); + assertThat(Color.fromRGB(testColor.r, testColor.g, testColor.b).getBlue(), is(testColor.b), testColor.name); + assertThat(Color.fromBGR(testColor.b, testColor.g, testColor.r).getBlue(), is(testColor.b), testColor.name); } } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB01() { - Color.fromRGB(0x00, 0x00, -1); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, 0x00, -1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB02() { - Color.fromRGB(0x00, 0x00, Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, 0x00, Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB03() { - Color.fromRGB(0x00, 0x00, Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, 0x00, Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB04() { - Color.fromRGB(0x00, 0x00, 0x100); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, 0x00, 0x100)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB05() { - Color.fromBGR(-1, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(-1, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB06() { - Color.fromBGR(Integer.MAX_VALUE, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(Integer.MAX_VALUE, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB07() { - Color.fromBGR(Integer.MIN_VALUE, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(Integer.MIN_VALUE, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB08() { - Color.fromBGR(0x100, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x100, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB09() { - Color.WHITE.setBlue(-1); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setBlue(-1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB10() { - Color.WHITE.setBlue(Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setBlue(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB11() { - Color.WHITE.setBlue(Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setBlue(Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB12() { - Color.WHITE.setBlue(0x100); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setBlue(0x100)); } // Green tests @Test public void testGreen() { for (TestColor testColor : examples) { - assertThat(testColor.name, Color.fromRGB(testColor.rgb).getGreen(), is(testColor.g)); - assertThat(testColor.name, Color.fromBGR(testColor.bgr).getGreen(), is(testColor.g)); - assertThat(testColor.name, Color.fromRGB(testColor.r, testColor.g, testColor.b).getGreen(), is(testColor.g)); - assertThat(testColor.name, Color.fromBGR(testColor.b, testColor.g, testColor.r).getGreen(), is(testColor.g)); + assertThat(Color.fromRGB(testColor.rgb).getGreen(), is(testColor.g), testColor.name); + assertThat(Color.fromBGR(testColor.bgr).getGreen(), is(testColor.g), testColor.name); + assertThat(Color.fromRGB(testColor.r, testColor.g, testColor.b).getGreen(), is(testColor.g), testColor.name); + assertThat(Color.fromBGR(testColor.b, testColor.g, testColor.r).getGreen(), is(testColor.g), testColor.name); } } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG01() { - Color.fromRGB(0x00, -1, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, -1, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG02() { - Color.fromRGB(0x00, Integer.MAX_VALUE, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, Integer.MAX_VALUE, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG03() { - Color.fromRGB(0x00, Integer.MIN_VALUE, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, Integer.MIN_VALUE, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG04() { - Color.fromRGB(0x00, 0x100, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, 0x100, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG05() { - Color.fromBGR(0x00, -1, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, -1, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG06() { - Color.fromBGR(0x00, Integer.MAX_VALUE, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, Integer.MAX_VALUE, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG07() { - Color.fromBGR(0x00, Integer.MIN_VALUE, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, Integer.MIN_VALUE, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG08() { - Color.fromBGR(0x00, 0x100, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x100, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG09() { - Color.WHITE.setGreen(-1); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setGreen(-1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG10() { - Color.WHITE.setGreen(Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setGreen(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG11() { - Color.WHITE.setGreen(Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setGreen(Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG12() { - Color.WHITE.setGreen(0x100); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setGreen(0x100)); } } diff --git a/paper-api/src/test/java/org/bukkit/CropStateTest.java b/paper-api/src/test/java/org/bukkit/CropStateTest.java index 5cd9d6d2d..6efe3f1c3 100644 --- a/paper-api/src/test/java/org/bukkit/CropStateTest.java +++ b/paper-api/src/test/java/org/bukkit/CropStateTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CropStateTest { @Test diff --git a/paper-api/src/test/java/org/bukkit/DifficultyTest.java b/paper-api/src/test/java/org/bukkit/DifficultyTest.java index d7fe8d39a..37623027c 100644 --- a/paper-api/src/test/java/org/bukkit/DifficultyTest.java +++ b/paper-api/src/test/java/org/bukkit/DifficultyTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class DifficultyTest { @Test diff --git a/paper-api/src/test/java/org/bukkit/DyeColorTest.java b/paper-api/src/test/java/org/bukkit/DyeColorTest.java index e56d9439a..4e9ff14fc 100644 --- a/paper-api/src/test/java/org/bukkit/DyeColorTest.java +++ b/paper-api/src/test/java/org/bukkit/DyeColorTest.java @@ -1,69 +1,57 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import java.util.ArrayList; -import java.util.List; import org.bukkit.material.Colorable; import org.bukkit.material.Dye; import org.bukkit.material.Wool; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; -@RunWith(Parameterized.class) public class DyeColorTest { - @Parameters(name = "{index}: {0}") - public static List data() { - List list = new ArrayList(); - for (DyeColor dye : DyeColor.values()) { - list.add(new Object[] {dye}); - } - return list; - } - - @Parameter public DyeColor dye; - - @Test + @ParameterizedTest + @EnumSource(DyeColor.class) @SuppressWarnings("deprecation") - public void getByData() { + public void getByData(DyeColor dye) { byte data = dye.getWoolData(); DyeColor byData = DyeColor.getByWoolData(data); assertThat(byData, is(dye)); } - @Test - public void getByWoolData() { + @ParameterizedTest + @EnumSource(DyeColor.class) + public void getByWoolData(DyeColor dye) { byte data = dye.getWoolData(); DyeColor byData = DyeColor.getByWoolData(data); assertThat(byData, is(dye)); } - @Test - public void getByDyeData() { + @ParameterizedTest + @EnumSource(DyeColor.class) + public void getByDyeData(DyeColor dye) { byte data = dye.getDyeData(); DyeColor byData = DyeColor.getByDyeData(data); assertThat(byData, is(dye)); } - @Test - public void getDyeDyeColor() { - testColorable(new Dye(Material.LEGACY_INK_SACK, dye.getDyeData())); - testColorable(new Dye(dye)); + @ParameterizedTest + @EnumSource(DyeColor.class) + public void getDyeDyeColor(DyeColor dye) { + testColorable(new Dye(Material.LEGACY_INK_SACK, dye.getDyeData()), dye); + testColorable(new Dye(dye), dye); } - @Test - public void getWoolDyeColor() { - testColorable(new Wool(Material.LEGACY_WOOL, dye.getWoolData())); + @ParameterizedTest + @EnumSource(DyeColor.class) + public void getWoolDyeColor(DyeColor dye) { + testColorable(new Wool(Material.LEGACY_WOOL, dye.getWoolData()), dye); } - private void testColorable(final Colorable colorable) { - assertThat(colorable.getColor(), is(this.dye)); + private void testColorable(final Colorable colorable, DyeColor dye) { + assertThat(colorable.getColor(), is(dye)); } } diff --git a/paper-api/src/test/java/org/bukkit/EffectTest.java b/paper-api/src/test/java/org/bukkit/EffectTest.java index 54e621e86..4344512fa 100644 --- a/paper-api/src/test/java/org/bukkit/EffectTest.java +++ b/paper-api/src/test/java/org/bukkit/EffectTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class EffectTest { @Test diff --git a/paper-api/src/test/java/org/bukkit/GameModeTest.java b/paper-api/src/test/java/org/bukkit/GameModeTest.java index 1c53e8ed8..c5d3a1513 100644 --- a/paper-api/src/test/java/org/bukkit/GameModeTest.java +++ b/paper-api/src/test/java/org/bukkit/GameModeTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class GameModeTest { @Test diff --git a/paper-api/src/test/java/org/bukkit/GrassSpeciesTest.java b/paper-api/src/test/java/org/bukkit/GrassSpeciesTest.java index 39f1b899e..6739dc240 100644 --- a/paper-api/src/test/java/org/bukkit/GrassSpeciesTest.java +++ b/paper-api/src/test/java/org/bukkit/GrassSpeciesTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class GrassSpeciesTest { @Test diff --git a/paper-api/src/test/java/org/bukkit/InstrumentTest.java b/paper-api/src/test/java/org/bukkit/InstrumentTest.java index 14ad060eb..8c1d88885 100644 --- a/paper-api/src/test/java/org/bukkit/InstrumentTest.java +++ b/paper-api/src/test/java/org/bukkit/InstrumentTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class InstrumentTest { @Test diff --git a/paper-api/src/test/java/org/bukkit/LastChatColorTest.java b/paper-api/src/test/java/org/bukkit/LastChatColorTest.java index 64e164ea7..3d1c839cc 100644 --- a/paper-api/src/test/java/org/bukkit/LastChatColorTest.java +++ b/paper-api/src/test/java/org/bukkit/LastChatColorTest.java @@ -1,40 +1,30 @@ package org.bukkit; -import static org.junit.Assert.*; -import java.util.Arrays; -import java.util.Collection; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import static org.junit.jupiter.api.Assertions.*; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class LastChatColorTest { - @Parameterized.Parameters - public static Collection data() { - return Arrays.asList(new Object[][]{ - {String.format("%c%ctest%c%ctest%c", ChatColor.COLOR_CHAR, ChatColor.RED.getChar(), ChatColor.COLOR_CHAR, ChatColor.ITALIC.getChar(), ChatColor.COLOR_CHAR), ChatColor.RED.toString() + ChatColor.ITALIC}, - {String.format("%c%ctest%c%ctest", ChatColor.COLOR_CHAR, ChatColor.RED.getChar(), ChatColor.COLOR_CHAR, ChatColor.BLUE.getChar()), ChatColor.BLUE.toString()}, - {"§x§1§2§3§4§5§6", "§x§1§2§3§4§5§6"}, - {"§y§1§2§3§4§5§6", "§6"}, - {"§3§4§5§6", "§6"}, - {"Test2§x§1§f§3§4§F§6test§l", "§x§1§f§3§4§F§6§l"}, - {"Test2§x§P§f§3§4§F§6test§l", "§6§l"}, - {"Test2§x§fxf§3§4§F§6test§l", "§6§l"}, - {"Test2§x§1§4§F§6test§l", "§6§l"} - }); + public static Stream data() { + return Stream.of( + Arguments.of(String.format("%c%ctest%c%ctest%c", ChatColor.COLOR_CHAR, ChatColor.RED.getChar(), ChatColor.COLOR_CHAR, ChatColor.ITALIC.getChar(), ChatColor.COLOR_CHAR), ChatColor.RED.toString() + ChatColor.ITALIC), + Arguments.of(String.format("%c%ctest%c%ctest", ChatColor.COLOR_CHAR, ChatColor.RED.getChar(), ChatColor.COLOR_CHAR, ChatColor.BLUE.getChar()), ChatColor.BLUE.toString()), + Arguments.of("§x§1§2§3§4§5§6", "§x§1§2§3§4§5§6"), + Arguments.of("§y§1§2§3§4§5§6", "§6"), + Arguments.of("§3§4§5§6", "§6"), + Arguments.of("Test2§x§1§f§3§4§F§6test§l", "§x§1§f§3§4§F§6§l"), + Arguments.of("Test2§x§P§f§3§4§F§6test§l", "§6§l"), + Arguments.of("Test2§x§fxf§3§4§F§6test§l", "§6§l"), + Arguments.of("Test2§x§1§4§F§6test§l", "§6§l") + ); } - private final String input; - private final String expected; - - public LastChatColorTest(String input, String expected) { - this.input = input; - this.expected = expected; - } - - @Test - public void testGetLastColors() { + @ParameterizedTest + @MethodSource("data") + public void testGetLastColors(String input, String expected) { assertEquals(expected, ChatColor.getLastColors(input)); } } diff --git a/paper-api/src/test/java/org/bukkit/LocationTest.java b/paper-api/src/test/java/org/bukkit/LocationTest.java index 02b97fa74..35a98c145 100644 --- a/paper-api/src/test/java/org/bukkit/LocationTest.java +++ b/paper-api/src/test/java/org/bukkit/LocationTest.java @@ -1,19 +1,15 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import static org.mockito.Mockito.*; -import com.google.common.collect.ImmutableList; -import java.util.List; import java.util.Random; +import java.util.stream.Stream; import org.bukkit.util.Vector; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class LocationTest { private static final double delta = 1.0 / 1000000; /** @@ -37,59 +33,58 @@ public class LocationTest { */ private static final double HALF_HALF_UNIT = Math.sqrt(1 / 4f); - @Parameters(name = "{index}: {0}") - public static List data() { + public static Stream data() { Random RANDOM = new Random(1L); // Test is deterministic int r = 0; - return ImmutableList.of( - new Object[]{"X", + return Stream.of( + Arguments.of("X", 1, 0, 0, 270, 0 - }, - new Object[]{"-X", + ), + Arguments.of("-X", -1, 0, 0, 90, 0 - }, - new Object[]{"Z", + ), + Arguments.of("Z", 0, 0, 1, 0, 0 - }, - new Object[]{"-Z", + ), + Arguments.of("-Z", 0, 0, -1, 180, 0 - }, - new Object[]{"Y", + ), + Arguments.of("Y", 0, 1, 0, 0, -90 // Zero is here as a "default" value - }, - new Object[]{"-Y", + ), + Arguments.of("-Y", 0, -1, 0, 0, 90 // Zero is here as a "default" value - }, - new Object[]{"X Z", + ), + Arguments.of("X Z", HALF_UNIT, 0, HALF_UNIT, (270 + 360) / 2, 0 - }, - new Object[]{"X -Z", + ), + Arguments.of("X -Z", HALF_UNIT, 0, -HALF_UNIT, (270 + 180) / 2, 0 - }, - new Object[]{"-X -Z", + ), + Arguments.of("-X -Z", -HALF_UNIT, 0, -HALF_UNIT, (90 + 180) / 2, 0 - }, - new Object[]{"-X Z", + ), + Arguments.of("-X Z", -HALF_UNIT, 0, HALF_UNIT, (90 + 0) / 2, 0 - }, - new Object[]{"X Y Z", + ), + Arguments.of("X Y Z", HALF_HALF_UNIT, HALF_UNIT, HALF_HALF_UNIT, (270 + 360) / 2, -45 - }, - new Object[]{"-X -Y -Z", + ), + Arguments.of("-X -Y -Z", -HALF_HALF_UNIT, -HALF_UNIT, -HALF_HALF_UNIT, (90 + 180) / 2, 45 - }, + ), getRandom(RANDOM, r++), getRandom(RANDOM, r++), getRandom(RANDOM, r++), @@ -111,7 +106,7 @@ public class LocationTest { ); } - private static Object[] getRandom(Random random, int index) { + private static Arguments getRandom(Random random, int index) { final double YAW_FACTOR = 360; final double YAW_OFFSET = 0; final double PITCH_FACTOR = 180; @@ -141,52 +136,42 @@ public class LocationTest { location.setDirection(vector); } - return new Object[]{"R" + index, + return Arguments.of("R" + index, vector.getX(), vector.getY(), vector.getZ(), location.getYaw(), location.getPitch() - }; + ); } - @Parameter(0) - public String nane; - @Parameter(1) - public double x; - @Parameter(2) - public double y; - @Parameter(3) - public double z; - @Parameter(4) - public float yaw; - @Parameter(5) - public float pitch; - - @Test - public void testExpectedPitchYaw() { - Location location = getEmptyLocation().setDirection(getVector()); + @ParameterizedTest + @MethodSource("data") + public void testExpectedPitchYaw(String name, double x, double y, double z, float yaw, float pitch) { + Location location = getEmptyLocation().setDirection(getVector(x, y, z)); assertThat((double) location.getYaw(), is(closeTo(yaw, delta))); assertThat((double) location.getPitch(), is(closeTo(pitch, delta))); } - @Test - public void testExpectedXYZ() { - Vector vector = getLocation().getDirection(); + @ParameterizedTest + @MethodSource("data") + public void testExpectedXYZ(String name, double x, double y, double z, float yaw, float pitch) { + Vector vector = getLocation(yaw, pitch).getDirection(); assertThat(vector.getX(), is(closeTo(x, delta))); assertThat(vector.getY(), is(closeTo(y, delta))); assertThat(vector.getZ(), is(closeTo(z, delta))); } - @Test - public void testEquals() { - Location first = getLocation().add(getVector()); - Location second = getLocation().add(getVector()); + @ParameterizedTest + @MethodSource("data") + public void testEquals(String name, double x, double y, double z, float yaw, float pitch) { + Location first = getLocation(yaw, pitch).add(getVector(x, y, z)); + Location second = getLocation(yaw, pitch).add(getVector(x, y, z)); assertThat(first.hashCode(), is(second.hashCode())); assertThat(first, is(second)); } - private Vector getVector() { + private Vector getVector(double x, double y, double z) { return new Vector(x, y, z); } @@ -196,7 +181,7 @@ public class LocationTest { return new Location(TEST_WORLD, 0, 0, 0); } - private Location getLocation() { + private Location getLocation(float yaw, float pitch) { Location location = getEmptyLocation(); location.setYaw(yaw); location.setPitch(pitch); diff --git a/paper-api/src/test/java/org/bukkit/MaterialTest.java b/paper-api/src/test/java/org/bukkit/MaterialTest.java index 6b0eaaadf..818aa21d3 100644 --- a/paper-api/src/test/java/org/bukkit/MaterialTest.java +++ b/paper-api/src/test/java/org/bukkit/MaterialTest.java @@ -1,9 +1,10 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.material.MaterialData; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MaterialTest { @Test @@ -30,9 +31,9 @@ public class MaterialTest { } } - @Test(expected = IllegalArgumentException.class) + @Test public void matchMaterialByNull() { - Material.matchMaterial(null); + assertThrows(IllegalArgumentException.class, () -> Material.matchMaterial(null)); } @Test diff --git a/paper-api/src/test/java/org/bukkit/NamespacedKeyTest.java b/paper-api/src/test/java/org/bukkit/NamespacedKeyTest.java index 9f57889cb..6317798e4 100644 --- a/paper-api/src/test/java/org/bukkit/NamespacedKeyTest.java +++ b/paper-api/src/test/java/org/bukkit/NamespacedKeyTest.java @@ -1,72 +1,72 @@ package org.bukkit; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class NamespacedKeyTest { @Test public void testValid() { - Assert.assertEquals("minecraft:foo", new NamespacedKey("minecraft", "foo").toString()); - Assert.assertEquals("minecraft:foo/bar", new NamespacedKey("minecraft", "foo/bar").toString()); - Assert.assertEquals("minecraft:foo/bar_baz", new NamespacedKey("minecraft", "foo/bar_baz").toString()); - Assert.assertEquals("minecraft:foo/bar_baz-qux", new NamespacedKey("minecraft", "foo/bar_baz-qux").toString()); - Assert.assertEquals("minecraft:foo/bar_baz-qux.quux", new NamespacedKey("minecraft", "foo/bar_baz-qux.quux").toString()); + assertEquals("minecraft:foo", new NamespacedKey("minecraft", "foo").toString()); + assertEquals("minecraft:foo/bar", new NamespacedKey("minecraft", "foo/bar").toString()); + assertEquals("minecraft:foo/bar_baz", new NamespacedKey("minecraft", "foo/bar_baz").toString()); + assertEquals("minecraft:foo/bar_baz-qux", new NamespacedKey("minecraft", "foo/bar_baz-qux").toString()); + assertEquals("minecraft:foo/bar_baz-qux.quux", new NamespacedKey("minecraft", "foo/bar_baz-qux.quux").toString()); } @Test public void testValidFromString() { NamespacedKey expected = NamespacedKey.minecraft("foo"); - Assert.assertEquals(expected, NamespacedKey.fromString("foo")); - Assert.assertEquals(expected, NamespacedKey.fromString(":foo")); - Assert.assertEquals(expected, NamespacedKey.fromString("minecraft:foo")); - Assert.assertEquals(new NamespacedKey("foo", "bar"), NamespacedKey.fromString("foo:bar")); + assertEquals(expected, NamespacedKey.fromString("foo")); + assertEquals(expected, NamespacedKey.fromString(":foo")); + assertEquals(expected, NamespacedKey.fromString("minecraft:foo")); + assertEquals(new NamespacedKey("foo", "bar"), NamespacedKey.fromString("foo:bar")); - Assert.assertNull(NamespacedKey.fromString("fOO")); - Assert.assertNull(NamespacedKey.fromString(":Foo")); - Assert.assertNull(NamespacedKey.fromString("fOO:bar")); - Assert.assertNull(NamespacedKey.fromString("minecraft:fOO")); - Assert.assertNull(NamespacedKey.fromString("foo:bar:bazz")); + assertNull(NamespacedKey.fromString("fOO")); + assertNull(NamespacedKey.fromString(":Foo")); + assertNull(NamespacedKey.fromString("fOO:bar")); + assertNull(NamespacedKey.fromString("minecraft:fOO")); + assertNull(NamespacedKey.fromString("foo:bar:bazz")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testFromStringEmptyInput() { - NamespacedKey.fromString(""); + assertThrows(IllegalArgumentException.class, () -> NamespacedKey.fromString("")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testFromStringNullInput() { - NamespacedKey.fromString(null); + assertThrows(IllegalArgumentException.class, () -> NamespacedKey.fromString(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testEmptyNamespace() { - new NamespacedKey("", "foo").toString(); + assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("", "foo").toString()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testEmptyKey() { - new NamespacedKey("minecraft", "").toString(); + assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("minecraft", "").toString()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidNamespace() { - new NamespacedKey("minecraft/test", "foo").toString(); + assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("minecraft/test", "foo").toString()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidNamespaceCasing() { - new NamespacedKey("Minecraft", "foo").toString(); + assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("Minecraft", "foo").toString()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidKeyCasing() { - new NamespacedKey("minecraft", "Foo").toString(); + assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("minecraft", "Foo").toString()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidKey() { - new NamespacedKey("minecraft", "foo!").toString(); + assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("minecraft", "foo!").toString()); } @Test @@ -75,10 +75,10 @@ public class NamespacedKeyTest { "loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas").toString(); } - @Test(expected = IllegalArgumentException.class) + @Test public void testAboveLength() { - new NamespacedKey("loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas", + assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas", "loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas/" - + "loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas").toString(); + + "loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas").toString()); } } diff --git a/paper-api/src/test/java/org/bukkit/NoteTest.java b/paper-api/src/test/java/org/bukkit/NoteTest.java index 0db4bfa43..616f4ce9b 100644 --- a/paper-api/src/test/java/org/bukkit/NoteTest.java +++ b/paper-api/src/test/java/org/bukkit/NoteTest.java @@ -1,10 +1,11 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import com.google.common.collect.Lists; import java.util.Collection; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class NoteTest { @Test @@ -51,24 +52,24 @@ public class NoteTest { } } - @Test(expected = IllegalArgumentException.class) + @Test public void createNoteBelowMin() { - new Note((byte) -1); + assertThrows(IllegalArgumentException.class, () -> new Note((byte) -1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void createNoteAboveMax() { - new Note((byte) 25); + assertThrows(IllegalArgumentException.class, () -> new Note((byte) 25)); } - @Test(expected = IllegalArgumentException.class) + @Test public void createNoteOctaveBelowMax() { - new Note((byte) -1, Note.Tone.A, true); + assertThrows(IllegalArgumentException.class, () -> new Note((byte) -1, Note.Tone.A, true)); } - @Test(expected = IllegalArgumentException.class) + @Test public void createNoteOctaveAboveMax() { - new Note((byte) 3, Note.Tone.A, true); + assertThrows(IllegalArgumentException.class, () -> new Note((byte) 3, Note.Tone.A, true)); } @Test @@ -114,9 +115,9 @@ public class NoteTest { assertEquals(note.getOctave(), 2); } - @Test(expected = IllegalArgumentException.class) + @Test public void testSharpWrapping2() { - new Note(2, Note.Tone.F, true).sharped(); + assertThrows(IllegalArgumentException.class, () -> new Note(2, Note.Tone.F, true).sharped()); } @Test diff --git a/paper-api/src/test/java/org/bukkit/TreeSpeciesTest.java b/paper-api/src/test/java/org/bukkit/TreeSpeciesTest.java index 51e956cc5..66401d83b 100644 --- a/paper-api/src/test/java/org/bukkit/TreeSpeciesTest.java +++ b/paper-api/src/test/java/org/bukkit/TreeSpeciesTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TreeSpeciesTest { @Test diff --git a/paper-api/src/test/java/org/bukkit/WorldTypeTest.java b/paper-api/src/test/java/org/bukkit/WorldTypeTest.java index 3c5f7b8a7..651499066 100644 --- a/paper-api/src/test/java/org/bukkit/WorldTypeTest.java +++ b/paper-api/src/test/java/org/bukkit/WorldTypeTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class WorldTypeTest { @Test diff --git a/paper-api/src/test/java/org/bukkit/configuration/ConfigurationSectionTest.java b/paper-api/src/test/java/org/bukkit/configuration/ConfigurationSectionTest.java index bfaacbaa3..ee5bc86f4 100644 --- a/paper-api/src/test/java/org/bukkit/configuration/ConfigurationSectionTest.java +++ b/paper-api/src/test/java/org/bukkit/configuration/ConfigurationSectionTest.java @@ -1,6 +1,6 @@ package org.bukkit.configuration; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -11,7 +11,7 @@ import org.bukkit.Material; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; -import org.junit.Test; +import org.junit.jupiter.api.Test; public abstract class ConfigurationSectionTest { public abstract ConfigurationSection getConfigurationSection(); diff --git a/paper-api/src/test/java/org/bukkit/configuration/ConfigurationTest.java b/paper-api/src/test/java/org/bukkit/configuration/ConfigurationTest.java index 65f6ba389..e5d926917 100644 --- a/paper-api/src/test/java/org/bukkit/configuration/ConfigurationTest.java +++ b/paper-api/src/test/java/org/bukkit/configuration/ConfigurationTest.java @@ -1,6 +1,6 @@ package org.bukkit.configuration; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -9,7 +9,7 @@ import java.util.Map; import java.util.Set; import org.bukkit.configuration.serialization.ConfigurationSerialization; import org.bukkit.util.Vector; -import org.junit.Test; +import org.junit.jupiter.api.Test; public abstract class ConfigurationTest { diff --git a/paper-api/src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java b/paper-api/src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java index d6a141036..c25303e81 100644 --- a/paper-api/src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java +++ b/paper-api/src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java @@ -1,6 +1,6 @@ package org.bukkit.configuration.file; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; @@ -8,13 +8,12 @@ import java.util.Arrays; import java.util.List; import java.util.Map; import org.bukkit.configuration.MemoryConfigurationTest; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; public abstract class FileConfigurationTest extends MemoryConfigurationTest { - @Rule - public TemporaryFolder testFolder = new TemporaryFolder(); + @TempDir + public File testFolder; @Override public abstract FileConfiguration getConfig(); @@ -36,7 +35,8 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest { @Test public void testSave_File() throws Exception { FileConfiguration config = getConfig(); - File file = testFolder.newFile("test.config"); + File file = new File(testFolder, "test.config"); + file.createNewFile(); for (Map.Entry entry : getTestValues().entrySet()) { config.set(entry.getKey(), entry.getValue()); @@ -50,7 +50,8 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest { @Test public void testSave_String() throws Exception { FileConfiguration config = getConfig(); - File file = testFolder.newFile("test.config"); + File file = new File(testFolder, "test.config"); + file.createNewFile(); for (Map.Entry entry : getTestValues().entrySet()) { config.set(entry.getKey(), entry.getValue()); @@ -78,7 +79,8 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest { @Test public void testLoad_File() throws Exception { FileConfiguration config = getConfig(); - File file = testFolder.newFile("test.config"); + File file = new File(testFolder, "test.config"); + file.createNewFile(); BufferedWriter writer = new BufferedWriter(new FileWriter(file)); String saved = getTestValuesString(); Map values = getTestValues(); @@ -101,7 +103,8 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest { @Test public void testLoad_String() throws Exception { FileConfiguration config = getConfig(); - File file = testFolder.newFile("test.config"); + File file = new File(testFolder, "test.config"); + file.createNewFile(); BufferedWriter writer = new BufferedWriter(new FileWriter(file)); String saved = getTestValuesString(); Map values = getTestValues(); diff --git a/paper-api/src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java b/paper-api/src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java index 003f45d8c..82c7f6ba9 100644 --- a/paper-api/src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java +++ b/paper-api/src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java @@ -1,6 +1,6 @@ package org.bukkit.configuration.file; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -12,7 +12,7 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.MemoryConfiguration; import org.jetbrains.annotations.NotNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class YamlConfigurationTest extends FileConfigurationTest { diff --git a/paper-api/src/test/java/org/bukkit/conversations/ConversationContextTest.java b/paper-api/src/test/java/org/bukkit/conversations/ConversationContextTest.java index 3780a47c1..48349dfb2 100644 --- a/paper-api/src/test/java/org/bukkit/conversations/ConversationContextTest.java +++ b/paper-api/src/test/java/org/bukkit/conversations/ConversationContextTest.java @@ -1,9 +1,9 @@ package org.bukkit.conversations; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** */ @@ -19,7 +19,7 @@ public class ConversationContextTest { public void TestPlugin() { Conversable conversable = new FakeConversable(); ConversationContext context = new ConversationContext(null, conversable, new HashMap()); - assertEquals(null, context.getPlugin()); + assertNull(context.getPlugin()); } @Test diff --git a/paper-api/src/test/java/org/bukkit/conversations/ConversationTest.java b/paper-api/src/test/java/org/bukkit/conversations/ConversationTest.java index c448dc724..8a515b0fe 100644 --- a/paper-api/src/test/java/org/bukkit/conversations/ConversationTest.java +++ b/paper-api/src/test/java/org/bukkit/conversations/ConversationTest.java @@ -1,8 +1,8 @@ package org.bukkit.conversations; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.plugin.TestPlugin; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** */ diff --git a/paper-api/src/test/java/org/bukkit/conversations/ValidatingPromptTest.java b/paper-api/src/test/java/org/bukkit/conversations/ValidatingPromptTest.java index 6093e9865..b0c6eb934 100644 --- a/paper-api/src/test/java/org/bukkit/conversations/ValidatingPromptTest.java +++ b/paper-api/src/test/java/org/bukkit/conversations/ValidatingPromptTest.java @@ -1,7 +1,7 @@ package org.bukkit.conversations; -import static org.junit.Assert.*; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; /** */ diff --git a/paper-api/src/test/java/org/bukkit/entity/memory/MemoryKeyTest.java b/paper-api/src/test/java/org/bukkit/entity/memory/MemoryKeyTest.java index b955f6a7a..2e426a908 100644 --- a/paper-api/src/test/java/org/bukkit/entity/memory/MemoryKeyTest.java +++ b/paper-api/src/test/java/org/bukkit/entity/memory/MemoryKeyTest.java @@ -1,41 +1,41 @@ package org.bukkit.entity.memory; +import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; import java.util.List; import org.bukkit.NamespacedKey; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MemoryKeyTest { @Test public void shouldContainAllMemories() { List memories = Arrays.asList(MemoryKey.HOME, MemoryKey.JOB_SITE, MemoryKey.MEETING_POINT); - Assert.assertTrue(MemoryKey.values().containsAll(memories)); + assertTrue(MemoryKey.values().containsAll(memories)); } @Test public void shouldGetMemoryKeyHomeByNamespacedKey() { - Assert.assertEquals(MemoryKey.HOME, MemoryKey.getByKey(NamespacedKey.minecraft("home"))); + assertEquals(MemoryKey.HOME, MemoryKey.getByKey(NamespacedKey.minecraft("home"))); } @Test public void shouldGetMemoryKeyJobSiteByNamespacedKey() { - Assert.assertEquals(MemoryKey.JOB_SITE, MemoryKey.getByKey(NamespacedKey.minecraft("job_site"))); + assertEquals(MemoryKey.JOB_SITE, MemoryKey.getByKey(NamespacedKey.minecraft("job_site"))); } @Test public void shouldGetMemoryKeyMeetingPointByNamespacedKey() { - Assert.assertEquals(MemoryKey.MEETING_POINT, MemoryKey.getByKey(NamespacedKey.minecraft("meeting_point"))); + assertEquals(MemoryKey.MEETING_POINT, MemoryKey.getByKey(NamespacedKey.minecraft("meeting_point"))); } @Test public void shouldReturnNullWhenNamespacedKeyisNotPresentAsMemoryKey() { - Assert.assertEquals(null, MemoryKey.getByKey(NamespacedKey.minecraft("not_present"))); + assertNull(MemoryKey.getByKey(NamespacedKey.minecraft("not_present"))); } @Test public void shouldReturnNullWhenNamespacedKeyisNull() { - Assert.assertNull(MemoryKey.getByKey(null)); + assertNull(MemoryKey.getByKey(null)); } } diff --git a/paper-api/src/test/java/org/bukkit/event/PlayerChatTabCompleteEventTest.java b/paper-api/src/test/java/org/bukkit/event/PlayerChatTabCompleteEventTest.java index 80c0bfbd2..346214f24 100644 --- a/paper-api/src/test/java/org/bukkit/event/PlayerChatTabCompleteEventTest.java +++ b/paper-api/src/test/java/org/bukkit/event/PlayerChatTabCompleteEventTest.java @@ -1,11 +1,11 @@ package org.bukkit.event; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.bukkit.support.MatcherAssert.*; +import static org.hamcrest.Matchers.*; import static org.mockito.Mockito.*; import com.google.common.collect.ImmutableList; import org.bukkit.event.player.PlayerChatTabCompleteEvent; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PlayerChatTabCompleteEventTest { diff --git a/paper-api/src/test/java/org/bukkit/event/SyntheticEventTest.java b/paper-api/src/test/java/org/bukkit/event/SyntheticEventTest.java index ab53cf143..40a086f28 100644 --- a/paper-api/src/test/java/org/bukkit/event/SyntheticEventTest.java +++ b/paper-api/src/test/java/org/bukkit/event/SyntheticEventTest.java @@ -1,13 +1,13 @@ package org.bukkit.event; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginLoader; import org.bukkit.plugin.SimplePluginManager; import org.bukkit.plugin.TestPlugin; import org.bukkit.plugin.java.JavaPluginLoader; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SyntheticEventTest extends AbstractTestingBase { @SuppressWarnings("deprecation") @@ -28,7 +28,7 @@ public class SyntheticEventTest extends AbstractTestingBase { pluginManager.registerEvents(impl, plugin); pluginManager.callEvent(event); - Assert.assertEquals(1, impl.callCount); + assertEquals(1, impl.callCount); } public abstract static class Base implements Listener { diff --git a/paper-api/src/test/java/org/bukkit/materials/MaterialDataTest.java b/paper-api/src/test/java/org/bukkit/materials/MaterialDataTest.java index a935ae4a2..8d78435cc 100644 --- a/paper-api/src/test/java/org/bukkit/materials/MaterialDataTest.java +++ b/paper-api/src/test/java/org/bukkit/materials/MaterialDataTest.java @@ -1,7 +1,7 @@ package org.bukkit.materials; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import org.bukkit.CropState; import org.bukkit.Material; import org.bukkit.NetherWartsState; @@ -20,7 +20,7 @@ import org.bukkit.material.Tree; import org.bukkit.material.Wood; import org.bukkit.material.WoodenStep; import org.bukkit.material.types.MushroomBlockTexture; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MaterialDataTest { @@ -28,10 +28,10 @@ public class MaterialDataTest { public void testDoor() { @SuppressWarnings("deprecation") Door door = new Door(); - assertThat("Constructed with default door type", door.getItemType(), equalTo(Material.LEGACY_WOODEN_DOOR)); - assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(false)); - assertThat("Constructed with default direction", door.getFacing(), equalTo(BlockFace.WEST)); - assertThat("Constructed with default open state", door.isOpen(), equalTo(false)); + assertThat(door.getItemType(), equalTo(Material.LEGACY_WOODEN_DOOR), "Constructed with default door type"); + assertThat(door.isTopHalf(), equalTo(false), "Constructed with default top or bottom"); + assertThat(door.getFacing(), equalTo(BlockFace.WEST), "Constructed with default direction"); + assertThat(door.isOpen(), equalTo(false), "Constructed with default open state"); Material[] types = new Material[]{Material.LEGACY_WOODEN_DOOR, Material.LEGACY_IRON_DOOR_BLOCK, Material.LEGACY_SPRUCE_DOOR, @@ -44,26 +44,26 @@ public class MaterialDataTest { // Test bottom half for (BlockFace facing : directions) { door = new Door(type, facing); - assertThat("Constructed with correct door type", door.getItemType(), equalTo(type)); - assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(false)); - assertThat("Constructed with correct direction", door.getFacing(), equalTo(facing)); - assertThat("Constructed with default open state", door.isOpen(), equalTo(false)); + assertThat(door.getItemType(), equalTo(type), "Constructed with correct door type"); + assertThat(door.isTopHalf(), equalTo(false), "Constructed with default top or bottom"); + assertThat(door.getFacing(), equalTo(facing), "Constructed with correct direction"); + assertThat(door.isOpen(), equalTo(false), "Constructed with default open state"); for (boolean openState : openStates) { door = new Door(type, facing, openState); - assertThat("Constructed with correct door type", door.getItemType(), equalTo(type)); - assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(false)); - assertThat("Constructed with correct direction", door.getFacing(), equalTo(facing)); - assertThat("Constructed with correct open state", door.isOpen(), equalTo(openState)); + assertThat(door.getItemType(), equalTo(type), "Constructed with correct door type"); + assertThat(door.isTopHalf(), equalTo(false), "Constructed with default top or bottom"); + assertThat(door.getFacing(), equalTo(facing), "Constructed with correct direction"); + assertThat(door.isOpen(), equalTo(openState), "Constructed with correct open state"); } } // Test top half for (boolean hingeState : hingeStates) { door = new Door(type, hingeState); - assertThat("Constructed with correct door type", door.getItemType(), equalTo(type)); - assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(true)); - assertThat("Constructed with correct direction", door.getHinge(), equalTo(hingeState)); + assertThat(door.getItemType(), equalTo(type), "Constructed with correct door type"); + assertThat(door.isTopHalf(), equalTo(true), "Constructed with default top or bottom"); + assertThat(door.getHinge(), equalTo(hingeState), "Constructed with correct direction"); } } } @@ -71,26 +71,26 @@ public class MaterialDataTest { @Test public void testWood() { Wood wood = new Wood(); - assertThat("Constructed with default wood type", wood.getItemType(), equalTo(Material.LEGACY_WOOD)); - assertThat("Constructed with default tree species", wood.getSpecies(), equalTo(TreeSpecies.GENERIC)); + assertThat(wood.getItemType(), equalTo(Material.LEGACY_WOOD), "Constructed with default wood type"); + assertThat(wood.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species"); TreeSpecies[] allSpecies = TreeSpecies.values(); for (TreeSpecies species : allSpecies) { wood = new Wood(species); - assertThat("Constructed with default wood type", wood.getItemType(), equalTo(Material.LEGACY_WOOD)); - assertThat("Constructed with correct tree species", wood.getSpecies(), equalTo(species)); + assertThat(wood.getItemType(), equalTo(Material.LEGACY_WOOD), "Constructed with default wood type"); + assertThat(wood.getSpecies(), equalTo(species), "Constructed with correct tree species"); } Material[] types = new Material[]{Material.LEGACY_WOOD, Material.LEGACY_WOOD_DOUBLE_STEP}; for (Material type : types) { wood = new Wood(type); - assertThat("Constructed with correct wood type", wood.getItemType(), equalTo(type)); - assertThat("Constructed with default tree species", wood.getSpecies(), equalTo(TreeSpecies.GENERIC)); + assertThat(wood.getItemType(), equalTo(type), "Constructed with correct wood type"); + assertThat(wood.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species"); for (TreeSpecies species : allSpecies) { wood = new Wood(type, species); - assertThat("Constructed with correct wood type", wood.getItemType(), equalTo(type)); - assertThat("Constructed with correct tree species", wood.getSpecies(), equalTo(species)); + assertThat(wood.getItemType(), equalTo(type), "Constructed with correct wood type"); + assertThat(wood.getSpecies(), equalTo(species), "Constructed with correct tree species"); } } } @@ -98,14 +98,14 @@ public class MaterialDataTest { @Test public void testTree() { Tree tree = new Tree(); - assertThat("Constructed with default tree type", tree.getItemType(), equalTo(Material.LEGACY_LOG)); - assertThat("Constructed with default tree species", tree.getSpecies(), equalTo(TreeSpecies.GENERIC)); - assertThat("Constructed with default direction", tree.getDirection(), equalTo(BlockFace.UP)); + assertThat(tree.getItemType(), equalTo(Material.LEGACY_LOG), "Constructed with default tree type"); + assertThat(tree.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species"); + assertThat(tree.getDirection(), equalTo(BlockFace.UP), "Constructed with default direction"); tree = new Tree(Material.LEGACY_LOG); - assertThat("Constructed with correct tree type", tree.getItemType(), equalTo(Material.LEGACY_LOG)); - assertThat("Constructed with default tree species", tree.getSpecies(), equalTo(TreeSpecies.GENERIC)); - assertThat("Constructed with default direction", tree.getDirection(), equalTo(BlockFace.UP)); + assertThat(tree.getItemType(), equalTo(Material.LEGACY_LOG), "Constructed with correct tree type"); + assertThat(tree.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species"); + assertThat(tree.getDirection(), equalTo(BlockFace.UP), "Constructed with default direction"); Material[] types = new Material[]{Material.LEGACY_LOG, Material.LEGACY_LOG_2}; TreeSpecies[][] allSpecies = new TreeSpecies[][]{ @@ -116,20 +116,20 @@ public class MaterialDataTest { for (int t = 0; t < types.length; t++) { for (TreeSpecies species : allSpecies[t]) { tree = new Tree(types[t], species); - assertThat("Constructed with correct tree type", tree.getItemType(), equalTo(types[t])); - assertThat("Constructed with correct tree species", tree.getSpecies(), equalTo(species)); - assertThat("Constructed with default direction", tree.getDirection(), equalTo(BlockFace.UP)); + assertThat(tree.getItemType(), equalTo(types[t]), "Constructed with correct tree type"); + assertThat(tree.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(tree.getDirection(), equalTo(BlockFace.UP), "Constructed with default direction"); // check item type is fixed automatically for invalid type-species combo tree = new Tree(types[types.length - 1 - t], species); - assertThat("Constructed with fixed tree type", tree.getItemType(), equalTo(types[t])); - assertThat("Constructed with correct tree species", tree.getSpecies(), equalTo(species)); - assertThat("Constructed with default direction", tree.getDirection(), equalTo(BlockFace.UP)); + assertThat(tree.getItemType(), equalTo(types[t]), "Constructed with fixed tree type"); + assertThat(tree.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(tree.getDirection(), equalTo(BlockFace.UP), "Constructed with default direction"); for (BlockFace dir : allDirections) { tree = new Tree(types[t], species, dir); - assertThat("Constructed with correct tree type", tree.getItemType(), equalTo(types[t])); - assertThat("Constructed with correct tree species", tree.getSpecies(), equalTo(species)); - assertThat("Constructed with correct direction", tree.getDirection(), equalTo(dir)); + assertThat(tree.getItemType(), equalTo(types[t]), "Constructed with correct tree type"); + assertThat(tree.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(tree.getDirection(), equalTo(dir), "Constructed with correct direction"); } } } @@ -138,16 +138,16 @@ public class MaterialDataTest { @Test public void testLeaves() { Leaves leaves = new Leaves(); - assertThat("Constructed with default leaf type", leaves.getItemType(), equalTo(Material.LEGACY_LEAVES)); - assertThat("Constructed with default tree species", leaves.getSpecies(), equalTo(TreeSpecies.GENERIC)); - assertThat("Constructed with default decayable", leaves.isDecayable(), equalTo(true)); - assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); + assertThat(leaves.getItemType(), equalTo(Material.LEGACY_LEAVES), "Constructed with default leaf type"); + assertThat(leaves.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species"); + assertThat(leaves.isDecayable(), equalTo(true), "Constructed with default decayable"); + assertThat(leaves.isDecaying(), equalTo(false), "Constructed with default decaying"); leaves = new Leaves(Material.LEGACY_LEAVES); - assertThat("Constructed with correct leaf type", leaves.getItemType(), equalTo(Material.LEGACY_LEAVES)); - assertThat("Constructed with default tree species", leaves.getSpecies(), equalTo(TreeSpecies.GENERIC)); - assertThat("Constructed with default decayable", leaves.isDecayable(), equalTo(true)); - assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); + assertThat(leaves.getItemType(), equalTo(Material.LEGACY_LEAVES), "Constructed with correct leaf type"); + assertThat(leaves.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species"); + assertThat(leaves.isDecayable(), equalTo(true), "Constructed with default decayable"); + assertThat(leaves.isDecaying(), equalTo(false), "Constructed with default decaying"); Material[] types = new Material[]{Material.LEGACY_LEAVES, Material.LEGACY_LEAVES_2}; TreeSpecies[][] allSpecies = new TreeSpecies[][]{ @@ -159,30 +159,30 @@ public class MaterialDataTest { for (int t = 0; t < types.length; t++) { for (TreeSpecies species : allSpecies[t]) { leaves = new Leaves(types[t], species); - assertThat("Constructed with correct leaf type", leaves.getItemType(), equalTo(types[t])); - assertThat("Constructed with correct tree species", leaves.getSpecies(), equalTo(species)); - assertThat("Constructed with default decayable", leaves.isDecayable(), equalTo(true)); - assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); + assertThat(leaves.getItemType(), equalTo(types[t]), "Constructed with correct leaf type"); + assertThat(leaves.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(leaves.isDecayable(), equalTo(true), "Constructed with default decayable"); + assertThat(leaves.isDecaying(), equalTo(false), "Constructed with default decaying"); // check item type is fixed automatically for invalid type-species combo leaves = new Leaves(types[types.length - 1 - t], species); - assertThat("Constructed with fixed leaf type", leaves.getItemType(), equalTo(types[t])); - assertThat("Constructed with correct tree species", leaves.getSpecies(), equalTo(species)); - assertThat("Constructed with default decayable", leaves.isDecayable(), equalTo(true)); - assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); + assertThat(leaves.getItemType(), equalTo(types[t]), "Constructed with fixed leaf type"); + assertThat(leaves.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(leaves.isDecayable(), equalTo(true), "Constructed with default decayable"); + assertThat(leaves.isDecaying(), equalTo(false), "Constructed with default decaying"); for (boolean isDecayable : decayable) { leaves = new Leaves(types[t], species, isDecayable); - assertThat("Constructed with correct wood type", leaves.getItemType(), equalTo(types[t])); - assertThat("Constructed with correct tree species", leaves.getSpecies(), equalTo(species)); - assertThat("Constructed with correct decayable", leaves.isDecayable(), equalTo(isDecayable)); - assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); + assertThat(leaves.getItemType(), equalTo(types[t]), "Constructed with correct wood type"); + assertThat(leaves.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(leaves.isDecayable(), equalTo(isDecayable), "Constructed with correct decayable"); + assertThat(leaves.isDecaying(), equalTo(false), "Constructed with default decaying"); for (boolean isDecaying : decaying) { leaves = new Leaves(types[t], species, isDecayable); leaves.setDecaying(isDecaying); - assertThat("Constructed with correct wood type", leaves.getItemType(), equalTo(types[t])); - assertThat("Constructed with correct tree species", leaves.getSpecies(), equalTo(species)); - assertThat("Constructed with correct decayable", leaves.isDecayable(), equalTo(isDecaying || isDecayable)); - assertThat("Constructed with correct decaying", leaves.isDecaying(), equalTo(isDecaying)); + assertThat(leaves.getItemType(), equalTo(types[t]), "Constructed with correct wood type"); + assertThat(leaves.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(leaves.isDecayable(), equalTo(isDecaying || isDecayable), "Constructed with correct decayable"); + assertThat(leaves.isDecaying(), equalTo(isDecaying), "Constructed with correct decaying"); } } } @@ -192,22 +192,22 @@ public class MaterialDataTest { @Test public void testWoodenStep() { WoodenStep woodenStep = new WoodenStep(); - assertThat("Constructed with default step type", woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP)); - assertThat("Constructed with default tree species", woodenStep.getSpecies(), equalTo(TreeSpecies.GENERIC)); - assertThat("Constructed with default inversion", woodenStep.isInverted(), equalTo(false)); + assertThat(woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP), "Constructed with default step type"); + assertThat(woodenStep.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species"); + assertThat(woodenStep.isInverted(), equalTo(false), "Constructed with default inversion"); TreeSpecies[] allSpecies = TreeSpecies.values(); boolean[] inversion = new boolean[]{true, false}; for (TreeSpecies species : allSpecies) { woodenStep = new WoodenStep(species); - assertThat("Constructed with default step type", woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP)); - assertThat("Constructed with correct tree species", woodenStep.getSpecies(), equalTo(species)); - assertThat("Constructed with default inversion", woodenStep.isInverted(), equalTo(false)); + assertThat(woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP), "Constructed with default step type"); + assertThat(woodenStep.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(woodenStep.isInverted(), equalTo(false), "Constructed with default inversion"); for (boolean isInverted : inversion) { woodenStep = new WoodenStep(species, isInverted); - assertThat("Constructed with default step type", woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP)); - assertThat("Constructed with correct tree species", woodenStep.getSpecies(), equalTo(species)); - assertThat("Constructed with correct inversion", woodenStep.isInverted(), equalTo(isInverted)); + assertThat(woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP), "Constructed with default step type"); + assertThat(woodenStep.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(woodenStep.isInverted(), equalTo(isInverted), "Constructed with correct inversion"); } } } @@ -215,22 +215,22 @@ public class MaterialDataTest { @Test public void testSapling() { Sapling sapling = new Sapling(); - assertThat("Constructed with default sapling type", sapling.getItemType(), equalTo(Material.LEGACY_SAPLING)); - assertThat("Constructed with default tree species", sapling.getSpecies(), equalTo(TreeSpecies.GENERIC)); - assertThat("Constructed with default growable", sapling.isInstantGrowable(), equalTo(false)); + assertThat(sapling.getItemType(), equalTo(Material.LEGACY_SAPLING), "Constructed with default sapling type"); + assertThat(sapling.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species"); + assertThat(sapling.isInstantGrowable(), equalTo(false), "Constructed with default growable"); TreeSpecies[] allSpecies = TreeSpecies.values(); boolean[] growable = new boolean[]{true, false}; for (TreeSpecies species : allSpecies) { sapling = new Sapling(species); - assertThat("Constructed with default sapling type", sapling.getItemType(), equalTo(Material.LEGACY_SAPLING)); - assertThat("Constructed with correct tree species", sapling.getSpecies(), equalTo(species)); - assertThat("Constructed with default growable", sapling.isInstantGrowable(), equalTo(false)); + assertThat(sapling.getItemType(), equalTo(Material.LEGACY_SAPLING), "Constructed with default sapling type"); + assertThat(sapling.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(sapling.isInstantGrowable(), equalTo(false), "Constructed with default growable"); for (boolean isInstantGrowable : growable) { sapling = new Sapling(species, isInstantGrowable); - assertThat("Constructed with default sapling type", sapling.getItemType(), equalTo(Material.LEGACY_SAPLING)); - assertThat("Constructed with correct tree species", sapling.getSpecies(), equalTo(species)); - assertThat("Constructed with correct growable", sapling.isInstantGrowable(), equalTo(isInstantGrowable)); + assertThat(sapling.getItemType(), equalTo(Material.LEGACY_SAPLING), "Constructed with default sapling type"); + assertThat(sapling.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(sapling.isInstantGrowable(), equalTo(isInstantGrowable), "Constructed with correct growable"); } } } @@ -244,19 +244,19 @@ public class MaterialDataTest { MushroomBlockTexture[] textures = MushroomBlockTexture.values(); for (Material type : mushroomTypes) { Mushroom mushroom = new Mushroom(type); - assertThat("Constructed with correct mushroom type", mushroom.getItemType(), equalTo(type)); - assertThat("Constructed with default pores face", mushroom.getBlockTexture(), equalTo(MushroomBlockTexture.ALL_PORES)); + assertThat(mushroom.getItemType(), equalTo(type), "Constructed with correct mushroom type"); + assertThat(mushroom.getBlockTexture(), equalTo(MushroomBlockTexture.ALL_PORES), "Constructed with default pores face"); for (int f = 0; f < setFaces.length; f++) { mushroom = new Mushroom(type, setFaces[f]); - assertThat("Constructed with correct mushroom type", mushroom.getItemType(), equalTo(type)); - assertThat("Constructed with correct texture", mushroom.getBlockTexture(), equalTo(MushroomBlockTexture.getCapByFace(setFaces[f]))); + assertThat(mushroom.getItemType(), equalTo(type), "Constructed with correct mushroom type"); + assertThat(mushroom.getBlockTexture(), equalTo(MushroomBlockTexture.getCapByFace(setFaces[f])), "Constructed with correct texture"); } for (MushroomBlockTexture texture : textures) { mushroom = new Mushroom(type, texture); - assertThat("Constructed with correct mushroom type", mushroom.getItemType(), equalTo(type)); - assertThat("Constructed with correct texture", mushroom.getBlockTexture(), equalTo(texture)); + assertThat(mushroom.getItemType(), equalTo(type), "Constructed with correct mushroom type"); + assertThat(mushroom.getBlockTexture(), equalTo(texture), "Constructed with correct texture"); } } } @@ -264,90 +264,90 @@ public class MaterialDataTest { @Test public void testCrops() { Crops crops = new Crops(); - assertThat("Constructed with default crops type", crops.getItemType(), equalTo(Material.LEGACY_CROPS)); - assertThat("Constructed with default crop state", crops.getState(), equalTo(CropState.SEEDED)); + assertThat(crops.getItemType(), equalTo(Material.LEGACY_CROPS), "Constructed with default crops type"); + assertThat(crops.getState(), equalTo(CropState.SEEDED), "Constructed with default crop state"); CropState[] allStates = CropState.values(); for (CropState state : allStates) { crops = new Crops(state); - assertThat("Constructed with default crops type", crops.getItemType(), equalTo(Material.LEGACY_CROPS)); - assertThat("Constructed with correct crop state", crops.getState(), equalTo(state)); + assertThat(crops.getItemType(), equalTo(Material.LEGACY_CROPS), "Constructed with default crops type"); + assertThat(crops.getState(), equalTo(state), "Constructed with correct crop state"); } // The crops which fully implement all crop states Material[] allCrops = new Material[]{Material.LEGACY_CROPS, Material.LEGACY_CARROT, Material.LEGACY_POTATO}; for (Material crop : allCrops) { crops = new Crops(crop); - assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(crop)); - assertThat("Constructed with default crop state", crops.getState(), equalTo(CropState.SEEDED)); + assertThat(crops.getItemType(), equalTo(crop), "Constructed with correct crops type"); + assertThat(crops.getState(), equalTo(CropState.SEEDED), "Constructed with default crop state"); for (CropState state : allStates) { crops = new Crops(crop, state); - assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(crop)); - assertThat("Constructed with correct crop state", crops.getState(), equalTo(state)); + assertThat(crops.getItemType(), equalTo(crop), "Constructed with correct crops type"); + assertThat(crops.getState(), equalTo(state), "Constructed with correct crop state"); } } // Beetroot are crops too, but they only have four states // Setting different crop states for beetroot will return the following when retrieved back CropState[] beetrootStates = new CropState[]{CropState.SEEDED, CropState.SEEDED, CropState.SMALL, CropState.SMALL, CropState.TALL, CropState.TALL, CropState.RIPE, CropState.RIPE}; - assertThat("Beetroot state translations match size", beetrootStates.length, equalTo(allStates.length)); + assertThat(beetrootStates.length, equalTo(allStates.length), "Beetroot state translations match size"); crops = new Crops(Material.LEGACY_BEETROOT_BLOCK); - assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(Material.LEGACY_BEETROOT_BLOCK)); - assertThat("Constructed with default crop state", crops.getState(), equalTo(CropState.SEEDED)); + assertThat(crops.getItemType(), equalTo(Material.LEGACY_BEETROOT_BLOCK), "Constructed with correct crops type"); + assertThat(crops.getState(), equalTo(CropState.SEEDED), "Constructed with default crop state"); for (int s = 0; s < beetrootStates.length; s++) { crops = new Crops(Material.LEGACY_BEETROOT_BLOCK, allStates[s]); - assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(Material.LEGACY_BEETROOT_BLOCK)); - assertThat("Constructed with correct crop state", crops.getState(), equalTo(beetrootStates[s])); + assertThat(crops.getItemType(), equalTo(Material.LEGACY_BEETROOT_BLOCK), "Constructed with correct crops type"); + assertThat(crops.getState(), equalTo(beetrootStates[s]), "Constructed with correct crop state"); } // In case you want to treat NetherWarts as Crops, although they really aren't crops = new Crops(Material.LEGACY_NETHER_WARTS); NetherWarts warts = new NetherWarts(); - assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(warts.getItemType())); - assertThat("Constructed with default crop state", crops.getState(), equalTo(CropState.SEEDED)); - assertThat("Constructed with default wart state", warts.getState(), equalTo(NetherWartsState.SEEDED)); + assertThat(crops.getItemType(), equalTo(warts.getItemType()), "Constructed with correct crops type"); + assertThat(crops.getState(), equalTo(CropState.SEEDED), "Constructed with default crop state"); + assertThat(warts.getState(), equalTo(NetherWartsState.SEEDED), "Constructed with default wart state"); allStates = new CropState[]{CropState.SEEDED, CropState.SMALL, CropState.TALL, CropState.RIPE}; NetherWartsState[] allWartStates = NetherWartsState.values(); - assertThat("Nether Warts state translations match size", allWartStates.length, equalTo(allStates.length)); + assertThat(allWartStates.length, equalTo(allStates.length), "Nether Warts state translations match size"); for (int s = 0; s < allStates.length; s++) { crops = new Crops(Material.LEGACY_NETHER_WARTS, allStates[s]); warts = new NetherWarts(allWartStates[s]); - assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(warts.getItemType())); - assertThat("Constructed with correct crop state", crops.getState(), equalTo(allStates[s])); - assertThat("Constructed with correct wart state", warts.getState(), equalTo(allWartStates[s])); + assertThat(crops.getItemType(), equalTo(warts.getItemType()), "Constructed with correct crops type"); + assertThat(crops.getState(), equalTo(allStates[s]), "Constructed with correct crop state"); + assertThat(warts.getState(), equalTo(allWartStates[s]), "Constructed with correct wart state"); } } @Test public void testDiode() { Diode diode = new Diode(); - assertThat("Constructed with backward compatible diode state", diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_ON)); - assertThat("Constructed with backward compatible powered", diode.isPowered(), equalTo(true)); - assertThat("Constructed with default delay", diode.getDelay(), equalTo(1)); - assertThat("Constructed with default direction", diode.getFacing(), equalTo(BlockFace.NORTH)); + assertThat(diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_ON), "Constructed with backward compatible diode state"); + assertThat(diode.isPowered(), equalTo(true), "Constructed with backward compatible powered"); + assertThat(diode.getDelay(), equalTo(1), "Constructed with default delay"); + assertThat(diode.getFacing(), equalTo(BlockFace.NORTH), "Constructed with default direction"); BlockFace[] directions = new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST}; int[] delays = new int[]{1, 2, 3, 4}; boolean[] states = new boolean[]{false, true}; for (BlockFace direction : directions) { diode = new Diode(direction); - assertThat("Constructed with default diode state", diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_OFF)); - assertThat("Constructed with default powered", diode.isPowered(), equalTo(false)); - assertThat("Constructed with default delay", diode.getDelay(), equalTo(1)); - assertThat("Constructed with correct direction", diode.getFacing(), equalTo(direction)); + assertThat(diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_OFF), "Constructed with default diode state"); + assertThat(diode.isPowered(), equalTo(false), "Constructed with default powered"); + assertThat(diode.getDelay(), equalTo(1), "Constructed with default delay"); + assertThat(diode.getFacing(), equalTo(direction), "Constructed with correct direction"); for (int delay : delays) { diode = new Diode(direction, delay); - assertThat("Constructed with default diode state", diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_OFF)); - assertThat("Constructed with default powered", diode.isPowered(), equalTo(false)); - assertThat("Constructed with correct delay", diode.getDelay(), equalTo(delay)); - assertThat("Constructed with correct direction", diode.getFacing(), equalTo(direction)); + assertThat(diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_OFF), "Constructed with default diode state"); + assertThat(diode.isPowered(), equalTo(false), "Constructed with default powered"); + assertThat(diode.getDelay(), equalTo(delay), "Constructed with correct delay"); + assertThat(diode.getFacing(), equalTo(direction), "Constructed with correct direction"); for (boolean state : states) { diode = new Diode(direction, delay, state); - assertThat("Constructed with correct diode state", diode.getItemType(), equalTo(state ? Material.LEGACY_DIODE_BLOCK_ON : Material.LEGACY_DIODE_BLOCK_OFF)); - assertThat("Constructed with default powered", diode.isPowered(), equalTo(state)); - assertThat("Constructed with correct delay", diode.getDelay(), equalTo(delay)); - assertThat("Constructed with correct direction", diode.getFacing(), equalTo(direction)); + assertThat(diode.getItemType(), equalTo(state ? Material.LEGACY_DIODE_BLOCK_ON : Material.LEGACY_DIODE_BLOCK_OFF), "Constructed with correct diode state"); + assertThat(diode.isPowered(), equalTo(state), "Constructed with default powered"); + assertThat(diode.getDelay(), equalTo(delay), "Constructed with correct delay"); + assertThat(diode.getFacing(), equalTo(direction), "Constructed with correct direction"); } } } @@ -356,44 +356,44 @@ public class MaterialDataTest { @Test public void testComparator() { Comparator comparator = new Comparator(); - assertThat("Constructed with default comparator state", comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF)); - assertThat("Constructed with default powered", comparator.isPowered(), equalTo(false)); - assertThat("Constructed with default being powered", comparator.isBeingPowered(), equalTo(false)); - assertThat("Constructed with default mode", comparator.isSubtractionMode(), equalTo(false)); - assertThat("Constructed with default direction", comparator.getFacing(), equalTo(BlockFace.NORTH)); + assertThat(comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF), "Constructed with default comparator state"); + assertThat(comparator.isPowered(), equalTo(false), "Constructed with default powered"); + assertThat(comparator.isBeingPowered(), equalTo(false), "Constructed with default being powered"); + assertThat(comparator.isSubtractionMode(), equalTo(false), "Constructed with default mode"); + assertThat(comparator.getFacing(), equalTo(BlockFace.NORTH), "Constructed with default direction"); BlockFace[] directions = new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST}; boolean[] modes = new boolean[]{false, true}; boolean[] states = new boolean[]{false, true}; for (BlockFace direction : directions) { comparator = new Comparator(direction); - assertThat("Constructed with default comparator state", comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF)); - assertThat("Constructed with default powered", comparator.isPowered(), equalTo(false)); - assertThat("Constructed with default being powered", comparator.isBeingPowered(), equalTo(false)); - assertThat("Constructed with default mode", comparator.isSubtractionMode(), equalTo(false)); - assertThat("Constructed with correct direction", comparator.getFacing(), equalTo(direction)); + assertThat(comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF), "Constructed with default comparator state"); + assertThat(comparator.isPowered(), equalTo(false), "Constructed with default powered"); + assertThat(comparator.isBeingPowered(), equalTo(false), "Constructed with default being powered"); + assertThat(comparator.isSubtractionMode(), equalTo(false), "Constructed with default mode"); + assertThat(comparator.getFacing(), equalTo(direction), "Constructed with correct direction"); for (boolean mode : modes) { comparator = new Comparator(direction, mode); - assertThat("Constructed with default comparator state", comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF)); - assertThat("Constructed with default powered", comparator.isPowered(), equalTo(false)); - assertThat("Constructed with default being powered", comparator.isBeingPowered(), equalTo(false)); - assertThat("Constructed with correct mode", comparator.isSubtractionMode(), equalTo(mode)); - assertThat("Constructed with correct direction", comparator.getFacing(), equalTo(direction)); + assertThat(comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF), "Constructed with default comparator state"); + assertThat(comparator.isPowered(), equalTo(false), "Constructed with default powered"); + assertThat(comparator.isBeingPowered(), equalTo(false), "Constructed with default being powered"); + assertThat(comparator.isSubtractionMode(), equalTo(mode), "Constructed with correct mode"); + assertThat(comparator.getFacing(), equalTo(direction), "Constructed with correct direction"); for (boolean state : states) { comparator = new Comparator(direction, mode, state); - assertThat("Constructed with correct comparator state", comparator.getItemType(), equalTo(state ? Material.LEGACY_REDSTONE_COMPARATOR_ON : Material.LEGACY_REDSTONE_COMPARATOR_OFF)); - assertThat("Constructed with correct powered", comparator.isPowered(), equalTo(state)); - assertThat("Constructed with default being powered", comparator.isBeingPowered(), equalTo(false)); - assertThat("Constructed with correct mode", comparator.isSubtractionMode(), equalTo(mode)); - assertThat("Constructed with correct direction", comparator.getFacing(), equalTo(direction)); + assertThat(comparator.getItemType(), equalTo(state ? Material.LEGACY_REDSTONE_COMPARATOR_ON : Material.LEGACY_REDSTONE_COMPARATOR_OFF), "Constructed with correct comparator state"); + assertThat(comparator.isPowered(), equalTo(state), "Constructed with correct powered"); + assertThat(comparator.isBeingPowered(), equalTo(false), "Constructed with default being powered"); + assertThat(comparator.isSubtractionMode(), equalTo(mode), "Constructed with correct mode"); + assertThat(comparator.getFacing(), equalTo(direction), "Constructed with correct direction"); // Check if the game sets the fourth bit, that block data is still interpreted correctly comparator.setData((byte) ((comparator.getData() & 0x7) | 0x8)); - assertThat("Constructed with correct comparator state", comparator.getItemType(), equalTo(state ? Material.LEGACY_REDSTONE_COMPARATOR_ON : Material.LEGACY_REDSTONE_COMPARATOR_OFF)); - assertThat("Constructed with correct powered", comparator.isPowered(), equalTo(state)); - assertThat("Constructed with correct being powered", comparator.isBeingPowered(), equalTo(true)); - assertThat("Constructed with correct mode", comparator.isSubtractionMode(), equalTo(mode)); - assertThat("Constructed with correct direction", comparator.getFacing(), equalTo(direction)); + assertThat(comparator.getItemType(), equalTo(state ? Material.LEGACY_REDSTONE_COMPARATOR_ON : Material.LEGACY_REDSTONE_COMPARATOR_OFF), "Constructed with correct comparator state"); + assertThat(comparator.isPowered(), equalTo(state), "Constructed with correct powered"); + assertThat(comparator.isBeingPowered(), equalTo(true), "Constructed with correct being powered"); + assertThat(comparator.isSubtractionMode(), equalTo(mode), "Constructed with correct mode"); + assertThat(comparator.getFacing(), equalTo(direction), "Constructed with correct direction"); } } } @@ -402,25 +402,25 @@ public class MaterialDataTest { @Test public void testHopper() { Hopper hopper = new Hopper(); - assertThat("Constructed with default hopper type", hopper.getItemType(), equalTo(Material.LEGACY_HOPPER)); - assertThat("Constructed with default active state", hopper.isActive(), equalTo(true)); - assertThat("Constructed with default powered state", hopper.isPowered(), equalTo(false)); - assertThat("Constructed with default direction", hopper.getFacing(), equalTo(BlockFace.DOWN)); + assertThat(hopper.getItemType(), equalTo(Material.LEGACY_HOPPER), "Constructed with default hopper type"); + assertThat(hopper.isActive(), equalTo(true), "Constructed with default active state"); + assertThat(hopper.isPowered(), equalTo(false), "Constructed with default powered state"); + assertThat(hopper.getFacing(), equalTo(BlockFace.DOWN), "Constructed with default direction"); BlockFace[] directions = new BlockFace[]{BlockFace.DOWN, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST, BlockFace.EAST}; boolean[] activeStates = new boolean[]{true, false}; for (BlockFace direction : directions) { hopper = new Hopper(direction); - assertThat("Constructed with default hopper type", hopper.getItemType(), equalTo(Material.LEGACY_HOPPER)); - assertThat("Constructed with default active state", hopper.isActive(), equalTo(true)); - assertThat("Constructed with correct powered state", hopper.isPowered(), equalTo(false)); - assertThat("Constructed with correct direction", hopper.getFacing(), equalTo(direction)); + assertThat(hopper.getItemType(), equalTo(Material.LEGACY_HOPPER), "Constructed with default hopper type"); + assertThat(hopper.isActive(), equalTo(true), "Constructed with default active state"); + assertThat(hopper.isPowered(), equalTo(false), "Constructed with correct powered state"); + assertThat(hopper.getFacing(), equalTo(direction), "Constructed with correct direction"); for (boolean isActive : activeStates) { hopper = new Hopper(direction, isActive); - assertThat("Constructed with default hopper type", hopper.getItemType(), equalTo(Material.LEGACY_HOPPER)); - assertThat("Constructed with correct active state", hopper.isActive(), equalTo(isActive)); - assertThat("Constructed with correct powered state", hopper.isPowered(), equalTo(!isActive)); - assertThat("Constructed with correct direction", hopper.getFacing(), equalTo(direction)); + assertThat(hopper.getItemType(), equalTo(Material.LEGACY_HOPPER), "Constructed with default hopper type"); + assertThat(hopper.isActive(), equalTo(isActive), "Constructed with correct active state"); + assertThat(hopper.isPowered(), equalTo(!isActive), "Constructed with correct powered state"); + assertThat(hopper.getFacing(), equalTo(direction), "Constructed with correct direction"); } } } diff --git a/paper-api/src/test/java/org/bukkit/metadata/FixedMetadataValueTest.java b/paper-api/src/test/java/org/bukkit/metadata/FixedMetadataValueTest.java index e8cea99fd..91584b94b 100644 --- a/paper-api/src/test/java/org/bukkit/metadata/FixedMetadataValueTest.java +++ b/paper-api/src/test/java/org/bukkit/metadata/FixedMetadataValueTest.java @@ -1,9 +1,9 @@ package org.bukkit.metadata; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.TestPlugin; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class FixedMetadataValueTest { private Plugin plugin = new TestPlugin("X"); @@ -21,7 +21,7 @@ public class FixedMetadataValueTest { subject = new FixedMetadataValue(plugin, new Integer(5)); assertEquals(new Integer(5), subject.value()); assertEquals(5, subject.asInt()); - assertEquals(true, subject.asBoolean()); + assertTrue(subject.asBoolean()); assertEquals(5, subject.asByte()); assertEquals(5.0, subject.asFloat(), 0.1e-8); assertEquals(5.0D, subject.asDouble(), 0.1e-8D); diff --git a/paper-api/src/test/java/org/bukkit/metadata/LazyMetadataValueTest.java b/paper-api/src/test/java/org/bukkit/metadata/LazyMetadataValueTest.java index bc8a18eea..dd2acf3f1 100644 --- a/paper-api/src/test/java/org/bukkit/metadata/LazyMetadataValueTest.java +++ b/paper-api/src/test/java/org/bukkit/metadata/LazyMetadataValueTest.java @@ -1,9 +1,9 @@ package org.bukkit.metadata; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.concurrent.Callable; import org.bukkit.plugin.TestPlugin; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class LazyMetadataValueTest { private LazyMetadataValue subject; @@ -41,7 +41,7 @@ public class LazyMetadataValueTest { assertEquals(value, subject.value()); } - @Test(expected = MetadataEvaluationException.class) + @Test public void testEvalException() { subject = new LazyMetadataValue(plugin, LazyMetadataValue.CacheStrategy.CACHE_AFTER_FIRST_EVAL, new Callable() { @Override @@ -49,7 +49,7 @@ public class LazyMetadataValueTest { throw new RuntimeException("Gotcha!"); } }); - subject.value(); + assertThrows(MetadataEvaluationException.class, () -> subject.value()); } @Test diff --git a/paper-api/src/test/java/org/bukkit/metadata/MetadataConversionTest.java b/paper-api/src/test/java/org/bukkit/metadata/MetadataConversionTest.java index a9c10a2fd..29546b621 100644 --- a/paper-api/src/test/java/org/bukkit/metadata/MetadataConversionTest.java +++ b/paper-api/src/test/java/org/bukkit/metadata/MetadataConversionTest.java @@ -15,10 +15,10 @@ package org.bukkit.metadata; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.TestPlugin; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** */ @@ -40,7 +40,7 @@ public class MetadataConversionTest { assertEquals(10, subject.asLong()); assertEquals(10, subject.asShort()); assertEquals(10, subject.asByte()); - assertEquals(true, subject.asBoolean()); + assertTrue(subject.asBoolean()); assertEquals("10", subject.asString()); } @@ -54,7 +54,7 @@ public class MetadataConversionTest { assertEquals(10, subject.asLong()); assertEquals(10, subject.asShort()); assertEquals(10, subject.asByte()); - assertEquals(true, subject.asBoolean()); + assertTrue(subject.asBoolean()); assertEquals("10.5", subject.asString()); } @@ -68,7 +68,7 @@ public class MetadataConversionTest { assertEquals(10, subject.asLong()); assertEquals(10, subject.asShort()); assertEquals(10, subject.asByte()); - assertEquals(false, subject.asBoolean()); + assertFalse(subject.asBoolean()); assertEquals("10", subject.asString()); } @@ -82,7 +82,7 @@ public class MetadataConversionTest { assertEquals(0, subject.asLong()); assertEquals(0, subject.asShort()); assertEquals(0, subject.asByte()); - assertEquals(true, subject.asBoolean()); + assertTrue(subject.asBoolean()); assertEquals("true", subject.asString()); } @@ -96,7 +96,7 @@ public class MetadataConversionTest { assertEquals(0, subject.asLong()); assertEquals(0, subject.asShort()); assertEquals(0, subject.asByte()); - assertEquals(false, subject.asBoolean()); + assertFalse(subject.asBoolean()); assertEquals("", subject.asString()); } } diff --git a/paper-api/src/test/java/org/bukkit/metadata/MetadataStoreTest.java b/paper-api/src/test/java/org/bukkit/metadata/MetadataStoreTest.java index 12373ff16..e52659f01 100644 --- a/paper-api/src/test/java/org/bukkit/metadata/MetadataStoreTest.java +++ b/paper-api/src/test/java/org/bukkit/metadata/MetadataStoreTest.java @@ -1,11 +1,11 @@ package org.bukkit.metadata; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.List; import java.util.concurrent.Callable; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.TestPlugin; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MetadataStoreTest { private Plugin pluginX = new TestPlugin("x"); diff --git a/paper-api/src/test/java/org/bukkit/metadata/MetadataValueAdapterTest.java b/paper-api/src/test/java/org/bukkit/metadata/MetadataValueAdapterTest.java index c1e78568a..2b6a53b2d 100644 --- a/paper-api/src/test/java/org/bukkit/metadata/MetadataValueAdapterTest.java +++ b/paper-api/src/test/java/org/bukkit/metadata/MetadataValueAdapterTest.java @@ -1,9 +1,9 @@ package org.bukkit.metadata; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.TestPlugin; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MetadataValueAdapterTest { private TestPlugin plugin = new TestPlugin("x"); @@ -38,25 +38,25 @@ public class MetadataValueAdapterTest { @Test public void testBooleanConversion() { // null is False. - assertEquals(false, simpleValue(null).asBoolean()); + assertFalse(simpleValue(null).asBoolean()); // String to boolean. - assertEquals(true, simpleValue("True").asBoolean()); - assertEquals(true, simpleValue("TRUE").asBoolean()); - assertEquals(false, simpleValue("false").asBoolean()); + assertTrue(simpleValue("True").asBoolean()); + assertTrue(simpleValue("TRUE").asBoolean()); + assertFalse(simpleValue("false").asBoolean()); // Number to boolean. - assertEquals(true, simpleValue(1).asBoolean()); - assertEquals(true, simpleValue(5.0).asBoolean()); - assertEquals(false, simpleValue(0).asBoolean()); - assertEquals(false, simpleValue(0.1).asBoolean()); + assertTrue(simpleValue(1).asBoolean()); + assertTrue(simpleValue(5.0).asBoolean()); + assertFalse(simpleValue(0).asBoolean()); + assertFalse(simpleValue(0.1).asBoolean()); // Boolean as boolean, of course. - assertEquals(true, simpleValue(Boolean.TRUE).asBoolean()); - assertEquals(false, simpleValue(Boolean.FALSE).asBoolean()); + assertTrue(simpleValue(Boolean.TRUE).asBoolean()); + assertFalse(simpleValue(Boolean.FALSE).asBoolean()); // any object that is not null and not a Boolean, String, or Number is true. - assertEquals(true, simpleValue(new Object()).asBoolean()); + assertTrue(simpleValue(new Object()).asBoolean()); } /** Test String conversions return an empty string when given null. */ diff --git a/paper-api/src/test/java/org/bukkit/plugin/PluginManagerTest.java b/paper-api/src/test/java/org/bukkit/plugin/PluginManagerTest.java index 4c61b180c..03b08e47e 100644 --- a/paper-api/src/test/java/org/bukkit/plugin/PluginManagerTest.java +++ b/paper-api/src/test/java/org/bukkit/plugin/PluginManagerTest.java @@ -1,14 +1,14 @@ package org.bukkit.plugin; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import org.bukkit.Bukkit; import org.bukkit.event.Event; import org.bukkit.event.TestEvent; import org.bukkit.permissions.Permission; import org.bukkit.support.AbstractTestingBase; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; public class PluginManagerTest extends AbstractTestingBase { private class MutableObject { @@ -164,20 +164,20 @@ public class PluginManagerTest extends AbstractTestingBase { private void testRemovePermissionByName(final String name) { final Permission perm = new Permission(name); pm.addPermission(perm); - assertThat("Permission \"" + name + "\" was not added", pm.getPermission(name), is(perm)); + assertThat(pm.getPermission(name), is(perm), "Permission \"" + name + "\" was not added"); pm.removePermission(name); - assertThat("Permission \"" + name + "\" was not removed", pm.getPermission(name), is(nullValue())); + assertThat(pm.getPermission(name), is(nullValue()), "Permission \"" + name + "\" was not removed"); } private void testRemovePermissionByPermission(final String name) { final Permission perm = new Permission(name); pm.addPermission(perm); - assertThat("Permission \"" + name + "\" was not added", pm.getPermission(name), is(perm)); + assertThat(pm.getPermission(name), is(perm), "Permission \"" + name + "\" was not added"); pm.removePermission(perm); - assertThat("Permission \"" + name + "\" was not removed", pm.getPermission(name), is(nullValue())); + assertThat(pm.getPermission(name), is(nullValue()), "Permission \"" + name + "\" was not removed"); } - @After + @AfterEach public void tearDown() { pm.clearPlugins(); assertThat(pm.getPermissions(), is(empty())); diff --git a/paper-api/src/test/java/org/bukkit/plugin/TimedRegisteredListenerTest.java b/paper-api/src/test/java/org/bukkit/plugin/TimedRegisteredListenerTest.java index 351fc4a9f..9ed416ed5 100644 --- a/paper-api/src/test/java/org/bukkit/plugin/TimedRegisteredListenerTest.java +++ b/paper-api/src/test/java/org/bukkit/plugin/TimedRegisteredListenerTest.java @@ -1,7 +1,7 @@ package org.bukkit.plugin; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import org.bukkit.event.Event; import org.bukkit.event.EventException; import org.bukkit.event.EventPriority; @@ -10,7 +10,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerMoveEvent; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TimedRegisteredListenerTest { diff --git a/paper-api/src/test/java/org/bukkit/plugin/messaging/StandardMessengerTest.java b/paper-api/src/test/java/org/bukkit/plugin/messaging/StandardMessengerTest.java index bf00b7a9d..144ae2f31 100644 --- a/paper-api/src/test/java/org/bukkit/plugin/messaging/StandardMessengerTest.java +++ b/paper-api/src/test/java/org/bukkit/plugin/messaging/StandardMessengerTest.java @@ -1,13 +1,13 @@ package org.bukkit.plugin.messaging; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.bukkit.support.MatcherAssert.*; +import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; import java.util.Collection; import org.bukkit.entity.Player; import org.bukkit.plugin.TestPlugin; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class StandardMessengerTest { public StandardMessenger getMessenger() { @@ -45,12 +45,12 @@ public class StandardMessengerTest { assertFalse(messenger.isOutgoingChannelRegistered(plugin, "test:foo")); } - @Test(expected = ReservedChannelException.class) + @Test public void testReservedOutgoingRegistration() { Messenger messenger = getMessenger(); TestPlugin plugin = getPlugin(); - messenger.registerOutgoingPluginChannel(plugin, "minecraft:register"); + assertThrows(ReservedChannelException.class, () -> messenger.registerOutgoingPluginChannel(plugin, "minecraft:register")); } @Test @@ -91,22 +91,22 @@ public class StandardMessengerTest { assertFalse(listener.hasReceived()); } - @Test(expected = ReservedChannelException.class) + @Test public void testReservedIncomingRegistration() { Messenger messenger = getMessenger(); TestPlugin plugin = getPlugin(); - messenger.registerIncomingPluginChannel(plugin, "minecraft:register", new TestMessageListener("test:foo", "test:bar".getBytes())); + assertThrows(ReservedChannelException.class, () -> messenger.registerIncomingPluginChannel(plugin, "minecraft:register", new TestMessageListener("test:foo", "test:bar".getBytes()))); } - @Test(expected = IllegalArgumentException.class) + @Test public void testDuplicateIncomingRegistration() { Messenger messenger = getMessenger(); TestPlugin plugin = getPlugin(); TestMessageListener listener = new TestMessageListener("test:foo", "test:bar".getBytes()); messenger.registerIncomingPluginChannel(plugin, "test:baz", listener); - messenger.registerIncomingPluginChannel(plugin, "test:baz", listener); + assertThrows(IllegalArgumentException.class, () -> messenger.registerIncomingPluginChannel(plugin, "test:baz", listener)); } @Test @@ -173,14 +173,14 @@ public class StandardMessengerTest { TestPlugin plugin1 = getPlugin(); TestPlugin plugin2 = getPlugin(); - assertEquals(messenger.getOutgoingChannels()); + assertCollectionEquals(messenger.getOutgoingChannels()); messenger.registerOutgoingPluginChannel(plugin1, "test:foo"); messenger.registerOutgoingPluginChannel(plugin1, "test:bar"); messenger.registerOutgoingPluginChannel(plugin2, "test:baz"); messenger.registerOutgoingPluginChannel(plugin2, "test:baz"); - assertEquals(messenger.getOutgoingChannels(), "test:foo", "test:bar", "test:baz"); + assertCollectionEquals(messenger.getOutgoingChannels(), "test:foo", "test:bar", "test:baz"); } @Test @@ -195,9 +195,9 @@ public class StandardMessengerTest { messenger.registerOutgoingPluginChannel(plugin2, "test:baz"); messenger.registerOutgoingPluginChannel(plugin2, "test:qux"); - assertEquals(messenger.getOutgoingChannels(plugin1), "test:foo", "test:bar"); - assertEquals(messenger.getOutgoingChannels(plugin2), "test:baz", "test:qux"); - assertEquals(messenger.getOutgoingChannels(plugin3)); + assertCollectionEquals(messenger.getOutgoingChannels(plugin1), "test:foo", "test:bar"); + assertCollectionEquals(messenger.getOutgoingChannels(plugin2), "test:baz", "test:qux"); + assertCollectionEquals(messenger.getOutgoingChannels(plugin3)); } @Test @@ -206,14 +206,14 @@ public class StandardMessengerTest { TestPlugin plugin1 = getPlugin(); TestPlugin plugin2 = getPlugin(); - assertEquals(messenger.getIncomingChannels()); + assertCollectionEquals(messenger.getIncomingChannels()); messenger.registerIncomingPluginChannel(plugin1, "test:foo", new TestMessageListener("test:foo", "test:bar".getBytes())); messenger.registerIncomingPluginChannel(plugin1, "test:bar", new TestMessageListener("test:foo", "test:bar".getBytes())); messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes())); messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes())); - assertEquals(messenger.getIncomingChannels(), "test:foo", "test:bar", "test:baz"); + assertCollectionEquals(messenger.getIncomingChannels(), "test:foo", "test:bar", "test:baz"); } @Test @@ -228,9 +228,9 @@ public class StandardMessengerTest { messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes())); messenger.registerIncomingPluginChannel(plugin2, "test:qux", new TestMessageListener("test:foo", "test:bar".getBytes())); - assertEquals(messenger.getIncomingChannels(plugin1), "test:foo", "test:bar"); - assertEquals(messenger.getIncomingChannels(plugin2), "test:baz", "test:qux"); - assertEquals(messenger.getIncomingChannels(plugin3)); + assertCollectionEquals(messenger.getIncomingChannels(plugin1), "test:foo", "test:bar"); + assertCollectionEquals(messenger.getIncomingChannels(plugin2), "test:baz", "test:qux"); + assertCollectionEquals(messenger.getIncomingChannels(plugin3)); } @Test @@ -244,9 +244,9 @@ public class StandardMessengerTest { PluginMessageListenerRegistration registration3 = messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes())); PluginMessageListenerRegistration registration4 = messenger.registerIncomingPluginChannel(plugin2, "test:qux", new TestMessageListener("test:foo", "test:bar".getBytes())); - assertEquals(messenger.getIncomingChannelRegistrations(plugin1), registration1, registration2); - assertEquals(messenger.getIncomingChannelRegistrations(plugin2), registration3, registration4); - assertEquals(messenger.getIncomingChannels(plugin3)); + assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin1), registration1, registration2); + assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin2), registration3, registration4); + assertCollectionEquals(messenger.getIncomingChannels(plugin3)); } @Test @@ -259,9 +259,9 @@ public class StandardMessengerTest { PluginMessageListenerRegistration registration3 = messenger.registerIncomingPluginChannel(plugin2, "test:foo", new TestMessageListener("test:foo", "test:bar".getBytes())); PluginMessageListenerRegistration registration4 = messenger.registerIncomingPluginChannel(plugin2, "test:bar", new TestMessageListener("test:foo", "test:bar".getBytes())); - assertEquals(messenger.getIncomingChannelRegistrations("test:foo"), registration1, registration3); - assertEquals(messenger.getIncomingChannelRegistrations("test:bar"), registration2, registration4); - assertEquals(messenger.getIncomingChannelRegistrations("test:baz")); + assertCollectionEquals(messenger.getIncomingChannelRegistrations("test:foo"), registration1, registration3); + assertCollectionEquals(messenger.getIncomingChannelRegistrations("test:bar"), registration2, registration4); + assertCollectionEquals(messenger.getIncomingChannelRegistrations("test:baz")); } @Test @@ -277,30 +277,30 @@ public class StandardMessengerTest { PluginMessageListenerRegistration registration5 = messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes())); PluginMessageListenerRegistration registration6 = messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes())); - assertEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:foo"), registration1, registration2); - assertEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:bar"), registration3); - assertEquals(messenger.getIncomingChannelRegistrations(plugin2, "test:bar"), registration4); - assertEquals(messenger.getIncomingChannelRegistrations(plugin2, "test:baz"), registration5, registration6); - assertEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:baz")); - assertEquals(messenger.getIncomingChannelRegistrations(plugin3, "test:qux")); + assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:foo"), registration1, registration2); + assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:bar"), registration3); + assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin2, "test:bar"), registration4); + assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin2, "test:baz"), registration5, registration6); + assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:baz")); + assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin3, "test:qux")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidChannel() { Messenger messenger = getMessenger(); TestPlugin plugin = getPlugin(); - messenger.registerOutgoingPluginChannel(plugin, "foo"); + assertThrows(IllegalArgumentException.class, () -> messenger.registerOutgoingPluginChannel(plugin, "foo")); } @Test public void testValidateAndCorrectChannel() { - Assert.assertEquals("bungeecord:main", StandardMessenger.validateAndCorrectChannel("BungeeCord")); - Assert.assertEquals("BungeeCord", StandardMessenger.validateAndCorrectChannel("bungeecord:main")); + assertEquals("bungeecord:main", StandardMessenger.validateAndCorrectChannel("BungeeCord")); + assertEquals("BungeeCord", StandardMessenger.validateAndCorrectChannel("bungeecord:main")); } - private static void assertEquals(Collection actual, T... expected) { - assertThat("Size of the array", actual.size(), is(expected.length)); + private static void assertCollectionEquals(Collection actual, T... expected) { + assertThat(actual.size(), is(expected.length), "Size of the array"); assertThat(actual, hasItems(expected)); } } diff --git a/paper-api/src/test/java/org/bukkit/plugin/messaging/TestMessageListener.java b/paper-api/src/test/java/org/bukkit/plugin/messaging/TestMessageListener.java index 7a5b6108d..20981f604 100644 --- a/paper-api/src/test/java/org/bukkit/plugin/messaging/TestMessageListener.java +++ b/paper-api/src/test/java/org/bukkit/plugin/messaging/TestMessageListener.java @@ -1,6 +1,6 @@ package org.bukkit.plugin.messaging; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.entity.Player; public class TestMessageListener implements PluginMessageListener { diff --git a/paper-api/src/test/java/org/bukkit/scoreboard/CriteriaTest.java b/paper-api/src/test/java/org/bukkit/scoreboard/CriteriaTest.java index 025ec8d63..034faf9a4 100644 --- a/paper-api/src/test/java/org/bukkit/scoreboard/CriteriaTest.java +++ b/paper-api/src/test/java/org/bukkit/scoreboard/CriteriaTest.java @@ -1,22 +1,22 @@ package org.bukkit.scoreboard; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.Material; import org.bukkit.Statistic; import org.bukkit.entity.EntityType; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CriteriaTest extends AbstractTestingBase { @Test public void testStatistic() { - Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, Material.STONE)); // Generic statistic with block - Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, EntityType.CREEPER)); // Generic statistic with entity type + assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, Material.STONE)); // Generic statistic with block + assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, EntityType.CREEPER)); // Generic statistic with entity type - Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.ENTITY_KILLED_BY, Material.AMETHYST_SHARD)); // Entity statistic with material - Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.MINE_BLOCK, Material.DIAMOND_PICKAXE)); // Block statistic with item - Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.BREAK_ITEM, Material.WATER)); // Item statistic with block - Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.KILL_ENTITY, Material.STONE)); // Entity statistic with Material + assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.ENTITY_KILLED_BY, Material.AMETHYST_SHARD)); // Entity statistic with material + assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.MINE_BLOCK, Material.DIAMOND_PICKAXE)); // Block statistic with item + assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.BREAK_ITEM, Material.WATER)); // Item statistic with block + assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.KILL_ENTITY, Material.STONE)); // Entity statistic with Material } } diff --git a/paper-api/src/test/java/org/bukkit/support/MatcherAssert.java b/paper-api/src/test/java/org/bukkit/support/MatcherAssert.java new file mode 100644 index 000000000..b100262e8 --- /dev/null +++ b/paper-api/src/test/java/org/bukkit/support/MatcherAssert.java @@ -0,0 +1,36 @@ +package org.bukkit.support; + +import org.hamcrest.Matcher; + +/** + * Custom assertThat methods, where the reason is put at the end of the method call. + * To better match with JUnit 5 argument order and also help with readability for longer reasons. + *
+ *
+ * assertThat(String.format("""
+ *         The block data created for the material %s is not an instance of the data class from that material.
+ *         """, material), blockData, is(instanceOf(expectedClass)));
+ * 
+ * vs. + *
+ * assertThat(blockData, is(instanceOf(expectedClass)), String.format("""
+ *         The block data created for the material %s is not an instance of the data class from that material.
+ *         """, material));
+ * 
+ */ +public final class MatcherAssert { + + private MatcherAssert() {} + + public static void assertThat(T actual, Matcher matcher) { + org.hamcrest.MatcherAssert.assertThat(actual, matcher); + } + + public static void assertThat(T actual, Matcher matcher, String reason) { + org.hamcrest.MatcherAssert.assertThat(reason, actual, matcher); + } + + public static void assertThat(boolean assertion, String reason) { + org.hamcrest.MatcherAssert.assertThat(reason, assertion); + } +} diff --git a/paper-api/src/test/java/org/bukkit/util/BoundingBoxTest.java b/paper-api/src/test/java/org/bukkit/util/BoundingBoxTest.java index 2d50a9ed6..3141c007d 100644 --- a/paper-api/src/test/java/org/bukkit/util/BoundingBoxTest.java +++ b/paper-api/src/test/java/org/bukkit/util/BoundingBoxTest.java @@ -1,11 +1,11 @@ package org.bukkit.util; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import java.util.Map; import org.bukkit.Location; import org.bukkit.block.BlockFace; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BoundingBoxTest { diff --git a/paper-api/src/test/java/org/bukkit/util/StringUtilStartsWithTest.java b/paper-api/src/test/java/org/bukkit/util/StringUtilStartsWithTest.java index 229c67c76..c93bd4d63 100644 --- a/paper-api/src/test/java/org/bukkit/util/StringUtilStartsWithTest.java +++ b/paper-api/src/test/java/org/bukkit/util/StringUtilStartsWithTest.java @@ -1,83 +1,72 @@ package org.bukkit.util; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import com.google.common.collect.ImmutableList; -import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class StringUtilStartsWithTest { - @Parameters(name = "{index}: {0} startsWith {1} == {2}") - public static List data() { - return ImmutableList.of( - new Object[] { - "Apple", - "Apples", - false - }, - new Object[] { - "Apples", - "Apple", - true - }, - new Object[] { - "Apple", - "Apple", - true - }, - new Object[] { - "Apple", - "apples", - false - }, - new Object[] { - "apple", - "Apples", - false - }, - new Object[] { - "apple", - "apples", - false - }, - new Object[] { - "Apples", - "apPL", - true - }, - new Object[] { - "123456789", - "1234567", - true - }, - new Object[] { - "", - "", - true - }, - new Object[] { - "string", - "", - true - } + public static Stream data() { + return Stream.of( + Arguments.of( + "Apple", + "Apples", + false + ), + Arguments.of( + "Apples", + "Apple", + true + ), + Arguments.of( + "Apple", + "Apple", + true + ), + Arguments.of( + "Apple", + "apples", + false + ), + Arguments.of( + "apple", + "Apples", + false + ), + Arguments.of( + "apple", + "apples", + false + ), + Arguments.of( + "Apples", + "apPL", + true + ), + Arguments.of( + "123456789", + "1234567", + true + ), + Arguments.of( + "", + "", + true + ), + Arguments.of( + "string", + "", + true + ) ); } - @Parameter(0) - public String base; - @Parameter(1) - public String prefix; - @Parameter(2) - public boolean result; - - @Test - public void testFor() { - assertThat(base + " starts with " + prefix + ": " + result, StringUtil.startsWithIgnoreCase(base, prefix), is(result)); + @ParameterizedTest + @MethodSource("data") + public void testFor(String base, String prefix, boolean result) { + assertThat(StringUtil.startsWithIgnoreCase(base, prefix), is(result), base + " starts with " + prefix + ": " + result); } } diff --git a/paper-api/src/test/java/org/bukkit/util/StringUtilTest.java b/paper-api/src/test/java/org/bukkit/util/StringUtilTest.java index 6476dd2d1..87e914619 100644 --- a/paper-api/src/test/java/org/bukkit/util/StringUtilTest.java +++ b/paper-api/src/test/java/org/bukkit/util/StringUtilTest.java @@ -1,38 +1,39 @@ package org.bukkit.util; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class StringUtilTest { - @Test(expected = NullPointerException.class) + @Test public void nullPrefixTest() { - StringUtil.startsWithIgnoreCase("String", null); + assertThrows(NullPointerException.class, () -> StringUtil.startsWithIgnoreCase("String", null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void nullStringTest() { - StringUtil.startsWithIgnoreCase(null, "String"); + assertThrows(IllegalArgumentException.class, () -> StringUtil.startsWithIgnoreCase(null, "String")); } - @Test(expected = IllegalArgumentException.class) + @Test public void nullCollectionTest() { - StringUtil.copyPartialMatches("Token", ImmutableList.of(), null); + assertThrows(IllegalArgumentException.class, () -> StringUtil.copyPartialMatches("Token", ImmutableList.of(), null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void nullIterableTest() { - StringUtil.copyPartialMatches("Token", null, new ArrayList()); + assertThrows(IllegalArgumentException.class, () -> StringUtil.copyPartialMatches("Token", null, new ArrayList())); } - @Test(expected = IllegalArgumentException.class) + @Test public void nullTokenTest() { - StringUtil.copyPartialMatches(null, ImmutableList.of(), new ArrayList()); + assertThrows(IllegalArgumentException.class, () -> StringUtil.copyPartialMatches(null, ImmutableList.of(), new ArrayList())); } @Test @@ -46,13 +47,13 @@ public class StringUtilTest { assertThat(list.size(), is(expected.size() * 2)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void copyUnsupportedTest() { - StringUtil.copyPartialMatches("token", ImmutableList.of("token1", "token2"), ImmutableList.of()); + assertThrows(UnsupportedOperationException.class, () -> StringUtil.copyPartialMatches("token", ImmutableList.of("token1", "token2"), ImmutableList.of())); } - @Test(expected = IllegalArgumentException.class) + @Test public void copyNullTest() { - StringUtil.copyPartialMatches("token", Arrays.asList("token1", "token2", null), new ArrayList()); + assertThrows(IllegalArgumentException.class, () -> StringUtil.copyPartialMatches("token", Arrays.asList("token1", "token2", null), new ArrayList())); } } diff --git a/paper-api/src/test/java/org/bukkit/util/VectorTest.java b/paper-api/src/test/java/org/bukkit/util/VectorTest.java index 03442bfff..f0927a0da 100644 --- a/paper-api/src/test/java/org/bukkit/util/VectorTest.java +++ b/paper-api/src/test/java/org/bukkit/util/VectorTest.java @@ -1,8 +1,8 @@ package org.bukkit.util; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.block.BlockFace; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class VectorTest { @@ -14,9 +14,9 @@ public class VectorTest { assertTrue(new Vector(1, 0, 0).isNormalized()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNullVectorAxis() { - new Vector(0, 1, 0).rotateAroundAxis(null, Math.PI); + assertThrows(IllegalArgumentException.class, () -> new Vector(0, 1, 0).rotateAroundAxis(null, Math.PI)); } @Test diff --git a/paper-api/src/test/java/org/bukkit/util/io/BukkitObjectStreamTest.java b/paper-api/src/test/java/org/bukkit/util/io/BukkitObjectStreamTest.java index d3edb72ff..7021a44e4 100644 --- a/paper-api/src/test/java/org/bukkit/util/io/BukkitObjectStreamTest.java +++ b/paper-api/src/test/java/org/bukkit/util/io/BukkitObjectStreamTest.java @@ -1,7 +1,7 @@ package org.bukkit.util.io; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import com.google.common.collect.ImmutableList; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -9,80 +9,69 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.List; +import java.util.stream.Stream; import org.bukkit.Color; import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect.Type; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.util.Vector; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; -@RunWith(Parameterized.class) public class BukkitObjectStreamTest { - @Parameters(name = "{index}: {0}") - public static List data() { - return ImmutableList.of( - new Object[] { - Color.class.getName(), - "rO0ABXNyADZjb20uZ29vZ2xlLmNvbW1vbi5jb2xsZWN0LkltbXV0YWJsZUxpc3QkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAVsACGVsZW1lbnRzdAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABXNyABpvcmcuYnVra2l0LnV0aWwuaW8uV3JhcHBlcvJQR+zxEm8FAgABTAADbWFwdAAPTGphdmEvdXRpbC9NYXA7eHBzcgA1Y29tLmdvb2dsZS5jb21tb24uY29sbGVjdC5JbW11dGFibGVNYXAkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABGtleXNxAH4AAVsABnZhbHVlc3EAfgABeHB1cQB+AAMAAAAEdAACPT10AANSRUR0AARCTFVFdAAFR1JFRU51cQB+AAMAAAAEdAAFQ29sb3JzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAA/3NxAH4AEQAAAP9zcQB+ABEAAAD/c3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARAAAAAHNxAH4AEQAAAIBzcQB+ABEAAACAc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARAAAAgHNxAH4AEQAAAIBxAH4AGnNxAH4ABXNxAH4ACHVxAH4AAwAAAARxAH4AC3EAfgAMcQB+AA1xAH4ADnVxAH4AAwAAAARxAH4AEHNxAH4AEQAAAP9xAH4AGnEAfgAac3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARAAAA/3EAfgAac3EAfgARAAAApQ==", - ImmutableList.of( - Color.WHITE, - Color.TEAL, - Color.PURPLE, - Color.RED, - Color.ORANGE - ) - }, - new Object[] { - FireworkEffect.class.getName(), - "rO0ABXNyADZjb20uZ29vZ2xlLmNvbW1vbi5jb2xsZWN0LkltbXV0YWJsZUxpc3QkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAVsACGVsZW1lbnRzdAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAAA3NyABpvcmcuYnVra2l0LnV0aWwuaW8uV3JhcHBlcvJQR+zxEm8FAgABTAADbWFwdAAPTGphdmEvdXRpbC9NYXA7eHBzcgA1Y29tLmdvb2dsZS5jb21tb24uY29sbGVjdC5JbW11dGFibGVNYXAkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABGtleXNxAH4AAVsABnZhbHVlc3EAfgABeHB1cQB+AAMAAAAGdAACPT10AAdmbGlja2VydAAFdHJhaWx0AAZjb2xvcnN0AAtmYWRlLWNvbG9yc3QABHR5cGV1cQB+AAMAAAAGdAAIRmlyZXdvcmtzcgARamF2YS5sYW5nLkJvb2xlYW7NIHKA1Zz67gIAAVoABXZhbHVleHABc3EAfgATAHNxAH4AAHVxAH4AAwAAAAJzcQB+AAVzcQB+AAh1cQB+AAMAAAAEcQB+AAt0AANSRUR0AARCTFVFdAAFR1JFRU51cQB+AAMAAAAEdAAFQ29sb3JzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAHEAfgAicQB+ACJzcQB+AAVzcQB+AAh1cQB+AAMAAAAEcQB+AAtxAH4AG3EAfgAccQB+AB11cQB+AAMAAAAEcQB+AB9zcQB+ACAAAADAc3EAfgAgAAAAwHNxAH4AIAAAAMBzcQB+AAB1cQB+AAMAAAABc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+ABtxAH4AHHEAfgAddXEAfgADAAAABHEAfgAfc3EAfgAgAAAA/3NxAH4AIAAAAP9zcQB+ACAAAAD/dAAKQkFMTF9MQVJHRXNxAH4ABXNxAH4ACHVxAH4AAwAAAAZxAH4AC3EAfgAMcQB+AA1xAH4ADnEAfgAPcQB+ABB1cQB+AAMAAAAGcQB+ABJxAH4AFXEAfgAVc3EAfgAAdXEAfgADAAAAAXNxAH4ABXNxAH4ACHVxAH4AAwAAAARxAH4AC3EAfgAbcQB+ABxxAH4AHXVxAH4AAwAAAARxAH4AH3EAfgAic3EAfgAgAAAAgHEAfgAic3EAfgAAdXEAfgADAAAAAHQABEJBTExzcQB+AAVzcQB+AAh1cQB+AAMAAAAGcQB+AAtxAH4ADHEAfgANcQB+AA5xAH4AD3EAfgAQdXEAfgADAAAABnEAfgAScQB+ABRxAH4AFHNxAH4AAHVxAH4AAwAAAAFzcQB+AAVzcQB+AAh1cQB+AAMAAAAEcQB+AAtxAH4AG3EAfgAccQB+AB11cQB+AAMAAAAEcQB+AB9zcQB+ACAAAACAcQB+ACJxAH4AInEAfgA/dAAHQ1JFRVBFUg==", - ImmutableList.of( - FireworkEffect.builder() - .withColor(Color.BLACK, Color.SILVER) - .with(Type.BALL_LARGE) - .withFade(Color.WHITE) - .withFlicker() - .build(), - FireworkEffect.builder() - .withColor(Color.NAVY) - .build(), - FireworkEffect.builder() - .withColor(Color.MAROON) - .withTrail() - .withFlicker() - .with(Type.CREEPER) - .build() - ), - }, - new Object[] { - Vector.class.getName(), - "rO0ABXNyADZjb20uZ29vZ2xlLmNvbW1vbi5jb2xsZWN0LkltbXV0YWJsZUxpc3QkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAVsACGVsZW1lbnRzdAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABHNyABpvcmcuYnVra2l0LnV0aWwuaW8uV3JhcHBlcvJQR+zxEm8FAgABTAADbWFwdAAPTGphdmEvdXRpbC9NYXA7eHBzcgA1Y29tLmdvb2dsZS5jb21tb24uY29sbGVjdC5JbW11dGFibGVNYXAkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABGtleXNxAH4AAVsABnZhbHVlc3EAfgABeHB1cQB+AAMAAAAEdAACPT10AAF4dAABeXQAAXp1cQB+AAMAAAAEdAAGVmVjdG9yc3IAEGphdmEubGFuZy5Eb3VibGWAs8JKKWv7BAIAAUQABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAAAAAABzcQB+ABEAAAAAAAAAAHNxAH4AEQAAAAAAAAAAc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARQIOFwo9cKPZzcQB+ABFAtCKcKPXCj3NxAH4AEUBzrpeNT987c3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARwEQTMzMzMzNzcQB+ABFASYAAAAAAAHNxAH4AEcCjqG3UQTVUc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARQd/////AAABzcQB+ABHB4AAAAAAAAHNxAH4AEQAAAAAAAAAA", - ImmutableList.of( - new Vector(0, 0, 0), - new Vector(624.72, 5154.61, 314.912), - new Vector(-40.15, 51, -2516.21451), - new Vector(Integer.MAX_VALUE, Integer.MIN_VALUE, 0) - ) - }); + public static Stream data() { + return Stream.of( + Arguments.of( + Color.class.getName(), + "rO0ABXNyADZjb20uZ29vZ2xlLmNvbW1vbi5jb2xsZWN0LkltbXV0YWJsZUxpc3QkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAVsACGVsZW1lbnRzdAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABXNyABpvcmcuYnVra2l0LnV0aWwuaW8uV3JhcHBlcvJQR+zxEm8FAgABTAADbWFwdAAPTGphdmEvdXRpbC9NYXA7eHBzcgA1Y29tLmdvb2dsZS5jb21tb24uY29sbGVjdC5JbW11dGFibGVNYXAkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABGtleXNxAH4AAVsABnZhbHVlc3EAfgABeHB1cQB+AAMAAAAEdAACPT10AANSRUR0AARCTFVFdAAFR1JFRU51cQB+AAMAAAAEdAAFQ29sb3JzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAA/3NxAH4AEQAAAP9zcQB+ABEAAAD/c3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARAAAAAHNxAH4AEQAAAIBzcQB+ABEAAACAc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARAAAAgHNxAH4AEQAAAIBxAH4AGnNxAH4ABXNxAH4ACHVxAH4AAwAAAARxAH4AC3EAfgAMcQB+AA1xAH4ADnVxAH4AAwAAAARxAH4AEHNxAH4AEQAAAP9xAH4AGnEAfgAac3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARAAAA/3EAfgAac3EAfgARAAAApQ==", + ImmutableList.of( + Color.WHITE, + Color.TEAL, + Color.PURPLE, + Color.RED, + Color.ORANGE + ) + ), + Arguments.of( + FireworkEffect.class.getName(), + "rO0ABXNyADZjb20uZ29vZ2xlLmNvbW1vbi5jb2xsZWN0LkltbXV0YWJsZUxpc3QkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAVsACGVsZW1lbnRzdAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAAA3NyABpvcmcuYnVra2l0LnV0aWwuaW8uV3JhcHBlcvJQR+zxEm8FAgABTAADbWFwdAAPTGphdmEvdXRpbC9NYXA7eHBzcgA1Y29tLmdvb2dsZS5jb21tb24uY29sbGVjdC5JbW11dGFibGVNYXAkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABGtleXNxAH4AAVsABnZhbHVlc3EAfgABeHB1cQB+AAMAAAAGdAACPT10AAdmbGlja2VydAAFdHJhaWx0AAZjb2xvcnN0AAtmYWRlLWNvbG9yc3QABHR5cGV1cQB+AAMAAAAGdAAIRmlyZXdvcmtzcgARamF2YS5sYW5nLkJvb2xlYW7NIHKA1Zz67gIAAVoABXZhbHVleHABc3EAfgATAHNxAH4AAHVxAH4AAwAAAAJzcQB+AAVzcQB+AAh1cQB+AAMAAAAEcQB+AAt0AANSRUR0AARCTFVFdAAFR1JFRU51cQB+AAMAAAAEdAAFQ29sb3JzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAHEAfgAicQB+ACJzcQB+AAVzcQB+AAh1cQB+AAMAAAAEcQB+AAtxAH4AG3EAfgAccQB+AB11cQB+AAMAAAAEcQB+AB9zcQB+ACAAAADAc3EAfgAgAAAAwHNxAH4AIAAAAMBzcQB+AAB1cQB+AAMAAAABc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+ABtxAH4AHHEAfgAddXEAfgADAAAABHEAfgAfc3EAfgAgAAAA/3NxAH4AIAAAAP9zcQB+ACAAAAD/dAAKQkFMTF9MQVJHRXNxAH4ABXNxAH4ACHVxAH4AAwAAAAZxAH4AC3EAfgAMcQB+AA1xAH4ADnEAfgAPcQB+ABB1cQB+AAMAAAAGcQB+ABJxAH4AFXEAfgAVc3EAfgAAdXEAfgADAAAAAXNxAH4ABXNxAH4ACHVxAH4AAwAAAARxAH4AC3EAfgAbcQB+ABxxAH4AHXVxAH4AAwAAAARxAH4AH3EAfgAic3EAfgAgAAAAgHEAfgAic3EAfgAAdXEAfgADAAAAAHQABEJBTExzcQB+AAVzcQB+AAh1cQB+AAMAAAAGcQB+AAtxAH4ADHEAfgANcQB+AA5xAH4AD3EAfgAQdXEAfgADAAAABnEAfgAScQB+ABRxAH4AFHNxAH4AAHVxAH4AAwAAAAFzcQB+AAVzcQB+AAh1cQB+AAMAAAAEcQB+AAtxAH4AG3EAfgAccQB+AB11cQB+AAMAAAAEcQB+AB9zcQB+ACAAAACAcQB+ACJxAH4AInEAfgA/dAAHQ1JFRVBFUg==", + ImmutableList.of( + FireworkEffect.builder() + .withColor(Color.BLACK, Color.SILVER) + .with(Type.BALL_LARGE) + .withFade(Color.WHITE) + .withFlicker() + .build(), + FireworkEffect.builder() + .withColor(Color.NAVY) + .build(), + FireworkEffect.builder() + .withColor(Color.MAROON) + .withTrail() + .withFlicker() + .with(Type.CREEPER) + .build() + ) + ), + Arguments.of( + Vector.class.getName(), + "rO0ABXNyADZjb20uZ29vZ2xlLmNvbW1vbi5jb2xsZWN0LkltbXV0YWJsZUxpc3QkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAVsACGVsZW1lbnRzdAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABHNyABpvcmcuYnVra2l0LnV0aWwuaW8uV3JhcHBlcvJQR+zxEm8FAgABTAADbWFwdAAPTGphdmEvdXRpbC9NYXA7eHBzcgA1Y29tLmdvb2dsZS5jb21tb24uY29sbGVjdC5JbW11dGFibGVNYXAkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABGtleXNxAH4AAVsABnZhbHVlc3EAfgABeHB1cQB+AAMAAAAEdAACPT10AAF4dAABeXQAAXp1cQB+AAMAAAAEdAAGVmVjdG9yc3IAEGphdmEubGFuZy5Eb3VibGWAs8JKKWv7BAIAAUQABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAAAAAABzcQB+ABEAAAAAAAAAAHNxAH4AEQAAAAAAAAAAc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARQIOFwo9cKPZzcQB+ABFAtCKcKPXCj3NxAH4AEUBzrpeNT987c3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARwEQTMzMzMzNzcQB+ABFASYAAAAAAAHNxAH4AEcCjqG3UQTVUc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARQd/////AAABzcQB+ABHB4AAAAAAAAHNxAH4AEQAAAAAAAAAA", + ImmutableList.of( + new Vector(0, 0, 0), + new Vector(624.72, 5154.61, 314.912), + new Vector(-40.15, 51, -2516.21451), + new Vector(Integer.MAX_VALUE, Integer.MIN_VALUE, 0) + ) + )); } - @Parameter(0) - public String className; - - @Parameter(1) - public String preEncoded; - - @Parameter(2) - public List object; - - @Test - public void checkSerlialization() throws Throwable { + @ParameterizedTest + @MethodSource("data") + public void checkSerlialization(String className, String preEncoded, List object) throws Throwable { // If this test fails, you may start your trek to debug by commenting the '@Ignore' on the next method // (and of course, you would read those comments too) final ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -102,7 +91,7 @@ public class BukkitObjectStreamTest { final byte[] preEncodedArray = Base64Coder.decode(preEncoded); final Object readBack; - final Object preEncoded; + final Object encoded; ObjectInputStream ois = null; ObjectInputStream preois = null; @@ -113,7 +102,7 @@ public class BukkitObjectStreamTest { preois = new BukkitObjectInputStream(preIn); readBack = ois.readObject(); - preEncoded = preois.readObject(); + encoded = preois.readObject(); } finally { if (ois != null) { try { @@ -130,12 +119,13 @@ public class BukkitObjectStreamTest { } assertThat(object, is(readBack)); - assertThat(object, is(preEncoded)); + assertThat(object, is(encoded)); } - @Ignore - @Test - public void preEncoded() throws Throwable { + @Disabled + @ParameterizedTest + @MethodSource("data") + public void preEncoded(String className, String preEncoded, List object) throws Throwable { // This test is placed in the case that a necessary change is made to change the encoding format // Just remove the ignore (or run manually) and it'll give you the new pre-encoded values