2020-08-23 02:55:38 +02:00
|
|
|
package world.bentobox.greenhouses.managers;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.mockito.ArgumentMatchers.anyInt;
|
|
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
2021-01-10 20:57:02 +01:00
|
|
|
import org.bukkit.Location;
|
2020-08-23 02:55:38 +02:00
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.BlockFace;
|
|
|
|
import org.bukkit.util.BoundingBox;
|
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
import org.mockito.Mock;
|
|
|
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
|
|
import org.powermock.modules.junit4.PowerMockRunner;
|
|
|
|
|
|
|
|
import world.bentobox.bentobox.BentoBox;
|
|
|
|
import world.bentobox.greenhouses.data.Greenhouse;
|
2021-09-18 19:12:47 +02:00
|
|
|
import world.bentobox.greenhouses.managers.EcoSystemManager.GrowthBlock;
|
2020-08-23 02:55:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author tastybento
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
@RunWith(PowerMockRunner.class)
|
|
|
|
@PrepareForTest({Bukkit.class, BentoBox.class})
|
|
|
|
public class EcoSystemManagerTest {
|
|
|
|
|
|
|
|
private Greenhouse gh;
|
|
|
|
@Mock
|
|
|
|
private World world;
|
|
|
|
@Mock
|
|
|
|
private Block block;
|
|
|
|
@Mock
|
|
|
|
private Block air;
|
|
|
|
@Mock
|
|
|
|
private Block liquid;
|
|
|
|
@Mock
|
|
|
|
private Block plant;
|
|
|
|
|
|
|
|
// CUT
|
|
|
|
private EcoSystemManager eco;
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
@Before
|
2021-08-01 08:10:07 +02:00
|
|
|
public void setUp() {
|
2021-01-10 20:57:02 +01:00
|
|
|
gh = new Greenhouse();
|
2020-08-23 02:55:38 +02:00
|
|
|
// 4x4x4 greenhouse
|
2021-01-10 20:57:02 +01:00
|
|
|
BoundingBox bb = BoundingBox.of(new Vector(0,0,0), new Vector(6,5,6));
|
|
|
|
gh.setBoundingBox(bb);
|
2020-08-23 02:55:38 +02:00
|
|
|
// World
|
2021-01-10 20:57:02 +01:00
|
|
|
Location l = new Location(world, 0,0,0);
|
|
|
|
gh.setLocation(l);
|
2020-08-23 02:55:38 +02:00
|
|
|
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(block);
|
2020-08-26 03:04:53 +02:00
|
|
|
// Blocks
|
2020-08-23 02:55:38 +02:00
|
|
|
// Air
|
2020-08-26 03:04:53 +02:00
|
|
|
// Liquid false
|
2020-08-23 02:55:38 +02:00
|
|
|
when(air.isEmpty()).thenReturn(true);
|
|
|
|
when(air.isPassable()).thenReturn(true);
|
|
|
|
when(air.getRelative(eq(BlockFace.UP))).thenReturn(air);
|
|
|
|
// Plant
|
2020-08-26 03:04:53 +02:00
|
|
|
// Empty false
|
|
|
|
// Liquid false
|
2020-08-23 02:55:38 +02:00
|
|
|
when(plant.isPassable()).thenReturn(true);
|
|
|
|
when(plant.getRelative(eq(BlockFace.UP))).thenReturn(air);
|
|
|
|
// Liquid
|
2020-08-26 03:04:53 +02:00
|
|
|
// Empty false
|
2020-08-23 02:55:38 +02:00
|
|
|
when(liquid.isLiquid()).thenReturn(true);
|
2020-08-26 03:04:53 +02:00
|
|
|
when(liquid.isPassable()).thenReturn(true);
|
2021-01-10 20:57:02 +01:00
|
|
|
when(liquid.getRelative(eq(BlockFace.UP))).thenReturn(air);
|
2020-08-23 02:55:38 +02:00
|
|
|
// Default for block
|
2020-08-26 03:04:53 +02:00
|
|
|
// Empty false
|
|
|
|
// Passable false
|
|
|
|
// Liquid false
|
2020-08-23 02:55:38 +02:00
|
|
|
when(block.getRelative(eq(BlockFace.UP))).thenReturn(air);
|
2021-01-10 20:57:02 +01:00
|
|
|
|
2020-08-23 02:55:38 +02:00
|
|
|
eco = new EcoSystemManager(null, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-01 08:10:07 +02:00
|
|
|
* Test method for {@link world.bentobox.greenhouses.managers.EcoSystemManager#getAvailableBlocks(Greenhouse, boolean)}.
|
2020-08-23 02:55:38 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testGetAvailableBlocksAirAboveBlock() {
|
2021-09-18 19:12:47 +02:00
|
|
|
List<GrowthBlock> result = eco.getAvailableBlocks(gh, false);
|
2020-08-23 02:55:38 +02:00
|
|
|
assertEquals(16, result.size());
|
2021-09-18 19:12:47 +02:00
|
|
|
assertEquals(air, result.get(0).block());
|
2020-08-23 02:55:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-01 08:10:07 +02:00
|
|
|
* Test method for {@link world.bentobox.greenhouses.managers.EcoSystemManager#getAvailableBlocks(Greenhouse, boolean)}.
|
2020-08-23 02:55:38 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testGetAvailableBlocksPlantAboveBlock() {
|
|
|
|
when(block.getRelative(eq(BlockFace.UP))).thenReturn(plant);
|
2021-09-18 19:12:47 +02:00
|
|
|
List<GrowthBlock> result = eco.getAvailableBlocks(gh, false);
|
2020-08-23 02:55:38 +02:00
|
|
|
assertEquals(16, result.size());
|
2021-09-18 19:12:47 +02:00
|
|
|
assertEquals(plant, result.get(0).block());
|
2020-08-23 02:55:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-01 08:10:07 +02:00
|
|
|
* Test method for {@link world.bentobox.greenhouses.managers.EcoSystemManager#getAvailableBlocks(Greenhouse, boolean)}.
|
2020-08-23 02:55:38 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testGetAvailableBlocksAllAir() {
|
|
|
|
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(air);
|
2021-09-18 19:12:47 +02:00
|
|
|
List<GrowthBlock> result = eco.getAvailableBlocks(gh, false);
|
2020-08-23 02:55:38 +02:00
|
|
|
assertEquals(0, result.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-01 08:10:07 +02:00
|
|
|
* Test method for {@link world.bentobox.greenhouses.managers.EcoSystemManager#getAvailableBlocks(Greenhouse, boolean)}.
|
2020-08-23 02:55:38 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testGetAvailableBlocksAllLiquid() {
|
|
|
|
when(liquid.getRelative(eq(BlockFace.UP))).thenReturn(liquid);
|
|
|
|
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(liquid);
|
2021-09-18 19:12:47 +02:00
|
|
|
List<GrowthBlock> result = eco.getAvailableBlocks(gh, false);
|
2020-08-23 02:55:38 +02:00
|
|
|
assertEquals(0, result.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-01 08:10:07 +02:00
|
|
|
* Test method for {@link world.bentobox.greenhouses.managers.EcoSystemManager#getAvailableBlocks(Greenhouse, boolean)}.
|
2020-08-23 02:55:38 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testGetAvailableBlocksAllPlant() {
|
|
|
|
when(plant.getRelative(eq(BlockFace.UP))).thenReturn(plant);
|
|
|
|
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(plant);
|
2021-09-18 19:12:47 +02:00
|
|
|
List<GrowthBlock> result = eco.getAvailableBlocks(gh, false);
|
2020-08-26 03:04:53 +02:00
|
|
|
assertEquals(16, result.size());
|
2021-09-18 19:12:47 +02:00
|
|
|
assertEquals(plant, result.get(0).block());
|
2020-08-23 02:55:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-01 08:10:07 +02:00
|
|
|
* Test method for {@link world.bentobox.greenhouses.managers.EcoSystemManager#getAvailableBlocks(Greenhouse, boolean)}.
|
2020-08-23 02:55:38 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testGetAvailableBlocksLiquidAboveBlockIgnoreLiquids() {
|
|
|
|
when(block.getRelative(eq(BlockFace.UP))).thenReturn(liquid);
|
2021-09-18 19:12:47 +02:00
|
|
|
List<GrowthBlock> result = eco.getAvailableBlocks(gh, true);
|
2020-08-23 02:55:38 +02:00
|
|
|
assertEquals(16, result.size());
|
2021-09-18 19:12:47 +02:00
|
|
|
assertEquals(liquid, result.get(0).block());
|
2020-08-23 02:55:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-01 08:10:07 +02:00
|
|
|
* Test method for {@link world.bentobox.greenhouses.managers.EcoSystemManager#getAvailableBlocks(Greenhouse, boolean)}.
|
2020-08-23 02:55:38 +02:00
|
|
|
*/
|
|
|
|
@Test
|
2020-08-26 03:04:53 +02:00
|
|
|
public void testGetAvailableBlocksAirAboveLiquidNotIgnoreLiquids() {
|
|
|
|
when(world.getBlockAt(anyInt(), eq(3), anyInt())).thenReturn(air);
|
|
|
|
when(world.getBlockAt(anyInt(), eq(2), anyInt())).thenReturn(liquid);
|
|
|
|
when(world.getBlockAt(anyInt(), eq(1), anyInt())).thenReturn(block);
|
|
|
|
when(liquid.getRelative(eq(BlockFace.UP))).thenReturn(air);
|
2020-08-23 02:55:38 +02:00
|
|
|
when(block.getRelative(eq(BlockFace.UP))).thenReturn(liquid);
|
2020-08-26 03:04:53 +02:00
|
|
|
|
2021-09-18 19:12:47 +02:00
|
|
|
List<GrowthBlock> result = eco.getAvailableBlocks(gh, false);
|
2020-08-26 03:04:53 +02:00
|
|
|
assertEquals(16, result.size());
|
2021-09-18 19:12:47 +02:00
|
|
|
for (GrowthBlock value : result) {
|
|
|
|
assertEquals(air, value.block());
|
2020-08-26 03:04:53 +02:00
|
|
|
}
|
|
|
|
}
|
2021-01-10 20:57:02 +01:00
|
|
|
|
2020-08-26 03:04:53 +02:00
|
|
|
/**
|
2021-08-01 08:10:07 +02:00
|
|
|
* Test method for {@link world.bentobox.greenhouses.managers.EcoSystemManager#getAvailableBlocks(Greenhouse, boolean)}.
|
2020-08-26 03:04:53 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testGetAvailableBlocksAirAboveLiquidIgnoreLiquids() {
|
|
|
|
when(world.getBlockAt(anyInt(), eq(3), anyInt())).thenReturn(air);
|
|
|
|
when(world.getBlockAt(anyInt(), eq(2), anyInt())).thenReturn(liquid);
|
|
|
|
when(world.getBlockAt(anyInt(), eq(1), anyInt())).thenReturn(block);
|
|
|
|
when(liquid.getRelative(eq(BlockFace.UP))).thenReturn(air);
|
|
|
|
when(block.getRelative(eq(BlockFace.UP))).thenReturn(liquid);
|
|
|
|
|
2021-09-18 19:12:47 +02:00
|
|
|
List<GrowthBlock> result = eco.getAvailableBlocks(gh, true);
|
2020-08-26 03:04:53 +02:00
|
|
|
assertEquals(16, result.size());
|
2021-09-18 19:12:47 +02:00
|
|
|
for (GrowthBlock value : result) {
|
|
|
|
assertEquals(liquid, value.block());
|
2020-08-26 03:04:53 +02:00
|
|
|
}
|
2020-08-23 02:55:38 +02:00
|
|
|
}
|
|
|
|
}
|