параметеризирован ChunkDataPacketTest
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package mc.core.network.proto_1_12_2.packets;
|
package mc.core.network.proto_1_12_2.packets;
|
||||||
|
|
||||||
import com.flowpowered.nbt.*;
|
import com.flowpowered.nbt.*;
|
||||||
|
import javafx.util.Pair;
|
||||||
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
|
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
|
||||||
import mc.core.network.proto_1_12_2.packets.DumbChunkData.DumbChunkSection;
|
import mc.core.network.proto_1_12_2.packets.DumbChunkData.DumbChunkSection;
|
||||||
import mc.core.world.Biome;
|
import mc.core.world.Biome;
|
||||||
@@ -9,67 +10,28 @@ import mc.core.world.chunk.Chunk;
|
|||||||
import mc.core.world.chunk.ChunkSection;
|
import mc.core.world.chunk.ChunkSection;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
class ChunkDataPacketTest {
|
class ChunkDataPacketTest {
|
||||||
private static DumbChunkData expectedDumbChunkData;
|
private static List<Pair<DumbChunkData, DumbChunkData>> listOfParams;
|
||||||
private static DumbChunkData actualDumbChunkData;
|
|
||||||
|
|
||||||
private static void setupExpectedData() throws IOException {
|
private static DumbChunkData createExpectedData() throws IOException {
|
||||||
InputStream inputStream = ChunkDataPacketTest.class.getResourceAsStream("ChunkDataPacket.bin");
|
InputStream inputStream = ChunkDataPacketTest.class.getResourceAsStream("ChunkDataPacket.bin");
|
||||||
assertNotNull(inputStream);
|
assertNotNull(inputStream);
|
||||||
expectedDumbChunkData = DumbChunkData.ReadFromNetInputStream(IOUtils.toByteArray(inputStream));
|
return DumbChunkData.ReadFromNetInputStream(IOUtils.toByteArray(inputStream));
|
||||||
}
|
|
||||||
|
|
||||||
private static Chunk createMockChunk() {
|
|
||||||
final ChunkSection chunkSection0 = createChunkSection(0);
|
|
||||||
final ChunkSection chunkSection1 = createChunkSection(1);
|
|
||||||
|
|
||||||
final Chunk chunk = mock(Chunk.class);
|
|
||||||
when(chunk.getX()).thenReturn(0);
|
|
||||||
when(chunk.getZ()).thenReturn(0);
|
|
||||||
when(chunk.getBiome(anyInt(), anyInt())).thenReturn(Biome.PLAINS);
|
|
||||||
when(chunk.getChunkSection(0)).thenReturn(chunkSection0);
|
|
||||||
when(chunk.getChunkSection(1)).thenReturn(chunkSection1);
|
|
||||||
|
|
||||||
return chunk;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void verifyMock(Chunk chunk) {
|
|
||||||
verify(chunk, atLeast(1)).getX();
|
|
||||||
verify(chunk, atLeast(1)).getZ();
|
|
||||||
verify(chunk, times(256)).getBiome(anyInt(), anyInt());
|
|
||||||
verify(chunk, atLeast(2)).getChunkSection(anyInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setupActualData() {
|
|
||||||
Chunk chunk = createMockChunk();
|
|
||||||
|
|
||||||
ChunkDataPacket packet = new ChunkDataPacket();
|
|
||||||
packet.setX(chunk.getX());
|
|
||||||
packet.setZ(chunk.getZ());
|
|
||||||
packet.setChunk(chunk);
|
|
||||||
packet.setInitChunk(true);
|
|
||||||
|
|
||||||
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
|
||||||
packet.writeSelf(netStream);
|
|
||||||
|
|
||||||
verifyMock(chunk);
|
|
||||||
|
|
||||||
actualDumbChunkData = DumbChunkData.ReadFromNetInputStream(netStream.toByteArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
static void beforeClassTest() throws IOException {
|
|
||||||
setupExpectedData();
|
|
||||||
setupActualData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Block createChestBlock(BlockType type, int x, int y, int z, int height) {
|
private static Block createChestBlock(BlockType type, int x, int y, int z, int height) {
|
||||||
@@ -153,42 +115,96 @@ class ChunkDataPacketTest {
|
|||||||
return chunkSection;
|
return chunkSection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private static Chunk createMockChunk() {
|
||||||
void testGeneral() {
|
final ChunkSection chunkSection0 = createChunkSection(0);
|
||||||
assertEquals(expectedDumbChunkData.getX(), actualDumbChunkData.getX());
|
final ChunkSection chunkSection1 = createChunkSection(1);
|
||||||
assertEquals(expectedDumbChunkData.getZ(), actualDumbChunkData.getZ());
|
|
||||||
assertEquals(expectedDumbChunkData.isInitChunk(), actualDumbChunkData.isInitChunk());
|
final Chunk chunk = mock(Chunk.class);
|
||||||
assertEquals(expectedDumbChunkData.getBitMask(), actualDumbChunkData.getBitMask());
|
when(chunk.getX()).thenReturn(0);
|
||||||
assertArrayEquals(expectedDumbChunkData.getBiomes(), actualDumbChunkData.getBiomes());
|
when(chunk.getZ()).thenReturn(0);
|
||||||
|
when(chunk.getBiome(anyInt(), anyInt())).thenReturn(Biome.PLAINS);
|
||||||
|
when(chunk.getChunkSection(0)).thenReturn(chunkSection0);
|
||||||
|
when(chunk.getChunkSection(1)).thenReturn(chunkSection1);
|
||||||
|
|
||||||
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private static void verifyMock(Chunk chunk) {
|
||||||
void testNBT() {
|
verify(chunk, atLeast(1)).getX();
|
||||||
assertEquals(expectedDumbChunkData.getNumberNBT(), actualDumbChunkData.getNumberNBT());
|
verify(chunk, atLeast(1)).getZ();
|
||||||
assertEquals(expectedDumbChunkData.getNbt().size(), actualDumbChunkData.getNbt().size());
|
verify(chunk, times(256)).getBiome(anyInt(), anyInt());
|
||||||
|
verify(chunk, atLeast(2)).getChunkSection(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
for (Tag<?> tag : actualDumbChunkData.getNbt()) {
|
private static DumbChunkData createActualData() {
|
||||||
assertTrue(expectedDumbChunkData.getNbt().contains(tag));
|
Chunk chunk = createMockChunk();
|
||||||
|
|
||||||
|
ChunkDataPacket packet = new ChunkDataPacket();
|
||||||
|
packet.setX(chunk.getX());
|
||||||
|
packet.setZ(chunk.getZ());
|
||||||
|
packet.setChunk(chunk);
|
||||||
|
packet.setInitChunk(true);
|
||||||
|
|
||||||
|
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
||||||
|
packet.writeSelf(netStream);
|
||||||
|
|
||||||
|
verifyMock(chunk);
|
||||||
|
|
||||||
|
return DumbChunkData.ReadFromNetInputStream(netStream.toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
static void beforeClassTest() throws IOException {
|
||||||
|
listOfParams = new ArrayList<>();
|
||||||
|
listOfParams.add(new Pair<>(createExpectedData(), createActualData()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Stream<Arguments> streamArguments() {
|
||||||
|
return listOfParams.stream().map(pair -> Arguments.of(pair.getKey(), pair.getValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("testGeneral")
|
||||||
|
@ParameterizedTest(name = "[{index}] => {0}")
|
||||||
|
@MethodSource("streamArguments")
|
||||||
|
void testGeneral(DumbChunkData expected, DumbChunkData actual) {
|
||||||
|
assertEquals(expected.getX(), actual.getX());
|
||||||
|
assertEquals(expected.getZ(), actual.getZ());
|
||||||
|
assertEquals(expected.isInitChunk(), actual.isInitChunk());
|
||||||
|
assertEquals(expected.getBitMask(), actual.getBitMask());
|
||||||
|
assertArrayEquals(expected.getBiomes(), actual.getBiomes());
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("testNBT")
|
||||||
|
@ParameterizedTest(name = "[{index}] => {0}")
|
||||||
|
@MethodSource("streamArguments")
|
||||||
|
void testNBT(DumbChunkData expected, DumbChunkData actual) {
|
||||||
|
assertEquals(expected.getNumberNBT(), actual.getNumberNBT());
|
||||||
|
assertEquals(expected.getNbt().size(), actual.getNbt().size());
|
||||||
|
|
||||||
|
for (Tag<?> tag : actual.getNbt()) {
|
||||||
|
assertTrue(expected.getNbt().contains(tag));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@DisplayName("testData (disabled light test)")
|
||||||
void testData() {
|
@ParameterizedTest(name = "[{index}] => {0}")
|
||||||
assertEquals(expectedDumbChunkData.getData().length, actualDumbChunkData.getData().length);
|
@MethodSource("streamArguments")
|
||||||
|
void testData(DumbChunkData expected, DumbChunkData actual) {
|
||||||
|
assertEquals(expected.getData().length, actual.getData().length);
|
||||||
|
|
||||||
for (int numberSection = 0; numberSection < expectedDumbChunkData.getData().length; numberSection++) {
|
for (int numberSection = 0; numberSection < expected.getData().length; numberSection++) {
|
||||||
final DumbChunkSection expectedDumbChunkSection = expectedDumbChunkData.getData()[numberSection];
|
final DumbChunkSection expectedSection = expected.getData()[numberSection];
|
||||||
final DumbChunkSection actualDumbChunkSection = actualDumbChunkData.getData()[numberSection];
|
final DumbChunkSection actualSection = actual.getData()[numberSection];
|
||||||
|
|
||||||
// Palette
|
// Palette
|
||||||
testPalette(expectedDumbChunkSection, actualDumbChunkSection, numberSection);
|
testPalette(expectedSection, actualSection, numberSection);
|
||||||
|
|
||||||
// Data
|
// Data
|
||||||
testDataBlock(expectedDumbChunkSection, actualDumbChunkSection, numberSection);
|
testDataBlock(expectedSection, actualSection, numberSection);
|
||||||
|
|
||||||
// Block and Sky light
|
// Block and Sky light
|
||||||
// DISABLE //
|
// DISABLE //
|
||||||
//testLight(expectedDumbChunkSection, actualDumbChunkSection, numberSection);
|
//testLight(expectedSection, actualSection, numberSection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,6 +111,14 @@ class DumbChunkData {
|
|||||||
return dumbChunkData;
|
return dumbChunkData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DumbChunkData{" +
|
||||||
|
"x=" + x +
|
||||||
|
", z=" + z +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
@Getter
|
@Getter
|
||||||
static class DumbChunkSection {
|
static class DumbChunkSection {
|
||||||
|
|||||||
Reference in New Issue
Block a user