### Question:
BroadcastMessagePersister implements MessagePersister { @Override public int persistMessages(List<String> messages) { int responseCode = -1; if (broadcastUri != null) { try { HttpClient client = HttpClients.createDefault(); HttpPost post = new HttpPost(broadcastUri); post.setHeader("User-Agent", "Streams"); List<NameValuePair> urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("messages", serializeMessages(messages))); post.setEntity(new UrlEncodedFormEntity(urlParameters, "UTF-8")); HttpResponse response = client.execute(post); responseCode = response.getStatusLine().getStatusCode(); LOGGER.debug("Broadcast {} messages to URI: {}", messages.size(), broadcastUri); } catch (Exception ex) { LOGGER.error("Failed to broadcast message to URI: {}, exception: {}", broadcastUri, ex); } } return responseCode; } BroadcastMessagePersister(String broadcastUri); @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() { BroadcastMessagePersister persister = new BroadcastMessagePersister("http: List<String> messages = new ArrayList<>(); for (int x = 0; x < 10; x++) { messages.add("Fake_message #" + x); } int statusCode = persister.persistMessages(messages); assertNotNull(statusCode); assertNotEquals(statusCode, 200); }
@Test public void testInvalidUrl() { BroadcastMessagePersister persister = new BroadcastMessagePersister("h"); List<String> messages = new ArrayList<>(); for (int x = 0; x < 10; x++) { messages.add("Fake_message #" + x); } int statusCode = persister.persistMessages(messages); assertNotNull(statusCode); assertEquals(statusCode, -1); }