TlsAttackerSocket { public byte[] receiveBytes() throws IOException { ReceiveAction action = new ReceiveAction(new ApplicationMessage()); action.setConnectionAlias(state.getTlsContext().getConnection().getAlias()); action.execute(state); List<ProtocolMessage> receivedMessages = action.getReceivedMessages(); List<ApplicationMessage> receivedAppMessages = new LinkedList<>(); for (ProtocolMessage message : receivedMessages) { if (message instanceof ApplicationMessage) { receivedAppMessages.add((ApplicationMessage) message); } } ByteArrayOutputStream stream = new ByteArrayOutputStream(); for (ApplicationMessage message : receivedAppMessages) { stream.write(message.getData().getValue()); } return stream.toByteArray(); } TlsAttackerSocket(State state); void sendRawBytes(byte[] bytes); byte[] receiveRawBytes(); void send(String string); void send(byte[] bytes); byte[] receiveBytes(); String receiveString(); void send(ProtocolMessage message); void close();  }
@Test public void testReceiveBytes() throws Exception { transportHandler.setFetchableByte(new byte[] { 0x17, 0x03, 0x03, 0x00, 0x03, 8, 8, 8 }); byte[] receivedBytes = socket.receiveBytes(); assertArrayEquals(receivedBytes, new byte[] { 8, 8, 8 }); }