AlertSender { public static void send(String alertScript, String message) { try { Process alert = Runtime.getRuntime().exec(alertScript + " \"" + message + "\""); alert.waitFor(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(alert.getInputStream()))) { StringBuilder sb = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { sb.append(line).append("\n"); } int exitValue = alert.exitValue(); if (exitValue != 0) { System.out.println("Exit Code:" + exitValue); System.out.println("Message: " + sb.toString()); } } } catch (IOException | InterruptedException e) { e.printStackTrace(); } sendCounter.incrementAndGet(); } private  AlertSender(); static void send(String alertScript, String message); @VisibleForTesting static int getSendCount();  }
@Test public void testSend() throws Exception { int sendCountBefore = AlertSender.getSendCount(); AlertSender.send(ALERT_SCRIPT, "snapshot test"); Assert.assertEquals(sendCountBefore + 1, AlertSender.getSendCount()); }