diff --git a/README.md b/README.md index 2f8abbb9..4e652394 100644 --- a/README.md +++ b/README.md @@ -83,12 +83,12 @@ Code Requirements * Do not attempt to fix multiple problems with a single patch or pull request. * Avoid moving or renaming classes. * All non-private methods and constructors must have specified nullability through [annotations](https://github.com/JetBrains/java-annotations) -* All classes/methods/fields related to a [Minecraft Experimental Feature](https://minecraft.fandom.com/wiki/Experimental_Gameplay) must be marked with [`@MinecraftExperimental`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/MinecraftExperimental.html) +* All classes/methods/fields related to a [Minecraft Experimental Feature](https://minecraft.wiki/w/Experimental_Gameplay) must be marked with [`@MinecraftExperimental`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/MinecraftExperimental.html) * If necessary, you may consider the use of one of the following [ApiStatus Annotations](https://javadoc.io/doc/org.jetbrains/annotations-java5/23.0.0/org/jetbrains/annotations/ApiStatus.html): * [`@ApiStatus.Experimental`](https://javadoc.io/doc/org.jetbrains/annotations-java5/23.0.0/org/jetbrains/annotations/ApiStatus.Experimental.html) for API that is subject to change * [`@ApiStatus.Internal`](https://javadoc.io/doc/org.jetbrains/annotations-java5/23.0.0/org/jetbrains/annotations/ApiStatus.Internal.html) for API that is intended only for internal use in the Bukkit project and will not adhere to Bukkit's API contract -Bukkit/CraftBukkit employs [JUnit 4](https://www.vogella.com/tutorials/JUnit4/article.html) for testing. Pull Requests(PR) should attempt to integrate within that framework as appropriate. +Bukkit/CraftBukkit employs [JUnit 5](https://www.vogella.com/tutorials/JUnit/article.html) for testing. Pull Requests(PR) should attempt to integrate within that framework as appropriate. Bukkit is a large project and what seems simple to a PR author at the time of writing may easily be overlooked by other authors and updates. Including unit tests with your PR will help to ensure the PR can be easily maintained over time and encourage the Spigot team to pull the PR. diff --git a/pom.xml b/pom.xml index 7e884b8b..d1d8a7a2 100644 --- a/pom.xml +++ b/pom.xml @@ -86,15 +86,15 @@ - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter + 5.10.0 test org.hamcrest - hamcrest-library - 1.3 + hamcrest + 2.2 test @@ -193,8 +193,6 @@ https://guava.dev/releases/31.1-jre/api/docs/ - https://javadoc.io/doc/org.yaml/snakeyaml/2.0/ - https://javadoc.io/doc/org.jetbrains/annotations-java5/24.0.1/ @@ -205,6 +203,11 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.0 + diff --git a/src/main/java/org/bukkit/FeatureFlag.java b/src/main/java/org/bukkit/FeatureFlag.java index 3b11344b..1d93e26b 100644 --- a/src/main/java/org/bukkit/FeatureFlag.java +++ b/src/main/java/org/bukkit/FeatureFlag.java @@ -4,6 +4,9 @@ import org.jetbrains.annotations.ApiStatus; /** * This represents a Feature Flag for a World. + *
+ * Flags which are unavailable in the current version will be null and/or + * removed. */ @ApiStatus.Experimental public interface FeatureFlag extends Keyed { @@ -15,7 +18,13 @@ public interface FeatureFlag extends Keyed { /** * AVAILABLE BETWEEN VERSIONS: 1.19 - 1.19.4 + * + * @deprecated not available since 1.20 */ + @Deprecated @MinecraftExperimental public static final FeatureFlag UPDATE_1_20 = Bukkit.getUnsafe().getFeatureFlag(NamespacedKey.minecraft("update_1_20")); + + @MinecraftExperimental + public static final FeatureFlag TRADE_REBALANCE = Bukkit.getUnsafe().getFeatureFlag(NamespacedKey.minecraft("trade_rebalance")); } diff --git a/src/main/java/org/bukkit/GameRule.java b/src/main/java/org/bukkit/GameRule.java index 9443baf6..3ac563da 100644 --- a/src/main/java/org/bukkit/GameRule.java +++ b/src/main/java/org/bukkit/GameRule.java @@ -10,7 +10,7 @@ import org.jetbrains.annotations.Nullable; * GameRules dictate certain behavior within Minecraft itself *
* For more information please visit the - * Minecraft + * Minecraft * Wiki * * @param type of rule (Boolean or Integer) diff --git a/src/main/java/org/bukkit/HeightMap.java b/src/main/java/org/bukkit/HeightMap.java index 27e7b6e7..db6fcd63 100644 --- a/src/main/java/org/bukkit/HeightMap.java +++ b/src/main/java/org/bukkit/HeightMap.java @@ -3,8 +3,7 @@ package org.bukkit; /** * Further information regarding heightmaps. * - * @see Gamepedia Chunk - * Format + * @see Minecraft Wiki */ public enum HeightMap { diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index 15e97ae2..05ff6ef3 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -7923,7 +7923,7 @@ public enum Material implements Keyed, Translatable { *
  • Only occluding blocks can be "powered" ({@link Block#isBlockPowered()}). * * This list may be inconclusive. For a full list of the side effects of an occluding - * block, see the Minecraft Wiki. + * block, see the Minecraft Wiki. * * @return True if this material is a block and occludes light */ diff --git a/src/main/java/org/bukkit/MinecraftExperimental.java b/src/main/java/org/bukkit/MinecraftExperimental.java index 4e7e6921..2365a8c6 100644 --- a/src/main/java/org/bukkit/MinecraftExperimental.java +++ b/src/main/java/org/bukkit/MinecraftExperimental.java @@ -9,7 +9,7 @@ import org.jetbrains.annotations.ApiStatus; /** * Indicates that the annotated element (class, method, field, etc.) is part of a - * minecraft experimental feature + * minecraft experimental feature * and is subject to changes by Mojang. *

    * Note: Elements marked with this annotation require the use of a datapack or otherwise diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java index 59cc5215..bc94011a 100644 --- a/src/main/java/org/bukkit/UnsafeValues.java +++ b/src/main/java/org/bukkit/UnsafeValues.java @@ -56,8 +56,7 @@ public interface UnsafeValues { * The advancement format is governed by Minecraft and has no specified * layout. *
    - * It is currently a JSON object, as described by the Minecraft Wiki: - * http://minecraft.gamepedia.com/Advancements + * It is currently a JSON object, as described by the Minecraft wiki. *
    * Loaded advancements will be stored and persisted across server restarts * and reloads. diff --git a/src/main/java/org/bukkit/WorldCreator.java b/src/main/java/org/bukkit/WorldCreator.java index cbe6b3a1..f9fa287d 100644 --- a/src/main/java/org/bukkit/WorldCreator.java +++ b/src/main/java/org/bukkit/WorldCreator.java @@ -321,7 +321,7 @@ public class WorldCreator { * @param generatorSettings The settings that should be used by the * generator * @return This object, for chaining - * @see Custom + * @see Custom * dimension (scroll to "When the generator ID type is * minecraft:flat)" */ diff --git a/src/main/java/org/bukkit/block/BlockState.java b/src/main/java/org/bukkit/block/BlockState.java index 0c0b3616..d1cfcfc7 100644 --- a/src/main/java/org/bukkit/block/BlockState.java +++ b/src/main/java/org/bukkit/block/BlockState.java @@ -6,6 +6,7 @@ import org.bukkit.World; import org.bukkit.block.data.BlockData; import org.bukkit.material.MaterialData; import org.bukkit.metadata.Metadatable; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -46,6 +47,15 @@ public interface BlockState extends Metadatable { @NotNull BlockData getBlockData(); + /** + * Returns a copy of this BlockState as an unplaced BlockState. + * + * @return a copy of the block state + */ + @NotNull + @ApiStatus.Experimental + BlockState copy(); + /** * Gets the type of this block state. * diff --git a/src/main/java/org/bukkit/block/Structure.java b/src/main/java/org/bukkit/block/Structure.java index bce0947d..ab245d11 100644 --- a/src/main/java/org/bukkit/block/Structure.java +++ b/src/main/java/org/bukkit/block/Structure.java @@ -223,7 +223,7 @@ public interface Structure extends TileState { /** * Only applicable while in {@link UsageMode#DATA}. Metadata are specific * functions that can be applied to the structure location. Consult the - * Minecraft + * Minecraft * wiki for more information. * * @param metadata the function to perform on the selected location @@ -233,7 +233,7 @@ public interface Structure extends TileState { /** * Get the metadata function this structure block will perform when * activated. Consult the - * Minecraft + * Minecraft * Wiki for more information. * * @return the function that will be performed when this block is activated diff --git a/src/main/java/org/bukkit/block/structure/UsageMode.java b/src/main/java/org/bukkit/block/structure/UsageMode.java index cbea3f38..8c6528ca 100644 --- a/src/main/java/org/bukkit/block/structure/UsageMode.java +++ b/src/main/java/org/bukkit/block/structure/UsageMode.java @@ -23,7 +23,7 @@ public enum UsageMode { * Used to run specific custom functions, which can only be used for certain * Structures. The structure block is removed after this function completes. * The data tags (functions) can be found on the - * wiki. + * wiki. */ DATA; } diff --git a/src/main/java/org/bukkit/entity/Display.java b/src/main/java/org/bukkit/entity/Display.java index bd7dfe80..2b6f0c62 100644 --- a/src/main/java/org/bukkit/entity/Display.java +++ b/src/main/java/org/bukkit/entity/Display.java @@ -48,6 +48,27 @@ public interface Display extends Entity { */ public void setInterpolationDuration(int duration); + /** + * Gets the teleport duration of this display. + *

      + *
    • 0 means that updates are applied immediately.
    • + *
    • 1 means that the display entity will move from current position to the updated one over one tick.
    • + *
    • Higher values spread the movement over multiple ticks.
    • + *
    + * + * @return teleport duration + */ + public int getTeleportDuration(); + + /** + * Sets the teleport duration of this display. + * + * @param duration new duration + * @throws IllegalArgumentException if duration is not between 0 and 59 + * @see #getTeleportDuration() + */ + public void setTeleportDuration(int duration); + /** * Gets the view distance/range of this display. * diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java index 1d6adae8..26631b6d 100644 --- a/src/main/java/org/bukkit/entity/Entity.java +++ b/src/main/java/org/bukkit/entity/Entity.java @@ -547,6 +547,20 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent @ApiStatus.Experimental public boolean isVisibleByDefault(); + /** + * Get all players that are currently tracking this entity. + *

    + * 'Tracking' means that this entity has been sent to the player and that + * they are receiving updates on its state. Note that the client's {@code + * 'Entity Distance'} setting does not affect the range at which entities + * are tracked. + * + * @return the players tracking this entity, or an empty set if none + */ + @NotNull + @ApiStatus.Experimental + Set getTrackedBy(); + /** * Sets whether the entity has a team colored (default: white) glow. * diff --git a/src/main/java/org/bukkit/entity/LightningStrike.java b/src/main/java/org/bukkit/entity/LightningStrike.java index 76aad05f..158ac20f 100644 --- a/src/main/java/org/bukkit/entity/LightningStrike.java +++ b/src/main/java/org/bukkit/entity/LightningStrike.java @@ -1,5 +1,9 @@ package org.bukkit.entity; +import org.bukkit.GameEvent; +import org.bukkit.enchantments.Enchantment; +import org.jetbrains.annotations.Nullable; + /** * Represents an instance of a lightning strike. May or may not do damage. */ @@ -12,4 +16,70 @@ public interface LightningStrike extends Entity { */ public boolean isEffect(); + /** + * Get the amount of flashes that will occur before the lightning is + * removed. By default this value is between 1 and 3. + * + * @return the flashes + */ + public int getFlashes(); + + /** + * Set the amount of flashes that will occur before the lightning is + * removed. One flash will occur after this lightning strike's life + * has reduced below 0. + * + * @param flashes the flashes + */ + public void setFlashes(int flashes); + + /** + * Get the amount of ticks this lightning strike will inflict damage + * upon its hit entities. + *

    + * When life ticks are negative, there is a random chance that another + * flash will be initiated and life ticks reset to 1. + * + * @return the life ticks + */ + public int getLifeTicks(); + + /** + * Get the amount of ticks this lightning strike will inflict damage + * upon its hit entities. + *

    + * When life ticks are negative, there is a random chance that another + * flash will be initiated and life ticks reset to 1. Additionally, if + * life ticks are set to 2 (the default value when a lightning strike + * has been spawned), a list of events will occur: + *

      + *
    • Impact sound effects will be played + *
    • Fire will be spawned (dependent on difficulty) + *
    • Lightning rods will be powered (if hit) + *
    • Copper will be stripped (if hit) + *
    • {@link GameEvent#LIGHTNING_STRIKE} will be dispatched + *
    + * + * @param ticks the life ticks + */ + public void setLifeTicks(int ticks); + + /** + * Get the {@link Player} that caused this lightning to strike. This + * will occur naturally if a trident enchanted with + * {@link Enchantment#CHANNELING Channeling} were thrown at an entity + * during a storm. + * + * @return the player + */ + @Nullable + public Player getCausingPlayer(); + + /** + * Set the {@link Player} that caused this lightning to strike. + * + * @param player the player + */ + public void setCausingPlayer(@Nullable Player player); + } diff --git a/src/main/java/org/bukkit/entity/Projectile.java b/src/main/java/org/bukkit/entity/Projectile.java index c854860c..906b33b7 100644 --- a/src/main/java/org/bukkit/entity/Projectile.java +++ b/src/main/java/org/bukkit/entity/Projectile.java @@ -25,11 +25,11 @@ public interface Projectile extends Entity { /** * Determine if this projectile should bounce or not when it hits. - *

    - * If a small fireball does not bounce it will set the target on fire. * * @return true if it should bounce. + * @deprecated does not do anything */ + @Deprecated public boolean doesBounce(); /** @@ -37,6 +37,8 @@ public interface Projectile extends Entity { * something. * * @param doesBounce whether or not it should bounce. + * @deprecated does not do anything */ + @Deprecated public void setBounce(boolean doesBounce); } diff --git a/src/main/java/org/bukkit/entity/SpawnCategory.java b/src/main/java/org/bukkit/entity/SpawnCategory.java index a2772ada..b1a0de51 100644 --- a/src/main/java/org/bukkit/entity/SpawnCategory.java +++ b/src/main/java/org/bukkit/entity/SpawnCategory.java @@ -3,7 +3,7 @@ package org.bukkit.entity; /** * Represents groups of entities with shared spawn behaviors and mob caps. * - * @see Minecraft Wiki + * @see Minecraft Wiki */ public enum SpawnCategory { diff --git a/src/main/java/org/bukkit/entity/TropicalFish.java b/src/main/java/org/bukkit/entity/TropicalFish.java index bc5055f2..ab31289b 100644 --- a/src/main/java/org/bukkit/entity/TropicalFish.java +++ b/src/main/java/org/bukkit/entity/TropicalFish.java @@ -55,7 +55,7 @@ public interface TropicalFish extends Fish { /** * Enumeration of all different fish patterns. Refer to the - * Minecraft Wiki + * Minecraft Wiki * for pictures. */ public static enum Pattern { diff --git a/src/main/java/org/bukkit/event/world/AsyncStructureGenerateEvent.java b/src/main/java/org/bukkit/event/world/AsyncStructureGenerateEvent.java new file mode 100644 index 00000000..91a13737 --- /dev/null +++ b/src/main/java/org/bukkit/event/world/AsyncStructureGenerateEvent.java @@ -0,0 +1,229 @@ +package org.bukkit.event.world; + +import com.google.common.base.Preconditions; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import org.bukkit.NamespacedKey; +import org.bukkit.World; +import org.bukkit.event.HandlerList; +import org.bukkit.generator.structure.Structure; +import org.bukkit.util.BlockTransformer; +import org.bukkit.util.BoundingBox; +import org.bukkit.util.EntityTransformer; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * This event will sometimes fire synchronously, depending on how it was + * triggered. + *

    + * The constructor provides a boolean to indicate if the event was fired + * synchronously or asynchronously. When asynchronous, this event can be called + * from any thread, sans the main thread, and has limited access to the API. + *

    + * If a {@link Structure} is naturally placed in a chunk of the world, this + * event will be asynchronous. If a player executes the '/place structure' + * command, this event will be synchronous. + * + * Allows to register transformers that can modify the blocks placed and + * entities spawned by the structure. + *

    + * Care should be taken to check {@link #isAsynchronous()} and treat the event + * appropriately. + *

    + */ +@ApiStatus.Experimental +public class AsyncStructureGenerateEvent extends WorldEvent { + + public static enum Cause { + COMMAND, + WORLD_GENERATION, + CUSTOM; + } + + private static final HandlerList handlers = new HandlerList(); + + private final Cause cause; + + private final Structure structure; + private final BoundingBox boundingBox; + + private final int chunkX, chunkZ; + + private final Map blockTransformers = new LinkedHashMap<>(); + private final Map entityTransformers = new LinkedHashMap<>(); + + public AsyncStructureGenerateEvent(@NotNull World world, boolean async, @NotNull Cause cause, @NotNull Structure structure, @NotNull BoundingBox boundingBox, int chunkX, int chunkZ) { + super(world, async); + this.structure = structure; + this.boundingBox = boundingBox; + this.chunkX = chunkX; + this.chunkZ = chunkZ; + this.cause = cause; + } + + /** + * Gets the event cause. + * + * @return the event cause + */ + @NotNull + public Cause getCause() { + return cause; + } + + /** + * Gets a block transformer by key. + * + * @param key the key of the block transformer + * + * @return the block transformer or null + */ + @Nullable + public BlockTransformer getBlockTransformer(@NotNull NamespacedKey key) { + Preconditions.checkNotNull(key, "NamespacedKey cannot be null"); + return blockTransformers.get(key); + } + + /** + * Sets a block transformer to a key. + * + * @param key the key + * @param transformer the block transformer + */ + public void setBlockTransformer(@NotNull NamespacedKey key, @NotNull BlockTransformer transformer) { + Preconditions.checkNotNull(key, "NamespacedKey cannot be null"); + Preconditions.checkNotNull(transformer, "BlockTransformer cannot be null"); + blockTransformers.put(key, transformer); + } + + /** + * Removes a block transformer. + * + * @param key the key of the block transformer + */ + public void removeBlockTransformer(@NotNull NamespacedKey key) { + Preconditions.checkNotNull(key, "NamespacedKey cannot be null"); + blockTransformers.remove(key); + } + + /** + * Removes all block transformers. + */ + public void clearBlockTransformers() { + blockTransformers.clear(); + } + + /** + * Gets all block transformers in a unmodifiable map. + * + * @return the block transformers in a map + */ + @NotNull + public Map getBlockTransformers() { + return Collections.unmodifiableMap(blockTransformers); + } + + /** + * Gets a entity transformer by key. + * + * @param key the key of the entity transformer + * + * @return the entity transformer or null + */ + @Nullable + public EntityTransformer getEntityTransformer(@NotNull NamespacedKey key) { + Preconditions.checkNotNull(key, "NamespacedKey cannot be null"); + return entityTransformers.get(key); + } + + /** + * Sets a entity transformer to a key. + * + * @param key the key + * @param transformer the entity transformer + */ + public void setEntityTransformer(@NotNull NamespacedKey key, @NotNull EntityTransformer transformer) { + Preconditions.checkNotNull(key, "NamespacedKey cannot be null"); + Preconditions.checkNotNull(transformer, "EntityTransformer cannot be null"); + entityTransformers.put(key, transformer); + } + + /** + * Removes a entity transformer. + * + * @param key the key of the entity transformer + */ + public void removeEntityTransformer(@NotNull NamespacedKey key) { + Preconditions.checkNotNull(key, "NamespacedKey cannot be null"); + entityTransformers.remove(key); + } + + /** + * Removes all entity transformers. + */ + public void clearEntityTransformers() { + entityTransformers.clear(); + } + + /** + * Gets all entity transformers in a unmodifiable map. + * + * @return the entity transformers in a map + */ + @NotNull + public Map getEntityTransformers() { + return Collections.unmodifiableMap(entityTransformers); + } + + /** + * Get the structure reference that is generated. + * + * @return the structure + */ + @NotNull + public Structure getStructure() { + return structure; + } + + /** + * Get the bounding box of the structure. + * + * @return the bounding box + */ + @NotNull + public BoundingBox getBoundingBox() { + return boundingBox.clone(); + } + + /** + * Get the x coordinate of the origin chunk of the structure. + * + * @return the chunk x coordinate + */ + public int getChunkX() { + return chunkX; + } + + /** + * Get the z coordinate of the origin chunk of the structure. + * + * @return the chunk z coordinate + */ + public int getChunkZ() { + return chunkZ; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/main/java/org/bukkit/loot/LootTable.java b/src/main/java/org/bukkit/loot/LootTable.java index b7529fc7..ee5bd79f 100644 --- a/src/main/java/org/bukkit/loot/LootTable.java +++ b/src/main/java/org/bukkit/loot/LootTable.java @@ -12,8 +12,8 @@ import org.jetbrains.annotations.Nullable; * LootTables are technical files that represent what items should be in * naturally generated containers, what items should be dropped when killing a * mob, or what items can be fished. - * - * See the + *
    + * See the
    * Minecraft Wiki for more information. */ public interface LootTable extends Keyed { diff --git a/src/main/java/org/bukkit/loot/LootTables.java b/src/main/java/org/bukkit/loot/LootTables.java index 95bbda00..4e8479dc 100644 --- a/src/main/java/org/bukkit/loot/LootTables.java +++ b/src/main/java/org/bukkit/loot/LootTables.java @@ -8,9 +8,9 @@ import org.jetbrains.annotations.NotNull; /** * This enum holds a list of all known {@link LootTable}s offered by Mojang. * This list is not guaranteed to be accurate in future versions. - * + *
    * See the - * + * * Minecraft Wiki for more information on loot tables. */ public enum LootTables implements Keyed { diff --git a/src/main/java/org/bukkit/packs/DataPack.java b/src/main/java/org/bukkit/packs/DataPack.java index e424680e..3d5af25a 100644 --- a/src/main/java/org/bukkit/packs/DataPack.java +++ b/src/main/java/org/bukkit/packs/DataPack.java @@ -8,6 +8,8 @@ import org.jetbrains.annotations.NotNull; /** * Represents a data pack. + * + * @see Minecraft wiki */ @ApiStatus.Experimental public interface DataPack extends Keyed { @@ -29,16 +31,42 @@ public interface DataPack extends Keyed { public String getDescription(); /** - * Gets the pack version. + * Gets the pack format. *
    - * This is related to the server version to work. + * Pack formats are non-standard and unrelated to the version of Minecraft. For + * a list of known pack versions, see the + * Minecraft Wiki. * * @return the pack version - * @deprecated packs can support multiple versions + * @see #getMinSupportedPackFormat() + * @see #getMaxSupportedPackFormat() */ - @Deprecated public int getPackFormat(); + /** + * Gets the minimum supported pack format. If the data pack does not specify a + * minimum supported format, {@link #getPackFormat()} is returned. + *
    + * Pack formats are non-standard and unrelated to the version of Minecraft. For + * a list of known pack versions, see the + * Minecraft Wiki. + * + * @return the min pack version supported + */ + public int getMinSupportedPackFormat(); + + /** + * Gets the maximum supported pack format. If the data pack does not specify a + * maximum supported format, {@link #getPackFormat()} is returned. + *
    + * Pack formats are non-standard and unrelated to the version of Minecraft. For + * a list of known pack versions, see the + * Minecraft Wiki. + * + * @return the max pack version supported + */ + public int getMaxSupportedPackFormat(); + /** * Gets if the data pack is enabled on the server. * diff --git a/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java b/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java index 0eae1c02..539df566 100644 --- a/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java +++ b/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java @@ -335,7 +335,7 @@ public final class PluginDescriptionFile { *

  • An entry of this list can be referenced in {@link #getDepend()}, * {@link #getSoftDepend()}, and {@link #getLoadBefore()}. *
  • provides must be in YAML list + * href="https://en.wikipedia.org/wiki/YAML#Lists">YAML list * format. * *

    @@ -454,7 +454,7 @@ public final class PluginDescriptionFile { *

  • A SpigotMC forum handle or email address is recommended. *
  • Is displayed when a user types /version PluginName *
  • authors must be in YAML list + * href="https://en.wikipedia.org/wiki/YAML#Lists">YAML list * format. * *

    @@ -491,7 +491,7 @@ public final class PluginDescriptionFile { *

  • A SpigotMC forum handle or email address is recommended. *
  • Is displayed when a user types /version PluginName *
  • contributors must be in YAML list + * href="https://en.wikipedia.org/wiki/YAML#Lists">YAML list * format. * *

    @@ -538,7 +538,7 @@ public final class PluginDescriptionFile { * href=https://en.wikipedia.org/wiki/Circular_dependency>network, * all plugins in that network will fail. *

  • depend must be in YAML list + * href="https://en.wikipedia.org/wiki/YAML#Lists">YAML list * format. * *

    @@ -570,7 +570,7 @@ public final class PluginDescriptionFile { * or soft-dependending each other), it will arbitrarily choose a * plugin that can be resolved when ignoring soft-dependencies. *

  • softdepend must be in YAML list + * href="https://en.wikipedia.org/wiki/YAML#Lists">YAML list * format. * *

    @@ -597,7 +597,7 @@ public final class PluginDescriptionFile { * specified plugin's {@link #getSoftDepend()} include {@link * #getName() this plugin}. *

  • loadbefore must be in YAML list + * href="https://en.wikipedia.org/wiki/YAML#Lists">YAML list * format. * *

    @@ -661,7 +661,7 @@ public final class PluginDescriptionFile { * aliases * {@link PluginCommand#setAliases(List)} * String or List of + * href="https://en.wikipedia.org/wiki/YAML#Lists">List of * strings * Alternative command names, with special usefulness for commands * that are already registered. Aliases are not effective when @@ -809,7 +809,7 @@ public final class PluginDescriptionFile { *

    * Child permissions may be defined in a number of ways:

      *
    • Children may be defined as a list of + * href="https://en.wikipedia.org/wiki/YAML#Lists">list of * names. Using a list will treat all children associated * positively to their parent. *
    • Children may be defined as a map. Each permission name maps @@ -917,7 +917,7 @@ public final class PluginDescriptionFile { * by the API, effectively discluding any derived type from any * plugin's classpath. *
    • awareness must be in YAML list + * href="https://en.wikipedia.org/wiki/YAML#Lists">YAML list * format. *
    *

    diff --git a/src/main/java/org/bukkit/util/BlockTransformer.java b/src/main/java/org/bukkit/util/BlockTransformer.java new file mode 100644 index 00000000..7f430519 --- /dev/null +++ b/src/main/java/org/bukkit/util/BlockTransformer.java @@ -0,0 +1,62 @@ +package org.bukkit.util; + +import org.bukkit.block.BlockState; +import org.bukkit.block.data.BlockData; +import org.bukkit.generator.LimitedRegion; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +/** + * A BlockTransformer is used to modify blocks that are placed by structure. + */ +@FunctionalInterface +@ApiStatus.Experimental +public interface BlockTransformer { + + /** + * The TransformationState allows access to the original block state and the + * block state of the block that was at the location of the transformation + * in the world before the transformation started. + */ + public static interface TransformationState { + + /** + * Creates a clone of the original block state that a structure wanted + * to place and caches it for the current transformer. + * + * @return a clone of the original block state. + */ + @NotNull + BlockState getOriginal(); + + /** + * Creates a clone of the block state that was at the location of the + * currently modified block at the start of the transformation process + * and caches it for the current transformer. + * + * @return a clone of the world block state. + */ + @NotNull + BlockState getWorld(); + + } + + /** + * Transforms a block in a structure. + * + * NOTE: The usage of {@link BlockData#createBlockState()} can provide even + * more flexibility to return the exact block state you might want to + * return. + * + * @param region the accessible region + * @param x the x position of the block + * @param y the y position of the block + * @param z the z position of the block + * @param current the state of the block that should be placed + * @param state the state of this transformation. + * + * @return the new block state + */ + @NotNull + BlockState transform(@NotNull LimitedRegion region, int x, int y, int z, @NotNull BlockState current, @NotNull TransformationState state); +} diff --git a/src/main/java/org/bukkit/util/EntityTransformer.java b/src/main/java/org/bukkit/util/EntityTransformer.java new file mode 100644 index 00000000..d1f44fd9 --- /dev/null +++ b/src/main/java/org/bukkit/util/EntityTransformer.java @@ -0,0 +1,29 @@ +package org.bukkit.util; + +import org.bukkit.entity.Entity; +import org.bukkit.generator.LimitedRegion; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +/** + * A EntityTransformer is used to modify entities that are spawned by structure. + */ +@FunctionalInterface +@ApiStatus.Experimental +public interface EntityTransformer { + + /** + * Transforms a entity in a structure. + * + * @param region the accessible region + * @param x the x position of the entity + * @param y the y position of the entity + * @param z the z position of the entity + * @param entity the entity + * @param allowedToSpawn if the entity is allowed to spawn + * + * @return {@code true} if the entity should be spawned otherwise + * {@code false} + */ + boolean transform(@NotNull LimitedRegion region, int x, int y, int z, @NotNull Entity entity, boolean allowedToSpawn); +} diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java index 4ac3dd97..64e7aef6 100644 --- a/src/test/java/org/bukkit/AnnotationTest.java +++ b/src/test/java/org/bukkit/AnnotationTest.java @@ -1,5 +1,6 @@ package org.bukkit; +import static org.junit.jupiter.api.Assertions.*; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -13,8 +14,7 @@ import java.util.List; import java.util.Map; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.objectweb.asm.ClassReader; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; @@ -49,7 +49,7 @@ public class AnnotationTest { File file = new File(loc.toURI()); // Running from jar is not supported yet - Assert.assertTrue("code must be in a directory", file.isDirectory()); + assertTrue(file.isDirectory(), "code must be in a directory"); final HashMap foundClasses = new HashMap<>(); collectClasses(file, foundClasses); @@ -97,7 +97,7 @@ public class AnnotationTest { System.out.println(message); } - Assert.fail("There " + errors.size() + " are missing annotation(s)"); + fail("There " + errors.size() + " are missing annotation(s)"); } private static void collectClasses(@NotNull File from, @NotNull Map to) throws IOException { diff --git a/src/test/java/org/bukkit/BukkitMirrorTest.java b/src/test/java/org/bukkit/BukkitMirrorTest.java index 2dfada66..89ca06eb 100644 --- a/src/test/java/org/bukkit/BukkitMirrorTest.java +++ b/src/test/java/org/bukkit/BukkitMirrorTest.java @@ -1,72 +1,59 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import com.google.common.base.Function; -import com.google.common.collect.Lists; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.Arrays; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class BukkitMirrorTest { - @Parameters(name = "{index}: {1}") - public static List data() { - return Lists.transform(Arrays.asList(Server.class.getDeclaredMethods()), new Function() { - @Override - public Object[] apply(Method input) { - return new Object[] { - input, - input.toGenericString().substring("public abstract ".length()).replace("(", "{").replace(")", "}") - }; - } - }); + public static Stream data() { + return Stream.of(Server.class.getDeclaredMethods()) + .map(method -> { + try { + return Arguments.of( + method, + method.toGenericString().substring("public abstract ".length()).replace("(", "{").replace(")", "}"), + Bukkit.class.getDeclaredMethod(method.getName(), method.getParameterTypes()) + ); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + }); } - @Parameter(0) - public Method server; - - @Parameter(1) - public String name; - - private Method bukkit; - - @Before - public void makeBukkit() throws Throwable { - bukkit = Bukkit.class.getDeclaredMethod(server.getName(), server.getParameterTypes()); - } - - @Test - public void isStatic() throws Throwable { + @ParameterizedTest + @MethodSource("data") + public void isStatic(Method server, String name, Method bukkit) throws Throwable { assertThat(Modifier.isStatic(bukkit.getModifiers()), is(true)); } - @Test - public void isDeprecated() throws Throwable { + @ParameterizedTest + @MethodSource("data") + public void isDeprecated(Method server, String name, Method bukkit) throws Throwable { assertThat(bukkit.isAnnotationPresent(Deprecated.class), is(server.isAnnotationPresent(Deprecated.class))); } - @Test - public void returnType() throws Throwable { + @ParameterizedTest + @MethodSource("data") + public void returnType(Method server, String name, Method bukkit) throws Throwable { assertThat(bukkit.getReturnType(), is((Object) server.getReturnType())); // assertThat(bukkit.getGenericReturnType(), is(server.getGenericReturnType())); // too strict on type generics } - @Test - public void parameterTypes() throws Throwable { + @ParameterizedTest + @MethodSource("data") + public void parameterTypes(Method server, String name, Method bukkit) throws Throwable { // assertThat(bukkit.getGenericParameterTypes(), is(server.getGenericParameterTypes())); // too strict on type generics } - @Test - public void declaredException() throws Throwable { + @ParameterizedTest + @MethodSource("data") + public void declaredException(Method server, String name, Method bukkit) throws Throwable { assertThat(bukkit.getGenericExceptionTypes(), is(server.getGenericExceptionTypes())); } } diff --git a/src/test/java/org/bukkit/ChatColorTest.java b/src/test/java/org/bukkit/ChatColorTest.java index fc4e8085..11c0f868 100644 --- a/src/test/java/org/bukkit/ChatColorTest.java +++ b/src/test/java/org/bukkit/ChatColorTest.java @@ -1,8 +1,9 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class ChatColorTest { @@ -13,14 +14,14 @@ public class ChatColorTest { } } - @Test(expected = IllegalArgumentException.class) + @Test public void getByStringWithNull() { - ChatColor.getByChar((String) null); + assertThrows(IllegalArgumentException.class, () -> ChatColor.getByChar((String) null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void getByStringWithEmpty() { - ChatColor.getByChar(""); + assertThrows(IllegalArgumentException.class, () -> ChatColor.getByChar("")); } @Test diff --git a/src/test/java/org/bukkit/ChatPaginatorTest.java b/src/test/java/org/bukkit/ChatPaginatorTest.java index b0384b12..2d7c5459 100644 --- a/src/test/java/org/bukkit/ChatPaginatorTest.java +++ b/src/test/java/org/bukkit/ChatPaginatorTest.java @@ -1,9 +1,9 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; import org.bukkit.util.ChatPaginator; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ChatPaginatorTest { @Test diff --git a/src/test/java/org/bukkit/CoalTypeTest.java b/src/test/java/org/bukkit/CoalTypeTest.java index b90f10c4..9373bfd2 100644 --- a/src/test/java/org/bukkit/CoalTypeTest.java +++ b/src/test/java/org/bukkit/CoalTypeTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CoalTypeTest { @Test diff --git a/src/test/java/org/bukkit/ColorTest.java b/src/test/java/org/bukkit/ColorTest.java index 1f722fb2..f29fd7bc 100644 --- a/src/test/java/org/bukkit/ColorTest.java +++ b/src/test/java/org/bukkit/ColorTest.java @@ -1,9 +1,10 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.configuration.file.YamlConfiguration; -import org.junit.Test; +import org.junit.jupiter.api.Test; @SuppressWarnings("javadoc") public class ColorTest { @@ -58,7 +59,7 @@ public class ColorTest { YamlConfiguration deserialized = new YamlConfiguration(); deserialized.loadFromString(serialized); - assertThat(testColor.name + " on " + serialized, base, is(deserialized.getColor("color"))); + assertThat(base, is(deserialized.getColor("color")), testColor.name + " on " + serialized); } } @@ -73,14 +74,14 @@ public class ColorTest { Color fromRGBs = Color.fromRGB(testColor.r, testColor.g, testColor.b); Color fromBGRs = Color.fromBGR(testColor.b, testColor.g, testColor.r); - assertThat(testColor.name, fromARGB, is(fromARGB)); - assertThat(testColor.name, fromARGBs, is(fromARGBs)); - assertThat(testColor.name, fromRGB, is(fromRGBs)); - assertThat(testColor.name, fromRGB, is(fromBGR)); - assertThat(testColor.name, fromRGB, is(fromBGRs)); - assertThat(testColor.name, fromRGBs, is(fromBGR)); - assertThat(testColor.name, fromRGBs, is(fromBGRs)); - assertThat(testColor.name, fromBGR, is(fromBGRs)); + assertThat(fromARGB, is(fromARGB), testColor.name); + assertThat(fromARGBs, is(fromARGBs), testColor.name); + assertThat(fromRGB, is(fromRGBs), testColor.name); + assertThat(fromRGB, is(fromBGR), testColor.name); + assertThat(fromRGB, is(fromBGRs), testColor.name); + assertThat(fromRGBs, is(fromBGR), testColor.name); + assertThat(fromRGBs, is(fromBGRs), testColor.name); + assertThat(fromBGR, is(fromBGRs), testColor.name); } } @@ -93,11 +94,11 @@ public class ColorTest { TestColor testTo = examples[j]; Color to = Color.fromARGB(testTo.argb); String name = testFrom.name + " to " + testTo.name; - assertThat(name, from, is(not(to))); + assertThat(from, is(not(to)), name); Color transform = from.setAlpha(testTo.a).setRed(testTo.r).setBlue(testTo.b).setGreen(testTo.g); - assertThat(name, transform, is(not(sameInstance(from)))); - assertThat(name, transform, is(to)); + assertThat(transform, is(not(sameInstance(from))), name); + assertThat(transform, is(to), name); } } } @@ -106,8 +107,8 @@ public class ColorTest { @Test public void testARGB() { for (TestColor testColor : examples) { - assertThat(testColor.name, Color.fromARGB(testColor.argb).asARGB(), is(testColor.argb)); - assertThat(testColor.name, Color.fromARGB(testColor.a, testColor.r, testColor.g, testColor.b).asARGB(), is(testColor.argb)); + assertThat(Color.fromARGB(testColor.argb).asARGB(), is(testColor.argb), testColor.name); + assertThat(Color.fromARGB(testColor.a, testColor.r, testColor.g, testColor.b).asARGB(), is(testColor.argb), testColor.name); } } @@ -115,342 +116,342 @@ public class ColorTest { @Test public void testRGB() { for (TestColor testColor : examples) { - assertThat(testColor.name, Color.fromRGB(testColor.rgb).asRGB(), is(testColor.rgb)); - assertThat(testColor.name, Color.fromBGR(testColor.bgr).asRGB(), is(testColor.rgb)); - assertThat(testColor.name, Color.fromRGB(testColor.r, testColor.g, testColor.b).asRGB(), is(testColor.rgb)); - assertThat(testColor.name, Color.fromBGR(testColor.b, testColor.g, testColor.r).asRGB(), is(testColor.rgb)); + assertThat(Color.fromRGB(testColor.rgb).asRGB(), is(testColor.rgb), testColor.name); + assertThat(Color.fromBGR(testColor.bgr).asRGB(), is(testColor.rgb), testColor.name); + assertThat(Color.fromRGB(testColor.r, testColor.g, testColor.b).asRGB(), is(testColor.rgb), testColor.name); + assertThat(Color.fromBGR(testColor.b, testColor.g, testColor.r).asRGB(), is(testColor.rgb), testColor.name); } } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidRGB1() { - Color.fromRGB(0x01000000); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x01000000)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidRGB2() { - Color.fromRGB(Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidRGB3() { - Color.fromRGB(Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidRGB4() { - Color.fromRGB(-1); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(-1)); } // BGR tests @Test public void testBGR() { for (TestColor testColor : examples) { - assertThat(testColor.name, Color.fromRGB(testColor.rgb).asBGR(), is(testColor.bgr)); - assertThat(testColor.name, Color.fromBGR(testColor.bgr).asBGR(), is(testColor.bgr)); - assertThat(testColor.name, Color.fromRGB(testColor.r, testColor.g, testColor.b).asBGR(), is(testColor.bgr)); - assertThat(testColor.name, Color.fromBGR(testColor.b, testColor.g, testColor.r).asBGR(), is(testColor.bgr)); + assertThat(Color.fromRGB(testColor.rgb).asBGR(), is(testColor.bgr), testColor.name); + assertThat(Color.fromBGR(testColor.bgr).asBGR(), is(testColor.bgr), testColor.name); + assertThat(Color.fromRGB(testColor.r, testColor.g, testColor.b).asBGR(), is(testColor.bgr), testColor.name); + assertThat(Color.fromBGR(testColor.b, testColor.g, testColor.r).asBGR(), is(testColor.bgr), testColor.name); } } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidBGR1() { - Color.fromBGR(0x01000000); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x01000000)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidBGR2() { - Color.fromBGR(Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidBGR3() { - Color.fromBGR(Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidBGR4() { - Color.fromBGR(-1); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(-1)); } // Alpha tests @Test public void testAlpha() { for (TestColor testColor : examples) { - assertThat(testColor.name, Color.fromARGB(testColor.argb).getAlpha(), is(testColor.a)); + assertThat(Color.fromARGB(testColor.argb).getAlpha(), is(testColor.a), testColor.name); } } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA01() { - Color.fromARGB(-1, 0x00, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromARGB(-1, 0x00, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA02() { - Color.fromARGB(Integer.MAX_VALUE, 0x00, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromARGB(Integer.MAX_VALUE, 0x00, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA03() { - Color.fromARGB(Integer.MIN_VALUE, 0x00, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromARGB(Integer.MIN_VALUE, 0x00, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA04() { - Color.fromARGB(0x100, 0x00, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromARGB(0x100, 0x00, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA05() { - Color.fromBGR(0x00, 0x00, 0x00).setAlpha(-1); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, 0x00).setAlpha(-1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA06() { - Color.fromBGR(0x00, 0x00, 0x00).setAlpha(Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, 0x00).setAlpha(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA07() { - Color.fromBGR(0x00, 0x00, 0x00).setAlpha(Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, 0x00).setAlpha(Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA08() { - Color.fromBGR(0x00, 0x00, 0x00).setAlpha(0x100); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, 0x00).setAlpha(0x100)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA09() { - Color.WHITE.setAlpha(-1); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setAlpha(-1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA10() { - Color.WHITE.setAlpha(Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setAlpha(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA11() { - Color.WHITE.setAlpha(Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setAlpha(Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidA12() { - Color.WHITE.setAlpha(0x100); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setAlpha(0x100)); } // Red tests @Test public void testRed() { for (TestColor testColor : examples) { - assertThat(testColor.name, Color.fromRGB(testColor.rgb).getRed(), is(testColor.r)); - assertThat(testColor.name, Color.fromBGR(testColor.bgr).getRed(), is(testColor.r)); - assertThat(testColor.name, Color.fromRGB(testColor.r, testColor.g, testColor.b).getRed(), is(testColor.r)); - assertThat(testColor.name, Color.fromBGR(testColor.b, testColor.g, testColor.r).getRed(), is(testColor.r)); + assertThat(Color.fromRGB(testColor.rgb).getRed(), is(testColor.r), testColor.name); + assertThat(Color.fromBGR(testColor.bgr).getRed(), is(testColor.r), testColor.name); + assertThat(Color.fromRGB(testColor.r, testColor.g, testColor.b).getRed(), is(testColor.r), testColor.name); + assertThat(Color.fromBGR(testColor.b, testColor.g, testColor.r).getRed(), is(testColor.r), testColor.name); } } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR01() { - Color.fromRGB(-1, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(-1, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR02() { - Color.fromRGB(Integer.MAX_VALUE, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(Integer.MAX_VALUE, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR03() { - Color.fromRGB(Integer.MIN_VALUE, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(Integer.MIN_VALUE, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR04() { - Color.fromRGB(0x100, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x100, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR05() { - Color.fromBGR(0x00, 0x00, -1); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, -1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR06() { - Color.fromBGR(0x00, 0x00, Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR07() { - Color.fromBGR(0x00, 0x00, Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR08() { - Color.fromBGR(0x00, 0x00, 0x100); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x00, 0x100)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR09() { - Color.WHITE.setRed(-1); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setRed(-1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR10() { - Color.WHITE.setRed(Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setRed(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR11() { - Color.WHITE.setRed(Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setRed(Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidR12() { - Color.WHITE.setRed(0x100); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setRed(0x100)); } // Blue tests @Test public void testBlue() { for (TestColor testColor : examples) { - assertThat(testColor.name, Color.fromRGB(testColor.rgb).getBlue(), is(testColor.b)); - assertThat(testColor.name, Color.fromBGR(testColor.bgr).getBlue(), is(testColor.b)); - assertThat(testColor.name, Color.fromRGB(testColor.r, testColor.g, testColor.b).getBlue(), is(testColor.b)); - assertThat(testColor.name, Color.fromBGR(testColor.b, testColor.g, testColor.r).getBlue(), is(testColor.b)); + assertThat(Color.fromRGB(testColor.rgb).getBlue(), is(testColor.b), testColor.name); + assertThat(Color.fromBGR(testColor.bgr).getBlue(), is(testColor.b), testColor.name); + assertThat(Color.fromRGB(testColor.r, testColor.g, testColor.b).getBlue(), is(testColor.b), testColor.name); + assertThat(Color.fromBGR(testColor.b, testColor.g, testColor.r).getBlue(), is(testColor.b), testColor.name); } } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB01() { - Color.fromRGB(0x00, 0x00, -1); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, 0x00, -1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB02() { - Color.fromRGB(0x00, 0x00, Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, 0x00, Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB03() { - Color.fromRGB(0x00, 0x00, Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, 0x00, Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB04() { - Color.fromRGB(0x00, 0x00, 0x100); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, 0x00, 0x100)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB05() { - Color.fromBGR(-1, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(-1, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB06() { - Color.fromBGR(Integer.MAX_VALUE, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(Integer.MAX_VALUE, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB07() { - Color.fromBGR(Integer.MIN_VALUE, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(Integer.MIN_VALUE, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB08() { - Color.fromBGR(0x100, 0x00, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x100, 0x00, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB09() { - Color.WHITE.setBlue(-1); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setBlue(-1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB10() { - Color.WHITE.setBlue(Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setBlue(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB11() { - Color.WHITE.setBlue(Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setBlue(Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidB12() { - Color.WHITE.setBlue(0x100); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setBlue(0x100)); } // Green tests @Test public void testGreen() { for (TestColor testColor : examples) { - assertThat(testColor.name, Color.fromRGB(testColor.rgb).getGreen(), is(testColor.g)); - assertThat(testColor.name, Color.fromBGR(testColor.bgr).getGreen(), is(testColor.g)); - assertThat(testColor.name, Color.fromRGB(testColor.r, testColor.g, testColor.b).getGreen(), is(testColor.g)); - assertThat(testColor.name, Color.fromBGR(testColor.b, testColor.g, testColor.r).getGreen(), is(testColor.g)); + assertThat(Color.fromRGB(testColor.rgb).getGreen(), is(testColor.g), testColor.name); + assertThat(Color.fromBGR(testColor.bgr).getGreen(), is(testColor.g), testColor.name); + assertThat(Color.fromRGB(testColor.r, testColor.g, testColor.b).getGreen(), is(testColor.g), testColor.name); + assertThat(Color.fromBGR(testColor.b, testColor.g, testColor.r).getGreen(), is(testColor.g), testColor.name); } } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG01() { - Color.fromRGB(0x00, -1, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, -1, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG02() { - Color.fromRGB(0x00, Integer.MAX_VALUE, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, Integer.MAX_VALUE, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG03() { - Color.fromRGB(0x00, Integer.MIN_VALUE, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, Integer.MIN_VALUE, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG04() { - Color.fromRGB(0x00, 0x100, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromRGB(0x00, 0x100, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG05() { - Color.fromBGR(0x00, -1, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, -1, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG06() { - Color.fromBGR(0x00, Integer.MAX_VALUE, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, Integer.MAX_VALUE, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG07() { - Color.fromBGR(0x00, Integer.MIN_VALUE, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, Integer.MIN_VALUE, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG08() { - Color.fromBGR(0x00, 0x100, 0x00); + assertThrows(IllegalArgumentException.class, () -> Color.fromBGR(0x00, 0x100, 0x00)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG09() { - Color.WHITE.setGreen(-1); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setGreen(-1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG10() { - Color.WHITE.setGreen(Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setGreen(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG11() { - Color.WHITE.setGreen(Integer.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setGreen(Integer.MIN_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidG12() { - Color.WHITE.setGreen(0x100); + assertThrows(IllegalArgumentException.class, () -> Color.WHITE.setGreen(0x100)); } } diff --git a/src/test/java/org/bukkit/CropStateTest.java b/src/test/java/org/bukkit/CropStateTest.java index 5cd9d6d2..6efe3f1c 100644 --- a/src/test/java/org/bukkit/CropStateTest.java +++ b/src/test/java/org/bukkit/CropStateTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CropStateTest { @Test diff --git a/src/test/java/org/bukkit/DifficultyTest.java b/src/test/java/org/bukkit/DifficultyTest.java index d7fe8d39..37623027 100644 --- a/src/test/java/org/bukkit/DifficultyTest.java +++ b/src/test/java/org/bukkit/DifficultyTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class DifficultyTest { @Test diff --git a/src/test/java/org/bukkit/DyeColorTest.java b/src/test/java/org/bukkit/DyeColorTest.java index e56d9439..4e9ff14f 100644 --- a/src/test/java/org/bukkit/DyeColorTest.java +++ b/src/test/java/org/bukkit/DyeColorTest.java @@ -1,69 +1,57 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import java.util.ArrayList; -import java.util.List; import org.bukkit.material.Colorable; import org.bukkit.material.Dye; import org.bukkit.material.Wool; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; -@RunWith(Parameterized.class) public class DyeColorTest { - @Parameters(name = "{index}: {0}") - public static List data() { - List list = new ArrayList(); - for (DyeColor dye : DyeColor.values()) { - list.add(new Object[] {dye}); - } - return list; - } - - @Parameter public DyeColor dye; - - @Test + @ParameterizedTest + @EnumSource(DyeColor.class) @SuppressWarnings("deprecation") - public void getByData() { + public void getByData(DyeColor dye) { byte data = dye.getWoolData(); DyeColor byData = DyeColor.getByWoolData(data); assertThat(byData, is(dye)); } - @Test - public void getByWoolData() { + @ParameterizedTest + @EnumSource(DyeColor.class) + public void getByWoolData(DyeColor dye) { byte data = dye.getWoolData(); DyeColor byData = DyeColor.getByWoolData(data); assertThat(byData, is(dye)); } - @Test - public void getByDyeData() { + @ParameterizedTest + @EnumSource(DyeColor.class) + public void getByDyeData(DyeColor dye) { byte data = dye.getDyeData(); DyeColor byData = DyeColor.getByDyeData(data); assertThat(byData, is(dye)); } - @Test - public void getDyeDyeColor() { - testColorable(new Dye(Material.LEGACY_INK_SACK, dye.getDyeData())); - testColorable(new Dye(dye)); + @ParameterizedTest + @EnumSource(DyeColor.class) + public void getDyeDyeColor(DyeColor dye) { + testColorable(new Dye(Material.LEGACY_INK_SACK, dye.getDyeData()), dye); + testColorable(new Dye(dye), dye); } - @Test - public void getWoolDyeColor() { - testColorable(new Wool(Material.LEGACY_WOOL, dye.getWoolData())); + @ParameterizedTest + @EnumSource(DyeColor.class) + public void getWoolDyeColor(DyeColor dye) { + testColorable(new Wool(Material.LEGACY_WOOL, dye.getWoolData()), dye); } - private void testColorable(final Colorable colorable) { - assertThat(colorable.getColor(), is(this.dye)); + private void testColorable(final Colorable colorable, DyeColor dye) { + assertThat(colorable.getColor(), is(dye)); } } diff --git a/src/test/java/org/bukkit/EffectTest.java b/src/test/java/org/bukkit/EffectTest.java index 54e621e8..4344512f 100644 --- a/src/test/java/org/bukkit/EffectTest.java +++ b/src/test/java/org/bukkit/EffectTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class EffectTest { @Test diff --git a/src/test/java/org/bukkit/GameModeTest.java b/src/test/java/org/bukkit/GameModeTest.java index 1c53e8ed..c5d3a151 100644 --- a/src/test/java/org/bukkit/GameModeTest.java +++ b/src/test/java/org/bukkit/GameModeTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class GameModeTest { @Test diff --git a/src/test/java/org/bukkit/GrassSpeciesTest.java b/src/test/java/org/bukkit/GrassSpeciesTest.java index 39f1b899..6739dc24 100644 --- a/src/test/java/org/bukkit/GrassSpeciesTest.java +++ b/src/test/java/org/bukkit/GrassSpeciesTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class GrassSpeciesTest { @Test diff --git a/src/test/java/org/bukkit/InstrumentTest.java b/src/test/java/org/bukkit/InstrumentTest.java index 14ad060e..8c1d8888 100644 --- a/src/test/java/org/bukkit/InstrumentTest.java +++ b/src/test/java/org/bukkit/InstrumentTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class InstrumentTest { @Test diff --git a/src/test/java/org/bukkit/LastChatColorTest.java b/src/test/java/org/bukkit/LastChatColorTest.java index 64e164ea..3d1c839c 100644 --- a/src/test/java/org/bukkit/LastChatColorTest.java +++ b/src/test/java/org/bukkit/LastChatColorTest.java @@ -1,40 +1,30 @@ package org.bukkit; -import static org.junit.Assert.*; -import java.util.Arrays; -import java.util.Collection; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import static org.junit.jupiter.api.Assertions.*; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class LastChatColorTest { - @Parameterized.Parameters - public static Collection data() { - return Arrays.asList(new Object[][]{ - {String.format("%c%ctest%c%ctest%c", ChatColor.COLOR_CHAR, ChatColor.RED.getChar(), ChatColor.COLOR_CHAR, ChatColor.ITALIC.getChar(), ChatColor.COLOR_CHAR), ChatColor.RED.toString() + ChatColor.ITALIC}, - {String.format("%c%ctest%c%ctest", ChatColor.COLOR_CHAR, ChatColor.RED.getChar(), ChatColor.COLOR_CHAR, ChatColor.BLUE.getChar()), ChatColor.BLUE.toString()}, - {"§x§1§2§3§4§5§6", "§x§1§2§3§4§5§6"}, - {"§y§1§2§3§4§5§6", "§6"}, - {"§3§4§5§6", "§6"}, - {"Test2§x§1§f§3§4§F§6test§l", "§x§1§f§3§4§F§6§l"}, - {"Test2§x§P§f§3§4§F§6test§l", "§6§l"}, - {"Test2§x§fxf§3§4§F§6test§l", "§6§l"}, - {"Test2§x§1§4§F§6test§l", "§6§l"} - }); + public static Stream data() { + return Stream.of( + Arguments.of(String.format("%c%ctest%c%ctest%c", ChatColor.COLOR_CHAR, ChatColor.RED.getChar(), ChatColor.COLOR_CHAR, ChatColor.ITALIC.getChar(), ChatColor.COLOR_CHAR), ChatColor.RED.toString() + ChatColor.ITALIC), + Arguments.of(String.format("%c%ctest%c%ctest", ChatColor.COLOR_CHAR, ChatColor.RED.getChar(), ChatColor.COLOR_CHAR, ChatColor.BLUE.getChar()), ChatColor.BLUE.toString()), + Arguments.of("§x§1§2§3§4§5§6", "§x§1§2§3§4§5§6"), + Arguments.of("§y§1§2§3§4§5§6", "§6"), + Arguments.of("§3§4§5§6", "§6"), + Arguments.of("Test2§x§1§f§3§4§F§6test§l", "§x§1§f§3§4§F§6§l"), + Arguments.of("Test2§x§P§f§3§4§F§6test§l", "§6§l"), + Arguments.of("Test2§x§fxf§3§4§F§6test§l", "§6§l"), + Arguments.of("Test2§x§1§4§F§6test§l", "§6§l") + ); } - private final String input; - private final String expected; - - public LastChatColorTest(String input, String expected) { - this.input = input; - this.expected = expected; - } - - @Test - public void testGetLastColors() { + @ParameterizedTest + @MethodSource("data") + public void testGetLastColors(String input, String expected) { assertEquals(expected, ChatColor.getLastColors(input)); } } diff --git a/src/test/java/org/bukkit/LocationTest.java b/src/test/java/org/bukkit/LocationTest.java index 02b97fa7..35a98c14 100644 --- a/src/test/java/org/bukkit/LocationTest.java +++ b/src/test/java/org/bukkit/LocationTest.java @@ -1,19 +1,15 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import static org.mockito.Mockito.*; -import com.google.common.collect.ImmutableList; -import java.util.List; import java.util.Random; +import java.util.stream.Stream; import org.bukkit.util.Vector; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class LocationTest { private static final double delta = 1.0 / 1000000; /** @@ -37,59 +33,58 @@ public class LocationTest { */ private static final double HALF_HALF_UNIT = Math.sqrt(1 / 4f); - @Parameters(name = "{index}: {0}") - public static List data() { + public static Stream data() { Random RANDOM = new Random(1L); // Test is deterministic int r = 0; - return ImmutableList.of( - new Object[]{"X", + return Stream.of( + Arguments.of("X", 1, 0, 0, 270, 0 - }, - new Object[]{"-X", + ), + Arguments.of("-X", -1, 0, 0, 90, 0 - }, - new Object[]{"Z", + ), + Arguments.of("Z", 0, 0, 1, 0, 0 - }, - new Object[]{"-Z", + ), + Arguments.of("-Z", 0, 0, -1, 180, 0 - }, - new Object[]{"Y", + ), + Arguments.of("Y", 0, 1, 0, 0, -90 // Zero is here as a "default" value - }, - new Object[]{"-Y", + ), + Arguments.of("-Y", 0, -1, 0, 0, 90 // Zero is here as a "default" value - }, - new Object[]{"X Z", + ), + Arguments.of("X Z", HALF_UNIT, 0, HALF_UNIT, (270 + 360) / 2, 0 - }, - new Object[]{"X -Z", + ), + Arguments.of("X -Z", HALF_UNIT, 0, -HALF_UNIT, (270 + 180) / 2, 0 - }, - new Object[]{"-X -Z", + ), + Arguments.of("-X -Z", -HALF_UNIT, 0, -HALF_UNIT, (90 + 180) / 2, 0 - }, - new Object[]{"-X Z", + ), + Arguments.of("-X Z", -HALF_UNIT, 0, HALF_UNIT, (90 + 0) / 2, 0 - }, - new Object[]{"X Y Z", + ), + Arguments.of("X Y Z", HALF_HALF_UNIT, HALF_UNIT, HALF_HALF_UNIT, (270 + 360) / 2, -45 - }, - new Object[]{"-X -Y -Z", + ), + Arguments.of("-X -Y -Z", -HALF_HALF_UNIT, -HALF_UNIT, -HALF_HALF_UNIT, (90 + 180) / 2, 45 - }, + ), getRandom(RANDOM, r++), getRandom(RANDOM, r++), getRandom(RANDOM, r++), @@ -111,7 +106,7 @@ public class LocationTest { ); } - private static Object[] getRandom(Random random, int index) { + private static Arguments getRandom(Random random, int index) { final double YAW_FACTOR = 360; final double YAW_OFFSET = 0; final double PITCH_FACTOR = 180; @@ -141,52 +136,42 @@ public class LocationTest { location.setDirection(vector); } - return new Object[]{"R" + index, + return Arguments.of("R" + index, vector.getX(), vector.getY(), vector.getZ(), location.getYaw(), location.getPitch() - }; + ); } - @Parameter(0) - public String nane; - @Parameter(1) - public double x; - @Parameter(2) - public double y; - @Parameter(3) - public double z; - @Parameter(4) - public float yaw; - @Parameter(5) - public float pitch; - - @Test - public void testExpectedPitchYaw() { - Location location = getEmptyLocation().setDirection(getVector()); + @ParameterizedTest + @MethodSource("data") + public void testExpectedPitchYaw(String name, double x, double y, double z, float yaw, float pitch) { + Location location = getEmptyLocation().setDirection(getVector(x, y, z)); assertThat((double) location.getYaw(), is(closeTo(yaw, delta))); assertThat((double) location.getPitch(), is(closeTo(pitch, delta))); } - @Test - public void testExpectedXYZ() { - Vector vector = getLocation().getDirection(); + @ParameterizedTest + @MethodSource("data") + public void testExpectedXYZ(String name, double x, double y, double z, float yaw, float pitch) { + Vector vector = getLocation(yaw, pitch).getDirection(); assertThat(vector.getX(), is(closeTo(x, delta))); assertThat(vector.getY(), is(closeTo(y, delta))); assertThat(vector.getZ(), is(closeTo(z, delta))); } - @Test - public void testEquals() { - Location first = getLocation().add(getVector()); - Location second = getLocation().add(getVector()); + @ParameterizedTest + @MethodSource("data") + public void testEquals(String name, double x, double y, double z, float yaw, float pitch) { + Location first = getLocation(yaw, pitch).add(getVector(x, y, z)); + Location second = getLocation(yaw, pitch).add(getVector(x, y, z)); assertThat(first.hashCode(), is(second.hashCode())); assertThat(first, is(second)); } - private Vector getVector() { + private Vector getVector(double x, double y, double z) { return new Vector(x, y, z); } @@ -196,7 +181,7 @@ public class LocationTest { return new Location(TEST_WORLD, 0, 0, 0); } - private Location getLocation() { + private Location getLocation(float yaw, float pitch) { Location location = getEmptyLocation(); location.setYaw(yaw); location.setPitch(pitch); diff --git a/src/test/java/org/bukkit/MaterialTest.java b/src/test/java/org/bukkit/MaterialTest.java index 6b0eaaad..818aa21d 100644 --- a/src/test/java/org/bukkit/MaterialTest.java +++ b/src/test/java/org/bukkit/MaterialTest.java @@ -1,9 +1,10 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.material.MaterialData; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MaterialTest { @Test @@ -30,9 +31,9 @@ public class MaterialTest { } } - @Test(expected = IllegalArgumentException.class) + @Test public void matchMaterialByNull() { - Material.matchMaterial(null); + assertThrows(IllegalArgumentException.class, () -> Material.matchMaterial(null)); } @Test diff --git a/src/test/java/org/bukkit/NamespacedKeyTest.java b/src/test/java/org/bukkit/NamespacedKeyTest.java index 9f57889c..6317798e 100644 --- a/src/test/java/org/bukkit/NamespacedKeyTest.java +++ b/src/test/java/org/bukkit/NamespacedKeyTest.java @@ -1,72 +1,72 @@ package org.bukkit; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class NamespacedKeyTest { @Test public void testValid() { - Assert.assertEquals("minecraft:foo", new NamespacedKey("minecraft", "foo").toString()); - Assert.assertEquals("minecraft:foo/bar", new NamespacedKey("minecraft", "foo/bar").toString()); - Assert.assertEquals("minecraft:foo/bar_baz", new NamespacedKey("minecraft", "foo/bar_baz").toString()); - Assert.assertEquals("minecraft:foo/bar_baz-qux", new NamespacedKey("minecraft", "foo/bar_baz-qux").toString()); - Assert.assertEquals("minecraft:foo/bar_baz-qux.quux", new NamespacedKey("minecraft", "foo/bar_baz-qux.quux").toString()); + assertEquals("minecraft:foo", new NamespacedKey("minecraft", "foo").toString()); + assertEquals("minecraft:foo/bar", new NamespacedKey("minecraft", "foo/bar").toString()); + assertEquals("minecraft:foo/bar_baz", new NamespacedKey("minecraft", "foo/bar_baz").toString()); + assertEquals("minecraft:foo/bar_baz-qux", new NamespacedKey("minecraft", "foo/bar_baz-qux").toString()); + assertEquals("minecraft:foo/bar_baz-qux.quux", new NamespacedKey("minecraft", "foo/bar_baz-qux.quux").toString()); } @Test public void testValidFromString() { NamespacedKey expected = NamespacedKey.minecraft("foo"); - Assert.assertEquals(expected, NamespacedKey.fromString("foo")); - Assert.assertEquals(expected, NamespacedKey.fromString(":foo")); - Assert.assertEquals(expected, NamespacedKey.fromString("minecraft:foo")); - Assert.assertEquals(new NamespacedKey("foo", "bar"), NamespacedKey.fromString("foo:bar")); + assertEquals(expected, NamespacedKey.fromString("foo")); + assertEquals(expected, NamespacedKey.fromString(":foo")); + assertEquals(expected, NamespacedKey.fromString("minecraft:foo")); + assertEquals(new NamespacedKey("foo", "bar"), NamespacedKey.fromString("foo:bar")); - Assert.assertNull(NamespacedKey.fromString("fOO")); - Assert.assertNull(NamespacedKey.fromString(":Foo")); - Assert.assertNull(NamespacedKey.fromString("fOO:bar")); - Assert.assertNull(NamespacedKey.fromString("minecraft:fOO")); - Assert.assertNull(NamespacedKey.fromString("foo:bar:bazz")); + assertNull(NamespacedKey.fromString("fOO")); + assertNull(NamespacedKey.fromString(":Foo")); + assertNull(NamespacedKey.fromString("fOO:bar")); + assertNull(NamespacedKey.fromString("minecraft:fOO")); + assertNull(NamespacedKey.fromString("foo:bar:bazz")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testFromStringEmptyInput() { - NamespacedKey.fromString(""); + assertThrows(IllegalArgumentException.class, () -> NamespacedKey.fromString("")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testFromStringNullInput() { - NamespacedKey.fromString(null); + assertThrows(IllegalArgumentException.class, () -> NamespacedKey.fromString(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testEmptyNamespace() { - new NamespacedKey("", "foo").toString(); + assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("", "foo").toString()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testEmptyKey() { - new NamespacedKey("minecraft", "").toString(); + assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("minecraft", "").toString()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidNamespace() { - new NamespacedKey("minecraft/test", "foo").toString(); + assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("minecraft/test", "foo").toString()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidNamespaceCasing() { - new NamespacedKey("Minecraft", "foo").toString(); + assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("Minecraft", "foo").toString()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidKeyCasing() { - new NamespacedKey("minecraft", "Foo").toString(); + assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("minecraft", "Foo").toString()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidKey() { - new NamespacedKey("minecraft", "foo!").toString(); + assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("minecraft", "foo!").toString()); } @Test @@ -75,10 +75,10 @@ public class NamespacedKeyTest { "loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas").toString(); } - @Test(expected = IllegalArgumentException.class) + @Test public void testAboveLength() { - new NamespacedKey("loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas", + assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas", "loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas/" - + "loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas").toString(); + + "loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas").toString()); } } diff --git a/src/test/java/org/bukkit/NoteTest.java b/src/test/java/org/bukkit/NoteTest.java index 0db4bfa4..616f4ce9 100644 --- a/src/test/java/org/bukkit/NoteTest.java +++ b/src/test/java/org/bukkit/NoteTest.java @@ -1,10 +1,11 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import com.google.common.collect.Lists; import java.util.Collection; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class NoteTest { @Test @@ -51,24 +52,24 @@ public class NoteTest { } } - @Test(expected = IllegalArgumentException.class) + @Test public void createNoteBelowMin() { - new Note((byte) -1); + assertThrows(IllegalArgumentException.class, () -> new Note((byte) -1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void createNoteAboveMax() { - new Note((byte) 25); + assertThrows(IllegalArgumentException.class, () -> new Note((byte) 25)); } - @Test(expected = IllegalArgumentException.class) + @Test public void createNoteOctaveBelowMax() { - new Note((byte) -1, Note.Tone.A, true); + assertThrows(IllegalArgumentException.class, () -> new Note((byte) -1, Note.Tone.A, true)); } - @Test(expected = IllegalArgumentException.class) + @Test public void createNoteOctaveAboveMax() { - new Note((byte) 3, Note.Tone.A, true); + assertThrows(IllegalArgumentException.class, () -> new Note((byte) 3, Note.Tone.A, true)); } @Test @@ -114,9 +115,9 @@ public class NoteTest { assertEquals(note.getOctave(), 2); } - @Test(expected = IllegalArgumentException.class) + @Test public void testSharpWrapping2() { - new Note(2, Note.Tone.F, true).sharped(); + assertThrows(IllegalArgumentException.class, () -> new Note(2, Note.Tone.F, true).sharped()); } @Test diff --git a/src/test/java/org/bukkit/TreeSpeciesTest.java b/src/test/java/org/bukkit/TreeSpeciesTest.java index 51e956cc..66401d83 100644 --- a/src/test/java/org/bukkit/TreeSpeciesTest.java +++ b/src/test/java/org/bukkit/TreeSpeciesTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TreeSpeciesTest { @Test diff --git a/src/test/java/org/bukkit/WorldTypeTest.java b/src/test/java/org/bukkit/WorldTypeTest.java index 3c5f7b8a..65149906 100644 --- a/src/test/java/org/bukkit/WorldTypeTest.java +++ b/src/test/java/org/bukkit/WorldTypeTest.java @@ -1,8 +1,8 @@ package org.bukkit; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class WorldTypeTest { @Test diff --git a/src/test/java/org/bukkit/configuration/ConfigurationSectionTest.java b/src/test/java/org/bukkit/configuration/ConfigurationSectionTest.java index 95de9458..4982d38b 100644 --- a/src/test/java/org/bukkit/configuration/ConfigurationSectionTest.java +++ b/src/test/java/org/bukkit/configuration/ConfigurationSectionTest.java @@ -1,6 +1,6 @@ package org.bukkit.configuration; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -12,7 +12,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemType; import org.bukkit.support.AbstractTestingBase; import org.bukkit.util.Vector; -import org.junit.Test; +import org.junit.jupiter.api.Test; public abstract class ConfigurationSectionTest extends AbstractTestingBase { public abstract ConfigurationSection getConfigurationSection(); diff --git a/src/test/java/org/bukkit/configuration/ConfigurationTest.java b/src/test/java/org/bukkit/configuration/ConfigurationTest.java index 65f6ba38..e5d92691 100644 --- a/src/test/java/org/bukkit/configuration/ConfigurationTest.java +++ b/src/test/java/org/bukkit/configuration/ConfigurationTest.java @@ -1,6 +1,6 @@ package org.bukkit.configuration; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -9,7 +9,7 @@ import java.util.Map; import java.util.Set; import org.bukkit.configuration.serialization.ConfigurationSerialization; import org.bukkit.util.Vector; -import org.junit.Test; +import org.junit.jupiter.api.Test; public abstract class ConfigurationTest { diff --git a/src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java b/src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java index d6a14103..c25303e8 100644 --- a/src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java +++ b/src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java @@ -1,6 +1,6 @@ package org.bukkit.configuration.file; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; @@ -8,13 +8,12 @@ import java.util.Arrays; import java.util.List; import java.util.Map; import org.bukkit.configuration.MemoryConfigurationTest; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; public abstract class FileConfigurationTest extends MemoryConfigurationTest { - @Rule - public TemporaryFolder testFolder = new TemporaryFolder(); + @TempDir + public File testFolder; @Override public abstract FileConfiguration getConfig(); @@ -36,7 +35,8 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest { @Test public void testSave_File() throws Exception { FileConfiguration config = getConfig(); - File file = testFolder.newFile("test.config"); + File file = new File(testFolder, "test.config"); + file.createNewFile(); for (Map.Entry entry : getTestValues().entrySet()) { config.set(entry.getKey(), entry.getValue()); @@ -50,7 +50,8 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest { @Test public void testSave_String() throws Exception { FileConfiguration config = getConfig(); - File file = testFolder.newFile("test.config"); + File file = new File(testFolder, "test.config"); + file.createNewFile(); for (Map.Entry entry : getTestValues().entrySet()) { config.set(entry.getKey(), entry.getValue()); @@ -78,7 +79,8 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest { @Test public void testLoad_File() throws Exception { FileConfiguration config = getConfig(); - File file = testFolder.newFile("test.config"); + File file = new File(testFolder, "test.config"); + file.createNewFile(); BufferedWriter writer = new BufferedWriter(new FileWriter(file)); String saved = getTestValuesString(); Map values = getTestValues(); @@ -101,7 +103,8 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest { @Test public void testLoad_String() throws Exception { FileConfiguration config = getConfig(); - File file = testFolder.newFile("test.config"); + File file = new File(testFolder, "test.config"); + file.createNewFile(); BufferedWriter writer = new BufferedWriter(new FileWriter(file)); String saved = getTestValuesString(); Map values = getTestValues(); diff --git a/src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java b/src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java index 003f45d8..82c7f6ba 100644 --- a/src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java +++ b/src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java @@ -1,6 +1,6 @@ package org.bukkit.configuration.file; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -12,7 +12,7 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.MemoryConfiguration; import org.jetbrains.annotations.NotNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class YamlConfigurationTest extends FileConfigurationTest { diff --git a/src/test/java/org/bukkit/conversations/ConversationContextTest.java b/src/test/java/org/bukkit/conversations/ConversationContextTest.java index 3780a47c..48349dfb 100644 --- a/src/test/java/org/bukkit/conversations/ConversationContextTest.java +++ b/src/test/java/org/bukkit/conversations/ConversationContextTest.java @@ -1,9 +1,9 @@ package org.bukkit.conversations; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** */ @@ -19,7 +19,7 @@ public class ConversationContextTest { public void TestPlugin() { Conversable conversable = new FakeConversable(); ConversationContext context = new ConversationContext(null, conversable, new HashMap()); - assertEquals(null, context.getPlugin()); + assertNull(context.getPlugin()); } @Test diff --git a/src/test/java/org/bukkit/conversations/ConversationTest.java b/src/test/java/org/bukkit/conversations/ConversationTest.java index c448dc72..8a515b0f 100644 --- a/src/test/java/org/bukkit/conversations/ConversationTest.java +++ b/src/test/java/org/bukkit/conversations/ConversationTest.java @@ -1,8 +1,8 @@ package org.bukkit.conversations; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.plugin.TestPlugin; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** */ diff --git a/src/test/java/org/bukkit/conversations/ValidatingPromptTest.java b/src/test/java/org/bukkit/conversations/ValidatingPromptTest.java index 6093e986..b0c6eb93 100644 --- a/src/test/java/org/bukkit/conversations/ValidatingPromptTest.java +++ b/src/test/java/org/bukkit/conversations/ValidatingPromptTest.java @@ -1,7 +1,7 @@ package org.bukkit.conversations; -import static org.junit.Assert.*; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; /** */ diff --git a/src/test/java/org/bukkit/entity/memory/MemoryKeyTest.java b/src/test/java/org/bukkit/entity/memory/MemoryKeyTest.java index b955f6a7..2e426a90 100644 --- a/src/test/java/org/bukkit/entity/memory/MemoryKeyTest.java +++ b/src/test/java/org/bukkit/entity/memory/MemoryKeyTest.java @@ -1,41 +1,41 @@ package org.bukkit.entity.memory; +import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; import java.util.List; import org.bukkit.NamespacedKey; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MemoryKeyTest { @Test public void shouldContainAllMemories() { List memories = Arrays.asList(MemoryKey.HOME, MemoryKey.JOB_SITE, MemoryKey.MEETING_POINT); - Assert.assertTrue(MemoryKey.values().containsAll(memories)); + assertTrue(MemoryKey.values().containsAll(memories)); } @Test public void shouldGetMemoryKeyHomeByNamespacedKey() { - Assert.assertEquals(MemoryKey.HOME, MemoryKey.getByKey(NamespacedKey.minecraft("home"))); + assertEquals(MemoryKey.HOME, MemoryKey.getByKey(NamespacedKey.minecraft("home"))); } @Test public void shouldGetMemoryKeyJobSiteByNamespacedKey() { - Assert.assertEquals(MemoryKey.JOB_SITE, MemoryKey.getByKey(NamespacedKey.minecraft("job_site"))); + assertEquals(MemoryKey.JOB_SITE, MemoryKey.getByKey(NamespacedKey.minecraft("job_site"))); } @Test public void shouldGetMemoryKeyMeetingPointByNamespacedKey() { - Assert.assertEquals(MemoryKey.MEETING_POINT, MemoryKey.getByKey(NamespacedKey.minecraft("meeting_point"))); + assertEquals(MemoryKey.MEETING_POINT, MemoryKey.getByKey(NamespacedKey.minecraft("meeting_point"))); } @Test public void shouldReturnNullWhenNamespacedKeyisNotPresentAsMemoryKey() { - Assert.assertEquals(null, MemoryKey.getByKey(NamespacedKey.minecraft("not_present"))); + assertNull(MemoryKey.getByKey(NamespacedKey.minecraft("not_present"))); } @Test public void shouldReturnNullWhenNamespacedKeyisNull() { - Assert.assertNull(MemoryKey.getByKey(null)); + assertNull(MemoryKey.getByKey(null)); } } diff --git a/src/test/java/org/bukkit/event/PlayerChatTabCompleteEventTest.java b/src/test/java/org/bukkit/event/PlayerChatTabCompleteEventTest.java index 3d2d7f4d..c80cdd84 100644 --- a/src/test/java/org/bukkit/event/PlayerChatTabCompleteEventTest.java +++ b/src/test/java/org/bukkit/event/PlayerChatTabCompleteEventTest.java @@ -1,12 +1,12 @@ package org.bukkit.event; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.bukkit.support.MatcherAssert.*; +import static org.hamcrest.Matchers.*; import static org.mockito.Mockito.*; import com.google.common.collect.ImmutableList; import org.bukkit.event.player.PlayerChatTabCompleteEvent; import org.bukkit.support.AbstractTestingBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PlayerChatTabCompleteEventTest extends AbstractTestingBase { diff --git a/src/test/java/org/bukkit/event/SyntheticEventTest.java b/src/test/java/org/bukkit/event/SyntheticEventTest.java index ab53cf14..40a086f2 100644 --- a/src/test/java/org/bukkit/event/SyntheticEventTest.java +++ b/src/test/java/org/bukkit/event/SyntheticEventTest.java @@ -1,13 +1,13 @@ package org.bukkit.event; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginLoader; import org.bukkit.plugin.SimplePluginManager; import org.bukkit.plugin.TestPlugin; import org.bukkit.plugin.java.JavaPluginLoader; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SyntheticEventTest extends AbstractTestingBase { @SuppressWarnings("deprecation") @@ -28,7 +28,7 @@ public class SyntheticEventTest extends AbstractTestingBase { pluginManager.registerEvents(impl, plugin); pluginManager.callEvent(event); - Assert.assertEquals(1, impl.callCount); + assertEquals(1, impl.callCount); } public abstract static class Base implements Listener { diff --git a/src/test/java/org/bukkit/materials/MaterialDataTest.java b/src/test/java/org/bukkit/materials/MaterialDataTest.java index a935ae4a..8d78435c 100644 --- a/src/test/java/org/bukkit/materials/MaterialDataTest.java +++ b/src/test/java/org/bukkit/materials/MaterialDataTest.java @@ -1,7 +1,7 @@ package org.bukkit.materials; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import org.bukkit.CropState; import org.bukkit.Material; import org.bukkit.NetherWartsState; @@ -20,7 +20,7 @@ import org.bukkit.material.Tree; import org.bukkit.material.Wood; import org.bukkit.material.WoodenStep; import org.bukkit.material.types.MushroomBlockTexture; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MaterialDataTest { @@ -28,10 +28,10 @@ public class MaterialDataTest { public void testDoor() { @SuppressWarnings("deprecation") Door door = new Door(); - assertThat("Constructed with default door type", door.getItemType(), equalTo(Material.LEGACY_WOODEN_DOOR)); - assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(false)); - assertThat("Constructed with default direction", door.getFacing(), equalTo(BlockFace.WEST)); - assertThat("Constructed with default open state", door.isOpen(), equalTo(false)); + assertThat(door.getItemType(), equalTo(Material.LEGACY_WOODEN_DOOR), "Constructed with default door type"); + assertThat(door.isTopHalf(), equalTo(false), "Constructed with default top or bottom"); + assertThat(door.getFacing(), equalTo(BlockFace.WEST), "Constructed with default direction"); + assertThat(door.isOpen(), equalTo(false), "Constructed with default open state"); Material[] types = new Material[]{Material.LEGACY_WOODEN_DOOR, Material.LEGACY_IRON_DOOR_BLOCK, Material.LEGACY_SPRUCE_DOOR, @@ -44,26 +44,26 @@ public class MaterialDataTest { // Test bottom half for (BlockFace facing : directions) { door = new Door(type, facing); - assertThat("Constructed with correct door type", door.getItemType(), equalTo(type)); - assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(false)); - assertThat("Constructed with correct direction", door.getFacing(), equalTo(facing)); - assertThat("Constructed with default open state", door.isOpen(), equalTo(false)); + assertThat(door.getItemType(), equalTo(type), "Constructed with correct door type"); + assertThat(door.isTopHalf(), equalTo(false), "Constructed with default top or bottom"); + assertThat(door.getFacing(), equalTo(facing), "Constructed with correct direction"); + assertThat(door.isOpen(), equalTo(false), "Constructed with default open state"); for (boolean openState : openStates) { door = new Door(type, facing, openState); - assertThat("Constructed with correct door type", door.getItemType(), equalTo(type)); - assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(false)); - assertThat("Constructed with correct direction", door.getFacing(), equalTo(facing)); - assertThat("Constructed with correct open state", door.isOpen(), equalTo(openState)); + assertThat(door.getItemType(), equalTo(type), "Constructed with correct door type"); + assertThat(door.isTopHalf(), equalTo(false), "Constructed with default top or bottom"); + assertThat(door.getFacing(), equalTo(facing), "Constructed with correct direction"); + assertThat(door.isOpen(), equalTo(openState), "Constructed with correct open state"); } } // Test top half for (boolean hingeState : hingeStates) { door = new Door(type, hingeState); - assertThat("Constructed with correct door type", door.getItemType(), equalTo(type)); - assertThat("Constructed with default top or bottom", door.isTopHalf(), equalTo(true)); - assertThat("Constructed with correct direction", door.getHinge(), equalTo(hingeState)); + assertThat(door.getItemType(), equalTo(type), "Constructed with correct door type"); + assertThat(door.isTopHalf(), equalTo(true), "Constructed with default top or bottom"); + assertThat(door.getHinge(), equalTo(hingeState), "Constructed with correct direction"); } } } @@ -71,26 +71,26 @@ public class MaterialDataTest { @Test public void testWood() { Wood wood = new Wood(); - assertThat("Constructed with default wood type", wood.getItemType(), equalTo(Material.LEGACY_WOOD)); - assertThat("Constructed with default tree species", wood.getSpecies(), equalTo(TreeSpecies.GENERIC)); + assertThat(wood.getItemType(), equalTo(Material.LEGACY_WOOD), "Constructed with default wood type"); + assertThat(wood.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species"); TreeSpecies[] allSpecies = TreeSpecies.values(); for (TreeSpecies species : allSpecies) { wood = new Wood(species); - assertThat("Constructed with default wood type", wood.getItemType(), equalTo(Material.LEGACY_WOOD)); - assertThat("Constructed with correct tree species", wood.getSpecies(), equalTo(species)); + assertThat(wood.getItemType(), equalTo(Material.LEGACY_WOOD), "Constructed with default wood type"); + assertThat(wood.getSpecies(), equalTo(species), "Constructed with correct tree species"); } Material[] types = new Material[]{Material.LEGACY_WOOD, Material.LEGACY_WOOD_DOUBLE_STEP}; for (Material type : types) { wood = new Wood(type); - assertThat("Constructed with correct wood type", wood.getItemType(), equalTo(type)); - assertThat("Constructed with default tree species", wood.getSpecies(), equalTo(TreeSpecies.GENERIC)); + assertThat(wood.getItemType(), equalTo(type), "Constructed with correct wood type"); + assertThat(wood.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species"); for (TreeSpecies species : allSpecies) { wood = new Wood(type, species); - assertThat("Constructed with correct wood type", wood.getItemType(), equalTo(type)); - assertThat("Constructed with correct tree species", wood.getSpecies(), equalTo(species)); + assertThat(wood.getItemType(), equalTo(type), "Constructed with correct wood type"); + assertThat(wood.getSpecies(), equalTo(species), "Constructed with correct tree species"); } } } @@ -98,14 +98,14 @@ public class MaterialDataTest { @Test public void testTree() { Tree tree = new Tree(); - assertThat("Constructed with default tree type", tree.getItemType(), equalTo(Material.LEGACY_LOG)); - assertThat("Constructed with default tree species", tree.getSpecies(), equalTo(TreeSpecies.GENERIC)); - assertThat("Constructed with default direction", tree.getDirection(), equalTo(BlockFace.UP)); + assertThat(tree.getItemType(), equalTo(Material.LEGACY_LOG), "Constructed with default tree type"); + assertThat(tree.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species"); + assertThat(tree.getDirection(), equalTo(BlockFace.UP), "Constructed with default direction"); tree = new Tree(Material.LEGACY_LOG); - assertThat("Constructed with correct tree type", tree.getItemType(), equalTo(Material.LEGACY_LOG)); - assertThat("Constructed with default tree species", tree.getSpecies(), equalTo(TreeSpecies.GENERIC)); - assertThat("Constructed with default direction", tree.getDirection(), equalTo(BlockFace.UP)); + assertThat(tree.getItemType(), equalTo(Material.LEGACY_LOG), "Constructed with correct tree type"); + assertThat(tree.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species"); + assertThat(tree.getDirection(), equalTo(BlockFace.UP), "Constructed with default direction"); Material[] types = new Material[]{Material.LEGACY_LOG, Material.LEGACY_LOG_2}; TreeSpecies[][] allSpecies = new TreeSpecies[][]{ @@ -116,20 +116,20 @@ public class MaterialDataTest { for (int t = 0; t < types.length; t++) { for (TreeSpecies species : allSpecies[t]) { tree = new Tree(types[t], species); - assertThat("Constructed with correct tree type", tree.getItemType(), equalTo(types[t])); - assertThat("Constructed with correct tree species", tree.getSpecies(), equalTo(species)); - assertThat("Constructed with default direction", tree.getDirection(), equalTo(BlockFace.UP)); + assertThat(tree.getItemType(), equalTo(types[t]), "Constructed with correct tree type"); + assertThat(tree.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(tree.getDirection(), equalTo(BlockFace.UP), "Constructed with default direction"); // check item type is fixed automatically for invalid type-species combo tree = new Tree(types[types.length - 1 - t], species); - assertThat("Constructed with fixed tree type", tree.getItemType(), equalTo(types[t])); - assertThat("Constructed with correct tree species", tree.getSpecies(), equalTo(species)); - assertThat("Constructed with default direction", tree.getDirection(), equalTo(BlockFace.UP)); + assertThat(tree.getItemType(), equalTo(types[t]), "Constructed with fixed tree type"); + assertThat(tree.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(tree.getDirection(), equalTo(BlockFace.UP), "Constructed with default direction"); for (BlockFace dir : allDirections) { tree = new Tree(types[t], species, dir); - assertThat("Constructed with correct tree type", tree.getItemType(), equalTo(types[t])); - assertThat("Constructed with correct tree species", tree.getSpecies(), equalTo(species)); - assertThat("Constructed with correct direction", tree.getDirection(), equalTo(dir)); + assertThat(tree.getItemType(), equalTo(types[t]), "Constructed with correct tree type"); + assertThat(tree.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(tree.getDirection(), equalTo(dir), "Constructed with correct direction"); } } } @@ -138,16 +138,16 @@ public class MaterialDataTest { @Test public void testLeaves() { Leaves leaves = new Leaves(); - assertThat("Constructed with default leaf type", leaves.getItemType(), equalTo(Material.LEGACY_LEAVES)); - assertThat("Constructed with default tree species", leaves.getSpecies(), equalTo(TreeSpecies.GENERIC)); - assertThat("Constructed with default decayable", leaves.isDecayable(), equalTo(true)); - assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); + assertThat(leaves.getItemType(), equalTo(Material.LEGACY_LEAVES), "Constructed with default leaf type"); + assertThat(leaves.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species"); + assertThat(leaves.isDecayable(), equalTo(true), "Constructed with default decayable"); + assertThat(leaves.isDecaying(), equalTo(false), "Constructed with default decaying"); leaves = new Leaves(Material.LEGACY_LEAVES); - assertThat("Constructed with correct leaf type", leaves.getItemType(), equalTo(Material.LEGACY_LEAVES)); - assertThat("Constructed with default tree species", leaves.getSpecies(), equalTo(TreeSpecies.GENERIC)); - assertThat("Constructed with default decayable", leaves.isDecayable(), equalTo(true)); - assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); + assertThat(leaves.getItemType(), equalTo(Material.LEGACY_LEAVES), "Constructed with correct leaf type"); + assertThat(leaves.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species"); + assertThat(leaves.isDecayable(), equalTo(true), "Constructed with default decayable"); + assertThat(leaves.isDecaying(), equalTo(false), "Constructed with default decaying"); Material[] types = new Material[]{Material.LEGACY_LEAVES, Material.LEGACY_LEAVES_2}; TreeSpecies[][] allSpecies = new TreeSpecies[][]{ @@ -159,30 +159,30 @@ public class MaterialDataTest { for (int t = 0; t < types.length; t++) { for (TreeSpecies species : allSpecies[t]) { leaves = new Leaves(types[t], species); - assertThat("Constructed with correct leaf type", leaves.getItemType(), equalTo(types[t])); - assertThat("Constructed with correct tree species", leaves.getSpecies(), equalTo(species)); - assertThat("Constructed with default decayable", leaves.isDecayable(), equalTo(true)); - assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); + assertThat(leaves.getItemType(), equalTo(types[t]), "Constructed with correct leaf type"); + assertThat(leaves.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(leaves.isDecayable(), equalTo(true), "Constructed with default decayable"); + assertThat(leaves.isDecaying(), equalTo(false), "Constructed with default decaying"); // check item type is fixed automatically for invalid type-species combo leaves = new Leaves(types[types.length - 1 - t], species); - assertThat("Constructed with fixed leaf type", leaves.getItemType(), equalTo(types[t])); - assertThat("Constructed with correct tree species", leaves.getSpecies(), equalTo(species)); - assertThat("Constructed with default decayable", leaves.isDecayable(), equalTo(true)); - assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); + assertThat(leaves.getItemType(), equalTo(types[t]), "Constructed with fixed leaf type"); + assertThat(leaves.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(leaves.isDecayable(), equalTo(true), "Constructed with default decayable"); + assertThat(leaves.isDecaying(), equalTo(false), "Constructed with default decaying"); for (boolean isDecayable : decayable) { leaves = new Leaves(types[t], species, isDecayable); - assertThat("Constructed with correct wood type", leaves.getItemType(), equalTo(types[t])); - assertThat("Constructed with correct tree species", leaves.getSpecies(), equalTo(species)); - assertThat("Constructed with correct decayable", leaves.isDecayable(), equalTo(isDecayable)); - assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); + assertThat(leaves.getItemType(), equalTo(types[t]), "Constructed with correct wood type"); + assertThat(leaves.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(leaves.isDecayable(), equalTo(isDecayable), "Constructed with correct decayable"); + assertThat(leaves.isDecaying(), equalTo(false), "Constructed with default decaying"); for (boolean isDecaying : decaying) { leaves = new Leaves(types[t], species, isDecayable); leaves.setDecaying(isDecaying); - assertThat("Constructed with correct wood type", leaves.getItemType(), equalTo(types[t])); - assertThat("Constructed with correct tree species", leaves.getSpecies(), equalTo(species)); - assertThat("Constructed with correct decayable", leaves.isDecayable(), equalTo(isDecaying || isDecayable)); - assertThat("Constructed with correct decaying", leaves.isDecaying(), equalTo(isDecaying)); + assertThat(leaves.getItemType(), equalTo(types[t]), "Constructed with correct wood type"); + assertThat(leaves.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(leaves.isDecayable(), equalTo(isDecaying || isDecayable), "Constructed with correct decayable"); + assertThat(leaves.isDecaying(), equalTo(isDecaying), "Constructed with correct decaying"); } } } @@ -192,22 +192,22 @@ public class MaterialDataTest { @Test public void testWoodenStep() { WoodenStep woodenStep = new WoodenStep(); - assertThat("Constructed with default step type", woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP)); - assertThat("Constructed with default tree species", woodenStep.getSpecies(), equalTo(TreeSpecies.GENERIC)); - assertThat("Constructed with default inversion", woodenStep.isInverted(), equalTo(false)); + assertThat(woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP), "Constructed with default step type"); + assertThat(woodenStep.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species"); + assertThat(woodenStep.isInverted(), equalTo(false), "Constructed with default inversion"); TreeSpecies[] allSpecies = TreeSpecies.values(); boolean[] inversion = new boolean[]{true, false}; for (TreeSpecies species : allSpecies) { woodenStep = new WoodenStep(species); - assertThat("Constructed with default step type", woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP)); - assertThat("Constructed with correct tree species", woodenStep.getSpecies(), equalTo(species)); - assertThat("Constructed with default inversion", woodenStep.isInverted(), equalTo(false)); + assertThat(woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP), "Constructed with default step type"); + assertThat(woodenStep.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(woodenStep.isInverted(), equalTo(false), "Constructed with default inversion"); for (boolean isInverted : inversion) { woodenStep = new WoodenStep(species, isInverted); - assertThat("Constructed with default step type", woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP)); - assertThat("Constructed with correct tree species", woodenStep.getSpecies(), equalTo(species)); - assertThat("Constructed with correct inversion", woodenStep.isInverted(), equalTo(isInverted)); + assertThat(woodenStep.getItemType(), equalTo(Material.LEGACY_WOOD_STEP), "Constructed with default step type"); + assertThat(woodenStep.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(woodenStep.isInverted(), equalTo(isInverted), "Constructed with correct inversion"); } } } @@ -215,22 +215,22 @@ public class MaterialDataTest { @Test public void testSapling() { Sapling sapling = new Sapling(); - assertThat("Constructed with default sapling type", sapling.getItemType(), equalTo(Material.LEGACY_SAPLING)); - assertThat("Constructed with default tree species", sapling.getSpecies(), equalTo(TreeSpecies.GENERIC)); - assertThat("Constructed with default growable", sapling.isInstantGrowable(), equalTo(false)); + assertThat(sapling.getItemType(), equalTo(Material.LEGACY_SAPLING), "Constructed with default sapling type"); + assertThat(sapling.getSpecies(), equalTo(TreeSpecies.GENERIC), "Constructed with default tree species"); + assertThat(sapling.isInstantGrowable(), equalTo(false), "Constructed with default growable"); TreeSpecies[] allSpecies = TreeSpecies.values(); boolean[] growable = new boolean[]{true, false}; for (TreeSpecies species : allSpecies) { sapling = new Sapling(species); - assertThat("Constructed with default sapling type", sapling.getItemType(), equalTo(Material.LEGACY_SAPLING)); - assertThat("Constructed with correct tree species", sapling.getSpecies(), equalTo(species)); - assertThat("Constructed with default growable", sapling.isInstantGrowable(), equalTo(false)); + assertThat(sapling.getItemType(), equalTo(Material.LEGACY_SAPLING), "Constructed with default sapling type"); + assertThat(sapling.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(sapling.isInstantGrowable(), equalTo(false), "Constructed with default growable"); for (boolean isInstantGrowable : growable) { sapling = new Sapling(species, isInstantGrowable); - assertThat("Constructed with default sapling type", sapling.getItemType(), equalTo(Material.LEGACY_SAPLING)); - assertThat("Constructed with correct tree species", sapling.getSpecies(), equalTo(species)); - assertThat("Constructed with correct growable", sapling.isInstantGrowable(), equalTo(isInstantGrowable)); + assertThat(sapling.getItemType(), equalTo(Material.LEGACY_SAPLING), "Constructed with default sapling type"); + assertThat(sapling.getSpecies(), equalTo(species), "Constructed with correct tree species"); + assertThat(sapling.isInstantGrowable(), equalTo(isInstantGrowable), "Constructed with correct growable"); } } } @@ -244,19 +244,19 @@ public class MaterialDataTest { MushroomBlockTexture[] textures = MushroomBlockTexture.values(); for (Material type : mushroomTypes) { Mushroom mushroom = new Mushroom(type); - assertThat("Constructed with correct mushroom type", mushroom.getItemType(), equalTo(type)); - assertThat("Constructed with default pores face", mushroom.getBlockTexture(), equalTo(MushroomBlockTexture.ALL_PORES)); + assertThat(mushroom.getItemType(), equalTo(type), "Constructed with correct mushroom type"); + assertThat(mushroom.getBlockTexture(), equalTo(MushroomBlockTexture.ALL_PORES), "Constructed with default pores face"); for (int f = 0; f < setFaces.length; f++) { mushroom = new Mushroom(type, setFaces[f]); - assertThat("Constructed with correct mushroom type", mushroom.getItemType(), equalTo(type)); - assertThat("Constructed with correct texture", mushroom.getBlockTexture(), equalTo(MushroomBlockTexture.getCapByFace(setFaces[f]))); + assertThat(mushroom.getItemType(), equalTo(type), "Constructed with correct mushroom type"); + assertThat(mushroom.getBlockTexture(), equalTo(MushroomBlockTexture.getCapByFace(setFaces[f])), "Constructed with correct texture"); } for (MushroomBlockTexture texture : textures) { mushroom = new Mushroom(type, texture); - assertThat("Constructed with correct mushroom type", mushroom.getItemType(), equalTo(type)); - assertThat("Constructed with correct texture", mushroom.getBlockTexture(), equalTo(texture)); + assertThat(mushroom.getItemType(), equalTo(type), "Constructed with correct mushroom type"); + assertThat(mushroom.getBlockTexture(), equalTo(texture), "Constructed with correct texture"); } } } @@ -264,90 +264,90 @@ public class MaterialDataTest { @Test public void testCrops() { Crops crops = new Crops(); - assertThat("Constructed with default crops type", crops.getItemType(), equalTo(Material.LEGACY_CROPS)); - assertThat("Constructed with default crop state", crops.getState(), equalTo(CropState.SEEDED)); + assertThat(crops.getItemType(), equalTo(Material.LEGACY_CROPS), "Constructed with default crops type"); + assertThat(crops.getState(), equalTo(CropState.SEEDED), "Constructed with default crop state"); CropState[] allStates = CropState.values(); for (CropState state : allStates) { crops = new Crops(state); - assertThat("Constructed with default crops type", crops.getItemType(), equalTo(Material.LEGACY_CROPS)); - assertThat("Constructed with correct crop state", crops.getState(), equalTo(state)); + assertThat(crops.getItemType(), equalTo(Material.LEGACY_CROPS), "Constructed with default crops type"); + assertThat(crops.getState(), equalTo(state), "Constructed with correct crop state"); } // The crops which fully implement all crop states Material[] allCrops = new Material[]{Material.LEGACY_CROPS, Material.LEGACY_CARROT, Material.LEGACY_POTATO}; for (Material crop : allCrops) { crops = new Crops(crop); - assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(crop)); - assertThat("Constructed with default crop state", crops.getState(), equalTo(CropState.SEEDED)); + assertThat(crops.getItemType(), equalTo(crop), "Constructed with correct crops type"); + assertThat(crops.getState(), equalTo(CropState.SEEDED), "Constructed with default crop state"); for (CropState state : allStates) { crops = new Crops(crop, state); - assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(crop)); - assertThat("Constructed with correct crop state", crops.getState(), equalTo(state)); + assertThat(crops.getItemType(), equalTo(crop), "Constructed with correct crops type"); + assertThat(crops.getState(), equalTo(state), "Constructed with correct crop state"); } } // Beetroot are crops too, but they only have four states // Setting different crop states for beetroot will return the following when retrieved back CropState[] beetrootStates = new CropState[]{CropState.SEEDED, CropState.SEEDED, CropState.SMALL, CropState.SMALL, CropState.TALL, CropState.TALL, CropState.RIPE, CropState.RIPE}; - assertThat("Beetroot state translations match size", beetrootStates.length, equalTo(allStates.length)); + assertThat(beetrootStates.length, equalTo(allStates.length), "Beetroot state translations match size"); crops = new Crops(Material.LEGACY_BEETROOT_BLOCK); - assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(Material.LEGACY_BEETROOT_BLOCK)); - assertThat("Constructed with default crop state", crops.getState(), equalTo(CropState.SEEDED)); + assertThat(crops.getItemType(), equalTo(Material.LEGACY_BEETROOT_BLOCK), "Constructed with correct crops type"); + assertThat(crops.getState(), equalTo(CropState.SEEDED), "Constructed with default crop state"); for (int s = 0; s < beetrootStates.length; s++) { crops = new Crops(Material.LEGACY_BEETROOT_BLOCK, allStates[s]); - assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(Material.LEGACY_BEETROOT_BLOCK)); - assertThat("Constructed with correct crop state", crops.getState(), equalTo(beetrootStates[s])); + assertThat(crops.getItemType(), equalTo(Material.LEGACY_BEETROOT_BLOCK), "Constructed with correct crops type"); + assertThat(crops.getState(), equalTo(beetrootStates[s]), "Constructed with correct crop state"); } // In case you want to treat NetherWarts as Crops, although they really aren't crops = new Crops(Material.LEGACY_NETHER_WARTS); NetherWarts warts = new NetherWarts(); - assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(warts.getItemType())); - assertThat("Constructed with default crop state", crops.getState(), equalTo(CropState.SEEDED)); - assertThat("Constructed with default wart state", warts.getState(), equalTo(NetherWartsState.SEEDED)); + assertThat(crops.getItemType(), equalTo(warts.getItemType()), "Constructed with correct crops type"); + assertThat(crops.getState(), equalTo(CropState.SEEDED), "Constructed with default crop state"); + assertThat(warts.getState(), equalTo(NetherWartsState.SEEDED), "Constructed with default wart state"); allStates = new CropState[]{CropState.SEEDED, CropState.SMALL, CropState.TALL, CropState.RIPE}; NetherWartsState[] allWartStates = NetherWartsState.values(); - assertThat("Nether Warts state translations match size", allWartStates.length, equalTo(allStates.length)); + assertThat(allWartStates.length, equalTo(allStates.length), "Nether Warts state translations match size"); for (int s = 0; s < allStates.length; s++) { crops = new Crops(Material.LEGACY_NETHER_WARTS, allStates[s]); warts = new NetherWarts(allWartStates[s]); - assertThat("Constructed with correct crops type", crops.getItemType(), equalTo(warts.getItemType())); - assertThat("Constructed with correct crop state", crops.getState(), equalTo(allStates[s])); - assertThat("Constructed with correct wart state", warts.getState(), equalTo(allWartStates[s])); + assertThat(crops.getItemType(), equalTo(warts.getItemType()), "Constructed with correct crops type"); + assertThat(crops.getState(), equalTo(allStates[s]), "Constructed with correct crop state"); + assertThat(warts.getState(), equalTo(allWartStates[s]), "Constructed with correct wart state"); } } @Test public void testDiode() { Diode diode = new Diode(); - assertThat("Constructed with backward compatible diode state", diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_ON)); - assertThat("Constructed with backward compatible powered", diode.isPowered(), equalTo(true)); - assertThat("Constructed with default delay", diode.getDelay(), equalTo(1)); - assertThat("Constructed with default direction", diode.getFacing(), equalTo(BlockFace.NORTH)); + assertThat(diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_ON), "Constructed with backward compatible diode state"); + assertThat(diode.isPowered(), equalTo(true), "Constructed with backward compatible powered"); + assertThat(diode.getDelay(), equalTo(1), "Constructed with default delay"); + assertThat(diode.getFacing(), equalTo(BlockFace.NORTH), "Constructed with default direction"); BlockFace[] directions = new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST}; int[] delays = new int[]{1, 2, 3, 4}; boolean[] states = new boolean[]{false, true}; for (BlockFace direction : directions) { diode = new Diode(direction); - assertThat("Constructed with default diode state", diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_OFF)); - assertThat("Constructed with default powered", diode.isPowered(), equalTo(false)); - assertThat("Constructed with default delay", diode.getDelay(), equalTo(1)); - assertThat("Constructed with correct direction", diode.getFacing(), equalTo(direction)); + assertThat(diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_OFF), "Constructed with default diode state"); + assertThat(diode.isPowered(), equalTo(false), "Constructed with default powered"); + assertThat(diode.getDelay(), equalTo(1), "Constructed with default delay"); + assertThat(diode.getFacing(), equalTo(direction), "Constructed with correct direction"); for (int delay : delays) { diode = new Diode(direction, delay); - assertThat("Constructed with default diode state", diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_OFF)); - assertThat("Constructed with default powered", diode.isPowered(), equalTo(false)); - assertThat("Constructed with correct delay", diode.getDelay(), equalTo(delay)); - assertThat("Constructed with correct direction", diode.getFacing(), equalTo(direction)); + assertThat(diode.getItemType(), equalTo(Material.LEGACY_DIODE_BLOCK_OFF), "Constructed with default diode state"); + assertThat(diode.isPowered(), equalTo(false), "Constructed with default powered"); + assertThat(diode.getDelay(), equalTo(delay), "Constructed with correct delay"); + assertThat(diode.getFacing(), equalTo(direction), "Constructed with correct direction"); for (boolean state : states) { diode = new Diode(direction, delay, state); - assertThat("Constructed with correct diode state", diode.getItemType(), equalTo(state ? Material.LEGACY_DIODE_BLOCK_ON : Material.LEGACY_DIODE_BLOCK_OFF)); - assertThat("Constructed with default powered", diode.isPowered(), equalTo(state)); - assertThat("Constructed with correct delay", diode.getDelay(), equalTo(delay)); - assertThat("Constructed with correct direction", diode.getFacing(), equalTo(direction)); + assertThat(diode.getItemType(), equalTo(state ? Material.LEGACY_DIODE_BLOCK_ON : Material.LEGACY_DIODE_BLOCK_OFF), "Constructed with correct diode state"); + assertThat(diode.isPowered(), equalTo(state), "Constructed with default powered"); + assertThat(diode.getDelay(), equalTo(delay), "Constructed with correct delay"); + assertThat(diode.getFacing(), equalTo(direction), "Constructed with correct direction"); } } } @@ -356,44 +356,44 @@ public class MaterialDataTest { @Test public void testComparator() { Comparator comparator = new Comparator(); - assertThat("Constructed with default comparator state", comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF)); - assertThat("Constructed with default powered", comparator.isPowered(), equalTo(false)); - assertThat("Constructed with default being powered", comparator.isBeingPowered(), equalTo(false)); - assertThat("Constructed with default mode", comparator.isSubtractionMode(), equalTo(false)); - assertThat("Constructed with default direction", comparator.getFacing(), equalTo(BlockFace.NORTH)); + assertThat(comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF), "Constructed with default comparator state"); + assertThat(comparator.isPowered(), equalTo(false), "Constructed with default powered"); + assertThat(comparator.isBeingPowered(), equalTo(false), "Constructed with default being powered"); + assertThat(comparator.isSubtractionMode(), equalTo(false), "Constructed with default mode"); + assertThat(comparator.getFacing(), equalTo(BlockFace.NORTH), "Constructed with default direction"); BlockFace[] directions = new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST}; boolean[] modes = new boolean[]{false, true}; boolean[] states = new boolean[]{false, true}; for (BlockFace direction : directions) { comparator = new Comparator(direction); - assertThat("Constructed with default comparator state", comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF)); - assertThat("Constructed with default powered", comparator.isPowered(), equalTo(false)); - assertThat("Constructed with default being powered", comparator.isBeingPowered(), equalTo(false)); - assertThat("Constructed with default mode", comparator.isSubtractionMode(), equalTo(false)); - assertThat("Constructed with correct direction", comparator.getFacing(), equalTo(direction)); + assertThat(comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF), "Constructed with default comparator state"); + assertThat(comparator.isPowered(), equalTo(false), "Constructed with default powered"); + assertThat(comparator.isBeingPowered(), equalTo(false), "Constructed with default being powered"); + assertThat(comparator.isSubtractionMode(), equalTo(false), "Constructed with default mode"); + assertThat(comparator.getFacing(), equalTo(direction), "Constructed with correct direction"); for (boolean mode : modes) { comparator = new Comparator(direction, mode); - assertThat("Constructed with default comparator state", comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF)); - assertThat("Constructed with default powered", comparator.isPowered(), equalTo(false)); - assertThat("Constructed with default being powered", comparator.isBeingPowered(), equalTo(false)); - assertThat("Constructed with correct mode", comparator.isSubtractionMode(), equalTo(mode)); - assertThat("Constructed with correct direction", comparator.getFacing(), equalTo(direction)); + assertThat(comparator.getItemType(), equalTo(Material.LEGACY_REDSTONE_COMPARATOR_OFF), "Constructed with default comparator state"); + assertThat(comparator.isPowered(), equalTo(false), "Constructed with default powered"); + assertThat(comparator.isBeingPowered(), equalTo(false), "Constructed with default being powered"); + assertThat(comparator.isSubtractionMode(), equalTo(mode), "Constructed with correct mode"); + assertThat(comparator.getFacing(), equalTo(direction), "Constructed with correct direction"); for (boolean state : states) { comparator = new Comparator(direction, mode, state); - assertThat("Constructed with correct comparator state", comparator.getItemType(), equalTo(state ? Material.LEGACY_REDSTONE_COMPARATOR_ON : Material.LEGACY_REDSTONE_COMPARATOR_OFF)); - assertThat("Constructed with correct powered", comparator.isPowered(), equalTo(state)); - assertThat("Constructed with default being powered", comparator.isBeingPowered(), equalTo(false)); - assertThat("Constructed with correct mode", comparator.isSubtractionMode(), equalTo(mode)); - assertThat("Constructed with correct direction", comparator.getFacing(), equalTo(direction)); + assertThat(comparator.getItemType(), equalTo(state ? Material.LEGACY_REDSTONE_COMPARATOR_ON : Material.LEGACY_REDSTONE_COMPARATOR_OFF), "Constructed with correct comparator state"); + assertThat(comparator.isPowered(), equalTo(state), "Constructed with correct powered"); + assertThat(comparator.isBeingPowered(), equalTo(false), "Constructed with default being powered"); + assertThat(comparator.isSubtractionMode(), equalTo(mode), "Constructed with correct mode"); + assertThat(comparator.getFacing(), equalTo(direction), "Constructed with correct direction"); // Check if the game sets the fourth bit, that block data is still interpreted correctly comparator.setData((byte) ((comparator.getData() & 0x7) | 0x8)); - assertThat("Constructed with correct comparator state", comparator.getItemType(), equalTo(state ? Material.LEGACY_REDSTONE_COMPARATOR_ON : Material.LEGACY_REDSTONE_COMPARATOR_OFF)); - assertThat("Constructed with correct powered", comparator.isPowered(), equalTo(state)); - assertThat("Constructed with correct being powered", comparator.isBeingPowered(), equalTo(true)); - assertThat("Constructed with correct mode", comparator.isSubtractionMode(), equalTo(mode)); - assertThat("Constructed with correct direction", comparator.getFacing(), equalTo(direction)); + assertThat(comparator.getItemType(), equalTo(state ? Material.LEGACY_REDSTONE_COMPARATOR_ON : Material.LEGACY_REDSTONE_COMPARATOR_OFF), "Constructed with correct comparator state"); + assertThat(comparator.isPowered(), equalTo(state), "Constructed with correct powered"); + assertThat(comparator.isBeingPowered(), equalTo(true), "Constructed with correct being powered"); + assertThat(comparator.isSubtractionMode(), equalTo(mode), "Constructed with correct mode"); + assertThat(comparator.getFacing(), equalTo(direction), "Constructed with correct direction"); } } } @@ -402,25 +402,25 @@ public class MaterialDataTest { @Test public void testHopper() { Hopper hopper = new Hopper(); - assertThat("Constructed with default hopper type", hopper.getItemType(), equalTo(Material.LEGACY_HOPPER)); - assertThat("Constructed with default active state", hopper.isActive(), equalTo(true)); - assertThat("Constructed with default powered state", hopper.isPowered(), equalTo(false)); - assertThat("Constructed with default direction", hopper.getFacing(), equalTo(BlockFace.DOWN)); + assertThat(hopper.getItemType(), equalTo(Material.LEGACY_HOPPER), "Constructed with default hopper type"); + assertThat(hopper.isActive(), equalTo(true), "Constructed with default active state"); + assertThat(hopper.isPowered(), equalTo(false), "Constructed with default powered state"); + assertThat(hopper.getFacing(), equalTo(BlockFace.DOWN), "Constructed with default direction"); BlockFace[] directions = new BlockFace[]{BlockFace.DOWN, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST, BlockFace.EAST}; boolean[] activeStates = new boolean[]{true, false}; for (BlockFace direction : directions) { hopper = new Hopper(direction); - assertThat("Constructed with default hopper type", hopper.getItemType(), equalTo(Material.LEGACY_HOPPER)); - assertThat("Constructed with default active state", hopper.isActive(), equalTo(true)); - assertThat("Constructed with correct powered state", hopper.isPowered(), equalTo(false)); - assertThat("Constructed with correct direction", hopper.getFacing(), equalTo(direction)); + assertThat(hopper.getItemType(), equalTo(Material.LEGACY_HOPPER), "Constructed with default hopper type"); + assertThat(hopper.isActive(), equalTo(true), "Constructed with default active state"); + assertThat(hopper.isPowered(), equalTo(false), "Constructed with correct powered state"); + assertThat(hopper.getFacing(), equalTo(direction), "Constructed with correct direction"); for (boolean isActive : activeStates) { hopper = new Hopper(direction, isActive); - assertThat("Constructed with default hopper type", hopper.getItemType(), equalTo(Material.LEGACY_HOPPER)); - assertThat("Constructed with correct active state", hopper.isActive(), equalTo(isActive)); - assertThat("Constructed with correct powered state", hopper.isPowered(), equalTo(!isActive)); - assertThat("Constructed with correct direction", hopper.getFacing(), equalTo(direction)); + assertThat(hopper.getItemType(), equalTo(Material.LEGACY_HOPPER), "Constructed with default hopper type"); + assertThat(hopper.isActive(), equalTo(isActive), "Constructed with correct active state"); + assertThat(hopper.isPowered(), equalTo(!isActive), "Constructed with correct powered state"); + assertThat(hopper.getFacing(), equalTo(direction), "Constructed with correct direction"); } } } diff --git a/src/test/java/org/bukkit/metadata/FixedMetadataValueTest.java b/src/test/java/org/bukkit/metadata/FixedMetadataValueTest.java index e8cea99f..91584b94 100644 --- a/src/test/java/org/bukkit/metadata/FixedMetadataValueTest.java +++ b/src/test/java/org/bukkit/metadata/FixedMetadataValueTest.java @@ -1,9 +1,9 @@ package org.bukkit.metadata; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.TestPlugin; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class FixedMetadataValueTest { private Plugin plugin = new TestPlugin("X"); @@ -21,7 +21,7 @@ public class FixedMetadataValueTest { subject = new FixedMetadataValue(plugin, new Integer(5)); assertEquals(new Integer(5), subject.value()); assertEquals(5, subject.asInt()); - assertEquals(true, subject.asBoolean()); + assertTrue(subject.asBoolean()); assertEquals(5, subject.asByte()); assertEquals(5.0, subject.asFloat(), 0.1e-8); assertEquals(5.0D, subject.asDouble(), 0.1e-8D); diff --git a/src/test/java/org/bukkit/metadata/LazyMetadataValueTest.java b/src/test/java/org/bukkit/metadata/LazyMetadataValueTest.java index bc8a18ee..dd2acf3f 100644 --- a/src/test/java/org/bukkit/metadata/LazyMetadataValueTest.java +++ b/src/test/java/org/bukkit/metadata/LazyMetadataValueTest.java @@ -1,9 +1,9 @@ package org.bukkit.metadata; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.concurrent.Callable; import org.bukkit.plugin.TestPlugin; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class LazyMetadataValueTest { private LazyMetadataValue subject; @@ -41,7 +41,7 @@ public class LazyMetadataValueTest { assertEquals(value, subject.value()); } - @Test(expected = MetadataEvaluationException.class) + @Test public void testEvalException() { subject = new LazyMetadataValue(plugin, LazyMetadataValue.CacheStrategy.CACHE_AFTER_FIRST_EVAL, new Callable() { @Override @@ -49,7 +49,7 @@ public class LazyMetadataValueTest { throw new RuntimeException("Gotcha!"); } }); - subject.value(); + assertThrows(MetadataEvaluationException.class, () -> subject.value()); } @Test diff --git a/src/test/java/org/bukkit/metadata/MetadataConversionTest.java b/src/test/java/org/bukkit/metadata/MetadataConversionTest.java index a9c10a2f..29546b62 100644 --- a/src/test/java/org/bukkit/metadata/MetadataConversionTest.java +++ b/src/test/java/org/bukkit/metadata/MetadataConversionTest.java @@ -15,10 +15,10 @@ package org.bukkit.metadata; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.TestPlugin; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** */ @@ -40,7 +40,7 @@ public class MetadataConversionTest { assertEquals(10, subject.asLong()); assertEquals(10, subject.asShort()); assertEquals(10, subject.asByte()); - assertEquals(true, subject.asBoolean()); + assertTrue(subject.asBoolean()); assertEquals("10", subject.asString()); } @@ -54,7 +54,7 @@ public class MetadataConversionTest { assertEquals(10, subject.asLong()); assertEquals(10, subject.asShort()); assertEquals(10, subject.asByte()); - assertEquals(true, subject.asBoolean()); + assertTrue(subject.asBoolean()); assertEquals("10.5", subject.asString()); } @@ -68,7 +68,7 @@ public class MetadataConversionTest { assertEquals(10, subject.asLong()); assertEquals(10, subject.asShort()); assertEquals(10, subject.asByte()); - assertEquals(false, subject.asBoolean()); + assertFalse(subject.asBoolean()); assertEquals("10", subject.asString()); } @@ -82,7 +82,7 @@ public class MetadataConversionTest { assertEquals(0, subject.asLong()); assertEquals(0, subject.asShort()); assertEquals(0, subject.asByte()); - assertEquals(true, subject.asBoolean()); + assertTrue(subject.asBoolean()); assertEquals("true", subject.asString()); } @@ -96,7 +96,7 @@ public class MetadataConversionTest { assertEquals(0, subject.asLong()); assertEquals(0, subject.asShort()); assertEquals(0, subject.asByte()); - assertEquals(false, subject.asBoolean()); + assertFalse(subject.asBoolean()); assertEquals("", subject.asString()); } } diff --git a/src/test/java/org/bukkit/metadata/MetadataStoreTest.java b/src/test/java/org/bukkit/metadata/MetadataStoreTest.java index 12373ff1..e52659f0 100644 --- a/src/test/java/org/bukkit/metadata/MetadataStoreTest.java +++ b/src/test/java/org/bukkit/metadata/MetadataStoreTest.java @@ -1,11 +1,11 @@ package org.bukkit.metadata; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.List; import java.util.concurrent.Callable; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.TestPlugin; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MetadataStoreTest { private Plugin pluginX = new TestPlugin("x"); diff --git a/src/test/java/org/bukkit/metadata/MetadataValueAdapterTest.java b/src/test/java/org/bukkit/metadata/MetadataValueAdapterTest.java index c1e78568..2b6a53b2 100644 --- a/src/test/java/org/bukkit/metadata/MetadataValueAdapterTest.java +++ b/src/test/java/org/bukkit/metadata/MetadataValueAdapterTest.java @@ -1,9 +1,9 @@ package org.bukkit.metadata; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.TestPlugin; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MetadataValueAdapterTest { private TestPlugin plugin = new TestPlugin("x"); @@ -38,25 +38,25 @@ public class MetadataValueAdapterTest { @Test public void testBooleanConversion() { // null is False. - assertEquals(false, simpleValue(null).asBoolean()); + assertFalse(simpleValue(null).asBoolean()); // String to boolean. - assertEquals(true, simpleValue("True").asBoolean()); - assertEquals(true, simpleValue("TRUE").asBoolean()); - assertEquals(false, simpleValue("false").asBoolean()); + assertTrue(simpleValue("True").asBoolean()); + assertTrue(simpleValue("TRUE").asBoolean()); + assertFalse(simpleValue("false").asBoolean()); // Number to boolean. - assertEquals(true, simpleValue(1).asBoolean()); - assertEquals(true, simpleValue(5.0).asBoolean()); - assertEquals(false, simpleValue(0).asBoolean()); - assertEquals(false, simpleValue(0.1).asBoolean()); + assertTrue(simpleValue(1).asBoolean()); + assertTrue(simpleValue(5.0).asBoolean()); + assertFalse(simpleValue(0).asBoolean()); + assertFalse(simpleValue(0.1).asBoolean()); // Boolean as boolean, of course. - assertEquals(true, simpleValue(Boolean.TRUE).asBoolean()); - assertEquals(false, simpleValue(Boolean.FALSE).asBoolean()); + assertTrue(simpleValue(Boolean.TRUE).asBoolean()); + assertFalse(simpleValue(Boolean.FALSE).asBoolean()); // any object that is not null and not a Boolean, String, or Number is true. - assertEquals(true, simpleValue(new Object()).asBoolean()); + assertTrue(simpleValue(new Object()).asBoolean()); } /** Test String conversions return an empty string when given null. */ diff --git a/src/test/java/org/bukkit/plugin/PluginManagerTest.java b/src/test/java/org/bukkit/plugin/PluginManagerTest.java index 4c61b180..03b08e47 100644 --- a/src/test/java/org/bukkit/plugin/PluginManagerTest.java +++ b/src/test/java/org/bukkit/plugin/PluginManagerTest.java @@ -1,14 +1,14 @@ package org.bukkit.plugin; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import org.bukkit.Bukkit; import org.bukkit.event.Event; import org.bukkit.event.TestEvent; import org.bukkit.permissions.Permission; import org.bukkit.support.AbstractTestingBase; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; public class PluginManagerTest extends AbstractTestingBase { private class MutableObject { @@ -164,20 +164,20 @@ public class PluginManagerTest extends AbstractTestingBase { private void testRemovePermissionByName(final String name) { final Permission perm = new Permission(name); pm.addPermission(perm); - assertThat("Permission \"" + name + "\" was not added", pm.getPermission(name), is(perm)); + assertThat(pm.getPermission(name), is(perm), "Permission \"" + name + "\" was not added"); pm.removePermission(name); - assertThat("Permission \"" + name + "\" was not removed", pm.getPermission(name), is(nullValue())); + assertThat(pm.getPermission(name), is(nullValue()), "Permission \"" + name + "\" was not removed"); } private void testRemovePermissionByPermission(final String name) { final Permission perm = new Permission(name); pm.addPermission(perm); - assertThat("Permission \"" + name + "\" was not added", pm.getPermission(name), is(perm)); + assertThat(pm.getPermission(name), is(perm), "Permission \"" + name + "\" was not added"); pm.removePermission(perm); - assertThat("Permission \"" + name + "\" was not removed", pm.getPermission(name), is(nullValue())); + assertThat(pm.getPermission(name), is(nullValue()), "Permission \"" + name + "\" was not removed"); } - @After + @AfterEach public void tearDown() { pm.clearPlugins(); assertThat(pm.getPermissions(), is(empty())); diff --git a/src/test/java/org/bukkit/plugin/TimedRegisteredListenerTest.java b/src/test/java/org/bukkit/plugin/TimedRegisteredListenerTest.java index 351fc4a9..9ed416ed 100644 --- a/src/test/java/org/bukkit/plugin/TimedRegisteredListenerTest.java +++ b/src/test/java/org/bukkit/plugin/TimedRegisteredListenerTest.java @@ -1,7 +1,7 @@ package org.bukkit.plugin; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import org.bukkit.event.Event; import org.bukkit.event.EventException; import org.bukkit.event.EventPriority; @@ -10,7 +10,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerMoveEvent; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TimedRegisteredListenerTest { diff --git a/src/test/java/org/bukkit/plugin/messaging/StandardMessengerTest.java b/src/test/java/org/bukkit/plugin/messaging/StandardMessengerTest.java index eb417041..56641736 100644 --- a/src/test/java/org/bukkit/plugin/messaging/StandardMessengerTest.java +++ b/src/test/java/org/bukkit/plugin/messaging/StandardMessengerTest.java @@ -1,14 +1,14 @@ package org.bukkit.plugin.messaging; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.bukkit.support.MatcherAssert.*; +import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; import java.util.Collection; import org.bukkit.entity.Player; import org.bukkit.plugin.TestPlugin; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class StandardMessengerTest extends AbstractTestingBase { public StandardMessenger getMessenger() { @@ -46,12 +46,12 @@ public class StandardMessengerTest extends AbstractTestingBase { assertFalse(messenger.isOutgoingChannelRegistered(plugin, "test:foo")); } - @Test(expected = ReservedChannelException.class) + @Test public void testReservedOutgoingRegistration() { Messenger messenger = getMessenger(); TestPlugin plugin = getPlugin(); - messenger.registerOutgoingPluginChannel(plugin, "minecraft:register"); + assertThrows(ReservedChannelException.class, () -> messenger.registerOutgoingPluginChannel(plugin, "minecraft:register")); } @Test @@ -92,22 +92,22 @@ public class StandardMessengerTest extends AbstractTestingBase { assertFalse(listener.hasReceived()); } - @Test(expected = ReservedChannelException.class) + @Test public void testReservedIncomingRegistration() { Messenger messenger = getMessenger(); TestPlugin plugin = getPlugin(); - messenger.registerIncomingPluginChannel(plugin, "minecraft:register", new TestMessageListener("test:foo", "test:bar".getBytes())); + assertThrows(ReservedChannelException.class, () -> messenger.registerIncomingPluginChannel(plugin, "minecraft:register", new TestMessageListener("test:foo", "test:bar".getBytes()))); } - @Test(expected = IllegalArgumentException.class) + @Test public void testDuplicateIncomingRegistration() { Messenger messenger = getMessenger(); TestPlugin plugin = getPlugin(); TestMessageListener listener = new TestMessageListener("test:foo", "test:bar".getBytes()); messenger.registerIncomingPluginChannel(plugin, "test:baz", listener); - messenger.registerIncomingPluginChannel(plugin, "test:baz", listener); + assertThrows(IllegalArgumentException.class, () -> messenger.registerIncomingPluginChannel(plugin, "test:baz", listener)); } @Test @@ -174,14 +174,14 @@ public class StandardMessengerTest extends AbstractTestingBase { TestPlugin plugin1 = getPlugin(); TestPlugin plugin2 = getPlugin(); - assertEquals(messenger.getOutgoingChannels()); + assertCollectionEquals(messenger.getOutgoingChannels()); messenger.registerOutgoingPluginChannel(plugin1, "test:foo"); messenger.registerOutgoingPluginChannel(plugin1, "test:bar"); messenger.registerOutgoingPluginChannel(plugin2, "test:baz"); messenger.registerOutgoingPluginChannel(plugin2, "test:baz"); - assertEquals(messenger.getOutgoingChannels(), "test:foo", "test:bar", "test:baz"); + assertCollectionEquals(messenger.getOutgoingChannels(), "test:foo", "test:bar", "test:baz"); } @Test @@ -196,9 +196,9 @@ public class StandardMessengerTest extends AbstractTestingBase { messenger.registerOutgoingPluginChannel(plugin2, "test:baz"); messenger.registerOutgoingPluginChannel(plugin2, "test:qux"); - assertEquals(messenger.getOutgoingChannels(plugin1), "test:foo", "test:bar"); - assertEquals(messenger.getOutgoingChannels(plugin2), "test:baz", "test:qux"); - assertEquals(messenger.getOutgoingChannels(plugin3)); + assertCollectionEquals(messenger.getOutgoingChannels(plugin1), "test:foo", "test:bar"); + assertCollectionEquals(messenger.getOutgoingChannels(plugin2), "test:baz", "test:qux"); + assertCollectionEquals(messenger.getOutgoingChannels(plugin3)); } @Test @@ -207,14 +207,14 @@ public class StandardMessengerTest extends AbstractTestingBase { TestPlugin plugin1 = getPlugin(); TestPlugin plugin2 = getPlugin(); - assertEquals(messenger.getIncomingChannels()); + assertCollectionEquals(messenger.getIncomingChannels()); messenger.registerIncomingPluginChannel(plugin1, "test:foo", new TestMessageListener("test:foo", "test:bar".getBytes())); messenger.registerIncomingPluginChannel(plugin1, "test:bar", new TestMessageListener("test:foo", "test:bar".getBytes())); messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes())); messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes())); - assertEquals(messenger.getIncomingChannels(), "test:foo", "test:bar", "test:baz"); + assertCollectionEquals(messenger.getIncomingChannels(), "test:foo", "test:bar", "test:baz"); } @Test @@ -229,9 +229,9 @@ public class StandardMessengerTest extends AbstractTestingBase { messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes())); messenger.registerIncomingPluginChannel(plugin2, "test:qux", new TestMessageListener("test:foo", "test:bar".getBytes())); - assertEquals(messenger.getIncomingChannels(plugin1), "test:foo", "test:bar"); - assertEquals(messenger.getIncomingChannels(plugin2), "test:baz", "test:qux"); - assertEquals(messenger.getIncomingChannels(plugin3)); + assertCollectionEquals(messenger.getIncomingChannels(plugin1), "test:foo", "test:bar"); + assertCollectionEquals(messenger.getIncomingChannels(plugin2), "test:baz", "test:qux"); + assertCollectionEquals(messenger.getIncomingChannels(plugin3)); } @Test @@ -245,9 +245,9 @@ public class StandardMessengerTest extends AbstractTestingBase { PluginMessageListenerRegistration registration3 = messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes())); PluginMessageListenerRegistration registration4 = messenger.registerIncomingPluginChannel(plugin2, "test:qux", new TestMessageListener("test:foo", "test:bar".getBytes())); - assertEquals(messenger.getIncomingChannelRegistrations(plugin1), registration1, registration2); - assertEquals(messenger.getIncomingChannelRegistrations(plugin2), registration3, registration4); - assertEquals(messenger.getIncomingChannels(plugin3)); + assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin1), registration1, registration2); + assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin2), registration3, registration4); + assertCollectionEquals(messenger.getIncomingChannels(plugin3)); } @Test @@ -260,9 +260,9 @@ public class StandardMessengerTest extends AbstractTestingBase { PluginMessageListenerRegistration registration3 = messenger.registerIncomingPluginChannel(plugin2, "test:foo", new TestMessageListener("test:foo", "test:bar".getBytes())); PluginMessageListenerRegistration registration4 = messenger.registerIncomingPluginChannel(plugin2, "test:bar", new TestMessageListener("test:foo", "test:bar".getBytes())); - assertEquals(messenger.getIncomingChannelRegistrations("test:foo"), registration1, registration3); - assertEquals(messenger.getIncomingChannelRegistrations("test:bar"), registration2, registration4); - assertEquals(messenger.getIncomingChannelRegistrations("test:baz")); + assertCollectionEquals(messenger.getIncomingChannelRegistrations("test:foo"), registration1, registration3); + assertCollectionEquals(messenger.getIncomingChannelRegistrations("test:bar"), registration2, registration4); + assertCollectionEquals(messenger.getIncomingChannelRegistrations("test:baz")); } @Test @@ -278,30 +278,30 @@ public class StandardMessengerTest extends AbstractTestingBase { PluginMessageListenerRegistration registration5 = messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes())); PluginMessageListenerRegistration registration6 = messenger.registerIncomingPluginChannel(plugin2, "test:baz", new TestMessageListener("test:foo", "test:bar".getBytes())); - assertEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:foo"), registration1, registration2); - assertEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:bar"), registration3); - assertEquals(messenger.getIncomingChannelRegistrations(plugin2, "test:bar"), registration4); - assertEquals(messenger.getIncomingChannelRegistrations(plugin2, "test:baz"), registration5, registration6); - assertEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:baz")); - assertEquals(messenger.getIncomingChannelRegistrations(plugin3, "test:qux")); + assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:foo"), registration1, registration2); + assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:bar"), registration3); + assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin2, "test:bar"), registration4); + assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin2, "test:baz"), registration5, registration6); + assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin1, "test:baz")); + assertCollectionEquals(messenger.getIncomingChannelRegistrations(plugin3, "test:qux")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidChannel() { Messenger messenger = getMessenger(); TestPlugin plugin = getPlugin(); - messenger.registerOutgoingPluginChannel(plugin, "foo"); + assertThrows(IllegalArgumentException.class, () -> messenger.registerOutgoingPluginChannel(plugin, "foo")); } @Test public void testValidateAndCorrectChannel() { - Assert.assertEquals("bungeecord:main", StandardMessenger.validateAndCorrectChannel("BungeeCord")); - Assert.assertEquals("BungeeCord", StandardMessenger.validateAndCorrectChannel("bungeecord:main")); + assertEquals("bungeecord:main", StandardMessenger.validateAndCorrectChannel("BungeeCord")); + assertEquals("BungeeCord", StandardMessenger.validateAndCorrectChannel("bungeecord:main")); } - private static void assertEquals(Collection actual, T... expected) { - assertThat("Size of the array", actual.size(), is(expected.length)); + private static void assertCollectionEquals(Collection actual, T... expected) { + assertThat(actual.size(), is(expected.length), "Size of the array"); assertThat(actual, hasItems(expected)); } } diff --git a/src/test/java/org/bukkit/plugin/messaging/TestMessageListener.java b/src/test/java/org/bukkit/plugin/messaging/TestMessageListener.java index 7a5b6108..20981f60 100644 --- a/src/test/java/org/bukkit/plugin/messaging/TestMessageListener.java +++ b/src/test/java/org/bukkit/plugin/messaging/TestMessageListener.java @@ -1,6 +1,6 @@ package org.bukkit.plugin.messaging; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.entity.Player; public class TestMessageListener implements PluginMessageListener { diff --git a/src/test/java/org/bukkit/scoreboard/CriteriaTest.java b/src/test/java/org/bukkit/scoreboard/CriteriaTest.java index 87958640..961def90 100644 --- a/src/test/java/org/bukkit/scoreboard/CriteriaTest.java +++ b/src/test/java/org/bukkit/scoreboard/CriteriaTest.java @@ -1,23 +1,23 @@ package org.bukkit.scoreboard; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.Statistic; import org.bukkit.block.BlockType; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemType; import org.bukkit.support.AbstractTestingBase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CriteriaTest extends AbstractTestingBase { @Test public void testStatistic() { - Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, BlockType.STONE)); // Generic statistic with block - Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, EntityType.CREEPER)); // Generic statistic with entity type + assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, BlockType.STONE)); // Generic statistic with block + assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, EntityType.CREEPER)); // Generic statistic with entity type - Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.ENTITY_KILLED_BY, ItemType.AMETHYST_SHARD)); // Entity statistic with item type - Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.MINE_BLOCK, ItemType.DIAMOND_PICKAXE)); // Block statistic with item - Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.BREAK_ITEM, BlockType.WATER)); // Item statistic with block - Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.KILL_ENTITY, BlockType.STONE)); // Entity statistic with block type + assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.ENTITY_KILLED_BY, ItemType.AMETHYST_SHARD)); // Entity statistic with item type + assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.MINE_BLOCK, ItemType.DIAMOND_PICKAXE)); // Block statistic with item + assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.BREAK_ITEM, BlockType.WATER)); // Item statistic with block + assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.KILL_ENTITY, BlockType.STONE)); // Entity statistic with block type } } diff --git a/src/test/java/org/bukkit/support/MatcherAssert.java b/src/test/java/org/bukkit/support/MatcherAssert.java new file mode 100644 index 00000000..b100262e --- /dev/null +++ b/src/test/java/org/bukkit/support/MatcherAssert.java @@ -0,0 +1,36 @@ +package org.bukkit.support; + +import org.hamcrest.Matcher; + +/** + * Custom assertThat methods, where the reason is put at the end of the method call. + * To better match with JUnit 5 argument order and also help with readability for longer reasons. + *
    + *
    + * assertThat(String.format("""
    + *         The block data created for the material %s is not an instance of the data class from that material.
    + *         """, material), blockData, is(instanceOf(expectedClass)));
    + * 
    + * vs. + *
    + * assertThat(blockData, is(instanceOf(expectedClass)), String.format("""
    + *         The block data created for the material %s is not an instance of the data class from that material.
    + *         """, material));
    + * 
    + */ +public final class MatcherAssert { + + private MatcherAssert() {} + + public static void assertThat(T actual, Matcher matcher) { + org.hamcrest.MatcherAssert.assertThat(actual, matcher); + } + + public static void assertThat(T actual, Matcher matcher, String reason) { + org.hamcrest.MatcherAssert.assertThat(reason, actual, matcher); + } + + public static void assertThat(boolean assertion, String reason) { + org.hamcrest.MatcherAssert.assertThat(reason, assertion); + } +} diff --git a/src/test/java/org/bukkit/util/BoundingBoxTest.java b/src/test/java/org/bukkit/util/BoundingBoxTest.java index 2d50a9ed..3141c007 100644 --- a/src/test/java/org/bukkit/util/BoundingBoxTest.java +++ b/src/test/java/org/bukkit/util/BoundingBoxTest.java @@ -1,11 +1,11 @@ package org.bukkit.util; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import java.util.Map; import org.bukkit.Location; import org.bukkit.block.BlockFace; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BoundingBoxTest { diff --git a/src/test/java/org/bukkit/util/StringUtilStartsWithTest.java b/src/test/java/org/bukkit/util/StringUtilStartsWithTest.java index 229c67c7..c93bd4d6 100644 --- a/src/test/java/org/bukkit/util/StringUtilStartsWithTest.java +++ b/src/test/java/org/bukkit/util/StringUtilStartsWithTest.java @@ -1,83 +1,72 @@ package org.bukkit.util; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import com.google.common.collect.ImmutableList; -import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class StringUtilStartsWithTest { - @Parameters(name = "{index}: {0} startsWith {1} == {2}") - public static List data() { - return ImmutableList.of( - new Object[] { - "Apple", - "Apples", - false - }, - new Object[] { - "Apples", - "Apple", - true - }, - new Object[] { - "Apple", - "Apple", - true - }, - new Object[] { - "Apple", - "apples", - false - }, - new Object[] { - "apple", - "Apples", - false - }, - new Object[] { - "apple", - "apples", - false - }, - new Object[] { - "Apples", - "apPL", - true - }, - new Object[] { - "123456789", - "1234567", - true - }, - new Object[] { - "", - "", - true - }, - new Object[] { - "string", - "", - true - } + public static Stream data() { + return Stream.of( + Arguments.of( + "Apple", + "Apples", + false + ), + Arguments.of( + "Apples", + "Apple", + true + ), + Arguments.of( + "Apple", + "Apple", + true + ), + Arguments.of( + "Apple", + "apples", + false + ), + Arguments.of( + "apple", + "Apples", + false + ), + Arguments.of( + "apple", + "apples", + false + ), + Arguments.of( + "Apples", + "apPL", + true + ), + Arguments.of( + "123456789", + "1234567", + true + ), + Arguments.of( + "", + "", + true + ), + Arguments.of( + "string", + "", + true + ) ); } - @Parameter(0) - public String base; - @Parameter(1) - public String prefix; - @Parameter(2) - public boolean result; - - @Test - public void testFor() { - assertThat(base + " starts with " + prefix + ": " + result, StringUtil.startsWithIgnoreCase(base, prefix), is(result)); + @ParameterizedTest + @MethodSource("data") + public void testFor(String base, String prefix, boolean result) { + assertThat(StringUtil.startsWithIgnoreCase(base, prefix), is(result), base + " starts with " + prefix + ": " + result); } } diff --git a/src/test/java/org/bukkit/util/StringUtilTest.java b/src/test/java/org/bukkit/util/StringUtilTest.java index 6476dd2d..87e91461 100644 --- a/src/test/java/org/bukkit/util/StringUtilTest.java +++ b/src/test/java/org/bukkit/util/StringUtilTest.java @@ -1,38 +1,39 @@ package org.bukkit.util; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class StringUtilTest { - @Test(expected = NullPointerException.class) + @Test public void nullPrefixTest() { - StringUtil.startsWithIgnoreCase("String", null); + assertThrows(NullPointerException.class, () -> StringUtil.startsWithIgnoreCase("String", null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void nullStringTest() { - StringUtil.startsWithIgnoreCase(null, "String"); + assertThrows(IllegalArgumentException.class, () -> StringUtil.startsWithIgnoreCase(null, "String")); } - @Test(expected = IllegalArgumentException.class) + @Test public void nullCollectionTest() { - StringUtil.copyPartialMatches("Token", ImmutableList.of(), null); + assertThrows(IllegalArgumentException.class, () -> StringUtil.copyPartialMatches("Token", ImmutableList.of(), null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void nullIterableTest() { - StringUtil.copyPartialMatches("Token", null, new ArrayList()); + assertThrows(IllegalArgumentException.class, () -> StringUtil.copyPartialMatches("Token", null, new ArrayList())); } - @Test(expected = IllegalArgumentException.class) + @Test public void nullTokenTest() { - StringUtil.copyPartialMatches(null, ImmutableList.of(), new ArrayList()); + assertThrows(IllegalArgumentException.class, () -> StringUtil.copyPartialMatches(null, ImmutableList.of(), new ArrayList())); } @Test @@ -46,13 +47,13 @@ public class StringUtilTest { assertThat(list.size(), is(expected.size() * 2)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void copyUnsupportedTest() { - StringUtil.copyPartialMatches("token", ImmutableList.of("token1", "token2"), ImmutableList.of()); + assertThrows(UnsupportedOperationException.class, () -> StringUtil.copyPartialMatches("token", ImmutableList.of("token1", "token2"), ImmutableList.of())); } - @Test(expected = IllegalArgumentException.class) + @Test public void copyNullTest() { - StringUtil.copyPartialMatches("token", Arrays.asList("token1", "token2", null), new ArrayList()); + assertThrows(IllegalArgumentException.class, () -> StringUtil.copyPartialMatches("token", Arrays.asList("token1", "token2", null), new ArrayList())); } } diff --git a/src/test/java/org/bukkit/util/VectorTest.java b/src/test/java/org/bukkit/util/VectorTest.java index 03442bff..f0927a0d 100644 --- a/src/test/java/org/bukkit/util/VectorTest.java +++ b/src/test/java/org/bukkit/util/VectorTest.java @@ -1,8 +1,8 @@ package org.bukkit.util; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.bukkit.block.BlockFace; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class VectorTest { @@ -14,9 +14,9 @@ public class VectorTest { assertTrue(new Vector(1, 0, 0).isNormalized()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNullVectorAxis() { - new Vector(0, 1, 0).rotateAroundAxis(null, Math.PI); + assertThrows(IllegalArgumentException.class, () -> new Vector(0, 1, 0).rotateAroundAxis(null, Math.PI)); } @Test diff --git a/src/test/java/org/bukkit/util/io/BukkitObjectStreamTest.java b/src/test/java/org/bukkit/util/io/BukkitObjectStreamTest.java index d3edb72f..7021a44e 100644 --- a/src/test/java/org/bukkit/util/io/BukkitObjectStreamTest.java +++ b/src/test/java/org/bukkit/util/io/BukkitObjectStreamTest.java @@ -1,7 +1,7 @@ package org.bukkit.util.io; +import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import com.google.common.collect.ImmutableList; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -9,80 +9,69 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.List; +import java.util.stream.Stream; import org.bukkit.Color; import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect.Type; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.util.Vector; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; -@RunWith(Parameterized.class) public class BukkitObjectStreamTest { - @Parameters(name = "{index}: {0}") - public static List data() { - return ImmutableList.of( - new Object[] { - Color.class.getName(), - "rO0ABXNyADZjb20uZ29vZ2xlLmNvbW1vbi5jb2xsZWN0LkltbXV0YWJsZUxpc3QkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAVsACGVsZW1lbnRzdAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABXNyABpvcmcuYnVra2l0LnV0aWwuaW8uV3JhcHBlcvJQR+zxEm8FAgABTAADbWFwdAAPTGphdmEvdXRpbC9NYXA7eHBzcgA1Y29tLmdvb2dsZS5jb21tb24uY29sbGVjdC5JbW11dGFibGVNYXAkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABGtleXNxAH4AAVsABnZhbHVlc3EAfgABeHB1cQB+AAMAAAAEdAACPT10AANSRUR0AARCTFVFdAAFR1JFRU51cQB+AAMAAAAEdAAFQ29sb3JzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAA/3NxAH4AEQAAAP9zcQB+ABEAAAD/c3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARAAAAAHNxAH4AEQAAAIBzcQB+ABEAAACAc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARAAAAgHNxAH4AEQAAAIBxAH4AGnNxAH4ABXNxAH4ACHVxAH4AAwAAAARxAH4AC3EAfgAMcQB+AA1xAH4ADnVxAH4AAwAAAARxAH4AEHNxAH4AEQAAAP9xAH4AGnEAfgAac3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARAAAA/3EAfgAac3EAfgARAAAApQ==", - ImmutableList.of( - Color.WHITE, - Color.TEAL, - Color.PURPLE, - Color.RED, - Color.ORANGE - ) - }, - new Object[] { - FireworkEffect.class.getName(), - "rO0ABXNyADZjb20uZ29vZ2xlLmNvbW1vbi5jb2xsZWN0LkltbXV0YWJsZUxpc3QkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAVsACGVsZW1lbnRzdAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAAA3NyABpvcmcuYnVra2l0LnV0aWwuaW8uV3JhcHBlcvJQR+zxEm8FAgABTAADbWFwdAAPTGphdmEvdXRpbC9NYXA7eHBzcgA1Y29tLmdvb2dsZS5jb21tb24uY29sbGVjdC5JbW11dGFibGVNYXAkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABGtleXNxAH4AAVsABnZhbHVlc3EAfgABeHB1cQB+AAMAAAAGdAACPT10AAdmbGlja2VydAAFdHJhaWx0AAZjb2xvcnN0AAtmYWRlLWNvbG9yc3QABHR5cGV1cQB+AAMAAAAGdAAIRmlyZXdvcmtzcgARamF2YS5sYW5nLkJvb2xlYW7NIHKA1Zz67gIAAVoABXZhbHVleHABc3EAfgATAHNxAH4AAHVxAH4AAwAAAAJzcQB+AAVzcQB+AAh1cQB+AAMAAAAEcQB+AAt0AANSRUR0AARCTFVFdAAFR1JFRU51cQB+AAMAAAAEdAAFQ29sb3JzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAHEAfgAicQB+ACJzcQB+AAVzcQB+AAh1cQB+AAMAAAAEcQB+AAtxAH4AG3EAfgAccQB+AB11cQB+AAMAAAAEcQB+AB9zcQB+ACAAAADAc3EAfgAgAAAAwHNxAH4AIAAAAMBzcQB+AAB1cQB+AAMAAAABc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+ABtxAH4AHHEAfgAddXEAfgADAAAABHEAfgAfc3EAfgAgAAAA/3NxAH4AIAAAAP9zcQB+ACAAAAD/dAAKQkFMTF9MQVJHRXNxAH4ABXNxAH4ACHVxAH4AAwAAAAZxAH4AC3EAfgAMcQB+AA1xAH4ADnEAfgAPcQB+ABB1cQB+AAMAAAAGcQB+ABJxAH4AFXEAfgAVc3EAfgAAdXEAfgADAAAAAXNxAH4ABXNxAH4ACHVxAH4AAwAAAARxAH4AC3EAfgAbcQB+ABxxAH4AHXVxAH4AAwAAAARxAH4AH3EAfgAic3EAfgAgAAAAgHEAfgAic3EAfgAAdXEAfgADAAAAAHQABEJBTExzcQB+AAVzcQB+AAh1cQB+AAMAAAAGcQB+AAtxAH4ADHEAfgANcQB+AA5xAH4AD3EAfgAQdXEAfgADAAAABnEAfgAScQB+ABRxAH4AFHNxAH4AAHVxAH4AAwAAAAFzcQB+AAVzcQB+AAh1cQB+AAMAAAAEcQB+AAtxAH4AG3EAfgAccQB+AB11cQB+AAMAAAAEcQB+AB9zcQB+ACAAAACAcQB+ACJxAH4AInEAfgA/dAAHQ1JFRVBFUg==", - ImmutableList.of( - FireworkEffect.builder() - .withColor(Color.BLACK, Color.SILVER) - .with(Type.BALL_LARGE) - .withFade(Color.WHITE) - .withFlicker() - .build(), - FireworkEffect.builder() - .withColor(Color.NAVY) - .build(), - FireworkEffect.builder() - .withColor(Color.MAROON) - .withTrail() - .withFlicker() - .with(Type.CREEPER) - .build() - ), - }, - new Object[] { - Vector.class.getName(), - "rO0ABXNyADZjb20uZ29vZ2xlLmNvbW1vbi5jb2xsZWN0LkltbXV0YWJsZUxpc3QkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAVsACGVsZW1lbnRzdAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABHNyABpvcmcuYnVra2l0LnV0aWwuaW8uV3JhcHBlcvJQR+zxEm8FAgABTAADbWFwdAAPTGphdmEvdXRpbC9NYXA7eHBzcgA1Y29tLmdvb2dsZS5jb21tb24uY29sbGVjdC5JbW11dGFibGVNYXAkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABGtleXNxAH4AAVsABnZhbHVlc3EAfgABeHB1cQB+AAMAAAAEdAACPT10AAF4dAABeXQAAXp1cQB+AAMAAAAEdAAGVmVjdG9yc3IAEGphdmEubGFuZy5Eb3VibGWAs8JKKWv7BAIAAUQABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAAAAAABzcQB+ABEAAAAAAAAAAHNxAH4AEQAAAAAAAAAAc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARQIOFwo9cKPZzcQB+ABFAtCKcKPXCj3NxAH4AEUBzrpeNT987c3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARwEQTMzMzMzNzcQB+ABFASYAAAAAAAHNxAH4AEcCjqG3UQTVUc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARQd/////AAABzcQB+ABHB4AAAAAAAAHNxAH4AEQAAAAAAAAAA", - ImmutableList.of( - new Vector(0, 0, 0), - new Vector(624.72, 5154.61, 314.912), - new Vector(-40.15, 51, -2516.21451), - new Vector(Integer.MAX_VALUE, Integer.MIN_VALUE, 0) - ) - }); + public static Stream data() { + return Stream.of( + Arguments.of( + Color.class.getName(), + "rO0ABXNyADZjb20uZ29vZ2xlLmNvbW1vbi5jb2xsZWN0LkltbXV0YWJsZUxpc3QkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAVsACGVsZW1lbnRzdAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABXNyABpvcmcuYnVra2l0LnV0aWwuaW8uV3JhcHBlcvJQR+zxEm8FAgABTAADbWFwdAAPTGphdmEvdXRpbC9NYXA7eHBzcgA1Y29tLmdvb2dsZS5jb21tb24uY29sbGVjdC5JbW11dGFibGVNYXAkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABGtleXNxAH4AAVsABnZhbHVlc3EAfgABeHB1cQB+AAMAAAAEdAACPT10AANSRUR0AARCTFVFdAAFR1JFRU51cQB+AAMAAAAEdAAFQ29sb3JzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAA/3NxAH4AEQAAAP9zcQB+ABEAAAD/c3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARAAAAAHNxAH4AEQAAAIBzcQB+ABEAAACAc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARAAAAgHNxAH4AEQAAAIBxAH4AGnNxAH4ABXNxAH4ACHVxAH4AAwAAAARxAH4AC3EAfgAMcQB+AA1xAH4ADnVxAH4AAwAAAARxAH4AEHNxAH4AEQAAAP9xAH4AGnEAfgAac3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARAAAA/3EAfgAac3EAfgARAAAApQ==", + ImmutableList.of( + Color.WHITE, + Color.TEAL, + Color.PURPLE, + Color.RED, + Color.ORANGE + ) + ), + Arguments.of( + FireworkEffect.class.getName(), + "rO0ABXNyADZjb20uZ29vZ2xlLmNvbW1vbi5jb2xsZWN0LkltbXV0YWJsZUxpc3QkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAVsACGVsZW1lbnRzdAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAAA3NyABpvcmcuYnVra2l0LnV0aWwuaW8uV3JhcHBlcvJQR+zxEm8FAgABTAADbWFwdAAPTGphdmEvdXRpbC9NYXA7eHBzcgA1Y29tLmdvb2dsZS5jb21tb24uY29sbGVjdC5JbW11dGFibGVNYXAkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABGtleXNxAH4AAVsABnZhbHVlc3EAfgABeHB1cQB+AAMAAAAGdAACPT10AAdmbGlja2VydAAFdHJhaWx0AAZjb2xvcnN0AAtmYWRlLWNvbG9yc3QABHR5cGV1cQB+AAMAAAAGdAAIRmlyZXdvcmtzcgARamF2YS5sYW5nLkJvb2xlYW7NIHKA1Zz67gIAAVoABXZhbHVleHABc3EAfgATAHNxAH4AAHVxAH4AAwAAAAJzcQB+AAVzcQB+AAh1cQB+AAMAAAAEcQB+AAt0AANSRUR0AARCTFVFdAAFR1JFRU51cQB+AAMAAAAEdAAFQ29sb3JzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAHEAfgAicQB+ACJzcQB+AAVzcQB+AAh1cQB+AAMAAAAEcQB+AAtxAH4AG3EAfgAccQB+AB11cQB+AAMAAAAEcQB+AB9zcQB+ACAAAADAc3EAfgAgAAAAwHNxAH4AIAAAAMBzcQB+AAB1cQB+AAMAAAABc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+ABtxAH4AHHEAfgAddXEAfgADAAAABHEAfgAfc3EAfgAgAAAA/3NxAH4AIAAAAP9zcQB+ACAAAAD/dAAKQkFMTF9MQVJHRXNxAH4ABXNxAH4ACHVxAH4AAwAAAAZxAH4AC3EAfgAMcQB+AA1xAH4ADnEAfgAPcQB+ABB1cQB+AAMAAAAGcQB+ABJxAH4AFXEAfgAVc3EAfgAAdXEAfgADAAAAAXNxAH4ABXNxAH4ACHVxAH4AAwAAAARxAH4AC3EAfgAbcQB+ABxxAH4AHXVxAH4AAwAAAARxAH4AH3EAfgAic3EAfgAgAAAAgHEAfgAic3EAfgAAdXEAfgADAAAAAHQABEJBTExzcQB+AAVzcQB+AAh1cQB+AAMAAAAGcQB+AAtxAH4ADHEAfgANcQB+AA5xAH4AD3EAfgAQdXEAfgADAAAABnEAfgAScQB+ABRxAH4AFHNxAH4AAHVxAH4AAwAAAAFzcQB+AAVzcQB+AAh1cQB+AAMAAAAEcQB+AAtxAH4AG3EAfgAccQB+AB11cQB+AAMAAAAEcQB+AB9zcQB+ACAAAACAcQB+ACJxAH4AInEAfgA/dAAHQ1JFRVBFUg==", + ImmutableList.of( + FireworkEffect.builder() + .withColor(Color.BLACK, Color.SILVER) + .with(Type.BALL_LARGE) + .withFade(Color.WHITE) + .withFlicker() + .build(), + FireworkEffect.builder() + .withColor(Color.NAVY) + .build(), + FireworkEffect.builder() + .withColor(Color.MAROON) + .withTrail() + .withFlicker() + .with(Type.CREEPER) + .build() + ) + ), + Arguments.of( + Vector.class.getName(), + "rO0ABXNyADZjb20uZ29vZ2xlLmNvbW1vbi5jb2xsZWN0LkltbXV0YWJsZUxpc3QkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAVsACGVsZW1lbnRzdAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABHNyABpvcmcuYnVra2l0LnV0aWwuaW8uV3JhcHBlcvJQR+zxEm8FAgABTAADbWFwdAAPTGphdmEvdXRpbC9NYXA7eHBzcgA1Y29tLmdvb2dsZS5jb21tb24uY29sbGVjdC5JbW11dGFibGVNYXAkU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABGtleXNxAH4AAVsABnZhbHVlc3EAfgABeHB1cQB+AAMAAAAEdAACPT10AAF4dAABeXQAAXp1cQB+AAMAAAAEdAAGVmVjdG9yc3IAEGphdmEubGFuZy5Eb3VibGWAs8JKKWv7BAIAAUQABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAAAAAABzcQB+ABEAAAAAAAAAAHNxAH4AEQAAAAAAAAAAc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARQIOFwo9cKPZzcQB+ABFAtCKcKPXCj3NxAH4AEUBzrpeNT987c3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARwEQTMzMzMzNzcQB+ABFASYAAAAAAAHNxAH4AEcCjqG3UQTVUc3EAfgAFc3EAfgAIdXEAfgADAAAABHEAfgALcQB+AAxxAH4ADXEAfgAOdXEAfgADAAAABHEAfgAQc3EAfgARQd/////AAABzcQB+ABHB4AAAAAAAAHNxAH4AEQAAAAAAAAAA", + ImmutableList.of( + new Vector(0, 0, 0), + new Vector(624.72, 5154.61, 314.912), + new Vector(-40.15, 51, -2516.21451), + new Vector(Integer.MAX_VALUE, Integer.MIN_VALUE, 0) + ) + )); } - @Parameter(0) - public String className; - - @Parameter(1) - public String preEncoded; - - @Parameter(2) - public List object; - - @Test - public void checkSerlialization() throws Throwable { + @ParameterizedTest + @MethodSource("data") + public void checkSerlialization(String className, String preEncoded, List object) throws Throwable { // If this test fails, you may start your trek to debug by commenting the '@Ignore' on the next method // (and of course, you would read those comments too) final ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -102,7 +91,7 @@ public class BukkitObjectStreamTest { final byte[] preEncodedArray = Base64Coder.decode(preEncoded); final Object readBack; - final Object preEncoded; + final Object encoded; ObjectInputStream ois = null; ObjectInputStream preois = null; @@ -113,7 +102,7 @@ public class BukkitObjectStreamTest { preois = new BukkitObjectInputStream(preIn); readBack = ois.readObject(); - preEncoded = preois.readObject(); + encoded = preois.readObject(); } finally { if (ois != null) { try { @@ -130,12 +119,13 @@ public class BukkitObjectStreamTest { } assertThat(object, is(readBack)); - assertThat(object, is(preEncoded)); + assertThat(object, is(encoded)); } - @Ignore - @Test - public void preEncoded() throws Throwable { + @Disabled + @ParameterizedTest + @MethodSource("data") + public void preEncoded(String className, String preEncoded, List object) throws Throwable { // This test is placed in the case that a necessary change is made to change the encoding format // Just remove the ignore (or run manually) and it'll give you the new pre-encoded values