Merge branch 'master' into enums-to-registers

# Conflicts:
#	src/main/java/org/bukkit/attribute/Attribute.java
#	src/test/java/org/bukkit/ArtTest.java
#	src/test/java/org/bukkit/event/PlayerChatTabCompleteEventTest.java
#	src/test/java/org/bukkit/plugin/messaging/StandardMessengerTest.java
#	src/test/java/org/bukkit/scoreboard/CriteriaTest.java
This commit is contained in:
DerFrZocker 2023-10-07 14:32:02 +02:00
commit 6c6da4673a
No known key found for this signature in database
GPG key ID: 713F71FFFE1DDF91
72 changed files with 1342 additions and 894 deletions

View file

@ -83,12 +83,12 @@ Code Requirements
* Do not attempt to fix multiple problems with a single patch or pull request. * Do not attempt to fix multiple problems with a single patch or pull request.
* Avoid moving or renaming classes. * Avoid moving or renaming classes.
* All non-private methods and constructors must have specified nullability through [annotations](https://github.com/JetBrains/java-annotations) * 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): * 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.Experimental`](https://javadoc.io/doc/org.jetbrains/annotations-java5/23.0.0/org/jetbrains/annotations/ApiStatus.Experimental.html) for API that is subject to change
* [`@ApiStatus.Internal`](https://javadoc.io/doc/org.jetbrains/annotations-java5/23.0.0/org/jetbrains/annotations/ApiStatus.Internal.html) for API that is intended only for internal use in the Bukkit project and will not adhere to Bukkit's API contract * [`@ApiStatus.Internal`](https://javadoc.io/doc/org.jetbrains/annotations-java5/23.0.0/org/jetbrains/annotations/ApiStatus.Internal.html) for API that is intended only for internal use in the Bukkit project and will not adhere to Bukkit's API contract
Bukkit/CraftBukkit employs [JUnit 4](https://www.vogella.com/tutorials/JUnit4/article.html) for testing. Pull Requests(PR) should attempt to integrate within that framework as appropriate. Bukkit/CraftBukkit employs [JUnit 5](https://www.vogella.com/tutorials/JUnit/article.html) for testing. Pull Requests(PR) should attempt to integrate within that framework as appropriate.
Bukkit is a large project and what seems simple to a PR author at the time of writing may easily be overlooked by other authors and updates. Including unit tests with your PR Bukkit is a large project and what seems simple to a PR author at the time of writing may easily be overlooked by other authors and updates. Including unit tests with your PR
will help to ensure the PR can be easily maintained over time and encourage the Spigot team to pull the PR. will help to ensure the PR can be easily maintained over time and encourage the Spigot team to pull the PR.

17
pom.xml
View file

@ -86,15 +86,15 @@
</dependency> </dependency>
<!-- testing --> <!-- testing -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit</artifactId> <artifactId>junit-jupiter</artifactId>
<version>4.13.2</version> <version>5.10.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.hamcrest</groupId> <groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId> <artifactId>hamcrest</artifactId>
<version>1.3</version> <version>2.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -193,8 +193,6 @@
<configuration> <configuration>
<links> <links>
<link>https://guava.dev/releases/31.1-jre/api/docs/</link> <link>https://guava.dev/releases/31.1-jre/api/docs/</link>
<link>https://javadoc.io/doc/org.yaml/snakeyaml/2.0/</link>
<link>https://javadoc.io/doc/org.jetbrains/annotations-java5/24.0.1/</link>
</links> </links>
<tags> <tags>
<tag> <tag>
@ -205,6 +203,11 @@
</tags> </tags>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins> </plugins>
</build> </build>

View file

@ -4,6 +4,9 @@ import org.jetbrains.annotations.ApiStatus;
/** /**
* This represents a Feature Flag for a World. * This represents a Feature Flag for a World.
* <br>
* Flags which are unavailable in the current version will be null and/or
* removed.
*/ */
@ApiStatus.Experimental @ApiStatus.Experimental
public interface FeatureFlag extends Keyed { public interface FeatureFlag extends Keyed {
@ -15,7 +18,13 @@ public interface FeatureFlag extends Keyed {
/** /**
* <strong>AVAILABLE BETWEEN VERSIONS:</strong> 1.19 - 1.19.4 * <strong>AVAILABLE BETWEEN VERSIONS:</strong> 1.19 - 1.19.4
*
* @deprecated not available since 1.20
*/ */
@Deprecated
@MinecraftExperimental @MinecraftExperimental
public static final FeatureFlag UPDATE_1_20 = Bukkit.getUnsafe().getFeatureFlag(NamespacedKey.minecraft("update_1_20")); 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"));
} }

View file

@ -10,7 +10,7 @@ import org.jetbrains.annotations.Nullable;
* GameRules dictate certain behavior within Minecraft itself * GameRules dictate certain behavior within Minecraft itself
* <br> * <br>
* For more information please visit the * For more information please visit the
* <a href="https://minecraft.gamepedia.com/Commands/gamerule">Minecraft * <a href="https://minecraft.wiki/w/Commands/gamerule">Minecraft
* Wiki</a> * Wiki</a>
* *
* @param <T> type of rule (Boolean or Integer) * @param <T> type of rule (Boolean or Integer)

View file

@ -3,8 +3,7 @@ package org.bukkit;
/** /**
* Further information regarding heightmaps. * Further information regarding heightmaps.
* *
* @see <a href="https://minecraft.gamepedia.com/Chunk_format">Gamepedia Chunk * @see <a href="https://minecraft.wiki/w/Chunk_format">Minecraft Wiki</a>
* Format</a>
*/ */
public enum HeightMap { public enum HeightMap {

View file

@ -7923,7 +7923,7 @@ public enum Material implements Keyed, Translatable {
* <li>Only occluding blocks can be "powered" ({@link Block#isBlockPowered()}). * <li>Only occluding blocks can be "powered" ({@link Block#isBlockPowered()}).
* </ul> * </ul>
* This list may be inconclusive. For a full list of the side effects of an occluding * This list may be inconclusive. For a full list of the side effects of an occluding
* block, see the <a href="https://minecraft.fandom.com/wiki/Opacity">Minecraft Wiki</a>. * block, see the <a href="https://minecraft.wiki/w/Opacity">Minecraft Wiki</a>.
* *
* @return True if this material is a block and occludes light * @return True if this material is a block and occludes light
*/ */

View file

@ -9,7 +9,7 @@ import org.jetbrains.annotations.ApiStatus;
/** /**
* Indicates that the annotated element (class, method, field, etc.) is part of a * Indicates that the annotated element (class, method, field, etc.) is part of a
* <a href="https://minecraft.fandom.com/wiki/Experimental_Gameplay">minecraft experimental feature</a> * <a href="https://minecraft.wiki/w/Experimental_Gameplay">minecraft experimental feature</a>
* and is subject to changes by Mojang. * and is subject to changes by Mojang.
* <p> * <p>
* <b>Note:</b> Elements marked with this annotation require the use of a datapack or otherwise * <b>Note:</b> Elements marked with this annotation require the use of a datapack or otherwise

View file

@ -56,8 +56,7 @@ public interface UnsafeValues {
* The advancement format is governed by Minecraft and has no specified * The advancement format is governed by Minecraft and has no specified
* layout. * layout.
* <br> * <br>
* It is currently a JSON object, as described by the Minecraft Wiki: * It is currently a JSON object, as described by the <a href="https://minecraft.wiki/w/Advancements">Minecraft wiki</a>.
* http://minecraft.gamepedia.com/Advancements
* <br> * <br>
* Loaded advancements will be stored and persisted across server restarts * Loaded advancements will be stored and persisted across server restarts
* and reloads. * and reloads.

View file

@ -321,7 +321,7 @@ public class WorldCreator {
* @param generatorSettings The settings that should be used by the * @param generatorSettings The settings that should be used by the
* generator * generator
* @return This object, for chaining * @return This object, for chaining
* @see <a href="https://minecraft.gamepedia.com/Custom_dimension">Custom * @see <a href="https://minecraft.wiki/w/Custom_dimension">Custom
* dimension</a> (scroll to "When the generator ID type is * dimension</a> (scroll to "When the generator ID type is
* <code>minecraft:flat</code>)" * <code>minecraft:flat</code>)"
*/ */

View file

@ -6,6 +6,7 @@ import org.bukkit.World;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
import org.bukkit.metadata.Metadatable; import org.bukkit.metadata.Metadatable;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -46,6 +47,15 @@ public interface BlockState extends Metadatable {
@NotNull @NotNull
BlockData getBlockData(); 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. * Gets the type of this block state.
* *

View file

@ -223,7 +223,7 @@ public interface Structure extends TileState {
/** /**
* Only applicable while in {@link UsageMode#DATA}. Metadata are specific * Only applicable while in {@link UsageMode#DATA}. Metadata are specific
* functions that can be applied to the structure location. Consult the * functions that can be applied to the structure location. Consult the
* <a href="https://minecraft.gamepedia.com/Structure_Block#Data">Minecraft * <a href="https://minecraft.wiki/w/Structure_Block#Data">Minecraft
* wiki</a> for more information. * wiki</a> for more information.
* *
* @param metadata the function to perform on the selected location * @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 * Get the metadata function this structure block will perform when
* activated. Consult the * activated. Consult the
* <a href="https://minecraft.gamepedia.com/Structure_Block#Data">Minecraft * <a href="https://minecraft.wiki/w/Structure_Block#Data">Minecraft
* Wiki</a> for more information. * Wiki</a> for more information.
* *
* @return the function that will be performed when this block is activated * @return the function that will be performed when this block is activated

View file

@ -23,7 +23,7 @@ public enum UsageMode {
* Used to run specific custom functions, which can only be used for certain * Used to run specific custom functions, which can only be used for certain
* Structures. The structure block is removed after this function completes. * Structures. The structure block is removed after this function completes.
* The data tags (functions) can be found on the * The data tags (functions) can be found on the
* <a href="http://minecraft.gamepedia.com/Structure_Block#Data">wiki</a>. * <a href="https://minecraft.wiki/w/Structure_Block#Data">wiki</a>.
*/ */
DATA; DATA;
} }

View file

@ -48,6 +48,27 @@ public interface Display extends Entity {
*/ */
public void setInterpolationDuration(int duration); public void setInterpolationDuration(int duration);
/**
* Gets the teleport duration of this display.
* <ul>
* <li>0 means that updates are applied immediately.</li>
* <li>1 means that the display entity will move from current position to the updated one over one tick.</li>
* <li>Higher values spread the movement over multiple ticks.</li>
* </ul>
*
* @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. * Gets the view distance/range of this display.
* *

View file

@ -547,6 +547,20 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@ApiStatus.Experimental @ApiStatus.Experimental
public boolean isVisibleByDefault(); public boolean isVisibleByDefault();
/**
* Get all players that are currently tracking this entity.
* <p>
* '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<Player> getTrackedBy();
/** /**
* Sets whether the entity has a team colored (default: white) glow. * Sets whether the entity has a team colored (default: white) glow.
* *

View file

@ -1,5 +1,9 @@
package org.bukkit.entity; 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. * 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(); 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.
* <p>
* 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.
* <p>
* 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:
* <ul>
* <li>Impact sound effects will be played
* <li>Fire will be spawned (dependent on difficulty)
* <li>Lightning rods will be powered (if hit)
* <li>Copper will be stripped (if hit)
* <li>{@link GameEvent#LIGHTNING_STRIKE} will be dispatched
* </ul>
*
* @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);
} }

View file

@ -25,11 +25,11 @@ public interface Projectile extends Entity {
/** /**
* Determine if this projectile should bounce or not when it hits. * Determine if this projectile should bounce or not when it hits.
* <p>
* If a small fireball does not bounce it will set the target on fire.
* *
* @return true if it should bounce. * @return true if it should bounce.
* @deprecated does not do anything
*/ */
@Deprecated
public boolean doesBounce(); public boolean doesBounce();
/** /**
@ -37,6 +37,8 @@ public interface Projectile extends Entity {
* something. * something.
* *
* @param doesBounce whether or not it should bounce. * @param doesBounce whether or not it should bounce.
* @deprecated does not do anything
*/ */
@Deprecated
public void setBounce(boolean doesBounce); public void setBounce(boolean doesBounce);
} }

View file

@ -3,7 +3,7 @@ package org.bukkit.entity;
/** /**
* Represents groups of entities with shared spawn behaviors and mob caps. * Represents groups of entities with shared spawn behaviors and mob caps.
* *
* @see <a href="https://minecraft.fandom.com/wiki/Spawn#Java_Edition_mob_cap">Minecraft Wiki</a> * @see <a href="https://minecraft.wiki/w/Spawn#Java_Edition_mob_cap">Minecraft Wiki</a>
*/ */
public enum SpawnCategory { public enum SpawnCategory {

View file

@ -55,7 +55,7 @@ public interface TropicalFish extends Fish {
/** /**
* Enumeration of all different fish patterns. Refer to the * Enumeration of all different fish patterns. Refer to the
* <a href="https://minecraft.gamepedia.com/Fish_(mob)">Minecraft Wiki</a> * <a href="https://minecraft.wiki/w/Fish">Minecraft Wiki</a>
* for pictures. * for pictures.
*/ */
public static enum Pattern { public static enum Pattern {

View file

@ -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.
* <p>
* 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.
* <p>
* 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.
* <p>
* Care should be taken to check {@link #isAsynchronous()} and treat the event
* appropriately.
* <p>
*/
@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<NamespacedKey, BlockTransformer> blockTransformers = new LinkedHashMap<>();
private final Map<NamespacedKey, EntityTransformer> 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<NamespacedKey, BlockTransformer> 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<NamespacedKey, EntityTransformer> 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;
}
}

View file

@ -12,8 +12,8 @@ import org.jetbrains.annotations.Nullable;
* LootTables are technical files that represent what items should be in * LootTables are technical files that represent what items should be in
* naturally generated containers, what items should be dropped when killing a * naturally generated containers, what items should be dropped when killing a
* mob, or what items can be fished. * mob, or what items can be fished.
* * <br>
* See the <a href="https://minecraft.gamepedia.com/Loot_table"> * See the <a href="https://minecraft.wiki/w/Loot_table">
* Minecraft Wiki</a> for more information. * Minecraft Wiki</a> for more information.
*/ */
public interface LootTable extends Keyed { public interface LootTable extends Keyed {

View file

@ -8,9 +8,9 @@ import org.jetbrains.annotations.NotNull;
/** /**
* This enum holds a list of all known {@link LootTable}s offered by Mojang. * 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. * This list is not guaranteed to be accurate in future versions.
* * <br>
* See the * See the
* <a href="https://minecraft.gamepedia.com/Loot_table#List_of_loot_tables"> * <a href="https://minecraft.wiki/w/Loot_table#List_of_loot_tables">
* Minecraft Wiki</a> for more information on loot tables. * Minecraft Wiki</a> for more information on loot tables.
*/ */
public enum LootTables implements Keyed { public enum LootTables implements Keyed {

View file

@ -8,6 +8,8 @@ import org.jetbrains.annotations.NotNull;
/** /**
* Represents a data pack. * Represents a data pack.
*
* @see <a href="https://minecraft.wiki/w/Data_pack">Minecraft wiki</a>
*/ */
@ApiStatus.Experimental @ApiStatus.Experimental
public interface DataPack extends Keyed { public interface DataPack extends Keyed {
@ -29,16 +31,42 @@ public interface DataPack extends Keyed {
public String getDescription(); public String getDescription();
/** /**
* Gets the pack version. * Gets the pack format.
* <br> * <br>
* 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
* <a href="https://minecraft.wiki/w/Data_pack#Pack_format">Minecraft Wiki</a>.
* *
* @return the pack version * @return the pack version
* @deprecated packs can support multiple versions * @see #getMinSupportedPackFormat()
* @see #getMaxSupportedPackFormat()
*/ */
@Deprecated
public int getPackFormat(); public int getPackFormat();
/**
* Gets the minimum supported pack format. If the data pack does not specify a
* minimum supported format, {@link #getPackFormat()} is returned.
* <br>
* Pack formats are non-standard and unrelated to the version of Minecraft. For
* a list of known pack versions, see the
* <a href="https://minecraft.wiki/w/Data_pack#Pack_format">Minecraft Wiki</a>.
*
* @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.
* <br>
* Pack formats are non-standard and unrelated to the version of Minecraft. For
* a list of known pack versions, see the
* <a href="https://minecraft.wiki/w/Data_pack#Pack_format">Minecraft Wiki</a>.
*
* @return the max pack version supported
*/
public int getMaxSupportedPackFormat();
/** /**
* Gets if the data pack is enabled on the server. * Gets if the data pack is enabled on the server.
* *

View file

@ -335,7 +335,7 @@ public final class PluginDescriptionFile {
* <li>An entry of this list can be referenced in {@link #getDepend()}, * <li>An entry of this list can be referenced in {@link #getDepend()},
* {@link #getSoftDepend()}, and {@link #getLoadBefore()}. * {@link #getSoftDepend()}, and {@link #getLoadBefore()}.
* <li><code>provides</code> must be in <a * <li><code>provides</code> must be in <a
* href="http://en.wikipedia.org/wiki/YAML#Lists">YAML list * href="https://en.wikipedia.org/wiki/YAML#Lists">YAML list
* format</a>. * format</a>.
* </ul> * </ul>
* <p> * <p>
@ -454,7 +454,7 @@ public final class PluginDescriptionFile {
* <li>A SpigotMC forum handle or email address is recommended. * <li>A SpigotMC forum handle or email address is recommended.
* <li>Is displayed when a user types <code>/version PluginName</code> * <li>Is displayed when a user types <code>/version PluginName</code>
* <li><code>authors</code> must be in <a * <li><code>authors</code> must be in <a
* href="http://en.wikipedia.org/wiki/YAML#Lists">YAML list * href="https://en.wikipedia.org/wiki/YAML#Lists">YAML list
* format</a>. * format</a>.
* </ul> * </ul>
* <p> * <p>
@ -491,7 +491,7 @@ public final class PluginDescriptionFile {
* <li>A SpigotMC forum handle or email address is recommended. * <li>A SpigotMC forum handle or email address is recommended.
* <li>Is displayed when a user types <code>/version PluginName</code> * <li>Is displayed when a user types <code>/version PluginName</code>
* <li><code>contributors</code> must be in <a * <li><code>contributors</code> must be in <a
* href="http://en.wikipedia.org/wiki/YAML#Lists">YAML list * href="https://en.wikipedia.org/wiki/YAML#Lists">YAML list
* format</a>. * format</a>.
* </ul> * </ul>
* <p> * <p>
@ -538,7 +538,7 @@ public final class PluginDescriptionFile {
* href=https://en.wikipedia.org/wiki/Circular_dependency>network</a>, * href=https://en.wikipedia.org/wiki/Circular_dependency>network</a>,
* all plugins in that network will fail. * all plugins in that network will fail.
* <li><code>depend</code> must be in <a * <li><code>depend</code> must be in <a
* href="http://en.wikipedia.org/wiki/YAML#Lists">YAML list * href="https://en.wikipedia.org/wiki/YAML#Lists">YAML list
* format</a>. * format</a>.
* </ul> * </ul>
* <p> * <p>
@ -570,7 +570,7 @@ public final class PluginDescriptionFile {
* or soft-dependending each other), it will arbitrarily choose a * or soft-dependending each other), it will arbitrarily choose a
* plugin that can be resolved when ignoring soft-dependencies. * plugin that can be resolved when ignoring soft-dependencies.
* <li><code>softdepend</code> must be in <a * <li><code>softdepend</code> must be in <a
* href="http://en.wikipedia.org/wiki/YAML#Lists">YAML list * href="https://en.wikipedia.org/wiki/YAML#Lists">YAML list
* format</a>. * format</a>.
* </ul> * </ul>
* <p> * <p>
@ -597,7 +597,7 @@ public final class PluginDescriptionFile {
* specified plugin's {@link #getSoftDepend()} include {@link * specified plugin's {@link #getSoftDepend()} include {@link
* #getName() this plugin}. * #getName() this plugin}.
* <li><code>loadbefore</code> must be in <a * <li><code>loadbefore</code> must be in <a
* href="http://en.wikipedia.org/wiki/YAML#Lists">YAML list * href="https://en.wikipedia.org/wiki/YAML#Lists">YAML list
* format</a>. * format</a>.
* </ul> * </ul>
* <p> * <p>
@ -661,7 +661,7 @@ public final class PluginDescriptionFile {
* <td><code>aliases</code></td> * <td><code>aliases</code></td>
* <td>{@link PluginCommand#setAliases(List)}</td> * <td>{@link PluginCommand#setAliases(List)}</td>
* <td>String or <a * <td>String or <a
* href="http://en.wikipedia.org/wiki/YAML#Lists">List</a> of * href="https://en.wikipedia.org/wiki/YAML#Lists">List</a> of
* strings</td> * strings</td>
* <td>Alternative command names, with special usefulness for commands * <td>Alternative command names, with special usefulness for commands
* that are already registered. <i>Aliases are not effective when * that are already registered. <i>Aliases are not effective when
@ -809,7 +809,7 @@ public final class PluginDescriptionFile {
* <p> * <p>
* Child permissions may be defined in a number of ways:<ul> * Child permissions may be defined in a number of ways:<ul>
* <li>Children may be defined as a <a * <li>Children may be defined as a <a
* href="http://en.wikipedia.org/wiki/YAML#Lists">list</a> of * href="https://en.wikipedia.org/wiki/YAML#Lists">list</a> of
* names. Using a list will treat all children associated * names. Using a list will treat all children associated
* positively to their parent. * positively to their parent.
* <li>Children may be defined as a map. Each permission name maps * <li>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 * by the API, effectively discluding any derived type from any
* plugin's classpath. * plugin's classpath.
* <li><code>awareness</code> must be in <a * <li><code>awareness</code> must be in <a
* href="http://en.wikipedia.org/wiki/YAML#Lists">YAML list * href="https://en.wikipedia.org/wiki/YAML#Lists">YAML list
* format</a>. * format</a>.
* </ul> * </ul>
* <p> * <p>

View file

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

View file

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

View file

@ -1,5 +1,6 @@
package org.bukkit; package org.bukkit;
import static org.junit.jupiter.api.Assertions.*;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
@ -13,8 +14,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
@ -49,7 +49,7 @@ public class AnnotationTest {
File file = new File(loc.toURI()); File file = new File(loc.toURI());
// Running from jar is not supported yet // Running from jar is not supported yet
Assert.assertTrue("code must be in a directory", file.isDirectory()); assertTrue(file.isDirectory(), "code must be in a directory");
final HashMap<String, ClassNode> foundClasses = new HashMap<>(); final HashMap<String, ClassNode> foundClasses = new HashMap<>();
collectClasses(file, foundClasses); collectClasses(file, foundClasses);
@ -97,7 +97,7 @@ public class AnnotationTest {
System.out.println(message); System.out.println(message);
} }
Assert.fail("There " + errors.size() + " are missing annotation(s)"); fail("There " + errors.size() + " are missing annotation(s)");
} }
private static void collectClasses(@NotNull File from, @NotNull Map<String, ClassNode> to) throws IOException { private static void collectClasses(@NotNull File from, @NotNull Map<String, ClassNode> to) throws IOException {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -15,10 +15,10 @@
package org.bukkit.metadata; package org.bukkit.metadata;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.TestPlugin; import org.bukkit.plugin.TestPlugin;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
*/ */
@ -40,7 +40,7 @@ public class MetadataConversionTest {
assertEquals(10, subject.asLong()); assertEquals(10, subject.asLong());
assertEquals(10, subject.asShort()); assertEquals(10, subject.asShort());
assertEquals(10, subject.asByte()); assertEquals(10, subject.asByte());
assertEquals(true, subject.asBoolean()); assertTrue(subject.asBoolean());
assertEquals("10", subject.asString()); assertEquals("10", subject.asString());
} }
@ -54,7 +54,7 @@ public class MetadataConversionTest {
assertEquals(10, subject.asLong()); assertEquals(10, subject.asLong());
assertEquals(10, subject.asShort()); assertEquals(10, subject.asShort());
assertEquals(10, subject.asByte()); assertEquals(10, subject.asByte());
assertEquals(true, subject.asBoolean()); assertTrue(subject.asBoolean());
assertEquals("10.5", subject.asString()); assertEquals("10.5", subject.asString());
} }
@ -68,7 +68,7 @@ public class MetadataConversionTest {
assertEquals(10, subject.asLong()); assertEquals(10, subject.asLong());
assertEquals(10, subject.asShort()); assertEquals(10, subject.asShort());
assertEquals(10, subject.asByte()); assertEquals(10, subject.asByte());
assertEquals(false, subject.asBoolean()); assertFalse(subject.asBoolean());
assertEquals("10", subject.asString()); assertEquals("10", subject.asString());
} }
@ -82,7 +82,7 @@ public class MetadataConversionTest {
assertEquals(0, subject.asLong()); assertEquals(0, subject.asLong());
assertEquals(0, subject.asShort()); assertEquals(0, subject.asShort());
assertEquals(0, subject.asByte()); assertEquals(0, subject.asByte());
assertEquals(true, subject.asBoolean()); assertTrue(subject.asBoolean());
assertEquals("true", subject.asString()); assertEquals("true", subject.asString());
} }
@ -96,7 +96,7 @@ public class MetadataConversionTest {
assertEquals(0, subject.asLong()); assertEquals(0, subject.asLong());
assertEquals(0, subject.asShort()); assertEquals(0, subject.asShort());
assertEquals(0, subject.asByte()); assertEquals(0, subject.asByte());
assertEquals(false, subject.asBoolean()); assertFalse(subject.asBoolean());
assertEquals("", subject.asString()); assertEquals("", subject.asString());
} }
} }

View file

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

View file

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

View file

@ -1,14 +1,14 @@
package org.bukkit.plugin; package org.bukkit.plugin;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.TestEvent; import org.bukkit.event.TestEvent;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class PluginManagerTest extends AbstractTestingBase { public class PluginManagerTest extends AbstractTestingBase {
private class MutableObject { private class MutableObject {
@ -164,20 +164,20 @@ public class PluginManagerTest extends AbstractTestingBase {
private void testRemovePermissionByName(final String name) { private void testRemovePermissionByName(final String name) {
final Permission perm = new Permission(name); final Permission perm = new Permission(name);
pm.addPermission(perm); pm.addPermission(perm);
assertThat("Permission \"" + name + "\" was not added", pm.getPermission(name), is(perm)); assertThat(pm.getPermission(name), is(perm), "Permission \"" + name + "\" was not added");
pm.removePermission(name); pm.removePermission(name);
assertThat("Permission \"" + name + "\" was not removed", pm.getPermission(name), is(nullValue())); assertThat(pm.getPermission(name), is(nullValue()), "Permission \"" + name + "\" was not removed");
} }
private void testRemovePermissionByPermission(final String name) { private void testRemovePermissionByPermission(final String name) {
final Permission perm = new Permission(name); final Permission perm = new Permission(name);
pm.addPermission(perm); pm.addPermission(perm);
assertThat("Permission \"" + name + "\" was not added", pm.getPermission(name), is(perm)); assertThat(pm.getPermission(name), is(perm), "Permission \"" + name + "\" was not added");
pm.removePermission(perm); pm.removePermission(perm);
assertThat("Permission \"" + name + "\" was not removed", pm.getPermission(name), is(nullValue())); assertThat(pm.getPermission(name), is(nullValue()), "Permission \"" + name + "\" was not removed");
} }
@After @AfterEach
public void tearDown() { public void tearDown() {
pm.clearPlugins(); pm.clearPlugins();
assertThat(pm.getPermissions(), is(empty())); assertThat(pm.getPermissions(), is(empty()));

View file

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

View file

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

View file

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

View file

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

View file

@ -0,0 +1,36 @@
package org.bukkit.support;
import org.hamcrest.Matcher;
/**
* Custom assertThat methods, where the reason is put at the end of the method call.
* To better match with JUnit 5 argument order and also help with readability for longer reasons.
* <br>
* <pre>
* assertThat(String.format("""
* The block data created for the material %s is not an instance of the data class from that material.
* """, material), blockData, is(instanceOf(expectedClass)));
* </pre>
* vs.
* <pre>
* assertThat(blockData, is(instanceOf(expectedClass)), String.format("""
* The block data created for the material %s is not an instance of the data class from that material.
* """, material));
* </pre>
*/
public final class MatcherAssert {
private MatcherAssert() {}
public static <T> void assertThat(T actual, Matcher<? super T> matcher) {
org.hamcrest.MatcherAssert.assertThat(actual, matcher);
}
public static <T> void assertThat(T actual, Matcher<? super T> matcher, String reason) {
org.hamcrest.MatcherAssert.assertThat(reason, actual, matcher);
}
public static void assertThat(boolean assertion, String reason) {
org.hamcrest.MatcherAssert.assertThat(reason, assertion);
}
}

View file

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

View file

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

View file

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

View file

@ -1,8 +1,8 @@
package org.bukkit.util; package org.bukkit.util;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class VectorTest { public class VectorTest {
@ -14,9 +14,9 @@ public class VectorTest {
assertTrue(new Vector(1, 0, 0).isNormalized()); assertTrue(new Vector(1, 0, 0).isNormalized());
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testNullVectorAxis() { public void testNullVectorAxis() {
new Vector(0, 1, 0).rotateAroundAxis(null, Math.PI); assertThrows(IllegalArgumentException.class, () -> new Vector(0, 1, 0).rotateAroundAxis(null, Math.PI));
} }
@Test @Test

View file

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