@Test public void testCtf1() throws IOException { try (DataInputStream dataInputStream = streamSimulator.getDataInputStream(); DataOutputStream dataOutputStream = streamSimulator.getDataOutputStream()) { Protocol protocol = new Protocol(dataInputStream, dataOutputStream); streamSimulator.writeForInputStream("ROK 1 9"); protocol.ayt(); streamSimulator.writeForInputStream("ROK 0 "); protocol.sco("test"); streamSimulator.writeForInputStream("ROK 13 crashed=false"); protocol.ctt(); streamSimulator.writeForInputStream("ROK 0 "); protocol.swa("test"); streamSimulator.writeForInputStream("ROK 13 crashed=false"); ReceiveMessage receiveMessage = protocol.ctf("abc123".getBytes(StandardCharsets.UTF_8)); Assert.assertEquals(receiveMessage.getCommand(), Command.ROK); Assert.assertEquals( receiveMessage.getBody(), "crashed=false".getBytes(StandardCharsets.UTF_8)); Assert.assertEquals( streamSimulator.readLastFromOutputStream(), "CTF 6 abc123".getBytes(StandardCharsets.UTF_8)); } catch (ProtocolStateException ignored) { Assert.fail(); } }
@Test public void testSwa2() throws IOException { try (DataInputStream dataInputStream = streamSimulator.getDataInputStream(); DataOutputStream dataOutputStream = streamSimulator.getDataOutputStream()) { Protocol protocol = new Protocol(dataInputStream, dataOutputStream); protocol.swa("test"); Assert.fail(); } catch (ProtocolStateException ignored) { } }