Archived
0

обновлены тесты Location's

This commit is contained in:
2018-09-08 02:11:54 +03:00
parent bd37bc8615
commit 1a2ebcfa0a
4 changed files with 59 additions and 22 deletions

View File

@@ -0,0 +1,34 @@
package mc.core;
import mc.core.world.World;
import mc.core.world.chunk.Chunk;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@Configuration
public class SpringConfig {
@Bean()
public World simpleMockWorld() {
return mock(World.class);
}
@Bean
public World chunkedMockWorld() {
World world = mock(World.class);
when(world.getChunk(anyInt(), anyInt())).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
Chunk chunk = mock(Chunk.class);
when(chunk.getX()).thenReturn((int) args[0]);
when(chunk.getZ()).thenReturn((int) args[1]);
return chunk;
});
return world;
}
}

View File

@@ -2,18 +2,27 @@ package mc.core;
import mc.core.world.World;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class TestEntityLocation {
@Autowired
@Qualifier("simpleMockWorld")
private World mockWorld;
@Test
public void cloneTest() {
World dummyWorld = mock(World.class);
EntityLocation firstLocation = new EntityLocation(10, 20, 30, 40, 50, dummyWorld);
assertSame("Lost world reference before cloning", dummyWorld, firstLocation.getWorld());
EntityLocation firstLocation = new EntityLocation(10, 20, 30, 40, 50, mockWorld);
assertSame("Lost world reference before cloning", mockWorld, firstLocation.getWorld());
EntityLocation locationClone = firstLocation.clone();
assertEquals("X mismatch", firstLocation.getX(), locationClone.getX(), 0);

View File

@@ -4,27 +4,22 @@ import mc.core.world.World;
import mc.core.world.chunk.Chunk;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class TestLocation {
@Autowired
@Qualifier("chunkedMockWorld")
private World world;
@Before
public void prepareWorld() {
this.world = mock(World.class);
when(world.getChunk(anyInt(), anyInt())).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
Chunk chunk = mock(Chunk.class);
when(chunk.getX()).thenReturn((int) args[0]);
when(chunk.getZ()).thenReturn((int) args[1]);
return chunk;
});
}
@Test
public void testGetBlockXZ() {
Location location;