#1256: Update tests to JUnit 5

This commit is contained in:
DerFrZocker 2023-09-23 18:10:23 +10:00 committed by md_5
parent f71a799f03
commit 452fcb5997
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
62 changed files with 770 additions and 732 deletions

View File

@ -64,7 +64,7 @@ Code Requirements
* Do not submit your personal changes to configuration files. * Do not submit your personal changes to configuration files.
* Avoid moving or renaming classes. * Avoid moving or renaming classes.
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.

16
pom.xml
View File

@ -217,6 +217,12 @@
<artifactId>json-simple</artifactId> <artifactId>json-simple</artifactId>
<version>1.1.1</version> <version>1.1.1</version>
<scope>runtime</scope> <scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.xerial</groupId> <groupId>org.xerial</groupId>
@ -258,15 +264,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>
</dependencies> </dependencies>

View File

@ -1,7 +1,8 @@
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 com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.util.Collections; import java.util.Collections;
import java.util.EnumMap; import java.util.EnumMap;
@ -14,7 +15,7 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.decoration.PaintingVariant; import net.minecraft.world.entity.decoration.PaintingVariant;
import org.bukkit.craftbukkit.CraftArt; import org.bukkit.craftbukkit.CraftArt;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class ArtTest extends AbstractTestingBase { public class ArtTest extends AbstractTestingBase {
private static final int UNIT_MULTIPLIER = 16; private static final int UNIT_MULTIPLIER = 16;
@ -32,16 +33,16 @@ public class ArtTest extends AbstractTestingBase {
Art subject = CraftArt.minecraftHolderToBukkit(enumArt); Art subject = CraftArt.minecraftHolderToBukkit(enumArt);
String message = String.format("org.bukkit.Art is missing '%s'", name); String message = String.format("org.bukkit.Art is missing '%s'", name);
assertNotNull(message, subject); assertNotNull(subject, message);
assertThat(Art.getByName(name), is(subject)); assertThat(Art.getByName(name), is(subject));
assertThat("Art." + subject + "'s width", subject.getBlockWidth(), is(width)); assertThat(subject.getBlockWidth(), is(width), "Art." + subject + "'s width");
assertThat("Art." + subject + "'s height", subject.getBlockHeight(), is(height)); assertThat(subject.getBlockHeight(), is(height), "Art." + subject + "'s height");
arts.remove(subject); arts.remove(subject);
} }
assertThat("org.bukkit.Art has too many arts", arts, is(Collections.EMPTY_LIST)); assertThat(arts, is(Collections.EMPTY_LIST), "org.bukkit.Art has too many arts");
} }
@Test @Test
@ -49,8 +50,8 @@ public class ArtTest extends AbstractTestingBase {
Map<Holder<PaintingVariant>, Art> cache = new HashMap<>(); Map<Holder<PaintingVariant>, Art> cache = new HashMap<>();
for (Art art : Art.values()) { for (Art art : Art.values()) {
Holder<PaintingVariant> enumArt = CraftArt.bukkitToMinecraftHolder(art); Holder<PaintingVariant> enumArt = CraftArt.bukkitToMinecraftHolder(art);
assertNotNull(art.name(), enumArt); assertNotNull(enumArt, art.name());
assertThat(art.name(), cache.put(enumArt, art), is(nullValue())); assertThat(cache.put(enumArt, art), is(nullValue()), art.name());
} }
} }
@ -59,8 +60,8 @@ public class ArtTest extends AbstractTestingBase {
Map<Art, Holder<PaintingVariant>> cache = new EnumMap(Art.class); Map<Art, Holder<PaintingVariant>> cache = new EnumMap(Art.class);
for (Holder<PaintingVariant> enumArt : BuiltInRegistries.PAINTING_VARIANT.asHolderIdMap()) { for (Holder<PaintingVariant> enumArt : BuiltInRegistries.PAINTING_VARIANT.asHolderIdMap()) {
Art art = CraftArt.minecraftHolderToBukkit(enumArt); Art art = CraftArt.minecraftHolderToBukkit(enumArt);
assertNotNull("Could not CraftArt.NotchToBukkit " + enumArt, art); assertNotNull(art, "Could not CraftArt.NotchToBukkit " + enumArt);
assertThat("Duplicate artwork " + enumArt, cache.put(art, enumArt), is(nullValue())); assertThat(cache.put(art, enumArt), is(nullValue()), "Duplicate artwork " + enumArt);
} }
} }
} }

View File

@ -1,11 +1,11 @@
package org.bukkit; package org.bukkit;
import static org.junit.jupiter.api.Assertions.*;
import net.minecraft.world.level.biome.BiomeBase; import net.minecraft.world.level.biome.BiomeBase;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.craftbukkit.block.CraftBiome;
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 BiomeTest extends AbstractTestingBase { public class BiomeTest extends AbstractTestingBase {
@ -16,7 +16,7 @@ public class BiomeTest extends AbstractTestingBase {
continue; continue;
} }
Assert.assertNotNull("No NMS mapping for " + biome, CraftBiome.bukkitToMinecraftHolder(biome)); assertNotNull(CraftBiome.bukkitToMinecraftHolder(biome), "No NMS mapping for " + biome);
} }
} }
@ -24,7 +24,7 @@ public class BiomeTest extends AbstractTestingBase {
public void testMinecraftToBukkit() { public void testMinecraftToBukkit() {
for (BiomeBase biomeBase : BIOMES) { for (BiomeBase biomeBase : BIOMES) {
Biome biome = CraftBiome.minecraftToBukkit(biomeBase); Biome biome = CraftBiome.minecraftToBukkit(biomeBase);
Assert.assertTrue("No Bukkit mapping for " + biomeBase, biome != null && biome != Biome.CUSTOM); assertTrue(biome != null && biome != Biome.CUSTOM, "No Bukkit mapping for " + biomeBase);
} }
} }
} }

View File

@ -1,38 +1,30 @@
package org.bukkit; package org.bukkit;
import java.util.ArrayList; import static org.junit.jupiter.api.Assertions.*;
import java.util.List; import java.util.stream.Stream;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.block.state.IBlockData;
import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Assert; 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;
/** /**
* This test class ensures that all Blocks (as registered in BuiltInRegistries.BLOCK) * This test class ensures that all Blocks (as registered in BuiltInRegistries.BLOCK)
* can be converted into their CraftBlockData equivalent. * can be converted into their CraftBlockData equivalent.
*/ */
@RunWith(Parameterized.class)
public class BlockDataConversionTest extends AbstractTestingBase { public class BlockDataConversionTest extends AbstractTestingBase {
@Parameterized.Parameters(name = "{index}: {0}") public static Stream<Arguments> data() {
public static List<Object[]> args() { return BuiltInRegistries.BLOCK.stream().map(Block::defaultBlockState).map(Arguments::of);
List<Object[]> list = new ArrayList<>();
for (Block block : (Iterable<Block>) BuiltInRegistries.BLOCK) {
list.add(new Object[]{block.defaultBlockState()});
}
return list;
} }
@Parameterized.Parameter(0) public IBlockData data; @ParameterizedTest
@MethodSource("data")
@Test public void testNotNull(IBlockData data) {
public void testNotNull() { assertNotNull(data);
Assert.assertNotNull(data); assertNotNull(CraftBlockData.fromData(data));
Assert.assertNotNull(CraftBlockData.fromData(data));
} }
} }

View File

@ -1,6 +1,8 @@
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.jupiter.api.Assertions.*;
import net.minecraft.core.EnumDirection; import net.minecraft.core.EnumDirection;
import net.minecraft.world.level.block.BlockCake; import net.minecraft.world.level.block.BlockCake;
import net.minecraft.world.level.block.BlockChest; import net.minecraft.world.level.block.BlockChest;
@ -11,8 +13,7 @@ import org.bukkit.block.data.type.Cake;
import org.bukkit.block.data.type.Chest; import org.bukkit.block.data.type.Chest;
import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.block.data.CraftBlockData;
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 BlockDataTest extends AbstractTestingBase { public class BlockDataTest extends AbstractTestingBase {
@ -21,48 +22,48 @@ public class BlockDataTest extends AbstractTestingBase {
BlockData cakeTest = CraftBlockData.fromData(Blocks.CAKE.defaultBlockState().setValue(BlockCake.BITES, 3)); BlockData cakeTest = CraftBlockData.fromData(Blocks.CAKE.defaultBlockState().setValue(BlockCake.BITES, 3));
BlockData materialString = CraftBlockData.newData(Material.CAKE, "[bites=3]"); BlockData materialString = CraftBlockData.newData(Material.CAKE, "[bites=3]");
Assert.assertThat(materialString, is(cakeTest)); assertThat(materialString, is(cakeTest));
BlockData combined = CraftBlockData.newData(null, "cake[bites=3]"); BlockData combined = CraftBlockData.newData(null, "cake[bites=3]");
Assert.assertThat(combined, is(cakeTest)); assertThat(combined, is(cakeTest));
BlockData combinedMinecraft = CraftBlockData.newData(null, "minecraft:cake[bites=3]"); BlockData combinedMinecraft = CraftBlockData.newData(null, "minecraft:cake[bites=3]");
Assert.assertThat(combinedMinecraft, is(cakeTest)); assertThat(combinedMinecraft, is(cakeTest));
BlockData inverted = CraftBlockData.newData(null, cakeTest.getAsString()); BlockData inverted = CraftBlockData.newData(null, cakeTest.getAsString());
Assert.assertThat(inverted, is(cakeTest)); assertThat(inverted, is(cakeTest));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testBadMaterial() { public void testBadMaterial() {
CraftBlockData.newData(null, "invalid"); assertThrows(IllegalArgumentException.class, () -> CraftBlockData.newData(null, "invalid"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testBadSyntax() { public void testBadSyntax() {
CraftBlockData.newData(null, "minecraft:cake[bites=3"); assertThrows(IllegalArgumentException.class, () -> CraftBlockData.newData(null, "minecraft:cake[bites=3"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testDoubleMaterial() { public void testDoubleMaterial() {
CraftBlockData.newData(Material.CAKE, "minecraft:cake[bites=3]"); assertThrows(IllegalArgumentException.class, () -> CraftBlockData.newData(Material.CAKE, "minecraft:cake[bites=3]"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testMistake() { public void testMistake() {
BlockData cakeTest = CraftBlockData.fromData(Blocks.CAKE.defaultBlockState().setValue(BlockCake.BITES, 3)); BlockData cakeTest = CraftBlockData.fromData(Blocks.CAKE.defaultBlockState().setValue(BlockCake.BITES, 3));
CraftBlockData.newData(Material.CAKE, cakeTest.toString()); assertThrows(IllegalArgumentException.class, () -> CraftBlockData.newData(Material.CAKE, cakeTest.toString()));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testItem() { public void testItem() {
CraftBlockData.newData(Material.DIAMOND_AXE, null); assertThrows(IllegalArgumentException.class, () -> CraftBlockData.newData(Material.DIAMOND_AXE, null));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testItemParse() { public void testItemParse() {
CraftBlockData.newData(null, "minecraft:diamond_axe"); assertThrows(IllegalArgumentException.class, () -> CraftBlockData.newData(null, "minecraft:diamond_axe"));
} }
@Test @Test
@ -70,11 +71,11 @@ public class BlockDataTest extends AbstractTestingBase {
Cake cakeTest = (Cake) CraftBlockData.fromData(Blocks.CAKE.defaultBlockState().setValue(BlockCake.BITES, 3)); Cake cakeTest = (Cake) CraftBlockData.fromData(Blocks.CAKE.defaultBlockState().setValue(BlockCake.BITES, 3));
Cake clone = (Cake) cakeTest.clone(); Cake clone = (Cake) cakeTest.clone();
Assert.assertFalse("Clone did not return new object", cakeTest == clone); assertNotSame(cakeTest, clone, "Clone did not return new object");
Assert.assertThat("Clone is not equal", clone, is(cakeTest)); assertThat(clone, is(cakeTest), "Clone is not equal");
clone.setBites(1); clone.setBites(1);
Assert.assertThat("Clone is not actually clone", clone, is(not(cakeTest))); assertThat(clone, is(not(cakeTest)), "Clone is not actually clone");
} }
@Test @Test
@ -85,13 +86,13 @@ public class BlockDataTest extends AbstractTestingBase {
BlockData candidate; BlockData candidate;
Assert.assertFalse("Target and match are not yet equal", trueTarget.equals(waterlogged)); assertNotEquals(trueTarget, waterlogged, "Target and match are not yet equal");
candidate = trueTarget.merge(waterlogged); candidate = trueTarget.merge(waterlogged);
Assert.assertTrue("Target and candidate are now equal", trueTarget.equals(candidate)); assertEquals(trueTarget, candidate, "Target and candidate are now equal");
Assert.assertFalse("Target and match are not yet equal", falseTarget.equals(waterlogged)); assertNotEquals(falseTarget, waterlogged, "Target and match are not yet equal");
candidate = falseTarget.merge(waterlogged); candidate = falseTarget.merge(waterlogged);
Assert.assertFalse("Target and candidate are still not equal", falseTarget.equals(candidate)); assertNotEquals(falseTarget, candidate, "Target and candidate are still not equal");
} }
@Test @Test
@ -102,24 +103,24 @@ public class BlockDataTest extends AbstractTestingBase {
BlockData candidate; BlockData candidate;
Assert.assertFalse("Target and match are not yet equal", trueTarget.equals(any)); assertNotEquals(trueTarget, any, "Target and match are not yet equal");
candidate = trueTarget.merge(any); candidate = trueTarget.merge(any);
Assert.assertTrue("Target and candidate are now equal", trueTarget.equals(candidate)); assertEquals(trueTarget, candidate, "Target and candidate are now equal");
Assert.assertFalse("Target and match are not yet equal", falseTarget.equals(any)); assertNotEquals(falseTarget, any, "Target and match are not yet equal");
candidate = falseTarget.merge(any); candidate = falseTarget.merge(any);
Assert.assertTrue("Target and candidate are now equal", falseTarget.equals(candidate)); assertEquals(falseTarget, candidate, "Target and candidate are now equal");
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testCannotMerge1() { public void testCannotMerge1() {
Chest one = (Chest) CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]"); Chest one = (Chest) CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]");
Chest two = (Chest) CraftBlockData.fromData(Blocks.CHEST.defaultBlockState()); Chest two = (Chest) CraftBlockData.fromData(Blocks.CHEST.defaultBlockState());
one.merge(two); assertThrows(IllegalArgumentException.class, () -> one.merge(two));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testCannotMerge2() { public void testCannotMerge2() {
Chest one = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]"); Chest one = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]");
Chest two = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]"); Chest two = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]");
@ -127,30 +128,30 @@ public class BlockDataTest extends AbstractTestingBase {
one.merge(two); one.merge(two);
two.setFacing(BlockFace.NORTH); two.setFacing(BlockFace.NORTH);
one.merge(two); assertThrows(IllegalArgumentException.class, () -> one.merge(two));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testCannotMerge3() { public void testCannotMerge3() {
Chest one = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]"); Chest one = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]");
Chest two = (Chest) CraftBlockData.newData(null, "minecraft:trapped_chest[waterlogged=true]"); Chest two = (Chest) CraftBlockData.newData(null, "minecraft:trapped_chest[waterlogged=true]");
one.merge(two); assertThrows(IllegalArgumentException.class, () -> one.merge(two));
} }
@Test @Test
public void testMatch() { public void testMatch() {
Assert.assertTrue(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]").matches(CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]"))); assertTrue(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]").matches(CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]")));
Assert.assertFalse(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=false]").matches(CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]"))); assertFalse(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=false]").matches(CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]")));
Assert.assertTrue(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]").matches(CraftBlockData.newData(null, "minecraft:chest"))); assertTrue(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]").matches(CraftBlockData.newData(null, "minecraft:chest")));
Assert.assertFalse(CraftBlockData.newData(null, "minecraft:trapped_chest[facing=east,waterlogged=false]").matches(CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]"))); assertFalse(CraftBlockData.newData(null, "minecraft:trapped_chest[facing=east,waterlogged=false]").matches(CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]")));
Assert.assertTrue(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]").matches(CraftBlockData.newData(null, "minecraft:chest[waterlogged=true,facing=east]"))); assertTrue(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]").matches(CraftBlockData.newData(null, "minecraft:chest[waterlogged=true,facing=east]")));
Chest one = (Chest) CraftBlockData.fromData(Blocks.CHEST.defaultBlockState().setValue(BlockChest.FACING, EnumDirection.EAST)); Chest one = (Chest) CraftBlockData.fromData(Blocks.CHEST.defaultBlockState().setValue(BlockChest.FACING, EnumDirection.EAST));
Chest two = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=false]"); Chest two = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=false]");
Assert.assertTrue(one.matches(two)); assertTrue(one.matches(two));
Assert.assertFalse(two.matches(one)); assertFalse(two.matches(one));
} }
@Test @Test
@ -158,15 +159,15 @@ public class BlockDataTest extends AbstractTestingBase {
String dataString = "minecraft:chest[facing=east,waterlogged=true]"; String dataString = "minecraft:chest[facing=east,waterlogged=true]";
BlockData data = CraftBlockData.newData(null, dataString); BlockData data = CraftBlockData.newData(null, dataString);
Assert.assertThat(data.getAsString(true), is(dataString)); assertThat(data.getAsString(true), is(dataString));
Assert.assertThat(data.getAsString(false), is("minecraft:chest[facing=east,type=single,waterlogged=true]")); assertThat(data.getAsString(false), is("minecraft:chest[facing=east,type=single,waterlogged=true]"));
} }
@Test @Test
public void testGetAsString2() { public void testGetAsString2() {
Chest data = (Chest) CraftBlockData.fromData(Blocks.CHEST.defaultBlockState().setValue(BlockChest.FACING, EnumDirection.EAST)); Chest data = (Chest) CraftBlockData.fromData(Blocks.CHEST.defaultBlockState().setValue(BlockChest.FACING, EnumDirection.EAST));
Assert.assertThat(data.getAsString(true), is("minecraft:chest[facing=east,type=single,waterlogged=false]")); assertThat(data.getAsString(true), is("minecraft:chest[facing=east,type=single,waterlogged=false]"));
Assert.assertThat(data.getAsString(false), is("minecraft:chest[facing=east,type=single,waterlogged=false]")); assertThat(data.getAsString(false), is("minecraft:chest[facing=east,type=single,waterlogged=false]"));
} }
} }

View File

