Hello, Mockito!
This commit is contained in:
@@ -12,7 +12,4 @@ dependencies {
|
||||
compile (group: 'com.google.guava', name: 'guava', version: '24.1-jre')
|
||||
/* Named Binary Tags */
|
||||
compile (group: 'com.flowpowered', name: 'flow-nbt', version: '1.0.0')
|
||||
|
||||
/* Simple log */
|
||||
testCompile (group: 'org.slf4j', name: 'slf4j-simple', version: slf4j_version)
|
||||
}
|
||||
|
||||
@@ -1,40 +1,16 @@
|
||||
package mc.core;
|
||||
|
||||
import mc.core.world.World;
|
||||
import mc.core.world.WorldType;
|
||||
import mc.core.world.chunk.Chunk;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class TestEntityLocation {
|
||||
@Test
|
||||
public void cloneTest() {
|
||||
World dummyWorld = new World() {
|
||||
@Override
|
||||
public WorldType getWorldType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityLocation getSpawn() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpawn(EntityLocation location) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk getChunk(int x, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChunk(int x, int z, Chunk chunk) {
|
||||
|
||||
}
|
||||
};
|
||||
World dummyWorld = mock(World.class);
|
||||
|
||||
EntityLocation firstLocation = new EntityLocation(10, 20, 30, 40, 50, dummyWorld);
|
||||
Assert.assertSame("Lost world reference before cloning", dummyWorld, firstLocation.getWorld());
|
||||
|
||||
@@ -1,80 +1,33 @@
|
||||
package mc.core;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import mc.core.world.Biome;
|
||||
import mc.core.world.World;
|
||||
import mc.core.world.WorldType;
|
||||
import mc.core.world.chunk.Chunk;
|
||||
import mc.core.world.chunk.ChunkSection;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class TestLocation {
|
||||
private class DummyWorld implements World {
|
||||
@RequiredArgsConstructor
|
||||
private class DummyChunk implements Chunk {
|
||||
@Getter
|
||||
private final int x, z;
|
||||
private World world;
|
||||
|
||||
@Override
|
||||
public ChunkSection getChunkSection(int height) {
|
||||
return null;
|
||||
}
|
||||
@Before
|
||||
public void prepareWorld() {
|
||||
this.world = mock(World.class);
|
||||
when(world.getChunk(anyInt(), anyInt())).thenAnswer(invocation -> {
|
||||
Object[] args = invocation.getArguments();
|
||||
|
||||
@Override
|
||||
public void setChunkSection(int height, ChunkSection chunkSection) {
|
||||
}
|
||||
Chunk chunk = mock(Chunk.class);
|
||||
when(chunk.getX()).thenReturn((int) args[0]);
|
||||
when(chunk.getZ()).thenReturn((int) args[1]);
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int localX, int localZ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(int localX, int localZ, Biome biome) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWorld(World world) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldType getWorldType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityLocation getSpawn() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpawn(EntityLocation location) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk getChunk(int x, int z) {
|
||||
return new DummyChunk(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChunk(int x, int z, Chunk chunkSection) {
|
||||
|
||||
}
|
||||
return chunk;
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBlockXZ() {
|
||||
World world = new DummyWorld();
|
||||
Location location;
|
||||
|
||||
location = new Location(0d, 0, 0d, world);
|
||||
@@ -120,7 +73,6 @@ public class TestLocation {
|
||||
|
||||
@Test
|
||||
public void testGetChunk() {
|
||||
World world = new DummyWorld();
|
||||
Location location;
|
||||
Chunk chunk;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user