#909: Update tests to JUnit 5

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
Bukkit/Spigot 2023-09-24 06:09:10 +10:00
parent eef02e5dd2
commit 2a6d2d27d7
50 changed files with 837 additions and 863 deletions

View file

@ -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.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 * [`@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 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. will help to ensure the PR can be easily maintained over time and encourage the Spigot team to pull the PR.

View file

@ -86,15 +86,15 @@
</dependency> </dependency>
<!-- testing --> <!-- testing -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit</artifactId> <artifactId>junit-jupiter</artifactId>
<version>4.13.2</version> <version>5.10.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.hamcrest</groupId> <groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId> <artifactId>hamcrest</artifactId>
<version>1.3</version> <version>2.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View file

@ -1,5 +1,6 @@
package org.bukkit; package org.bukkit;
import static org.junit.jupiter.api.Assertions.*;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
@ -13,8 +14,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
@ -49,7 +49,7 @@ public class AnnotationTest {
File file = new File(loc.toURI()); File file = new File(loc.toURI());
// Running from jar is not supported yet // 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<String, ClassNode> foundClasses = new HashMap<>(); final HashMap<String, ClassNode> foundClasses = new HashMap<>();
collectClasses(file, foundClasses); collectClasses(file, foundClasses);
@ -97,7 +97,7 @@ public class AnnotationTest {
System.out.println(message); 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<String, ClassNode> to) throws IOException { private static void collectClasses(@NotNull File from, @NotNull Map<String, ClassNode> to) throws IOException {

View file

@ -1,14 +1,15 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class ArtTest { public class ArtTest {
@Test(expected = IllegalArgumentException.class) @Test
public void getByNullName() { public void getByNullName() {
Art.getByName(null); assertThrows(IllegalArgumentException.class, () -> Art.getByName(null));
} }
@Test @Test

View file

@ -1,72 +1,59 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; 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.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Arrays; import java.util.stream.Stream;
import java.util.List; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.Before; import org.junit.jupiter.params.provider.Arguments;
import org.junit.Test; import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class BukkitMirrorTest { public class BukkitMirrorTest {
@Parameters(name = "{index}: {1}") public static Stream<Arguments> data() {
public static List<Object[]> data() { return Stream.of(Server.class.getDeclaredMethods())
return Lists.transform(Arrays.asList(Server.class.getDeclaredMethods()), new Function<Method, Object[]>() { .map(method -> {
@Override try {
public Object[] apply(Method input) { return Arguments.of(
return new Object[] { method,
input, method.toGenericString().substring("public abstract ".length()).replace("(", "{").replace(")", "}"),
input.toGenericString().substring("public abstract ".length()).replace("(", "{").replace(")", "}") Bukkit.class.getDeclaredMethod(method.getName(), method.getParameterTypes())
}; );
} } catch (NoSuchMethodException e) {
}); throw new RuntimeException(e);
}
});
} }
@Parameter(0) @ParameterizedTest
public Method server; @MethodSource("data")
public void isStatic(Method server, String name, Method bukkit) throws Throwable {
@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 {
assertThat(Modifier.isStatic(bukkit.getModifiers()), is(true)); assertThat(Modifier.isStatic(bukkit.getModifiers()), is(true));
} }
@Test @ParameterizedTest
public void isDeprecated() throws Throwable { @MethodSource("data")
public void isDeprecated(Method server, String name, Method bukkit) throws Throwable {
assertThat(bukkit.isAnnotationPresent(Deprecated.class), is(server.isAnnotationPresent(Deprecated.class))); assertThat(bukkit.isAnnotationPresent(Deprecated.class), is(server.isAnnotationPresent(Deprecated.class)));
} }
@Test @ParameterizedTest
public void returnType() throws Throwable { @MethodSource("data")
public void returnType(Method server, String name, Method bukkit) throws Throwable {
assertThat(bukkit.getReturnType(), is((Object) server.getReturnType())); assertThat(bukkit.getReturnType(), is((Object) server.getReturnType()));
// assertThat(bukkit.getGenericReturnType(), is(server.getGenericReturnType())); // too strict on <T> type generics // assertThat(bukkit.getGenericReturnType(), is(server.getGenericReturnType())); // too strict on <T> type generics
} }
@Test @ParameterizedTest
public void parameterTypes() throws Throwable { @MethodSource("data")
public void parameterTypes(Method server, String name, Method bukkit) throws Throwable {
// assertThat(bukkit.getGenericParameterTypes(), is(server.getGenericParameterTypes())); // too strict on <T> type generics // assertThat(bukkit.getGenericParameterTypes(), is(server.getGenericParameterTypes())); // too strict on <T> type generics
} }
@Test @ParameterizedTest
public void declaredException() throws Throwable { @MethodSource("data")
public void declaredException(Method server, String name, Method bukkit) throws Throwable {
assertThat(bukkit.getGenericExceptionTypes(), is(server.getGenericExceptionTypes())); assertThat(bukkit.getGenericExceptionTypes(), is(server.getGenericExceptionTypes()));
} }
} }

View file

@ -1,8 +1,9 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class ChatColorTest { public class ChatColorTest {
@ -13,14 +14,14 @@ public class ChatColorTest {
} }
} }
@Test(expected = IllegalArgumentException.class) @Test
public void getByStringWithNull() { public void getByStringWithNull() {
ChatColor.getByChar((String) null); assertThrows(IllegalArgumentException.class, () -> ChatColor.getByChar((String) null));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void getByStringWithEmpty() { public void getByStringWithEmpty() {
ChatColor.getByChar(""); assertThrows(IllegalArgumentException.class, () -> ChatColor.getByChar(""));
} }
@Test @Test

View file

@ -1,9 +1,9 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import org.bukkit.util.ChatPaginator; import org.bukkit.util.ChatPaginator;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class ChatPaginatorTest { public class ChatPaginatorTest {
@Test @Test

View file

@ -1,8 +1,8 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class CoalTypeTest { public class CoalTypeTest {
@Test @Test

View file

@ -1,9 +1,10 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; 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.bukkit.configuration.file.YamlConfiguration;
import org.junit.Test; import org.junit.jupiter.api.Test;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class ColorTest { public class ColorTest {
@ -58,7 +59,7 @@ public class ColorTest {
YamlConfiguration deserialized = new YamlConfiguration(); YamlConfiguration deserialized = new YamlConfiguration();
deserialized.loadFromString(serialized); 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 fromRGBs = Color.fromRGB(testColor.r, testColor.g, testColor.b);
Color fromBGRs = Color.fromBGR(testColor.b, testColor.g, testColor.r); Color fromBGRs = Color.fromBGR(testColor.b, testColor.g, testColor.r);
assertThat(testColor.name, fromARGB, is(fromARGB)); assertThat(fromARGB, is(fromARGB), testColor.name);
assertThat(testColor.name, fromARGBs, is(fromARGBs)); assertThat(fromARGBs, is(fromARGBs), testColor.name);
assertThat(testColor.name, fromRGB, is(fromRGBs)); assertThat(fromRGB, is(fromRGBs), testColor.name);
assertThat(testColor.name, fromRGB, is(fromBGR)); assertThat(fromRGB, is(fromBGR), testColor.name);
assertThat(testColor.name, fromRGB, is(fromBGRs)); assertThat(fromRGB, is(fromBGRs), testColor.name);
assertThat(testColor.name, fromRGBs, is(fromBGR)); assertThat(fromRGBs, is(fromBGR), testColor.name);
assertThat(testColor.name, fromRGBs, is(fromBGRs)); assertThat(fromRGBs, is(fromBGRs), testColor.name);
assertThat(testColor.name, fromBGR, is(fromBGRs)); assertThat(fromBGR, is(fromBGRs), testColor.name);
} }
} }
@ -93,11 +94,11 @@ public class ColorTest {
TestColor testTo = examples[j]; TestColor testTo = examples[j];
Color to = Color.fromARGB(testTo.argb); Color to = Color.fromARGB(testTo.argb);
String name = testFrom.name + " to " + testTo.name; 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); Color transform = from.setAlpha(testTo.a).setRed(testTo.r).setBlue(testTo.b).setGreen(testTo.g);
assertThat(name, transform, is(not(sameInstance(from)))); assertThat(transform, is(not(sameInstance(from))), name);
assertThat(name, transform, is(to)); assertThat(transform, is(to), name);
} }
} }
} }
@ -106,8 +107,8 @@ public class ColorTest {
@Test @Test
public void testARGB() { public void testARGB() {
for (TestColor testColor : examples) { for (TestColor testColor : examples) {
assertThat(testColor.name, Color.fromARGB(testColor.argb).asARGB(), is(testColor.argb)); assertThat(Color.fromARGB(testColor.argb).asARGB(), is(testColor.argb), testColor.name);
assertThat(testColor.name, Color.fromARGB(testColor.a, testColor.r, testColor.g, testColor.b).asARGB(), is(testColor.argb)); 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 @Test
public void testRGB() { public void testRGB() {
for (TestColor testColor : examples) { for (TestColor testColor : examples) {
assertThat(testColor.name, Color.fromRGB(testColor.rgb).asRGB(), is(testColor.rgb)); assertThat(Color.fromRGB(testColor.rgb).asRGB(), is(testColor.rgb), testColor.name);
assertThat(testColor.name, Color.fromBGR(testColor.bgr).asRGB(), is(testColor.rgb)); assertThat(Color.fromBGR(testColor.bgr).asRGB(), is(testColor.rgb), testColor.name);
assertThat(testColor.name, Color.fromRGB(testColor.r, testColor.g, testColor.b).asRGB(), is(testColor.rgb)); assertThat(Color.fromRGB(testColor.r, testColor.g, testColor.b).asRGB(), is(testColor.rgb), testColor.name);
assertThat(testColor.name, Color.fromBGR(testColor.b, testColor.g, testColor.r).asRGB(), is(testColor.rgb)); assertThat(Color.fromBGR(testColor.b, testColor.g, testColor.r).asRGB(), is(testColor.rgb), testColor.name);
} }
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidRGB1() { public void testInvalidRGB1() {
Color.fromRGB(0x01000000); assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x01000000));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidRGB2() { public void testInvalidRGB2() {
Color.fromRGB(Integer.MIN_VALUE); assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(Integer.MIN_VALUE));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidRGB3() { public void testInvalidRGB3() {
Color.fromRGB(Integer.MAX_VALUE); assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(Integer.MAX_VALUE));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidRGB4() { public void testInvalidRGB4() {
Color.fromRGB(-1); assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(-1));
} }
// BGR tests // BGR tests
@Test @Test
public void testBGR() { public void testBGR() {
for (TestColor testColor : examples) { for (TestColor testColor : examples) {
assertThat(testColor.name, Color.fromRGB(testColor.rgb).asBGR(), is(testColor.bgr)); assertThat(Color.fromRGB(testColor.rgb).asBGR(), is(testColor.bgr), testColor.name);
assertThat(testColor.name, Color.fromBGR(testColor.bgr).asBGR(), is(testColor.bgr)); assertThat(Color.fromBGR(testColor.bgr).asBGR(), is(testColor.bgr), testColor.name);
assertThat(testColor.name, Color.fromRGB(testColor.r, testColor.g, testColor.b).asBGR(), is(testColor.bgr)); assertThat(Color.fromRGB(testColor.r, testColor.g, testColor.b).asBGR(), is(testColor.bgr), testColor.name);
assertThat(testColor.name, Color.fromBGR(testColor.b, testColor.g, testColor.r).asBGR(), is(testColor.bgr)); assertThat(Color.fromBGR(testColor.b, testColor.g, testColor.r).asBGR(), is(testColor.bgr), testColor.name);
} }
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidBGR1() { public void testInvalidBGR1() {
Color.fromBGR(0x01000000); assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x01000000));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidBGR2() { public void testInvalidBGR2() {
Color.fromBGR(Integer.MIN_VALUE); assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(Integer.MIN_VALUE));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidBGR3() { public void testInvalidBGR3() {
Color.fromBGR(Integer.MAX_VALUE); assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(Integer.MAX_VALUE));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidBGR4() { public void testInvalidBGR4() {
Color.fromBGR(-1); assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(-1));
} }
// Alpha tests // Alpha tests
@Test @Test
public void testAlpha() { public void testAlpha() {
for (TestColor testColor : examples) { 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() { 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() { 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() { 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() { 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() { 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() { 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() { 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() { 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() { public void testInvalidA09() {
Color.WHITE.setAlpha(-1); assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setAlpha(-1));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidA10() { 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() { 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() { public void testInvalidA12() {
Color.WHITE.setAlpha(0x100); assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setAlpha(0x100));
} }
// Red tests // Red tests
@Test @Test
public void testRed() { public void testRed() {
for (TestColor testColor : examples) { for (TestColor testColor : examples) {
assertThat(testColor.name, Color.fromRGB(testColor.rgb).getRed(), is(testColor.r)); assertThat(Color.fromRGB(testColor.rgb).getRed(), is(testColor.r), testColor.name);
assertThat(testColor.name, Color.fromBGR(testColor.bgr).getRed(), is(testColor.r)); assertThat(Color.fromBGR(testColor.bgr).getRed(), is(testColor.r), testColor.name);
assertThat(testColor.name, Color.fromRGB(testColor.r, testColor.g, testColor.b).getRed(), is(testColor.r)); assertThat(Color.fromRGB(testColor.r, testColor.g, testColor.b).getRed(), is(testColor.r), testColor.name);
assertThat(testColor.name, Color.fromBGR(testColor.b, testColor.g, testColor.r).getRed(), is(testColor.r)); assertThat(Color.fromBGR(testColor.b, testColor.g, testColor.r).getRed(), is(testColor.r), testColor.name);
} }
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidR01() { public void testInvalidR01() {
Color.fromRGB(-1, 0x00, 0x00); assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(-1, 0x00, 0x00));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidR02() { 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() { 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() { public void testInvalidR04() {
Color.fromRGB(0x100, 0x00, 0x00); assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x100, 0x00, 0x00));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidR05() { public void testInvalidR05() {
Color.fromBGR(0x00, 0x00, -1); assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, -1));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidR06() { 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() { 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() { public void testInvalidR08() {
Color.fromBGR(0x00, 0x00, 0x100); assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, 0x100));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidR09() { public void testInvalidR09() {
Color.WHITE.setRed(-1); assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setRed(-1));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidR10() { 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() { 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() { public void testInvalidR12() {
Color.WHITE.setRed(0x100); assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setRed(0x100));
} }
// Blue tests // Blue tests
@Test @Test
public void testBlue() { public void testBlue() {
for (TestColor testColor : examples) { for (TestColor testColor : examples) {
assertThat(testColor.name, Color.fromRGB(testColor.rgb).getBlue(), is(testColor.b)); assertThat(Color.fromRGB(testColor.rgb).getBlue(), is(testColor.b), testColor.name);
assertThat(testColor.name, Color.fromBGR(testColor.bgr).getBlue(), is(testColor.b)); assertThat(Color.fromBGR(testColor.bgr).getBlue(), is(testColor.b), testColor.name);
assertThat(testColor.name, Color.fromRGB(testColor.r, testColor.g, testColor.b).getBlue(), is(testColor.b)); assertThat(Color.fromRGB(testColor.r, testColor.g, testColor.b).getBlue(), is(testColor.b), testColor.name);
assertThat(testColor.name, Color.fromBGR(testColor.b, testColor.g, testColor.r).getBlue(), is(testColor.b)); assertThat(Color.fromBGR(testColor.b, testColor.g, testColor.r).getBlue(), is(testColor.b), testColor.name);
} }
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidB01() { public void testInvalidB01() {
Color.fromRGB(0x00, 0x00, -1); assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, 0x00, -1));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidB02() { 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() { 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() { public void testInvalidB04() {
Color.fromRGB(0x00, 0x00, 0x100); assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, 0x00, 0x100));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidB05() { public void testInvalidB05() {
Color.fromBGR(-1, 0x00, 0x00); assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(-1, 0x00, 0x00));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidB06() { 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() { 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() { public void testInvalidB08() {
Color.fromBGR(0x100, 0x00, 0x00); assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x100, 0x00, 0x00));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidB09() { public void testInvalidB09() {
Color.WHITE.setBlue(-1); assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setBlue(-1));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidB10() { 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() { 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() { public void testInvalidB12() {
Color.WHITE.setBlue(0x100); assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setBlue(0x100));
} }
// Green tests // Green tests
@Test @Test
public void testGreen() { public void testGreen() {
for (TestColor testColor : examples) { for (TestColor testColor : examples) {
assertThat(testColor.name, Color.fromRGB(testColor.rgb).getGreen(), is(testColor.g)); assertThat(Color.fromRGB(testColor.rgb).getGreen(), is(testColor.g), testColor.name);
assertThat(testColor.name, Color.fromBGR(testColor.bgr).getGreen(), is(testColor.g)); assertThat(Color.fromBGR(testColor.bgr).getGreen(), is(testColor.g), testColor.name);
assertThat(testColor.name, Color.fromRGB(testColor.r, testColor.g, testColor.b).getGreen(), is(testColor.g)); assertThat(Color.fromRGB(testColor.r, testColor.g, testColor.b).getGreen(), is(testColor.g), testColor.name);
assertThat(testColor.name, Color.fromBGR(testColor.b, testColor.g, testColor.r).getGreen(), is(testColor.g)); assertThat(Color.fromBGR(testColor.b, testColor.g, testColor.r).getGreen(), is(testColor.g), testColor.name);
} }
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidG01() { public void testInvalidG01() {
Color.fromRGB(0x00, -1, 0x00); assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, -1, 0x00));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidG02() { 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() { 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() { public void testInvalidG04() {
Color.fromRGB(0x00, 0x100, 0x00); assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, 0x100, 0x00));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidG05() { public void testInvalidG05() {
Color.fromBGR(0x00, -1, 0x00); assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, -1, 0x00));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidG06() { 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() { 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() { public void testInvalidG08() {
Color.fromBGR(0x00, 0x100, 0x00); assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x100, 0x00));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidG09() { public void testInvalidG09() {
Color.WHITE.setGreen(-1); assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setGreen(-1));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidG10() { 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() { 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() { public void testInvalidG12() {
Color.WHITE.setGreen(0x100); assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setGreen(0x100));
} }
} }

View file

@ -1,8 +1,8 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class CropStateTest { public class CropStateTest {
@Test @Test

View file

@ -1,8 +1,8 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class DifficultyTest { public class DifficultyTest {
@Test @Test

View file

@ -1,69 +1,57 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; 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.Colorable;
import org.bukkit.material.Dye; import org.bukkit.material.Dye;
import org.bukkit.material.Wool; import org.bukkit.material.Wool;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.EnumSource;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class DyeColorTest { public class DyeColorTest {
@Parameters(name = "{index}: {0}") @ParameterizedTest
public static List<Object[]> data() { @EnumSource(DyeColor.class)
List<Object[]> list = new ArrayList<Object[]>();
for (DyeColor dye : DyeColor.values()) {
list.add(new Object[] {dye});
}
return list;
}
@Parameter public DyeColor dye;
@Test
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void getByData() { public void getByData(DyeColor dye) {
byte data = dye.getWoolData(); byte data = dye.getWoolData();
DyeColor byData = DyeColor.getByWoolData(data); DyeColor byData = DyeColor.getByWoolData(data);
assertThat(byData, is(dye)); assertThat(byData, is(dye));
} }
@Test @ParameterizedTest
public void getByWoolData() { @EnumSource(DyeColor.class)
public void getByWoolData(DyeColor dye) {
byte data = dye.getWoolData(); byte data = dye.getWoolData();
DyeColor byData = DyeColor.getByWoolData(data); DyeColor byData = DyeColor.getByWoolData(data);
assertThat(byData, is(dye)); assertThat(byData, is(dye));
} }
@Test @ParameterizedTest
public void getByDyeData() { @EnumSource(DyeColor.class)
public void getByDyeData(DyeColor dye) {
byte data = dye.getDyeData(); byte data = dye.getDyeData();
DyeColor byData = DyeColor.getByDyeData(data); DyeColor byData = DyeColor.getByDyeData(data);
assertThat(byData, is(dye)); assertThat(byData, is(dye));
} }
@Test @ParameterizedTest
public void getDyeDyeColor() { @EnumSource(DyeColor.class)
testColorable(new Dye(Material.LEGACY_INK_SACK, dye.getDyeData())); public void getDyeDyeColor(DyeColor dye) {
testColorable(new Dye(dye)); testColorable(new Dye(Material.LEGACY_INK_SACK, dye.getDyeData()), dye);
testColorable(new Dye(dye), dye);
} }
@Test @ParameterizedTest
public void getWoolDyeColor() { @EnumSource(DyeColor.class)
testColorable(new Wool(Material.LEGACY_WOOL, dye.getWoolData())); public void getWoolDyeColor(DyeColor dye) {
testColorable(new Wool(Material.LEGACY_WOOL, dye.getWoolData()), dye);
} }
private void testColorable(final Colorable colorable) { private void testColorable(final Colorable colorable, DyeColor dye) {
assertThat(colorable.getColor(), is(this.dye)); assertThat(colorable.getColor(), is(dye));
} }
} }

View file

@ -1,8 +1,8 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class EffectTest { public class EffectTest {
@Test @Test

View file

@ -1,8 +1,8 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class GameModeTest { public class GameModeTest {
@Test @Test

View file

@ -1,8 +1,8 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class GrassSpeciesTest { public class GrassSpeciesTest {
@Test @Test

View file

@ -1,8 +1,8 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class InstrumentTest { public class InstrumentTest {
@Test @Test

View file

@ -1,40 +1,30 @@
package org.bukkit; package org.bukkit;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.util.Arrays; import java.util.stream.Stream;
import java.util.Collection; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.Test; import org.junit.jupiter.params.provider.Arguments;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class LastChatColorTest { public class LastChatColorTest {
@Parameterized.Parameters public static Stream<Arguments> data() {
public static Collection<Object[]> data() { return Stream.of(
return Arrays.asList(new Object[][]{ 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),
{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()),
{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"),
{"§x§1§2§3§4§5§6", "§x§1§2§3§4§5§6"}, Arguments.of("§y§1§2§3§4§5§6", "§6"),
{"§y§1§2§3§4§5§6", "§6"}, Arguments.of("§3§4§5§6", "§6"),
{"§3§4§5§6", "§6"}, Arguments.of("Test2§x§1§f§3§4§F§6test§l", "§x§1§f§3§4§F§6§l"),
{"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"),
{"Test2§x§P§f§3§4§F§6test§l", "§6§l"}, Arguments.of("Test2§x§fxf§3§4§F§6test§l", "§6§l"),
{"Test2§x§fxf§3§4§F§6test§l", "§6§l"}, Arguments.of("Test2§x§1§4§F§6test§l", "§6§l")
{"Test2§x§1§4§F§6test§l", "§6§l"} );
});
} }
private final String input; @ParameterizedTest
private final String expected; @MethodSource("data")
public void testGetLastColors(String input, String expected) {
public LastChatColorTest(String input, String expected) {
this.input = input;
this.expected = expected;
}
@Test
public void testGetLastColors() {
assertEquals(expected, ChatColor.getLastColors(input)); assertEquals(expected, ChatColor.getLastColors(input));
} }
} }

View file

@ -1,19 +1,15 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.stream.Stream;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.Arguments;
import org.junit.runners.Parameterized; import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class LocationTest { public class LocationTest {
private static final double delta = 1.0 / 1000000; 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); private static final double HALF_HALF_UNIT = Math.sqrt(1 / 4f);
@Parameters(name = "{index}: {0}") public static Stream<Arguments> data() {
public static List<Object[]> data() {
Random RANDOM = new Random(1L); // Test is deterministic Random RANDOM = new Random(1L); // Test is deterministic
int r = 0; int r = 0;
return ImmutableList.<Object[]>of( return Stream.of(
new Object[]{"X", Arguments.of("X",
1, 0, 0, 1, 0, 0,
270, 0 270, 0
}, ),
new Object[]{"-X", Arguments.of("-X",
-1, 0, 0, -1, 0, 0,
90, 0 90, 0
}, ),
new Object[]{"Z", Arguments.of("Z",
0, 0, 1, 0, 0, 1,
0, 0 0, 0
}, ),
new Object[]{"-Z", Arguments.of("-Z",
0, 0, -1, 0, 0, -1,
180, 0 180, 0
}, ),
new Object[]{"Y", Arguments.of("Y",
0, 1, 0, 0, 1, 0,
0, -90 // Zero is here as a "default" value 0, -90 // Zero is here as a "default" value
}, ),
new Object[]{"-Y", Arguments.of("-Y",
0, -1, 0, 0, -1, 0,
0, 90 // Zero is here as a "default" value 0, 90 // Zero is here as a "default" value
}, ),
new Object[]{"X Z", Arguments.of("X Z",
HALF_UNIT, 0, HALF_UNIT, HALF_UNIT, 0, HALF_UNIT,
(270 + 360) / 2, 0 (270 + 360) / 2, 0
}, ),
new Object[]{"X -Z", Arguments.of("X -Z",
HALF_UNIT, 0, -HALF_UNIT, HALF_UNIT, 0, -HALF_UNIT,
(270 + 180) / 2, 0 (270 + 180) / 2, 0
}, ),
new Object[]{"-X -Z", Arguments.of("-X -Z",
-HALF_UNIT, 0, -HALF_UNIT, -HALF_UNIT, 0, -HALF_UNIT,
(90 + 180) / 2, 0 (90 + 180) / 2, 0
}, ),
new Object[]{"-X Z", Arguments.of("-X Z",
-HALF_UNIT, 0, HALF_UNIT, -HALF_UNIT, 0, HALF_UNIT,
(90 + 0) / 2, 0 (90 + 0) / 2, 0
}, ),
new Object[]{"X Y Z", Arguments.of("X Y Z",
HALF_HALF_UNIT, HALF_UNIT, HALF_HALF_UNIT, HALF_HALF_UNIT, HALF_UNIT, HALF_HALF_UNIT,
(270 + 360) / 2, -45 (270 + 360) / 2, -45
}, ),
new Object[]{"-X -Y -Z", Arguments.of("-X -Y -Z",
-HALF_HALF_UNIT, -HALF_UNIT, -HALF_HALF_UNIT, -HALF_HALF_UNIT, -HALF_UNIT, -HALF_HALF_UNIT,
(90 + 180) / 2, 45 (90 + 180) / 2, 45
}, ),
getRandom(RANDOM, r++), getRandom(RANDOM, r++),
getRandom(RANDOM, r++), 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_FACTOR = 360;
final double YAW_OFFSET = 0; final double YAW_OFFSET = 0;
final double PITCH_FACTOR = 180; final double PITCH_FACTOR = 180;
@ -141,52 +136,42 @@ public class LocationTest {
location.setDirection(vector); location.setDirection(vector);
} }
return new Object[]{"R" + index, return Arguments.of("R" + index,
vector.getX(), vector.getY(), vector.getZ(), vector.getX(), vector.getY(), vector.getZ(),
location.getYaw(), location.getPitch() location.getYaw(), location.getPitch()
}; );
} }
@Parameter(0) @ParameterizedTest
public String nane; @MethodSource("data")
@Parameter(1) public void testExpectedPitchYaw(String name, double x, double y, double z, float yaw, float pitch) {
public double x; Location location = getEmptyLocation().setDirection(getVector(x, y, z));
@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());
assertThat((double) location.getYaw(), is(closeTo(yaw, delta))); assertThat((double) location.getYaw(), is(closeTo(yaw, delta)));
assertThat((double) location.getPitch(), is(closeTo(pitch, delta))); assertThat((double) location.getPitch(), is(closeTo(pitch, delta)));
} }
@Test @ParameterizedTest
public void testExpectedXYZ() { @MethodSource("data")
Vector vector = getLocation().getDirection(); 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.getX(), is(closeTo(x, delta)));
assertThat(vector.getY(), is(closeTo(y, delta))); assertThat(vector.getY(), is(closeTo(y, delta)));
assertThat(vector.getZ(), is(closeTo(z, delta))); assertThat(vector.getZ(), is(closeTo(z, delta)));
} }
@Test @ParameterizedTest
public void testEquals() { @MethodSource("data")
Location first = getLocation().add(getVector()); public void testEquals(String name, double x, double y, double z, float yaw, float pitch) {
Location second = getLocation().add(getVector()); 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.hashCode(), is(second.hashCode()));
assertThat(first, is(second)); assertThat(first, is(second));
} }
private Vector getVector() { private Vector getVector(double x, double y, double z) {
return new Vector(x, y, z); return new Vector(x, y, z);
} }
@ -196,7 +181,7 @@ public class LocationTest {
return new Location(TEST_WORLD, 0, 0, 0); return new Location(TEST_WORLD, 0, 0, 0);
} }
private Location getLocation() { private Location getLocation(float yaw, float pitch) {
Location location = getEmptyLocation(); Location location = getEmptyLocation();
location.setYaw(yaw); location.setYaw(yaw);
location.setPitch(pitch); location.setPitch(pitch);

View file

@ -1,9 +1,10 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class MaterialTest { public class MaterialTest {
@Test @Test
@ -30,9 +31,9 @@ public class MaterialTest {
} }
} }
@Test(expected = IllegalArgumentException.class) @Test
public void matchMaterialByNull() { public void matchMaterialByNull() {
Material.matchMaterial(null); assertThrows(IllegalArgumentException.class, () -> Material.matchMaterial(null));
} }
@Test @Test

View file

@ -1,72 +1,72 @@
package org.bukkit; package org.bukkit;
import org.junit.Assert; import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class NamespacedKeyTest { public class NamespacedKeyTest {
@Test @Test
public void testValid() { public void testValid() {
Assert.assertEquals("minecraft:foo", new NamespacedKey("minecraft", "foo").toString()); assertEquals("minecraft:foo", new NamespacedKey("minecraft", "foo").toString());
Assert.assertEquals("minecraft:foo/bar", new NamespacedKey("minecraft", "foo/bar").toString()); assertEquals("minecraft:foo/bar", new NamespacedKey("minecraft", "foo/bar").toString());
Assert.assertEquals("minecraft:foo/bar_baz", new NamespacedKey("minecraft", "foo/bar_baz").toString()); 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()); 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/bar_baz-qux.quux", new NamespacedKey("minecraft", "foo/bar_baz-qux.quux").toString());
} }
@Test @Test
public void testValidFromString() { public void testValidFromString() {
NamespacedKey expected = NamespacedKey.minecraft("foo"); NamespacedKey expected = NamespacedKey.minecraft("foo");
Assert.assertEquals(expected, NamespacedKey.fromString("foo")); assertEquals(expected, NamespacedKey.fromString("foo"));
Assert.assertEquals(expected, NamespacedKey.fromString(":foo")); assertEquals(expected, NamespacedKey.fromString(":foo"));
Assert.assertEquals(expected, NamespacedKey.fromString("minecraft:foo")); assertEquals(expected, NamespacedKey.fromString("minecraft:foo"));
Assert.assertEquals(new NamespacedKey("foo", "bar"), NamespacedKey.fromString("foo:bar")); assertEquals(new NamespacedKey("foo", "bar"), NamespacedKey.fromString("foo:bar"));
Assert.assertNull(NamespacedKey.fromString("fOO")); assertNull(NamespacedKey.fromString("fOO"));
Assert.assertNull(NamespacedKey.fromString(":Foo")); assertNull(NamespacedKey.fromString(":Foo"));
Assert.assertNull(NamespacedKey.fromString("fOO:bar")); assertNull(NamespacedKey.fromString("fOO:bar"));
Assert.assertNull(NamespacedKey.fromString("minecraft:fOO")); assertNull(NamespacedKey.fromString("minecraft:fOO"));
Assert.assertNull(NamespacedKey.fromString("foo:bar:bazz")); assertNull(NamespacedKey.fromString("foo:bar:bazz"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testFromStringEmptyInput() { public void testFromStringEmptyInput() {
NamespacedKey.fromString(""); assertThrows(IllegalArgumentException.class, () -> NamespacedKey.fromString(""));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testFromStringNullInput() { public void testFromStringNullInput() {
NamespacedKey.fromString(null); assertThrows(IllegalArgumentException.class, () -> NamespacedKey.fromString(null));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testEmptyNamespace() { public void testEmptyNamespace() {
new NamespacedKey("", "foo").toString(); assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("", "foo").toString());
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testEmptyKey() { public void testEmptyKey() {
new NamespacedKey("minecraft", "").toString(); assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("minecraft", "").toString());
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidNamespace() { 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() { public void testInvalidNamespaceCasing() {
new NamespacedKey("Minecraft", "foo").toString(); assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("Minecraft", "foo").toString());
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidKeyCasing() { public void testInvalidKeyCasing() {
new NamespacedKey("minecraft", "Foo").toString(); assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("minecraft", "Foo").toString());
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidKey() { public void testInvalidKey() {
new NamespacedKey("minecraft", "foo!").toString(); assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("minecraft", "foo!").toString());
} }
@Test @Test
@ -75,10 +75,10 @@ public class NamespacedKeyTest {
"loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas").toString(); "loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas").toString();
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testAboveLength() { public void testAboveLength() {
new NamespacedKey("loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas", assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas",
"loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas/" "loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas/"
+ "loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas").toString(); + "loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas").toString());
} }
} }

View file

@ -1,10 +1,11 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.util.Collection; import java.util.Collection;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class NoteTest { public class NoteTest {
@Test @Test
@ -51,24 +52,24 @@ public class NoteTest {
} }
} }
@Test(expected = IllegalArgumentException.class) @Test
public void createNoteBelowMin() { public void createNoteBelowMin() {
new Note((byte) -1); assertThrows(IllegalArgumentException.class, () -> new Note((byte) -1));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void createNoteAboveMax() { public void createNoteAboveMax() {
new Note((byte) 25); assertThrows(IllegalArgumentException.class, () -> new Note((byte) 25));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void createNoteOctaveBelowMax() { 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() { public void createNoteOctaveAboveMax() {
new Note((byte) 3, Note.Tone.A, true); assertThrows(IllegalArgumentException.class, () -> new Note((byte) 3, Note.Tone.A, true));
} }
@Test @Test
@ -114,9 +115,9 @@ public class NoteTest {
assertEquals(note.getOctave(), 2); assertEquals(note.getOctave(), 2);
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testSharpWrapping2() { public void testSharpWrapping2() {
new Note(2, Note.Tone.F, true).sharped(); assertThrows(IllegalArgumentException.class, () -> new Note(2, Note.Tone.F, true).sharped());
} }
@Test @Test

View file

@ -1,8 +1,8 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class TreeSpeciesTest { public class TreeSpeciesTest {
@Test @Test

View file

@ -1,8 +1,8 @@
package org.bukkit; package org.bukkit;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class WorldTypeTest { public class WorldTypeTest {
@Test @Test

View file

@ -1,6 +1,6 @@
package org.bukkit.configuration; package org.bukkit.configuration;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -11,7 +11,7 @@ import org.bukkit.Material;
import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.junit.Test; import org.junit.jupiter.api.Test;
public abstract class ConfigurationSectionTest { public abstract class ConfigurationSectionTest {
public abstract ConfigurationSection getConfigurationSection(); public abstract ConfigurationSection getConfigurationSection();

View file

@ -1,6 +1,6 @@
package org.bukkit.configuration; package org.bukkit.configuration;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -9,7 +9,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.bukkit.configuration.serialization.ConfigurationSerialization; import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.junit.Test; import org.junit.jupiter.api.Test;
public abstract class ConfigurationTest { public abstract class ConfigurationTest {

View file

@ -1,6 +1,6 @@
package org.bukkit.configuration.file; package org.bukkit.configuration.file;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
@ -8,13 +8,12 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.bukkit.configuration.MemoryConfigurationTest; import org.bukkit.configuration.MemoryConfigurationTest;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.io.TempDir;
import org.junit.rules.TemporaryFolder;
public abstract class FileConfigurationTest extends MemoryConfigurationTest { public abstract class FileConfigurationTest extends MemoryConfigurationTest {
@Rule @TempDir
public TemporaryFolder testFolder = new TemporaryFolder(); public File testFolder;
@Override @Override
public abstract FileConfiguration getConfig(); public abstract FileConfiguration getConfig();
@ -36,7 +35,8 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest {
@Test @Test
public void testSave_File() throws Exception { public void testSave_File() throws Exception {
FileConfiguration config = getConfig(); FileConfiguration config = getConfig();
File file = testFolder.newFile("test.config"); File file = new File(testFolder, "test.config");
file.createNewFile();
for (Map.Entry<String, Object> entry : getTestValues().entrySet()) { for (Map.Entry<String, Object> entry : getTestValues().entrySet()) {
config.set(entry.getKey(), entry.getValue()); config.set(entry.getKey(), entry.getValue());
@ -50,7 +50,8 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest {
@Test @Test
public void testSave_String() throws Exception { public void testSave_String() throws Exception {
FileConfiguration config = getConfig(); FileConfiguration config = getConfig();
File file = testFolder.newFile("test.config"); File file = new File(testFolder, "test.config");
file.createNewFile();
for (Map.Entry<String, Object> entry : getTestValues().entrySet()) { for (Map.Entry<String, Object> entry : getTestValues().entrySet()) {
config.set(entry.getKey(), entry.getValue()); config.set(entry.getKey(), entry.getValue());
@ -78,7 +79,8 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest {
@Test @Test
public void testLoad_File() throws Exception { public void testLoad_File() throws Exception {
FileConfiguration config = getConfig(); 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)); BufferedWriter writer = new BufferedWriter(new FileWriter(file));
String saved = getTestValuesString(); String saved = getTestValuesString();
Map<String, Object> values = getTestValues(); Map<String, Object> values = getTestValues();
@ -101,7 +103,8 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest {
@Test @Test
public void testLoad_String() throws Exception { public void testLoad_String() throws Exception {
FileConfiguration config = getConfig(); 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)); BufferedWriter writer = new BufferedWriter(new FileWriter(file));
String saved = getTestValuesString(); String saved = getTestValuesString();
Map<String, Object> values = getTestValues(); Map<String, Object> values = getTestValues();

View file

@ -1,6 +1,6 @@
package org.bukkit.configuration.file; package org.bukkit.configuration.file;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -12,7 +12,7 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.MemoryConfiguration; import org.bukkit.configuration.MemoryConfiguration;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class YamlConfigurationTest extends FileConfigurationTest { public class YamlConfigurationTest extends FileConfigurationTest {

View file

@ -1,9 +1,9 @@
package org.bukkit.conversations; package org.bukkit.conversations;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
*/ */
@ -19,7 +19,7 @@ public class ConversationContextTest {
public void TestPlugin() { public void TestPlugin() {
Conversable conversable = new FakeConversable(); Conversable conversable = new FakeConversable();
ConversationContext context = new ConversationContext(null, conversable, new HashMap<Object, Object>()); ConversationContext context = new ConversationContext(null, conversable, new HashMap<Object, Object>());
assertEquals(null, context.getPlugin()); assertNull(context.getPlugin());
} }
@Test @Test

View file

@ -1,8 +1,8 @@
package org.bukkit.conversations; package org.bukkit.conversations;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import org.bukkit.plugin.TestPlugin; import org.bukkit.plugin.TestPlugin;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
*/ */

View file

@ -1,7 +1,7 @@
package org.bukkit.conversations; package org.bukkit.conversations;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
*/ */

View file

@ -1,41 +1,41 @@
package org.bukkit.entity.memory; package org.bukkit.entity.memory;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class MemoryKeyTest { public class MemoryKeyTest {
@Test @Test
public void shouldContainAllMemories() { public void shouldContainAllMemories() {
List<MemoryKey> memories = Arrays.asList(MemoryKey.HOME, MemoryKey.JOB_SITE, MemoryKey.MEETING_POINT); List<MemoryKey> memories = Arrays.asList(MemoryKey.HOME, MemoryKey.JOB_SITE, MemoryKey.MEETING_POINT);
Assert.assertTrue(MemoryKey.values().containsAll(memories)); assertTrue(MemoryKey.values().containsAll(memories));
} }
@Test @Test
public void shouldGetMemoryKeyHomeByNamespacedKey() { public void shouldGetMemoryKeyHomeByNamespacedKey() {
Assert.assertEquals(MemoryKey.HOME, MemoryKey.getByKey(NamespacedKey.minecraft("home"))); assertEquals(MemoryKey.HOME, MemoryKey.getByKey(NamespacedKey.minecraft("home")));
} }
@Test @Test
public void shouldGetMemoryKeyJobSiteByNamespacedKey() { 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 @Test
public void shouldGetMemoryKeyMeetingPointByNamespacedKey() { 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 @Test
public void shouldReturnNullWhenNamespacedKeyisNotPresentAsMemoryKey() { public void shouldReturnNullWhenNamespacedKeyisNotPresentAsMemoryKey() {
Assert.assertEquals(null, MemoryKey.getByKey(NamespacedKey.minecraft("not_present"))); assertNull(MemoryKey.getByKey(NamespacedKey.minecraft("not_present")));
} }
@Test @Test
public void shouldReturnNullWhenNamespacedKeyisNull() { public void shouldReturnNullWhenNamespacedKeyisNull() {
Assert.assertNull(MemoryKey.getByKey(null)); assertNull(MemoryKey.getByKey(null));
} }
} }

View file

@ -1,11 +1,11 @@
package org.bukkit.event; package org.bukkit.event;
import static org.hamcrest.CoreMatchers.*; import static org.bukkit.support.MatcherAssert.*;
import static org.junit.Assert.*; import static org.hamcrest.Matchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.bukkit.event.player.PlayerChatTabCompleteEvent; import org.bukkit.event.player.PlayerChatTabCompleteEvent;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class PlayerChatTabCompleteEventTest { public class PlayerChatTabCompleteEventTest {

View file

@ -1,13 +1,13 @@
package org.bukkit.event; package org.bukkit.event;
import static org.junit.jupiter.api.Assertions.*;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginLoader; import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.SimplePluginManager; import org.bukkit.plugin.SimplePluginManager;
import org.bukkit.plugin.TestPlugin; import org.bukkit.plugin.TestPlugin;
import org.bukkit.plugin.java.JavaPluginLoader; import org.bukkit.plugin.java.JavaPluginLoader;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class SyntheticEventTest extends AbstractTestingBase { public class SyntheticEventTest extends AbstractTestingBase {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -28,7 +28,7 @@ public class SyntheticEventTest extends AbstractTestingBase {
pluginManager.registerEvents(impl, plugin); pluginManager.registerEvents(impl, plugin);
pluginManager.callEvent(event); pluginManager.callEvent(event);
Assert.assertEquals(1, impl.callCount); assertEquals(1, impl.callCount);
} }
public abstract static class Base<E extends Event> implements Listener { public abstract static class Base<E extends Event> implements Listener {

View file

@ -1,7 +1,7 @@
package org.bukkit.materials; package org.bukkit.materials;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import org.bukkit.CropState; import org.bukkit.CropState;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NetherWartsState; import org.bukkit.NetherWartsState;
@ -20,7 +20,7 @@ import org.bukkit.material.Tree;
import org.bukkit.material.Wood; import org.bukkit.material.Wood;
import org.bukkit.material.WoodenStep; import org.bukkit.material.WoodenStep;
import org.bukkit.material.types.MushroomBlockTexture; import org.bukkit.material.types.MushroomBlockTexture;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class MaterialDataTest { public class MaterialDataTest {
@ -28,10 +28,10 @@ public class MaterialDataTest {
public void testDoor() { public void testDoor() {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
Door door = new Door(); Door door = new Door();
assertThat("Constructed with default door type", door.getItemType(), equalTo(Material.LEGACY_WOODEN_DOOR)); assertThat(door.getItemType(), equalTo(Material.LEGACY_WOODEN_DOOR), "Constructed with default door type");
assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(false)); assertThat(door.isTopHalf(), equalTo(false), "Constructed with default top or bottom");
assertThat("Constructed with default direction", door.getFacing(), equalTo(BlockFace.WEST)); assertThat(door.getFacing(), equalTo(BlockFace.WEST), "Constructed with default direction");
assertThat("Constructed with default open state", door.isOpen(), equalTo(false)); assertThat(door.isOpen(), equalTo(false), "Constructed with default open state");
Material[] types = new Material[]{Material.LEGACY_WOODEN_DOOR, Material[] types = new Material[]{Material.LEGACY_WOODEN_DOOR,
Material.LEGACY_IRON_DOOR_BLOCK, Material.LEGACY_SPRUCE_DOOR, Material.LEGACY_IRON_DOOR_BLOCK, Material.LEGACY_SPRUCE_DOOR,
@ -44,26 +44,26 @@ public class MaterialDataTest {
// Test bottom half // Test bottom half
for (BlockFace facing : directions) { for (BlockFace facing : directions) {
door = new Door(type, facing); door = new Door(type, facing);
assertThat("Constructed with correct door type", door.getItemType(), equalTo(type)); assertThat(door.getItemType(), equalTo(type), "Constructed with correct door type");
assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(false)); assertThat(door.isTopHalf(), equalTo(false), "Constructed with default top or bottom");
assertThat("Constructed with correct direction", door.getFacing(), equalTo(facing)); assertThat(door.getFacing(), equalTo(facing), "Constructed with correct direction");
assertThat("Constructed with default open state", door.isOpen(), equalTo(false)); assertThat(door.isOpen(), equalTo(false), "Constructed with default open state");
for (boolean openState : openStates) { for (boolean openState : openStates) {
door = new Door(type, facing, openState); door = new Door(type, facing, openState);
assertThat("Constructed with correct door type", door.getItemType(), equalTo(type)); assertThat(door.getItemType(), equalTo(type), "Constructed with correct door type");
assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(false)); assertThat(door.isTopHalf(), equalTo(false), "Constructed with default top or bottom");
assertThat("Constructed with correct direction", door.getFacing(), equalTo(facing)); assertThat(door.getFacing(), equalTo(facing), "Constructed with correct direction");
assertThat("Constructed with correct open state", door.isOpen(), equalTo(openState)); assertThat(door.isOpen(), equalTo(openState), "Constructed with correct open state");
} }
} }
// Test top half // Test top half
for (boolean hingeState : hingeStates) { for (boolean hingeState : hingeStates) {
door = new Door(type, hingeState); door = new Door(type, hingeState);
assertThat("Constructed with correct door type", door.getItemType(), equalTo(type)); assertThat(door.getItemType(), equalTo(type), "Constructed with correct door type");
assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(true)); assertThat(door.isTopHalf(), equalTo(true), "Constructed with default top or bottom");
assertThat("Constructed with correct direction", door.getHinge(), equalTo(hingeState)); assertThat(door.getHinge(), equalTo(hingeState), "Constructed with correct direction");
} }
} }
} }
@ -71,26 +71,26 @@ public class MaterialDataTest {
@Test @Test
public void testWood() { public void testWood() {
Wood wood = new Wood(); Wood wood = new Wood();
assertThat("Constructed with default wood type", wood.getItemType(), equalTo(Material.LEGACY_WOOD)); assertThat(wood.getItemType(), equalTo(Material.LEGACY_WOOD), "Constructed with default wood type");
assertThat("Constructed with default tree species", wood.getSpecies(), equalTo(TreeSpecies.GENERIC)); assertThat(wood.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species");
TreeSpecies[] allSpecies = TreeSpecies.values(); TreeSpecies[] allSpecies = TreeSpecies.values();
for (TreeSpecies species : allSpecies) { for (TreeSpecies species : allSpecies) {
wood = new Wood(species); wood = new Wood(species);
assertThat("Constructed with default wood type", wood.getItemType(), equalTo(Material.LEGACY_WOOD)); assertThat(wood.getItemType(), equalTo(Material.LEGACY_WOOD), "Constructed with default wood type");
assertThat("Constructed with correct tree species", wood.getSpecies(), equalTo(species)); assertThat(wood.getSpecies(), equalTo(species), "Constructed with correct tree species");
} }
Material[] types = new Material[]{Material.LEGACY_WOOD, Material.LEGACY_WOOD_DOUBLE_STEP}; Material[] types = new Material[]{Material.LEGACY_WOOD, Material.LEGACY_WOOD_DOUBLE_STEP};
for (Material type : types) { for (Material type : types) {
wood = new Wood(type); wood = new Wood(type);
assertThat("Constructed with correct wood type", wood.getItemType(), equalTo(type)); assertThat(wood.getItemType(), equalTo(type), "Constructed with correct wood type");
assertThat("Constructed with default tree species", wood.getSpecies(), equalTo(TreeSpecies.GENERIC)); assertThat(wood.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species");
for (TreeSpecies species : allSpecies) { for (TreeSpecies species : allSpecies) {
wood = new Wood(type, species); wood = new Wood(type, species);
assertThat("Constructed with correct wood type", wood.getItemType(), equalTo(type)); assertThat(wood.getItemType(), equalTo(type), "Constructed with correct wood type");
assertThat("Constructed with correct tree species", wood.getSpecies(), equalTo(species)); assertThat(wood.getSpecies(), equalTo(species), "Constructed with correct tree species");
} }
} }
} }
@ -98,14 +98,14 @@ public class MaterialDataTest {
@Test @Test
public void testTree() { public void testTree() {
Tree tree = new Tree(); Tree tree = new Tree();
assertThat("Constructed with default tree type", tree.getItemType(), equalTo(Material.LEGACY_LOG)); assertThat(tree.getItemType(), equalTo(Material.LEGACY_LOG), "Constructed with default tree type");
assertThat("Constructed with default tree species", tree.getSpecies(), equalTo(TreeSpecies.GENERIC)); assertThat(tree.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species");
assertThat("Constructed with default direction", tree.getDirection(), equalTo(BlockFace.UP)); assertThat(tree.getDirection(), equalTo(BlockFace.UP), "Constructed with default direction");
tree = new Tree(Material.LEGACY_LOG); tree = new Tree(Material.LEGACY_LOG);
assertThat("Constructed with correct tree type", tree.getItemType(), equalTo(Material.LEGACY_LOG)); assertThat(tree.getItemType(), equalTo(Material.LEGACY_LOG), "Constructed with correct tree type");
assertThat("Constructed with default tree species", tree.getSpecies(), equalTo(TreeSpecies.GENERIC)); assertThat(tree.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species");
assertThat("Constructed with default direction", tree.getDirection(), equalTo(BlockFace.UP)); assertThat(tree.getDirection(), equalTo(BlockFace.UP), "Constructed with default direction");
Material[] types = new Material[]{Material.LEGACY_LOG, Material.LEGACY_LOG_2}; Material[] types = new Material[]{Material.LEGACY_LOG, Material.LEGACY_LOG_2};
TreeSpecies[][] allSpecies = new TreeSpecies[][]{ TreeSpecies[][] allSpecies = new TreeSpecies[][]{
@ -116,20 +116,20 @@ public class MaterialDataTest {
for (int t = 0; t < types.length; t++) { for (int t = 0; t < types.length; t++) {
for (TreeSpecies species : allSpecies[t]) { for (TreeSpecies species : allSpecies[t]) {
tree = new Tree(types[t], species); tree = new Tree(types[t], species);
assertThat("Constructed with correct tree type", tree.getItemType(), equalTo(types[t])); assertThat(tree.getItemType(), equalTo(types[t]), "Constructed with correct tree type");
assertThat("Constructed with correct tree species", tree.getSpecies(), equalTo(species)); assertThat(tree.getSpecies(), equalTo(species), "Constructed with correct tree species");
assertThat("Constructed with default direction", tree.getDirection(), equalTo(BlockFace.UP)); assertThat(tree.getDirection(), equalTo(BlockFace.UP), "Constructed with default direction");
// check item type is fixed automatically for invalid type-species combo // check item type is fixed automatically for invalid type-species combo
tree = new Tree(types[types.length - 1 - t], species); tree = new Tree(types[types.length - 1 - t], species);
assertThat("Constructed with fixed tree type", tree.getItemType(), equalTo(types[t])); assertThat(tree.getItemType(), equalTo(types[t]), "Constructed with fixed tree type");
assertThat("Constructed with correct tree species", tree.getSpecies(), equalTo(species)); assertThat(tree.getSpecies(), equalTo(species), "Constructed with correct tree species");
assertThat("Constructed with default direction", tree.getDirection(), equalTo(BlockFace.UP)); assertThat(tree.getDirection(), equalTo(BlockFace.UP), "Constructed with default direction");
for (BlockFace dir : allDirections) { for (BlockFace dir : allDirections) {
tree = new Tree(types[t], species, dir); tree = new Tree(types[t], species, dir);
assertThat("Constructed with correct tree type", tree.getItemType(), equalTo(types[t])); assertThat(tree.getItemType(), equalTo(types[t]), "Constructed with correct tree type");
assertThat("Constructed with correct tree species", tree.getSpecies(), equalTo(species)); assertThat(tree.getSpecies(), equalTo(species), "Constructed with correct tree species");
assertThat("Constructed with correct direction", tree.getDirection(), equalTo(dir)); assertThat(tree.getDirection(), equalTo(dir), "Constructed with correct direction");
} }
} }
} }
@ -138,16 +138,16 @@ public class MaterialDataTest {
@Test @Test
public void testLeaves() { public void testLeaves() {
Leaves leaves = new Leaves(); Leaves leaves = new Leaves();
assertThat("Constructed with default leaf type", leaves.getItemType(), equalTo(Material.LEGACY_LEAVES)); assertThat(leaves.getItemType(), equalTo(Material.LEGACY_LEAVES), "Constructed with default leaf type");
assertThat("Constructed with default tree species", leaves.getSpecies(), equalTo(TreeSpecies.GENERIC)); assertThat(leaves.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species");
assertThat("Constructed with default decayable", leaves.isDecayable(), equalTo(true)); assertThat(leaves.isDecayable(), equalTo(true), "Constructed with default decayable");
assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); assertThat(leaves.isDecaying(), equalTo(false), "Constructed with default decaying");
leaves = new Leaves(Material.LEGACY_LEAVES); leaves = new Leaves(Material.LEGACY_LEAVES);
assertThat("Constructed with correct leaf type", leaves.getItemType(), equalTo(Material.LEGACY_LEAVES)); assertThat(leaves.getItemType(), equalTo(Material.LEGACY_LEAVES), "Constructed with correct leaf type");
assertThat("Constructed with default tree species", leaves.getSpecies(), equalTo(TreeSpecies.GENERIC)); assertThat(leaves.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species");
assertThat("Constructed with default decayable", leaves.isDecayable(), equalTo(true)); assertThat(leaves.isDecayable(), equalTo(true), "Constructed with default decayable");
assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); assertThat(leaves.isDecaying(), equalTo(false), "Constructed with default decaying");
Material[] types = new Material[]{Material.LEGACY_LEAVES, Material.LEGACY_LEAVES_2}; Material[] types = new Material[]{Material.LEGACY_LEAVES, Material.LEGACY_LEAVES_2};
TreeSpecies[][] allSpecies = new TreeSpecies[][]{ TreeSpecies[][] allSpecies = new TreeSpecies[][]{
@ -159,30 +159,30 @@ public class MaterialDataTest {
for (int t = 0; t < types.length; t++) { for (int t = 0; t < types.length; t++) {
for (TreeSpecies species : allSpecies[t]) { for (TreeSpecies species : allSpecies[t]) {
leaves = new Leaves(types[t], species); leaves = new Leaves(types[t], species);
assertThat("Constructed with correct leaf type", leaves.getItemType(), equalTo(types[t])); assertThat(leaves.getItemType(), equalTo(types[t]), "Constructed with correct leaf type");
assertThat("Constructed with correct tree species", leaves.getSpecies(), equalTo(species)); assertThat(leaves.getSpecies(), equalTo(species), "Constructed with correct tree species");
assertThat("Constructed with default decayable", leaves.isDecayable(), equalTo(true)); assertThat(leaves.isDecayable(), equalTo(true), "Constructed with default decayable");
assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); assertThat(leaves.isDecaying(), equalTo(false), "Constructed with default decaying");
// check item type is fixed automatically for invalid type-species combo // check item type is fixed automatically for invalid type-species combo
leaves = new Leaves(types[types.length - 1 - t], species); leaves = new Leaves(types[types.length - 1 - t], species);
assertThat("Constructed with fixed leaf type", leaves.getItemType(), equalTo(types[t])); assertThat(leaves.getItemType(), equalTo(types[t]), "Constructed with fixed leaf type");
assertThat("Constructed with correct tree species", leaves.getSpecies(), equalTo(species)); assertThat(leaves.getSpecies(), equalTo(species), "Constructed with correct tree species");
assertThat("Constructed with default decayable", leaves.isDecayable(), equalTo(true)); assertThat(leaves.isDecayable(), equalTo(true), "Constructed with default decayable");
assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); assertThat(leaves.isDecaying(), equalTo(false), "Constructed with default decaying");
for (boolean isDecayable : decayable) { for (boolean isDecayable : decayable) {
leaves = new Leaves(types[t], species, isDecayable); leaves = new Leaves(types[t], species, isDecayable);
assertThat("Constructed with correct wood type", leaves.getItemType(), equalTo(types[t])); assertThat(leaves.getItemType(), equalTo(types[t]), "Constructed with correct wood type");
assertThat("Constructed with correct tree species", leaves.getSpecies(), equalTo(species)); assertThat(leaves.getSpecies(), equalTo(species), "Constructed with correct tree species");
assertThat("Constructed with correct decayable", leaves.isDecayable(), equalTo(isDecayable)); assertThat(leaves.isDecayable(), equalTo(isDecayable), "Constructed with correct decayable");
assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); assertThat(leaves.isDecaying(), equalTo(false), "Constructed with default decaying");
for (boolean isDecaying : decaying) { for (boolean isDecaying : decaying) {
leaves = new Leaves(types[t], species, isDecayable); leaves = new Leaves(types[t], species, isDecayable);
leaves.setDecaying(isDecaying); leaves.setDecaying(isDecaying);
assertThat("Constructed with correct wood type", leaves.getItemType(), equalTo(types[t])); assertThat(leaves.getItemType(), equalTo(types[t]), "Constructed with correct wood type");
assertThat("Constructed with correct tree species", leaves.getSpecies(), equalTo(species)); assertThat(leaves.getSpecies(), equalTo(species), "Constructed with correct tree species");
assertThat("Constructed with correct decayable", leaves.isDecayable(), equalTo(isDecaying || isDecayable)); assertThat(leaves.isDecayable(), equalTo(isDecaying || isDecayable), "Constructed with correct decayable");
assertThat("Constructed with correct decaying", leaves.isDecaying(), equalTo(isDecaying)); assertThat(leaves.isDecaying(), equalTo(isDecaying), "Constructed with correct decaying");
} }
} }
} }
@ -192,22 +192,22 @@ public class MaterialDataTest {
@Test @Test
public void testWoodenStep() { public void testWoodenStep() {
WoodenStep woodenStep = new WoodenStep(); WoodenStep woodenStep = new WoodenStep();
assertThat("Constructed with default step type", woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP)); assertThat(woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP), "Constructed with default step type");
assertThat("Constructed with default tree species", woodenStep.getSpecies(), equalTo(TreeSpecies.GENERIC)); assertThat(woodenStep.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species");
assertThat("Constructed with default inversion", woodenStep.isInverted(), equalTo(false)); assertThat(woodenStep.isInverted(), equalTo(false), "Constructed with default inversion");
TreeSpecies[] allSpecies = TreeSpecies.values(); TreeSpecies[] allSpecies = TreeSpecies.values();
boolean[] inversion = new boolean[]{true, false}; boolean[] inversion = new boolean[]{true, false};
for (TreeSpecies species : allSpecies) { for (TreeSpecies species : allSpecies) {
woodenStep = new WoodenStep(species); woodenStep = new WoodenStep(species);
assertThat("Constructed with default step type", woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP)); assertThat(woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP), "Constructed with default step type");
assertThat("Constructed with correct tree species", woodenStep.getSpecies(), equalTo(species)); assertThat(woodenStep.getSpecies(), equalTo(species), "Constructed with correct tree species");
assertThat("Constructed with default inversion", woodenStep.isInverted(), equalTo(false)); assertThat(woodenStep.isInverted(), equalTo(false), "Constructed with default inversion");
for (boolean isInverted : inversion) { for (boolean isInverted : inversion) {
woodenStep = new WoodenStep(species, isInverted); woodenStep = new WoodenStep(species, isInverted);
assertThat("Constructed with default step type", woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP)); assertThat(woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP), "Constructed with default step type");
assertThat("Constructed with correct tree species", woodenStep.getSpecies(), equalTo(species)); assertThat(woodenStep.getSpecies(), equalTo(species), "Constructed with correct tree species");
assertThat("Constructed with correct inversion", woodenStep.isInverted(), equalTo(isInverted)); assertThat(woodenStep.isInverted(), equalTo(isInverted), "Constructed with correct inversion");
} }
} }
} }
@ -215,22 +215,22 @@ public class MaterialDataTest {
@Test @Test
public void testSapling() { public void testSapling() {
Sapling sapling = new Sapling(); Sapling sapling = new Sapling();
assertThat("Constructed with default sapling type", sapling.getItemType(), equalTo(Material.LEGACY_SAPLING)); assertThat(sapling.getItemType(), equalTo(Material.LEGACY_SAPLING), "Constructed with default sapling type");
assertThat("Constructed with default tree species", sapling.getSpecies(), equalTo(TreeSpecies.GENERIC)); assertThat(sapling.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species");
assertThat("Constructed with default growable", sapling.isInstantGrowable(), equalTo(false)); assertThat(sapling.isInstantGrowable(), equalTo(false), "Constructed with default growable");
TreeSpecies[] allSpecies = TreeSpecies.values(); TreeSpecies[] allSpecies = TreeSpecies.values();
boolean[] growable = new boolean[]{true, false}; boolean[] growable = new boolean[]{true, false};
for (TreeSpecies species : allSpecies) { for (TreeSpecies species : allSpecies) {
sapling = new Sapling(species); sapling = new Sapling(species);
assertThat("Constructed with default sapling type", sapling.getItemType(), equalTo(Material.LEGACY_SAPLING)); assertThat(sapling.getItemType(), equalTo(Material.LEGACY_SAPLING), "Constructed with default sapling type");
assertThat("Constructed with correct tree species", sapling.getSpecies(), equalTo(species)); assertThat(sapling.getSpecies(), equalTo(species), "Constructed with correct tree species");
assertThat("Constructed with default growable", sapling.isInstantGrowable(), equalTo(false)); assertThat(sapling.isInstantGrowable(), equalTo(false), "Constructed with default growable");
for (boolean isInstantGrowable : growable) { for (boolean isInstantGrowable : growable) {
sapling = new Sapling(species, isInstantGrowable); sapling = new Sapling(species, isInstantGrowable);
assertThat("Constructed with default sapling type", sapling.getItemType(), equalTo(Material.LEGACY_SAPLING)); assertThat(sapling.getItemType(), equalTo(Material.LEGACY_SAPLING), "Constructed with default sapling type");
assertThat("Constructed with correct tree species", sapling.getSpecies(), equalTo(species)); assertThat(sapling.getSpecies(), equalTo(species), "Constructed with correct tree species");
assertThat("Constructed with correct growable", sapling.isInstantGrowable(), equalTo(isInstantGrowable)); assertThat(sapling.isInstantGrowable(), equalTo(isInstantGrowable), "Constructed with correct growable");
} }
} }
} }
@ -244,19 +244,19 @@ public class MaterialDataTest {
MushroomBlockTexture[] textures = MushroomBlockTexture.values(); MushroomBlockTexture[] textures = MushroomBlockTexture.values();
for (Material type : mushroomTypes) { for (Material type : mushroomTypes) {
Mushroom mushroom = new Mushroom(type); Mushroom mushroom = new Mushroom(type);
assertThat("Constructed with correct mushroom type", mushroom.getItemType(), equalTo(type)); assertThat(mushroom.getItemType(), equalTo(type), "Constructed with correct mushroom type");
assertThat("Constructed with default pores face", mushroom.getBlockTexture(), equalTo(MushroomBlockTexture.ALL_PORES)); assertThat(mushroom.getBlockTexture(), equalTo(MushroomBlockTexture.ALL_PORES), "Constructed with default pores face");
for (int f = 0; f < setFaces.length; f++) { for (int f = 0; f < setFaces.length; f++) {
mushroom = new Mushroom(type, setFaces[f]); mushroom = new Mushroom(type, setFaces[f]);
assertThat("Constructed with correct mushroom type", mushroom.getItemType(), equalTo(type)); assertThat(mushroom.getItemType(), equalTo(type), "Constructed with correct mushroom type");
assertThat("Constructed with correct texture", mushroom.getBlockTexture(), equalTo(MushroomBlockTexture.getCapByFace(setFaces[f]))); assertThat(mushroom.getBlockTexture(), equalTo(MushroomBlockTexture.getCapByFace(setFaces[f])), "Constructed with correct texture");
} }
for (MushroomBlockTexture texture : textures) { for (MushroomBlockTexture texture : textures) {
mushroom = new Mushroom(type, texture); mushroom = new Mushroom(type, texture);
assertThat("Constructed with correct mushroom type", mushroom.getItemType(), equalTo(type)); assertThat(mushroom.getItemType(), equalTo(type), "Constructed with correct mushroom type");
assertThat("Constructed with correct texture", mushroom.getBlockTexture(), equalTo(texture)); assertThat(mushroom.getBlockTexture(), equalTo(texture), "Constructed with correct texture");
} }
} }
} }
@ -264,90 +264,90 @@ public class MaterialDataTest {
@Test @Test
public void testCrops() { public void testCrops() {
Crops crops = new Crops(); Crops crops = new Crops();
assertThat("Constructed with default crops type", crops.getItemType(), equalTo(Material.LEGACY_CROPS)); assertThat(crops.getItemType(), equalTo(Material.LEGACY_CROPS), "Constructed with default crops type");
assertThat("Constructed with default crop state", crops.getState(), equalTo(CropState.SEEDED)); assertThat(crops.getState(), equalTo(CropState.SEEDED), "Constructed with default crop state");
CropState[] allStates = CropState.values(); CropState[] allStates = CropState.values();
for (CropState state : allStates) { for (CropState state : allStates) {
crops = new Crops(state); crops = new Crops(state);
assertThat("Constructed with default crops type", crops.getItemType(), equalTo(Material.LEGACY_CROPS)); assertThat(crops.getItemType(), equalTo(Material.LEGACY_CROPS), "Constructed with default crops type");
assertThat("Constructed with correct crop state", crops.getState(), equalTo(state)); assertThat(crops.getState(), equalTo(state), "Constructed with correct crop state");
} }
// The crops which fully implement all crop states // The crops which fully implement all crop states
Material[] allCrops = new Material[]{Material.LEGACY_CROPS, Material.LEGACY_CARROT, Material.LEGACY_POTATO}; Material[] allCrops = new Material[]{Material.LEGACY_CROPS, Material.LEGACY_CARROT, Material.LEGACY_POTATO};
for (Material crop : allCrops) { for (Material crop : allCrops) {
crops = new Crops(crop); crops = new Crops(crop);
assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(crop)); assertThat(crops.getItemType(), equalTo(crop), "Constructed with correct crops type");
assertThat("Constructed with default crop state", crops.getState(), equalTo(CropState.SEEDED)); assertThat(crops.getState(), equalTo(CropState.SEEDED), "Constructed with default crop state");
for (CropState state : allStates) { for (CropState state : allStates) {
crops = new Crops(crop, state); crops = new Crops(crop, state);
assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(crop)); assertThat(crops.getItemType(), equalTo(crop), "Constructed with correct crops type");
assertThat("Constructed with correct crop state", crops.getState(), equalTo(state)); assertThat(crops.getState(), equalTo(state), "Constructed with correct crop state");
} }
} }
// Beetroot are crops too, but they only have four states // Beetroot are crops too, but they only have four states
// Setting different crop states for beetroot will return the following when retrieved back // 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}; 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); crops = new Crops(Material.LEGACY_BEETROOT_BLOCK);
assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(Material.LEGACY_BEETROOT_BLOCK)); assertThat(crops.getItemType(), equalTo(Material.LEGACY_BEETROOT_BLOCK), "Constructed with correct crops type");
assertThat("Constructed with default crop state", crops.getState(), equalTo(CropState.SEEDED)); assertThat(crops.getState(), equalTo(CropState.SEEDED), "Constructed with default crop state");
for (int s = 0; s < beetrootStates.length; s++) { for (int s = 0; s < beetrootStates.length; s++) {
crops = new Crops(Material.LEGACY_BEETROOT_BLOCK, allStates[s]); crops = new Crops(Material.LEGACY_BEETROOT_BLOCK, allStates[s]);
assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(Material.LEGACY_BEETROOT_BLOCK)); assertThat(crops.getItemType(), equalTo(Material.LEGACY_BEETROOT_BLOCK), "Constructed with correct crops type");
assertThat("Constructed with correct crop state", crops.getState(), equalTo(beetrootStates[s])); 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 // In case you want to treat NetherWarts as Crops, although they really aren't
crops = new Crops(Material.LEGACY_NETHER_WARTS); crops = new Crops(Material.LEGACY_NETHER_WARTS);
NetherWarts warts = new NetherWarts(); NetherWarts warts = new NetherWarts();
assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(warts.getItemType())); assertThat(crops.getItemType(), equalTo(warts.getItemType()), "Constructed with correct crops type");
assertThat("Constructed with default crop state", crops.getState(), equalTo(CropState.SEEDED)); assertThat(crops.getState(), equalTo(CropState.SEEDED), "Constructed with default crop state");
assertThat("Constructed with default wart state", warts.getState(), equalTo(NetherWartsState.SEEDED)); assertThat(warts.getState(), equalTo(NetherWartsState.SEEDED), "Constructed with default wart state");
allStates = new CropState[]{CropState.SEEDED, CropState.SMALL, CropState.TALL, CropState.RIPE}; allStates = new CropState[]{CropState.SEEDED, CropState.SMALL, CropState.TALL, CropState.RIPE};
NetherWartsState[] allWartStates = NetherWartsState.values(); 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++) { for (int s = 0; s < allStates.length; s++) {
crops = new Crops(Material.LEGACY_NETHER_WARTS, allStates[s]); crops = new Crops(Material.LEGACY_NETHER_WARTS, allStates[s]);
warts = new NetherWarts(allWartStates[s]); warts = new NetherWarts(allWartStates[s]);
assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(warts.getItemType())); assertThat(crops.getItemType(), equalTo(warts.getItemType()), "Constructed with correct crops type");
assertThat("Constructed with correct crop state", crops.getState(), equalTo(allStates[s])); assertThat(crops.getState(), equalTo(allStates[s]), "Constructed with correct crop state");
assertThat("Constructed with correct wart state", warts.getState(), equalTo(allWartStates[s])); assertThat(warts.getState(), equalTo(allWartStates[s]), "Constructed with correct wart state");
} }
} }
@Test @Test
public void testDiode() { public void testDiode() {
Diode diode = new Diode(); Diode diode = new Diode();
assertThat("Constructed with backward compatible diode state", diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_ON)); assertThat(diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_ON), "Constructed with backward compatible diode state");
assertThat("Constructed with backward compatible powered", diode.isPowered(), equalTo(true)); assertThat(diode.isPowered(), equalTo(true), "Constructed with backward compatible powered");
assertThat("Constructed with default delay", diode.getDelay(), equalTo(1)); assertThat(diode.getDelay(), equalTo(1), "Constructed with default delay");
assertThat("Constructed with default direction", diode.getFacing(), equalTo(BlockFace.NORTH)); assertThat(diode.getFacing(), equalTo(BlockFace.NORTH), "Constructed with default direction");
BlockFace[] directions = new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST}; BlockFace[] directions = new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
int[] delays = new int[]{1, 2, 3, 4}; int[] delays = new int[]{1, 2, 3, 4};
boolean[] states = new boolean[]{false, true}; boolean[] states = new boolean[]{false, true};
for (BlockFace direction : directions) { for (BlockFace direction : directions) {
diode = new Diode(direction); diode = new Diode(direction);
assertThat("Constructed with default diode state", diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_OFF)); assertThat(diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_OFF), "Constructed with default diode state");
assertThat("Constructed with default powered", diode.isPowered(), equalTo(false)); assertThat(diode.isPowered(), equalTo(false), "Constructed with default powered");
assertThat("Constructed with default delay", diode.getDelay(), equalTo(1)); assertThat(diode.getDelay(), equalTo(1), "Constructed with default delay");
assertThat("Constructed with correct direction", diode.getFacing(), equalTo(direction)); assertThat(diode.getFacing(), equalTo(direction), "Constructed with correct direction");
for (int delay : delays) { for (int delay : delays) {
diode = new Diode(direction, delay); diode = new Diode(direction, delay);
assertThat("Constructed with default diode state", diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_OFF)); assertThat(diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_OFF), "Constructed with default diode state");
assertThat("Constructed with default powered", diode.isPowered(), equalTo(false)); assertThat(diode.isPowered(), equalTo(false), "Constructed with default powered");
assertThat("Constructed with correct delay", diode.getDelay(), equalTo(delay)); assertThat(diode.getDelay(), equalTo(delay), "Constructed with correct delay");
assertThat("Constructed with correct direction", diode.getFacing(), equalTo(direction)); assertThat(diode.getFacing(), equalTo(direction), "Constructed with correct direction");
for (boolean state : states) { for (boolean state : states) {
diode = new Diode(direction, delay, state); 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(diode.getItemType(), equalTo(state ? Material.LEGACY_DIODE_BLOCK_ON : Material.LEGACY_DIODE_BLOCK_OFF), "Constructed with correct diode state");
assertThat("Constructed with default powered", diode.isPowered(), equalTo(state)); assertThat(diode.isPowered(), equalTo(state), "Constructed with default powered");
assertThat("Constructed with correct delay", diode.getDelay(), equalTo(delay)); assertThat(diode.getDelay(), equalTo(delay), "Constructed with correct delay");
assertThat("Constructed with correct direction", diode.getFacing(), equalTo(direction)); assertThat(diode.getFacing(), equalTo(direction), "Constructed with correct direction");
} }
} }
} }
@ -356,44 +356,44 @@ public class MaterialDataTest {
@Test @Test
public void testComparator() { public void testComparator() {
Comparator comparator = new Comparator(); Comparator comparator = new Comparator();
assertThat("Constructed with default comparator state", comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF)); assertThat(comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF), "Constructed with default comparator state");
assertThat("Constructed with default powered", comparator.isPowered(), equalTo(false)); assertThat(comparator.isPowered(), equalTo(false), "Constructed with default powered");
assertThat("Constructed with default being powered", comparator.isBeingPowered(), equalTo(false)); assertThat(comparator.isBeingPowered(), equalTo(false), "Constructed with default being powered");
assertThat("Constructed with default mode", comparator.isSubtractionMode(), equalTo(false)); assertThat(comparator.isSubtractionMode(), equalTo(false), "Constructed with default mode");
assertThat("Constructed with default direction", comparator.getFacing(), equalTo(BlockFace.NORTH)); assertThat(comparator.getFacing(), equalTo(BlockFace.NORTH), "Constructed with default direction");
BlockFace[] directions = new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST}; BlockFace[] directions = new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
boolean[] modes = new boolean[]{false, true}; boolean[] modes = new boolean[]{false, true};
boolean[] states = new boolean[]{false, true}; boolean[] states = new boolean[]{false, true};
for (BlockFace direction : directions) { for (BlockFace direction : directions) {
comparator = new Comparator(direction); comparator = new Comparator(direction);
assertThat("Constructed with default comparator state", comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF)); assertThat(comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF), "Constructed with default comparator state");
assertThat("Constructed with default powered", comparator.isPowered(), equalTo(false)); assertThat(comparator.isPowered(), equalTo(false), "Constructed with default powered");
assertThat("Constructed with default being powered", comparator.isBeingPowered(), equalTo(false)); assertThat(comparator.isBeingPowered(), equalTo(false), "Constructed with default being powered");
assertThat("Constructed with default mode", comparator.isSubtractionMode(), equalTo(false)); assertThat(comparator.isSubtractionMode(), equalTo(false), "Constructed with default mode");
assertThat("Constructed with correct direction", comparator.getFacing(), equalTo(direction)); assertThat(comparator.getFacing(), equalTo(direction), "Constructed with correct direction");
for (boolean mode : modes) { for (boolean mode : modes) {
comparator = new Comparator(direction, mode); comparator = new Comparator(direction, mode);
assertThat("Constructed with default comparator state", comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF)); assertThat(comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF), "Constructed with default comparator state");
assertThat("Constructed with default powered", comparator.isPowered(), equalTo(false)); assertThat(comparator.isPowered(), equalTo(false), "Constructed with default powered");
assertThat("Constructed with default being powered", comparator.isBeingPowered(), equalTo(false)); assertThat(comparator.isBeingPowered(), equalTo(false), "Constructed with default being powered");
assertThat("Constructed with correct mode", comparator.isSubtractionMode(), equalTo(mode)); assertThat(comparator.isSubtractionMode(), equalTo(mode), "Constructed with correct mode");
assertThat("Constructed with correct direction", comparator.getFacing(), equalTo(direction)); assertThat(comparator.getFacing(), equalTo(direction), "Constructed with correct direction");
for (boolean state : states) { for (boolean state : states) {
comparator = new Comparator(direction, mode, state); 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(comparator.getItemType(), equalTo(state ? Material.LEGACY_REDSTONE_COMPARATOR_ON : Material.LEGACY_REDSTONE_COMPARATOR_OFF), "Constructed with correct comparator state");
assertThat("Constructed with correct powered", comparator.isPowered(), equalTo(state)); assertThat(comparator.isPowered(), equalTo(state), "Constructed with correct powered");
assertThat("Constructed with default being powered", comparator.isBeingPowered(), equalTo(false)); assertThat(comparator.isBeingPowered(), equalTo(false), "Constructed with default being powered");
assertThat("Constructed with correct mode", comparator.isSubtractionMode(), equalTo(mode)); assertThat(comparator.isSubtractionMode(), equalTo(mode), "Constructed with correct mode");
assertThat("Constructed with correct direction", comparator.getFacing(), equalTo(direction)); assertThat(comparator.getFacing(), equalTo(direction), "Constructed with correct direction");
// Check if the game sets the fourth bit, that block data is still interpreted correctly // Check if the game sets the fourth bit, that block data is still interpreted correctly
comparator.setData((byte) ((comparator.getData() & 0x7) | 0x8)); 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(comparator.getItemType(), equalTo(state ? Material.LEGACY_REDSTONE_COMPARATOR_ON : Material.LEGACY_REDSTONE_COMPARATOR_OFF), "Constructed with correct comparator state");
assertThat("Constructed with correct powered", comparator.isPowered(), equalTo(state)); assertThat(comparator.isPowered(), equalTo(state), "Constructed with correct powered");
assertThat("Constructed with correct being powered", comparator.isBeingPowered(), equalTo(true)); assertThat(comparator.isBeingPowered(), equalTo(true), "Constructed with correct being powered");
assertThat("Constructed with correct mode", comparator.isSubtractionMode(), equalTo(mode)); assertThat(comparator.isSubtractionMode(), equalTo(mode), "Constructed with correct mode");
assertThat("Constructed with correct direction", comparator.getFacing(), equalTo(direction)); assertThat(comparator.getFacing(), equalTo(direction), "Constructed with correct direction");
} }
} }
} }
@ -402,25 +402,25 @@ public class MaterialDataTest {
@Test @Test
public void testHopper() { public void testHopper() {
Hopper hopper = new Hopper(); Hopper hopper = new Hopper();
assertThat("Constructed with default hopper type", hopper.getItemType(), equalTo(Material.LEGACY_HOPPER)); assertThat(hopper.getItemType(), equalTo(Material.LEGACY_HOPPER), "Constructed with default hopper type");
assertThat("Constructed with default active state", hopper.isActive(), equalTo(true)); assertThat(hopper.isActive(), equalTo(true), "Constructed with default active state");
assertThat("Constructed with default powered state", hopper.isPowered(), equalTo(false)); assertThat(hopper.isPowered(), equalTo(false), "Constructed with default powered state");
assertThat("Constructed with default direction", hopper.getFacing(), equalTo(BlockFace.DOWN)); assertThat(hopper.getFacing(), equalTo(BlockFace.DOWN), "Constructed with default direction");
BlockFace[] directions = new BlockFace[]{BlockFace.DOWN, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST, BlockFace.EAST}; BlockFace[] directions = new BlockFace[]{BlockFace.DOWN, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST, BlockFace.EAST};
boolean[] activeStates = new boolean[]{true, false}; boolean[] activeStates = new boolean[]{true, false};
for (BlockFace direction : directions) { for (BlockFace direction : directions) {
hopper = new Hopper(direction); hopper = new Hopper(direction);
assertThat("Constructed with default hopper type", hopper.getItemType(), equalTo(Material.LEGACY_HOPPER)); assertThat(hopper.getItemType(), equalTo(Material.LEGACY_HOPPER), "Constructed with default hopper type");
assertThat("Constructed with default active state", hopper.isActive(), equalTo(true)); assertThat(hopper.isActive(), equalTo(true), "Constructed with default active state");
assertThat("Constructed with correct powered state", hopper.isPowered(), equalTo(false)); assertThat(hopper.isPowered(), equalTo(false), "Constructed with correct powered state");
assertThat("Constructed with correct direction", hopper.getFacing(), equalTo(direction)); assertThat(hopper.getFacing(), equalTo(direction), "Constructed with correct direction");
for (boolean isActive : activeStates) { for (boolean isActive : activeStates) {
hopper = new Hopper(direction, isActive); hopper = new Hopper(direction, isActive);
assertThat("Constructed with default hopper type", hopper.getItemType(), equalTo(Material.LEGACY_HOPPER)); assertThat(hopper.getItemType(), equalTo(Material.LEGACY_HOPPER), "Constructed with default hopper type");
assertThat("Constructed with correct active state", hopper.isActive(), equalTo(isActive)); assertThat(hopper.isActive(), equalTo(isActive), "Constructed with correct active state");
assertThat("Constructed with correct powered state", hopper.isPowered(), equalTo(!isActive)); assertThat(hopper.isPowered(), equalTo(!isActive), "Constructed with correct powered state");
assertThat("Constructed with correct direction", hopper.getFacing(), equalTo(direction)); assertThat(hopper.getFacing(), equalTo(direction), "Constructed with correct direction");
} }
} }
} }

View file

@ -1,9 +1,9 @@
package org.bukkit.metadata; 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.Plugin;
import org.bukkit.plugin.TestPlugin; import org.bukkit.plugin.TestPlugin;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class FixedMetadataValueTest { public class FixedMetadataValueTest {
private Plugin plugin = new TestPlugin("X"); private Plugin plugin = new TestPlugin("X");
@ -21,7 +21,7 @@ public class FixedMetadataValueTest {
subject = new FixedMetadataValue(plugin, new Integer(5)); subject = new FixedMetadataValue(plugin, new Integer(5));
assertEquals(new Integer(5), subject.value()); assertEquals(new Integer(5), subject.value());
assertEquals(5, subject.asInt()); assertEquals(5, subject.asInt());
assertEquals(true, subject.asBoolean()); assertTrue(subject.asBoolean());
assertEquals(5, subject.asByte()); assertEquals(5, subject.asByte());
assertEquals(5.0, subject.asFloat(), 0.1e-8); assertEquals(5.0, subject.asFloat(), 0.1e-8);
assertEquals(5.0D, subject.asDouble(), 0.1e-8D); assertEquals(5.0D, subject.asDouble(), 0.1e-8D);

View file

@ -1,9 +1,9 @@
package org.bukkit.metadata; package org.bukkit.metadata;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import org.bukkit.plugin.TestPlugin; import org.bukkit.plugin.TestPlugin;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class LazyMetadataValueTest { public class LazyMetadataValueTest {
private LazyMetadataValue subject; private LazyMetadataValue subject;
@ -41,7 +41,7 @@ public class LazyMetadataValueTest {
assertEquals(value, subject.value()); assertEquals(value, subject.value());
} }
@Test(expected = MetadataEvaluationException.class) @Test
public void testEvalException() { public void testEvalException() {
subject = new LazyMetadataValue(plugin, LazyMetadataValue.CacheStrategy.CACHE_AFTER_FIRST_EVAL, new Callable<Object>() { subject = new LazyMetadataValue(plugin, LazyMetadataValue.CacheStrategy.CACHE_AFTER_FIRST_EVAL, new Callable<Object>() {
@Override @Override
@ -49,7 +49,7 @@ public class LazyMetadataValueTest {
throw new RuntimeException("Gotcha!"); throw new RuntimeException("Gotcha!");
} }
}); });
subject.value(); assertThrows(MetadataEvaluationException.class, () -> subject.value());
} }
@Test @Test

View file

@ -15,10 +15,10 @@
package org.bukkit.metadata; 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.Plugin;
import org.bukkit.plugin.TestPlugin; 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.asLong());
assertEquals(10, subject.asShort()); assertEquals(10, subject.asShort());
assertEquals(10, subject.asByte()); assertEquals(10, subject.asByte());
assertEquals(true, subject.asBoolean()); assertTrue(subject.asBoolean());
assertEquals("10", subject.asString()); assertEquals("10", subject.asString());
} }
@ -54,7 +54,7 @@ public class MetadataConversionTest {
assertEquals(10, subject.asLong()); assertEquals(10, subject.asLong());
assertEquals(10, subject.asShort()); assertEquals(10, subject.asShort());
assertEquals(10, subject.asByte()); assertEquals(10, subject.asByte());
assertEquals(true, subject.asBoolean()); assertTrue(subject.asBoolean());
assertEquals("10.5", subject.asString()); assertEquals("10.5", subject.asString());
} }
@ -68,7 +68,7 @@ public class MetadataConversionTest {
assertEquals(10, subject.asLong()); assertEquals(10, subject.asLong());
assertEquals(10, subject.asShort()); assertEquals(10, subject.asShort());
assertEquals(10, subject.asByte()); assertEquals(10, subject.asByte());
assertEquals(false, subject.asBoolean()); assertFalse(subject.asBoolean());
assertEquals("10", subject.asString()); assertEquals("10", subject.asString());
} }
@ -82,7 +82,7 @@ public class MetadataConversionTest {
assertEquals(0, subject.asLong()); assertEquals(0, subject.asLong());
assertEquals(0, subject.asShort()); assertEquals(0, subject.asShort());
assertEquals(0, subject.asByte()); assertEquals(0, subject.asByte());
assertEquals(true, subject.asBoolean()); assertTrue(subject.asBoolean());
assertEquals("true", subject.asString()); assertEquals("true", subject.asString());
} }
@ -96,7 +96,7 @@ public class MetadataConversionTest {
assertEquals(0, subject.asLong()); assertEquals(0, subject.asLong());
assertEquals(0, subject.asShort()); assertEquals(0, subject.asShort());
assertEquals(0, subject.asByte()); assertEquals(0, subject.asByte());
assertEquals(false, subject.asBoolean()); assertFalse(subject.asBoolean());
assertEquals("", subject.asString()); assertEquals("", subject.asString());
} }
} }

View file

@ -1,11 +1,11 @@
package org.bukkit.metadata; package org.bukkit.metadata;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.TestPlugin; import org.bukkit.plugin.TestPlugin;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class MetadataStoreTest { public class MetadataStoreTest {
private Plugin pluginX = new TestPlugin("x"); private Plugin pluginX = new TestPlugin("x");

View file

@ -1,9 +1,9 @@
package org.bukkit.metadata; 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.Plugin;
import org.bukkit.plugin.TestPlugin; import org.bukkit.plugin.TestPlugin;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class MetadataValueAdapterTest { public class MetadataValueAdapterTest {
private TestPlugin plugin = new TestPlugin("x"); private TestPlugin plugin = new TestPlugin("x");
@ -38,25 +38,25 @@ public class MetadataValueAdapterTest {
@Test @Test
public void testBooleanConversion() { public void testBooleanConversion() {
// null is False. // null is False.
assertEquals(false, simpleValue(null).asBoolean()); assertFalse(simpleValue(null).asBoolean());
// String to boolean. // String to boolean.
assertEquals(true, simpleValue("True").asBoolean()); assertTrue(simpleValue("True").asBoolean());
assertEquals(true, simpleValue("TRUE").asBoolean()); assertTrue(simpleValue("TRUE").asBoolean());
assertEquals(false, simpleValue("false").asBoolean()); assertFalse(simpleValue("false").asBoolean());
// Number to boolean. // Number to boolean.
assertEquals(true, simpleValue(1).asBoolean()); assertTrue(simpleValue(1).asBoolean());
assertEquals(true, simpleValue(5.0).asBoolean()); assertTrue(simpleValue(5.0).asBoolean());
assertEquals(false, simpleValue(0).asBoolean()); assertFalse(simpleValue(0).asBoolean());
assertEquals(false, simpleValue(0.1).asBoolean()); assertFalse(simpleValue(0.1).asBoolean());
// Boolean as boolean, of course. // Boolean as boolean, of course.
assertEquals(true, simpleValue(Boolean.TRUE).asBoolean()); assertTrue(simpleValue(Boolean.TRUE).asBoolean());
assertEquals(false, simpleValue(Boolean.FALSE).asBoolean()); assertFalse(simpleValue(Boolean.FALSE).asBoolean());
// any object that is not null and not a Boolean, String, or Number is true. // 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. */ /** Test String conversions return an empty string when given null. */

View file

@ -1,14 +1,14 @@
package org.bukkit.plugin; package org.bukkit.plugin;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.TestEvent; import org.bukkit.event.TestEvent;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class PluginManagerTest extends AbstractTestingBase { public class PluginManagerTest extends AbstractTestingBase {
private class MutableObject { private class MutableObject {
@ -164,20 +164,20 @@ public class PluginManagerTest extends AbstractTestingBase {
private void testRemovePermissionByName(final String name) { private void testRemovePermissionByName(final String name) {
final Permission perm = new Permission(name); final Permission perm = new Permission(name);
pm.addPermission(perm); 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); 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) { private void testRemovePermissionByPermission(final String name) {
final Permission perm = new Permission(name); final Permission perm = new Permission(name);
pm.addPermission(perm); 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); 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() { public void tearDown() {
pm.clearPlugins(); pm.clearPlugins();
assertThat(pm.getPermissions(), is(empty())); assertThat(pm.getPermissions(), is(empty()));

View file

@ -1,7 +1,7 @@
package org.bukkit.plugin; package org.bukkit.plugin;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.EventException; import org.bukkit.event.EventException;
import org.bukkit.event.EventPriority; 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.PlayerEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class TimedRegisteredListenerTest { public class TimedRegisteredListenerTest {

View file

@ -1,13 +1,13 @@
package org.bukkit.plugin.messaging; package org.bukkit.plugin.messaging;
import static org.hamcrest.CoreMatchers.*; import static org.bukkit.support.MatcherAssert.*;
import static org.junit.Assert.*; import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.util.Collection; import java.util.Collection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.TestPlugin; import org.bukkit.plugin.TestPlugin;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class StandardMessengerTest { public class StandardMessengerTest {
public StandardMessenger getMessenger() { public StandardMessenger getMessenger() {
@ -45,12 +45,12 @@ public class StandardMessengerTest {
assertFalse(messenger.isOutgoingChannelRegistered(plugin, "test:foo")); assertFalse(messenger.isOutgoingChannelRegistered(plugin, "test:foo"));
} }
@Test(expected = ReservedChannelException.class) @Test
public void testReservedOutgoingRegistration() { public void testReservedOutgoingRegistration() {
Messenger messenger = getMessenger(); Messenger messenger = getMessenger();
TestPlugin plugin = getPlugin(); TestPlugin plugin = getPlugin();
messenger.registerOutgoingPluginChannel(plugin, "minecraft:register"); assertThrows(ReservedChannelException.class, () -> messenger.registerOutgoingPluginChannel(plugin, "minecraft:register"));
} }
@Test @Test
@ -91,22 +91,22 @@ public class StandardMessengerTest {
assertFalse(listener.hasReceived()); assertFalse(listener.hasReceived());
} }
@Test(expected = ReservedChannelException.class) @Test
public void testReservedIncomingRegistration() { public void testReservedIncomingRegistration() {
Messenger messenger = getMessenger(); Messenger messenger = getMessenger();
TestPlugin plugin = getPlugin(); 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() { public void testDuplicateIncomingRegistration() {
Messenger messenger = getMessenger(); Messenger messenger = getMessenger();
TestPlugin plugin = getPlugin(); TestPlugin plugin = getPlugin();
TestMessageListener listener = new TestMessageListener("test:foo", "test:bar".getBytes()); TestMessageListener listener = new TestMessageListener("test:foo", "test:bar".getBytes());
messenger.registerIncomingPluginChannel(plugin, "test:baz", listener); messenger.registerIncomingPluginChannel(plugin, "test:baz", listener);
messenger.registerIncomingPluginChannel(plugin, "test:baz", listener); assertThrows(IllegalArgumentException.class, () -> messenger.registerIncomingPluginChannel(plugin, "test:baz", listener));
} }
@Test @Test
@ -173,14 +173,14 @@ public class StandardMessengerTest {
TestPlugin plugin1 = getPlugin(); TestPlugin plugin1 = getPlugin();
TestPlugin plugin2 = getPlugin(); TestPlugin plugin2 = getPlugin();
assertEquals(messenger.getOutgoingChannels()); assertCollectionEquals(messenger.getOutgoingChannels());
messenger.registerOutgoingPluginChannel(plugin1, "test:foo"); messenger.registerOutgoingPluginChannel(plugin1, "test:foo");
messenger.registerOutgoingPluginChannel(plugin1, "test:bar"); messenger.registerOutgoingPluginChannel(plugin1, "test:bar");
messenger.registerOutgoingPluginChannel(plugin2, "test:baz"); messenger.registerOutgoingPluginChannel(plugin2, "test:baz");
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 @Test
@ -195,9 +195,9 @@ public class StandardMessengerTest {
messenger.registerOutgoingPluginChannel(plugin2, "test:baz"); messenger.registerOutgoingPluginChannel(plugin2, "test:baz");
messenger.registerOutgoingPluginChannel(plugin2, "test:qux"); messenger.registerOutgoingPluginChannel(plugin2, "test:qux");
assertEquals(messenger.getOutgoingChannels(plugin1), "test:foo", "test:bar"); assertCollectionEquals(messenger.getOutgoingChannels(plugin1), "test:foo", "test:bar");
assertEquals(messenger.getOutgoingChannels(plugin2), "test:baz", "test:qux"); assertCollectionEquals(messenger.getOutgoingChannels(plugin2), "test:baz", "test:qux");
assertEquals(messenger.getOutgoingChannels(plugin3)); assertCollectionEquals(messenger.getOutgoingChannels(plugin3));
} }
@Test @Test
@ -206,14 +206,14 @@ public class StandardMessengerTest {
TestPlugin plugin1 = getPlugin(); TestPlugin plugin1 = getPlugin();
TestPlugin plugin2 = 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:foo", new TestMessageListener("test:foo", "test:bar".getBytes()));
messenger.registerIncomingPluginChannel(plugin1, "test:bar", 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()));
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 @Test
@ -228,9 +228,9 @@ public class StandardMessengerTest {
messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes())); messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes()));
messenger.registerIncomingPluginChannel(plugin2, "test:qux", 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"); assertCollectionEquals(messenger.getIncomingChannels(plugin1), "test:foo", "test:bar");
assertEquals(messenger.getIncomingChannels(plugin2), "test:baz", "test:qux"); assertCollectionEquals(messenger.getIncomingChannels(plugin2), "test:baz", "test:qux");
assertEquals(messenger.getIncomingChannels(plugin3)); assertCollectionEquals(messenger.getIncomingChannels(plugin3));
} }
@Test @Test
@ -244,9 +244,9 @@ public class StandardMessengerTest {
PluginMessageListenerRegistration registration3 = messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes())); 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())); PluginMessageListenerRegistration registration4 = messenger.registerIncomingPluginChannel(plugin2, "test:qux", new TestMessageListener("test:foo", "test:bar".getBytes()));
assertEquals(messenger.getIncomingChannelRegistrations(plugin1), registration1, registration2); assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin1), registration1, registration2);
assertEquals(messenger.getIncomingChannelRegistrations(plugin2), registration3, registration4); assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin2), registration3, registration4);
assertEquals(messenger.getIncomingChannels(plugin3)); assertCollectionEquals(messenger.getIncomingChannels(plugin3));
} }
@Test @Test
@ -259,9 +259,9 @@ public class StandardMessengerTest {
PluginMessageListenerRegistration registration3 = messenger.registerIncomingPluginChannel(plugin2, "test:foo", new TestMessageListener("test:foo", "test:bar".getBytes())); 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())); PluginMessageListenerRegistration registration4 = messenger.registerIncomingPluginChannel(plugin2, "test:bar", new TestMessageListener("test:foo", "test:bar".getBytes()));
assertEquals(messenger.getIncomingChannelRegistrations("test:foo"), registration1, registration3); assertCollectionEquals(messenger.getIncomingChannelRegistrations("test:foo"), registration1, registration3);
assertEquals(messenger.getIncomingChannelRegistrations("test:bar"), registration2, registration4); assertCollectionEquals(messenger.getIncomingChannelRegistrations("test:bar"), registration2, registration4);
assertEquals(messenger.getIncomingChannelRegistrations("test:baz")); assertCollectionEquals(messenger.getIncomingChannelRegistrations("test:baz"));
} }
@Test @Test
@ -277,30 +277,30 @@ public class StandardMessengerTest {
PluginMessageListenerRegistration registration5 = messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes())); 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())); PluginMessageListenerRegistration registration6 = messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes()));
assertEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:foo"), registration1, registration2); assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:foo"), registration1, registration2);
assertEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:bar"), registration3); assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:bar"), registration3);
assertEquals(messenger.getIncomingChannelRegistrations(plugin2, "test:bar"), registration4); assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin2, "test:bar"), registration4);
assertEquals(messenger.getIncomingChannelRegistrations(plugin2, "test:baz"), registration5, registration6); assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin2, "test:baz"), registration5, registration6);
assertEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:baz")); assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:baz"));
assertEquals(messenger.getIncomingChannelRegistrations(plugin3, "test:qux")); assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin3, "test:qux"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testInvalidChannel() { public void testInvalidChannel() {
Messenger messenger = getMessenger(); Messenger messenger = getMessenger();
TestPlugin plugin = getPlugin(); TestPlugin plugin = getPlugin();
messenger.registerOutgoingPluginChannel(plugin, "foo"); assertThrows(IllegalArgumentException.class, () -> messenger.registerOutgoingPluginChannel(plugin, "foo"));
} }
@Test @Test
public void testValidateAndCorrectChannel() { public void testValidateAndCorrectChannel() {
Assert.assertEquals("bungeecord:main", StandardMessenger.validateAndCorrectChannel("BungeeCord")); assertEquals("bungeecord:main", StandardMessenger.validateAndCorrectChannel("BungeeCord"));
Assert.assertEquals("BungeeCord", StandardMessenger.validateAndCorrectChannel("bungeecord:main")); assertEquals("BungeeCord", StandardMessenger.validateAndCorrectChannel("bungeecord:main"));
} }
private static <T> void assertEquals(Collection<T> actual, T... expected) { private static <T> void assertCollectionEquals(Collection<T> actual, T... expected) {
assertThat("Size of the array", actual.size(), is(expected.length)); assertThat(actual.size(), is(expected.length), "Size of the array");
assertThat(actual, hasItems(expected)); assertThat(actual, hasItems(expected));
} }
} }

View file

@ -1,6 +1,6 @@
package org.bukkit.plugin.messaging; package org.bukkit.plugin.messaging;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class TestMessageListener implements PluginMessageListener { public class TestMessageListener implements PluginMessageListener {

View file

@ -1,22 +1,22 @@
package org.bukkit.scoreboard; package org.bukkit.scoreboard;
import static org.junit.jupiter.api.Assertions.*;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Statistic; import org.bukkit.Statistic;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class CriteriaTest extends AbstractTestingBase { public class CriteriaTest extends AbstractTestingBase {
@Test @Test
public void testStatistic() { public void testStatistic() {
Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, Material.STONE)); // Generic statistic with block 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, EntityType.CREEPER)); // Generic statistic with entity type
Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.ENTITY_KILLED_BY, Material.AMETHYST_SHARD)); // Entity statistic with material 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 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 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.KILL_ENTITY, Material.STONE)); // Entity statistic with Material
} }
} }

View file

@ -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.
* <br>
* <pre>
* 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)));
* </pre>
* vs.
* <pre>
* 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));
* </pre>
*/
public final class MatcherAssert {
private MatcherAssert() {}
public static <T> void assertThat(T actual, Matcher<? super T> matcher) {
org.hamcrest.MatcherAssert.assertThat(actual, matcher);
}
public static <T> void assertThat(T actual, Matcher<? super T> matcher, String reason) {
org.hamcrest.MatcherAssert.assertThat(reason, actual, matcher);
}
public static void assertThat(boolean assertion, String reason) {
org.hamcrest.MatcherAssert.assertThat(reason, assertion);
}
}

View file

@ -1,11 +1,11 @@
package org.bukkit.util; package org.bukkit.util;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.util.Map; import java.util.Map;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class BoundingBoxTest { public class BoundingBoxTest {

View file

@ -1,83 +1,72 @@
package org.bukkit.util; package org.bukkit.util;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*; import java.util.stream.Stream;
import com.google.common.collect.ImmutableList; import org.junit.jupiter.params.ParameterizedTest;
import java.util.List; import org.junit.jupiter.params.provider.Arguments;
import org.junit.Test; import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class StringUtilStartsWithTest { public class StringUtilStartsWithTest {
@Parameters(name = "{index}: {0} startsWith {1} == {2}") public static Stream<Arguments> data() {
public static List<Object[]> data() { return Stream.of(
return ImmutableList.<Object[]>of( Arguments.of(
new Object[] { "Apple",
"Apple", "Apples",
"Apples", false
false ),
}, Arguments.of(
new Object[] { "Apples",
"Apples", "Apple",
"Apple", true
true ),
}, Arguments.of(
new Object[] { "Apple",
"Apple", "Apple",
"Apple", true
true ),
}, Arguments.of(
new Object[] { "Apple",
"Apple", "apples",
"apples", false
false ),
}, Arguments.of(
new Object[] { "apple",
"apple", "Apples",
"Apples", false
false ),
}, Arguments.of(
new Object[] { "apple",
"apple", "apples",
"apples", false
false ),
}, Arguments.of(
new Object[] { "Apples",
"Apples", "apPL",
"apPL", true
true ),
}, Arguments.of(
new Object[] { "123456789",
"123456789", "1234567",
"1234567", true
true ),
}, Arguments.of(
new Object[] { "",
"", "",
"", true
true ),
}, Arguments.of(
new Object[] { "string",
"string", "",
"", true
true )
}
); );
} }
@Parameter(0) @ParameterizedTest
public String base; @MethodSource("data")
@Parameter(1) public void testFor(String base, String prefix, boolean result) {
public String prefix; assertThat(StringUtil.startsWithIgnoreCase(base, prefix), is(result), base + " starts with " + prefix + ": " + result);
@Parameter(2)
public boolean result;
@Test
public void testFor() {
assertThat(base + " starts with " + prefix + ": " + result, StringUtil.startsWithIgnoreCase(base, prefix), is(result));
} }
} }

View file

@ -1,38 +1,39 @@
package org.bukkit.util; package org.bukkit.util;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class StringUtilTest { public class StringUtilTest {
@Test(expected = NullPointerException.class) @Test
public void nullPrefixTest() { public void nullPrefixTest() {
StringUtil.startsWithIgnoreCase("String", null); assertThrows(NullPointerException.class, () -> StringUtil.startsWithIgnoreCase("String", null));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void nullStringTest() { public void nullStringTest() {
StringUtil.startsWithIgnoreCase(null, "String"); assertThrows(IllegalArgumentException.class, () -> StringUtil.startsWithIgnoreCase(null, "String"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void nullCollectionTest() { public void nullCollectionTest() {
StringUtil.copyPartialMatches("Token", ImmutableList.<String>of(), null); assertThrows(IllegalArgumentException.class, () -> StringUtil.copyPartialMatches("Token", ImmutableList.<String>of(), null));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void nullIterableTest() { public void nullIterableTest() {
StringUtil.copyPartialMatches("Token", null, new ArrayList<String>()); assertThrows(IllegalArgumentException.class, () -> StringUtil.copyPartialMatches("Token", null, new ArrayList<String>()));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void nullTokenTest() { public void nullTokenTest() {
StringUtil.copyPartialMatches(null, ImmutableList.<String>of(), new ArrayList<String>()); assertThrows(IllegalArgumentException.class, () -> StringUtil.copyPartialMatches(null, ImmutableList.<String>of(), new ArrayList<String>()));
} }
@Test @Test
@ -46,13 +47,13 @@ public class StringUtilTest {
assertThat(list.size(), is(expected.size() * 2)); assertThat(list.size(), is(expected.size() * 2));
} }
@Test(expected = UnsupportedOperationException.class) @Test
public void copyUnsupportedTest() { 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() { public void copyNullTest() {
StringUtil.copyPartialMatches("token", Arrays.asList("token1", "token2", null), new ArrayList<String>()); assertThrows(IllegalArgumentException.class, () -> StringUtil.copyPartialMatches("token", Arrays.asList("token1", "token2", null), new ArrayList<String>()));
} }
} }

View file

@ -1,8 +1,8 @@
package org.bukkit.util; package org.bukkit.util;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class VectorTest { public class VectorTest {
@ -14,9 +14,9 @@ public class VectorTest {
assertTrue(new Vector(1, 0, 0).isNormalized()); assertTrue(new Vector(1, 0, 0).isNormalized());
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testNullVectorAxis() { 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 @Test

View file

@ -1,7 +1,7 @@
package org.bukkit.util.io; package org.bukkit.util.io;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -9,80 +9,69 @@ import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Type; import org.bukkit.FireworkEffect.Type;
import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.Arguments;
import org.junit.runners.Parameterized; import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
@RunWith(Parameterized.class)
public class BukkitObjectStreamTest { public class BukkitObjectStreamTest {
@Parameters(name = "{index}: {0}") public static Stream<Arguments> data() {
public static List<Object[]> data() { return Stream.of(
return ImmutableList.<Object[]>of( Arguments.of(
new Object[] { Color.class.getName(),
Color.class.getName(), "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", ImmutableList.of(
ImmutableList.of( Color.WHITE,
Color.WHITE, Color.TEAL,
Color.TEAL, Color.PURPLE,
Color.PURPLE, Color.RED,
Color.RED, Color.ORANGE
Color.ORANGE )
) ),
}, Arguments.of(
new Object[] { FireworkEffect.class.getName(),
FireworkEffect.class.getName(), "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", ImmutableList.of(
ImmutableList.of( FireworkEffect.builder()
FireworkEffect.builder() .withColor(Color.BLACK, Color.SILVER)
.withColor(Color.BLACK, Color.SILVER) .with(Type.BALL_LARGE)
.with(Type.BALL_LARGE) .withFade(Color.WHITE)
.withFade(Color.WHITE) .withFlicker()
.withFlicker() .build(),
.build(), FireworkEffect.builder()
FireworkEffect.builder() .withColor(Color.NAVY)
.withColor(Color.NAVY) .build(),
.build(), FireworkEffect.builder()
FireworkEffect.builder() .withColor(Color.MAROON)
.withColor(Color.MAROON) .withTrail()
.withTrail() .withFlicker()
.withFlicker() .with(Type.CREEPER)
.with(Type.CREEPER) .build()
.build() )
), ),
}, Arguments.of(
new Object[] { Vector.class.getName(),
Vector.class.getName(), "rO0ABXNyADZjb20uZ29vZ2xlLmNvbW1vbi5jb2xsZWN0LkltbXV0YWJsZUxpc3QkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAVsACGVsZW1lbnRzdAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABHNyABpvcmcuYnVra2l0LnV0aWwuaW8uV3JhcHBlcvJQR+zxEm8FAgABTAADbWFwdAAPTGphdmEvdXRpbC9NYXA7eHBzcgA1Y29tLmdvb2dsZS5jb21tb24uY29sbGVjdC5JbW11dGFibGVNYXAkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABGtleXNxAH4AAVsABnZhbHVlc3EAfgABeHB1cQB+AAMAAAAEdAACPT10AAF4dAABeXQAAXp1cQB+AAMAAAAEdAAGVmVjdG9yc3IAEGphdmEubGFuZy5Eb3VibGWAs8JKKWv7BAIAAUQABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAAAAAABzcQB+ABEAAAAAAAAAAHNxAH4AEQAAAAAAAAAAc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARQIOFwo9cKPZzcQB+ABFAtCKcKPXCj3NxAH4AEUBzrpeNT987c3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARwEQTMzMzMzNzcQB+ABFASYAAAAAAAHNxAH4AEcCjqG3UQTVUc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARQd/////AAABzcQB+ABHB4AAAAAAAAHNxAH4AEQAAAAAAAAAA",
"rO0ABXNyADZjb20uZ29vZ2xlLmNvbW1vbi5jb2xsZWN0LkltbXV0YWJsZUxpc3QkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAVsACGVsZW1lbnRzdAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABHNyABpvcmcuYnVra2l0LnV0aWwuaW8uV3JhcHBlcvJQR+zxEm8FAgABTAADbWFwdAAPTGphdmEvdXRpbC9NYXA7eHBzcgA1Y29tLmdvb2dsZS5jb21tb24uY29sbGVjdC5JbW11dGFibGVNYXAkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABGtleXNxAH4AAVsABnZhbHVlc3EAfgABeHB1cQB+AAMAAAAEdAACPT10AAF4dAABeXQAAXp1cQB+AAMAAAAEdAAGVmVjdG9yc3IAEGphdmEubGFuZy5Eb3VibGWAs8JKKWv7BAIAAUQABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAAAAAABzcQB+ABEAAAAAAAAAAHNxAH4AEQAAAAAAAAAAc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARQIOFwo9cKPZzcQB+ABFAtCKcKPXCj3NxAH4AEUBzrpeNT987c3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARwEQTMzMzMzNzcQB+ABFASYAAAAAAAHNxAH4AEcCjqG3UQTVUc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARQd/////AAABzcQB+ABHB4AAAAAAAAHNxAH4AEQAAAAAAAAAA", ImmutableList.of(
ImmutableList.of( new Vector(0, 0, 0),
new Vector(0, 0, 0), new Vector(624.72, 5154.61, 314.912),
new Vector(624.72, 5154.61, 314.912), new Vector(-40.15, 51, -2516.21451),
new Vector(-40.15, 51, -2516.21451), new Vector(Integer.MAX_VALUE, Integer.MIN_VALUE, 0)
new Vector(Integer.MAX_VALUE, Integer.MIN_VALUE, 0) )
) ));
});
} }
@Parameter(0) @ParameterizedTest
public String className; @MethodSource("data")
public void checkSerlialization(String className, String preEncoded, List<ConfigurationSerializable> object) throws Throwable {
@Parameter(1)
public String preEncoded;
@Parameter(2)
public List<ConfigurationSerializable> object;
@Test
public void checkSerlialization() throws Throwable {
// If this test fails, you may start your trek to debug by commenting the '@Ignore' on the next method // 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) // (and of course, you would read those comments too)
final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -102,7 +91,7 @@ public class BukkitObjectStreamTest {
final byte[] preEncodedArray = Base64Coder.decode(preEncoded); final byte[] preEncodedArray = Base64Coder.decode(preEncoded);
final Object readBack; final Object readBack;
final Object preEncoded; final Object encoded;
ObjectInputStream ois = null; ObjectInputStream ois = null;
ObjectInputStream preois = null; ObjectInputStream preois = null;
@ -113,7 +102,7 @@ public class BukkitObjectStreamTest {
preois = new BukkitObjectInputStream(preIn); preois = new BukkitObjectInputStream(preIn);
readBack = ois.readObject(); readBack = ois.readObject();
preEncoded = preois.readObject(); encoded = preois.readObject();
} finally { } finally {
if (ois != null) { if (ois != null) {
try { try {
@ -130,12 +119,13 @@ public class BukkitObjectStreamTest {
} }
assertThat(object, is(readBack)); assertThat(object, is(readBack));
assertThat(object, is(preEncoded)); assertThat(object, is(encoded));
} }
@Ignore @Disabled
@Test @ParameterizedTest
public void preEncoded() throws Throwable { @MethodSource("data")
public void preEncoded(String className, String preEncoded, List<ConfigurationSerializable> object) throws Throwable {
// This test is placed in the case that a necessary change is made to change the encoding format // 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 // Just remove the ignore (or run manually) and it'll give you the new pre-encoded values