@ -1,24 +1,23 @@
package org.bukkit; package org.bukkit;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import net.minecraft.EnumChatFormat; import net.minecraft.EnumChatFormat;
import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.network.chat.IChatBaseComponent;
import org.bukkit.craftbukkit.util.CraftChatMessage; import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class ChatTest { public class ChatTest {
@Test @Test
public void testColors() { public void testColors() {
for (ChatColor color : ChatColor.values()) { for (ChatColor color : ChatColor.values()) {
Assert.assertNotNull(CraftChatMessage.getColor(color)); assertNotNull(CraftChatMessage.getColor(color));
Assert.assertEquals(color, CraftChatMessage.getColor(CraftChatMessage.getColor(color))); assertEquals(color, CraftChatMessage.getColor(CraftChatMessage.getColor(color)));
} }
for (EnumChatFormat format : EnumChatFormat.values()) { for (EnumChatFormat format : EnumChatFormat.values()) {
Assert.assertNotNull(CraftChatMessage.getColor(format)); assertNotNull(CraftChatMessage.getColor(format));
Assert.assertEquals(format, CraftChatMessage.getColor(CraftChatMessage.getColor(format))); assertEquals(format, CraftChatMessage.getColor(CraftChatMessage.getColor(format)));
} }
} }

View File

@ -1,41 +1,26 @@
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 net.minecraft.world.item.EnumColor; import net.minecraft.world.item.EnumColor;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
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 DyeColorsTest extends AbstractTestingBase { public class DyeColorsTest extends AbstractTestingBase {
@Parameters(name = "{index}: {0}") @ParameterizedTest
public static List<Object[]> data() { @EnumSource(DyeColor.class)
List<Object[]> list = new ArrayList<Object[]>(); public void checkColor(DyeColor dye) {
for (DyeColor dye : DyeColor.values()) {
list.add(new Object[] {dye});
}
return list;
}
@Parameter public DyeColor dye;
@Test
public void checkColor() {
Color color = dye.getColor(); Color color = dye.getColor();
float[] nmsColorArray = EnumColor.byId(dye.getWoolData()).getTextureDiffuseColors(); float[] nmsColorArray = EnumColor.byId(dye.getWoolData()).getTextureDiffuseColors();
Color nmsColor = Color.fromRGB((int) (nmsColorArray[0] * 255), (int) (nmsColorArray[1] * 255), (int) (nmsColorArray[2] * 255)); Color nmsColor = Color.fromRGB((int) (nmsColorArray[0] * 255), (int) (nmsColorArray[1] * 255), (int) (nmsColorArray[2] * 255));
assertThat(color, is(nmsColor)); assertThat(color, is(nmsColor));
} }
@Test @ParameterizedTest
public void checkFireworkColor() { @EnumSource(DyeColor.class)
public void checkFireworkColor(DyeColor dye) {
Color color = dye.getFireworkColor(); Color color = dye.getFireworkColor();
int nmsColor = EnumColor.byId(dye.getWoolData()).getFireworkColor(); int nmsColor = EnumColor.byId(dye.getWoolData()).getFireworkColor();
assertThat(color, is(Color.fromRGB(nmsColor))); assertThat(color, is(Color.fromRGB(nmsColor)));

View File

@ -1,12 +1,12 @@
package org.bukkit; package org.bukkit;
import static org.junit.jupiter.api.Assertions.*;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.MinecraftKey; import net.minecraft.resources.MinecraftKey;
import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
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 EnchantmentTest extends AbstractTestingBase { public class EnchantmentTest extends AbstractTestingBase {
@ -17,9 +17,9 @@ public class EnchantmentTest extends AbstractTestingBase {
Enchantment bukkitById = Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(key)); Enchantment bukkitById = Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(key));
Assert.assertFalse("Unknown enchant name for " + key, bukkitById.getName().startsWith("UNKNOWN")); assertFalse(bukkitById.getName().startsWith("UNKNOWN"), "Unknown enchant name for " + key);
Assert.assertNotNull("Unknown target for " + key, bukkitById.getItemTarget()); assertNotNull(bukkitById.getItemTarget(), "Unknown target for " + key);
} }
} }
} }

View File

@ -1,10 +1,10 @@
package org.bukkit; package org.bukkit;
import static org.junit.jupiter.api.Assertions.*;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey;
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 GameEventTest extends AbstractTestingBase { public class GameEventTest extends AbstractTestingBase {
@ -13,7 +13,7 @@ public class GameEventTest extends AbstractTestingBase {
for (net.minecraft.world.level.gameevent.GameEvent nms : BuiltInRegistries.GAME_EVENT) { for (net.minecraft.world.level.gameevent.GameEvent nms : BuiltInRegistries.GAME_EVENT) {
GameEvent bukkit = GameEvent.getByKey(CraftNamespacedKey.fromMinecraft(BuiltInRegistries.GAME_EVENT.getKey(nms))); GameEvent bukkit = GameEvent.getByKey(CraftNamespacedKey.fromMinecraft(BuiltInRegistries.GAME_EVENT.getKey(nms)));
Assert.assertNotNull("Bukkit should not be null " + nms, bukkit); assertNotNull(bukkit, "Bukkit should not be null " + nms);
} }
} }
} }

View File

@ -1,10 +1,10 @@
package org.bukkit; package org.bukkit;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Map; import java.util.Map;
import net.minecraft.world.level.GameRules; import net.minecraft.world.level.GameRules;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class GameRuleTest { public class GameRuleTest {
@ -14,8 +14,8 @@ public class GameRuleTest {
for (GameRule<?> rule : rules) { for (GameRule<?> rule : rules) {
GameRule<?> registeredRule = GameRule.getByName(rule.getName()); GameRule<?> registeredRule = GameRule.getByName(rule.getName());
Assert.assertNotNull("Null GameRule", registeredRule); assertNotNull(registeredRule, "Null GameRule");
Assert.assertEquals("Invalid GameRule equality", rule, registeredRule); assertEquals(rule, registeredRule, "Invalid GameRule equality");
} }
} }
@ -26,31 +26,31 @@ public class GameRuleTest {
for (Map.Entry<String, GameRules.GameRuleKey<?>> entry : minecraftRules.entrySet()) { for (Map.Entry<String, GameRules.GameRuleKey<?>> entry : minecraftRules.entrySet()) {
GameRule<?> bukkitRule = GameRule.getByName(entry.getKey()); GameRule<?> bukkitRule = GameRule.getByName(entry.getKey());
Assert.assertNotNull("Missing " + entry.getKey(), bukkitRule); assertNotNull(bukkitRule, "Missing " + entry.getKey());
Assert.assertEquals("Invalid GameRule Name", bukkitRule.getName(), entry.getKey()); assertEquals(bukkitRule.getName(), entry.getKey(), "Invalid GameRule Name");
} }
} }
@Test(expected = NullPointerException.class) @Test
public void nullGameRuleName() { public void nullGameRuleName() {
GameRule.getByName(null); assertThrows(NullPointerException.class, () -> GameRule.getByName(null));
} }
@Test @Test
public void emptyGameRuleName() { public void emptyGameRuleName() {
Assert.assertNull(GameRule.getByName("")); assertNull(GameRule.getByName(""));
} }
@Test @Test
public void incorrectGameRuleName() { public void incorrectGameRuleName() {
Assert.assertNull(GameRule.getByName("doAnnounceAdvancements")); assertNull(GameRule.getByName("doAnnounceAdvancements"));
Assert.assertNull(GameRule.getByName("sendCommandBlockFeedback")); assertNull(GameRule.getByName("sendCommandBlockFeedback"));
} }
@Test @Test
public void invalidCasing() { public void invalidCasing() {
Assert.assertNull(GameRule.getByName("CommandBlockOutput")); assertNull(GameRule.getByName("CommandBlockOutput"));
Assert.assertNull(GameRule.getByName("spAwnRadius")); assertNull(GameRule.getByName("spAwnRadius"));
Assert.assertNull(GameRule.getByName("rand0mTickSpeEd")); assertNull(GameRule.getByName("rand0mTickSpeEd"));
} }
} }

View File

@ -1,12 +1,12 @@
package org.bukkit; package org.bukkit;
import static org.junit.jupiter.api.Assertions.*;
import net.minecraft.resources.MinecraftKey; import net.minecraft.resources.MinecraftKey;
import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.loot.LootTable; import org.bukkit.loot.LootTable;
import org.bukkit.loot.LootTables; import org.bukkit.loot.LootTables;
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 LootTablesTest extends AbstractTestingBase { public class LootTablesTest extends AbstractTestingBase {
@ -17,8 +17,8 @@ public class LootTablesTest extends AbstractTestingBase {
for (LootTables table : tables) { for (LootTables table : tables) {
LootTable lootTable = Bukkit.getLootTable(table.getKey()); LootTable lootTable = Bukkit.getLootTable(table.getKey());
Assert.assertNotNull("Unknown LootTable " + table.getKey(), lootTable); assertNotNull(lootTable, "Unknown LootTable " + table.getKey());
Assert.assertEquals(lootTable.getKey(), table.getKey()); assertEquals(lootTable.getKey(), table.getKey());
} }
} }
@ -28,8 +28,8 @@ public class LootTablesTest extends AbstractTestingBase {
NamespacedKey bukkitKey = CraftNamespacedKey.fromMinecraft(key); NamespacedKey bukkitKey = CraftNamespacedKey.fromMinecraft(key);
LootTables lootTable = Registry.LOOT_TABLES.get(bukkitKey); LootTables lootTable = Registry.LOOT_TABLES.get(bukkitKey);
Assert.assertNotNull("Unknown LootTable " + key, lootTable); assertNotNull(lootTable, "Unknown LootTable " + key);
Assert.assertEquals(lootTable.getKey(), bukkitKey); assertEquals(lootTable.getKey(), bukkitKey);
} }
} }
} }

View File

@ -1,7 +1,8 @@
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 com.google.common.collect.Maps; import com.google.common.collect.Maps;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -16,7 +17,7 @@ import net.minecraft.resources.MinecraftKey;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class MaterialTest extends AbstractTestingBase { public class MaterialTest extends AbstractTestingBase {
@ -42,8 +43,8 @@ public class MaterialTest extends AbstractTestingBase {
Material material = materials.remove(id); Material material = materials.remove(id);
assertThat("Missing " + name + "(" + id + ")", material, is(not(nullValue()))); assertThat(material, is(not(nullValue())), "Missing " + name + "(" + id + ")");
assertNotNull("No item mapping for " + name, CraftMagicNumbers.getMaterial(item)); assertNotNull(CraftMagicNumbers.getMaterial(item), "No item mapping for " + name);
} }
assertThat(materials, is(Collections.EMPTY_MAP)); assertThat(materials, is(Collections.EMPTY_MAP));

View File

@ -1,5 +1,6 @@
package org.bukkit; package org.bukkit;
import static org.junit.jupiter.api.Assertions.*;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.CraftParticle; import org.bukkit.craftbukkit.CraftParticle;
@ -7,8 +8,7 @@ import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
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 ParticleTest extends AbstractTestingBase { public class ParticleTest extends AbstractTestingBase {
@ -34,10 +34,10 @@ public class ParticleTest extends AbstractTestingBase {
data = 0; data = 0;
} }
Assert.assertNotNull("Missing Bukkit->NMS particle mapping for " + bukkit, CraftParticle.toNMS(bukkit, data)); assertNotNull(CraftParticle.toNMS(bukkit, data), "Missing Bukkit->NMS particle mapping for " + bukkit);
} }
for (net.minecraft.core.particles.Particle nms : BuiltInRegistries.PARTICLE_TYPE) { for (net.minecraft.core.particles.Particle nms : BuiltInRegistries.PARTICLE_TYPE) {
Assert.assertNotNull("Missing NMS->Bukkit particle mapping for " + BuiltInRegistries.PARTICLE_TYPE.getKey(nms), CraftParticle.minecraftToBukkit(nms)); assertNotNull(CraftParticle.minecraftToBukkit(nms), "Missing NMS->Bukkit particle mapping for " + BuiltInRegistries.PARTICLE_TYPE.getKey(nms));
} }
} }
} }

View File

