Skip to content

Commit

Permalink
Fixed RoofTest
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jan 16, 2021
1 parent cc11402 commit ff487a7
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/test/java/world/bentobox/greenhouses/greenhouse/RoofTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.util.Vector;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -35,14 +35,13 @@ public class RoofTest {

private Roof roof;
@Mock
private Block block;
@Mock
private Location location;
@Mock
private World world;
@Mock
private Greenhouses addon;
private Settings s;
@Mock
private AsyncWorldCache cache;

/**
Expand All @@ -57,7 +56,7 @@ public void setUp() throws Exception {

when(world.getMaxHeight()).thenReturn(255);
// Block
when(block.getType()).thenReturn(Material.AIR, Material.AIR, Material.AIR, Material.AIR,
when(cache.getBlockType(any())).thenReturn(Material.AIR, Material.AIR, Material.AIR, Material.AIR,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Expand All @@ -82,26 +81,22 @@ public void setUp() throws Exception {
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.AIR);
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(block);
when(world.getBlockAt(any(Location.class))).thenReturn(block);
when(location.getWorld()).thenReturn(world);
when(location.getBlockX()).thenReturn(10);
when(location.getBlockY()).thenReturn(10);
when(location.getBlockZ()).thenReturn(10);
when(location.getBlock()).thenReturn(block);
when(location.clone()).thenReturn(location);

cache = new AsyncWorldCache(world);
// Test
roof = new Roof(cache, location);
roof.findRoof();
assertTrue(roof.findRoof(new Vector(10,10,10)));
}

@Test
public void testNoGlass() {
when(block.getType()).thenReturn(Material.AIR);
when(cache.getBlockType(anyInt(), anyInt(), anyInt())).thenReturn(Material.AIR);
roof = new Roof(cache, location);
roof.findRoof();
assertFalse(roof.findRoof(new Vector(10,10,10)));
}

/**
Expand Down Expand Up @@ -165,7 +160,7 @@ public void testGetLocation() {
*/
@Test
public void testToString() {
assertTrue(roof.toString().endsWith("minX=-9, maxX=28, minZ=-9, maxZ=29, height=14, roofFound=true]"));
assertEquals("Roof [height=14, roofFound=true, minX=-9, maxX=28, minZ=-9, maxZ=29]", roof.toString());
}

/**
Expand Down

0 comments on commit ff487a7

Please sign in to comment.