QueryParsers { public Set<String> getLanguages() { Set<String> result = new HashSet<String>(); for (QueryParser parser : parsers.values()) { result.add(parser.getLanguage()); } return Collections.unmodifiableSet(result); } QueryParsers( QueryParser... parsers );  QueryParsers( Iterable<QueryParser> parsers ); void addLanguage( QueryParser languageParser ); void addLanguages( QueryParser firstLanguage,
                              QueryParser... additionalLanguages ); void addLanguages( Iterable<QueryParser> languages ); QueryParser removeLanguage( String language ); Collection<QueryParser> removeLanguages( String firstLanguage,
                                                    String... additionalLanguages ); Set<String> getLanguages(); QueryParser getParserFor( String language ); QueryCommand parse( TypeSystem typeSystem,
                               String language,
                               String query ); @Override int hashCode(); @Override boolean equals( Object obj ); @Override String toString();  }
@Test public void shouldAllowNullArrayInConstructor() { parsers = new QueryParsers((QueryParser[])null); assertThat(parsers.getLanguages().isEmpty(), is(true)); }
@Test public void shouldAllowNullIterableInConstructor() { parsers = new QueryParsers((Iterable<QueryParser>)null); assertThat(parsers.getLanguages().isEmpty(), is(true)); }
@Test public void shouldAllowOneQueryParserReferenceInConstructor() { parsers = new QueryParsers(parser1); assertThat(parsers.getLanguages().size(), is(1)); assertThat(parsers.getLanguages().contains(parser1.getLanguage()), is(true)); }
@Test public void shouldAllowTwoQueryParserReferencesInConstructor() { parsers = new QueryParsers(parser1, parser2); assertThat(parsers.getLanguages().size(), is(2)); assertThat(parsers.getLanguages().contains(parser1.getLanguage()), is(true)); assertThat(parsers.getLanguages().contains(parser2.getLanguage()), is(true)); }
@Test public void shouldAllowThreeQueryParserReferencesInConstructor() { parsers = new QueryParsers(parser1, parser2, parser3); assertThat(parsers.getLanguages().size(), is(3)); assertThat(parsers.getLanguages().contains(parser1.getLanguage()), is(true)); assertThat(parsers.getLanguages().contains(parser2.getLanguage()), is(true)); assertThat(parsers.getLanguages().contains(parser3.getLanguage()), is(true)); }
@Test public void shouldOverwriteQueryParsersWithSameLanguageInConstructor() { parser2 = new MockParser(parser1.getLanguage()); parsers = new QueryParsers(parser1, parser2, parser3); assertThat(parsers.getLanguages().size(), is(2)); assertThat(parsers.getLanguages().contains(parser2.getLanguage()), is(true)); assertThat(parsers.getLanguages().contains(parser3.getLanguage()), is(true)); }