IpTranslatorProcessor { protected List<String> getIpsFromSlackMessage(SlackMessage message) { String text = message.getText(); List<String> parsedIps = new LinkedList<>(); Arrays.stream(text.split("\\n")) .filter(i -> i.startsWith("IP addresses added to auto block list:")) .findFirst().ifPresent(ipAddedLine -> { ipAddedLine = StringUtils.removeStart(ipAddedLine, "IP addresses added to auto block list: "); ipAddedLine = StringUtils.removeEnd(ipAddedLine.trim(), ","); String[] ips = ipAddedLine.split(","); Arrays.stream(ips).forEach(ipLine -> { parsedIps.add(ipLine.trim().split("\\s")[0]); }); }); return parsedIps.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList()); }  void processMessageIfFromRateLimiter(SlackMessage message);  }
@Test public void test_that_getIpsFromSlackMessage_returns_ips_as_expected() { List<String> ips = processor.getIpsFromSlackMessage(slackMessage); assertEquals(ImmutableList.of("52.71.59.82"), ips); }