### Question:
LogstashUdpMessagePersister implements MessagePersister { @Override public int persistMessages(List<String> messages) { int responseCode = -1; if (broadcastUri != null) { DatagramSocket socket = null; try { socket = new DatagramSocket(); } catch (SocketException ex) { LOGGER.error("Metrics Broadcast Setup Failed: " + ex.getMessage()); } try { ByteBuffer toWrite = ByteBuffer.wrap(serializeMessages(messages).getBytes()); byte[] byteArray = toWrite.array(); DatagramPacket packet = new DatagramPacket(byteArray, byteArray.length); socket.connect(new InetSocketAddress(uri.getHost(), uri.getPort())); socket.send(packet); } catch ( Exception ex ) { LOGGER.error("Metrics Broadcast Failed: " + ex.getMessage()); } finally { socket.close(); } } return responseCode; } LogstashUdpMessagePersister(String broadcastUri); void setup(); @Override /** * Given a list of messages as Strings, broadcast them to the broadcastUri * (if one is defined) * @param messages * @return int status code from POST response */ int persistMessages(List<String> messages);  }### Answer:
@Test public void testFailedPersist() { LogstashUdpMessagePersister persister = new LogstashUdpMessagePersister("udp: List<String> messageArray = new ArrayList<>(); for (int x = 0; x < 10; x ++) { messageArray.add("Fake_message #" + x); } persister.persistMessages(messageArray); byte[] receiveData = new byte[1024]; DatagramPacket messageDatagram = new DatagramPacket(receiveData, receiveData.length); try { socket.receive(messageDatagram); Assert.assertNotNull(messageDatagram); List<String> messages = Stream.of((new String(messageDatagram.getData())).split("\n")).collect(Collectors.toList()); Assert.assertEquals(messageArray, messages.subList(0,10)); } catch (IOException ex) { LOGGER.error("Metrics Broadcast Test Failed: " + ex.getMessage()); } }