@ -1,9 +1,8 @@
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 com.google.common.collect.Lists;
import java.util.List;
import java.util.Map; import java.util.Map;
import net.minecraft.core.BlockPosition; import net.minecraft.core.BlockPosition;
import net.minecraft.world.EnumHand; import net.minecraft.world.EnumHand;
@ -29,44 +28,29 @@ import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
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 PerMaterialTest extends AbstractTestingBase { public class PerMaterialTest extends AbstractTestingBase {
private static Map<Block, Integer> fireValues; private static Map<Block, Integer> fireValues;
@BeforeClass @BeforeAll
public static void getFireValues() { public static void getFireValues() {
fireValues = ((BlockFire) Blocks.FIRE).igniteOdds; fireValues = ((BlockFire) Blocks.FIRE).igniteOdds;
} }
@Parameters(name = "{index}: {0}") @ParameterizedTest
public static List<Object[]> data() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
List<Object[]> list = Lists.newArrayList(); public void isBlock(Material material) {
for (Material material : Material.values()) {
if (!material.isLegacy()) {
list.add(new Object[] {material});
}
}
return list;
}
@Parameter public Material material;
@Test
public void isBlock() {
if (material != Material.AIR && material != Material.CAVE_AIR && material != Material.VOID_AIR) { if (material != Material.AIR && material != Material.CAVE_AIR && material != Material.VOID_AIR) {
assertThat(material.isBlock(), is(not(CraftMagicNumbers.getBlock(material) == null))); assertThat(material.isBlock(), is(not(CraftMagicNumbers.getBlock(material) == null)));
} }
} }
@Test @ParameterizedTest
public void isSolid() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void isSolid(Material material) {
if (material == Material.AIR) { if (material == Material.AIR) {
assertFalse(material.isSolid()); assertFalse(material.isSolid());
} else if (material.isBlock()) { } else if (material.isBlock()) {
@ -76,8 +60,9 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void isEdible() { @EnumSource(value = Material.class, names = ".LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void isEdible(Material material) {
if (material.isBlock()) { if (material.isBlock()) {
assertFalse(material.isEdible()); assertFalse(material.isEdible());
} else { } else {
@ -85,13 +70,15 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void isRecord() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void isRecord(Material material) {
assertThat(material.isRecord(), is(CraftMagicNumbers.getItem(material) instanceof ItemRecord)); assertThat(material.isRecord(), is(CraftMagicNumbers.getItem(material) instanceof ItemRecord));
} }
@Test @ParameterizedTest
public void maxDurability() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void maxDurability(Material material) {
if (INVALIDATED_MATERIALS.contains(material)) return; if (INVALIDATED_MATERIALS.contains(material)) return;
if (material == Material.AIR) { if (material == Material.AIR) {
@ -102,8 +89,9 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void maxStackSize() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void maxStackSize(Material material) {
if (INVALIDATED_MATERIALS.contains(material)) return; if (INVALIDATED_MATERIALS.contains(material)) return;
final ItemStack bukkit = new ItemStack(material); final ItemStack bukkit = new ItemStack(material);
@ -120,8 +108,9 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void isTransparent() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void isTransparent(Material material) {
if (material == Material.AIR) { if (material == Material.AIR) {
assertTrue(material.isTransparent()); assertTrue(material.isTransparent());
} else if (material.isBlock()) { } else if (material.isBlock()) {
@ -131,8 +120,9 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void isFlammable() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void isFlammable(Material material) {
if (material != Material.AIR && material.isBlock()) { if (material != Material.AIR && material.isBlock()) {
assertThat(material.isFlammable(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().ignitedByLava())); assertThat(material.isFlammable(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().ignitedByLava()));
} else { } else {
@ -140,8 +130,9 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void isBurnable() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void isBurnable(Material material) {
if (material.isBlock()) { if (material.isBlock()) {
Block block = CraftMagicNumbers.getBlock(material); Block block = CraftMagicNumbers.getBlock(material);
assertThat(material.isBurnable(), is(fireValues.containsKey(block) && fireValues.get(block) > 0)); assertThat(material.isBurnable(), is(fireValues.containsKey(block) && fireValues.get(block) > 0));
@ -150,8 +141,9 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void isFuel() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void isFuel(Material material) {
if (material.isItem()) { if (material.isItem()) {
assertThat(material.isFuel(), is(TileEntityFurnace.isFuel(new net.minecraft.world.item.ItemStack(CraftMagicNumbers.getItem(material))))); assertThat(material.isFuel(), is(TileEntityFurnace.isFuel(new net.minecraft.world.item.ItemStack(CraftMagicNumbers.getItem(material)))));
} else { } else {
@ -159,8 +151,9 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void isOccluding() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void isOccluding(Material material) {
if (material.isBlock()) { if (material.isBlock()) {
assertThat(material.isOccluding(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().isRedstoneConductor(BlockAccessAir.INSTANCE, BlockPosition.ZERO))); assertThat(material.isOccluding(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().isRedstoneConductor(BlockAccessAir.INSTANCE, BlockPosition.ZERO)));
} else { } else {
@ -168,8 +161,9 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void hasGravity() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void hasGravity(Material material) {
if (material.isBlock()) { if (material.isBlock()) {
assertThat(material.hasGravity(), is(CraftMagicNumbers.getBlock(material) instanceof BlockFalling)); assertThat(material.hasGravity(), is(CraftMagicNumbers.getBlock(material) instanceof BlockFalling));
} else { } else {
@ -177,8 +171,9 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void usesDurability() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void usesDurability(Material material) {
if (!material.isBlock()) { if (!material.isBlock()) {
assertThat(EnchantmentTarget.BREAKABLE.includes(material), is(CraftMagicNumbers.getItem(material).canBeDepleted())); assertThat(EnchantmentTarget.BREAKABLE.includes(material), is(CraftMagicNumbers.getItem(material).canBeDepleted()));
} else { } else {
@ -186,8 +181,9 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void testDurability() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void testDurability(Material material) {
if (!material.isBlock()) { if (!material.isBlock()) {
assertThat(material.getMaxDurability(), is((short) CraftMagicNumbers.getItem(material).getMaxDamage())); assertThat(material.getMaxDurability(), is((short) CraftMagicNumbers.getItem(material).getMaxDamage()));
} else { } else {
@ -195,8 +191,9 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void testBlock() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void testBlock(Material material) {
if (material == Material.AIR) { if (material == Material.AIR) {
assertTrue(material.isBlock()); assertTrue(material.isBlock());
} else { } else {
@ -204,8 +201,9 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void testAir() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void testAir(Material material) {
if (material.isBlock()) { if (material.isBlock()) {
assertThat(material.isAir(), is(equalTo(CraftMagicNumbers.getBlock(material).defaultBlockState().isAir()))); assertThat(material.isAir(), is(equalTo(CraftMagicNumbers.getBlock(material).defaultBlockState().isAir())));
} else { } else {
@ -213,8 +211,9 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void testItem() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void testItem(Material material) {
if (material == Material.AIR) { if (material == Material.AIR) {
assertTrue(material.isItem()); assertTrue(material.isItem());
} else { } else {
@ -222,8 +221,9 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void testInteractable() throws ReflectiveOperationException { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void testInteractable(Material material) throws ReflectiveOperationException {
if (material.isBlock()) { if (material.isBlock()) {
assertThat(material.isInteractable(), assertThat(material.isInteractable(),
is(!CraftMagicNumbers.getBlock(material).getClass() is(!CraftMagicNumbers.getBlock(material).getClass()
@ -234,36 +234,41 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void testBlockHardness() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void testBlockHardness(Material material) {
if (material.isBlock()) { if (material.isBlock()) {
assertThat(material.getHardness(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().destroySpeed)); assertThat(material.getHardness(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().destroySpeed));
} }
} }
@Test @ParameterizedTest
public void testBlastResistance() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void testBlastResistance(Material material) {
if (material.isBlock()) { if (material.isBlock()) {
assertThat(material.getBlastResistance(), is(CraftMagicNumbers.getBlock(material).getExplosionResistance())); assertThat(material.getBlastResistance(), is(CraftMagicNumbers.getBlock(material).getExplosionResistance()));
} }
} }
@Test @ParameterizedTest
public void testSlipperiness() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void testSlipperiness(Material material) {
if (material.isBlock()) { if (material.isBlock()) {
assertThat(material.getSlipperiness(), is(CraftMagicNumbers.getBlock(material).getFriction())); assertThat(material.getSlipperiness(), is(CraftMagicNumbers.getBlock(material).getFriction()));
} }
} }
@Test @ParameterizedTest
public void testBlockDataCreation() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void testBlockDataCreation(Material material) {
if (material.isBlock()) { if (material.isBlock()) {
assertNotNull(material.createBlockData()); assertNotNull(material.createBlockData());
} }
} }
@Test @ParameterizedTest
public void testCraftingRemainingItem() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void testCraftingRemainingItem(Material material) {
if (material.isItem()) { if (material.isItem()) {
Item expectedItem = CraftMagicNumbers.getItem(material).getCraftingRemainingItem(); Item expectedItem = CraftMagicNumbers.getItem(material).getCraftingRemainingItem();
Material expected = expectedItem == null ? null : CraftMagicNumbers.getMaterial(expectedItem); Material expected = expectedItem == null ? null : CraftMagicNumbers.getMaterial(expectedItem);
@ -272,27 +277,30 @@ public class PerMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void testEquipmentSlot() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void testEquipmentSlot(Material material) {
if (material.isItem()) { if (material.isItem()) {
EquipmentSlot expected = CraftEquipmentSlot.getSlot(EntityInsentient.getEquipmentSlotForItem(CraftItemStack.asNMSCopy(new ItemStack(material)))); EquipmentSlot expected = CraftEquipmentSlot.getSlot(EntityInsentient.getEquipmentSlotForItem(CraftItemStack.asNMSCopy(new ItemStack(material))));
assertThat(material.getEquipmentSlot(), is(expected)); assertThat(material.getEquipmentSlot(), is(expected));
} }
} }
@Test @ParameterizedTest
public void testBlockDataClass() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void testBlockDataClass(Material material) {
if (material.isBlock()) { if (material.isBlock()) {
Class<?> expectedClass = material.data; Class<?> expectedClass = material.data;
if (expectedClass != MaterialData.class) { if (expectedClass != MaterialData.class) {
BlockData blockData = Bukkit.createBlockData(material); BlockData blockData = Bukkit.createBlockData(material);
assertTrue(expectedClass + " <> " + blockData.getClass(), expectedClass.isInstance(blockData)); assertTrue(expectedClass.isInstance(blockData), expectedClass + " <> " + blockData.getClass());
} }
} }
} }
@Test @ParameterizedTest
public void testCreativeCategory() { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
public void testCreativeCategory(Material material) {
if (material.isItem()) { if (material.isItem()) {
material.getCreativeCategory(); material.getCreativeCategory();
} }

View File

@ -1,32 +1,29 @@
package org.bukkit; package org.bukkit;
import static org.junit.jupiter.api.Assertions.*;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.stream.Stream;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Assert; import org.junit.jupiter.api.BeforeAll;
import org.junit.BeforeClass; 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;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class PerRegistryTest extends AbstractTestingBase { public class PerRegistryTest extends AbstractTestingBase {
private static Random random; private static Random random;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
random = new Random(); random = new Random();
} }
@Parameters(name = "{index}: {0}") public static Stream<Arguments> data() {
public static List<Object[]> data() { List<Arguments> data = Lists.newArrayList();
List<Object[]> data = Lists.newArrayList();
Field[] registryFields = Registry.class.getFields(); Field[] registryFields = Registry.class.getFields();
for (Field registryField : registryFields) { for (Field registryField : registryFields) {
@ -37,42 +34,42 @@ public class PerRegistryTest extends AbstractTestingBase {
continue; continue;
} }
data.add(new Object[] {registry}); data.add(Arguments.of(registry));
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
return data; return data.stream();
} }
@Parameter public Registry<? extends Keyed> registry; @ParameterizedTest
@MethodSource("data")
@Test public void testGet(Registry<?> registry) {
public void testGet() { registry.forEach(element -> {
this.registry.forEach(element -> {
// Values in the registry should be referentially equal to what is returned with #get() // Values in the registry should be referentially equal to what is returned with #get()
// This ensures that new instances are not created each time #get() is invoked // This ensures that new instances are not created each time #get() is invoked
Assert.assertSame(element, registry.get(element.getKey())); assertSame(element, registry.get(element.getKey()));
}); });
} }
@Test @ParameterizedTest
public void testMatch() { @MethodSource("data")
this.registry.forEach(element -> { public void testMatch(Registry<?> registry) {
registry.forEach(element -> {
NamespacedKey key = element.getKey(); NamespacedKey key = element.getKey();
assertSameMatchWithKeyMessage(element, key.toString()); // namespace:key assertSameMatchWithKeyMessage(registry, element, key.toString()); // namespace:key
assertSameMatchWithKeyMessage(element, key.getKey()); // key assertSameMatchWithKeyMessage(registry, element, key.getKey()); // key
assertSameMatchWithKeyMessage(element, key.toString().replace('_', ' ')); // namespace:key with space assertSameMatchWithKeyMessage(registry, element, key.toString().replace('_', ' ')); // namespace:key with space
assertSameMatchWithKeyMessage(element, key.getKey().replace('_', ' ')); // key with space assertSameMatchWithKeyMessage(registry, element, key.getKey().replace('_', ' ')); // key with space
assertSameMatchWithKeyMessage(element, randomizeCase(key.toString())); // nAmeSPaCe:kEY assertSameMatchWithKeyMessage(registry, element, randomizeCase(key.toString())); // nAmeSPaCe:kEY
assertSameMatchWithKeyMessage(element, randomizeCase(key.getKey())); // kEy assertSameMatchWithKeyMessage(registry, element, randomizeCase(key.getKey())); // kEy
}); });
} }
private void assertSameMatchWithKeyMessage(Keyed element, String key) { private void assertSameMatchWithKeyMessage(Registry<?> registry, Keyed element, String key) {
Assert.assertSame(key, element, registry.match(key)); assertSame(element, registry.match(key), key);
} }
private String randomizeCase(String input) { private String randomizeCase(String input) {

View File

@ -1,7 +1,8 @@
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 com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -10,7 +11,7 @@ import net.minecraft.resources.MinecraftKey;
import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class PotionEffectTypeTest extends AbstractTestingBase { public class PotionEffectTypeTest extends AbstractTestingBase {
@ -23,11 +24,11 @@ public class PotionEffectTypeTest extends AbstractTestingBase {
PotionEffectType effect = PotionEffectType.getByKey(CraftNamespacedKey.fromMinecraft(key)); PotionEffectType effect = PotionEffectType.getByKey(CraftNamespacedKey.fromMinecraft(key));
String message = String.format("org.bukkit.PotionEffectType is missing '%s'", name); String message = String.format("org.bukkit.PotionEffectType is missing '%s'", name);
assertNotNull(message, effect); assertNotNull(effect, message);
effects.remove(effect); effects.remove(effect);
} }
assertThat("org.bukkit.PotionEffectType has too many effects", effects, is(Collections.EMPTY_LIST)); assertThat(effects, is(Collections.EMPTY_LIST), "org.bukkit.PotionEffectType has too many effects");
} }
} }

View File

@ -1,5 +1,6 @@
package org.bukkit; package org.bukkit;
import static org.junit.jupiter.api.Assertions.*;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
@ -12,8 +13,7 @@ import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.inventory.meta.trim.TrimMaterial; import org.bukkit.inventory.meta.trim.TrimMaterial;
import org.bukkit.inventory.meta.trim.TrimPattern; import org.bukkit.inventory.meta.trim.TrimPattern;
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 RegistryConstantsTest extends AbstractTestingBase { public class RegistryConstantsTest extends AbstractTestingBase {
@ -45,7 +45,7 @@ public class RegistryConstantsTest extends AbstractTestingBase {
} }
Assert.assertTrue(excessKeys.size() + " excess constants(s) in " + clazz.getSimpleName() + " that do not exist: " + excessKeys, excessKeys.isEmpty()); assertTrue(excessKeys.isEmpty(), excessKeys.size() + " excess constants(s) in " + clazz.getSimpleName() + " that do not exist: " + excessKeys);
} }
private <T extends Keyed, M> void testMissingConstants(Class<T> clazz, ResourceKey<IRegistry<M>> nmsRegistryKey) { private <T extends Keyed, M> void testMissingConstants(Class<T> clazz, ResourceKey<IRegistry<M>> nmsRegistryKey) {
@ -59,14 +59,14 @@ public class RegistryConstantsTest extends AbstractTestingBase {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
T bukkitObject = (T) clazz.getField(minecraftKey.getPath().toUpperCase()).get(null); T bukkitObject = (T) clazz.getField(minecraftKey.getPath().toUpperCase()).get(null);
Assert.assertEquals("Keys are not the same for " + minecraftKey, minecraftKey, CraftNamespacedKey.toMinecraft(bukkitObject.getKey())); assertEquals(minecraftKey, CraftNamespacedKey.toMinecraft(bukkitObject.getKey()), "Keys are not the same for " + minecraftKey);
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
missingKeys.add(minecraftKey); missingKeys.add(minecraftKey);
} catch (Exception e) { } catch (Exception e) {
Assert.fail(e.getMessage()); fail(e.getMessage());
} }
} }
Assert.assertTrue("Missing (" + missingKeys.size() + ") constants in " + clazz.getSimpleName() + ": " + missingKeys, missingKeys.isEmpty()); assertTrue(missingKeys.isEmpty(), "Missing (" + missingKeys.size() + ") constants in " + clazz.getSimpleName() + ": " + missingKeys);
} }
} }

View File

@ -1,40 +1,41 @@
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 net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.MinecraftKey; import net.minecraft.resources.MinecraftKey;
import org.bukkit.craftbukkit.CraftSound; import org.bukkit.craftbukkit.CraftSound;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class SoundTest extends AbstractTestingBase { public class SoundTest extends AbstractTestingBase {
@Test @Test
public void testGetSound() { public void testGetSound() {
for (Sound sound : Sound.values()) { for (Sound sound : Sound.values()) {
assertThat(sound.name(), CraftSound.bukkitToMinecraft(sound), is(not(nullValue()))); assertThat(CraftSound.bukkitToMinecraft(sound), is(not(nullValue())), sound.name());
} }
} }
@Test @Test
public void testReverse() { public void testReverse() {
for (MinecraftKey effect : BuiltInRegistries.SOUND_EVENT.keySet()) { for (MinecraftKey effect : BuiltInRegistries.SOUND_EVENT.keySet()) {
assertNotNull(effect + "", Sound.valueOf(effect.getPath().replace('.', '_').toUpperCase(java.util.Locale.ENGLISH))); assertNotNull(Sound.valueOf(effect.getPath().replace('.', '_').toUpperCase(java.util.Locale.ENGLISH)), effect + "");
} }
} }
@Test @Test
public void testCategory() { public void testCategory() {
for (SoundCategory category : SoundCategory.values()) { for (SoundCategory category : SoundCategory.values()) {
assertNotNull(category + "", net.minecraft.sounds.SoundCategory.valueOf(category.name())); assertNotNull(net.minecraft.sounds.SoundCategory.valueOf(category.name()), category + "");
} }
} }
@Test @Test
public void testCategoryReverse() { public void testCategoryReverse() {
for (net.minecraft.sounds.SoundCategory category : net.minecraft.sounds.SoundCategory.values()) { for (net.minecraft.sounds.SoundCategory category : net.minecraft.sounds.SoundCategory.values()) {
assertNotNull(category + "", SoundCategory.valueOf(category.name())); assertNotNull(SoundCategory.valueOf(category.name()), category + "");
} }
} }
} }

View File

@ -1,7 +1,8 @@
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 com.google.common.collect.HashMultiset; import com.google.common.collect.HashMultiset;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.stats.StatisticWrapper; import net.minecraft.stats.StatisticWrapper;
@ -9,7 +10,7 @@ import net.minecraft.world.entity.EntityTypes;
import org.bukkit.craftbukkit.CraftStatistic; import org.bukkit.craftbukkit.CraftStatistic;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class StatisticsAndAchievementsTest extends AbstractTestingBase { public class StatisticsAndAchievementsTest extends AbstractTestingBase {
@ -20,7 +21,7 @@ public class StatisticsAndAchievementsTest extends AbstractTestingBase {
if (statistic.getType() == Statistic.Type.ENTITY) { if (statistic.getType() == Statistic.Type.ENTITY) {
for (EntityType entity : EntityType.values()) { for (EntityType entity : EntityType.values()) {
if (entity.getName() != null) { if (entity.getName() != null) {
assertNotNull(statistic + " missing for " + entity, CraftStatistic.getEntityStatistic(statistic, entity)); assertNotNull(CraftStatistic.getEntityStatistic(statistic, entity), statistic + " missing for " + entity);
} }
} }
} }
@ -37,12 +38,12 @@ public class StatisticsAndAchievementsTest extends AbstractTestingBase {
String message = String.format("org.bukkit.Statistic is missing: '%s'", statistic); String message = String.format("org.bukkit.Statistic is missing: '%s'", statistic);
Statistic subject = CraftStatistic.getBukkitStatistic(statistic); Statistic subject = CraftStatistic.getBukkitStatistic(statistic);
assertThat(message, subject, is(not(nullValue()))); assertThat(subject, is(not(nullValue())), message);
if (wrapper.getRegistry() == BuiltInRegistries.BLOCK || wrapper.getRegistry() == BuiltInRegistries.ITEM) { if (wrapper.getRegistry() == BuiltInRegistries.BLOCK || wrapper.getRegistry() == BuiltInRegistries.ITEM) {
assertNotNull("Material type map missing for " + wrapper.getRegistry().getKey(child), CraftStatistic.getMaterialFromStatistic(statistic)); assertNotNull(CraftStatistic.getMaterialFromStatistic(statistic), "Material type map missing for " + wrapper.getRegistry().getKey(child));
} else if (wrapper.getRegistry() == BuiltInRegistries.ENTITY_TYPE) { } else if (wrapper.getRegistry() == BuiltInRegistries.ENTITY_TYPE) {
assertNotNull("Entity type map missing for " + EntityTypes.getKey((EntityTypes<?>) child), CraftStatistic.getEntityTypeFromStatistic((net.minecraft.stats.Statistic<EntityTypes<?>>) statistic)); assertNotNull(CraftStatistic.getEntityTypeFromStatistic((net.minecraft.stats.Statistic<EntityTypes<?>>) statistic), "Entity type map missing for " + EntityTypes.getKey((EntityTypes<?>) child));
} }
statistics.add(subject); statistics.add(subject);
@ -51,7 +52,7 @@ public class StatisticsAndAchievementsTest extends AbstractTestingBase {
for (Statistic statistic : Statistic.values()) { for (Statistic statistic : Statistic.values()) {
String message = String.format("org.bukkit.Statistic.%s does not have a corresponding minecraft statistic", statistic.name()); String message = String.format("org.bukkit.Statistic.%s does not have a corresponding minecraft statistic", statistic.name());
assertThat(message, statistics.remove(statistic, statistics.count(statistic)), is(greaterThan(0))); assertThat(statistics.remove(statistic, statistics.count(statistic)), is(greaterThan(0)), message);
} }
} }
} }

View File

@ -1,10 +1,10 @@
package org.bukkit.block.banner; package org.bukkit.block.banner;
import junit.framework.Assert; import static org.junit.jupiter.api.Assertions.*;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.level.block.entity.EnumBannerPatternType; import net.minecraft.world.level.block.entity.EnumBannerPatternType;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class PatternTypeTest extends AbstractTestingBase { public class PatternTypeTest extends AbstractTestingBase {
@ -13,7 +13,7 @@ public class PatternTypeTest extends AbstractTestingBase {
for (EnumBannerPatternType nms : BuiltInRegistries.BANNER_PATTERN) { for (EnumBannerPatternType nms : BuiltInRegistries.BANNER_PATTERN) {
PatternType bukkit = PatternType.getByIdentifier(nms.getHashname()); PatternType bukkit = PatternType.getByIdentifier(nms.getHashname());
Assert.assertNotNull("No Bukkit banner for " + nms + " " + nms.getHashname(), bukkit); assertNotNull(bukkit, "No Bukkit banner for " + nms + " " + nms.getHashname());
} }
} }
@ -28,7 +28,7 @@ public class PatternTypeTest extends AbstractTestingBase {
} }
} }
Assert.assertNotNull("No NMS banner for " + bukkit + " " + bukkit.getIdentifier(), found); assertNotNull(found, "No NMS banner for " + bukkit + " " + bukkit.getIdentifier());
} }
} }
} }

View File

@ -1,22 +1,22 @@
package org.bukkit.craftbukkit; package org.bukkit.craftbukkit;
import static org.junit.jupiter.api.Assertions.*;
import org.bukkit.HeightMap; import org.bukkit.HeightMap;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class HeightMapTest { public class HeightMapTest {
@Test @Test
public void heightMapConversionFromNMSToBukkitShouldNotThrowExceptio() { public void heightMapConversionFromNMSToBukkitShouldNotThrowExceptio() {
for (net.minecraft.world.level.levelgen.HeightMap.Type nmsHeightMapType : net.minecraft.world.level.levelgen.HeightMap.Type.values()) { for (net.minecraft.world.level.levelgen.HeightMap.Type nmsHeightMapType : net.minecraft.world.level.levelgen.HeightMap.Type.values()) {
Assert.assertNotNull("fromNMS", CraftHeightMap.fromNMS(nmsHeightMapType)); assertNotNull(CraftHeightMap.fromNMS(nmsHeightMapType), "fromNMS");
} }
} }
@Test @Test
public void heightMapConversionFromBukkitToNMSShouldNotThrowExceptio() { public void heightMapConversionFromBukkitToNMSShouldNotThrowExceptio() {
for (HeightMap bukkitHeightMap : HeightMap.values()) { for (HeightMap bukkitHeightMap : HeightMap.values()) {
Assert.assertNotNull("toNMS", CraftHeightMap.toNMS(bukkitHeightMap)); assertNotNull(CraftHeightMap.toNMS(bukkitHeightMap), "toNMS");
} }
} }
} }

View File

@ -1,11 +1,11 @@
package org.bukkit.craftbukkit.attribute; package org.bukkit.craftbukkit.attribute;
import static org.junit.jupiter.api.Assertions.*;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.entity.ai.attributes.AttributeBase; import net.minecraft.world.entity.ai.attributes.AttributeBase;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
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 AttributeTest extends AbstractTestingBase { public class AttributeTest extends AbstractTestingBase {
@ -14,7 +14,7 @@ public class AttributeTest extends AbstractTestingBase {
for (AttributeBase nms : BuiltInRegistries.ATTRIBUTE) { for (AttributeBase nms : BuiltInRegistries.ATTRIBUTE) {
Attribute bukkit = CraftAttribute.minecraftToBukkit(nms); Attribute bukkit = CraftAttribute.minecraftToBukkit(nms);
Assert.assertNotNull(nms.toString(), bukkit); assertNotNull(bukkit, nms.toString());
} }
} }
@ -23,7 +23,7 @@ public class AttributeTest extends AbstractTestingBase {
for (Attribute attribute : Attribute.values()) { for (Attribute attribute : Attribute.values()) {
AttributeBase nms = CraftAttribute.bukkitToMinecraft(attribute); AttributeBase nms = CraftAttribute.bukkitToMinecraft(attribute);
Assert.assertNotNull(attribute.name(), nms); assertNotNull(nms, attribute.name());
} }
} }
} }

View File

@ -1,9 +1,6 @@
package org.bukkit.craftbukkit.block; package org.bukkit.craftbukkit.block;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.*;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import net.minecraft.core.BlockPosition; import net.minecraft.core.BlockPosition;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
@ -12,7 +9,7 @@ import net.minecraft.world.level.block.entity.TileEntity;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class BlockStateTest extends AbstractTestingBase { public class BlockStateTest extends AbstractTestingBase {
@ -24,7 +21,7 @@ public class BlockStateTest extends AbstractTestingBase {
boolean isCraftBlockEntityState = CraftBlockEntityState.class.isAssignableFrom(blockStateType); boolean isCraftBlockEntityState = CraftBlockEntityState.class.isAssignableFrom(blockStateType);
if (block instanceof ITileEntity) { if (block instanceof ITileEntity) {
assertTrue(material + " has BlockState of type " + blockStateType.getName() + ", but expected subtype of CraftBlockEntityState", isCraftBlockEntityState); assertTrue(isCraftBlockEntityState, material + " has BlockState of type " + blockStateType.getName() + ", but expected subtype of CraftBlockEntityState");
// check tile entity type // check tile entity type
TileEntity tileEntity = ((ITileEntity) block).newBlockEntity(BlockPosition.ZERO, block.defaultBlockState()); TileEntity tileEntity = ((ITileEntity) block).newBlockEntity(BlockPosition.ZERO, block.defaultBlockState());
@ -37,10 +34,10 @@ public class BlockStateTest extends AbstractTestingBase {
fail(material + " has no tile entity, it be added to CraftBlockStates#isTileEntityOptional"); fail(material + " has no tile entity, it be added to CraftBlockStates#isTileEntityOptional");
} }
assertNotNull(material + " has no tile entity expected tile entity of type " + tileEntity.getClass(), materialTileEntity); assertNotNull(materialTileEntity, material + " has no tile entity expected tile entity of type " + tileEntity.getClass());
assertSame(material + " has unexpected tile entity type, expected " + tileEntity.getClass() + " but got " + tileEntity.getClass(), materialTileEntity.getClass(), tileEntity.getClass()); assertSame(materialTileEntity.getClass(), tileEntity.getClass(), material + " has unexpected tile entity type, expected " + tileEntity.getClass() + " but got " + tileEntity.getClass());
} else { } else {
assertTrue(material + " has unexpected CraftBlockEntityState subytype " + blockStateType.getName() + " (but is not a tile)", !isCraftBlockEntityState); assertFalse(isCraftBlockEntityState, material + " has unexpected CraftBlockEntityState subytype " + blockStateType.getName() + " (but is not a tile)");
} }
} }
} }

View File

@ -1,10 +1,10 @@
package org.bukkit.craftbukkit.generator; package org.bukkit.craftbukkit.generator;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class ChunkDataTest extends AbstractTestingBase { public class ChunkDataTest extends AbstractTestingBase {
@ -35,28 +35,28 @@ public class ChunkDataTest extends AbstractTestingBase {
@Test @Test
public void testMinHeight() { public void testMinHeight() {
OldCraftChunkData data = new OldCraftChunkData(-128, 128, BIOMES); OldCraftChunkData data = new OldCraftChunkData(-128, 128, BIOMES);
assertTrue("Could not set block below min height", testSetBlock(data, 0, -256, 0, RED_WOOL, AIR)); assertTrue(testSetBlock(data, 0, -256, 0, RED_WOOL, AIR), "Could not set block below min height");
assertTrue("Could set block above min height", testSetBlock(data, 0, -64, 0, RED_WOOL, RED_WOOL)); assertTrue(testSetBlock(data, 0, -64, 0, RED_WOOL, RED_WOOL), "Could set block above min height");
} }
@Test @Test
public void testMaxHeight() { public void testMaxHeight() {
OldCraftChunkData data = new OldCraftChunkData(0, 128, BIOMES); OldCraftChunkData data = new OldCraftChunkData(0, 128, BIOMES);
assertTrue("Could not set block above max height", testSetBlock(data, 0, 128, 0, RED_WOOL, AIR)); assertTrue(testSetBlock(data, 0, 128, 0, RED_WOOL, AIR), "Could not set block above max height");
assertTrue("Could set block below max height", testSetBlock(data, 0, 127, 0, RED_WOOL, RED_WOOL)); assertTrue(testSetBlock(data, 0, 127, 0, RED_WOOL, RED_WOOL), "Could set block below max height");
} }
@Test @Test
public void testBoundsCheckingSingle() { public void testBoundsCheckingSingle() {
OldCraftChunkData data = new OldCraftChunkData(0, 256, BIOMES); OldCraftChunkData data = new OldCraftChunkData(0, 256, BIOMES);
assertTrue("Can set block inside chunk bounds", testSetBlock(data, 0, 0, 0, RED_WOOL, RED_WOOL)); assertTrue(testSetBlock(data, 0, 0, 0, RED_WOOL, RED_WOOL), "Can set block inside chunk bounds");
assertTrue("Can set block inside chunk bounds", testSetBlock(data, 15, 255, 15, RED_WOOL, RED_WOOL)); assertTrue(testSetBlock(data, 15, 255, 15, RED_WOOL, RED_WOOL), "Can set block inside chunk bounds");
assertTrue("Can no set block outside chunk bounds", testSetBlock(data, -1, 0, 0, RED_WOOL, AIR)); assertTrue(testSetBlock(data, -1, 0, 0, RED_WOOL, AIR), "Can no set block outside chunk bounds");
assertTrue("Can no set block outside chunk bounds", testSetBlock(data, 0, -1, 0, RED_WOOL, AIR)); assertTrue(testSetBlock(data, 0, -1, 0, RED_WOOL, AIR), "Can no set block outside chunk bounds");
assertTrue("Can no set block outside chunk bounds", testSetBlock(data, 0, 0, -1, RED_WOOL, AIR)); assertTrue(testSetBlock(data, 0, 0, -1, RED_WOOL, AIR), "Can no set block outside chunk bounds");
assertTrue("Can no set block outside chunk bounds", testSetBlock(data, 16, 0, 0, RED_WOOL, AIR)); assertTrue(testSetBlock(data, 16, 0, 0, RED_WOOL, AIR), "Can no set block outside chunk bounds");
assertTrue("Can no set block outside chunk bounds", testSetBlock(data, 0, 256, 0, RED_WOOL, AIR)); assertTrue(testSetBlock(data, 0, 256, 0, RED_WOOL, AIR), "Can no set block outside chunk bounds");
assertTrue("Can no set block outside chunk bounds", testSetBlock(data, 0, 0, 16, RED_WOOL, AIR)); assertTrue(testSetBlock(data, 0, 0, 16, RED_WOOL, AIR), "Can no set block outside chunk bounds");
} }
@Test @Test

View File

@ -1,7 +1,7 @@
package org.bukkit.craftbukkit.inventory; package org.bukkit.craftbukkit.inventory;
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.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -13,7 +13,7 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class CompositeSerialization extends AbstractTestingBase { public class CompositeSerialization extends AbstractTestingBase {
@ -63,7 +63,7 @@ public class CompositeSerialization extends AbstractTestingBase {
assertThat(stacks, hasSize(raw.size())); assertThat(stacks, hasSize(raw.size()));
for (int i = 0; i < raw.size(); i++) { for (int i = 0; i < raw.size(); i++) {
assertThat(String.valueOf(i), (Object) stacks.get(i), is((Object) raw.get(i))); assertThat((Object) stacks.get(i), is((Object) raw.get(i)), String.valueOf(i));
} }
} }
} }

View File

@ -1,6 +1,6 @@
package org.bukkit.craftbukkit.inventory; package org.bukkit.craftbukkit.inventory;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.io.StringReader; import java.io.StringReader;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -18,52 +18,52 @@ import org.bukkit.inventory.meta.tags.CustomItemTagContainer;
import org.bukkit.inventory.meta.tags.ItemTagAdapterContext; import org.bukkit.inventory.meta.tags.ItemTagAdapterContext;
import org.bukkit.inventory.meta.tags.ItemTagType; import org.bukkit.inventory.meta.tags.ItemTagType;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Before; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class DeprecatedItemMetaCustomValueTest extends AbstractTestingBase { public class DeprecatedItemMetaCustomValueTest extends AbstractTestingBase {
private static NamespacedKey VALID_KEY; private static NamespacedKey VALID_KEY;
@Before @BeforeAll
public void setup() { public static void setup() {
VALID_KEY = new NamespacedKey("test", "validkey"); VALID_KEY = new NamespacedKey("test", "validkey");
} }
/* /*
Sets a test Sets a test
*/ */
@Test(expected = IllegalArgumentException.class) @Test
public void testSetNoAdapter() { public void testSetNoAdapter() {
ItemMeta itemMeta = createNewItemMeta(); ItemMeta itemMeta = createNewItemMeta();
itemMeta.getCustomTagContainer().setCustomTag(VALID_KEY, new PrimitiveTagType<>(boolean.class), true); assertThrows(IllegalArgumentException.class, () -> itemMeta.getCustomTagContainer().setCustomTag(VALID_KEY, new PrimitiveTagType<>(boolean.class), true));
} }
/* /*
Contains a tag Contains a tag
*/ */
@Test(expected = IllegalArgumentException.class) @Test
public void testHasNoAdapter() { public void testHasNoAdapter() {
ItemMeta itemMeta = createNewItemMeta(); ItemMeta itemMeta = createNewItemMeta();
itemMeta.getCustomTagContainer().setCustomTag(VALID_KEY, ItemTagType.INTEGER, 1); // We gotta set this so we at least try to compare it itemMeta.getCustomTagContainer().setCustomTag(VALID_KEY, ItemTagType.INTEGER, 1); // We gotta set this so we at least try to compare it
itemMeta.getCustomTagContainer().hasCustomTag(VALID_KEY, new PrimitiveTagType<>(boolean.class)); assertThrows(IllegalArgumentException.class, () -> itemMeta.getCustomTagContainer().hasCustomTag(VALID_KEY, new PrimitiveTagType<>(boolean.class)));
} }
/* /*
Getting a tag Getting a tag
*/ */
@Test(expected = IllegalArgumentException.class) @Test
public void testGetNoAdapter() { public void testGetNoAdapter() {
ItemMeta itemMeta = createNewItemMeta(); ItemMeta itemMeta = createNewItemMeta();
itemMeta.getCustomTagContainer().setCustomTag(VALID_KEY, ItemTagType.INTEGER, 1); //We gotta set this so we at least try to compare it itemMeta.getCustomTagContainer().setCustomTag(VALID_KEY, ItemTagType.INTEGER, 1); //We gotta set this so we at least try to compare it
itemMeta.getCustomTagContainer().getCustomTag(VALID_KEY, new PrimitiveTagType<>(boolean.class)); assertThrows(IllegalArgumentException.class, () -> itemMeta.getCustomTagContainer().getCustomTag(VALID_KEY, new PrimitiveTagType<>(boolean.class)));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testGetWrongType() { public void testGetWrongType() {
ItemMeta itemMeta = createNewItemMeta(); ItemMeta itemMeta = createNewItemMeta();
itemMeta.getCustomTagContainer().setCustomTag(VALID_KEY, ItemTagType.INTEGER, 1); itemMeta.getCustomTagContainer().setCustomTag(VALID_KEY, ItemTagType.INTEGER, 1);
itemMeta.getCustomTagContainer().getCustomTag(VALID_KEY, ItemTagType.STRING); assertThrows(IllegalArgumentException.class, () -> itemMeta.getCustomTagContainer().getCustomTag(VALID_KEY, ItemTagType.STRING));
} }
@Test @Test

View File

@ -1,21 +1,20 @@
package org.bukkit.craftbukkit.inventory; package org.bukkit.craftbukkit.inventory;
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 java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
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 FactoryItemMaterialTest extends AbstractTestingBase { public class FactoryItemMaterialTest extends AbstractTestingBase {
static final ItemFactory factory = CraftItemFactory.instance(); static final ItemFactory factory = CraftItemFactory.instance();
static final StringBuilder buffer = new StringBuilder(); static final StringBuilder buffer = new StringBuilder();
@ -41,19 +40,17 @@ public class FactoryItemMaterialTest extends AbstractTestingBase {
return buffer.delete(0, Integer.MAX_VALUE).append(from.getClass().getName()).append('(').append(from.name()).append(") to ").append(to.getClass().getName()).append('(').append(to.name()).append(')').toString(); return buffer.delete(0, Integer.MAX_VALUE).append(from.getClass().getName()).append('(').append(from.name()).append(") to ").append(to.getClass().getName()).append('(').append(to.name()).append(')').toString();
} }
@Parameters(name = "Material[{index}]:{0}") public static Stream<Arguments> data() {
public static List<Object[]> data() { List<Arguments> list = new ArrayList<>();
List<Object[]> list = new ArrayList<Object[]>();
for (Material material : materials) { for (Material material : materials) {
list.add(new Object[] {material}); list.add(Arguments.of(material));
} }
return list; return list.stream();
} }
@Parameter(0) public Material material; @ParameterizedTest
@MethodSource("data")
@Test public void itemStack(Material material) {
public void itemStack() {
ItemStack bukkitStack = new ItemStack(material); ItemStack bukkitStack = new ItemStack(material);
CraftItemStack craftStack = CraftItemStack.asCraftCopy(bukkitStack); CraftItemStack craftStack = CraftItemStack.asCraftCopy(bukkitStack);
ItemMeta meta = factory.getItemMeta(material); ItemMeta meta = factory.getItemMeta(material);
@ -65,8 +62,9 @@ public class FactoryItemMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void generalCase() { @MethodSource("data")
public void generalCase(Material material) {
CraftMetaItem meta = (CraftMetaItem) factory.getItemMeta(material); CraftMetaItem meta = (CraftMetaItem) factory.getItemMeta(material);
if (meta == null) { if (meta == null) {
assertThat(material, is(Material.AIR)); assertThat(material, is(Material.AIR));
@ -80,8 +78,9 @@ public class FactoryItemMaterialTest extends AbstractTestingBase {
} }
} }
@Test @ParameterizedTest
public void asMetaFor() { @MethodSource("data")
public void asMetaFor(Material material) {
final CraftMetaItem baseMeta = (CraftMetaItem) factory.getItemMeta(material); final CraftMetaItem baseMeta = (CraftMetaItem) factory.getItemMeta(material);
if (baseMeta == null) { if (baseMeta == null) {
assertThat(material, is(Material.AIR)); assertThat(material, is(Material.AIR));
@ -96,19 +95,20 @@ public class FactoryItemMaterialTest extends AbstractTestingBase {
final String testName = name(material, other); final String testName = name(material, other);
if (otherMeta == null) { if (otherMeta == null) {
assertThat(testName, other, is(Material.AIR)); assertThat(other, is(Material.AIR), testName);
continue; continue;
} }
assertTrue(testName, factory.isApplicable(otherMeta, craftStack)); assertTrue(factory.isApplicable(otherMeta, craftStack), testName);
assertTrue(testName, factory.isApplicable(otherMeta, bukkitStack)); assertTrue(factory.isApplicable(otherMeta, bukkitStack), testName);
assertTrue(testName, factory.isApplicable(otherMeta, other)); assertTrue(factory.isApplicable(otherMeta, other), testName);
assertTrue(testName, otherMeta.applicableTo(other)); assertTrue(otherMeta.applicableTo(other), testName);
} }
} }
@Test @ParameterizedTest
public void blankEqualities() { @MethodSource("data")
public void blankEqualities(Material material) {
if (material == Material.AIR) { if (material == Material.AIR) {
return; return;
} }
@ -137,17 +137,17 @@ public class FactoryItemMaterialTest extends AbstractTestingBase {
final CraftMetaItem otherMeta = (CraftMetaItem) factory.asMetaFor(baseMetaClone, other); final CraftMetaItem otherMeta = (CraftMetaItem) factory.asMetaFor(baseMetaClone, other);
if (otherMeta == null) { if (otherMeta == null) {
assertThat(testName, other, is(Material.AIR)); assertThat(other, is(Material.AIR), testName);
continue; continue;
} }
assertTrue(testName, factory.equals(baseMeta, otherMeta)); assertTrue(factory.equals(baseMeta, otherMeta), testName);
assertTrue(testName, factory.equals(otherMeta, baseMeta)); assertTrue(factory.equals(otherMeta, baseMeta), testName);
assertThat(testName, baseMeta, is(otherMeta)); assertThat(baseMeta, is(otherMeta), testName);
assertThat(testName, otherMeta, is(baseMeta)); assertThat(otherMeta, is(baseMeta), testName);
assertThat(testName, baseMeta.hashCode(), is(otherMeta.hashCode())); assertThat(baseMeta.hashCode(), is(otherMeta.hashCode()), testName);
} }
} }
} }

View File

@ -1,10 +1,11 @@
package org.bukkit.craftbukkit.inventory; package org.bukkit.craftbukkit.inventory;
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 java.lang.reflect.Method; import java.lang.reflect.Method;
import org.bukkit.Material; import org.bukkit.Material;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class ItemMetaCloneTest { public class ItemMetaCloneTest {
@ -14,8 +15,8 @@ public class ItemMetaCloneTest {
Class<?> clazz = CraftItemFactory.instance().getItemMeta(material).getClass(); Class<?> clazz = CraftItemFactory.instance().getItemMeta(material).getClass();
Method clone = clazz.getDeclaredMethod("clone"); Method clone = clazz.getDeclaredMethod("clone");
assertNotNull("Class " + clazz + " does not override clone()", clone); assertNotNull(clone, "Class " + clazz + " does not override clone()");
assertThat("Class " + clazz + " clone return type does not match", clone.getReturnType(), is(equalTo(clazz))); assertThat(clone.getReturnType(), is(equalTo(clazz)), "Class " + clazz + " clone return type does not match");
} }
} }
} }

View File

@ -1,27 +1,24 @@
package org.bukkit.craftbukkit.inventory; package org.bukkit.craftbukkit.inventory;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.stream.Stream;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.configuration.serialization.DelegateDeserialization;
import org.bukkit.craftbukkit.Overridden; import org.bukkit.craftbukkit.Overridden;
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 ItemMetaImplementationOverrideTest { public class ItemMetaImplementationOverrideTest {
static final Class<CraftMetaItem> parent = CraftMetaItem.class; static final Class<CraftMetaItem> parent = CraftMetaItem.class;
@Parameters(name = "[{index}]:{1}") public static Stream<Arguments> data() {
public static List<Object[]> data() { final List<Arguments> testData = new ArrayList<>();
final List<Object[]> testData = new ArrayList<Object[]>();
List<Class<? extends CraftMetaItem>> classes = new ArrayList<Class<? extends CraftMetaItem>>(); List<Class<? extends CraftMetaItem>> classes = new ArrayList<Class<? extends CraftMetaItem>>();
for (Material material : ItemStackTest.COMPOUND_MATERIALS) { for (Material material : ItemStackTest.COMPOUND_MATERIALS) {
@ -42,7 +39,7 @@ public class ItemMetaImplementationOverrideTest {
for (final Class<?> clazz : classes) { for (final Class<?> clazz : classes) {
for (final Method method : list) { for (final Method method : list) {
testData.add( testData.add(
new Object[] { Arguments.of(
new Callable<Method>() { new Callable<Method>() {
@Override @Override
public Method call() throws Exception { public Method call() throws Exception {
@ -50,12 +47,12 @@ public class ItemMetaImplementationOverrideTest {
} }
}, },
clazz.getSimpleName() + " contains " + method.getName() clazz.getSimpleName() + " contains " + method.getName()
} )
); );
} }
testData.add( testData.add(
new Object[] { Arguments.of(
new Callable<DelegateDeserialization>() { new Callable<DelegateDeserialization>() {
@Override @Override
public DelegateDeserialization call() throws Exception { public DelegateDeserialization call() throws Exception {
@ -63,18 +60,16 @@ public class ItemMetaImplementationOverrideTest {
} }
}, },
clazz.getSimpleName() + " contains annotation " + DelegateDeserialization.class clazz.getSimpleName() + " contains annotation " + DelegateDeserialization.class
} )
); );
} }
return testData; return testData.stream();
} }
@Parameter(0) public Callable<?> test; @ParameterizedTest
@Parameter(1) public String name; @MethodSource("data")
public void testClass(Callable<?> test, String name) throws Throwable {
@Test assertThat(test.call(), is(not(nullValue())), name);
public void testClass() throws Throwable {
assertThat(name, test.call(), is(not(nullValue())));
} }
} }

View File

@ -1,7 +1,8 @@
package org.bukkit.craftbukkit.inventory; package org.bukkit.craftbukkit.inventory;
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 java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -61,30 +62,30 @@ import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType; import org.bukkit.potion.PotionType;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class ItemMetaTest extends AbstractTestingBase { public class ItemMetaTest extends AbstractTestingBase {
static final int MAX_FIREWORK_POWER = 127; // Please update ItemStackFireworkTest if/when this gets changed. static final int MAX_FIREWORK_POWER = 127; // Please update ItemStackFireworkTest if/when this gets changed.
@Test(expected = IllegalArgumentException.class) @Test
public void testPowerLimitExact() { public void testPowerLimitExact() {
newFireworkMeta().setPower(MAX_FIREWORK_POWER + 1); assertThrows(IllegalArgumentException.class, () -> newFireworkMeta().setPower(MAX_FIREWORK_POWER + 1));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testPowerLimitMax() { public void testPowerLimitMax() {
newFireworkMeta().setPower(Integer.MAX_VALUE); assertThrows(IllegalArgumentException.class, () -> newFireworkMeta().setPower(Integer.MAX_VALUE));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testPowerLimitMin() { public void testPowerLimitMin() {
newFireworkMeta().setPower(Integer.MIN_VALUE); assertThrows(IllegalArgumentException.class, () -> newFireworkMeta().setPower(Integer.MIN_VALUE));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testPowerLimitNegative() { public void testPowerLimitNegative() {
newFireworkMeta().setPower(-1); assertThrows(IllegalArgumentException.class, () -> newFireworkMeta().setPower(-1));
} }
@Test @Test
@ -92,7 +93,7 @@ public class ItemMetaTest extends AbstractTestingBase {
for (int i = 0; i <= MAX_FIREWORK_POWER; i++) { for (int i = 0; i <= MAX_FIREWORK_POWER; i++) {
FireworkMeta firework = newFireworkMeta(); FireworkMeta firework = newFireworkMeta();
firework.setPower(i); firework.setPower(i);
assertThat(String.valueOf(i), firework.getPower(), is(i)); assertThat(firework.getPower(), is(i), String.valueOf(i));
} }
} }
@ -152,7 +153,7 @@ public class ItemMetaTest extends AbstractTestingBase {
craft.setItemMeta(craft.getItemMeta()); craft.setItemMeta(craft.getItemMeta());
ItemStack bukkit = new ItemStack(craft); ItemStack bukkit = new ItemStack(craft);
assertThat(craft, is(bukkit)); assertThat(craft, is(bukkit));
assertThat(bukkit, is((ItemStack) craft)); assertThat(bukkit, is(craft));
} }
@Test @Test
@ -179,14 +180,14 @@ public class ItemMetaTest extends AbstractTestingBase {
ItemMeta meta = stack.getItemMeta(); ItemMeta meta = stack.getItemMeta();
if (block instanceof ITileEntity) { if (block instanceof ITileEntity) {
assertTrue(stack + " has meta of type " + meta + " expected BlockStateMeta", meta instanceof BlockStateMeta); assertTrue(meta instanceof BlockStateMeta, stack + " has meta of type " + meta + " expected BlockStateMeta");
BlockStateMeta blockState = (BlockStateMeta) meta; BlockStateMeta blockState = (BlockStateMeta) meta;
assertNotNull(stack + " has null block state", blockState.getBlockState()); assertNotNull(blockState.getBlockState(), stack + " has null block state");
blockState.setBlockState(blockState.getBlockState()); blockState.setBlockState(blockState.getBlockState());
} else { } else {
assertTrue(stack + " has unexpected meta of type BlockStateMeta (but is not a tile)", !(meta instanceof BlockStateMeta)); assertFalse(meta instanceof BlockStateMeta, stack + " has unexpected meta of type BlockStateMeta (but is not a tile)");
} }
} }
} }
@ -200,9 +201,9 @@ public class ItemMetaTest extends AbstractTestingBase {
CraftMetaItem baseMeta = (CraftMetaItem) Bukkit.getItemFactory().getItemMeta(material); CraftMetaItem baseMeta = (CraftMetaItem) Bukkit.getItemFactory().getItemMeta(material);
ItemMeta baseMetaItem = CraftItemStack.getItemMeta(item.getDefaultInstance()); ItemMeta baseMetaItem = CraftItemStack.getItemMeta(item.getDefaultInstance());
assertTrue(material + " is not handled in CraftItemFactory", baseMeta instanceof CraftMetaSpawnEgg); assertTrue(baseMeta instanceof CraftMetaSpawnEgg, material + " is not handled in CraftItemFactory");
assertTrue(material + " is not applicable to CraftMetaSpawnEgg", baseMeta.applicableTo(material)); assertTrue(baseMeta.applicableTo(material), material + " is not applicable to CraftMetaSpawnEgg");
assertTrue(material + " is not handled in CraftItemStack", baseMetaItem instanceof SpawnEggMeta); assertTrue(baseMetaItem instanceof SpawnEggMeta, material + " is not handled in CraftItemStack");
} }
} }
} }
@ -411,7 +412,7 @@ public class ItemMetaTest extends AbstractTestingBase {
} }
); );
assertThat("Forgotten test?", providers, hasSize(ItemStackTest.COMPOUND_MATERIALS.length - 4/* Normal item meta, skulls, eggs and tile entities */)); assertThat(providers, hasSize(ItemStackTest.COMPOUND_MATERIALS.length - 4/* Normal item meta, skulls, eggs and tile entities */), "Forgotten test?");
for (final StackProvider provider : providers) { for (final StackProvider provider : providers) {
downCastTest(new BukkitWrapper(provider)); downCastTest(new BukkitWrapper(provider));
@ -452,8 +453,8 @@ public class ItemMetaTest extends AbstractTestingBase {
final ItemStack craftBlank = CraftItemStack.asCraftCopy(blank); final ItemStack craftBlank = CraftItemStack.asCraftCopy(blank);
// Check that equality and similarity works for each meta implementation // Check that equality and similarity works for each meta implementation
assertThat(name, provider.stack(), is(provider.stack())); assertThat(provider.stack(), is(provider.stack()), name);
assertThat(name, provider.stack().isSimilar(provider.stack()), is(true)); assertThat(provider.stack().isSimilar(provider.stack()), is(true), name);
downCastTest(name, provider.stack(), blank); downCastTest(name, provider.stack(), blank);
blank.setItemMeta(blank.getItemMeta()); blank.setItemMeta(blank.getItemMeta());
@ -465,11 +466,11 @@ public class ItemMetaTest extends AbstractTestingBase {
} }
private void downCastTest(final String name, final ItemStack stack, final ItemStack blank) { private void downCastTest(final String name, final ItemStack stack, final ItemStack blank) {
assertThat(name, stack, is(not(blank))); assertThat(stack, is(not(blank)), name);
assertThat(name, stack.getItemMeta(), is(not(blank.getItemMeta()))); assertThat(stack.getItemMeta(), is(not(blank.getItemMeta())), name);
stack.setType(Material.STONE); stack.setType(Material.STONE);
assertThat(name, stack, is(blank)); assertThat(stack, is(blank), name);
} }
} }

View File

@ -3,21 +3,15 @@ package org.bukkit.craftbukkit.inventory;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.inventory.ItemStackTest.CompoundOperator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.Operator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.StackProvider;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.BookMeta;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.Arguments;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ItemStackBookTest extends ItemStackTest { public class ItemStackBookTest extends ItemStackTest {
@Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") public static Stream<Arguments> data() {
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.WRITTEN_BOOK, Material.WRITABLE_BOOK); return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.WRITTEN_BOOK, Material.WRITABLE_BOOK);
} }

View File

@ -3,22 +3,16 @@ package org.bukkit.craftbukkit.inventory;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.inventory.ItemStackTest.CompoundOperator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.Operator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.StackProvider;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.Arguments;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ItemStackEnchantStorageTest extends ItemStackTest { public class ItemStackEnchantStorageTest extends ItemStackTest {
@Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") public static Stream<Arguments> data() {
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.ENCHANTED_BOOK); return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.ENCHANTED_BOOK);
} }

View File

@ -3,24 +3,18 @@ package org.bukkit.craftbukkit.inventory;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import java.util.Arrays; import java.util.Arrays;
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.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.inventory.ItemStackTest.CompoundOperator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.Operator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.StackProvider;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkEffectMeta; import org.bukkit.inventory.meta.FireworkEffectMeta;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.Arguments;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ItemStackFireworkChargeTest extends ItemStackTest { public class ItemStackFireworkChargeTest extends ItemStackTest {
@Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") public static Stream<Arguments> data() {
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.FIREWORK_STAR); return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.FIREWORK_STAR);
} }

View File

@ -3,24 +3,18 @@ package org.bukkit.craftbukkit.inventory;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import java.util.Arrays; import java.util.Arrays;
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.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.inventory.ItemStackTest.CompoundOperator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.Operator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.StackProvider;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.inventory.meta.FireworkMeta;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.Arguments;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ItemStackFireworkTest extends ItemStackTest { public class ItemStackFireworkTest extends ItemStackTest {
@Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") public static Stream<Arguments> data() {
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.FIREWORK_ROCKET); return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.FIREWORK_ROCKET);
} }

View File

@ -3,22 +3,16 @@ package org.bukkit.craftbukkit.inventory;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.inventory.ItemStackTest.CompoundOperator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.Operator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.StackProvider;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.Arguments;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ItemStackLeatherTest extends ItemStackTest { public class ItemStackLeatherTest extends ItemStackTest {
@Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") public static Stream<Arguments> data() {
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.LEATHER_BOOTS, Material.LEATHER_CHESTPLATE, Material.LEATHER_HELMET, Material.LEATHER_LEGGINGS); return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.LEATHER_BOOTS, Material.LEATHER_CHESTPLATE, Material.LEATHER_HELMET, Material.LEATHER_LEGGINGS);
} }

View File

@ -3,22 +3,16 @@ package org.bukkit.craftbukkit.inventory;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.bukkit.craftbukkit.inventory.ItemStackTest.CompoundOperator; import java.util.stream.Stream;
import org.bukkit.craftbukkit.inventory.ItemStackTest.Operator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.StackProvider;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.Repairable; import org.bukkit.inventory.meta.Repairable;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.Arguments;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ItemStackLoreEnchantmentTest extends ItemStackTest { public class ItemStackLoreEnchantmentTest extends ItemStackTest {
@Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") public static Stream<Arguments> data() {
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, ItemStackTest.COMPOUND_MATERIALS); return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, ItemStackTest.COMPOUND_MATERIALS);
} }

View File

@ -3,21 +3,15 @@ package org.bukkit.craftbukkit.inventory;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.inventory.ItemStackTest.CompoundOperator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.Operator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.StackProvider;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.MapMeta; import org.bukkit.inventory.meta.MapMeta;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.Arguments;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ItemStackMapTest extends ItemStackTest { public class ItemStackMapTest extends ItemStackTest {
@Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") public static Stream<Arguments> data() {
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.FILLED_MAP); return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.FILLED_MAP);
} }

View File

@ -3,22 +3,16 @@ package org.bukkit.craftbukkit.inventory;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.inventory.ItemStackTest.CompoundOperator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.Operator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.StackProvider;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.Arguments;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ItemStackPotionsTest extends ItemStackTest { public class ItemStackPotionsTest extends ItemStackTest {
@Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") public static Stream<Arguments> data() {
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.POTION); return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.POTION);
} }

View File

@ -3,21 +3,15 @@ package org.bukkit.craftbukkit.inventory;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.inventory.ItemStackTest.CompoundOperator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.Operator;
import org.bukkit.craftbukkit.inventory.ItemStackTest.StackProvider;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.Arguments;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ItemStackSkullTest extends ItemStackTest { public class ItemStackSkullTest extends ItemStackTest {
@Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") public static Stream<Arguments> data() {
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.PLAYER_HEAD); return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.PLAYER_HEAD);
} }

View File

@ -1,10 +1,9 @@
package org.bukkit.craftbukkit.inventory; package org.bukkit.craftbukkit.inventory;
import static org.bukkit.support.Matchers.*; import static org.bukkit.support.MatcherAssert.*;
import static org.bukkit.support.Matchers.sameHash;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -15,6 +14,7 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Stream;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -24,14 +24,11 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.bukkit.util.io.BukkitObjectInputStream; import org.bukkit.util.io.BukkitObjectInputStream;
import org.bukkit.util.io.BukkitObjectOutputStream; import org.bukkit.util.io.BukkitObjectOutputStream;
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 ItemStackTest extends AbstractTestingBase { public class ItemStackTest extends AbstractTestingBase {
abstract static class StackProvider { abstract static class StackProvider {
final Material material; final Material material;
@ -70,8 +67,8 @@ public class ItemStackTest extends AbstractTestingBase {
* @param materials * @param materials
* @return * @return
*/ */
static List<Object[]> compound(final List<Object[]> parameterList, final String nameFormat, final int nameIndex, final Material...materials) { static Stream<Arguments> compound(final List<Object[]> parameterList, final String nameFormat, final int nameIndex, final Material... materials) {
final List<Object[]> out = new ArrayList<Object[]>(); final List<Arguments> out = new ArrayList<>();
for (Object[] params : parameterList) { for (Object[] params : parameterList) {
final int len = params.length; final int len = params.length;
for (final Material material : materials) { for (final Material material : materials) {
@ -89,10 +86,10 @@ public class ItemStackTest extends AbstractTestingBase {
} }
} }
paramsOut[nameIndex] = String.format(nameFormat, paramsOut[nameIndex], material); paramsOut[nameIndex] = String.format(nameFormat, paramsOut[nameIndex], material);
out.add(paramsOut); out.add(Arguments.of(paramsOut));
} }
} }
return out; return out.stream();
} }
} }
@ -305,9 +302,8 @@ public class ItemStackTest extends AbstractTestingBase {
} }
} }
@Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") public static Stream<Arguments> data() {
public static List<Object[]> data() { return Stream.empty(); // TODO, test basic durability issues
return ImmutableList.of(); // TODO, test basic durability issues
} }
static final Object[][] EMPTY_ARRAY = new Object[0][]; static final Object[][] EMPTY_ARRAY = new Object[0][];
@ -330,26 +326,55 @@ public class ItemStackTest extends AbstractTestingBase {
COMPOUND_MATERIALS = possibleMaterials.values().toArray(new Material[possibleMaterials.size()]); COMPOUND_MATERIALS = possibleMaterials.values().toArray(new Material[possibleMaterials.size()]);
} }
@Parameter(0) public StackProvider provider; @ParameterizedTest(name = "[{index}]:{" + NAME_PARAMETER + "}")
@Parameter(1) public StackProvider unequalProvider; @MethodSource({"data",
@Parameter(NAME_PARAMETER) public String name; "org.bukkit.craftbukkit.inventory.ItemStackSkullTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackPotionsTest#data",
@Test "org.bukkit.craftbukkit.inventory.ItemStackMapTest#data",
public void testBukkitInequality() { "org.bukkit.craftbukkit.inventory.ItemStackLoreEnchantmentTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackLeatherTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackFireworkTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackFireworkChargeTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackEnchantStorageTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackBookTest#data"
})
public void testBukkitInequality(StackProvider provider, StackProvider unequalProvider, String name) {
final StackWrapper bukkitWrapper = new CraftWrapper(provider); final StackWrapper bukkitWrapper = new CraftWrapper(provider);
testInequality(bukkitWrapper, new BukkitWrapper(unequalProvider)); testInequality(bukkitWrapper, new BukkitWrapper(unequalProvider));
testInequality(bukkitWrapper, new BukkitWrapper(new NoOpProvider(provider.material))); testInequality(bukkitWrapper, new BukkitWrapper(new NoOpProvider(provider.material)));
} }
@Test @ParameterizedTest(name = "[{index}]:{" + NAME_PARAMETER + "}")
public void testCraftInequality() { @MethodSource({"data",
"org.bukkit.craftbukkit.inventory.ItemStackSkullTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackPotionsTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackMapTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackLoreEnchantmentTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackLeatherTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackFireworkTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackFireworkChargeTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackEnchantStorageTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackBookTest#data"
})
public void testCraftInequality(StackProvider provider, StackProvider unequalProvider, String name) {
final StackWrapper craftWrapper = new CraftWrapper(provider); final StackWrapper craftWrapper = new CraftWrapper(provider);
testInequality(craftWrapper, new CraftWrapper(unequalProvider)); testInequality(craftWrapper, new CraftWrapper(unequalProvider));
testInequality(craftWrapper, new CraftWrapper(new NoOpProvider(provider.material))); testInequality(craftWrapper, new CraftWrapper(new NoOpProvider(provider.material)));
} }
@Test @ParameterizedTest(name = "[{index}]:{" + NAME_PARAMETER + "}")
public void testMixedInequality() { @MethodSource({"data",
"org.bukkit.craftbukkit.inventory.ItemStackSkullTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackPotionsTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackMapTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackLoreEnchantmentTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackLeatherTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackFireworkTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackFireworkChargeTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackEnchantStorageTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackBookTest#data"
})
public void testMixedInequality(StackProvider provider, StackProvider unequalProvider, String name) {
final StackWrapper craftWrapper = new CraftWrapper(provider); final StackWrapper craftWrapper = new CraftWrapper(provider);
testInequality(craftWrapper, new BukkitWrapper(unequalProvider)); testInequality(craftWrapper, new BukkitWrapper(unequalProvider));
testInequality(craftWrapper, new BukkitWrapper(new NoOpProvider(provider.material))); testInequality(craftWrapper, new BukkitWrapper(new NoOpProvider(provider.material)));
@ -400,23 +425,67 @@ public class ItemStackTest extends AbstractTestingBase {
assertThat(newUnequalCraftStack.getItemMeta(), is(not(stack.getItemMeta()))); assertThat(newUnequalCraftStack.getItemMeta(), is(not(stack.getItemMeta())));
} }
@Test @ParameterizedTest(name = "[{index}]:{" + NAME_PARAMETER + "}")
public void testBukkitYamlDeserialize() throws Throwable { @MethodSource({"data",
"org.bukkit.craftbukkit.inventory.ItemStackSkullTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackPotionsTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackMapTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackLoreEnchantmentTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackLeatherTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackFireworkTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackFireworkChargeTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackEnchantStorageTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackBookTest#data"
})
public void testBukkitYamlDeserialize(StackProvider provider, StackProvider unequalProvider, String name) throws Throwable {
testYamlDeserialize(new BukkitWrapper(provider), new BukkitWrapper(unequalProvider)); testYamlDeserialize(new BukkitWrapper(provider), new BukkitWrapper(unequalProvider));
} }
@Test @ParameterizedTest(name = "[{index}]:{" + NAME_PARAMETER + "}")
public void testCraftYamlDeserialize() throws Throwable { @MethodSource({"data",
"org.bukkit.craftbukkit.inventory.ItemStackSkullTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackPotionsTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackMapTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackLoreEnchantmentTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackLeatherTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackFireworkTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackFireworkChargeTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackEnchantStorageTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackBookTest#data"
})
public void testCraftYamlDeserialize(StackProvider provider, StackProvider unequalProvider, String name) throws Throwable {
testYamlDeserialize(new CraftWrapper(provider), new CraftWrapper(unequalProvider)); testYamlDeserialize(new CraftWrapper(provider), new CraftWrapper(unequalProvider));
} }
@Test @ParameterizedTest(name = "[{index}]:{" + NAME_PARAMETER + "}")
public void testBukkitStreamDeserialize() throws Throwable { @MethodSource({"data",
"org.bukkit.craftbukkit.inventory.ItemStackSkullTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackPotionsTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackMapTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackLoreEnchantmentTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackLeatherTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackFireworkTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackFireworkChargeTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackEnchantStorageTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackBookTest#data"
})
public void testBukkitStreamDeserialize(StackProvider provider, StackProvider unequalProvider, String name) throws Throwable {
testStreamDeserialize(new BukkitWrapper(provider), new BukkitWrapper(unequalProvider)); testStreamDeserialize(new BukkitWrapper(provider), new BukkitWrapper(unequalProvider));
} }
@Test @ParameterizedTest(name = "[{index}]:{" + NAME_PARAMETER + "}")
public void testCraftStreamDeserialize() throws Throwable { @MethodSource({"data",
"org.bukkit.craftbukkit.inventory.ItemStackSkullTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackPotionsTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackMapTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackLoreEnchantmentTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackLeatherTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackFireworkTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackFireworkChargeTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackEnchantStorageTest#data",
"org.bukkit.craftbukkit.inventory.ItemStackBookTest#data"
})
public void testCraftStreamDeserialize(StackProvider provider, StackProvider unequalProvider, String name) throws Throwable {
testStreamDeserialize(new CraftWrapper(provider), new CraftWrapper(unequalProvider)); testStreamDeserialize(new CraftWrapper(provider), new CraftWrapper(unequalProvider));
} }
@ -486,9 +555,9 @@ public class ItemStackTest extends AbstractTestingBase {
} }
static void testEqualities(String information, ItemStack primaryRead, ItemStack unequalRead, ItemStack primaryOriginal, ItemStack unequalOriginal) { static void testEqualities(String information, ItemStack primaryRead, ItemStack unequalRead, ItemStack primaryOriginal, ItemStack unequalOriginal) {
assertThat(information, primaryRead, allOf(equalTo(primaryOriginal), sameHash(primaryOriginal))); assertThat(primaryRead, allOf(equalTo(primaryOriginal), sameHash(primaryOriginal)), information);
assertThat(information, unequalRead, allOf(equalTo(unequalOriginal), sameHash(unequalOriginal))); assertThat(unequalRead, allOf(equalTo(unequalOriginal), sameHash(unequalOriginal)), information);
assertThat(information, primaryRead, is(not(unequalOriginal))); assertThat(primaryRead, is(not(unequalOriginal)), information);
assertThat(information, primaryRead, is(not(unequalRead))); assertThat(primaryRead, is(not(unequalRead)), information);
} }
} }

View File

@ -1,11 +1,11 @@
package org.bukkit.craftbukkit.inventory; package org.bukkit.craftbukkit.inventory;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.item.enchantment.Enchantments;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class NMSCraftItemStackTest extends AbstractTestingBase { public class NMSCraftItemStackTest extends AbstractTestingBase {

View File

@ -1,6 +1,6 @@
package org.bukkit.craftbukkit.inventory; package org.bukkit.craftbukkit.inventory;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.io.StringReader; import java.io.StringReader;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -17,52 +17,52 @@ import org.bukkit.persistence.PersistentDataAdapterContext;
import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Before; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class PersistentDataContainerTest extends AbstractTestingBase { public class PersistentDataContainerTest extends AbstractTestingBase {
private static NamespacedKey VALID_KEY; private static NamespacedKey VALID_KEY;
@Before @BeforeAll
public void setup() { public static void setup() {
VALID_KEY = new NamespacedKey("test", "validkey"); VALID_KEY = new NamespacedKey("test", "validkey");
} }
/* /*
Sets a test Sets a test
*/ */
@Test(expected = IllegalArgumentException.class) @Test
public void testSetNoAdapter() { public void testSetNoAdapter() {
ItemMeta itemMeta = createNewItemMeta(); ItemMeta itemMeta = createNewItemMeta();
itemMeta.getPersistentDataContainer().set(VALID_KEY, new PrimitiveTagType<>(boolean.class), true); assertThrows(IllegalArgumentException.class, () -> itemMeta.getPersistentDataContainer().set(VALID_KEY, new PrimitiveTagType<>(boolean.class), true));
} }
/* /*
Contains a tag Contains a tag
*/ */
@Test(expected = IllegalArgumentException.class) @Test
public void testHasNoAdapter() { public void testHasNoAdapter() {
ItemMeta itemMeta = createNewItemMeta(); ItemMeta itemMeta = createNewItemMeta();
itemMeta.getPersistentDataContainer().set(VALID_KEY, PersistentDataType.INTEGER, 1); // We gotta set this so we at least try to compare it itemMeta.getPersistentDataContainer().set(VALID_KEY, PersistentDataType.INTEGER, 1); // We gotta set this so we at least try to compare it
itemMeta.getPersistentDataContainer().has(VALID_KEY, new PrimitiveTagType<>(boolean.class)); assertThrows(IllegalArgumentException.class, () -> itemMeta.getPersistentDataContainer().has(VALID_KEY, new PrimitiveTagType<>(boolean.class)));
} }
/* /*
Getting a tag Getting a tag
*/ */
@Test(expected = IllegalArgumentException.class) @Test
public void testGetNoAdapter() { public void testGetNoAdapter() {
ItemMeta itemMeta = createNewItemMeta(); ItemMeta itemMeta = createNewItemMeta();
itemMeta.getPersistentDataContainer().set(VALID_KEY, PersistentDataType.INTEGER, 1); //We gotta set this so we at least try to compare it itemMeta.getPersistentDataContainer().set(VALID_KEY, PersistentDataType.INTEGER, 1); //We gotta set this so we at least try to compare it
itemMeta.getPersistentDataContainer().get(VALID_KEY, new PrimitiveTagType<>(boolean.class)); assertThrows(IllegalArgumentException.class, () -> itemMeta.getPersistentDataContainer().get(VALID_KEY, new PrimitiveTagType<>(boolean.class)));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testGetWrongType() { public void testGetWrongType() {
ItemMeta itemMeta = createNewItemMeta(); ItemMeta itemMeta = createNewItemMeta();
itemMeta.getPersistentDataContainer().set(VALID_KEY, PersistentDataType.INTEGER, 1); itemMeta.getPersistentDataContainer().set(VALID_KEY, PersistentDataType.INTEGER, 1);
itemMeta.getPersistentDataContainer().get(VALID_KEY, PersistentDataType.STRING); assertThrows(IllegalArgumentException.class, () -> itemMeta.getPersistentDataContainer().get(VALID_KEY, PersistentDataType.STRING));
} }
@Test @Test

View File

@ -1,11 +1,11 @@
package org.bukkit.craftbukkit.inventory; package org.bukkit.craftbukkit.inventory;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import net.minecraft.world.entity.player.PlayerInventory; import net.minecraft.world.entity.player.PlayerInventory;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items; import net.minecraft.world.item.Items;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class PlayerInventoryTest extends AbstractTestingBase { public class PlayerInventoryTest extends AbstractTestingBase {

View File

@ -1,24 +1,24 @@
package org.bukkit.craftbukkit.legacy; package org.bukkit.craftbukkit.legacy;
import static org.junit.jupiter.api.Assertions.*;
import org.bukkit.Material; import org.bukkit.Material;
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 EvilTest extends AbstractTestingBase { public class EvilTest extends AbstractTestingBase {
@Test @Test
public void testFrom() { public void testFrom() {
Assert.assertEquals(Material.LEGACY_STONE, CraftEvil.getMaterial(1)); assertEquals(Material.LEGACY_STONE, CraftEvil.getMaterial(1));
} }
@Test @Test
public void testTo() { public void testTo() {
Assert.assertEquals(1, CraftEvil.getId(Material.LEGACY_STONE)); assertEquals(1, CraftEvil.getId(Material.LEGACY_STONE));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testIllegal() { public void testIllegal() {
Material.STONE.getId(); assertThrows(IllegalArgumentException.class, () -> Material.STONE.getId());
} }
} }

View File

@ -1,5 +1,6 @@
package org.bukkit.craftbukkit.legacy; package org.bukkit.craftbukkit.legacy;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -7,8 +8,7 @@ import org.bukkit.Material;
import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
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 LegacyTest extends AbstractTestingBase { public class LegacyTest extends AbstractTestingBase {
@ -125,18 +125,18 @@ public class LegacyTest extends AbstractTestingBase {
if (!INVALIDATED_MATERIALS.contains(material) && !material.isLegacy()) { if (!INVALIDATED_MATERIALS.contains(material) && !material.isLegacy()) {
MaterialData converted = CraftLegacy.toLegacyData(material); MaterialData converted = CraftLegacy.toLegacyData(material);
Assert.assertNotEquals("Could not toLegacy " + material, Material.LEGACY_AIR, converted.getItemType()); assertNotEquals(Material.LEGACY_AIR, converted.getItemType(), "Could not toLegacy " + material);
if (!INVALIDATED_MATERIALS.contains(converted.getItemType())) { if (!INVALIDATED_MATERIALS.contains(converted.getItemType())) {
Assert.assertNotEquals("Could not fromLegacy(toLegacy) " + converted + "(" + material + ")", Material.AIR, CraftLegacy.fromLegacy(converted)); assertNotEquals(Material.AIR, CraftLegacy.fromLegacy(converted), "Could not fromLegacy(toLegacy) " + converted + "(" + material + ")");
} }
if (!INVERSION_FAILS.contains(material)) { if (!INVERSION_FAILS.contains(material)) {
Assert.assertEquals("Could not fromLegacy(toLegacy) " + converted + "(" + material + ")", material, CraftLegacy.fromLegacy(converted)); assertEquals(material, CraftLegacy.fromLegacy(converted), "Could not fromLegacy(toLegacy) " + converted + "(" + material + ")");
} }
} }
} }
Assert.assertEquals("Could not toLegacy Air", Material.LEGACY_AIR, CraftLegacy.toLegacy(Material.AIR)); assertEquals(Material.LEGACY_AIR, CraftLegacy.toLegacy(Material.AIR), "Could not toLegacy Air");
} }
@Test @Test
@ -144,32 +144,32 @@ public class LegacyTest extends AbstractTestingBase {
for (Material material : Material.values()) { for (Material material : Material.values()) {
if (!INVALIDATED_MATERIALS.contains(material) && material.isLegacy()) { if (!INVALIDATED_MATERIALS.contains(material) && material.isLegacy()) {
Material converted = CraftLegacy.fromLegacy(material); Material converted = CraftLegacy.fromLegacy(material);
Assert.assertNotEquals("Could not fromLegacy " + material, Material.AIR, converted); assertNotEquals(Material.AIR, converted, "Could not fromLegacy " + material);
Assert.assertNotEquals("Could not toLegacy(fromLegacy) " + converted + "(" + material + ")", Material.AIR, CraftLegacy.toLegacy(converted)); assertNotEquals(Material.AIR, CraftLegacy.toLegacy(converted), "Could not toLegacy(fromLegacy) " + converted + "(" + material + ")");
if (!INVERSION_FAILS.contains(material)) { if (!INVERSION_FAILS.contains(material)) {
Assert.assertEquals("Could not toLegacy(fromLegacy) " + converted + "(" + material + ")", material, CraftLegacy.toLegacy(converted)); assertEquals(material, CraftLegacy.toLegacy(converted), "Could not toLegacy(fromLegacy) " + converted + "(" + material + ")");
} }
} }
} }
Assert.assertEquals("Could not fromLegacy Air", Material.AIR, CraftLegacy.fromLegacy(Material.LEGACY_AIR)); assertEquals(Material.AIR, CraftLegacy.fromLegacy(Material.LEGACY_AIR), "Could not fromLegacy Air");
} }
@Test @Test
public void testRestricted() { public void testRestricted() {
for (Material material : CraftLegacy.values()) { for (Material material : CraftLegacy.values()) {
Assert.assertTrue("Must iterate only legacy materials", material.isLegacy()); assertTrue(material.isLegacy(), "Must iterate only legacy materials");
} }
for (Material material : org.bukkit.craftbukkit.util.CraftLegacy.modern_values()) { for (Material material : org.bukkit.craftbukkit.util.CraftLegacy.modern_values()) {
Assert.assertFalse("Must iterate only modern materials", material.isLegacy()); assertFalse(material.isLegacy(), "Must iterate only modern materials");
} }
} }
@Test @Test
public void testManual() { public void testManual() {
Assert.assertEquals(Material.YELLOW_DYE, CraftMagicNumbers.INSTANCE.getMaterial("dandelion_yellow", 1631)); assertEquals(Material.YELLOW_DYE, CraftMagicNumbers.INSTANCE.getMaterial("dandelion_yellow", 1631));
Assert.assertEquals(Material.OAK_WALL_SIGN, CraftMagicNumbers.INSTANCE.getMaterial("wall_sign", 1631)); assertEquals(Material.OAK_WALL_SIGN, CraftMagicNumbers.INSTANCE.getMaterial("wall_sign", 1631));
} }
} }

View File

@ -1,5 +1,6 @@
package org.bukkit.craftbukkit.profile; package org.bukkit.craftbukkit.profile;
import static org.junit.jupiter.api.Assertions.*;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.Property;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@ -11,8 +12,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerialization; import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.profile.PlayerProfile; import org.bukkit.profile.PlayerProfile;
import org.bukkit.profile.PlayerTextures; import org.bukkit.profile.PlayerTextures;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class PlayerProfileTest { public class PlayerProfileTest {
@ -62,19 +62,19 @@ public class PlayerProfileTest {
@Test @Test
public void testProvidedValues() { public void testProvidedValues() {
Property property = new Property(CraftPlayerTextures.PROPERTY_NAME, VALUE, SIGNATURE); Property property = new Property(CraftPlayerTextures.PROPERTY_NAME, VALUE, SIGNATURE);
Assert.assertTrue("Invalid test property signature, has the public key changed?", CraftProfileProperty.hasValidSignature(property)); assertTrue(CraftProfileProperty.hasValidSignature(property), "Invalid test property signature, has the public key changed?");
} }
@Test @Test
public void testProfileCreation() { public void testProfileCreation() {
// Invalid profiles: // Invalid profiles:
Assert.assertThrows(IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> {
new CraftPlayerProfile(null, null); new CraftPlayerProfile(null, null);
}); });
Assert.assertThrows(IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> {
new CraftPlayerProfile(null, ""); new CraftPlayerProfile(null, "");
}); });
Assert.assertThrows(IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> {
new CraftPlayerProfile(null, " "); new CraftPlayerProfile(null, " ");
}); });
@ -87,48 +87,48 @@ public class PlayerProfileTest {
@Test @Test
public void testGameProfileWrapping() { public void testGameProfileWrapping() {
// Invalid profiles: // Invalid profiles:
Assert.assertThrows(NullPointerException.class, () -> { assertThrows(NullPointerException.class, () -> {
new CraftPlayerProfile(null); new CraftPlayerProfile(null);
}); });
// Valid profiles: // Valid profiles:
CraftPlayerProfile profile1 = new CraftPlayerProfile(new GameProfile(UNIQUE_ID, NAME)); CraftPlayerProfile profile1 = new CraftPlayerProfile(new GameProfile(UNIQUE_ID, NAME));
Assert.assertEquals("Unique id is not the same", UNIQUE_ID, profile1.getUniqueId()); assertEquals(UNIQUE_ID, profile1.getUniqueId(), "Unique id is not the same");
Assert.assertEquals("Name is not the same", NAME, profile1.getName()); assertEquals(NAME, profile1.getName(), "Name is not the same");
CraftPlayerProfile profile2 = new CraftPlayerProfile(new GameProfile(UNIQUE_ID, "")); CraftPlayerProfile profile2 = new CraftPlayerProfile(new GameProfile(UNIQUE_ID, ""));
Assert.assertEquals("Unique id is not the same", UNIQUE_ID, profile2.getUniqueId()); assertEquals(UNIQUE_ID, profile2.getUniqueId(), "Unique id is not the same");
Assert.assertEquals("Name is not null", null, profile2.getName()); assertEquals(null, profile2.getName(), "Name is not null");
CraftPlayerProfile profile3 = new CraftPlayerProfile(new GameProfile(SystemUtils.NIL_UUID, NAME)); CraftPlayerProfile profile3 = new CraftPlayerProfile(new GameProfile(SystemUtils.NIL_UUID, NAME));
Assert.assertEquals("Unique id is not null", null, profile3.getUniqueId()); assertEquals(null, profile3.getUniqueId(), "Unique id is not null");
Assert.assertEquals("Name is not the same", NAME, profile3.getName()); assertEquals(NAME, profile3.getName(), "Name is not the same");
} }
@Test @Test
public void testTexturesLoading() { public void testTexturesLoading() {
CraftPlayerProfile profile = buildPlayerProfile(); CraftPlayerProfile profile = buildPlayerProfile();
Assert.assertEquals("Unique id is not the same", UNIQUE_ID, profile.getUniqueId()); assertEquals(UNIQUE_ID, profile.getUniqueId(), "Unique id is not the same");
Assert.assertEquals("Name is not the same", NAME, profile.getName()); assertEquals(NAME, profile.getName(), "Name is not the same");
Assert.assertEquals("Skin url is not the same", SKIN, profile.getTextures().getSkin()); assertEquals(SKIN, profile.getTextures().getSkin(), "Skin url is not the same");
Assert.assertEquals("Skin model is not the same", PlayerTextures.SkinModel.SLIM, profile.getTextures().getSkinModel()); assertEquals(PlayerTextures.SkinModel.SLIM, profile.getTextures().getSkinModel(), "Skin model is not the same");
Assert.assertEquals("Cape url is not the same", CAPE, profile.getTextures().getCape()); assertEquals(CAPE, profile.getTextures().getCape(), "Cape url is not the same");
Assert.assertEquals("Timestamp is not the same", TIMESTAMP, profile.getTextures().getTimestamp()); assertEquals(TIMESTAMP, profile.getTextures().getTimestamp(), "Timestamp is not the same");
} }
@Test @Test
public void testBuildGameProfile() { public void testBuildGameProfile() {
CraftPlayerProfile profile = buildPlayerProfile(); CraftPlayerProfile profile = buildPlayerProfile();
GameProfile gameProfile = profile.buildGameProfile(); GameProfile gameProfile = profile.buildGameProfile();
Assert.assertNotNull("GameProfile is null", gameProfile); assertNotNull(gameProfile, "GameProfile is null");
Property property = CraftPlayerProfile.getProperty(gameProfile, CraftPlayerTextures.PROPERTY_NAME); Property property = CraftPlayerProfile.getProperty(gameProfile, CraftPlayerTextures.PROPERTY_NAME);
Assert.assertNotNull("Textures property is null", property); assertNotNull(property, "Textures property is null");
Assert.assertEquals("Property values are not the same", VALUE, property.value()); assertEquals(VALUE, property.value(), "Property values are not the same");
Assert.assertEquals("Names are not the same", NAME, gameProfile.getName()); assertEquals(NAME, gameProfile.getName(), "Names are not the same");
Assert.assertEquals("Unique ids are not the same", UNIQUE_ID, gameProfile.getId()); assertEquals(UNIQUE_ID, gameProfile.getId(), "Unique ids are not the same");
Assert.assertTrue("Signature is missing", property.hasSignature()); assertTrue(property.hasSignature(), "Signature is missing");
Assert.assertTrue("Signature is not valid", CraftProfileProperty.hasValidSignature(property)); assertTrue(CraftProfileProperty.hasValidSignature(property), "Signature is not valid");
} }
@Test @Test
@ -136,34 +136,34 @@ public class PlayerProfileTest {
CraftPlayerProfile profile = buildPlayerProfile(); CraftPlayerProfile profile = buildPlayerProfile();
GameProfile gameProfile1 = profile.buildGameProfile(); GameProfile gameProfile1 = profile.buildGameProfile();
GameProfile gameProfile2 = profile.buildGameProfile(); GameProfile gameProfile2 = profile.buildGameProfile();
Assert.assertTrue("CraftPlayerProfile#buildGameProfile() does not produce a new instance", gameProfile1 != gameProfile2); assertNotSame(gameProfile1, gameProfile2, "CraftPlayerProfile#buildGameProfile() does not produce a new instance");
} }
@Test @Test
public void testSignatureValidation() { public void testSignatureValidation() {
CraftPlayerProfile profile = buildPlayerProfile(); CraftPlayerProfile profile = buildPlayerProfile();
Assert.assertTrue("Signature is not valid", profile.getTextures().isSigned()); assertTrue(profile.getTextures().isSigned(), "Signature is not valid");
} }
@Test @Test
public void testSignatureInvalidation() { public void testSignatureInvalidation() {
CraftPlayerProfile profile = buildPlayerProfile(); CraftPlayerProfile profile = buildPlayerProfile();
profile.getTextures().setSkin(null); profile.getTextures().setSkin(null);
Assert.assertTrue("Textures has a timestamp", profile.getTextures().getTimestamp() == 0L); assertEquals(0L, profile.getTextures().getTimestamp(), "Textures has a timestamp");
Assert.assertTrue("Textures signature is valid", !profile.getTextures().isSigned()); assertFalse(profile.getTextures().isSigned(), "Textures signature is valid");
// Ensure that the invalidation is preserved when the property is rebuilt: // Ensure that the invalidation is preserved when the property is rebuilt:
profile.rebuildDirtyProperties(); profile.rebuildDirtyProperties();
Assert.assertTrue("Rebuilt textures has a timestamp", profile.getTextures().getTimestamp() == 0L); assertEquals(0L, profile.getTextures().getTimestamp(), "Rebuilt textures has a timestamp");
Assert.assertTrue("Rebuilt textures signature is valid", !profile.getTextures().isSigned()); assertFalse(profile.getTextures().isSigned(), "Rebuilt textures signature is valid");
} }
@Test @Test
public void testSetSkinResetsSkinModel() { public void testSetSkinResetsSkinModel() {
CraftPlayerProfile profile = buildPlayerProfile(); CraftPlayerProfile profile = buildPlayerProfile();
Assert.assertEquals("Skin model is not the same", PlayerTextures.SkinModel.SLIM, profile.getTextures().getSkinModel()); assertEquals(PlayerTextures.SkinModel.SLIM, profile.getTextures().getSkinModel(), "Skin model is not the same");
profile.getTextures().setSkin(SKIN); profile.getTextures().setSkin(SKIN);
Assert.assertEquals("Skin model was not reset by skin change", PlayerTextures.SkinModel.CLASSIC, profile.getTextures().getSkinModel()); assertEquals(PlayerTextures.SkinModel.CLASSIC, profile.getTextures().getSkinModel(), "Skin model was not reset by skin change");
} }
@Test @Test
@ -171,35 +171,35 @@ public class PlayerProfileTest {
CraftPlayerProfile profile = buildPlayerProfile(); CraftPlayerProfile profile = buildPlayerProfile();
CraftPlayerProfile profile2 = new CraftPlayerProfile(new GameProfile(UNIQUE_ID, NAME)); CraftPlayerProfile profile2 = new CraftPlayerProfile(new GameProfile(UNIQUE_ID, NAME));
Assert.assertTrue("profile has no textures", !profile.getTextures().isEmpty()); assertFalse(profile.getTextures().isEmpty(), "profile has no textures");
Assert.assertTrue("profile2 has textures", profile2.getTextures().isEmpty()); assertTrue(profile2.getTextures().isEmpty(), "profile2 has textures");
profile2.setTextures(profile.getTextures()); profile2.setTextures(profile.getTextures());
Assert.assertTrue("profile2 has no textures", !profile2.getTextures().isEmpty()); assertFalse(profile2.getTextures().isEmpty(), "profile2 has no textures");
Assert.assertEquals("copied profile textures are not the same", profile.getTextures(), profile2.getTextures()); assertEquals(profile.getTextures(), profile2.getTextures(), "copied profile textures are not the same");
profile2.setTextures(null); profile2.setTextures(null);
Assert.assertTrue("cleared profile2 has textures", profile2.getTextures().isEmpty()); assertTrue(profile2.getTextures().isEmpty(), "cleared profile2 has textures");
Assert.assertTrue("cleared profile2 has textures timestamp", profile2.getTextures().getTimestamp() == 0L); assertEquals(0L, profile2.getTextures().getTimestamp(), "cleared profile2 has textures timestamp");
Assert.assertTrue("cleared profile2 has signed textures", !profile2.getTextures().isSigned()); assertFalse(profile2.getTextures().isSigned(), "cleared profile2 has signed textures");
} }
@Test @Test
public void testClearTextures() { public void testClearTextures() {
CraftPlayerProfile profile = buildPlayerProfile(); CraftPlayerProfile profile = buildPlayerProfile();
Assert.assertTrue("profile has no textures", !profile.getTextures().isEmpty()); assertFalse(profile.getTextures().isEmpty(), "profile has no textures");
profile.getTextures().clear(); profile.getTextures().clear();
Assert.assertTrue("cleared profile has textures", profile.getTextures().isEmpty()); assertTrue(profile.getTextures().isEmpty(), "cleared profile has textures");
Assert.assertTrue("cleared profile has textures timestamp", profile.getTextures().getTimestamp() == 0L); assertEquals(0L, profile.getTextures().getTimestamp(), "cleared profile has textures timestamp");
Assert.assertTrue("cleared profile has signed textures", !profile.getTextures().isSigned()); assertFalse(profile.getTextures().isSigned(), "cleared profile has signed textures");
} }
@Test @Test
public void testCustomSkin() { public void testCustomSkin() {
CraftPlayerProfile profile = new CraftPlayerProfile(UNIQUE_ID, NAME); CraftPlayerProfile profile = new CraftPlayerProfile(UNIQUE_ID, NAME);
profile.getTextures().setSkin(SKIN); profile.getTextures().setSkin(SKIN);
Assert.assertEquals("profile with custom skin does not match expected value", COMPACT_VALUE, profile.getTextures().getProperty().value()); assertEquals(COMPACT_VALUE, profile.getTextures().getProperty().value(), "profile with custom skin does not match expected value");
} }
@Test @Test
@ -211,35 +211,35 @@ public class PlayerProfileTest {
CraftPlayerProfile profile5 = new CraftPlayerProfile(UNIQUE_ID, null); CraftPlayerProfile profile5 = new CraftPlayerProfile(UNIQUE_ID, null);
CraftPlayerProfile profile6 = new CraftPlayerProfile(null, NAME); CraftPlayerProfile profile6 = new CraftPlayerProfile(null, NAME);
Assert.assertEquals("profile1 and profile2 are not equal", profile1, profile2); assertEquals(profile1, profile2, "profile1 and profile2 are not equal");
Assert.assertEquals("profile3 and profile4 are not equal", profile3, profile4); assertEquals(profile3, profile4, "profile3 and profile4 are not equal");
Assert.assertNotEquals("profile1 and profile3 are equal", profile1, profile3); assertNotEquals(profile1, profile3, "profile1 and profile3 are equal");
Assert.assertNotEquals("profile4 and profile5 are equal", profile4, profile5); assertNotEquals(profile4, profile5, "profile4 and profile5 are equal");
Assert.assertNotEquals("profile4 and profile6 are equal", profile4, profile6); assertNotEquals(profile4, profile6, "profile4 and profile6 are equal");
} }
@Test @Test
public void testTexturesEquals() { public void testTexturesEquals() {
CraftPlayerProfile profile1 = buildPlayerProfile(); CraftPlayerProfile profile1 = buildPlayerProfile();
CraftPlayerProfile profile2 = buildPlayerProfile(); CraftPlayerProfile profile2 = buildPlayerProfile();
Assert.assertEquals("Profile textures are not equal", profile1.getTextures(), profile2.getTextures()); assertEquals(profile1.getTextures(), profile2.getTextures(), "Profile textures are not equal");
profile1.getTextures().setCape(null); profile1.getTextures().setCape(null);
Assert.assertNotEquals("Modified profile textures are still equal", profile1.getTextures(), profile2.getTextures()); assertNotEquals(profile1.getTextures(), profile2.getTextures(), "Modified profile textures are still equal");
profile2.getTextures().setCape(null); profile2.getTextures().setCape(null);
Assert.assertEquals("Modified profile textures are not equal", profile1.getTextures(), profile2.getTextures()); assertEquals(profile1.getTextures(), profile2.getTextures(), "Modified profile textures are not equal");
} }
@Test @Test
public void testClone() { public void testClone() {
PlayerProfile profile = buildPlayerProfile(); PlayerProfile profile = buildPlayerProfile();
PlayerProfile copy = profile.clone(); PlayerProfile copy = profile.clone();
Assert.assertEquals("profile and copy are not equal", profile, copy); assertEquals(profile, copy, "profile and copy are not equal");
// New copies are independent (don't affect the original profile): // New copies are independent (don't affect the original profile):
copy.getTextures().setSkin(null); copy.getTextures().setSkin(null);
Assert.assertEquals("copy is not independent", SKIN, profile.getTextures().getSkin()); assertEquals(SKIN, profile.getTextures().getSkin(), "copy is not independent");
} }
@Test @Test
@ -255,7 +255,7 @@ public class PlayerProfileTest {
configuration = new YamlConfiguration(); configuration = new YamlConfiguration();
configuration.loadFromString(saved); configuration.loadFromString(saved);
Assert.assertTrue(configuration.contains("test")); assertTrue(configuration.contains("test"));
Assert.assertEquals("Profiles are not equal", playerProfile, configuration.get("test")); assertEquals(playerProfile, configuration.get("test"), "Profiles are not equal");
} }
} }

View File

@ -1,11 +1,11 @@
package org.bukkit.craftbukkit.util; package org.bukkit.craftbukkit.util;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import net.minecraft.network.chat.ComponentContents; import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.network.chat.IChatMutableComponent; import net.minecraft.network.chat.IChatMutableComponent;
import net.minecraft.network.chat.contents.LiteralContents; import net.minecraft.network.chat.contents.LiteralContents;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class CraftChatMessageTest { public class CraftChatMessageTest {
@ -35,7 +35,7 @@ public class CraftChatMessageTest {
// dont retain line returns multiple components // dont retain line returns multiple components
IChatBaseComponent[] components = CraftChatMessage.fromString("Hello§0\n§rFoo\n§5Test"); IChatBaseComponent[] components = CraftChatMessage.fromString("Hello§0\n§rFoo\n§5Test");
assertEquals("Has 3 components", 3, components.length); assertEquals(3, components.length, "Has 3 components");
assertEquals("Hello§0", CraftChatMessage.fromComponent(components[0])); assertEquals("Hello§0", CraftChatMessage.fromComponent(components[0]));
assertEquals(/*§r*/"Foo", CraftChatMessage.fromComponent(components[1])); assertEquals(/*§r*/"Foo", CraftChatMessage.fromComponent(components[1]));
assertEquals("§5Test", CraftChatMessage.fromComponent(components[2])); assertEquals("§5Test", CraftChatMessage.fromComponent(components[2]));
@ -85,14 +85,14 @@ public class CraftChatMessageTest {
private void testString(String input, String expected, boolean keepNewLines) { private void testString(String input, String expected, boolean keepNewLines) {
IChatBaseComponent cmp = CraftChatMessage.fromString(input, keepNewLines)[0]; IChatBaseComponent cmp = CraftChatMessage.fromString(input, keepNewLines)[0];
String actual = CraftChatMessage.fromComponent(cmp); String actual = CraftChatMessage.fromComponent(cmp);
assertEquals("\nComponent: " + cmp + "\n", expected, actual); assertEquals(expected, actual, "\nComponent: " + cmp + "\n");
} }
private void testPlainString(String expected) { private void testPlainString(String expected) {
IChatBaseComponent component = CraftChatMessage.fromString(expected, false, true)[0]; IChatBaseComponent component = CraftChatMessage.fromString(expected, false, true)[0];
String actual = CraftChatMessage.fromComponent(component); String actual = CraftChatMessage.fromComponent(component);
assertEquals("fromComponent does not match input: " + component, expected, actual); assertEquals(expected, actual, "fromComponent does not match input: " + component);
assertTrue("Non-plain component: " + component, !containsNonPlainComponent(component)); assertFalse(containsNonPlainComponent(component), "Non-plain component: " + component);
} }
private boolean containsNonPlainComponent(IChatBaseComponent component) { private boolean containsNonPlainComponent(IChatBaseComponent component) {
@ -106,10 +106,10 @@ public class CraftChatMessageTest {
private void testComponent(String expected, IChatBaseComponent cmp) { private void testComponent(String expected, IChatBaseComponent cmp) {
String actual = CraftChatMessage.fromComponent(cmp); String actual = CraftChatMessage.fromComponent(cmp);
assertEquals("\nComponent: " + cmp + "\n", expected, actual); assertEquals(expected, actual, "\nComponent: " + cmp + "\n");
IChatBaseComponent expectedCmp = CraftChatMessage.fromString(expected, true)[0]; IChatBaseComponent expectedCmp = CraftChatMessage.fromString(expected, true)[0];
String actualExpectedCmp = CraftChatMessage.fromComponent(expectedCmp); String actualExpectedCmp = CraftChatMessage.fromComponent(expectedCmp);
assertEquals("\nComponent: " + expectedCmp + "\n", expected, actualExpectedCmp); assertEquals(expected, actualExpectedCmp, "\nComponent: " + expectedCmp + "\n");
} }
} }

View File

@ -1,13 +1,13 @@
package org.bukkit.enchantments; package org.bukkit.enchantments;
import static org.junit.jupiter.api.Assertions.*;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.enchantment.EnchantmentSlotType; import net.minecraft.world.item.enchantment.EnchantmentSlotType;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftMagicNumbers;
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 EnchantmentTargetTest extends AbstractTestingBase { public class EnchantmentTargetTest extends AbstractTestingBase {
@ -27,7 +27,7 @@ public class EnchantmentTargetTest extends AbstractTestingBase {
break; break;
} }
Assert.assertNotNull("No bukkit target for slot " + nmsSlot, bukkitTarget); assertNotNull(bukkitTarget, "No bukkit target for slot " + nmsSlot);
for (Item item : BuiltInRegistries.ITEM) { for (Item item : BuiltInRegistries.ITEM) {
Material material = CraftMagicNumbers.getMaterial(item); Material material = CraftMagicNumbers.getMaterial(item);
@ -35,7 +35,7 @@ public class EnchantmentTargetTest extends AbstractTestingBase {
boolean nms = nmsSlot.canEnchant(item); boolean nms = nmsSlot.canEnchant(item);
boolean bukkit = bukkitTarget.includes(material); boolean bukkit = bukkitTarget.includes(material);
Assert.assertEquals("Slot mismatch for " + bukkitTarget + " and " + material, nms, bukkit); assertEquals(nms, bukkit, "Slot mismatch for " + bukkitTarget + " and " + material);
} }
} }
} }

View File

@ -3,7 +3,7 @@ package org.bukkit.entity;
import net.minecraft.world.entity.vehicle.EntityBoat; import net.minecraft.world.entity.vehicle.EntityBoat;
import org.bukkit.craftbukkit.entity.CraftBoat; import org.bukkit.craftbukkit.entity.CraftBoat;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class BoatTest extends AbstractTestingBase { public class BoatTest extends AbstractTestingBase {

View File

@ -1,9 +1,9 @@
package org.bukkit.entity; package org.bukkit.entity;
import static org.junit.jupiter.api.Assertions.*;
import net.minecraft.world.entity.boss.enderdragon.phases.DragonControllerPhase; import net.minecraft.world.entity.boss.enderdragon.phases.DragonControllerPhase;
import org.bukkit.craftbukkit.entity.CraftEnderDragon; import org.bukkit.craftbukkit.entity.CraftEnderDragon;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class EnderDragonPhaseTest { public class EnderDragonPhaseTest {
@ -11,38 +11,38 @@ public class EnderDragonPhaseTest {
public void testNotNull() { public void testNotNull() {
for (EnderDragon.Phase phase : EnderDragon.Phase.values()) { for (EnderDragon.Phase phase : EnderDragon.Phase.values()) {
DragonControllerPhase dragonControllerPhase = CraftEnderDragon.getMinecraftPhase(phase); DragonControllerPhase dragonControllerPhase = CraftEnderDragon.getMinecraftPhase(phase);
Assert.assertNotNull(phase.name(), dragonControllerPhase); assertNotNull(dragonControllerPhase, phase.name());
Assert.assertNotNull(phase.name(), CraftEnderDragon.getBukkitPhase(dragonControllerPhase)); assertNotNull(CraftEnderDragon.getBukkitPhase(dragonControllerPhase), phase.name());
} }
} }
@Test @Test
public void testBukkitToMinecraft() { public void testBukkitToMinecraft() {
Assert.assertEquals("CIRCLING", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.CIRCLING), DragonControllerPhase.HOLDING_PATTERN); assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.CIRCLING), DragonControllerPhase.HOLDING_PATTERN, "CIRCLING");
Assert.assertEquals("STRAFING", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.STRAFING), DragonControllerPhase.STRAFE_PLAYER); assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.STRAFING), DragonControllerPhase.STRAFE_PLAYER, "STRAFING");
Assert.assertEquals("FLY_TO_PORTAL", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.FLY_TO_PORTAL), DragonControllerPhase.LANDING_APPROACH); assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.FLY_TO_PORTAL), DragonControllerPhase.LANDING_APPROACH, "FLY_TO_PORTAL");
Assert.assertEquals("LAND_ON_PORTAL", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.LAND_ON_PORTAL), DragonControllerPhase.LANDING); assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.LAND_ON_PORTAL), DragonControllerPhase.LANDING, "LAND_ON_PORTAL");
Assert.assertEquals("LEAVE_PORTAL", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.LEAVE_PORTAL), DragonControllerPhase.TAKEOFF); assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.LEAVE_PORTAL), DragonControllerPhase.TAKEOFF, "LEAVE_PORTAL");
Assert.assertEquals("BREATH_ATTACK", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.BREATH_ATTACK), DragonControllerPhase.SITTING_FLAMING); assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.BREATH_ATTACK), DragonControllerPhase.SITTING_FLAMING, "BREATH_ATTACK");
Assert.assertEquals("SEARCH_FOR_BREATH_ATTACK_TARGET", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.SEARCH_FOR_BREATH_ATTACK_TARGET), DragonControllerPhase.SITTING_SCANNING); assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.SEARCH_FOR_BREATH_ATTACK_TARGET), DragonControllerPhase.SITTING_SCANNING, "SEARCH_FOR_BREATH_ATTACK_TARGET");
Assert.assertEquals("ROAR_BEFORE_ATTACK", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.ROAR_BEFORE_ATTACK), DragonControllerPhase.SITTING_ATTACKING); assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.ROAR_BEFORE_ATTACK), DragonControllerPhase.SITTING_ATTACKING, "ROAR_BEFORE_ATTACK");
Assert.assertEquals("CHARGE_PLAYER", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.CHARGE_PLAYER), DragonControllerPhase.CHARGING_PLAYER); assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.CHARGE_PLAYER), DragonControllerPhase.CHARGING_PLAYER, "CHARGE_PLAYER");
Assert.assertEquals("DYING", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.DYING), DragonControllerPhase.DYING); assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.DYING), DragonControllerPhase.DYING, "DYING");
Assert.assertEquals("HOVER", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.HOVER), DragonControllerPhase.HOVERING); assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.HOVER), DragonControllerPhase.HOVERING, "HOVER");
} }
@Test @Test
public void testMinecraftToBukkit() { public void testMinecraftToBukkit() {
Assert.assertEquals("CIRCLING", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.HOLDING_PATTERN), EnderDragon.Phase.CIRCLING); assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.HOLDING_PATTERN), EnderDragon.Phase.CIRCLING, "CIRCLING");
Assert.assertEquals("STRAFING", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.STRAFE_PLAYER), EnderDragon.Phase.STRAFING); assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.STRAFE_PLAYER), EnderDragon.Phase.STRAFING, "STRAFING");
Assert.assertEquals("FLY_TO_PORTAL", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.LANDING_APPROACH), EnderDragon.Phase.FLY_TO_PORTAL); assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.LANDING_APPROACH), EnderDragon.Phase.FLY_TO_PORTAL, "FLY_TO_PORTAL");
Assert.assertEquals("LAND_ON_PORTAL", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.LANDING), EnderDragon.Phase.LAND_ON_PORTAL); assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.LANDING), EnderDragon.Phase.LAND_ON_PORTAL, "LAND_ON_PORTAL");
Assert.assertEquals("LEAVE_PORTAL", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.TAKEOFF), EnderDragon.Phase.LEAVE_PORTAL); assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.TAKEOFF), EnderDragon.Phase.LEAVE_PORTAL, "LEAVE_PORTAL");
Assert.assertEquals("BREATH_ATTACK", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.SITTING_FLAMING), EnderDragon.Phase.BREATH_ATTACK); assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.SITTING_FLAMING), EnderDragon.Phase.BREATH_ATTACK, "BREATH_ATTACK");
Assert.assertEquals("SEARCH_FOR_BREATH_ATTACK_TARGET", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.SITTING_SCANNING), EnderDragon.Phase.SEARCH_FOR_BREATH_ATTACK_TARGET); assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.SITTING_SCANNING), EnderDragon.Phase.SEARCH_FOR_BREATH_ATTACK_TARGET, "SEARCH_FOR_BREATH_ATTACK_TARGET");
Assert.assertEquals("ROAR_BEFORE_ATTACK", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.SITTING_ATTACKING), EnderDragon.Phase.ROAR_BEFORE_ATTACK); assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.SITTING_ATTACKING), EnderDragon.Phase.ROAR_BEFORE_ATTACK, "ROAR_BEFORE_ATTACK");
Assert.assertEquals("CHARGE_PLAYER", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.CHARGING_PLAYER), EnderDragon.Phase.CHARGE_PLAYER); assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.CHARGING_PLAYER), EnderDragon.Phase.CHARGE_PLAYER, "CHARGE_PLAYER");
Assert.assertEquals("DYING", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.DYING), EnderDragon.Phase.DYING); assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.DYING), EnderDragon.Phase.DYING, "DYING");
Assert.assertEquals("HOVER", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.HOVERING), EnderDragon.Phase.HOVER); assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.HOVERING), EnderDragon.Phase.HOVER, "HOVER");
} }
} }

