обновлены тесты Location's
This commit is contained in:
@@ -35,15 +35,14 @@ subprojects {
|
||||
exclude group: 'commons-logging'
|
||||
}
|
||||
|
||||
/* Components */
|
||||
/* Lombok */
|
||||
compile (group: 'org.projectlombok', name: 'lombok', version: '1.16.16')
|
||||
|
||||
/* JUnit */
|
||||
/* Testing */
|
||||
testCompile (group: 'junit', name: 'junit', version: '4.12')
|
||||
/* Simple log */
|
||||
testCompile (group: 'org.slf4j', name: 'slf4j-simple', version: slf4j_version)
|
||||
/* Mockito */
|
||||
testCompile (group: 'org.mockito', name: 'mockito-core', version: '1.9.5')
|
||||
testCompile (group: 'org.springframework', name: 'spring-test', version: spring_version)
|
||||
}
|
||||
|
||||
task copyDep(type: Copy) {
|
||||
|
||||
34
core/src/test/java/mc/core/SpringConfig.java
Normal file
34
core/src/test/java/mc/core/SpringConfig.java
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user