### Question:
ReceivingClient extends AbstractSocketHandler { public void setMessageHandler(MessageHandler messageHandler) { this.messageHandler = messageHandler; } ReceivingClient(InetSocketAddress address, ScheduledExecutorService connectionScheduler, int readingBufferSize, byte endOfMessageByte); void setReconnectAttempts(int reconnectAttempts); void setDelayMillisBeforeReconnect(long delayMillisBeforeReconnect); void setMessageHandler(MessageHandler messageHandler);  }### Answer:
@Test public void validateSuccessfullConnectionAndCommunication() throws Exception { int port = this.availablePort(); String msgToSend = "Hello from validateSuccessfullConnectionAndCommunication"; InetSocketAddress address = new InetSocketAddress(port); Server server = new Server(address, 1024, EOM); server.start(); ReceivingClient client = new ReceivingClient(address, this.scheduler, 1024, EOM); StringBuilder stringBuilder = new StringBuilder(); client.setMessageHandler((fromAddress, message, partialMessage) -> stringBuilder.append(new String(message, StandardCharsets.UTF_8))); client.start(); assertTrue(client.isRunning()); this.sendToSocket(address, msgToSend); Thread.sleep(200); assertEquals("", stringBuilder.toString()); this.sendToSocket(address, "\r"); Thread.sleep(200); assertEquals(msgToSend + "\r", stringBuilder.toString()); client.stop(); server.stop(); assertFalse(client.isRunning()); assertFalse(server.isRunning()); }
@Test public void validateSuccessfullConnectionAndCommunicationWithClientBufferSmallerThenMessage() throws Exception { int port = this.availablePort(); String msgToSend = "Hello from validateSuccessfullConnectionAndCommunicationWithClientBufferSmallerThenMessage"; InetSocketAddress address = new InetSocketAddress(port); Server server = new Server(address, 1024, EOM); server.start(); ReceivingClient client = new ReceivingClient(address, this.scheduler, 64, EOM); List<String> messages = new ArrayList<>(); client.setMessageHandler((fromAddress, message, partialMessage) -> messages.add(new String(message, StandardCharsets.UTF_8))); client.start(); assertTrue(client.isRunning()); this.sendToSocket(address, msgToSend); this.sendToSocket(address, "\r"); Thread.sleep(200); assertEquals("Hello from validateSuccessfullConnectionAndCommunicationWithClie", messages.get(0)); assertEquals("ntBufferSmallerThenMessage\r", messages.get(1)); client.stop(); server.stop(); assertFalse(client.isRunning()); assertFalse(server.isRunning()); }
@Test public void validateMessageSendBeforeAfterClientConnectDisconnectNoEndOfMessageByte() throws Exception { int port = this.availablePort(); String msgToSend = "Hello from validateMessageSendBeforeAfterClientConnectDisconnectNoEndOfMessageByte"; InetSocketAddress address = new InetSocketAddress(port); Server server = new Server(address, 1024, EOM); server.start(); this.sendToSocket(address, "foo"); ReceivingClient client = new ReceivingClient(address, this.scheduler, 30, EOM); List<String> messages = new ArrayList<>(); client.setMessageHandler((fromAddress, message, partialMessage) -> messages.add(new String(message, StandardCharsets.UTF_8))); client.start(); assertTrue(client.isRunning()); this.sendToSocket(address, msgToSend); Thread.sleep(200); assertEquals(2, messages.size()); assertEquals("Hello from validateMessageSend", messages.get(0)); assertEquals("BeforeAfterClientConnectDiscon", messages.get(1)); messages.clear(); client.stop(); this.sendToSocket(address, msgToSend); Thread.sleep(200); assertEquals(0, messages.size()); this.sendToSocket(address, msgToSend); server.stop(); assertFalse(client.isRunning()); assertFalse(server.isRunning()); }