View File

@ -1,5 +1,6 @@
package org.bukkit.entity; package org.bukkit.entity;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -7,8 +8,7 @@ import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.MinecraftKey; import net.minecraft.resources.MinecraftKey;
import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.entity.EntityTypes;
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 EntityTypesTest extends AbstractTestingBase { public class EntityTypesTest extends AbstractTestingBase {
@ -20,12 +20,12 @@ public class EntityTypesTest extends AbstractTestingBase {
MinecraftKey key = EntityTypes.getKey(nms); MinecraftKey key = EntityTypes.getKey(nms);
EntityType bukkit = EntityType.fromName(key.getPath()); EntityType bukkit = EntityType.fromName(key.getPath());
Assert.assertNotNull("Missing nms->bukkit " + key, bukkit); assertNotNull(bukkit, "Missing nms->bukkit " + key);
Assert.assertTrue("Duplicate entity nms->" + bukkit, allBukkit.remove(bukkit)); assertTrue(allBukkit.remove(bukkit), "Duplicate entity nms->" + bukkit);
} }
Assert.assertTrue("Unmapped bukkit entities " + allBukkit, allBukkit.isEmpty()); assertTrue(allBukkit.isEmpty(), "Unmapped bukkit entities " + allBukkit);
} }
@Test @Test
@ -33,7 +33,7 @@ public class EntityTypesTest extends AbstractTestingBase {
for (EntityType entityType : EntityType.values()) { for (EntityType entityType : EntityType.values()) {
// Currently EntityType#getTranslationKey has a validation for null name then for test skip this and check correct names. // Currently EntityType#getTranslationKey has a validation for null name then for test skip this and check correct names.
if (entityType.getName() != null) { if (entityType.getName() != null) {
Assert.assertNotNull("Nulllable translation key for " + entityType, entityType.getTranslationKey()); assertNotNull(entityType.getTranslationKey(), "Nulllable translation key for " + entityType);
} }
} }
} }

