IrcCatNotificationService implements NotificationService { @Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { List<String> channels = Arrays.asList(subscription.getTarget().split(",")); try { for (String channel : channels) { String message = createMessage(check); sendMessage(seyrenConfig.getIrcCatHost(), seyrenConfig.getIrcCatPort(), message, channel); } } catch (IOException ioe) { throw new NotificationFailedException("Could not send message", ioe); } } @Inject  IrcCatNotificationService(SeyrenConfig seyrenConfig); @Override void sendNotification(Check check, Subscription subscription, List<Alert> alerts); @Override boolean canHandle(SubscriptionType subscriptionType);  }
@Test public void sendNotification() throws Exception { when(mockSeyrenConfig.getBaseUrl()).thenReturn("http: when(mockSeyrenConfig.getIrcCatHost()).thenReturn("localhost"); when(mockSeyrenConfig.getIrcCatPort()).thenReturn(IRCCAT_PORT); TcpServer tcpServer = new TcpServer(IRCCAT_PORT); synchronized (tcpServer) { tcpServer.start(); tcpServer.wait(1000); } Check check = new Check().withEnabled(true).withName("check-name") .withState(AlertType.ERROR); Subscription subscription = new Subscription().withType( SubscriptionType.IRCCAT).withTarget("#mychannel"); Alert alert = new Alert().withTarget("the.target.name") .withValue(BigDecimal.valueOf(12)) .withWarn(BigDecimal.valueOf(5)) .withError(BigDecimal.valueOf(10)).withFromType(AlertType.WARN) .withToType(AlertType.ERROR); List<Alert> alerts = Arrays.asList(alert); service.sendNotification(check, subscription, alerts); tcpServer.waitForNumberOfMessage(1, 1000); assertThat(tcpServer.getMessages().size(), is(1)); verify(mockSeyrenConfig).getIrcCatHost(); verify(mockSeyrenConfig).getIrcCatPort(); tcpServer.stop(); }