PatternUtils { public static String literalMatchGroup(Collection<String> strings) { Assert.notEmpty(strings, "Collection of strings argument cannot be empty or null"); StringBuffer buff = new StringBuffer("("); for (String s : strings) { buff.append(s); buff.append("|"); } buff.deleteCharAt(buff.lastIndexOf("|")); buff.append(")"); return buff.toString(); }  static String literalMatchGroup(Collection<String> strings);  }
@Test public void testLiteralMatchGroup_null() { assertThrows(IllegalArgumentException.class, () -> { PatternUtils.literalMatchGroup(null); }); }
@Test public void testLiteralMatchGroup_empty() { assertThrows(IllegalArgumentException.class, () -> { PatternUtils.literalMatchGroup(new ArrayList<String>()); }); }
@Test public void testLiteralMatchGroup() { List<String> list = new ArrayList<String>(); list.add("cat"); assertEquals("(cat)", PatternUtils.literalMatchGroup(list)); list.add("dog"); assertEquals("(cat|dog)", PatternUtils.literalMatchGroup(list)); list.add("rat"); assertEquals("(cat|dog|rat)", PatternUtils.literalMatchGroup(list)); }