PatternCompilerProvider { static void findPatternCompiler(Iterator<PatternCompiler> iterator) { if (iterator.hasNext()) { service = iterator.next(); if (iterator.hasNext()) { throwMoreThanOneCompilerException(iterator); } } else { service = new DefaultPatternCompiler(); } } private  PatternCompilerProvider();   }
@Test public void use_default_compiler_if_none_registered() { PatternCompilerProvider.findPatternCompiler(Collections.emptyIterator()); assertSame(DefaultPatternCompiler.class, PatternCompilerProvider.service.getClass()); }
@Test public void use_found_pattern_compiler_if_one_provided() { PatternCompiler compiler = getTestCompiler(); PatternCompilerProvider.findPatternCompiler(Collections.singletonList(compiler).iterator()); assertSame(compiler, PatternCompilerProvider.service); }
@Test public void throws_error_if_more_than_one_pattern_compiler() { final Executable testMethod = () -> PatternCompilerProvider.findPatternCompiler(Arrays.asList(new DefaultPatternCompiler(), getTestCompiler()).iterator()); final IllegalStateException thrownException = assertThrows(IllegalStateException.class, testMethod); assertThat("Unexpected message", thrownException.getMessage(), is(equalTo("More than one PatternCompiler: [class io.cucumber.cucumberexpressions.DefaultPatternCompiler, class io.cucumber.cucumberexpressions.PatternCompilerProviderTest$1]"))); }