Files
CrossJeeves/test/com/flaremicro/crossjeeves/net/packet/test/Packet5ArtifactTest.java
Flare Microsystems 75eb55d341 Add tests
2024-11-10 20:15:43 -08:00

75 lines
1.9 KiB
Java

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;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
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;
@RunWith(MockitoJUnitRunner.class)
public class Packet5ArtifactTest extends PacketTestBase {
@Mock
NetworkHandler handler;
@Test
public void testWrite() throws IOException
{
Packet4FileData packet = new Packet4FileData(1, new byte[]{1,2,3,4});
assertEquals(packet.getFileId(), 1);
assertArrayEquals(new byte[]{1,2,3,4}, packet.getFileChunk());
packet.sendPacket(output());
byte[] buffer = new byte[4];
assertEquals(4, input().readByte());
assertEquals(1, input().readLong());
assertEquals(4, input().readShort());
input().readFully(buffer);
assertArrayEquals(new byte[]{1,2,3,4}, buffer);
assertBufferEmpty();
}
@Test
public void testRead() throws IOException
{
Packet4FileData packet = new Packet4FileData();
output().writeLong(1);
output().writeShort(4);
output().write(new byte[]{1,2,3,4});
packet.recievePacket(input());
assertEquals(1, packet.getFileId());
assertArrayEquals(new byte[]{1,2,3,4}, packet.getFileChunk());
assertBufferEmpty();
}
@Test
public void testProcess() throws IOException
{
Packet4FileData packet = new Packet4FileData(1, new byte[]{1,2,3,4});
packet.processPacket(handler);
Mockito.verify(handler, Mockito.times(1)).handlePacket(packet);
}
@Test
public void testTypeCopy()
{
Packet4FileData packet = new Packet4FileData();
Packet clonedPacket = packet.cloneTypeOnly();
assertEquals(packet.getClass(), clonedPacket.getClass());
}
}