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.
* Avoid moving or renaming classes.
* All non-private methods and constructors must have specified nullability through [annotations](https://github.com/JetBrains/java-annotations)
* All classes/methods/fields related to a [Minecraft Experimental Feature](https://minecraft.fandom.com/wiki/Experimental_Gameplay) must be marked with [`@MinecraftExperimental`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/MinecraftExperimental.html)
* All classes/methods/fields related to a [Minecraft Experimental Feature](https://minecraft.wiki/w/Experimental_Gameplay) must be marked with [`@MinecraftExperimental`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/MinecraftExperimental.html)
* If necessary, you may consider the use of one of the following [ApiStatus Annotations](https://javadoc.io/doc/org.jetbrains/annotations-java5/23.0.0/org/jetbrains/annotations/ApiStatus.html):
* [`@ApiStatus.Experimental`](https://javadoc.io/doc/org.jetbrains/annotations-java5/23.0.0/org/jetbrains/annotations/ApiStatus.Experimental.html) for API that is subject to change
* [`@ApiStatus.Internal`](https://javadoc.io/doc/org.jetbrains/annotations-java5/23.0.0/org/jetbrains/annotations/ApiStatus.Internal.html) for API that is intended only for internal use in the Bukkit project and will not adhere to Bukkit's API contract
Bukkit/CraftBukkit employs [JUnit 4](https://www.vogella.com/tutorials/JUnit4/article.html) for testing. Pull Requests(PR) should attempt to integrate within that framework as appropriate.
Bukkit/CraftBukkit employs [JUnit 5](https://www.vogella.com/tutorials/JUnit/article.html) for testing. Pull Requests(PR) should attempt to integrate within that framework as appropriate.
Bukkit is a large project and what seems simple to a PR author at the time of writing may easily be overlooked by other authors and updates. Including unit tests with your PR
will help to ensure the PR can be easily maintained over time and encourage the Spigot team to pull the PR.

17
pom.xml
View file

@ -86,15 +86,15 @@
</dependency>
<!-- testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
@ -193,8 +193,6 @@
<configuration>
<links>
<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>
<tags>
<tag>
@ -205,6 +203,11 @@
</tags>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
</build>

View file

@ -4,6 +4,9 @@ import org.jetbrains.annotations.ApiStatus;
/**
* 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
public interface FeatureFlag extends Keyed {
@ -15,7 +18,13 @@ public interface FeatureFlag extends Keyed {
/**
* <strong>AVAILABLE BETWEEN VERSIONS:</strong> 1.19 - 1.19.4
*
* @deprecated not available since 1.20
*/
@Deprecated
@MinecraftExperimental
public static final FeatureFlag UPDATE_1_20 = Bukkit.getUnsafe().getFeatureFlag(NamespacedKey.minecraft("update_1_20"));
@MinecraftExperimental
public static final FeatureFlag TRADE_REBALANCE = Bukkit.getUnsafe().getFeatureFlag(NamespacedKey.minecraft("trade_rebalance"));
}

View file

@ -10,7 +10,7 @@ import org.jetbrains.annotations.Nullable;
* GameRules dictate certain behavior within Minecraft itself
* <br>
* 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>
*
* @param <T> type of rule (Boolean or Integer)

View file

@ -3,8 +3,7 @@ package org.bukkit;
/**
* Further information regarding heightmaps.
*
* @see <a href="https://minecraft.gamepedia.com/Chunk_format">Gamepedia Chunk
* Format</a>
* @see <a href="https://minecraft.wiki/w/Chunk_format">Minecraft Wiki</a>
*/
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()}).
* </ul>
* 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
*/

View file

@ -9,7 +9,7 @@ import org.jetbrains.annotations.ApiStatus;
/**
* 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.
* <p>
* <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
* layout.
* <br>
* It is currently a JSON object, as described by the Minecraft Wiki:
* http://minecraft.gamepedia.com/Advancements
* It is currently a JSON object, as described by the <a href="https://minecraft.wiki/w/Advancements">Minecraft wiki</a>.
* <br>
* Loaded advancements will be stored and persisted across server restarts
* and reloads.

View file

@ -321,7 +321,7 @@ public class WorldCreator {
* @param generatorSettings The settings that should be used by the
* generator
* @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
* <code>minecraft:flat</code>)"
*/

View file

@ -6,6 +6,7 @@ import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.material.MaterialData;
import org.bukkit.metadata.Metadatable;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -46,6 +47,15 @@ public interface BlockState extends Metadatable {
@NotNull
BlockData getBlockData();
/**
* Returns a copy of this BlockState as an unplaced BlockState.
*
* @return a copy of the block state
*/
@NotNull
@ApiStatus.Experimental
BlockState copy();
/**
* Gets the type of this block state.
*

View file

@ -223,7 +223,7 @@ public interface Structure extends TileState {
/**
* Only applicable while in {@link UsageMode#DATA}. Metadata are specific
* functions that can be applied to the structure location. Consult the
* <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.
*
* @param metadata the function to perform on the selected location
@ -233,7 +233,7 @@ public interface Structure extends TileState {
/**
* Get the metadata function this structure block will perform when
* activated. Consult the
* <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.
*
* @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
* Structures. The structure block is removed after this function completes.
* 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;
}

View file

@ -48,6 +48,27 @@ public interface Display extends Entity {
*/
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.
*

View file

@ -547,6 +547,20 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@ApiStatus.Experimental
public boolean isVisibleByDefault();
/**
* Get all players that are currently tracking this entity.
* <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.
*

View file

@ -1,5 +1,9 @@
package org.bukkit.entity;
import org.bukkit.GameEvent;
import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.Nullable;
/**
* Represents an instance of a lightning strike. May or may not do damage.
*/
@ -12,4 +16,70 @@ public interface LightningStrike extends Entity {
*/
public boolean isEffect();
/**
* Get the amount of flashes that will occur before the lightning is
* removed. By default this value is between 1 and 3.
*
* @return the flashes
*/
public int getFlashes();
/**
* Set the amount of flashes that will occur before the lightning is
* removed. One flash will occur after this lightning strike's life
* has reduced below 0.
*
* @param flashes the flashes
*/
public void setFlashes(int flashes);
/**
* Get the amount of ticks this lightning strike will inflict damage
* upon its hit entities.
* <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.
* <p>
* If a small fireball does not bounce it will set the target on fire.
*
* @return true if it should bounce.
* @deprecated does not do anything
*/
@Deprecated
public boolean doesBounce();
/**
@ -37,6 +37,8 @@ public interface Projectile extends Entity {
* something.
*
* @param doesBounce whether or not it should bounce.
* @deprecated does not do anything
*/
@Deprecated
public void setBounce(boolean doesBounce);
}

View file

@ -3,7 +3,7 @@ package org.bukkit.entity;
/**
* 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 {

View file

@ -55,7 +55,7 @@ public interface TropicalFish extends Fish {
/**
* 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.
*/
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
* naturally generated containers, what items should be dropped when killing a
* mob, or what items can be fished.
*
* See the <a href="https://minecraft.gamepedia.com/Loot_table">
* <br>
* See the <a href="https://minecraft.wiki/w/Loot_table">
* Minecraft Wiki</a> for more information.
*/
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 list is not guaranteed to be accurate in future versions.
*
* <br>
* 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.
*/
public enum LootTables implements Keyed {

View file

@ -8,6 +8,8 @@ import org.jetbrains.annotations.NotNull;
/**
* Represents a data pack.
*
* @see <a href="https://minecraft.wiki/w/Data_pack">Minecraft wiki</a>
*/
@ApiStatus.Experimental
public interface DataPack extends Keyed {
@ -29,16 +31,42 @@ public interface DataPack extends Keyed {
public String getDescription();
/**
* Gets the pack version.
* Gets the pack format.
* <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
* @deprecated packs can support multiple versions
* @see #getMinSupportedPackFormat()
* @see #getMaxSupportedPackFormat()
*/
@Deprecated
public int getPackFormat();
/**
* Gets the minimum supported pack format. If the data pack does not specify a
* minimum supported format, {@link #getPackFormat()} is returned.
* <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.
*

View file

@ -335,7 +335,7 @@ public final class PluginDescriptionFile {
* <li>An entry of this list can be referenced in {@link #getDepend()},
* {@link #getSoftDepend()}, and {@link #getLoadBefore()}.
* <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>.
* </ul>
* <p>
@ -454,7 +454,7 @@ public final class PluginDescriptionFile {
* <li>A SpigotMC forum handle or email address is recommended.
* <li>Is displayed when a user types <code>/version PluginName</code>
* <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>.
* </ul>
* <p>
@ -491,7 +491,7 @@ public final class PluginDescriptionFile {
* <li>A SpigotMC forum handle or email address is recommended.
* <li>Is displayed when a user types <code>/version PluginName</code>
* <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>.
* </ul>
* <p>
@ -538,7 +538,7 @@ public final class PluginDescriptionFile {
* href=https://en.wikipedia.org/wiki/Circular_dependency>network</a>,
* all plugins in that network will fail.
* <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>.
* </ul>
* <p>
@ -570,7 +570,7 @@ public final class PluginDescriptionFile {
* or soft-dependending each other), it will arbitrarily choose a
* plugin that can be resolved when ignoring soft-dependencies.
* <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>.
* </ul>
* <p>
@ -597,7 +597,7 @@ public final class PluginDescriptionFile {
* specified plugin's {@link #getSoftDepend()} include {@link
* #getName() this plugin}.
* <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>.
* </ul>
* <p>
@ -661,7 +661,7 @@ public final class PluginDescriptionFile {
* <td><code>aliases</code></td>
* <td>{@link PluginCommand#setAliases(List)}</td>
* <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>
* <td>Alternative command names, with special usefulness for commands
* that are already registered. <i>Aliases are not effective when
@ -809,7 +809,7 @@ public final class PluginDescriptionFile {
* <p>
* Child permissions may be defined in a number of ways:<ul>
* <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
* positively to their parent.
* <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
* plugin's classpath.
* <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>.
* </ul>
* <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;
import static org.junit.jupiter.api.Assertions.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -13,8 +14,7 @@ import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
@ -49,7 +49,7 @@ public class AnnotationTest {
File file = new File(loc.toURI());
// Running from jar is not supported yet
Assert.assertTrue("code must be in a directory", file.isDirectory());
assertTrue(file.isDirectory(), "code must be in a directory");
final HashMap<String, ClassNode> foundClasses = new HashMap<>();
collectClasses(file, foundClasses);
@ -97,7 +97,7 @@ public class AnnotationTest {
System.out.println(message);
}
Assert.fail("There " + errors.size() + " are missing annotation(s)");
fail("There " + errors.size() + " are missing annotation(s)");
}
private static void collectClasses(@NotNull File from, @NotNull Map<String, ClassNode> to) throws IOException {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,23 +1,23 @@
package org.bukkit.scoreboard;
import static org.junit.jupiter.api.Assertions.*;
import org.bukkit.Statistic;
import org.bukkit.block.BlockType;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemType;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class CriteriaTest extends AbstractTestingBase {
@Test
public void testStatistic() {
Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, BlockType.STONE)); // Generic statistic with block
Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, EntityType.CREEPER)); // Generic statistic with entity type
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, BlockType.STONE)); // Generic statistic with block
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, EntityType.CREEPER)); // Generic statistic with entity type
Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.ENTITY_KILLED_BY, ItemType.AMETHYST_SHARD)); // Entity statistic with item type
Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.MINE_BLOCK, ItemType.DIAMOND_PICKAXE)); // Block statistic with item
Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.BREAK_ITEM, BlockType.WATER)); // Item statistic with block
Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.KILL_ENTITY, BlockType.STONE)); // Entity statistic with block type
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.ENTITY_KILLED_BY, ItemType.AMETHYST_SHARD)); // Entity statistic with item type
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.MINE_BLOCK, ItemType.DIAMOND_PICKAXE)); // Block statistic with item
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.BREAK_ITEM, BlockType.WATER)); // Item statistic with block
assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.KILL_ENTITY, BlockType.STONE)); // Entity statistic with block type
}
}

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;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class BoundingBoxTest {

View file

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

View file

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

View file

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