Files
CrossJeeves/test/com/flaremicro/crossjeeves/net/packet/test/Packet7LogEntryTest.java
Flare Microsystems a2a5322835 Add missing files
2024-11-11 08:47:15 -08:00

71 lines
1.8 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.Packet7LogEntry;
@RunWith(MockitoJUnitRunner.class)
public class Packet7LogEntryTest extends PacketTestBase {
@Mock
NetworkHandler handler;
private static final byte PACKET_ID = 7;
private static final String LOG_ENTRY = "reason";
private static final byte STD_OUTPUT = Packet7LogEntry.STD_ERR;
@Test
public void testWrite() throws IOException
{
Packet7LogEntry packet = new Packet7LogEntry(STD_OUTPUT, LOG_ENTRY);
assertEquals(packet.getStdOutput(), STD_OUTPUT);
assertEquals(LOG_ENTRY, packet.getLogEntry());
packet.sendPacket(output());
assertEquals(PACKET_ID, input().readByte());
assertEquals(STD_OUTPUT, input().readByte());
assertEquals(LOG_ENTRY, input().readUTF());
}
@Test
public void testRead() throws IOException
{
Packet7LogEntry packet = new Packet7LogEntry();
output().writeByte(STD_OUTPUT);
output().writeUTF(LOG_ENTRY);
packet.recievePacket(input());
assertEquals(STD_OUTPUT, packet.getStdOutput());
assertEquals(LOG_ENTRY, packet.getLogEntry());
}
@Test
public void testProcess() throws IOException
{
Packet7LogEntry packet = new Packet7LogEntry(STD_OUTPUT, LOG_ENTRY);
packet.processPacket(handler);
Mockito.verify(handler, Mockito.times(1)).handlePacket(packet);
}
@Test
public void testTypeCopy()
{
Packet7LogEntry packet = new Packet7LogEntry();
Packet clonedPacket = packet.cloneTypeOnly();
assertEquals(packet.getClass(), clonedPacket.getClass());
}
}