From 07002cbfcd0841fc0f902a15b16eac80a204c938 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sat, 23 Sep 2023 18:10:23 +1000 Subject: [PATCH] #1256: Update tests to JUnit 5 By: DerFrZocker --- paper-server/README.md | 2 +- paper-server/pom.xml | 16 +- .../src/test/java/org/bukkit/ArtTest.java | 21 +-- .../src/test/java/org/bukkit/BiomeTest.java | 8 +- .../org/bukkit/BlockDataConversionTest.java | 32 ++-- .../test/java/org/bukkit/BlockDataTest.java | 93 +++++----- .../src/test/java/org/bukkit/ChatTest.java | 13 +- .../test/java/org/bukkit/DyeColorsTest.java | 33 +--- .../test/java/org/bukkit/EnchantmentTest.java | 8 +- .../test/java/org/bukkit/GameEventTest.java | 6 +- .../test/java/org/bukkit/GameRuleTest.java | 28 +-- .../test/java/org/bukkit/LootTablesTest.java | 12 +- .../test/java/org/bukkit/MaterialTest.java | 9 +- .../test/java/org/bukkit/ParticleTest.java | 8 +- .../test/java/org/bukkit/PerMaterialTest.java | 162 +++++++++--------- .../test/java/org/bukkit/PerRegistryTest.java | 59 +++---- .../java/org/bukkit/PotionEffectTypeTest.java | 9 +- .../org/bukkit/RegistryConstantsTest.java | 12 +- .../src/test/java/org/bukkit/SoundTest.java | 13 +- .../bukkit/StatisticsAndAchievementsTest.java | 15 +- .../bukkit/block/banner/PatternTypeTest.java | 8 +- .../org/bukkit/craftbukkit/HeightMapTest.java | 8 +- .../craftbukkit/attribute/AttributeTest.java | 8 +- .../craftbukkit/block/BlockStateTest.java | 15 +- .../craftbukkit/generator/ChunkDataTest.java | 28 +-- .../inventory/CompositeSerialization.java | 6 +- .../DeprecatedItemMetaCustomValueTest.java | 26 +-- .../inventory/FactoryItemMaterialTest.java | 66 +++---- .../inventory/ItemMetaCloneTest.java | 9 +- .../ItemMetaImplementationOverrideTest.java | 37 ++-- .../craftbukkit/inventory/ItemMetaTest.java | 49 +++--- .../inventory/ItemStackBookTest.java | 12 +- .../ItemStackEnchantStorageTest.java | 12 +- .../ItemStackFireworkChargeTest.java | 12 +- .../inventory/ItemStackFireworkTest.java | 12 +- .../inventory/ItemStackLeatherTest.java | 12 +- .../ItemStackLoreEnchantmentTest.java | 12 +- .../inventory/ItemStackMapTest.java | 12 +- .../inventory/ItemStackPotionsTest.java | 12 +- .../inventory/ItemStackSkullTest.java | 12 +- .../craftbukkit/inventory/ItemStackTest.java | 145 ++++++++++++---- .../inventory/NMSCraftItemStackTest.java | 4 +- .../PersistentDataContainerTest.java | 26 +-- .../inventory/PlayerInventoryTest.java | 4 +- .../bukkit/craftbukkit/legacy/EvilTest.java | 12 +- .../bukkit/craftbukkit/legacy/LegacyTest.java | 28 +-- .../profile/PlayerProfileTest.java | 116 ++++++------- .../util/CraftChatMessageTest.java | 16 +- .../enchantments/EnchantmentTargetTest.java | 8 +- .../test/java/org/bukkit/entity/BoatTest.java | 2 +- .../bukkit/entity/EnderDragonPhaseTest.java | 52 +++--- .../org/bukkit/entity/EntityTypesTest.java | 12 +- .../java/org/bukkit/entity/PandaGeneTest.java | 16 +- .../org/bukkit/entity/SpawnCategoryTest.java | 2 +- .../org/bukkit/entity/TropicalFishTest.java | 12 +- .../entity/memory/CraftMemoryKeyTest.java | 26 +-- .../generator/structure/StructureTest.java | 14 +- .../structure/StructureTypeTest.java | 14 +- .../src/test/java/org/bukkit/map/MapTest.java | 12 +- .../java/org/bukkit/potion/PotionTest.java | 14 +- .../bukkit/support/AbstractTestingBase.java | 4 +- .../org/bukkit/support/MatcherAssert.java | 36 ++++ 62 files changed, 770 insertions(+), 732 deletions(-) create mode 100644 paper-server/src/test/java/org/bukkit/support/MatcherAssert.java diff --git a/paper-server/README.md b/paper-server/README.md index 3db2c7cfd1..f978223678 100644 --- a/paper-server/README.md +++ b/paper-server/README.md @@ -64,7 +64,7 @@ Code Requirements * Do not submit your personal changes to configuration files. * 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 will help to ensure the PR can be easily maintained over time and encourage the Spigot team to pull the PR. diff --git a/paper-server/pom.xml b/paper-server/pom.xml index c4755bb7d0..366cd781d8 100644 --- a/paper-server/pom.xml +++ b/paper-server/pom.xml @@ -217,6 +217,12 @@ json-simple 1.1.1 runtime + + + junit + junit + + org.xerial @@ -258,15 +264,15 @@ - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter + 5.10.0 test org.hamcrest - hamcrest-library - 1.3 + hamcrest + 2.2 test diff --git a/paper-server/src/test/java/org/bukkit/ArtTest.java b/paper-server/src/test/java/org/bukkit/ArtTest.java index f89e2d95a4..f317c7d509 100644 --- a/paper-server/src/test/java/org/bukkit/ArtTest.java +++ b/paper-server/src/test/java/org/bukkit/ArtTest.java @@ -1,7 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import com.google.common.collect.Lists; import java.util.Collections; import java.util.EnumMap; @@ -14,7 +15,7 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.world.entity.decoration.PaintingVariant; import org.bukkit.craftbukkit.CraftArt; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ArtTest extends AbstractTestingBase { private static final int UNIT_MULTIPLIER = 16; @@ -32,16 +33,16 @@ public class ArtTest extends AbstractTestingBase { Art subject = CraftArt.minecraftHolderToBukkit(enumArt); 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." + subject + "'s width", subject.getBlockWidth(), is(width)); - assertThat("Art." + subject + "'s height", subject.getBlockHeight(), is(height)); + assertThat(subject.getBlockWidth(), is(width), "Art." + subject + "'s width"); + assertThat(subject.getBlockHeight(), is(height), "Art." + subject + "'s height"); 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 @@ -49,8 +50,8 @@ public class ArtTest extends AbstractTestingBase { Map, Art> cache = new HashMap<>(); for (Art art : Art.values()) { Holder enumArt = CraftArt.bukkitToMinecraftHolder(art); - assertNotNull(art.name(), enumArt); - assertThat(art.name(), cache.put(enumArt, art), is(nullValue())); + assertNotNull(enumArt, art.name()); + assertThat(cache.put(enumArt, art), is(nullValue()), art.name()); } } @@ -59,8 +60,8 @@ public class ArtTest extends AbstractTestingBase { Map> cache = new EnumMap(Art.class); for (Holder enumArt : BuiltInRegistries.PAINTING_VARIANT.asHolderIdMap()) { Art art = CraftArt.minecraftHolderToBukkit(enumArt); - assertNotNull("Could not CraftArt.NotchToBukkit " + enumArt, art); - assertThat("Duplicate artwork " + enumArt, cache.put(art, enumArt), is(nullValue())); + assertNotNull(art, "Could not CraftArt.NotchToBukkit " + enumArt); + assertThat(cache.put(art, enumArt), is(nullValue()), "Duplicate artwork " + enumArt); } } } diff --git a/paper-server/src/test/java/org/bukkit/BiomeTest.java b/paper-server/src/test/java/org/bukkit/BiomeTest.java index e737bc5e48..2d8e51585b 100644 --- a/paper-server/src/test/java/org/bukkit/BiomeTest.java +++ b/paper-server/src/test/java/org/bukkit/BiomeTest.java @@ -1,11 +1,11 @@ package org.bukkit; +import static org.junit.jupiter.api.Assertions.*; import net.minecraft.world.level.biome.BiomeBase; import org.bukkit.block.Biome; import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BiomeTest extends AbstractTestingBase { @@ -16,7 +16,7 @@ public class BiomeTest extends AbstractTestingBase { 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() { for (BiomeBase biomeBase : BIOMES) { 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); } } } diff --git a/paper-server/src/test/java/org/bukkit/BlockDataConversionTest.java b/paper-server/src/test/java/org/bukkit/BlockDataConversionTest.java index 3aded3548c..250a49c803 100644 --- a/paper-server/src/test/java/org/bukkit/BlockDataConversionTest.java +++ b/paper-server/src/test/java/org/bukkit/BlockDataConversionTest.java @@ -1,38 +1,30 @@ package org.bukkit; -import java.util.ArrayList; -import java.util.List; +import static org.junit.jupiter.api.Assertions.*; +import java.util.stream.Stream; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.IBlockData; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * This test class ensures that all Blocks (as registered in BuiltInRegistries.BLOCK) * can be converted into their CraftBlockData equivalent. */ -@RunWith(Parameterized.class) public class BlockDataConversionTest extends AbstractTestingBase { - @Parameterized.Parameters(name = "{index}: {0}") - public static List args() { - List list = new ArrayList<>(); - for (Block block : (Iterable) BuiltInRegistries.BLOCK) { - list.add(new Object[]{block.defaultBlockState()}); - } - return list; + public static Stream data() { + return BuiltInRegistries.BLOCK.stream().map(Block::defaultBlockState).map(Arguments::of); } - @Parameterized.Parameter(0) public IBlockData data; - - @Test - public void testNotNull() { - Assert.assertNotNull(data); - Assert.assertNotNull(CraftBlockData.fromData(data)); + @ParameterizedTest + @MethodSource("data") + public void testNotNull(IBlockData data) { + assertNotNull(data); + assertNotNull(CraftBlockData.fromData(data)); } } diff --git a/paper-server/src/test/java/org/bukkit/BlockDataTest.java b/paper-server/src/test/java/org/bukkit/BlockDataTest.java index 43d31466d6..982cf4b68a 100644 --- a/paper-server/src/test/java/org/bukkit/BlockDataTest.java +++ b/paper-server/src/test/java/org/bukkit/BlockDataTest.java @@ -1,6 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.*; import net.minecraft.core.EnumDirection; import net.minecraft.world.level.block.BlockCake; 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.craftbukkit.block.data.CraftBlockData; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; 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 materialString = CraftBlockData.newData(Material.CAKE, "[bites=3]"); - Assert.assertThat(materialString, is(cakeTest)); + assertThat(materialString, is(cakeTest)); 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]"); - Assert.assertThat(combinedMinecraft, is(cakeTest)); + assertThat(combinedMinecraft, is(cakeTest)); BlockData inverted = CraftBlockData.newData(null, cakeTest.getAsString()); - Assert.assertThat(inverted, is(cakeTest)); + assertThat(inverted, is(cakeTest)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testBadMaterial() { - CraftBlockData.newData(null, "invalid"); + assertThrows(IllegalArgumentException.class, () -> CraftBlockData.newData(null, "invalid")); } - @Test(expected = IllegalArgumentException.class) + @Test 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() { - 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() { 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() { - CraftBlockData.newData(Material.DIAMOND_AXE, null); + assertThrows(IllegalArgumentException.class, () -> CraftBlockData.newData(Material.DIAMOND_AXE, null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testItemParse() { - CraftBlockData.newData(null, "minecraft:diamond_axe"); + assertThrows(IllegalArgumentException.class, () -> CraftBlockData.newData(null, "minecraft:diamond_axe")); } @Test @@ -70,11 +71,11 @@ public class BlockDataTest extends AbstractTestingBase { Cake cakeTest = (Cake) CraftBlockData.fromData(Blocks.CAKE.defaultBlockState().setValue(BlockCake.BITES, 3)); Cake clone = (Cake) cakeTest.clone(); - Assert.assertFalse("Clone did not return new object", cakeTest == clone); - Assert.assertThat("Clone is not equal", clone, is(cakeTest)); + assertNotSame(cakeTest, clone, "Clone did not return new object"); + assertThat(clone, is(cakeTest), "Clone is not equal"); 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 @@ -85,13 +86,13 @@ public class BlockDataTest extends AbstractTestingBase { 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); - 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); - Assert.assertFalse("Target and candidate are still not equal", falseTarget.equals(candidate)); + assertNotEquals(falseTarget, candidate, "Target and candidate are still not equal"); } @Test @@ -102,24 +103,24 @@ public class BlockDataTest extends AbstractTestingBase { 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); - 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); - 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() { Chest one = (Chest) CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]"); 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() { Chest one = (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); two.setFacing(BlockFace.NORTH); - one.merge(two); + assertThrows(IllegalArgumentException.class, () -> one.merge(two)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testCannotMerge3() { Chest one = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]"); Chest two = (Chest) CraftBlockData.newData(null, "minecraft:trapped_chest[waterlogged=true]"); - one.merge(two); + assertThrows(IllegalArgumentException.class, () -> one.merge(two)); } @Test public void testMatch() { - Assert.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]"))); - Assert.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]"))); - 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]"))); + assertFalse(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=false]").matches(CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]"))); + assertTrue(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]").matches(CraftBlockData.newData(null, "minecraft:chest"))); + assertFalse(CraftBlockData.newData(null, "minecraft:trapped_chest[facing=east,waterlogged=false]").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,facing=east]"))); Chest one = (Chest) CraftBlockData.fromData(Blocks.CHEST.defaultBlockState().setValue(BlockChest.FACING, EnumDirection.EAST)); Chest two = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=false]"); - Assert.assertTrue(one.matches(two)); - Assert.assertFalse(two.matches(one)); + assertTrue(one.matches(two)); + assertFalse(two.matches(one)); } @Test @@ -158,15 +159,15 @@ public class BlockDataTest extends AbstractTestingBase { String dataString = "minecraft:chest[facing=east,waterlogged=true]"; BlockData data = CraftBlockData.newData(null, dataString); - Assert.assertThat(data.getAsString(true), is(dataString)); - Assert.assertThat(data.getAsString(false), is("minecraft:chest[facing=east,type=single,waterlogged=true]")); + assertThat(data.getAsString(true), is(dataString)); + assertThat(data.getAsString(false), is("minecraft:chest[facing=east,type=single,waterlogged=true]")); } @Test public void testGetAsString2() { 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]")); - Assert.assertThat(data.getAsString(false), is("minecraft:chest[facing=east,type=single,waterlogged=false]")); + assertThat(data.getAsString(true), is("minecraft:chest[facing=east,type=single,waterlogged=false]")); + assertThat(data.getAsString(false), is("minecraft:chest[facing=east,type=single,waterlogged=false]")); } } diff --git a/paper-server/src/test/java/org/bukkit/ChatTest.java b/paper-server/src/test/java/org/bukkit/ChatTest.java index 30e96a0d6a..ea39fb457b 100644 --- a/paper-server/src/test/java/org/bukkit/ChatTest.java +++ b/paper-server/src/test/java/org/bukkit/ChatTest.java @@ -1,24 +1,23 @@ package org.bukkit; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import net.minecraft.EnumChatFormat; import net.minecraft.network.chat.IChatBaseComponent; import org.bukkit.craftbukkit.util.CraftChatMessage; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ChatTest { @Test public void testColors() { for (ChatColor color : ChatColor.values()) { - Assert.assertNotNull(CraftChatMessage.getColor(color)); - Assert.assertEquals(color, CraftChatMessage.getColor(CraftChatMessage.getColor(color))); + assertNotNull(CraftChatMessage.getColor(color)); + assertEquals(color, CraftChatMessage.getColor(CraftChatMessage.getColor(color))); } for (EnumChatFormat format : EnumChatFormat.values()) { - Assert.assertNotNull(CraftChatMessage.getColor(format)); - Assert.assertEquals(format, CraftChatMessage.getColor(CraftChatMessage.getColor(format))); + assertNotNull(CraftChatMessage.getColor(format)); + assertEquals(format, CraftChatMessage.getColor(CraftChatMessage.getColor(format))); } } diff --git a/paper-server/src/test/java/org/bukkit/DyeColorsTest.java b/paper-server/src/test/java/org/bukkit/DyeColorsTest.java index 933719e762..9b75155e54 100644 --- a/paper-server/src/test/java/org/bukkit/DyeColorsTest.java +++ b/paper-server/src/test/java/org/bukkit/DyeColorsTest.java @@ -1,41 +1,26 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import java.util.ArrayList; -import java.util.List; import net.minecraft.world.item.EnumColor; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; -@RunWith(Parameterized.class) public class DyeColorsTest extends AbstractTestingBase { - @Parameters(name = "{index}: {0}") - public static List data() { - List list = new ArrayList(); - for (DyeColor dye : DyeColor.values()) { - list.add(new Object[] {dye}); - } - return list; - } - - @Parameter public DyeColor dye; - - @Test - public void checkColor() { + @ParameterizedTest + @EnumSource(DyeColor.class) + public void checkColor(DyeColor dye) { Color color = dye.getColor(); float[] nmsColorArray = EnumColor.byId(dye.getWoolData()).getTextureDiffuseColors(); Color nmsColor = Color.fromRGB((int) (nmsColorArray[0] * 255), (int) (nmsColorArray[1] * 255), (int) (nmsColorArray[2] * 255)); assertThat(color, is(nmsColor)); } - @Test - public void checkFireworkColor() { + @ParameterizedTest + @EnumSource(DyeColor.class) + public void checkFireworkColor(DyeColor dye) { Color color = dye.getFireworkColor(); int nmsColor = EnumColor.byId(dye.getWoolData()).getFireworkColor(); assertThat(color, is(Color.fromRGB(nmsColor))); diff --git a/paper-server/src/test/java/org/bukkit/EnchantmentTest.java b/paper-server/src/test/java/org/bukkit/EnchantmentTest.java index f32102a177..442128edd9 100644 --- a/paper-server/src/test/java/org/bukkit/EnchantmentTest.java +++ b/paper-server/src/test/java/org/bukkit/EnchantmentTest.java @@ -1,12 +1,12 @@ package org.bukkit; +import static org.junit.jupiter.api.Assertions.*; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.MinecraftKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.enchantments.Enchantment; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class EnchantmentTest extends AbstractTestingBase { @@ -17,9 +17,9 @@ public class EnchantmentTest extends AbstractTestingBase { 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); } } } diff --git a/paper-server/src/test/java/org/bukkit/GameEventTest.java b/paper-server/src/test/java/org/bukkit/GameEventTest.java index bb25e9e0ec..7459947525 100644 --- a/paper-server/src/test/java/org/bukkit/GameEventTest.java +++ b/paper-server/src/test/java/org/bukkit/GameEventTest.java @@ -1,10 +1,10 @@ package org.bukkit; +import static org.junit.jupiter.api.Assertions.*; import net.minecraft.core.registries.BuiltInRegistries; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; 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) { 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); } } } diff --git a/paper-server/src/test/java/org/bukkit/GameRuleTest.java b/paper-server/src/test/java/org/bukkit/GameRuleTest.java index b9ac29bde2..e3ab023405 100644 --- a/paper-server/src/test/java/org/bukkit/GameRuleTest.java +++ b/paper-server/src/test/java/org/bukkit/GameRuleTest.java @@ -1,10 +1,10 @@ package org.bukkit; +import static org.junit.jupiter.api.Assertions.*; import java.util.Map; import net.minecraft.world.level.GameRules; import org.bukkit.craftbukkit.CraftWorld; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class GameRuleTest { @@ -14,8 +14,8 @@ public class GameRuleTest { for (GameRule rule : rules) { GameRule registeredRule = GameRule.getByName(rule.getName()); - Assert.assertNotNull("Null GameRule", registeredRule); - Assert.assertEquals("Invalid GameRule equality", rule, registeredRule); + assertNotNull(registeredRule, "Null GameRule"); + assertEquals(rule, registeredRule, "Invalid GameRule equality"); } } @@ -26,31 +26,31 @@ public class GameRuleTest { for (Map.Entry> entry : minecraftRules.entrySet()) { GameRule bukkitRule = GameRule.getByName(entry.getKey()); - Assert.assertNotNull("Missing " + entry.getKey(), bukkitRule); - Assert.assertEquals("Invalid GameRule Name", bukkitRule.getName(), entry.getKey()); + assertNotNull(bukkitRule, "Missing " + entry.getKey()); + assertEquals(bukkitRule.getName(), entry.getKey(), "Invalid GameRule Name"); } } - @Test(expected = NullPointerException.class) + @Test public void nullGameRuleName() { - GameRule.getByName(null); + assertThrows(NullPointerException.class, () -> GameRule.getByName(null)); } @Test public void emptyGameRuleName() { - Assert.assertNull(GameRule.getByName("")); + assertNull(GameRule.getByName("")); } @Test public void incorrectGameRuleName() { - Assert.assertNull(GameRule.getByName("doAnnounceAdvancements")); - Assert.assertNull(GameRule.getByName("sendCommandBlockFeedback")); + assertNull(GameRule.getByName("doAnnounceAdvancements")); + assertNull(GameRule.getByName("sendCommandBlockFeedback")); } @Test public void invalidCasing() { - Assert.assertNull(GameRule.getByName("CommandBlockOutput")); - Assert.assertNull(GameRule.getByName("spAwnRadius")); - Assert.assertNull(GameRule.getByName("rand0mTickSpeEd")); + assertNull(GameRule.getByName("CommandBlockOutput")); + assertNull(GameRule.getByName("spAwnRadius")); + assertNull(GameRule.getByName("rand0mTickSpeEd")); } } diff --git a/paper-server/src/test/java/org/bukkit/LootTablesTest.java b/paper-server/src/test/java/org/bukkit/LootTablesTest.java index 5f6b547080..6d6745b458 100644 --- a/paper-server/src/test/java/org/bukkit/LootTablesTest.java +++ b/paper-server/src/test/java/org/bukkit/LootTablesTest.java @@ -1,12 +1,12 @@ package org.bukkit; +import static org.junit.jupiter.api.Assertions.*; import net.minecraft.resources.MinecraftKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.loot.LootTable; import org.bukkit.loot.LootTables; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class LootTablesTest extends AbstractTestingBase { @@ -17,8 +17,8 @@ public class LootTablesTest extends AbstractTestingBase { for (LootTables table : tables) { LootTable lootTable = Bukkit.getLootTable(table.getKey()); - Assert.assertNotNull("Unknown LootTable " + table.getKey(), lootTable); - Assert.assertEquals(lootTable.getKey(), table.getKey()); + assertNotNull(lootTable, "Unknown LootTable " + table.getKey()); + assertEquals(lootTable.getKey(), table.getKey()); } } @@ -28,8 +28,8 @@ public class LootTablesTest extends AbstractTestingBase { NamespacedKey bukkitKey = CraftNamespacedKey.fromMinecraft(key); LootTables lootTable = Registry.LOOT_TABLES.get(bukkitKey); - Assert.assertNotNull("Unknown LootTable " + key, lootTable); - Assert.assertEquals(lootTable.getKey(), bukkitKey); + assertNotNull(lootTable, "Unknown LootTable " + key); + assertEquals(lootTable.getKey(), bukkitKey); } } } diff --git a/paper-server/src/test/java/org/bukkit/MaterialTest.java b/paper-server/src/test/java/org/bukkit/MaterialTest.java index f2973810c2..1b30d1ceb0 100644 --- a/paper-server/src/test/java/org/bukkit/MaterialTest.java +++ b/paper-server/src/test/java/org/bukkit/MaterialTest.java @@ -1,7 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import com.google.common.collect.Maps; import java.util.ArrayList; import java.util.Arrays; @@ -16,7 +17,7 @@ import net.minecraft.resources.MinecraftKey; import net.minecraft.world.item.Item; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MaterialTest extends AbstractTestingBase { @@ -42,8 +43,8 @@ public class MaterialTest extends AbstractTestingBase { Material material = materials.remove(id); - assertThat("Missing " + name + "(" + id + ")", material, is(not(nullValue()))); - assertNotNull("No item mapping for " + name, CraftMagicNumbers.getMaterial(item)); + assertThat(material, is(not(nullValue())), "Missing " + name + "(" + id + ")"); + assertNotNull(CraftMagicNumbers.getMaterial(item), "No item mapping for " + name); } assertThat(materials, is(Collections.EMPTY_MAP)); diff --git a/paper-server/src/test/java/org/bukkit/ParticleTest.java b/paper-server/src/test/java/org/bukkit/ParticleTest.java index e1cca688f7..100197ba3b 100644 --- a/paper-server/src/test/java/org/bukkit/ParticleTest.java +++ b/paper-server/src/test/java/org/bukkit/ParticleTest.java @@ -1,5 +1,6 @@ package org.bukkit; +import static org.junit.jupiter.api.Assertions.*; import net.minecraft.core.registries.BuiltInRegistries; import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.CraftParticle; @@ -7,8 +8,7 @@ import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ParticleTest extends AbstractTestingBase { @@ -34,10 +34,10 @@ public class ParticleTest extends AbstractTestingBase { 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) { - 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)); } } } diff --git a/paper-server/src/test/java/org/bukkit/PerMaterialTest.java b/paper-server/src/test/java/org/bukkit/PerMaterialTest.java index 344ca0129e..a2a92dcbfd 100644 --- a/paper-server/src/test/java/org/bukkit/PerMaterialTest.java +++ b/paper-server/src/test/java/org/bukkit/PerMaterialTest.java @@ -1,9 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import com.google.common.collect.Lists; -import java.util.List; +import static org.junit.jupiter.api.Assertions.*; import java.util.Map; import net.minecraft.core.BlockPosition; import net.minecraft.world.EnumHand; @@ -29,44 +28,29 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; import org.bukkit.support.AbstractTestingBase; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; -@RunWith(Parameterized.class) public class PerMaterialTest extends AbstractTestingBase { private static Map fireValues; - @BeforeClass + @BeforeAll public static void getFireValues() { fireValues = ((BlockFire) Blocks.FIRE).igniteOdds; } - @Parameters(name = "{index}: {0}") - public static List data() { - List list = Lists.newArrayList(); - for (Material material : Material.values()) { - if (!material.isLegacy()) { - list.add(new Object[] {material}); - } - } - return list; - } - - @Parameter public Material material; - - @Test - public void isBlock() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void isBlock(Material material) { if (material != Material.AIR && material != Material.CAVE_AIR && material != Material.VOID_AIR) { assertThat(material.isBlock(), is(not(CraftMagicNumbers.getBlock(material) == null))); } } - @Test - public void isSolid() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void isSolid(Material material) { if (material == Material.AIR) { assertFalse(material.isSolid()); } else if (material.isBlock()) { @@ -76,8 +60,9 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void isEdible() { + @ParameterizedTest + @EnumSource(value = Material.class, names = ".LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void isEdible(Material material) { if (material.isBlock()) { assertFalse(material.isEdible()); } else { @@ -85,13 +70,15 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void isRecord() { + @ParameterizedTest + @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)); } - @Test - public void maxDurability() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void maxDurability(Material material) { if (INVALIDATED_MATERIALS.contains(material)) return; if (material == Material.AIR) { @@ -102,8 +89,9 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void maxStackSize() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void maxStackSize(Material material) { if (INVALIDATED_MATERIALS.contains(material)) return; final ItemStack bukkit = new ItemStack(material); @@ -120,8 +108,9 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void isTransparent() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void isTransparent(Material material) { if (material == Material.AIR) { assertTrue(material.isTransparent()); } else if (material.isBlock()) { @@ -131,8 +120,9 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void isFlammable() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void isFlammable(Material material) { if (material != Material.AIR && material.isBlock()) { assertThat(material.isFlammable(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().ignitedByLava())); } else { @@ -140,8 +130,9 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void isBurnable() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void isBurnable(Material material) { if (material.isBlock()) { Block block = CraftMagicNumbers.getBlock(material); assertThat(material.isBurnable(), is(fireValues.containsKey(block) && fireValues.get(block) > 0)); @@ -150,8 +141,9 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void isFuel() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void isFuel(Material material) { if (material.isItem()) { assertThat(material.isFuel(), is(TileEntityFurnace.isFuel(new net.minecraft.world.item.ItemStack(CraftMagicNumbers.getItem(material))))); } else { @@ -159,8 +151,9 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void isOccluding() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void isOccluding(Material material) { if (material.isBlock()) { assertThat(material.isOccluding(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().isRedstoneConductor(BlockAccessAir.INSTANCE, BlockPosition.ZERO))); } else { @@ -168,8 +161,9 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void hasGravity() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void hasGravity(Material material) { if (material.isBlock()) { assertThat(material.hasGravity(), is(CraftMagicNumbers.getBlock(material) instanceof BlockFalling)); } else { @@ -177,8 +171,9 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void usesDurability() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void usesDurability(Material material) { if (!material.isBlock()) { assertThat(EnchantmentTarget.BREAKABLE.includes(material), is(CraftMagicNumbers.getItem(material).canBeDepleted())); } else { @@ -186,8 +181,9 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void testDurability() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void testDurability(Material material) { if (!material.isBlock()) { assertThat(material.getMaxDurability(), is((short) CraftMagicNumbers.getItem(material).getMaxDamage())); } else { @@ -195,8 +191,9 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void testBlock() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void testBlock(Material material) { if (material == Material.AIR) { assertTrue(material.isBlock()); } else { @@ -204,8 +201,9 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void testAir() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void testAir(Material material) { if (material.isBlock()) { assertThat(material.isAir(), is(equalTo(CraftMagicNumbers.getBlock(material).defaultBlockState().isAir()))); } else { @@ -213,8 +211,9 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void testItem() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void testItem(Material material) { if (material == Material.AIR) { assertTrue(material.isItem()); } else { @@ -222,8 +221,9 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void testInteractable() throws ReflectiveOperationException { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void testInteractable(Material material) throws ReflectiveOperationException { if (material.isBlock()) { assertThat(material.isInteractable(), is(!CraftMagicNumbers.getBlock(material).getClass() @@ -234,36 +234,41 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void testBlockHardness() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void testBlockHardness(Material material) { if (material.isBlock()) { assertThat(material.getHardness(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().destroySpeed)); } } - @Test - public void testBlastResistance() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void testBlastResistance(Material material) { if (material.isBlock()) { assertThat(material.getBlastResistance(), is(CraftMagicNumbers.getBlock(material).getExplosionResistance())); } } - @Test - public void testSlipperiness() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void testSlipperiness(Material material) { if (material.isBlock()) { assertThat(material.getSlipperiness(), is(CraftMagicNumbers.getBlock(material).getFriction())); } } - @Test - public void testBlockDataCreation() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void testBlockDataCreation(Material material) { if (material.isBlock()) { assertNotNull(material.createBlockData()); } } - @Test - public void testCraftingRemainingItem() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void testCraftingRemainingItem(Material material) { if (material.isItem()) { Item expectedItem = CraftMagicNumbers.getItem(material).getCraftingRemainingItem(); Material expected = expectedItem == null ? null : CraftMagicNumbers.getMaterial(expectedItem); @@ -272,27 +277,30 @@ public class PerMaterialTest extends AbstractTestingBase { } } - @Test - public void testEquipmentSlot() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void testEquipmentSlot(Material material) { if (material.isItem()) { EquipmentSlot expected = CraftEquipmentSlot.getSlot(EntityInsentient.getEquipmentSlotForItem(CraftItemStack.asNMSCopy(new ItemStack(material)))); assertThat(material.getEquipmentSlot(), is(expected)); } } - @Test - public void testBlockDataClass() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void testBlockDataClass(Material material) { if (material.isBlock()) { Class expectedClass = material.data; if (expectedClass != MaterialData.class) { BlockData blockData = Bukkit.createBlockData(material); - assertTrue(expectedClass + " <> " + blockData.getClass(), expectedClass.isInstance(blockData)); + assertTrue(expectedClass.isInstance(blockData), expectedClass + " <> " + blockData.getClass()); } } } - @Test - public void testCreativeCategory() { + @ParameterizedTest + @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + public void testCreativeCategory(Material material) { if (material.isItem()) { material.getCreativeCategory(); } diff --git a/paper-server/src/test/java/org/bukkit/PerRegistryTest.java b/paper-server/src/test/java/org/bukkit/PerRegistryTest.java index 2125bf2eaf..1f2a085683 100644 --- a/paper-server/src/test/java/org/bukkit/PerRegistryTest.java +++ b/paper-server/src/test/java/org/bukkit/PerRegistryTest.java @@ -1,32 +1,29 @@ package org.bukkit; +import static org.junit.jupiter.api.Assertions.*; import com.google.common.collect.Lists; import java.lang.reflect.Field; import java.util.List; import java.util.Random; +import java.util.stream.Stream; import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class PerRegistryTest extends AbstractTestingBase { private static Random random; - @BeforeClass + @BeforeAll public static void init() { random = new Random(); } - @Parameters(name = "{index}: {0}") - public static List data() { - List data = Lists.newArrayList(); + public static Stream data() { + List data = Lists.newArrayList(); Field[] registryFields = Registry.class.getFields(); for (Field registryField : registryFields) { @@ -37,42 +34,42 @@ public class PerRegistryTest extends AbstractTestingBase { continue; } - data.add(new Object[] {registry}); + data.add(Arguments.of(registry)); } catch (ReflectiveOperationException e) { e.printStackTrace(); } } - return data; + return data.stream(); } - @Parameter public Registry registry; - - @Test - public void testGet() { - this.registry.forEach(element -> { + @ParameterizedTest + @MethodSource("data") + public void testGet(Registry registry) { + registry.forEach(element -> { // 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 - Assert.assertSame(element, registry.get(element.getKey())); + assertSame(element, registry.get(element.getKey())); }); } - @Test - public void testMatch() { - this.registry.forEach(element -> { + @ParameterizedTest + @MethodSource("data") + public void testMatch(Registry registry) { + registry.forEach(element -> { NamespacedKey key = element.getKey(); - assertSameMatchWithKeyMessage(element, key.toString()); // namespace:key - assertSameMatchWithKeyMessage(element, key.getKey()); // key - assertSameMatchWithKeyMessage(element, key.toString().replace('_', ' ')); // namespace:key with space - assertSameMatchWithKeyMessage(element, key.getKey().replace('_', ' ')); // key with space - assertSameMatchWithKeyMessage(element, randomizeCase(key.toString())); // nAmeSPaCe:kEY - assertSameMatchWithKeyMessage(element, randomizeCase(key.getKey())); // kEy + assertSameMatchWithKeyMessage(registry, element, key.toString()); // namespace:key + assertSameMatchWithKeyMessage(registry, element, key.getKey()); // key + assertSameMatchWithKeyMessage(registry, element, key.toString().replace('_', ' ')); // namespace:key with space + assertSameMatchWithKeyMessage(registry, element, key.getKey().replace('_', ' ')); // key with space + assertSameMatchWithKeyMessage(registry, element, randomizeCase(key.toString())); // nAmeSPaCe:kEY + assertSameMatchWithKeyMessage(registry, element, randomizeCase(key.getKey())); // kEy }); } - private void assertSameMatchWithKeyMessage(Keyed element, String key) { - Assert.assertSame(key, element, registry.match(key)); + private void assertSameMatchWithKeyMessage(Registry registry, Keyed element, String key) { + assertSame(element, registry.match(key), key); } private String randomizeCase(String input) { diff --git a/paper-server/src/test/java/org/bukkit/PotionEffectTypeTest.java b/paper-server/src/test/java/org/bukkit/PotionEffectTypeTest.java index 2257e056f7..ae6ceef196 100644 --- a/paper-server/src/test/java/org/bukkit/PotionEffectTypeTest.java +++ b/paper-server/src/test/java/org/bukkit/PotionEffectTypeTest.java @@ -1,7 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import com.google.common.collect.Lists; import java.util.Collections; import java.util.List; @@ -10,7 +11,7 @@ import net.minecraft.resources.MinecraftKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.potion.PotionEffectType; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PotionEffectTypeTest extends AbstractTestingBase { @@ -23,11 +24,11 @@ public class PotionEffectTypeTest extends AbstractTestingBase { PotionEffectType effect = PotionEffectType.getByKey(CraftNamespacedKey.fromMinecraft(key)); String message = String.format("org.bukkit.PotionEffectType is missing '%s'", name); - assertNotNull(message, effect); + assertNotNull(effect, message); 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"); } } diff --git a/paper-server/src/test/java/org/bukkit/RegistryConstantsTest.java b/paper-server/src/test/java/org/bukkit/RegistryConstantsTest.java index 3eca3e3db6..a19dca66c9 100644 --- a/paper-server/src/test/java/org/bukkit/RegistryConstantsTest.java +++ b/paper-server/src/test/java/org/bukkit/RegistryConstantsTest.java @@ -1,5 +1,6 @@ package org.bukkit; +import static org.junit.jupiter.api.Assertions.*; import java.lang.reflect.Field; import java.lang.reflect.Modifier; 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.TrimPattern; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; 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 void testMissingConstants(Class clazz, ResourceKey> nmsRegistryKey) { @@ -59,14 +59,14 @@ public class RegistryConstantsTest extends AbstractTestingBase { @SuppressWarnings("unchecked") 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) { missingKeys.add(minecraftKey); } 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); } } diff --git a/paper-server/src/test/java/org/bukkit/SoundTest.java b/paper-server/src/test/java/org/bukkit/SoundTest.java index d96a2820c0..ff62148d66 100644 --- a/paper-server/src/test/java/org/bukkit/SoundTest.java +++ b/paper-server/src/test/java/org/bukkit/SoundTest.java @@ -1,40 +1,41 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.MinecraftKey; import org.bukkit.craftbukkit.CraftSound; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SoundTest extends AbstractTestingBase { @Test public void testGetSound() { for (Sound sound : Sound.values()) { - assertThat(sound.name(), CraftSound.bukkitToMinecraft(sound), is(not(nullValue()))); + assertThat(CraftSound.bukkitToMinecraft(sound), is(not(nullValue())), sound.name()); } } @Test public void testReverse() { 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 public void testCategory() { for (SoundCategory category : SoundCategory.values()) { - assertNotNull(category + "", net.minecraft.sounds.SoundCategory.valueOf(category.name())); + assertNotNull(net.minecraft.sounds.SoundCategory.valueOf(category.name()), category + ""); } } @Test public void testCategoryReverse() { for (net.minecraft.sounds.SoundCategory category : net.minecraft.sounds.SoundCategory.values()) { - assertNotNull(category + "", SoundCategory.valueOf(category.name())); + assertNotNull(SoundCategory.valueOf(category.name()), category + ""); } } } diff --git a/paper-server/src/test/java/org/bukkit/StatisticsAndAchievementsTest.java b/paper-server/src/test/java/org/bukkit/StatisticsAndAchievementsTest.java index 5c0fbee45a..d83ab63d91 100644 --- a/paper-server/src/test/java/org/bukkit/StatisticsAndAchievementsTest.java +++ b/paper-server/src/test/java/org/bukkit/StatisticsAndAchievementsTest.java @@ -1,7 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import com.google.common.collect.HashMultiset; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.stats.StatisticWrapper; @@ -9,7 +10,7 @@ import net.minecraft.world.entity.EntityTypes; import org.bukkit.craftbukkit.CraftStatistic; import org.bukkit.entity.EntityType; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class StatisticsAndAchievementsTest extends AbstractTestingBase { @@ -20,7 +21,7 @@ public class StatisticsAndAchievementsTest extends AbstractTestingBase { if (statistic.getType() == Statistic.Type.ENTITY) { for (EntityType entity : EntityType.values()) { 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); 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) { - 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) { - assertNotNull("Entity type map missing for " + EntityTypes.getKey((EntityTypes) child), CraftStatistic.getEntityTypeFromStatistic((net.minecraft.stats.Statistic>) statistic)); + assertNotNull(CraftStatistic.getEntityTypeFromStatistic((net.minecraft.stats.Statistic>) statistic), "Entity type map missing for " + EntityTypes.getKey((EntityTypes) child)); } statistics.add(subject); @@ -51,7 +52,7 @@ public class StatisticsAndAchievementsTest extends AbstractTestingBase { for (Statistic statistic : Statistic.values()) { 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); } } } diff --git a/paper-server/src/test/java/org/bukkit/block/banner/PatternTypeTest.java b/paper-server/src/test/java/org/bukkit/block/banner/PatternTypeTest.java index 7f85dd6289..5134fe8d98 100644 --- a/paper-server/src/test/java/org/bukkit/block/banner/PatternTypeTest.java +++ b/paper-server/src/test/java/org/bukkit/block/banner/PatternTypeTest.java @@ -1,10 +1,10 @@ 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.world.level.block.entity.EnumBannerPatternType; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PatternTypeTest extends AbstractTestingBase { @@ -13,7 +13,7 @@ public class PatternTypeTest extends AbstractTestingBase { for (EnumBannerPatternType nms : BuiltInRegistries.BANNER_PATTERN) { 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()); } } } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/HeightMapTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/HeightMapTest.java index 356ba66452..e6eb382993 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/HeightMapTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/HeightMapTest.java @@ -1,22 +1,22 @@ package org.bukkit.craftbukkit; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.HeightMap; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class HeightMapTest { @Test public void heightMapConversionFromNMSToBukkitShouldNotThrowExceptio() { 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 public void heightMapConversionFromBukkitToNMSShouldNotThrowExceptio() { for (HeightMap bukkitHeightMap : HeightMap.values()) { - Assert.assertNotNull("toNMS", CraftHeightMap.toNMS(bukkitHeightMap)); + assertNotNull(CraftHeightMap.toNMS(bukkitHeightMap), "toNMS"); } } } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/attribute/AttributeTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/attribute/AttributeTest.java index a5ddd1e1fe..98ce37eeac 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/attribute/AttributeTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/attribute/AttributeTest.java @@ -1,11 +1,11 @@ package org.bukkit.craftbukkit.attribute; +import static org.junit.jupiter.api.Assertions.*; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.entity.ai.attributes.AttributeBase; import org.bukkit.attribute.Attribute; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AttributeTest extends AbstractTestingBase { @@ -14,7 +14,7 @@ public class AttributeTest extends AbstractTestingBase { for (AttributeBase nms : BuiltInRegistries.ATTRIBUTE) { 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()) { AttributeBase nms = CraftAttribute.bukkitToMinecraft(attribute); - Assert.assertNotNull(attribute.name(), nms); + assertNotNull(nms, attribute.name()); } } } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/block/BlockStateTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/block/BlockStateTest.java index 79dc00ec9b..68107d4d26 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/block/BlockStateTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/block/BlockStateTest.java @@ -1,9 +1,6 @@ package org.bukkit.craftbukkit.block; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; import net.minecraft.core.BlockPosition; import net.minecraft.core.registries.BuiltInRegistries; 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.craftbukkit.util.CraftMagicNumbers; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BlockStateTest extends AbstractTestingBase { @@ -24,7 +21,7 @@ public class BlockStateTest extends AbstractTestingBase { boolean isCraftBlockEntityState = CraftBlockEntityState.class.isAssignableFrom(blockStateType); 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 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"); } - assertNotNull(material + " has no tile entity expected tile entity of type " + tileEntity.getClass(), materialTileEntity); - assertSame(material + " has unexpected tile entity type, expected " + tileEntity.getClass() + " but got " + tileEntity.getClass(), materialTileEntity.getClass(), tileEntity.getClass()); + assertNotNull(materialTileEntity, material + " has no tile entity expected tile entity of type " + tileEntity.getClass()); + assertSame(materialTileEntity.getClass(), tileEntity.getClass(), material + " has unexpected tile entity type, expected " + tileEntity.getClass() + " but got " + tileEntity.getClass()); } 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)"); } } } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/generator/ChunkDataTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/generator/ChunkDataTest.java index 8faa970635..15ee83d724 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/generator/ChunkDataTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/generator/ChunkDataTest.java @@ -1,10 +1,10 @@ package org.bukkit.craftbukkit.generator; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.Material; import org.bukkit.block.data.BlockData; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ChunkDataTest extends AbstractTestingBase { @@ -35,28 +35,28 @@ public class ChunkDataTest extends AbstractTestingBase { @Test public void testMinHeight() { OldCraftChunkData data = new OldCraftChunkData(-128, 128, BIOMES); - assertTrue("Could not set block below min height", testSetBlock(data, 0, -256, 0, RED_WOOL, AIR)); - assertTrue("Could set block above min height", testSetBlock(data, 0, -64, 0, RED_WOOL, RED_WOOL)); + assertTrue(testSetBlock(data, 0, -256, 0, RED_WOOL, AIR), "Could not set block below min height"); + assertTrue(testSetBlock(data, 0, -64, 0, RED_WOOL, RED_WOOL), "Could set block above min height"); } @Test public void testMaxHeight() { OldCraftChunkData data = new OldCraftChunkData(0, 128, BIOMES); - assertTrue("Could not set block above max height", testSetBlock(data, 0, 128, 0, RED_WOOL, AIR)); - assertTrue("Could set block below max height", testSetBlock(data, 0, 127, 0, RED_WOOL, RED_WOOL)); + assertTrue(testSetBlock(data, 0, 128, 0, RED_WOOL, AIR), "Could not set block above max height"); + assertTrue(testSetBlock(data, 0, 127, 0, RED_WOOL, RED_WOOL), "Could set block below max height"); } @Test public void testBoundsCheckingSingle() { OldCraftChunkData data = new OldCraftChunkData(0, 256, BIOMES); - assertTrue("Can set block inside chunk bounds", testSetBlock(data, 0, 0, 0, RED_WOOL, RED_WOOL)); - assertTrue("Can set block inside chunk bounds", testSetBlock(data, 15, 255, 15, RED_WOOL, RED_WOOL)); - assertTrue("Can no set block outside chunk bounds", testSetBlock(data, -1, 0, 0, RED_WOOL, AIR)); - assertTrue("Can no set block outside chunk bounds", testSetBlock(data, 0, -1, 0, RED_WOOL, AIR)); - assertTrue("Can no set block outside chunk bounds", testSetBlock(data, 0, 0, -1, RED_WOOL, AIR)); - assertTrue("Can no set block outside chunk bounds", testSetBlock(data, 16, 0, 0, RED_WOOL, AIR)); - assertTrue("Can no set block outside chunk bounds", testSetBlock(data, 0, 256, 0, RED_WOOL, AIR)); - assertTrue("Can no set block outside chunk bounds", testSetBlock(data, 0, 0, 16, RED_WOOL, AIR)); + assertTrue(testSetBlock(data, 0, 0, 0, RED_WOOL, RED_WOOL), "Can set block inside chunk bounds"); + assertTrue(testSetBlock(data, 15, 255, 15, RED_WOOL, RED_WOOL), "Can set block inside chunk bounds"); + assertTrue(testSetBlock(data, -1, 0, 0, RED_WOOL, AIR), "Can no set block outside chunk bounds"); + assertTrue(testSetBlock(data, 0, -1, 0, RED_WOOL, AIR), "Can no set block outside chunk bounds"); + assertTrue(testSetBlock(data, 0, 0, -1, RED_WOOL, AIR), "Can no set block outside chunk bounds"); + assertTrue(testSetBlock(data, 16, 0, 0, RED_WOOL, AIR), "Can no set block outside chunk bounds"); + assertTrue(testSetBlock(data, 0, 256, 0, RED_WOOL, AIR), "Can no set block outside chunk bounds"); + assertTrue(testSetBlock(data, 0, 0, 16, RED_WOOL, AIR), "Can no set block outside chunk bounds"); } @Test diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/CompositeSerialization.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/CompositeSerialization.java index 1bbfa365b0..956bc1a464 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/CompositeSerialization.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/CompositeSerialization.java @@ -1,7 +1,7 @@ package org.bukkit.craftbukkit.inventory; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -13,7 +13,7 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CompositeSerialization extends AbstractTestingBase { @@ -63,7 +63,7 @@ public class CompositeSerialization extends AbstractTestingBase { assertThat(stacks, hasSize(raw.size())); 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)); } } } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java index 6c447cda2f..7ee5db71b8 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java @@ -1,6 +1,6 @@ package org.bukkit.craftbukkit.inventory; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.StringReader; import java.lang.reflect.Array; 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.ItemTagType; import org.bukkit.support.AbstractTestingBase; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class DeprecatedItemMetaCustomValueTest extends AbstractTestingBase { private static NamespacedKey VALID_KEY; - @Before - public void setup() { + @BeforeAll + public static void setup() { VALID_KEY = new NamespacedKey("test", "validkey"); } /* Sets a test */ - @Test(expected = IllegalArgumentException.class) + @Test public void testSetNoAdapter() { 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 */ - @Test(expected = IllegalArgumentException.class) + @Test public void testHasNoAdapter() { 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().hasCustomTag(VALID_KEY, new PrimitiveTagType<>(boolean.class)); + assertThrows(IllegalArgumentException.class, () -> itemMeta.getCustomTagContainer().hasCustomTag(VALID_KEY, new PrimitiveTagType<>(boolean.class))); } /* Getting a tag */ - @Test(expected = IllegalArgumentException.class) + @Test public void testGetNoAdapter() { 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().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() { ItemMeta itemMeta = createNewItemMeta(); 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 diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/FactoryItemMaterialTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/FactoryItemMaterialTest.java index c279579c2b..4ada232ec6 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/FactoryItemMaterialTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/FactoryItemMaterialTest.java @@ -1,21 +1,20 @@ package org.bukkit.craftbukkit.inventory; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.List; +import java.util.stream.Stream; import org.bukkit.Material; import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class FactoryItemMaterialTest extends AbstractTestingBase { static final ItemFactory factory = CraftItemFactory.instance(); 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(); } - @Parameters(name = "Material[{index}]:{0}") - public static List data() { - List list = new ArrayList(); + public static Stream data() { + List list = new ArrayList<>(); for (Material material : materials) { - list.add(new Object[] {material}); + list.add(Arguments.of(material)); } - return list; + return list.stream(); } - @Parameter(0) public Material material; - - @Test - public void itemStack() { + @ParameterizedTest + @MethodSource("data") + public void itemStack(Material material) { ItemStack bukkitStack = new ItemStack(material); CraftItemStack craftStack = CraftItemStack.asCraftCopy(bukkitStack); ItemMeta meta = factory.getItemMeta(material); @@ -65,8 +62,9 @@ public class FactoryItemMaterialTest extends AbstractTestingBase { } } - @Test - public void generalCase() { + @ParameterizedTest + @MethodSource("data") + public void generalCase(Material material) { CraftMetaItem meta = (CraftMetaItem) factory.getItemMeta(material); if (meta == null) { assertThat(material, is(Material.AIR)); @@ -80,8 +78,9 @@ public class FactoryItemMaterialTest extends AbstractTestingBase { } } - @Test - public void asMetaFor() { + @ParameterizedTest + @MethodSource("data") + public void asMetaFor(Material material) { final CraftMetaItem baseMeta = (CraftMetaItem) factory.getItemMeta(material); if (baseMeta == null) { assertThat(material, is(Material.AIR)); @@ -96,19 +95,20 @@ public class FactoryItemMaterialTest extends AbstractTestingBase { final String testName = name(material, other); if (otherMeta == null) { - assertThat(testName, other, is(Material.AIR)); + assertThat(other, is(Material.AIR), testName); continue; } - assertTrue(testName, factory.isApplicable(otherMeta, craftStack)); - assertTrue(testName, factory.isApplicable(otherMeta, bukkitStack)); - assertTrue(testName, factory.isApplicable(otherMeta, other)); - assertTrue(testName, otherMeta.applicableTo(other)); + assertTrue(factory.isApplicable(otherMeta, craftStack), testName); + assertTrue(factory.isApplicable(otherMeta, bukkitStack), testName); + assertTrue(factory.isApplicable(otherMeta, other), testName); + assertTrue(otherMeta.applicableTo(other), testName); } } - @Test - public void blankEqualities() { + @ParameterizedTest + @MethodSource("data") + public void blankEqualities(Material material) { if (material == Material.AIR) { return; } @@ -137,17 +137,17 @@ public class FactoryItemMaterialTest extends AbstractTestingBase { final CraftMetaItem otherMeta = (CraftMetaItem) factory.asMetaFor(baseMetaClone, other); if (otherMeta == null) { - assertThat(testName, other, is(Material.AIR)); + assertThat(other, is(Material.AIR), testName); continue; } - assertTrue(testName, factory.equals(baseMeta, otherMeta)); - assertTrue(testName, factory.equals(otherMeta, baseMeta)); + assertTrue(factory.equals(baseMeta, otherMeta), testName); + assertTrue(factory.equals(otherMeta, baseMeta), testName); - assertThat(testName, baseMeta, is(otherMeta)); - assertThat(testName, otherMeta, is(baseMeta)); + assertThat(baseMeta, is(otherMeta), testName); + assertThat(otherMeta, is(baseMeta), testName); - assertThat(testName, baseMeta.hashCode(), is(otherMeta.hashCode())); + assertThat(baseMeta.hashCode(), is(otherMeta.hashCode()), testName); } } } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaCloneTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaCloneTest.java index cefedd7d1e..12840f5c31 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaCloneTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaCloneTest.java @@ -1,10 +1,11 @@ package org.bukkit.craftbukkit.inventory; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.lang.reflect.Method; import org.bukkit.Material; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ItemMetaCloneTest { @@ -14,8 +15,8 @@ public class ItemMetaCloneTest { Class clazz = CraftItemFactory.instance().getItemMeta(material).getClass(); Method clone = clazz.getDeclaredMethod("clone"); - assertNotNull("Class " + clazz + " does not override clone()", clone); - assertThat("Class " + clazz + " clone return type does not match", clone.getReturnType(), is(equalTo(clazz))); + assertNotNull(clone, "Class " + clazz + " does not override clone()"); + assertThat(clone.getReturnType(), is(equalTo(clazz)), "Class " + clazz + " clone return type does not match"); } } } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaImplementationOverrideTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaImplementationOverrideTest.java index 61ac1fb7c5..c3964e439c 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaImplementationOverrideTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaImplementationOverrideTest.java @@ -1,27 +1,24 @@ package org.bukkit.craftbukkit.inventory; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; +import java.util.stream.Stream; import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.craftbukkit.Overridden; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class ItemMetaImplementationOverrideTest { static final Class parent = CraftMetaItem.class; - @Parameters(name = "[{index}]:{1}") - public static List data() { - final List testData = new ArrayList(); + public static Stream data() { + final List testData = new ArrayList<>(); List> classes = new ArrayList>(); for (Material material : ItemStackTest.COMPOUND_MATERIALS) { @@ -42,7 +39,7 @@ public class ItemMetaImplementationOverrideTest { for (final Class clazz : classes) { for (final Method method : list) { testData.add( - new Object[] { + Arguments.of( new Callable() { @Override public Method call() throws Exception { @@ -50,12 +47,12 @@ public class ItemMetaImplementationOverrideTest { } }, clazz.getSimpleName() + " contains " + method.getName() - } + ) ); } testData.add( - new Object[] { + Arguments.of( new Callable() { @Override public DelegateDeserialization call() throws Exception { @@ -63,18 +60,16 @@ public class ItemMetaImplementationOverrideTest { } }, clazz.getSimpleName() + " contains annotation " + DelegateDeserialization.class - } + ) ); } - return testData; + return testData.stream(); } - @Parameter(0) public Callable test; - @Parameter(1) public String name; - - @Test - public void testClass() throws Throwable { - assertThat(name, test.call(), is(not(nullValue()))); + @ParameterizedTest + @MethodSource("data") + public void testClass(Callable test, String name) throws Throwable { + assertThat(test.call(), is(not(nullValue())), name); } } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java index 8e13cbf139..ad44e23ca1 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java @@ -1,7 +1,8 @@ package org.bukkit.craftbukkit.inventory; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -61,30 +62,30 @@ import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ItemMetaTest extends AbstractTestingBase { static final int MAX_FIREWORK_POWER = 127; // Please update ItemStackFireworkTest if/when this gets changed. - @Test(expected = IllegalArgumentException.class) + @Test 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() { - newFireworkMeta().setPower(Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> newFireworkMeta().setPower(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testPowerLimitMin() { - newFireworkMeta().setPower(Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> newFireworkMeta().setPower(Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testPowerLimitNegative() { - newFireworkMeta().setPower(-1); + assertThrows(IllegalArgumentException.class, () -> newFireworkMeta().setPower(-1)); } @Test @@ -92,7 +93,7 @@ public class ItemMetaTest extends AbstractTestingBase { for (int i = 0; i <= MAX_FIREWORK_POWER; i++) { FireworkMeta firework = newFireworkMeta(); 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()); ItemStack bukkit = new ItemStack(craft); assertThat(craft, is(bukkit)); - assertThat(bukkit, is((ItemStack) craft)); + assertThat(bukkit, is(craft)); } @Test @@ -179,14 +180,14 @@ public class ItemMetaTest extends AbstractTestingBase { ItemMeta meta = stack.getItemMeta(); 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; - assertNotNull(stack + " has null block state", blockState.getBlockState()); + assertNotNull(blockState.getBlockState(), stack + " has null block state"); blockState.setBlockState(blockState.getBlockState()); } 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); ItemMeta baseMetaItem = CraftItemStack.getItemMeta(item.getDefaultInstance()); - assertTrue(material + " is not handled in CraftItemFactory", baseMeta instanceof CraftMetaSpawnEgg); - assertTrue(material + " is not applicable to CraftMetaSpawnEgg", baseMeta.applicableTo(material)); - assertTrue(material + " is not handled in CraftItemStack", baseMetaItem instanceof SpawnEggMeta); + assertTrue(baseMeta instanceof CraftMetaSpawnEgg, material + " is not handled in CraftItemFactory"); + assertTrue(baseMeta.applicableTo(material), material + " is not applicable to CraftMetaSpawnEgg"); + 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) { downCastTest(new BukkitWrapper(provider)); @@ -452,8 +453,8 @@ public class ItemMetaTest extends AbstractTestingBase { final ItemStack craftBlank = CraftItemStack.asCraftCopy(blank); // Check that equality and similarity works for each meta implementation - assertThat(name, provider.stack(), is(provider.stack())); - assertThat(name, provider.stack().isSimilar(provider.stack()), is(true)); + assertThat(provider.stack(), is(provider.stack()), name); + assertThat(provider.stack().isSimilar(provider.stack()), is(true), name); downCastTest(name, provider.stack(), blank); 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) { - assertThat(name, stack, is(not(blank))); - assertThat(name, stack.getItemMeta(), is(not(blank.getItemMeta()))); + assertThat(stack, is(not(blank)), name); + assertThat(stack.getItemMeta(), is(not(blank.getItemMeta())), name); stack.setType(Material.STONE); - assertThat(name, stack, is(blank)); + assertThat(stack, is(blank), name); } } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackBookTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackBookTest.java index 7b107a3c3b..7790a2e018 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackBookTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackBookTest.java @@ -3,21 +3,15 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Joiner; import java.util.Arrays; import java.util.List; +import java.util.stream.Stream; 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.meta.BookMeta; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ItemStackBookTest extends ItemStackTest { - @Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") - public static List data() { + public static Stream data() { return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.WRITTEN_BOOK, Material.WRITABLE_BOOK); } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackEnchantStorageTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackEnchantStorageTest.java index 349c9c8aab..0e42ae68f3 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackEnchantStorageTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackEnchantStorageTest.java @@ -3,22 +3,16 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Joiner; import java.util.Arrays; import java.util.List; +import java.util.stream.Stream; 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.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ItemStackEnchantStorageTest extends ItemStackTest { - @Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") - public static List data() { + public static Stream data() { return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.ENCHANTED_BOOK); } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkChargeTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkChargeTest.java index 989a67ed29..bba4089da2 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkChargeTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkChargeTest.java @@ -3,24 +3,18 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Joiner; import java.util.Arrays; import java.util.List; +import java.util.stream.Stream; import org.bukkit.Color; import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect.Type; import org.bukkit.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.meta.FireworkEffectMeta; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ItemStackFireworkChargeTest extends ItemStackTest { - @Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") - public static List data() { + public static Stream data() { return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.FIREWORK_STAR); } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkTest.java index 028b7e3591..1b18e38ceb 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkTest.java @@ -3,24 +3,18 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Joiner; import java.util.Arrays; import java.util.List; +import java.util.stream.Stream; import org.bukkit.Color; import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect.Type; import org.bukkit.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.meta.FireworkMeta; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ItemStackFireworkTest extends ItemStackTest { - @Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") - public static List data() { + public static Stream data() { return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.FIREWORK_ROCKET); } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackLeatherTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackLeatherTest.java index 99ec53dec9..6f9efb3d8f 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackLeatherTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackLeatherTest.java @@ -3,22 +3,16 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Joiner; import java.util.Arrays; import java.util.List; +import java.util.stream.Stream; import org.bukkit.Color; 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.meta.LeatherArmorMeta; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ItemStackLeatherTest extends ItemStackTest { - @Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") - public static List data() { + public static Stream data() { return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.LEATHER_BOOTS, Material.LEATHER_CHESTPLATE, Material.LEATHER_HELMET, Material.LEATHER_LEGGINGS); } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackLoreEnchantmentTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackLoreEnchantmentTest.java index a9e3de37cc..ded1d16638 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackLoreEnchantmentTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackLoreEnchantmentTest.java @@ -3,22 +3,16 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Joiner; import java.util.Arrays; import java.util.List; -import org.bukkit.craftbukkit.inventory.ItemStackTest.CompoundOperator; -import org.bukkit.craftbukkit.inventory.ItemStackTest.Operator; -import org.bukkit.craftbukkit.inventory.ItemStackTest.StackProvider; +import java.util.stream.Stream; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.Repairable; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ItemStackLoreEnchantmentTest extends ItemStackTest { - @Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") - public static List data() { + public static Stream data() { return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, ItemStackTest.COMPOUND_MATERIALS); } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackMapTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackMapTest.java index 70285d999c..184171656f 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackMapTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackMapTest.java @@ -3,21 +3,15 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Joiner; import java.util.Arrays; import java.util.List; +import java.util.stream.Stream; 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.meta.MapMeta; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ItemStackMapTest extends ItemStackTest { - @Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") - public static List data() { + public static Stream data() { return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.FILLED_MAP); } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackPotionsTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackPotionsTest.java index cf2f3b5ab7..fe6a2ed8a2 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackPotionsTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackPotionsTest.java @@ -3,22 +3,16 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Joiner; import java.util.Arrays; import java.util.List; +import java.util.stream.Stream; 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.meta.PotionMeta; import org.bukkit.potion.PotionEffectType; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ItemStackPotionsTest extends ItemStackTest { - @Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") - public static List data() { + public static Stream data() { return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.POTION); } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackSkullTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackSkullTest.java index 2040942bde..fff48e4403 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackSkullTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackSkullTest.java @@ -3,21 +3,15 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Joiner; import java.util.Arrays; import java.util.List; +import java.util.stream.Stream; 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.meta.SkullMeta; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ItemStackSkullTest extends ItemStackTest { - @Parameters(name = "[{index}]:{" + NAME_PARAMETER + "}") - public static List data() { + public static Stream data() { return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.PLAYER_HEAD); } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackTest.java index 1add9c7d39..643094f73d 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackTest.java @@ -1,10 +1,9 @@ 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.junit.Assert.*; import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -15,6 +14,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Stream; import org.bukkit.Material; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; @@ -24,14 +24,11 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.support.AbstractTestingBase; import org.bukkit.util.io.BukkitObjectInputStream; import org.bukkit.util.io.BukkitObjectOutputStream; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; -@RunWith(Parameterized.class) public class ItemStackTest extends AbstractTestingBase { abstract static class StackProvider { final Material material; @@ -70,8 +67,8 @@ public class ItemStackTest extends AbstractTestingBase { * @param materials * @return */ - static List compound(final List parameterList, final String nameFormat, final int nameIndex, final Material...materials) { - final List out = new ArrayList(); + static Stream compound(final List parameterList, final String nameFormat, final int nameIndex, final Material... materials) { + final List out = new ArrayList<>(); for (Object[] params : parameterList) { final int len = params.length; for (final Material material : materials) { @@ -89,10 +86,10 @@ public class ItemStackTest extends AbstractTestingBase { } } 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 List data() { - return ImmutableList.of(); // TODO, test basic durability issues + public static Stream data() { + return Stream.empty(); // TODO, test basic durability issues } 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()]); } - @Parameter(0) public StackProvider provider; - @Parameter(1) public StackProvider unequalProvider; - @Parameter(NAME_PARAMETER) public String name; - - @Test - public void testBukkitInequality() { + @ParameterizedTest(name = "[{index}]:{" + NAME_PARAMETER + "}") + @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 testBukkitInequality(StackProvider provider, StackProvider unequalProvider, String name) { final StackWrapper bukkitWrapper = new CraftWrapper(provider); testInequality(bukkitWrapper, new BukkitWrapper(unequalProvider)); testInequality(bukkitWrapper, new BukkitWrapper(new NoOpProvider(provider.material))); } - @Test - public void testCraftInequality() { + @ParameterizedTest(name = "[{index}]:{" + NAME_PARAMETER + "}") + @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); testInequality(craftWrapper, new CraftWrapper(unequalProvider)); testInequality(craftWrapper, new CraftWrapper(new NoOpProvider(provider.material))); } - @Test - public void testMixedInequality() { + @ParameterizedTest(name = "[{index}]:{" + NAME_PARAMETER + "}") + @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); testInequality(craftWrapper, new BukkitWrapper(unequalProvider)); testInequality(craftWrapper, new BukkitWrapper(new NoOpProvider(provider.material))); @@ -400,23 +425,67 @@ public class ItemStackTest extends AbstractTestingBase { assertThat(newUnequalCraftStack.getItemMeta(), is(not(stack.getItemMeta()))); } - @Test - public void testBukkitYamlDeserialize() throws Throwable { + @ParameterizedTest(name = "[{index}]:{" + NAME_PARAMETER + "}") + @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)); } - @Test - public void testCraftYamlDeserialize() throws Throwable { + @ParameterizedTest(name = "[{index}]:{" + NAME_PARAMETER + "}") + @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)); } - @Test - public void testBukkitStreamDeserialize() throws Throwable { + @ParameterizedTest(name = "[{index}]:{" + NAME_PARAMETER + "}") + @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)); } - @Test - public void testCraftStreamDeserialize() throws Throwable { + @ParameterizedTest(name = "[{index}]:{" + NAME_PARAMETER + "}") + @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)); } @@ -486,9 +555,9 @@ public class ItemStackTest extends AbstractTestingBase { } static void testEqualities(String information, ItemStack primaryRead, ItemStack unequalRead, ItemStack primaryOriginal, ItemStack unequalOriginal) { - assertThat(information, primaryRead, allOf(equalTo(primaryOriginal), sameHash(primaryOriginal))); - assertThat(information, unequalRead, allOf(equalTo(unequalOriginal), sameHash(unequalOriginal))); - assertThat(information, primaryRead, is(not(unequalOriginal))); - assertThat(information, primaryRead, is(not(unequalRead))); + assertThat(primaryRead, allOf(equalTo(primaryOriginal), sameHash(primaryOriginal)), information); + assertThat(unequalRead, allOf(equalTo(unequalOriginal), sameHash(unequalOriginal)), information); + assertThat(primaryRead, is(not(unequalOriginal)), information); + assertThat(primaryRead, is(not(unequalRead)), information); } } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/NMSCraftItemStackTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/NMSCraftItemStackTest.java index bed586fe7c..cf3a60c179 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/NMSCraftItemStackTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/NMSCraftItemStackTest.java @@ -1,11 +1,11 @@ package org.bukkit.craftbukkit.inventory; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import net.minecraft.world.item.enchantment.Enchantments; import org.bukkit.inventory.ItemStack; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class NMSCraftItemStackTest extends AbstractTestingBase { diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java index ff9cc59c37..ef566f095d 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java @@ -1,6 +1,6 @@ package org.bukkit.craftbukkit.inventory; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.StringReader; import java.lang.reflect.Array; import java.nio.ByteBuffer; @@ -17,52 +17,52 @@ import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import org.bukkit.support.AbstractTestingBase; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class PersistentDataContainerTest extends AbstractTestingBase { private static NamespacedKey VALID_KEY; - @Before - public void setup() { + @BeforeAll + public static void setup() { VALID_KEY = new NamespacedKey("test", "validkey"); } /* Sets a test */ - @Test(expected = IllegalArgumentException.class) + @Test public void testSetNoAdapter() { 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 */ - @Test(expected = IllegalArgumentException.class) + @Test public void testHasNoAdapter() { 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().has(VALID_KEY, new PrimitiveTagType<>(boolean.class)); + assertThrows(IllegalArgumentException.class, () -> itemMeta.getPersistentDataContainer().has(VALID_KEY, new PrimitiveTagType<>(boolean.class))); } /* Getting a tag */ - @Test(expected = IllegalArgumentException.class) + @Test public void testGetNoAdapter() { 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().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() { ItemMeta itemMeta = createNewItemMeta(); 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 diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/PlayerInventoryTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/PlayerInventoryTest.java index 724290302b..69feb4c3fe 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/PlayerInventoryTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/PlayerInventoryTest.java @@ -1,11 +1,11 @@ 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.item.ItemStack; import net.minecraft.world.item.Items; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PlayerInventoryTest extends AbstractTestingBase { diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/legacy/EvilTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/legacy/EvilTest.java index 713a205ab1..9e93602582 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/legacy/EvilTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/legacy/EvilTest.java @@ -1,24 +1,24 @@ package org.bukkit.craftbukkit.legacy; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.Material; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class EvilTest extends AbstractTestingBase { @Test public void testFrom() { - Assert.assertEquals(Material.LEGACY_STONE, CraftEvil.getMaterial(1)); + assertEquals(Material.LEGACY_STONE, CraftEvil.getMaterial(1)); } @Test 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() { - Material.STONE.getId(); + assertThrows(IllegalArgumentException.class, () -> Material.STONE.getId()); } } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/legacy/LegacyTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/legacy/LegacyTest.java index bf6d9fb625..65331d05d4 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/legacy/LegacyTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/legacy/LegacyTest.java @@ -1,5 +1,6 @@ package org.bukkit.craftbukkit.legacy; +import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -7,8 +8,7 @@ import org.bukkit.Material; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.material.MaterialData; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class LegacyTest extends AbstractTestingBase { @@ -125,18 +125,18 @@ public class LegacyTest extends AbstractTestingBase { if (!INVALIDATED_MATERIALS.contains(material) && !material.isLegacy()) { 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())) { - 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)) { - 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 @@ -144,32 +144,32 @@ public class LegacyTest extends AbstractTestingBase { for (Material material : Material.values()) { if (!INVALIDATED_MATERIALS.contains(material) && material.isLegacy()) { 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)) { - 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 public void testRestricted() { 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()) { - Assert.assertFalse("Must iterate only modern materials", material.isLegacy()); + assertFalse(material.isLegacy(), "Must iterate only modern materials"); } } @Test public void testManual() { - Assert.assertEquals(Material.YELLOW_DYE, CraftMagicNumbers.INSTANCE.getMaterial("dandelion_yellow", 1631)); - Assert.assertEquals(Material.OAK_WALL_SIGN, CraftMagicNumbers.INSTANCE.getMaterial("wall_sign", 1631)); + assertEquals(Material.YELLOW_DYE, CraftMagicNumbers.INSTANCE.getMaterial("dandelion_yellow", 1631)); + assertEquals(Material.OAK_WALL_SIGN, CraftMagicNumbers.INSTANCE.getMaterial("wall_sign", 1631)); } } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/profile/PlayerProfileTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/profile/PlayerProfileTest.java index 45a19d36d9..ef6771a10b 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/profile/PlayerProfileTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/profile/PlayerProfileTest.java @@ -1,5 +1,6 @@ package org.bukkit.craftbukkit.profile; +import static org.junit.jupiter.api.Assertions.*; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import java.net.MalformedURLException; @@ -11,8 +12,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.serialization.ConfigurationSerialization; import org.bukkit.profile.PlayerProfile; import org.bukkit.profile.PlayerTextures; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PlayerProfileTest { @@ -62,19 +62,19 @@ public class PlayerProfileTest { @Test public void testProvidedValues() { 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 public void testProfileCreation() { // Invalid profiles: - Assert.assertThrows(IllegalArgumentException.class, () -> { + assertThrows(IllegalArgumentException.class, () -> { new CraftPlayerProfile(null, null); }); - Assert.assertThrows(IllegalArgumentException.class, () -> { + assertThrows(IllegalArgumentException.class, () -> { new CraftPlayerProfile(null, ""); }); - Assert.assertThrows(IllegalArgumentException.class, () -> { + assertThrows(IllegalArgumentException.class, () -> { new CraftPlayerProfile(null, " "); }); @@ -87,48 +87,48 @@ public class PlayerProfileTest { @Test public void testGameProfileWrapping() { // Invalid profiles: - Assert.assertThrows(NullPointerException.class, () -> { + assertThrows(NullPointerException.class, () -> { new CraftPlayerProfile(null); }); // Valid profiles: CraftPlayerProfile profile1 = new CraftPlayerProfile(new GameProfile(UNIQUE_ID, NAME)); - Assert.assertEquals("Unique id is not the same", UNIQUE_ID, profile1.getUniqueId()); - Assert.assertEquals("Name is not the same", NAME, profile1.getName()); + assertEquals(UNIQUE_ID, profile1.getUniqueId(), "Unique id is not the same"); + assertEquals(NAME, profile1.getName(), "Name is not the same"); CraftPlayerProfile profile2 = new CraftPlayerProfile(new GameProfile(UNIQUE_ID, "")); - Assert.assertEquals("Unique id is not the same", UNIQUE_ID, profile2.getUniqueId()); - Assert.assertEquals("Name is not null", null, profile2.getName()); + assertEquals(UNIQUE_ID, profile2.getUniqueId(), "Unique id is not the same"); + assertEquals(null, profile2.getName(), "Name is not null"); CraftPlayerProfile profile3 = new CraftPlayerProfile(new GameProfile(SystemUtils.NIL_UUID, NAME)); - Assert.assertEquals("Unique id is not null", null, profile3.getUniqueId()); - Assert.assertEquals("Name is not the same", NAME, profile3.getName()); + assertEquals(null, profile3.getUniqueId(), "Unique id is not null"); + assertEquals(NAME, profile3.getName(), "Name is not the same"); } @Test public void testTexturesLoading() { CraftPlayerProfile profile = buildPlayerProfile(); - Assert.assertEquals("Unique id is not the same", UNIQUE_ID, profile.getUniqueId()); - Assert.assertEquals("Name is not the same", NAME, profile.getName()); - Assert.assertEquals("Skin url is not the same", SKIN, profile.getTextures().getSkin()); - Assert.assertEquals("Skin model is not the same", PlayerTextures.SkinModel.SLIM, profile.getTextures().getSkinModel()); - Assert.assertEquals("Cape url is not the same", CAPE, profile.getTextures().getCape()); - Assert.assertEquals("Timestamp is not the same", TIMESTAMP, profile.getTextures().getTimestamp()); + assertEquals(UNIQUE_ID, profile.getUniqueId(), "Unique id is not the same"); + assertEquals(NAME, profile.getName(), "Name is not the same"); + assertEquals(SKIN, profile.getTextures().getSkin(), "Skin url is not the same"); + assertEquals(PlayerTextures.SkinModel.SLIM, profile.getTextures().getSkinModel(), "Skin model is not the same"); + assertEquals(CAPE, profile.getTextures().getCape(), "Cape url is not the same"); + assertEquals(TIMESTAMP, profile.getTextures().getTimestamp(), "Timestamp is not the same"); } @Test public void testBuildGameProfile() { CraftPlayerProfile profile = buildPlayerProfile(); GameProfile gameProfile = profile.buildGameProfile(); - Assert.assertNotNull("GameProfile is null", gameProfile); + assertNotNull(gameProfile, "GameProfile is null"); Property property = CraftPlayerProfile.getProperty(gameProfile, CraftPlayerTextures.PROPERTY_NAME); - Assert.assertNotNull("Textures property is null", property); - Assert.assertEquals("Property values are not the same", VALUE, property.value()); - Assert.assertEquals("Names are not the same", NAME, gameProfile.getName()); - Assert.assertEquals("Unique ids are not the same", UNIQUE_ID, gameProfile.getId()); - Assert.assertTrue("Signature is missing", property.hasSignature()); - Assert.assertTrue("Signature is not valid", CraftProfileProperty.hasValidSignature(property)); + assertNotNull(property, "Textures property is null"); + assertEquals(VALUE, property.value(), "Property values are not the same"); + assertEquals(NAME, gameProfile.getName(), "Names are not the same"); + assertEquals(UNIQUE_ID, gameProfile.getId(), "Unique ids are not the same"); + assertTrue(property.hasSignature(), "Signature is missing"); + assertTrue(CraftProfileProperty.hasValidSignature(property), "Signature is not valid"); } @Test @@ -136,34 +136,34 @@ public class PlayerProfileTest { CraftPlayerProfile profile = buildPlayerProfile(); GameProfile gameProfile1 = 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 public void testSignatureValidation() { CraftPlayerProfile profile = buildPlayerProfile(); - Assert.assertTrue("Signature is not valid", profile.getTextures().isSigned()); + assertTrue(profile.getTextures().isSigned(), "Signature is not valid"); } @Test public void testSignatureInvalidation() { CraftPlayerProfile profile = buildPlayerProfile(); profile.getTextures().setSkin(null); - Assert.assertTrue("Textures has a timestamp", profile.getTextures().getTimestamp() == 0L); - Assert.assertTrue("Textures signature is valid", !profile.getTextures().isSigned()); + assertEquals(0L, profile.getTextures().getTimestamp(), "Textures has a timestamp"); + assertFalse(profile.getTextures().isSigned(), "Textures signature is valid"); // Ensure that the invalidation is preserved when the property is rebuilt: profile.rebuildDirtyProperties(); - Assert.assertTrue("Rebuilt textures has a timestamp", profile.getTextures().getTimestamp() == 0L); - Assert.assertTrue("Rebuilt textures signature is valid", !profile.getTextures().isSigned()); + assertEquals(0L, profile.getTextures().getTimestamp(), "Rebuilt textures has a timestamp"); + assertFalse(profile.getTextures().isSigned(), "Rebuilt textures signature is valid"); } @Test public void testSetSkinResetsSkinModel() { 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); - 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 @@ -171,35 +171,35 @@ public class PlayerProfileTest { CraftPlayerProfile profile = buildPlayerProfile(); CraftPlayerProfile profile2 = new CraftPlayerProfile(new GameProfile(UNIQUE_ID, NAME)); - Assert.assertTrue("profile has no textures", !profile.getTextures().isEmpty()); - Assert.assertTrue("profile2 has textures", profile2.getTextures().isEmpty()); + assertFalse(profile.getTextures().isEmpty(), "profile has no textures"); + assertTrue(profile2.getTextures().isEmpty(), "profile2 has textures"); profile2.setTextures(profile.getTextures()); - Assert.assertTrue("profile2 has no textures", !profile2.getTextures().isEmpty()); - Assert.assertEquals("copied profile textures are not the same", profile.getTextures(), profile2.getTextures()); + assertFalse(profile2.getTextures().isEmpty(), "profile2 has no textures"); + assertEquals(profile.getTextures(), profile2.getTextures(), "copied profile textures are not the same"); profile2.setTextures(null); - Assert.assertTrue("cleared profile2 has textures", profile2.getTextures().isEmpty()); - Assert.assertTrue("cleared profile2 has textures timestamp", profile2.getTextures().getTimestamp() == 0L); - Assert.assertTrue("cleared profile2 has signed textures", !profile2.getTextures().isSigned()); + assertTrue(profile2.getTextures().isEmpty(), "cleared profile2 has textures"); + assertEquals(0L, profile2.getTextures().getTimestamp(), "cleared profile2 has textures timestamp"); + assertFalse(profile2.getTextures().isSigned(), "cleared profile2 has signed textures"); } @Test public void testClearTextures() { CraftPlayerProfile profile = buildPlayerProfile(); - Assert.assertTrue("profile has no textures", !profile.getTextures().isEmpty()); + assertFalse(profile.getTextures().isEmpty(), "profile has no textures"); profile.getTextures().clear(); - Assert.assertTrue("cleared profile has textures", profile.getTextures().isEmpty()); - Assert.assertTrue("cleared profile has textures timestamp", profile.getTextures().getTimestamp() == 0L); - Assert.assertTrue("cleared profile has signed textures", !profile.getTextures().isSigned()); + assertTrue(profile.getTextures().isEmpty(), "cleared profile has textures"); + assertEquals(0L, profile.getTextures().getTimestamp(), "cleared profile has textures timestamp"); + assertFalse(profile.getTextures().isSigned(), "cleared profile has signed textures"); } @Test public void testCustomSkin() { CraftPlayerProfile profile = new CraftPlayerProfile(UNIQUE_ID, NAME); 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 @@ -211,35 +211,35 @@ public class PlayerProfileTest { CraftPlayerProfile profile5 = new CraftPlayerProfile(UNIQUE_ID, null); CraftPlayerProfile profile6 = new CraftPlayerProfile(null, NAME); - Assert.assertEquals("profile1 and profile2 are not equal", profile1, profile2); - Assert.assertEquals("profile3 and profile4 are not equal", profile3, profile4); - Assert.assertNotEquals("profile1 and profile3 are equal", profile1, profile3); - Assert.assertNotEquals("profile4 and profile5 are equal", profile4, profile5); - Assert.assertNotEquals("profile4 and profile6 are equal", profile4, profile6); + assertEquals(profile1, profile2, "profile1 and profile2 are not equal"); + assertEquals(profile3, profile4, "profile3 and profile4 are not equal"); + assertNotEquals(profile1, profile3, "profile1 and profile3 are equal"); + assertNotEquals(profile4, profile5, "profile4 and profile5 are equal"); + assertNotEquals(profile4, profile6, "profile4 and profile6 are equal"); } @Test public void testTexturesEquals() { CraftPlayerProfile profile1 = 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); - 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); - Assert.assertEquals("Modified profile textures are not equal", profile1.getTextures(), profile2.getTextures()); + assertEquals(profile1.getTextures(), profile2.getTextures(), "Modified profile textures are not equal"); } @Test public void testClone() { PlayerProfile profile = buildPlayerProfile(); 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): copy.getTextures().setSkin(null); - Assert.assertEquals("copy is not independent", SKIN, profile.getTextures().getSkin()); + assertEquals(SKIN, profile.getTextures().getSkin(), "copy is not independent"); } @Test @@ -255,7 +255,7 @@ public class PlayerProfileTest { configuration = new YamlConfiguration(); configuration.loadFromString(saved); - Assert.assertTrue(configuration.contains("test")); - Assert.assertEquals("Profiles are not equal", playerProfile, configuration.get("test")); + assertTrue(configuration.contains("test")); + assertEquals(playerProfile, configuration.get("test"), "Profiles are not equal"); } } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/util/CraftChatMessageTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/util/CraftChatMessageTest.java index e25b22987e..1044b913f8 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/util/CraftChatMessageTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/util/CraftChatMessageTest.java @@ -1,11 +1,11 @@ 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.IChatBaseComponent; import net.minecraft.network.chat.IChatMutableComponent; import net.minecraft.network.chat.contents.LiteralContents; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CraftChatMessageTest { @@ -35,7 +35,7 @@ public class CraftChatMessageTest { // dont retain line returns multiple components 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(/*§r*/"Foo", CraftChatMessage.fromComponent(components[1])); assertEquals("§5Test", CraftChatMessage.fromComponent(components[2])); @@ -85,14 +85,14 @@ public class CraftChatMessageTest { private void testString(String input, String expected, boolean keepNewLines) { IChatBaseComponent cmp = CraftChatMessage.fromString(input, keepNewLines)[0]; String actual = CraftChatMessage.fromComponent(cmp); - assertEquals("\nComponent: " + cmp + "\n", expected, actual); + assertEquals(expected, actual, "\nComponent: " + cmp + "\n"); } private void testPlainString(String expected) { IChatBaseComponent component = CraftChatMessage.fromString(expected, false, true)[0]; String actual = CraftChatMessage.fromComponent(component); - assertEquals("fromComponent does not match input: " + component, expected, actual); - assertTrue("Non-plain component: " + component, !containsNonPlainComponent(component)); + assertEquals(expected, actual, "fromComponent does not match input: " + component); + assertFalse(containsNonPlainComponent(component), "Non-plain component: " + component); } private boolean containsNonPlainComponent(IChatBaseComponent component) { @@ -106,10 +106,10 @@ public class CraftChatMessageTest { private void testComponent(String expected, IChatBaseComponent 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]; String actualExpectedCmp = CraftChatMessage.fromComponent(expectedCmp); - assertEquals("\nComponent: " + expectedCmp + "\n", expected, actualExpectedCmp); + assertEquals(expected, actualExpectedCmp, "\nComponent: " + expectedCmp + "\n"); } } diff --git a/paper-server/src/test/java/org/bukkit/enchantments/EnchantmentTargetTest.java b/paper-server/src/test/java/org/bukkit/enchantments/EnchantmentTargetTest.java index 69391d8281..d180cc2b64 100644 --- a/paper-server/src/test/java/org/bukkit/enchantments/EnchantmentTargetTest.java +++ b/paper-server/src/test/java/org/bukkit/enchantments/EnchantmentTargetTest.java @@ -1,13 +1,13 @@ package org.bukkit.enchantments; +import static org.junit.jupiter.api.Assertions.*; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.item.Item; import net.minecraft.world.item.enchantment.EnchantmentSlotType; import org.bukkit.Material; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class EnchantmentTargetTest extends AbstractTestingBase { @@ -27,7 +27,7 @@ public class EnchantmentTargetTest extends AbstractTestingBase { break; } - Assert.assertNotNull("No bukkit target for slot " + nmsSlot, bukkitTarget); + assertNotNull(bukkitTarget, "No bukkit target for slot " + nmsSlot); for (Item item : BuiltInRegistries.ITEM) { Material material = CraftMagicNumbers.getMaterial(item); @@ -35,7 +35,7 @@ public class EnchantmentTargetTest extends AbstractTestingBase { boolean nms = nmsSlot.canEnchant(item); boolean bukkit = bukkitTarget.includes(material); - Assert.assertEquals("Slot mismatch for " + bukkitTarget + " and " + material, nms, bukkit); + assertEquals(nms, bukkit, "Slot mismatch for " + bukkitTarget + " and " + material); } } } diff --git a/paper-server/src/test/java/org/bukkit/entity/BoatTest.java b/paper-server/src/test/java/org/bukkit/entity/BoatTest.java index 513e898c8f..7d50e204d5 100644 --- a/paper-server/src/test/java/org/bukkit/entity/BoatTest.java +++ b/paper-server/src/test/java/org/bukkit/entity/BoatTest.java @@ -3,7 +3,7 @@ package org.bukkit.entity; import net.minecraft.world.entity.vehicle.EntityBoat; import org.bukkit.craftbukkit.entity.CraftBoat; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BoatTest extends AbstractTestingBase { diff --git a/paper-server/src/test/java/org/bukkit/entity/EnderDragonPhaseTest.java b/paper-server/src/test/java/org/bukkit/entity/EnderDragonPhaseTest.java index 200f96a338..bc6d2be5b0 100644 --- a/paper-server/src/test/java/org/bukkit/entity/EnderDragonPhaseTest.java +++ b/paper-server/src/test/java/org/bukkit/entity/EnderDragonPhaseTest.java @@ -1,9 +1,9 @@ package org.bukkit.entity; +import static org.junit.jupiter.api.Assertions.*; import net.minecraft.world.entity.boss.enderdragon.phases.DragonControllerPhase; import org.bukkit.craftbukkit.entity.CraftEnderDragon; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class EnderDragonPhaseTest { @@ -11,38 +11,38 @@ public class EnderDragonPhaseTest { public void testNotNull() { for (EnderDragon.Phase phase : EnderDragon.Phase.values()) { DragonControllerPhase dragonControllerPhase = CraftEnderDragon.getMinecraftPhase(phase); - Assert.assertNotNull(phase.name(), dragonControllerPhase); - Assert.assertNotNull(phase.name(), CraftEnderDragon.getBukkitPhase(dragonControllerPhase)); + assertNotNull(dragonControllerPhase, phase.name()); + assertNotNull(CraftEnderDragon.getBukkitPhase(dragonControllerPhase), phase.name()); } } @Test public void testBukkitToMinecraft() { - Assert.assertEquals("CIRCLING", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.CIRCLING), DragonControllerPhase.HOLDING_PATTERN); - Assert.assertEquals("STRAFING", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.STRAFING), DragonControllerPhase.STRAFE_PLAYER); - Assert.assertEquals("FLY_TO_PORTAL", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.FLY_TO_PORTAL), DragonControllerPhase.LANDING_APPROACH); - Assert.assertEquals("LAND_ON_PORTAL", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.LAND_ON_PORTAL), DragonControllerPhase.LANDING); - Assert.assertEquals("LEAVE_PORTAL", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.LEAVE_PORTAL), DragonControllerPhase.TAKEOFF); - Assert.assertEquals("BREATH_ATTACK", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.BREATH_ATTACK), DragonControllerPhase.SITTING_FLAMING); - Assert.assertEquals("SEARCH_FOR_BREATH_ATTACK_TARGET", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.SEARCH_FOR_BREATH_ATTACK_TARGET), DragonControllerPhase.SITTING_SCANNING); - Assert.assertEquals("ROAR_BEFORE_ATTACK", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.ROAR_BEFORE_ATTACK), DragonControllerPhase.SITTING_ATTACKING); - Assert.assertEquals("CHARGE_PLAYER", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.CHARGE_PLAYER), DragonControllerPhase.CHARGING_PLAYER); - Assert.assertEquals("DYING", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.DYING), DragonControllerPhase.DYING); - Assert.assertEquals("HOVER", CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.HOVER), DragonControllerPhase.HOVERING); + assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.CIRCLING), DragonControllerPhase.HOLDING_PATTERN, "CIRCLING"); + assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.STRAFING), DragonControllerPhase.STRAFE_PLAYER, "STRAFING"); + assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.FLY_TO_PORTAL), DragonControllerPhase.LANDING_APPROACH, "FLY_TO_PORTAL"); + assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.LAND_ON_PORTAL), DragonControllerPhase.LANDING, "LAND_ON_PORTAL"); + assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.LEAVE_PORTAL), DragonControllerPhase.TAKEOFF, "LEAVE_PORTAL"); + assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.BREATH_ATTACK), DragonControllerPhase.SITTING_FLAMING, "BREATH_ATTACK"); + assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.SEARCH_FOR_BREATH_ATTACK_TARGET), DragonControllerPhase.SITTING_SCANNING, "SEARCH_FOR_BREATH_ATTACK_TARGET"); + assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.ROAR_BEFORE_ATTACK), DragonControllerPhase.SITTING_ATTACKING, "ROAR_BEFORE_ATTACK"); + assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.CHARGE_PLAYER), DragonControllerPhase.CHARGING_PLAYER, "CHARGE_PLAYER"); + assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.DYING), DragonControllerPhase.DYING, "DYING"); + assertEquals(CraftEnderDragon.getMinecraftPhase(EnderDragon.Phase.HOVER), DragonControllerPhase.HOVERING, "HOVER"); } @Test public void testMinecraftToBukkit() { - Assert.assertEquals("CIRCLING", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.HOLDING_PATTERN), EnderDragon.Phase.CIRCLING); - Assert.assertEquals("STRAFING", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.STRAFE_PLAYER), EnderDragon.Phase.STRAFING); - Assert.assertEquals("FLY_TO_PORTAL", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.LANDING_APPROACH), EnderDragon.Phase.FLY_TO_PORTAL); - Assert.assertEquals("LAND_ON_PORTAL", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.LANDING), EnderDragon.Phase.LAND_ON_PORTAL); - Assert.assertEquals("LEAVE_PORTAL", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.TAKEOFF), EnderDragon.Phase.LEAVE_PORTAL); - Assert.assertEquals("BREATH_ATTACK", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.SITTING_FLAMING), EnderDragon.Phase.BREATH_ATTACK); - Assert.assertEquals("SEARCH_FOR_BREATH_ATTACK_TARGET", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.SITTING_SCANNING), EnderDragon.Phase.SEARCH_FOR_BREATH_ATTACK_TARGET); - Assert.assertEquals("ROAR_BEFORE_ATTACK", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.SITTING_ATTACKING), EnderDragon.Phase.ROAR_BEFORE_ATTACK); - Assert.assertEquals("CHARGE_PLAYER", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.CHARGING_PLAYER), EnderDragon.Phase.CHARGE_PLAYER); - Assert.assertEquals("DYING", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.DYING), EnderDragon.Phase.DYING); - Assert.assertEquals("HOVER", CraftEnderDragon.getBukkitPhase(DragonControllerPhase.HOVERING), EnderDragon.Phase.HOVER); + assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.HOLDING_PATTERN), EnderDragon.Phase.CIRCLING, "CIRCLING"); + assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.STRAFE_PLAYER), EnderDragon.Phase.STRAFING, "STRAFING"); + assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.LANDING_APPROACH), EnderDragon.Phase.FLY_TO_PORTAL, "FLY_TO_PORTAL"); + assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.LANDING), EnderDragon.Phase.LAND_ON_PORTAL, "LAND_ON_PORTAL"); + assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.TAKEOFF), EnderDragon.Phase.LEAVE_PORTAL, "LEAVE_PORTAL"); + assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.SITTING_FLAMING), EnderDragon.Phase.BREATH_ATTACK, "BREATH_ATTACK"); + assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.SITTING_SCANNING), EnderDragon.Phase.SEARCH_FOR_BREATH_ATTACK_TARGET, "SEARCH_FOR_BREATH_ATTACK_TARGET"); + assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.SITTING_ATTACKING), EnderDragon.Phase.ROAR_BEFORE_ATTACK, "ROAR_BEFORE_ATTACK"); + assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.CHARGING_PLAYER), EnderDragon.Phase.CHARGE_PLAYER, "CHARGE_PLAYER"); + assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.DYING), EnderDragon.Phase.DYING, "DYING"); + assertEquals(CraftEnderDragon.getBukkitPhase(DragonControllerPhase.HOVERING), EnderDragon.Phase.HOVER, "HOVER"); } } diff --git a/paper-server/src/test/java/org/bukkit/entity/EntityTypesTest.java b/paper-server/src/test/java/org/bukkit/entity/EntityTypesTest.java index 366509f17b..220f7e388b 100644 --- a/paper-server/src/test/java/org/bukkit/entity/EntityTypesTest.java +++ b/paper-server/src/test/java/org/bukkit/entity/EntityTypesTest.java @@ -1,5 +1,6 @@ package org.bukkit.entity; +import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; import java.util.Set; import java.util.stream.Collectors; @@ -7,8 +8,7 @@ import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.MinecraftKey; import net.minecraft.world.entity.EntityTypes; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class EntityTypesTest extends AbstractTestingBase { @@ -20,12 +20,12 @@ public class EntityTypesTest extends AbstractTestingBase { MinecraftKey key = EntityTypes.getKey(nms); 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 @@ -33,7 +33,7 @@ public class EntityTypesTest extends AbstractTestingBase { for (EntityType entityType : EntityType.values()) { // Currently EntityType#getTranslationKey has a validation for null name then for test skip this and check correct names. if (entityType.getName() != null) { - Assert.assertNotNull("Nulllable translation key for " + entityType, entityType.getTranslationKey()); + assertNotNull(entityType.getTranslationKey(), "Nulllable translation key for " + entityType); } } } diff --git a/paper-server/src/test/java/org/bukkit/entity/PandaGeneTest.java b/paper-server/src/test/java/org/bukkit/entity/PandaGeneTest.java index 0b8e214b25..ccd4263e50 100644 --- a/paper-server/src/test/java/org/bukkit/entity/PandaGeneTest.java +++ b/paper-server/src/test/java/org/bukkit/entity/PandaGeneTest.java @@ -1,9 +1,9 @@ package org.bukkit.entity; +import static org.junit.jupiter.api.Assertions.*; import net.minecraft.world.entity.animal.EntityPanda; import org.bukkit.craftbukkit.entity.CraftPanda; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PandaGeneTest { @@ -12,9 +12,9 @@ public class PandaGeneTest { for (Panda.Gene gene : Panda.Gene.values()) { EntityPanda.Gene nms = CraftPanda.toNms(gene); - Assert.assertNotNull("NMS gene null for " + gene, nms); - Assert.assertEquals("Recessive status did not match " + gene, gene.isRecessive(), nms.isRecessive()); - Assert.assertEquals("Gene did not convert back " + gene, gene, CraftPanda.fromNms(nms)); + assertNotNull(nms, "NMS gene null for " + gene); + assertEquals(gene.isRecessive(), nms.isRecessive(), "Recessive status did not match " + gene); + 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()) { Panda.Gene bukkit = CraftPanda.fromNms(gene); - Assert.assertNotNull("Bukkit gene null for " + gene, bukkit); - Assert.assertEquals("Recessive status did not match " + gene, gene.isRecessive(), bukkit.isRecessive()); - Assert.assertEquals("Gene did not convert back " + gene, gene, CraftPanda.toNms(bukkit)); + assertNotNull(bukkit, "Bukkit gene null for " + gene); + assertEquals(gene.isRecessive(), bukkit.isRecessive(), "Recessive status did not match " + gene); + assertEquals(gene, CraftPanda.toNms(bukkit), "Gene did not convert back " + gene); } } } diff --git a/paper-server/src/test/java/org/bukkit/entity/SpawnCategoryTest.java b/paper-server/src/test/java/org/bukkit/entity/SpawnCategoryTest.java index 0084138b82..53af247a3e 100644 --- a/paper-server/src/test/java/org/bukkit/entity/SpawnCategoryTest.java +++ b/paper-server/src/test/java/org/bukkit/entity/SpawnCategoryTest.java @@ -2,7 +2,7 @@ package org.bukkit.entity; import net.minecraft.world.entity.EnumCreatureType; import org.bukkit.craftbukkit.util.CraftSpawnCategory; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SpawnCategoryTest { diff --git a/paper-server/src/test/java/org/bukkit/entity/TropicalFishTest.java b/paper-server/src/test/java/org/bukkit/entity/TropicalFishTest.java index aa70881a77..80c29f1b2e 100644 --- a/paper-server/src/test/java/org/bukkit/entity/TropicalFishTest.java +++ b/paper-server/src/test/java/org/bukkit/entity/TropicalFishTest.java @@ -1,11 +1,11 @@ package org.bukkit.entity; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import org.bukkit.DyeColor; import org.bukkit.craftbukkit.entity.CraftTropicalFish; import org.bukkit.entity.TropicalFish.Pattern; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TropicalFishTest { @@ -36,9 +36,9 @@ public class TropicalFishTest { } private void testVariant(int variant, DyeColor bodyColor, DyeColor patternColor, Pattern pattern) { - assertThat("variant write", CraftTropicalFish.getData(patternColor, bodyColor, pattern), is(variant)); - assertThat("pattern colour read", CraftTropicalFish.getPatternColor(variant), is(patternColor)); - assertThat("body colour read", CraftTropicalFish.getBodyColor(variant), is(bodyColor)); - assertThat("pattern read", CraftTropicalFish.getPattern(variant), is(pattern)); + assertThat(CraftTropicalFish.getData(patternColor, bodyColor, pattern), is(variant), "variant write"); + assertThat(CraftTropicalFish.getPatternColor(variant), is(patternColor), "pattern colour read"); + assertThat(CraftTropicalFish.getBodyColor(variant), is(bodyColor), "body colour read"); + assertThat(CraftTropicalFish.getPattern(variant), is(pattern), "pattern read"); } } diff --git a/paper-server/src/test/java/org/bukkit/entity/memory/CraftMemoryKeyTest.java b/paper-server/src/test/java/org/bukkit/entity/memory/CraftMemoryKeyTest.java index 6abd61ed50..fe17d6e580 100644 --- a/paper-server/src/test/java/org/bukkit/entity/memory/CraftMemoryKeyTest.java +++ b/paper-server/src/test/java/org/bukkit/entity/memory/CraftMemoryKeyTest.java @@ -1,57 +1,57 @@ package org.bukkit.entity.memory; +import static org.junit.jupiter.api.Assertions.*; import net.minecraft.core.GlobalPos; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.entity.ai.memory.MemoryModuleType; import org.bukkit.Location; import org.bukkit.craftbukkit.entity.memory.CraftMemoryKey; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class CraftMemoryKeyTest extends AbstractTestingBase { @Test public void shouldConvertBukkitHomeKeyToNMSRepresentation() { MemoryModuleType nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.HOME); - Assert.assertEquals("MemoryModuleType should be HOME", MemoryModuleType.HOME, nmsHomeKey); + assertEquals(MemoryModuleType.HOME, nmsHomeKey, "MemoryModuleType should be HOME"); } @Test public void shouldConvertBukkitJobSiteKeyToNMSRepresentation() { MemoryModuleType 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 public void shouldConvertBukkitMeetingPointKeyToNMSRepresentation() { MemoryModuleType 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 public void shouldConvertNMSHomeKeyToBukkitRepresentation() { MemoryKey bukkitHomeKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.HOME); - Assert.assertEquals("MemoryModuleType should be HOME", MemoryKey.HOME, bukkitHomeKey); + assertEquals(MemoryKey.HOME, bukkitHomeKey, "MemoryModuleType should be HOME"); } @Test public void shouldConvertNMSJobSiteKeyToBukkitRepresentation() { MemoryKey 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 public void shouldConvertNMSMeetingPointKeyToBukkitRepresentation() { MemoryKey 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 public void shouldReturnNullWhenBukkitRepresentationOfKeyisNotAvailable() { MemoryKey bukkitNoKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.NEAREST_LIVING_ENTITIES); - Assert.assertNull("MemoryModuleType should be null", bukkitNoKey); + assertNull(bukkitNoKey, "MemoryModuleType should be null"); } @Test @@ -59,18 +59,18 @@ public class CraftMemoryKeyTest extends AbstractTestingBase { for (MemoryModuleType memoryModuleType : BuiltInRegistries.MEMORY_MODULE_TYPE) { if (!memoryModuleType.getCodec().isPresent()) { MemoryKey bukkitNoKey = CraftMemoryKey.minecraftToBukkit(memoryModuleType); - Assert.assertNull("MemoryModuleType should be null", bukkitNoKey); + assertNull(bukkitNoKey, "MemoryModuleType should be null"); } } } @Test - @Ignore("Unit type not yet implemented") + @Disabled("Unit type not yet implemented") public void shouldReturnAnInstanceOfMemoryKeyWhenBukkitRepresentationOfKeyisAvailableAndSerializerIsPresent() { for (MemoryModuleType memoryModuleType : BuiltInRegistries.MEMORY_MODULE_TYPE) { if (memoryModuleType.getCodec().isPresent()) { 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)); } } } diff --git a/paper-server/src/test/java/org/bukkit/generator/structure/StructureTest.java b/paper-server/src/test/java/org/bukkit/generator/structure/StructureTest.java index 6ae21e6c6e..8c0669cf93 100644 --- a/paper-server/src/test/java/org/bukkit/generator/structure/StructureTest.java +++ b/paper-server/src/test/java/org/bukkit/generator/structure/StructureTest.java @@ -1,5 +1,6 @@ package org.bukkit.generator.structure; +import static org.junit.jupiter.api.Assertions.*; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import net.minecraft.core.IRegistry; @@ -9,8 +10,7 @@ import org.bukkit.NamespacedKey; import org.bukkit.Registry; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class StructureTest extends AbstractTestingBase { @@ -25,7 +25,7 @@ public class StructureTest extends AbstractTestingBase { } 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 { 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) { - Assert.fail("No Bukkit default structure for " + minecraftKey); + fail("No Bukkit default structure for " + minecraftKey); } 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) { - Assert.fail("Bukkit field is not of type structure for" + minecraftKey); + fail("Bukkit field is not of type structure for" + minecraftKey); } } } diff --git a/paper-server/src/test/java/org/bukkit/generator/structure/StructureTypeTest.java b/paper-server/src/test/java/org/bukkit/generator/structure/StructureTypeTest.java index c72020db9c..69bccab363 100644 --- a/paper-server/src/test/java/org/bukkit/generator/structure/StructureTypeTest.java +++ b/paper-server/src/test/java/org/bukkit/generator/structure/StructureTypeTest.java @@ -1,5 +1,6 @@ package org.bukkit.generator.structure; +import static org.junit.jupiter.api.Assertions.*; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import net.minecraft.core.registries.BuiltInRegistries; @@ -8,8 +9,7 @@ import org.bukkit.NamespacedKey; import org.bukkit.Registry; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class StructureTypeTest extends AbstractTestingBase { @@ -24,7 +24,7 @@ public class StructureTypeTest extends AbstractTestingBase { } 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 { 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) { - Assert.fail("No Bukkit default structure type for " + minecraftKey); + fail("No Bukkit default enchantment for " + minecraftKey); } 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) { - Assert.fail("Bukkit field is not of type structure type for" + minecraftKey); + fail("Bukkit field is not of type enchantment for" + minecraftKey); } } } diff --git a/paper-server/src/test/java/org/bukkit/map/MapTest.java b/paper-server/src/test/java/org/bukkit/map/MapTest.java index e47e7c009d..27b2fd8154 100644 --- a/paper-server/src/test/java/org/bukkit/map/MapTest.java +++ b/paper-server/src/test/java/org/bukkit/map/MapTest.java @@ -1,14 +1,14 @@ package org.bukkit.map; +import static org.junit.jupiter.api.Assertions.*; import java.awt.Color; import java.util.concurrent.ExecutionException; import java.util.logging.Level; import java.util.logging.Logger; import net.minecraft.world.level.material.MaterialMapColor; import org.bukkit.craftbukkit.map.CraftMapColorCache; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; 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 public void testMapColorCacheBuilding() throws ExecutionException, InterruptedException { CraftMapColorCache craftMapColorCache = new CraftMapColorCache(logger); @@ -72,7 +72,7 @@ public class MapTest { for (int g = 0; g < 256; g++) { for (int b = 0; b < 256; 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())); } } } diff --git a/paper-server/src/test/java/org/bukkit/potion/PotionTest.java b/paper-server/src/test/java/org/bukkit/potion/PotionTest.java index e13bd7e8bc..54d586757d 100644 --- a/paper-server/src/test/java/org/bukkit/potion/PotionTest.java +++ b/paper-server/src/test/java/org/bukkit/potion/PotionTest.java @@ -1,6 +1,6 @@ package org.bukkit.potion; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.EnumMap; import java.util.List; import java.util.Map; @@ -11,7 +11,7 @@ import net.minecraft.world.effect.MobEffectList; import net.minecraft.world.item.alchemy.PotionRegistry; import org.bukkit.craftbukkit.potion.CraftPotionEffectType; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PotionTest extends AbstractTestingBase { @Test @@ -21,10 +21,10 @@ public class PotionTest extends AbstractTestingBase { List eff = reg.getEffects(); if (eff.size() != 1) continue; PotionEffectType type = CraftPotionEffectType.minecraftToBukkit(eff.get(0).getEffect()); - assertNotNull(String.valueOf(reg), type); + assertNotNull(type, String.valueOf(reg)); PotionType enumType = PotionType.getByEffect(type); - assertNotNull(type.getName(), enumType); + assertNotNull(enumType, type.getName()); effects.put(enumType, enumType.name()); } @@ -39,11 +39,11 @@ public class PotionTest extends AbstractTestingBase { PotionEffectType bukkit = CraftPotionEffectType.minecraftToBukkit(nms); - assertNotNull("No Bukkit type for " + key, bukkit); - assertFalse("No name for " + key, bukkit.getName().contains("UNKNOWN")); + assertNotNull(bukkit, "No Bukkit type for " + key); + assertFalse(bukkit.getName().contains("UNKNOWN"), "No name for " + key); 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); } } } diff --git a/paper-server/src/test/java/org/bukkit/support/AbstractTestingBase.java b/paper-server/src/test/java/org/bukkit/support/AbstractTestingBase.java index ecfac636c0..777d41856d 100644 --- a/paper-server/src/test/java/org/bukkit/support/AbstractTestingBase.java +++ b/paper-server/src/test/java/org/bukkit/support/AbstractTestingBase.java @@ -1,5 +1,6 @@ package org.bukkit.support; +import static org.junit.jupiter.api.Assertions.*; import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.MoreExecutors; import java.util.List; @@ -24,7 +25,6 @@ import net.minecraft.world.level.biome.BiomeBase; import org.bukkit.Material; import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.util.CraftMagicNumbers; -import org.junit.Assert; /** * If you are getting: java.lang.ExceptionInInitializerError @@ -73,6 +73,6 @@ public abstract class AbstractTestingBase { } } 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() + ")"); } } diff --git a/paper-server/src/test/java/org/bukkit/support/MatcherAssert.java b/paper-server/src/test/java/org/bukkit/support/MatcherAssert.java new file mode 100644 index 0000000000..b100262e88 --- /dev/null +++ b/paper-server/src/test/java/org/bukkit/support/MatcherAssert.java @@ -0,0 +1,36 @@ +package org.bukkit.support; + +import org.hamcrest.Matcher; + +/** + * Custom assertThat methods, where the reason is put at the end of the method call. + * To better match with JUnit 5 argument order and also help with readability for longer reasons. + *
+ *
+ * assertThat(String.format("""
+ *         The block data created for the material %s is not an instance of the data class from that material.
+ *         """, material), blockData, is(instanceOf(expectedClass)));
+ * 
+ * vs. + *
+ * assertThat(blockData, is(instanceOf(expectedClass)), String.format("""
+ *         The block data created for the material %s is not an instance of the data class from that material.
+ *         """, material));
+ * 
+ */ +public final class MatcherAssert { + + private MatcherAssert() {} + + public static void assertThat(T actual, Matcher matcher) { + org.hamcrest.MatcherAssert.assertThat(actual, matcher); + } + + public static void assertThat(T actual, Matcher matcher, String reason) { + org.hamcrest.MatcherAssert.assertThat(reason, actual, matcher); + } + + public static void assertThat(boolean assertion, String reason) { + org.hamcrest.MatcherAssert.assertThat(reason, assertion); + } +}