BaseContextHandler { protected List<String> extractGroups(String pattern) { List<String> allMatches = new ArrayList<>(); if (pattern == null) { return allMatches; } Matcher m = Pattern.compile(GROUP_PATTERN).matcher(pattern); while (m.find()) { allMatches.add(m.group(1)); } return allMatches; }   static final String GROUP_PATTERN; }
@Test public void shouldNotExtractGroupsInPatternWithSpacesInName() { List<String> groups = capturer.extractGroups("{(hello world)}"); assertThat(groups, is(empty())); }
@Test public void shouldExtractGroupsInPatternWithUnderscoreInName() { List<String> groups = capturer.extractGroups("{(hello_world)}"); assertThat(groups, contains("hello_world")); }
@Test public void shouldExtractDotSeparatedName() { List<String> groups = capturer.extractGroups("{(hello.world)}"); assertThat(groups, contains("hello.world")); }
@Test public void shouldExtractNoGroupsInPattern() { List<String> groups = capturer.extractGroups("(hello)"); assertThat(groups, is(empty())); }
@Test public void shouldExtractSingleGroupInPattern() { List<String> groups = capturer.extractGroups("{(hello)}"); assertThat(groups, contains("hello")); }
@Test public void shouldExtractTwoGroupsInPattern() { List<String> groups = capturer.extractGroups("{(hello)}, {(world)}"); assertThat(groups, contains("hello", "world")); }