public static Pattern buildTopicRegex(Set<String> stringsToMatch) {
    StringJoiner sj = new StringJoiner("|");
    stringsToMatch.forEach(sj::add);
    return Pattern.compile(sj.toString());
  }
@Test
    public void testBuildTopicRegex() {
        Set<String> topicsToMatch = Set.of(TOPIC1, TOPIC2);
        Pattern pattern = buildTopicRegex(topicsToMatch);

        assertTrue(pattern.matcher(TOPIC1).matches());
        assertTrue(pattern.matcher(TOPIC2).matches());
        assertFalse(pattern.matcher(TOPIC3).matches());
    }