67 lines
1.7 KiB
Java
67 lines
1.7 KiB
Java
package com.flaremicro.crossjeeves.net.packet.test;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
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.Packet0Identify;
|
|
|
|
@RunWith(MockitoJUnitRunner.class)
|
|
public class Packet0IdentifyTest extends PacketTestBase {
|
|
|
|
@Mock
|
|
NetworkHandler handler;
|
|
|
|
@Test
|
|
public void testWrite() throws IOException
|
|
{
|
|
Packet0Identify packet = new Packet0Identify(1337);
|
|
assertEquals(1337, packet.getFlags());
|
|
assertEquals(Packet.PROTOCOL_VERSION, packet.getProtocolVersion());
|
|
packet.sendPacket(output());
|
|
|
|
assertEquals(0, input().readByte());
|
|
assertEquals(Packet.PROTOCOL_VERSION, input().readInt());
|
|
assertEquals(1337, input().readInt());
|
|
}
|
|
|
|
@Test
|
|
public void testRead() throws IOException
|
|
{
|
|
Packet0Identify packet = new Packet0Identify();
|
|
|
|
output().writeInt(Packet.PROTOCOL_VERSION);
|
|
output().writeInt(1337);
|
|
|
|
packet.recievePacket(input());
|
|
|
|
assertEquals(Packet.PROTOCOL_VERSION, packet.getProtocolVersion());
|
|
assertEquals(1337, packet.getFlags());
|
|
}
|
|
|
|
@Test
|
|
public void testProcess() throws IOException
|
|
{
|
|
Packet0Identify packet = new Packet0Identify(1337);
|
|
packet.processPacket(handler);
|
|
Mockito.verify(handler, Mockito.times(1)).handlePacket(packet);
|
|
}
|
|
|
|
@Test
|
|
public void testTypeCopy()
|
|
{
|
|
Packet0Identify packet = new Packet0Identify();
|
|
Packet clonedPacket = packet.cloneTypeOnly();
|
|
assertEquals(packet.getClass(), clonedPacket.getClass());
|
|
}
|
|
|
|
}
|