Added test classes and removed code smells

This commit is contained in:
tastybento 2019-03-09 09:26:05 -08:00
parent 02cfc28cd1
commit 91b33b893c
4 changed files with 841 additions and 79 deletions

View File

@ -7,6 +7,7 @@ import java.util.Random;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Biome;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.util.noise.PerlinOctaveGenerator;
@ -20,7 +21,7 @@ import world.bentobox.bskyblock.BSkyBlock;
public class ChunkGeneratorWorld extends ChunkGenerator {
BSkyBlock addon;
Random rand = new Random();
Random rand;
PerlinOctaveGenerator gen;
/**
@ -33,23 +34,25 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
@Override
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, ChunkGenerator.BiomeGrid biomeGrid) {
if (world.getEnvironment().equals(World.Environment.NETHER)) {
return generateNetherChunks(world, random);
this.rand = random;
if (world.getEnvironment().equals(World.Environment.NETHER) && addon.getSettings().isNetherRoof()) {
return generateNetherRoofChunks(world, random);
}
ChunkData result = createChunkData(world);
if (addon.getSettings().getSeaHeight() != 0) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
if (world.getEnvironment().equals(Environment.NORMAL)) {
biomeGrid.setBiome(x, z, addon.getSettings().getDefaultBiome());
}
for (int y = 0; y <= addon.getSettings().getSeaHeight(); y++) {
if (!world.getEnvironment().equals(Environment.NORMAL)) {
return result;
}
Biome bio = addon.getSettings().getDefaultBiome();
int seaHeight = addon.getSettings().getSeaHeight();
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
biomeGrid.setBiome(x, z, bio);
if (seaHeight != 0) {
for (int y = 0; y <= seaHeight; y++) {
result.setBlock(x, y, z, Material.WATER);
}
}
}
}
return result;
}
@ -67,84 +70,91 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
/*
* Nether Section
*/
private ChunkData generateNetherChunks(World world, Random random) {
private ChunkData generateNetherRoofChunks(World world, Random random) {
ChunkData result = createChunkData(world);
rand.setSeed(world.getSeed());
gen = new PerlinOctaveGenerator((long) (random.nextLong() * random.nextGaussian()), 8);
// This is a nether generator
if (!world.getEnvironment().equals(Environment.NETHER)) {
return result;
}
if (addon.getSettings().isNetherRoof()) {
// Make the roof - common across the world
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
// Do the ceiling
int maxHeight = world.getMaxHeight();
result.setBlock(x, (maxHeight - 1), z, Material.BEDROCK);
// Next three layers are a mix of bedrock and netherrack
for (int y = 2; y < 5; y++) {
double r = gen.noise(x, (maxHeight - y), z, 0.5, 0.5);
if (r > 0D) {
result.setBlock(x, (maxHeight - y), z, Material.BEDROCK);
}
}
// Next three layers are a mix of netherrack and air
for (int y = 5; y < 8; y++) {
double r = gen.noise(x, (double)maxHeight - y, z, 0.5, 0.5);
if (r > 0D) {
result.setBlock(x, (maxHeight - y), z, Material.NETHERRACK);
} else {
result.setBlock(x, (maxHeight - y), z, Material.AIR);
}
}
// Layer 8 may be glowstone
doGlowStone(result, maxHeight, x, z, random);
}
// Make the roof - common across the world
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
// Do the ceiling
makeCeiling(result, x, z, world.getMaxHeight());
}
}
return result;
}
private void doGlowStone(ChunkData result, int maxHeight, int x, int z, Random random) {
double r = gen.noise(x, (double)maxHeight - 8, z, random.nextFloat(), random.nextFloat());
if (r > 0.5D) {
// Have blobs of glowstone
switch (random.nextInt(4)) {
case 1:
// Single block
result.setBlock(x, (maxHeight - 8), z, Material.GLOWSTONE);
if (x < 14 && z < 14) {
result.setBlock(x + 1, (maxHeight - 8), z + 1, Material.GLOWSTONE);
result.setBlock(x + 2, (maxHeight - 8), z + 2, Material.GLOWSTONE);
result.setBlock(x + 1, (maxHeight - 8), z + 2, Material.GLOWSTONE);
result.setBlock(x + 1, (maxHeight - 8), z + 2, Material.GLOWSTONE);
}
break;
case 2:
// Stalatite
for (int i = 0; i < random.nextInt(10); i++) {
result.setBlock(x, (maxHeight - 8 - i), z, Material.GLOWSTONE);
}
break;
case 3:
result.setBlock(x, (maxHeight - 8), z, Material.GLOWSTONE);
if (x > 3 && z > 3) {
for (int xx = 0; xx < 3; xx++) {
for (int zz = 0; zz < 3; zz++) {
result.setBlock(x - xx, (maxHeight - 8 - random.nextInt(2)), z - xx, Material.GLOWSTONE);
}
}
}
break;
default:
result.setBlock(x, (maxHeight - 8), z, Material.GLOWSTONE);
private void makeCeiling(ChunkData result, int x, int z, int maxHeight) {
result.setBlock(x, (maxHeight - 1), z, Material.BEDROCK);
// Next three layers are a mix of bedrock and netherrack
for (int y = 2; y < 5; y++) {
double r = gen.noise(x, (maxHeight - y), z, 0.5, 0.5);
if (r > 0D) {
result.setBlock(x, (maxHeight - y), z, Material.BEDROCK);
}
result.setBlock(x, (maxHeight - 8), z, Material.GLOWSTONE);
} else {
result.setBlock(x, (maxHeight - 8), z, Material.AIR);
}
// Next three layers are a mix of netherrack and air
for (int y = 5; y < 8; y++) {
double r = gen.noise(x, (double)maxHeight - y, z, 0.5, 0.5);
if (r > 0D) {
result.setBlock(x, (maxHeight - y), z, Material.NETHERRACK);
} else {
result.setBlock(x, (maxHeight - y), z, Material.AIR);
}
}
// Layer 8 may be glowstone
doGlowStone(result, maxHeight, x, z);
}
private void doGlowStone(ChunkData result, int maxHeight, int x, int z) {
double r = gen.noise(x, (double)maxHeight - 8, z, rand.nextFloat(), rand.nextFloat());
if (r < 0.5D) {
return;
}
// Have blobs of glowstone
switch (rand.nextInt(4)) {
case 1:
// Blob type 1
setBlob1(result, x, maxHeight - 8, z);
break;
case 2:
// Stalactite
setStalactite(result, x, maxHeight - 8, z);
break;
case 3:
setBlob2(result, x, maxHeight - 8, z);
break;
default:
result.setBlock(x, (maxHeight - 8), z, Material.GLOWSTONE);
}
result.setBlock(x, (maxHeight - 8), z, Material.GLOWSTONE);
}
private void setBlob2(ChunkData result, int x, int y, int z) {
result.setBlock(x, y, z, Material.GLOWSTONE);
if (x > 3 && z > 3) {
for (int xx = 0; xx < 3; xx++) {
for (int zz = 0; zz < 3; zz++) {
result.setBlock(x - xx, y - rand.nextInt(2), z - xx, Material.GLOWSTONE);
}
}
}
}
private void setStalactite(ChunkData result, int x, int y, int z) {
for (int i = 0; i < rand.nextInt(10); i++) {
result.setBlock(x, y - i, z, Material.GLOWSTONE);
}
}
private void setBlob1(ChunkData result, int x, int y, int z) {
result.setBlock(x, y, z, Material.GLOWSTONE);
if (x < 14 && z < 14) {
result.setBlock(x + 1, y, z + 1, Material.GLOWSTONE);
result.setBlock(x + 2, y, z + 2, Material.GLOWSTONE);
result.setBlock(x + 1, y, z + 2, Material.GLOWSTONE);
result.setBlock(x + 1, y, z + 2, Material.GLOWSTONE);
}
}
}

View File

@ -0,0 +1,528 @@
/**
*
*/
package world.bentobox.bskyblock;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.block.Biome;
import org.bukkit.entity.EntityType;
import org.junit.Before;
import org.junit.Test;
/**
* @author tastybento
*
*/
public class SettingsTest {
Settings s;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
s = new Settings();
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setFriendlyName(java.lang.String)}.
*/
@Test
public void testSetFriendlyName() {
s.setFriendlyName("name");
assertEquals("name", s.getFriendlyName());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setWorldName(java.lang.String)}.
*/
@Test
public void testSetWorldName() {
s.setWorldName("name");
assertEquals("name", s.getWorldName());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setDifficulty(org.bukkit.Difficulty)}.
*/
@Test
public void testSetDifficulty() {
s.setDifficulty(Difficulty.PEACEFUL);
assertEquals(Difficulty.PEACEFUL, s.getDifficulty());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setIslandDistance(int)}.
*/
@Test
public void testSetIslandDistance() {
s.setIslandDistance(123);
assertEquals(123, s.getIslandDistance());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setIslandProtectionRange(int)}.
*/
@Test
public void testSetIslandProtectionRange() {
s.setIslandProtectionRange(123);
assertEquals(123, s.getIslandProtectionRange());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setIslandStartX(int)}.
*/
@Test
public void testSetIslandStartX() {
s.setIslandStartX(123);
assertEquals(123, s.getIslandStartX());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setIslandStartZ(int)}.
*/
@Test
public void testSetIslandStartZ() {
s.setIslandStartZ(123);
assertEquals(123, s.getIslandStartZ());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setIslandXOffset(int)}.
*/
@Test
public void testSetIslandXOffset() {
s.setIslandXOffset(123);
assertEquals(123, s.getIslandXOffset());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setIslandZOffset(int)}.
*/
@Test
public void testSetIslandZOffset() {
s.setIslandZOffset(123);
assertEquals(123, s.getIslandZOffset());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setIslandHeight(int)}.
*/
@Test
public void testSetIslandHeight() {
s.setIslandHeight(123);
assertEquals(123, s.getIslandHeight());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setUseOwnGenerator(boolean)}.
*/
@Test
public void testSetUseOwnGenerator() {
s.setUseOwnGenerator(true);
assertTrue(s.isUseOwnGenerator());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setSeaHeight(int)}.
*/
@Test
public void testSetSeaHeight() {
s.setSeaHeight(123);
assertEquals(123, s.getSeaHeight());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setMaxIslands(int)}.
*/
@Test
public void testSetMaxIslands() {
s.setMaxIslands(123);
assertEquals(123, s.getMaxIslands());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setDefaultGameMode(org.bukkit.GameMode)}.
*/
@Test
public void testSetDefaultGameMode() {
s.setDefaultGameMode(GameMode.CREATIVE);
assertEquals(GameMode.CREATIVE, s.getDefaultGameMode());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setNetherGenerate(boolean)}.
*/
@Test
public void testSetNetherGenerate() {
s.setNetherGenerate(true);
assertTrue(s.isNetherGenerate());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setNetherIslands(boolean)}.
*/
@Test
public void testSetNetherIslands() {
s.setNetherIslands(true);
assertTrue(s.isNetherIslands());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setNetherTrees(boolean)}.
*/
@Test
public void testSetNetherTrees() {
s.setNetherTrees(true);
assertTrue(s.isNetherTrees());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setNetherRoof(boolean)}.
*/
@Test
public void testSetNetherRoof() {
s.setNetherRoof(true);
assertTrue(s.isNetherRoof());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setNetherSpawnRadius(int)}.
*/
@Test
public void testSetNetherSpawnRadius() {
s.setNetherSpawnRadius(123);
assertEquals(123, s.getNetherSpawnRadius());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setEndGenerate(boolean)}.
*/
@Test
public void testSetEndGenerate() {
s.setEndGenerate(true);
assertTrue(s.isEndGenerate());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setEndIslands(boolean)}.
*/
@Test
public void testSetEndIslands() {
s.setEndIslands(true);
assertTrue(s.isEndIslands());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setDragonSpawn(boolean)}.
*/
@Test
public void testSetDragonSpawn() {
s.setDragonSpawn(true);
assertTrue(s.isDragonSpawn());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setRemoveMobsWhitelist(java.util.Set)}.
*/
@Test
public void testSetRemoveMobsWhitelist() {
Set<EntityType> wl = Collections.emptySet();
s.setRemoveMobsWhitelist(wl);
assertEquals(wl, s.getRemoveMobsWhitelist());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setWorldFlags(java.util.Map)}.
*/
@Test
public void testSetWorldFlags() {
Map<String, Boolean> worldFlags = Collections.emptyMap();
s.setWorldFlags(worldFlags);
assertEquals(worldFlags, s.getWorldFlags());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setVisibleSettings(java.util.List)}.
*/
@Test
public void testSetVisibleSettings() {
List<String> visibleSettings = Collections.emptyList();
s.setVisibleSettings(visibleSettings);
assertEquals(visibleSettings, s.getVisibleSettings());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setVisitorBannedCommands(java.util.List)}.
*/
@Test
public void testSetVisitorBannedCommands() {
List<String> visitorBannedCommands = Collections.emptyList();
s.setVisitorBannedCommands(visitorBannedCommands);
assertEquals(visitorBannedCommands, s.getVisitorBannedCommands());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setMaxTeamSize(int)}.
*/
@Test
public void testSetMaxTeamSize() {
s.setMaxTeamSize(123);
assertEquals(123, s.getMaxTeamSize());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setMaxHomes(int)}.
*/
@Test
public void testSetMaxHomes() {
s.setMaxHomes(123);
assertEquals(123, s.getMaxHomes());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setResetLimit(int)}.
*/
@Test
public void testSetResetLimit() {
s.setResetLimit(123);
assertEquals(123, s.getResetLimit());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setLeaversLoseReset(boolean)}.
*/
@Test
public void testSetLeaversLoseReset() {
s.setLeaversLoseReset(true);
assertTrue(s.isLeaversLoseReset());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setKickedKeepInventory(boolean)}.
*/
@Test
public void testSetKickedKeepInventory() {
s.setKickedKeepInventory(true);
assertTrue(s.isKickedKeepInventory());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setOnJoinResetMoney(boolean)}.
*/
@Test
public void testSetOnJoinResetMoney() {
s.setOnJoinResetMoney(true);
assertTrue(s.isOnJoinResetMoney());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setOnJoinResetInventory(boolean)}.
*/
@Test
public void testSetOnJoinResetInventory() {
s.setOnJoinResetInventory(true);
assertTrue(s.isOnJoinResetInventory());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setOnJoinResetEnderChest(boolean)}.
*/
@Test
public void testSetOnJoinResetEnderChest() {
s.setOnJoinResetEnderChest(true);
assertTrue(s.isOnJoinResetEnderChest());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setOnLeaveResetMoney(boolean)}.
*/
@Test
public void testSetOnLeaveResetMoney() {
s.setOnLeaveResetMoney(true);
assertTrue(s.isOnLeaveResetMoney());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setOnLeaveResetInventory(boolean)}.
*/
@Test
public void testSetOnLeaveResetInventory() {
s.setOnLeaveResetInventory(true);
assertTrue(s.isOnLeaveResetInventory());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setOnLeaveResetEnderChest(boolean)}.
*/
@Test
public void testSetOnLeaveResetEnderChest() {
s.setOnLeaveResetEnderChest(true);
assertTrue(s.isOnLeaveResetEnderChest());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setDeathsCounted(boolean)}.
*/
@Test
public void testSetDeathsCounted() {
s.setDeathsCounted(true);
assertTrue(s.isDeathsCounted());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setDeathsMax(int)}.
*/
@Test
public void testSetDeathsMax() {
s.setDeathsMax(123);
assertEquals(123, s.getDeathsMax());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setDeathsSumTeam(boolean)}.
*/
@Test
public void testSetDeathsSumTeam() {
s.setDeathsSumTeam(true);
assertTrue(s.isDeathsSumTeam());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setTeamJoinDeathReset(boolean)}.
*/
@Test
public void testSetTeamJoinDeathReset() {
s.setTeamJoinDeathReset(true);
assertTrue(s.isTeamJoinDeathReset());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setGeoLimitSettings(java.util.List)}.
*/
@Test
public void testSetGeoLimitSettings() {
List<String> geoLimitSettings = Collections.emptyList();
s.setGeoLimitSettings(geoLimitSettings);
assertEquals(geoLimitSettings, s.getGeoLimitSettings());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setIvSettings(java.util.List)}.
*/
@Test
public void testSetIvSettings() {
List<String> ivSettings = Collections.emptyList();
s.setIvSettings(ivSettings);
assertEquals(ivSettings, s.getIvSettings());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setAllowSetHomeInNether(boolean)}.
*/
@Test
public void testSetAllowSetHomeInNether() {
s.setAllowSetHomeInNether(true);
assertTrue(s.isAllowSetHomeInNether());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setAllowSetHomeInTheEnd(boolean)}.
*/
@Test
public void testSetAllowSetHomeInTheEnd() {
s.setAllowSetHomeInTheEnd(true);
assertTrue(s.isAllowSetHomeInTheEnd());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setRequireConfirmationToSetHomeInNether(boolean)}.
*/
@Test
public void testSetRequireConfirmationToSetHomeInNether() {
s.setRequireConfirmationToSetHomeInNether(true);
assertTrue(s.isRequireConfirmationToSetHomeInNether());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setRequireConfirmationToSetHomeInTheEnd(boolean)}.
*/
@Test
public void testSetRequireConfirmationToSetHomeInTheEnd() {
s.setRequireConfirmationToSetHomeInTheEnd(true);
assertTrue(s.isRequireConfirmationToSetHomeInTheEnd());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setResetEpoch(long)}.
*/
@Test
public void testSetResetEpoch() {
s.setResetEpoch(123);
assertEquals(123, s.getResetEpoch());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#getPermissionPrefix()}.
*/
@Test
public void testGetPermissionPrefix() {
assertEquals("bskyblock", s.getPermissionPrefix());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#isWaterUnsafe()}.
*/
@Test
public void testIsWaterUnsafe() {
assertFalse(s.isWaterUnsafe());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setDefaultBiome(org.bukkit.block.Biome)}.
*/
@Test
public void testSetDefaultBiome() {
s.setDefaultBiome(Biome.BADLANDS);
assertEquals(Biome.BADLANDS, s.getDefaultBiome());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#setBanLimit(int)}.
*/
@Test
public void testSetBanLimit() {
s.setBanLimit(123);
assertEquals(123, s.getBanLimit());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#getIslandCommand()}.
*/
@Test
public void testGetIslandCommand() {
s.setIslandCommand("island");
assertEquals("island", s.getIslandCommand());
}
/**
* Test method for {@link world.bentobox.bskyblock.Settings#getAdminCommand()}.
*/
@Test
public void testGetAdminCommand() {
s.setAdminCommand("admin");
assertEquals("admin", s.getAdminCommand());
}
}

View File

@ -0,0 +1,40 @@
package world.bentobox.bskyblock.commands;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Collections;
import org.junit.Test;
import org.mockito.Mockito;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.addons.AddonDescription;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
/**
* @author tastybento
*
*/
public class IslandAboutCommandTest {
/**
* Test method for {@link world.bentobox.bskyblock.commands.IslandAboutCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfString() {
CompositeCommand ic= mock(CompositeCommand.class);
Addon addon = mock(Addon.class);
AddonDescription desc = new AddonDescription.Builder("","BSkyBlock","1.2.3").build();
when(addon.getDescription()).thenReturn(desc);
when(ic.getAddon()).thenReturn(addon);
IslandAboutCommand c = new IslandAboutCommand(ic);
User user = mock(User.class);
c.execute(user, "", Collections.emptyList());
// Verify
Mockito.verify(user).sendRawMessage(Mockito.eq("Copyright (c) 2017 - 2019 tastybento, Poslovitch"));
Mockito.verify(user).sendRawMessage(Mockito.eq("About BSkyBlock 1.2.3:"));
}
}

View File

@ -0,0 +1,184 @@
package world.bentobox.bskyblock.generators;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.bukkit.generator.ChunkGenerator.ChunkData;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
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.bskyblock.BSkyBlock;
import world.bentobox.bskyblock.Settings;
/**
* @author tastybento
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class})
public class ChunkGeneratorWorldTest {
@Mock
private BSkyBlock addon;
private ChunkGeneratorWorld cg;
@Mock
private World world;
private final Random random = new Random();
@Mock
private BiomeGrid biomeGrid;
@Mock
private Settings settings;
@Mock
private ChunkData data;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// Bukkit
PowerMockito.mockStatic(Bukkit.class);
Server server = mock(Server.class);
when(server.createChunkData(Mockito.any())).thenReturn(data);
when(Bukkit.getServer()).thenReturn(server);
// Instance
cg = new ChunkGeneratorWorld(addon);
// World
when(world.getEnvironment()).thenReturn(World.Environment.NORMAL);
// Settings
when(addon.getSettings()).thenReturn(settings);
when(settings.getSeaHeight()).thenReturn(0);
when(settings.isNetherRoof()).thenReturn(true);
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
/**
* Test method for {@link world.bentobox.bskyblock.generators.ChunkGeneratorWorld#generateChunkData(org.bukkit.World, java.util.Random, int, int, org.bukkit.generator.ChunkGenerator.BiomeGrid)}.
*/
@Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridOverworldVoid() {
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd);
// Verifications
// Default biome
Mockito.verify(settings).getDefaultBiome();
Mockito.verify(biomeGrid, Mockito.times(16 * 16)).setBiome(Mockito.anyInt(), Mockito.anyInt(), Mockito.any());
// Sea height
Mockito.verify(settings).getSeaHeight();
// Void
Mockito.verify(cd, Mockito.never()).setBlock(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt(), Mockito.any(Material.class));
}
/**
* Test method for {@link world.bentobox.bskyblock.generators.ChunkGeneratorWorld#generateChunkData(org.bukkit.World, java.util.Random, int, int, org.bukkit.generator.ChunkGenerator.BiomeGrid)}.
*/
@Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridOverworldSea() {
// Set sea height
when(settings.getSeaHeight()).thenReturn(10);
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd);
// Verifications
// Default biome
Mockito.verify(settings).getDefaultBiome();
Mockito.verify(biomeGrid, Mockito.times(16 * 16)).setBiome(Mockito.anyInt(), Mockito.anyInt(), Mockito.any());
// Sea height
Mockito.verify(settings).getSeaHeight();
// Water. Blocks = 16 x 16 x 11 because block 0
Mockito.verify(cd, Mockito.times(2816)).setBlock(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt(), Mockito.eq(Material.WATER));
}
/**
* Test method for {@link world.bentobox.bskyblock.generators.ChunkGeneratorWorld#generateChunkData(org.bukkit.World, java.util.Random, int, int, org.bukkit.generator.ChunkGenerator.BiomeGrid)}.
*/
@Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridEnd() {
when(world.getEnvironment()).thenReturn(World.Environment.THE_END);
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd);
// Verifications
// Default biome
Mockito.verify(settings, Mockito.never()).getDefaultBiome();
// Never set biome in end
Mockito.verify(biomeGrid, Mockito.never()).setBiome(Mockito.anyInt(), Mockito.anyInt(), Mockito.any());
// Sea height
Mockito.verify(settings, Mockito.never()).getSeaHeight();
// Void
Mockito.verify(cd, Mockito.never()).setBlock(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt(), Mockito.any(Material.class));
}
/**
* Test method for {@link world.bentobox.bskyblock.generators.ChunkGeneratorWorld#generateChunkData(org.bukkit.World, java.util.Random, int, int, org.bukkit.generator.ChunkGenerator.BiomeGrid)}.
*/
@Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridNetherWithRoof() {
when(world.getEnvironment()).thenReturn(World.Environment.NETHER);
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd);
// Verifications
// Nether roof check
Mockito.verify(settings).isNetherRoof();
// Never set biome in nether
Mockito.verify(biomeGrid, Mockito.never()).setBiome(Mockito.anyInt(), Mockito.anyInt(), Mockito.any());
// Nether roof - at least bedrock layer
Mockito.verify(cd, Mockito.atLeast(16 * 16)).setBlock(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt(), Mockito.eq(Material.BEDROCK));
}
/**
* Test method for {@link world.bentobox.bskyblock.generators.ChunkGeneratorWorld#generateChunkData(org.bukkit.World, java.util.Random, int, int, org.bukkit.generator.ChunkGenerator.BiomeGrid)}.
*/
@Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridNetherNoRoof() {
when(settings.isNetherRoof()).thenReturn(false);
when(world.getEnvironment()).thenReturn(World.Environment.NETHER);
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd);
// Verifications
// Nether roof check
Mockito.verify(settings).isNetherRoof();
// Never set biome in nether
Mockito.verify(biomeGrid, Mockito.never()).setBiome(Mockito.anyInt(), Mockito.anyInt(), Mockito.any());
// Nether roof - at least bedrock layer
Mockito.verify(cd, Mockito.never()).setBlock(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt(), Mockito.any(Material.class));
}
/**
* Test method for {@link world.bentobox.bskyblock.generators.ChunkGeneratorWorld#canSpawn(org.bukkit.World, int, int)}.
*/
@Test
public void testCanSpawnWorldIntInt() {
assertTrue(cg.canSpawn(mock(World.class), 0, 1));
}
/**
* Test method for {@link world.bentobox.bskyblock.generators.ChunkGeneratorWorld#getDefaultPopulators(org.bukkit.World)}.
*/
@Test
public void testGetDefaultPopulatorsWorld() {
assertTrue(cg.getDefaultPopulators(mock(World.class)).isEmpty());
}
}