Updated to 1.21.3

This commit is contained in:
tastybento 2024-11-07 18:19:40 -08:00
parent 284e7e9601
commit a531721343
10 changed files with 235 additions and 40 deletions

10
pom.xml
View File

@ -54,11 +54,11 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version> <java.version>21</java.version>
<!-- Non-minecraft related dependencies --> <!-- Non-minecraft related dependencies -->
<powermock.version>2.0.9</powermock.version> <powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions --> <!-- More visible way how to change dependency versions -->
<spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version> <spigot.version>1.21.3-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>2.5.0-SNAPSHOT</bentobox.version> <bentobox.version>2.5.0-SNAPSHOT</bentobox.version>
<!-- Revision variable removes warning about dynamic version --> <!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision> <revision>${build.version}-SNAPSHOT</revision>
@ -121,11 +121,7 @@
</repository> </repository>
<repository> <repository>
<id>codemc-repo</id> <id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url> <url>https://repo.codemc.io/repository/tastybento/</url>
</repository>
<repository>
<id>codemc</id>
<url>https://repo.codemc.org/repository/maven-snapshots/</url>
</repository> </repository>
<repository> <repository>
<id>ess-repo</id> <id>ess-repo</id>

View File

@ -260,7 +260,7 @@ public class AISettings implements WorldSettings {
private Biome defaultBiome = Biome.WARM_OCEAN; private Biome defaultBiome = Biome.WARM_OCEAN;
@ConfigComment("The default biome for the nether world (this may affect what mobs can spawn)") @ConfigComment("The default biome for the nether world (this may affect what mobs can spawn)")
@ConfigEntry(path = "world.default-nether-biome") @ConfigEntry(path = "world.default-nether-biome")
private Biome defaultNetherBiome = Enums.getIfPresent(Biome.class, "NETHER").or(Enums.getIfPresent(Biome.class, "NETHER_WASTES").or(Biome.BADLANDS)); private Biome defaultNetherBiome = Biome.NETHER_WASTES;
@ConfigComment("The default biome for the end world (this may affect what mobs can spawn)") @ConfigComment("The default biome for the end world (this may affect what mobs can spawn)")
@ConfigEntry(path = "world.default-end-biome") @ConfigEntry(path = "world.default-end-biome")
private Biome defaultEndBiome = Biome.THE_END; private Biome defaultEndBiome = Biome.THE_END;

View File

@ -12,7 +12,6 @@ import org.bukkit.Sound;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -56,9 +55,9 @@ public class AcidEffect implements Listener {
private static final List<PotionEffectType> EFFECTS; private static final List<PotionEffectType> EFFECTS;
static { static {
if (!inTest()) { if (!inTest()) {
EFFECTS = List.of(PotionEffectType.BLINDNESS, PotionEffectType.CONFUSION, PotionEffectType.HUNGER, EFFECTS = List.of(PotionEffectType.BLINDNESS, PotionEffectType.NAUSEA, PotionEffectType.HUNGER,
PotionEffectType.SLOW, PotionEffectType.SLOW_DIGGING, PotionEffectType.WEAKNESS, PotionEffectType.SLOWNESS, PotionEffectType.MINING_FATIGUE, PotionEffectType.WEAKNESS,
PotionEffectType.POISON); PotionEffectType.POISON, PotionEffectType.DARKNESS, PotionEffectType.UNLUCK);
} else { } else {
EFFECTS = List.of(); EFFECTS = List.of();
} }
@ -294,8 +293,8 @@ public class AcidEffect implements Listener {
return true; return true;
} }
// Check if player is on a boat // Check if player is on a boat
if (player.getVehicle() != null && (player.getVehicle().getType().equals(EntityType.BOAT) if (player.getVehicle() != null && (player.getVehicle().getType().getKey().getKey().contains("boat")
|| player.getVehicle().getType().equals(EntityType.CHEST_BOAT))) { || player.getVehicle().getType().getKey().getKey().contains("raft"))) {
// I'M ON A BOAT! I'M ON A BOAT! A %^&&* BOAT! SNL Sketch. https://youtu.be/avaSdC0QOUM. // I'M ON A BOAT! I'M ON A BOAT! A %^&&* BOAT! SNL Sketch. https://youtu.be/avaSdC0QOUM.
return true; return true;
} }
@ -330,7 +329,7 @@ public class AcidEffect implements Listener {
*/ */
public static double getDamageReduced(LivingEntity le) { public static double getDamageReduced(LivingEntity le) {
// Full diamond armor value = 20. This normalizes it to a max of 0.8. Enchantments can raise it out further. // Full diamond armor value = 20. This normalizes it to a max of 0.8. Enchantments can raise it out further.
double red = le.getAttribute(Attribute.GENERIC_ARMOR).getValue() * 0.04; double red = le.getAttribute(Attribute.ARMOR).getValue() * 0.04;
EntityEquipment inv = le.getEquipment(); EntityEquipment inv = le.getEquipment();
ItemStack boots = inv.getBoots(); ItemStack boots = inv.getBoots();
ItemStack helmet = inv.getHelmet(); ItemStack helmet = inv.getHelmet();

View File

@ -7,6 +7,7 @@ import static org.junit.Assert.assertTrue;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Difficulty; import org.bukkit.Difficulty;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
@ -14,15 +15,24 @@ import org.bukkit.entity.EntityType;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import world.bentobox.acidisland.mocks.ServerMocks;
import world.bentobox.bentobox.lists.Flags; import world.bentobox.bentobox.lists.Flags;
/** /**
* @author tastybento * @author tastybento
* *
*/ */
@RunWith(PowerMockRunner.class)
@PrepareForTest({ Bukkit.class })
public class AISettingsTest { public class AISettingsTest {
/** /**
@ -30,6 +40,11 @@ public class AISettingsTest {
*/ */
private AISettings s; private AISettings s;
@BeforeClass
public static void beforeClass() {
ServerMocks.newServer();
}
/** /**
* @throws java.lang.Exception * @throws java.lang.Exception
*/ */

View File

@ -46,6 +46,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox; import org.powermock.reflect.Whitebox;
import world.bentobox.acidisland.mocks.ServerMocks;
import world.bentobox.acidisland.world.ChunkGeneratorWorld; import world.bentobox.acidisland.world.ChunkGeneratorWorld;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.Settings;
@ -104,6 +105,7 @@ public class AcidIslandTest {
when(DatabaseSetup.getDatabase()).thenReturn(dbSetup); when(DatabaseSetup.getDatabase()).thenReturn(dbSetup);
when(dbSetup.getHandler(any())).thenReturn(h); when(dbSetup.getHandler(any())).thenReturn(h);
when(h.saveObject(any())).thenReturn(CompletableFuture.completedFuture(true)); when(h.saveObject(any())).thenReturn(CompletableFuture.completedFuture(true));
ServerMocks.newServer();
} }
@After @After

View File

@ -24,6 +24,7 @@ import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance; import org.bukkit.attribute.AttributeInstance;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Boat; import org.bukkit.entity.Boat;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -44,6 +45,7 @@ import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -59,6 +61,7 @@ import com.earth2me.essentials.User;
import world.bentobox.acidisland.AISettings; import world.bentobox.acidisland.AISettings;
import world.bentobox.acidisland.AcidIsland; import world.bentobox.acidisland.AcidIsland;
import world.bentobox.acidisland.mocks.ServerMocks;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.IslandsManager;
@ -118,8 +121,11 @@ public class AcidEffectTest {
@Mock @Mock
private Server server; private Server server;
/** @BeforeClass
*/ public static void beforeClass() {
ServerMocks.newServer();
}
@Before @Before
public void setUp() { public void setUp() {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS); PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
@ -480,7 +486,7 @@ public class AcidEffectTest {
public void testOnPlayerMoveInBoat() { public void testOnPlayerMoveInBoat() {
when(settings.getAcidRainDamage()).thenReturn(0); when(settings.getAcidRainDamage()).thenReturn(0);
Entity boat = mock(Boat.class); Entity boat = mock(Boat.class);
when(boat.getType()).thenReturn(EntityType.BOAT); when(boat.getType()).thenReturn(EntityType.ACACIA_BOAT);
when(player.getVehicle()).thenReturn(boat); when(player.getVehicle()).thenReturn(boat);
PlayerMoveEvent e = new PlayerMoveEvent(player, from, to); PlayerMoveEvent e = new PlayerMoveEvent(player, from, to);
ae.onPlayerMove(e); ae.onPlayerMove(e);
@ -574,10 +580,11 @@ public class AcidEffectTest {
*/ */
@Test @Test
public void testGetDamageReducedFullDiamond() { public void testGetDamageReducedFullDiamond() {
AttributeInstance value = mock(AttributeInstance.class); Att value = new Att();
when(value.getValue()).thenReturn(20D); //AttributeInstance value = new AttributeInstance();
//when(value.getValue()).thenReturn(20D);
// Diamond armor // Diamond armor
when(player.getAttribute(eq(Attribute.GENERIC_ARMOR))).thenReturn(value); when(player.getAttribute(eq(Attribute.ARMOR))).thenReturn(value);
EntityEquipment equip = mock(EntityEquipment.class); EntityEquipment equip = mock(EntityEquipment.class);
when(equip.getBoots()).thenReturn(new ItemStack(Material.DIAMOND_BOOTS)); when(equip.getBoots()).thenReturn(new ItemStack(Material.DIAMOND_BOOTS));
when(equip.getHelmet()).thenReturn(new ItemStack(Material.DIAMOND_HELMET)); when(equip.getHelmet()).thenReturn(new ItemStack(Material.DIAMOND_HELMET));
@ -589,6 +596,57 @@ public class AcidEffectTest {
} }
class Att implements AttributeInstance {
@Override
public Attribute getAttribute() {
// TODO Auto-generated method stub
return null;
}
@Override
public double getBaseValue() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void setBaseValue(double value) {
// TODO Auto-generated method stub
}
@Override
public Collection<AttributeModifier> getModifiers() {
// TODO Auto-generated method stub
return null;
}
@Override
public void addModifier(AttributeModifier modifier) {
// TODO Auto-generated method stub
}
@Override
public void removeModifier(AttributeModifier modifier) {
// TODO Auto-generated method stub
}
@Override
public double getValue() {
return 20;
}
@Override
public double getDefaultValue() {
// TODO Auto-generated method stub
return 0;
}
}
/** /**
* Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#checkForRain(Player)}. * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#checkForRain(Player)}.
*/ */
@ -629,7 +687,7 @@ public class AcidEffectTest {
AttributeInstance value = mock(AttributeInstance.class); AttributeInstance value = mock(AttributeInstance.class);
when(value.getValue()).thenReturn(20D); when(value.getValue()).thenReturn(20D);
// Diamond armor // Diamond armor
when(player.getAttribute(eq(Attribute.GENERIC_ARMOR))).thenReturn(value); when(player.getAttribute(eq(Attribute.ARMOR))).thenReturn(value);
EntityEquipment equip = mock(EntityEquipment.class); EntityEquipment equip = mock(EntityEquipment.class);
when(equip.getBoots()).thenReturn(new ItemStack(Material.DIAMOND_BOOTS)); when(equip.getBoots()).thenReturn(new ItemStack(Material.DIAMOND_BOOTS));
when(equip.getHelmet()).thenReturn(new ItemStack(Material.DIAMOND_HELMET)); when(equip.getHelmet()).thenReturn(new ItemStack(Material.DIAMOND_HELMET));
@ -672,7 +730,7 @@ public class AcidEffectTest {
public void testIsSafeFromAcidBoat() { public void testIsSafeFromAcidBoat() {
when(player.isInsideVehicle()).thenReturn(true); when(player.isInsideVehicle()).thenReturn(true);
Entity boat = mock(Entity.class); Entity boat = mock(Entity.class);
when(boat.getType()).thenReturn(EntityType.BOAT); when(boat.getType()).thenReturn(EntityType.ACACIA_BOAT);
when(player.getVehicle()).thenReturn(boat); when(player.getVehicle()).thenReturn(boat);
assertTrue(ae.isSafeFromAcid(player)); assertTrue(ae.isSafeFromAcid(player));
} }
@ -684,7 +742,7 @@ public class AcidEffectTest {
public void testIsSafeFromAcidChestBoat() { public void testIsSafeFromAcidChestBoat() {
when(player.isInsideVehicle()).thenReturn(true); when(player.isInsideVehicle()).thenReturn(true);
Entity boat = mock(Entity.class); Entity boat = mock(Entity.class);
when(boat.getType()).thenReturn(EntityType.CHEST_BOAT); when(boat.getType()).thenReturn(EntityType.ACACIA_CHEST_BOAT);
when(player.getVehicle()).thenReturn(boat); when(player.getVehicle()).thenReturn(boat);
assertTrue(ae.isSafeFromAcid(player)); assertTrue(ae.isSafeFromAcid(player));
} }

View File

@ -19,6 +19,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@ -33,6 +34,7 @@ import com.earth2me.essentials.User;
import world.bentobox.acidisland.AISettings; import world.bentobox.acidisland.AISettings;
import world.bentobox.acidisland.AcidIsland; import world.bentobox.acidisland.AcidIsland;
import world.bentobox.acidisland.mocks.ServerMocks;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.IslandsManager;
@ -86,8 +88,11 @@ public class LavaCheckTest {
private LavaCheck lc; private LavaCheck lc;
/** @BeforeClass
*/ public static void beforeClass() {
ServerMocks.newServer();
}
@Before @Before
public void setUp() { public void setUp() {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS); PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);

View File

@ -0,0 +1,118 @@
package world.bentobox.acidisland.mocks;
import static org.mockito.ArgumentMatchers.notNull;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.Server;
import org.bukkit.Tag;
import org.bukkit.UnsafeValues;
import org.eclipse.jdt.annotation.NonNull;
public final class ServerMocks {
public static @NonNull Server newServer() {
Server mock = mock(Server.class);
Logger noOp = mock(Logger.class);
when(mock.getLogger()).thenReturn(noOp);
when(mock.isPrimaryThread()).thenReturn(true);
// Unsafe
UnsafeValues unsafe = mock(UnsafeValues.class);
when(mock.getUnsafe()).thenReturn(unsafe);
// Server must be available before tags can be mocked.
Bukkit.setServer(mock);
// Bukkit has a lot of static constants referencing registry values. To initialize those, the
// registries must be able to be fetched before the classes are touched.
Map<Class<? extends Keyed>, Object> registers = new HashMap<>();
doAnswer(invocationGetRegistry -> registers.computeIfAbsent(invocationGetRegistry.getArgument(0), clazz -> {
Registry<?> registry = mock(Registry.class);
Map<NamespacedKey, Keyed> cache = new HashMap<>();
doAnswer(invocationGetEntry -> {
NamespacedKey key = invocationGetEntry.getArgument(0);
// Some classes (like BlockType and ItemType) have extra generics that will be
// erased during runtime calls. To ensure accurate typing, grab the constant's field.
// This approach also allows us to return null for unsupported keys.
Class<? extends Keyed> constantClazz;
try {
//noinspection unchecked
constantClazz = (Class<? extends Keyed>) clazz
.getField(key.getKey().toUpperCase(Locale.ROOT).replace('.', '_')).getType();
} catch (ClassCastException e) {
throw new RuntimeException(e);
} catch (NoSuchFieldException e) {
return null;
}
return cache.computeIfAbsent(key, key1 -> {
Keyed keyed = mock(constantClazz);
doReturn(key).when(keyed).getKey();
return keyed;
});
}).when(registry).get(notNull());
return registry;
})).when(mock).getRegistry(notNull());
// Tags are dependent on registries, but use a different method.
// This will set up blank tags for each constant; all that needs to be done to render them
// functional is to re-mock Tag#getValues.
doAnswer(invocationGetTag -> {
Tag<?> tag = mock(Tag.class);
doReturn(invocationGetTag.getArgument(1)).when(tag).getKey();
doReturn(Set.of()).when(tag).getValues();
doAnswer(invocationIsTagged -> {
Keyed keyed = invocationIsTagged.getArgument(0);
Class<?> type = invocationGetTag.getArgument(2);
if (!type.isAssignableFrom(keyed.getClass())) {
return null;
}
// Since these are mocks, the exact instance might not be equal. Consider equal keys equal.
return tag.getValues().contains(keyed)
|| tag.getValues().stream().anyMatch(value -> value.getKey().equals(keyed.getKey()));
}).when(tag).isTagged(notNull());
return tag;
}).when(mock).getTag(notNull(), notNull(), notNull());
// Once the server is all set up, touch BlockType and ItemType to initialize.
// This prevents issues when trying to access dependent methods from a Material constant.
try {
Class.forName("org.bukkit.inventory.ItemType");
Class.forName("org.bukkit.block.BlockType");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
return mock;
}
public static void unsetBukkitServer() {
try {
Field server = Bukkit.class.getDeclaredField("server");
server.setAccessible(true);
server.set(null, null);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
private ServerMocks() {
}
}

View File

@ -34,6 +34,7 @@ import org.bukkit.scheduler.BukkitTask;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@ -44,6 +45,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
import world.bentobox.acidisland.AISettings; import world.bentobox.acidisland.AISettings;
import world.bentobox.acidisland.AcidIsland; import world.bentobox.acidisland.AcidIsland;
import world.bentobox.acidisland.mocks.ServerMocks;
/** /**
* @author tastybento * @author tastybento
@ -77,9 +79,11 @@ public class AcidTaskTest {
@Mock @Mock
private Location l; private Location l;
@BeforeClass
public static void beforeClass() {
ServerMocks.newServer();
}
/**
*/
@Before @Before
public void setUp() { public void setUp() {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS); PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
@ -116,7 +120,7 @@ public class AcidTaskTest {
mob.add(mock(Cod.class)); mob.add(mock(Cod.class));
Item i = mock(Item.class); Item i = mock(Item.class);
when(i.getLocation()).thenReturn(l); when(i.getLocation()).thenReturn(l);
when(i.getType()).thenReturn(EntityType.DROPPED_ITEM); when(i.getType()).thenReturn(EntityType.ITEM);
when(i.getWorld()).thenReturn(world); when(i.getWorld()).thenReturn(world);
mob.add(i); mob.add(i);
when(world.getEntities()).thenReturn(mob); when(world.getEntities()).thenReturn(mob);
@ -176,7 +180,7 @@ public class AcidTaskTest {
at.setItemsInWater(map); at.setItemsInWater(map);
at.applyDamage(e, 0); at.applyDamage(e, 0);
verify(world).playSound(eq(l), any(Sound.class), anyFloat(), anyFloat()); verify(world).playSound(eq(l), (Sound) Mockito.isNull(), anyFloat(), anyFloat());
verify(e).remove(); verify(e).remove();
assertTrue(map.isEmpty()); assertTrue(map.isEmpty());
} }

View File

@ -1,24 +1,23 @@
package world.bentobox.acidisland.world; package world.bentobox.acidisland.world;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.generator.ChunkGenerator.ChunkData; import org.bukkit.generator.ChunkGenerator.ChunkData;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import world.bentobox.acidisland.AISettings; import world.bentobox.acidisland.AISettings;
import world.bentobox.acidisland.AcidIsland; import world.bentobox.acidisland.AcidIsland;
import world.bentobox.acidisland.mocks.ServerMocks;
/** /**
* @author tastybento * @author tastybento
@ -33,19 +32,18 @@ public class ChunkGeneratorWorldTest {
private ChunkGeneratorWorld cg; private ChunkGeneratorWorld cg;
@Mock @Mock
private World world; private World world;
private AISettings settings; private AISettings settings;
@Mock @Mock
private ChunkData data; private ChunkData data;
/** @BeforeClass
*/ public static void beforeClass() {
ServerMocks.newServer();
}
@Before @Before
public void setUp() { public void setUp() {
// Bukkit
PowerMockito.mockStatic(Bukkit.class);
Server server = mock(Server.class);
when(server.createChunkData(any())).thenReturn(data);
when(Bukkit.getServer()).thenReturn(server);
// World // World
when(world.getEnvironment()).thenReturn(World.Environment.NORMAL); when(world.getEnvironment()).thenReturn(World.Environment.NORMAL);
when(world.getMaxHeight()).thenReturn(256); when(world.getMaxHeight()).thenReturn(256);