### Question:
ScriptEngineConfigurator implements ServiceListener { protected List<Pattern> compilePatternList(Set<String> patterns) { final List<Pattern> result = new ArrayList<Pattern>(); if (patterns != null) { for (final String pattern : patterns) { if (!pattern.isEmpty()) { final String regex = "\\Q" + pattern.replace("*", "\\E.*?\\Q") + "\\E"; result.add(Pattern.compile(regex)); } } } return result; } @Inject  ScriptEngineConfigurator(@Named("ScriptLogger")Logger logger); void registerServiceListener(); @Override void schemaChanged(String serviceName, String version); @Override void organizationConfigChanged(String serviceName, String version, String orgName, String groupName,
                                          String serviceComponent, int type); @Override void globalConfigChanged(String serviceName, String version, String groupName, String serviceComponent,
                                    int type);  }### Answer:
@Test public void shouldCompileEmptyPatternList() { Set<String> patterns = Collections.emptySet(); List<Pattern> result = engineConfigurator.compilePatternList(patterns); assertThat(result).isEmpty(); }
@Test public void shouldStripEmptyPatterns() { Set<String> patterns = Collections.singleton(""); List<Pattern> result = engineConfigurator.compilePatternList(patterns); assertThat(result).isEmpty(); }
@Test public void shouldCompileStarToWildcard() { Set<String> patterns = Collections.singleton("java.lang.*"); List<Pattern> result = engineConfigurator.compilePatternList(patterns); assertThat(result).hasSize(patterns.size()); assertThat(result.get(0).matcher("java.lang.Foo").matches()).isTrue(); assertThat(result.get(0).matcher("java.util.Foo").matches()).isFalse(); }
@Test public void shouldSupportMultipleWildcards() { Set<String> patterns = Collections.singleton("java.*.Foo*"); List<Pattern> result = engineConfigurator.compilePatternList(patterns); assertThat(result.get(0).matcher("java.lang.FooBar").matches()).isTrue(); assertThat(result.get(0).matcher("java.foo.FooBar").matches()).isTrue(); assertThat(result.get(0).matcher("java.FooBar").matches()).isFalse(); assertThat(result.get(0).matcher("java.foo.BarFoo").matches()).isFalse(); }
@Test public void shouldQuoteDotCharacters() { Set<String> patterns = Collections.singleton("java.lang.*"); List<Pattern> result = engineConfigurator.compilePatternList(patterns); assertThat(result.get(0).matcher("javaXlangXFoo").matches()).isFalse(); assertThat(result.get(0).matcher("java.lang.Foo").matches()).isTrue(); }
@Test public void shouldQuoteOtherSpecialChars() { Set<String> patterns = Collections.singleton("foo[1-9]"); List<Pattern> result = engineConfigurator.compilePatternList(patterns); assertThat(result.get(0).matcher("foo6").matches()).isFalse(); assertThat(result.get(0).matcher("foo[1-9]").matches()).isTrue(); }