View File

@ -1,9 +1,9 @@
package org.bukkit.entity; package org.bukkit.entity;
import static org.junit.jupiter.api.Assertions.*;
import net.minecraft.world.entity.animal.EntityPanda; import net.minecraft.world.entity.animal.EntityPanda;
import org.bukkit.craftbukkit.entity.CraftPanda; import org.bukkit.craftbukkit.entity.CraftPanda;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class PandaGeneTest { public class PandaGeneTest {
@ -12,9 +12,9 @@ public class PandaGeneTest {
for (Panda.Gene gene : Panda.Gene.values()) { for (Panda.Gene gene : Panda.Gene.values()) {
EntityPanda.Gene nms = CraftPanda.toNms(gene); EntityPanda.Gene nms = CraftPanda.toNms(gene);
Assert.assertNotNull("NMS gene null for " + gene, nms); assertNotNull(nms, "NMS gene null for " + gene);
Assert.assertEquals("Recessive status did not match " + gene, gene.isRecessive(), nms.isRecessive()); assertEquals(gene.isRecessive(), nms.isRecessive(), "Recessive status did not match " + gene);
Assert.assertEquals("Gene did not convert back " + gene, gene, CraftPanda.fromNms(nms)); assertEquals(gene, CraftPanda.fromNms(nms), "Gene did not convert back " + gene);
} }
} }
@ -23,9 +23,9 @@ public class PandaGeneTest {
for (EntityPanda.Gene gene : EntityPanda.Gene.values()) { for (EntityPanda.Gene gene : EntityPanda.Gene.values()) {
Panda.Gene bukkit = CraftPanda.fromNms(gene); Panda.Gene bukkit = CraftPanda.fromNms(gene);
Assert.assertNotNull("Bukkit gene null for " + gene, bukkit); assertNotNull(bukkit, "Bukkit gene null for " + gene);
Assert.assertEquals("Recessive status did not match " + gene, gene.isRecessive(), bukkit.isRecessive()); assertEquals(gene.isRecessive(), bukkit.isRecessive(), "Recessive status did not match " + gene);
Assert.assertEquals("Gene did not convert back " + gene, gene, CraftPanda.toNms(bukkit)); assertEquals(gene, CraftPanda.toNms(bukkit), "Gene did not convert back " + gene);
} }
} }
} }

