Add more net code
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.flaremicro.crossjeeves.net.packet.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -11,7 +13,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import com.flaremicro.crossjeeves.net.NetworkHandler;
|
||||
import com.flaremicro.crossjeeves.net.packet.Packet;
|
||||
import com.flaremicro.crossjeeves.net.packet.Packet5Artifact;
|
||||
import com.flaremicro.crossjeeves.net.packet.Packet4FileData;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class Packet4FileDataTest extends PacketTestBase {
|
||||
@@ -22,36 +24,41 @@ public class Packet4FileDataTest extends PacketTestBase {
|
||||
@Test
|
||||
public void testWrite() throws IOException
|
||||
{
|
||||
Packet5Artifact packet = new Packet5Artifact(1, "file.txt");
|
||||
Packet4FileData packet = new Packet4FileData(1, (short)4, new byte[]{1,2,3,4,5});
|
||||
assertEquals(packet.getFileId(), 1);
|
||||
assertEquals("file.txt", packet.getRelativeFile());
|
||||
assertArrayEquals(new byte[]{1,2,3,4,5}, packet.getFileChunk());
|
||||
packet.sendPacket(output());
|
||||
|
||||
byte[] buffer = new byte[4];
|
||||
|
||||
assertEquals(5, input().readByte());
|
||||
assertEquals(4, input().readByte());
|
||||
assertEquals(1, input().readLong());
|
||||
assertEquals("file.txt", input().readUTF());
|
||||
assertEquals(4, input().readShort());
|
||||
input().readFully(buffer);
|
||||
assertArrayEquals(new byte[]{1,2,3,4}, buffer);
|
||||
assertBufferEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRead() throws IOException
|
||||
{
|
||||
Packet5Artifact packet = new Packet5Artifact();
|
||||
Packet4FileData packet = new Packet4FileData();
|
||||
|
||||
output().writeLong(1);
|
||||
output().writeUTF("file.txt");
|
||||
output().writeShort(4);
|
||||
output().write(new byte[]{1,2,3,4});
|
||||
|
||||
packet.recievePacket(input());
|
||||
|
||||
assertEquals(1, packet.getFileId());
|
||||
assertEquals("file.txt", packet.getRelativeFile());
|
||||
assertArrayEquals(new byte[]{1,2,3,4}, packet.getFileChunk());
|
||||
assertBufferEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcess() throws IOException
|
||||
{
|
||||
Packet5Artifact packet = new Packet5Artifact(1, "file.txt");
|
||||
Packet4FileData packet = new Packet4FileData(1, (short) 4, new byte[]{1,2,3,4});
|
||||
packet.processPacket(handler);
|
||||
Mockito.verify(handler, Mockito.times(1)).handlePacket(packet);
|
||||
}
|
||||
@@ -59,7 +66,7 @@ public class Packet4FileDataTest extends PacketTestBase {
|
||||
@Test
|
||||
public void testTypeCopy()
|
||||
{
|
||||
Packet5Artifact packet = new Packet5Artifact();
|
||||
Packet4FileData packet = new Packet4FileData();
|
||||
Packet clonedPacket = packet.cloneTypeOnly();
|
||||
assertEquals(packet.getClass(), clonedPacket.getClass());
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.flaremicro.crossjeeves.net.packet.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -13,7 +11,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import com.flaremicro.crossjeeves.net.NetworkHandler;
|
||||
import com.flaremicro.crossjeeves.net.packet.Packet;
|
||||
import com.flaremicro.crossjeeves.net.packet.Packet4FileData;
|
||||
import com.flaremicro.crossjeeves.net.packet.Packet5Artifact;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class Packet5ArtifactTest extends PacketTestBase {
|
||||
@@ -24,41 +22,36 @@ public class Packet5ArtifactTest extends PacketTestBase {
|
||||
@Test
|
||||
public void testWrite() throws IOException
|
||||
{
|
||||
Packet4FileData packet = new Packet4FileData(1, new byte[]{1,2,3,4});
|
||||
Packet5Artifact packet = new Packet5Artifact(1, "file.txt");
|
||||
assertEquals(packet.getFileId(), 1);
|
||||
assertArrayEquals(new byte[]{1,2,3,4}, packet.getFileChunk());
|
||||
assertEquals("file.txt", packet.getRelativeFile());
|
||||
packet.sendPacket(output());
|
||||
|
||||
byte[] buffer = new byte[4];
|
||||
|
||||
assertEquals(4, input().readByte());
|
||||
assertEquals(5, input().readByte());
|
||||
assertEquals(1, input().readLong());
|
||||
assertEquals(4, input().readShort());
|
||||
input().readFully(buffer);
|
||||
assertArrayEquals(new byte[]{1,2,3,4}, buffer);
|
||||
assertEquals("file.txt", input().readUTF());
|
||||
assertBufferEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRead() throws IOException
|
||||
{
|
||||
Packet4FileData packet = new Packet4FileData();
|
||||
Packet5Artifact packet = new Packet5Artifact();
|
||||
|
||||
output().writeLong(1);
|
||||
output().writeShort(4);
|
||||
output().write(new byte[]{1,2,3,4});
|
||||
output().writeUTF("file.txt");
|
||||
|
||||
packet.recievePacket(input());
|
||||
|
||||
assertEquals(1, packet.getFileId());
|
||||
assertArrayEquals(new byte[]{1,2,3,4}, packet.getFileChunk());
|
||||
assertEquals("file.txt", packet.getRelativeFile());
|
||||
assertBufferEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcess() throws IOException
|
||||
{
|
||||
Packet4FileData packet = new Packet4FileData(1, new byte[]{1,2,3,4});
|
||||
Packet5Artifact packet = new Packet5Artifact(1, "file.txt");
|
||||
packet.processPacket(handler);
|
||||
Mockito.verify(handler, Mockito.times(1)).handlePacket(packet);
|
||||
}
|
||||
@@ -66,7 +59,7 @@ public class Packet5ArtifactTest extends PacketTestBase {
|
||||
@Test
|
||||
public void testTypeCopy()
|
||||
{
|
||||
Packet4FileData packet = new Packet4FileData();
|
||||
Packet5Artifact packet = new Packet5Artifact();
|
||||
Packet clonedPacket = packet.cloneTypeOnly();
|
||||
assertEquals(packet.getClass(), clonedPacket.getClass());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user