SeparatorUtil { public static String getSeparator(String targetString) { return mayContainComma(targetString) .or(() -> mayContainSemicolon(targetString)) .or(() -> mayContainColon(targetString)) .orElse(""); }  static String getSeparator(String targetString);  }
@Test public void getSeparatorShouldReturnCommaWhenCommaIsPresent() { String separator = SeparatorUtil.getSeparator("regex:(.*)@localhost, regex:user@test"); assertThat(separator).isEqualTo(","); }
@Test public void getSeparatorShouldReturnEmptyWhenColonIsPresentInPrefix() { String separator = SeparatorUtil.getSeparator("regex:(.*)@localhost"); assertThat(separator).isEqualTo(""); }
@Test public void getSeparatorShouldReturnEmptyWhenColonIsPresent() { String separator = SeparatorUtil.getSeparator("(.*)@localhost: user@test"); assertThat(separator).isEqualTo(":"); }
@Test public void getSeparatorShouldReturnColonWhenNoSeparator() { String separator = SeparatorUtil.getSeparator("user@test"); assertThat(separator).isEqualTo(":"); }