View File

@ -2,7 +2,7 @@ package org.bukkit.entity;
import net.minecraft.world.entity.EnumCreatureType; import net.minecraft.world.entity.EnumCreatureType;
import org.bukkit.craftbukkit.util.CraftSpawnCategory; import org.bukkit.craftbukkit.util.CraftSpawnCategory;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class SpawnCategoryTest { public class SpawnCategoryTest {

View File

@ -1,11 +1,11 @@
package org.bukkit.entity; package org.bukkit.entity;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.craftbukkit.entity.CraftTropicalFish; import org.bukkit.craftbukkit.entity.CraftTropicalFish;
import org.bukkit.entity.TropicalFish.Pattern; import org.bukkit.entity.TropicalFish.Pattern;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class TropicalFishTest { public class TropicalFishTest {
@ -36,9 +36,9 @@ public class TropicalFishTest {
} }
private void testVariant(int variant, DyeColor bodyColor, DyeColor patternColor, Pattern pattern) { private void testVariant(int variant, DyeColor bodyColor, DyeColor patternColor, Pattern pattern) {
assertThat("variant write", CraftTropicalFish.getData(patternColor, bodyColor, pattern), is(variant)); assertThat(CraftTropicalFish.getData(patternColor, bodyColor, pattern), is(variant), "variant write");
assertThat("pattern colour read", CraftTropicalFish.getPatternColor(variant), is(patternColor)); assertThat(CraftTropicalFish.getPatternColor(variant), is(patternColor), "pattern colour read");
assertThat("body colour read", CraftTropicalFish.getBodyColor(variant), is(bodyColor)); assertThat(CraftTropicalFish.getBodyColor(variant), is(bodyColor), "body colour read");
assertThat("pattern read", CraftTropicalFish.getPattern(variant), is(pattern)); assertThat(CraftTropicalFish.getPattern(variant), is(pattern), "pattern read");
} }
} }

View File

@ -1,57 +1,57 @@
package org.bukkit.entity.memory; package org.bukkit.entity.memory;
import static org.junit.jupiter.api.Assertions.*;
import net.minecraft.core.GlobalPos; import net.minecraft.core.GlobalPos;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.entity.ai.memory.MemoryModuleType; import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.craftbukkit.entity.memory.CraftMemoryKey; import org.bukkit.craftbukkit.entity.memory.CraftMemoryKey;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Assert; import org.junit.jupiter.api.Disabled;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class CraftMemoryKeyTest extends AbstractTestingBase { public class CraftMemoryKeyTest extends AbstractTestingBase {
@Test @Test
public void shouldConvertBukkitHomeKeyToNMSRepresentation() { public void shouldConvertBukkitHomeKeyToNMSRepresentation() {
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.HOME); MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.HOME);
Assert.assertEquals("MemoryModuleType should be HOME", MemoryModuleType.HOME, nmsHomeKey); assertEquals(MemoryModuleType.HOME, nmsHomeKey, "MemoryModuleType should be HOME");
} }
@Test @Test
public void shouldConvertBukkitJobSiteKeyToNMSRepresentation() { public void shouldConvertBukkitJobSiteKeyToNMSRepresentation() {
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.JOB_SITE); MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.JOB_SITE);
Assert.assertEquals("MemoryModuleType should be JOB_SITE", MemoryModuleType.JOB_SITE, nmsHomeKey); assertEquals(MemoryModuleType.JOB_SITE, nmsHomeKey, "MemoryModuleType should be JOB_SITE");
} }
@Test @Test
public void shouldConvertBukkitMeetingPointKeyToNMSRepresentation() { public void shouldConvertBukkitMeetingPointKeyToNMSRepresentation() {
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.MEETING_POINT); MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.MEETING_POINT);
Assert.assertEquals("MemoryModuleType should be MEETING_POINT", MemoryModuleType.MEETING_POINT, nmsHomeKey); assertEquals(MemoryModuleType.MEETING_POINT, nmsHomeKey, "MemoryModuleType should be MEETING_POINT");
} }
@Test @Test
public void shouldConvertNMSHomeKeyToBukkitRepresentation() { public void shouldConvertNMSHomeKeyToBukkitRepresentation() {
MemoryKey<Location> bukkitHomeKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.HOME); MemoryKey<Location> bukkitHomeKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.HOME);
Assert.assertEquals("MemoryModuleType should be HOME", MemoryKey.HOME, bukkitHomeKey); assertEquals(MemoryKey.HOME, bukkitHomeKey, "MemoryModuleType should be HOME");
} }
@Test @Test
public void shouldConvertNMSJobSiteKeyToBukkitRepresentation() { public void shouldConvertNMSJobSiteKeyToBukkitRepresentation() {
MemoryKey<Location> bukkitJobSiteKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.JOB_SITE); MemoryKey<Location> bukkitJobSiteKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.JOB_SITE);
Assert.assertEquals("MemoryKey should be JOB_SITE", MemoryKey.JOB_SITE, bukkitJobSiteKey); assertEquals(MemoryKey.JOB_SITE, bukkitJobSiteKey, "MemoryKey should be JOB_SITE");
} }
@Test @Test
public void shouldConvertNMSMeetingPointKeyToBukkitRepresentation() { public void shouldConvertNMSMeetingPointKeyToBukkitRepresentation() {
MemoryKey<Location> bukkitHomeKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.MEETING_POINT); MemoryKey<Location> bukkitHomeKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.MEETING_POINT);
Assert.assertEquals("MemoryKey should be MEETING_POINT", MemoryKey.MEETING_POINT, bukkitHomeKey); assertEquals(MemoryKey.MEETING_POINT, bukkitHomeKey, "MemoryKey should be MEETING_POINT");
} }
@Test @Test
public void shouldReturnNullWhenBukkitRepresentationOfKeyisNotAvailable() { public void shouldReturnNullWhenBukkitRepresentationOfKeyisNotAvailable() {
MemoryKey bukkitNoKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.NEAREST_LIVING_ENTITIES); MemoryKey bukkitNoKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.NEAREST_LIVING_ENTITIES);
Assert.assertNull("MemoryModuleType should be null", bukkitNoKey); assertNull(bukkitNoKey, "MemoryModuleType should be null");
} }
@Test @Test
@ -59,18 +59,18 @@ public class CraftMemoryKeyTest extends AbstractTestingBase {
for (MemoryModuleType<?> memoryModuleType : BuiltInRegistries.MEMORY_MODULE_TYPE) { for (MemoryModuleType<?> memoryModuleType : BuiltInRegistries.MEMORY_MODULE_TYPE) {
if (!memoryModuleType.getCodec().isPresent()) { if (!memoryModuleType.getCodec().isPresent()) {
MemoryKey bukkitNoKey = CraftMemoryKey.minecraftToBukkit(memoryModuleType); MemoryKey bukkitNoKey = CraftMemoryKey.minecraftToBukkit(memoryModuleType);
Assert.assertNull("MemoryModuleType should be null", bukkitNoKey); assertNull(bukkitNoKey, "MemoryModuleType should be null");
} }
} }
} }
@Test @Test
@Ignore("Unit type not yet implemented") @Disabled("Unit type not yet implemented")
public void shouldReturnAnInstanceOfMemoryKeyWhenBukkitRepresentationOfKeyisAvailableAndSerializerIsPresent() { public void shouldReturnAnInstanceOfMemoryKeyWhenBukkitRepresentationOfKeyisAvailableAndSerializerIsPresent() {
for (MemoryModuleType<?> memoryModuleType : BuiltInRegistries.MEMORY_MODULE_TYPE) { for (MemoryModuleType<?> memoryModuleType : BuiltInRegistries.MEMORY_MODULE_TYPE) {
if (memoryModuleType.getCodec().isPresent()) { if (memoryModuleType.getCodec().isPresent()) {
MemoryKey bukkitNoKey = CraftMemoryKey.minecraftToBukkit(memoryModuleType); MemoryKey bukkitNoKey = CraftMemoryKey.minecraftToBukkit(memoryModuleType);
Assert.assertNotNull("MemoryModuleType should not be null " + BuiltInRegistries.MEMORY_MODULE_TYPE.getKey(memoryModuleType), bukkitNoKey); assertNotNull(bukkitNoKey, "MemoryModuleType should not be null " + BuiltInRegistries.MEMORY_MODULE_TYPE.getKey(memoryModuleType));
} }
} }
} }

View File

@ -1,5 +1,6 @@
package org.bukkit.generator.structure; package org.bukkit.generator.structure;
import static org.junit.jupiter.api.Assertions.*;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import net.minecraft.core.IRegistry; import net.minecraft.core.IRegistry;
@ -9,8 +10,7 @@ import org.bukkit.NamespacedKey;
import org.bukkit.Registry; import org.bukkit.Registry;
import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey;
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 StructureTest extends AbstractTestingBase { public class StructureTest extends AbstractTestingBase {
@ -25,7 +25,7 @@ public class StructureTest extends AbstractTestingBase {
} }
String name = field.getName(); String name = field.getName();
Assert.assertNotNull("No structure for field name " + name, Registry.STRUCTURE.get(NamespacedKey.fromString(name.toLowerCase()))); assertNotNull(Registry.STRUCTURE.get(NamespacedKey.fromString(name.toLowerCase())), "No structure for field name " + name);
} }
} }
@ -38,13 +38,13 @@ public class StructureTest extends AbstractTestingBase {
try { try {
Structure bukkit = (Structure) Structure.class.getField(minecraftKey.getPath().toUpperCase()).get(null); Structure bukkit = (Structure) Structure.class.getField(minecraftKey.getPath().toUpperCase()).get(null);
Assert.assertEquals("Keys are not the same for " + minecraftKey, minecraftKey, CraftNamespacedKey.toMinecraft(bukkit.getKey())); assertEquals(minecraftKey, CraftNamespacedKey.toMinecraft(bukkit.getKey()), "Keys are not the same for " + minecraftKey);
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
Assert.fail("No Bukkit default structure for " + minecraftKey); fail("No Bukkit default structure for " + minecraftKey);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
Assert.fail("Bukkit field is not access able for " + minecraftKey); fail("Bukkit field is not access able for " + minecraftKey);
} catch (ClassCastException e) { } catch (ClassCastException e) {
Assert.fail("Bukkit field is not of type structure for" + minecraftKey); fail("Bukkit field is not of type structure for" + minecraftKey);
} }
} }
} }

View File

@ -1,5 +1,6 @@
package org.bukkit.generator.structure; package org.bukkit.generator.structure;
import static org.junit.jupiter.api.Assertions.*;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
@ -8,8 +9,7 @@ import org.bukkit.NamespacedKey;
import org.bukkit.Registry; import org.bukkit.Registry;
import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey;
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 StructureTypeTest extends AbstractTestingBase { public class StructureTypeTest extends AbstractTestingBase {
@ -24,7 +24,7 @@ public class StructureTypeTest extends AbstractTestingBase {
} }
String name = field.getName(); String name = field.getName();
Assert.assertNotNull("No structure type for field name " + name, Registry.STRUCTURE_TYPE.get(NamespacedKey.fromString(name.toLowerCase()))); assertNotNull(Registry.STRUCTURE_TYPE.get(NamespacedKey.fromString(name.toLowerCase())), "No enchantment for field name " + name);
} }
} }
@ -36,13 +36,13 @@ public class StructureTypeTest extends AbstractTestingBase {
try { try {
StructureType bukkit = (StructureType) StructureType.class.getField(minecraftKey.getPath().toUpperCase()).get(null); StructureType bukkit = (StructureType) StructureType.class.getField(minecraftKey.getPath().toUpperCase()).get(null);
Assert.assertEquals("Keys are not the same for " + minecraftKey, minecraftKey, CraftNamespacedKey.toMinecraft(bukkit.getKey())); assertEquals(minecraftKey, CraftNamespacedKey.toMinecraft(bukkit.getKey()), "Keys are not the same for " + minecraftKey);
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
Assert.fail("No Bukkit default structure type for " + minecraftKey); fail("No Bukkit default enchantment for " + minecraftKey);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
Assert.fail("Bukkit field is not access able for " + minecraftKey); fail("Bukkit field is not access able for " + minecraftKey);
} catch (ClassCastException e) { } catch (ClassCastException e) {
Assert.fail("Bukkit field is not of type structure type for" + minecraftKey); fail("Bukkit field is not of type enchantment for" + minecraftKey);
} }
} }
} }

View File

@ -1,14 +1,14 @@
package org.bukkit.map; package org.bukkit.map;
import static org.junit.jupiter.api.Assertions.*;
import java.awt.Color; import java.awt.Color;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.minecraft.world.level.material.MaterialMapColor; import net.minecraft.world.level.material.MaterialMapColor;
import org.bukkit.craftbukkit.map.CraftMapColorCache; import org.bukkit.craftbukkit.map.CraftMapColorCache;
import org.junit.Assert; import org.junit.jupiter.api.Disabled;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class MapTest { public class MapTest {
@ -59,10 +59,10 @@ public class MapTest {
} }
} }
} }
Assert.assertFalse(fail); assertFalse(fail);
} }
@Ignore("Test takes around 25 seconds, should be run by changes to the map color conversion") @Disabled("Test takes around 25 seconds, should be run by changes to the map color conversion")
@Test @Test
public void testMapColorCacheBuilding() throws ExecutionException, InterruptedException { public void testMapColorCacheBuilding() throws ExecutionException, InterruptedException {
CraftMapColorCache craftMapColorCache = new CraftMapColorCache(logger); CraftMapColorCache craftMapColorCache = new CraftMapColorCache(logger);
@ -72,7 +72,7 @@ public class MapTest {
for (int g = 0; g < 256; g++) { for (int g = 0; g < 256; g++) {
for (int b = 0; b < 256; b++) { for (int b = 0; b < 256; b++) {
Color color = new Color(r, g, b); Color color = new Color(r, g, b);
Assert.assertEquals(String.format("Incorrect matched color c(%s, %s, %s)", color.getRed(), color.getGreen(), color.getBlue()), MapPalette.matchColor(color), craftMapColorCache.matchColor(color)); assertEquals(MapPalette.matchColor(color), craftMapColorCache.matchColor(color), String.format("Incorrect matched color c(%s, %s, %s)", color.getRed(), color.getGreen(), color.getBlue()));
} }
} }
} }

View File

@ -1,6 +1,6 @@
package org.bukkit.potion; package org.bukkit.potion;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -11,7 +11,7 @@ import net.minecraft.world.effect.MobEffectList;
import net.minecraft.world.item.alchemy.PotionRegistry; import net.minecraft.world.item.alchemy.PotionRegistry;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType; import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class PotionTest extends AbstractTestingBase { public class PotionTest extends AbstractTestingBase {
@Test @Test
@ -21,10 +21,10 @@ public class PotionTest extends AbstractTestingBase {
List<MobEffect> eff = reg.getEffects(); List<MobEffect> eff = reg.getEffects();
if (eff.size() != 1) continue; if (eff.size() != 1) continue;
PotionEffectType type = CraftPotionEffectType.minecraftToBukkit(eff.get(0).getEffect()); PotionEffectType type = CraftPotionEffectType.minecraftToBukkit(eff.get(0).getEffect());
assertNotNull(String.valueOf(reg), type); assertNotNull(type, String.valueOf(reg));
PotionType enumType = PotionType.getByEffect(type); PotionType enumType = PotionType.getByEffect(type);
assertNotNull(type.getName(), enumType); assertNotNull(enumType, type.getName());
effects.put(enumType, enumType.name()); effects.put(enumType, enumType.name());
} }
@ -39,11 +39,11 @@ public class PotionTest extends AbstractTestingBase {
PotionEffectType bukkit = CraftPotionEffectType.minecraftToBukkit(nms); PotionEffectType bukkit = CraftPotionEffectType.minecraftToBukkit(nms);
assertNotNull("No Bukkit type for " + key, bukkit); assertNotNull(bukkit, "No Bukkit type for " + key);
assertFalse("No name for " + key, bukkit.getName().contains("UNKNOWN")); assertFalse(bukkit.getName().contains("UNKNOWN"), "No name for " + key);
PotionEffectType byName = PotionEffectType.getByName(bukkit.getName()); PotionEffectType byName = PotionEffectType.getByName(bukkit.getName());
assertEquals("Same type not returned by name " + key, bukkit, byName); assertEquals(bukkit, byName, "Same type not returned by name " + key);
} }
} }
} }

View File

@ -1,5 +1,6 @@
package org.bukkit.support; package org.bukkit.support;
import static org.junit.jupiter.api.Assertions.*;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.MoreExecutors;
import java.util.List; import java.util.List;
@ -24,7 +25,6 @@ import net.minecraft.world.level.biome.BiomeBase;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.junit.Assert;
/** /**
* If you are getting: java.lang.ExceptionInInitializerError * If you are getting: java.lang.ExceptionInInitializerError
@ -73,6 +73,6 @@ public abstract class AbstractTestingBase {
} }
} }
INVALIDATED_MATERIALS = builder.build(); INVALIDATED_MATERIALS = builder.build();
Assert.assertEquals("Expected 610 invalidated materials (got " + INVALIDATED_MATERIALS.size() + ")", 610, INVALIDATED_MATERIALS.size()); assertEquals(610, INVALIDATED_MATERIALS.size(), "Expected 610 invalidated materials (got " + INVALIDATED_MATERIALS.size() + ")");
} }
} }

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);
}
}