@Test public void getAllMarkupLanguagesFiltersDuplicates() { final MarkupLanguage language1 = new TestMarkupLanguage("Language 1"); final MarkupLanguage language1b = new MarkupLanguage() { { setName("Language 1"); } @Override public void processContent(MarkupParser parser, String markupContent, boolean asDocument) { throw new IllegalStateException(); } }; final MarkupLanguage language2 = new TestMarkupLanguage("Language 3"); final MarkupLanguage language2b = new TestMarkupLanguage("Language 3"); ServiceLocator locator = new ServiceLocator(ServiceLocatorTest.class.getClassLoader()) { @Override void loadMarkupLanguages(MarkupLanguageVisitor visitor) { visitor.accept(language1); visitor.accept(language1b); visitor.accept(language2); visitor.accept(language2b); } }; Set<MarkupLanguage> markupLanguages = locator.getAllMarkupLanguages(); assertEquals(3, markupLanguages.size()); assertTrue(markupLanguages.containsAll(ImmutableSet.of(language1, language1b))); assertTrue(markupLanguages.contains(language2) || markupLanguages.contains(language2b)); }
public Set<MarkupLanguage> getAllMarkupLanguages() { final Set<MarkupLanguage> markupLanguages = new HashSet<MarkupLanguage>(); loadMarkupLanguages(language -> { markupLanguages.add(language); return true; }); return filterDuplicates(markupLanguages); }
ServiceLocator { public Set<MarkupLanguage> getAllMarkupLanguages() { final Set<MarkupLanguage> markupLanguages = new HashSet<MarkupLanguage>(); loadMarkupLanguages(language -> { markupLanguages.add(language); return true; }); return filterDuplicates(markupLanguages); } }
ServiceLocator { public Set<MarkupLanguage> getAllMarkupLanguages() { final Set<MarkupLanguage> markupLanguages = new HashSet<MarkupLanguage>(); loadMarkupLanguages(language -> { markupLanguages.add(language); return true; }); return filterDuplicates(markupLanguages); } protected  ServiceLocator(ClassLoader classLoader); }
ServiceLocator { public Set<MarkupLanguage> getAllMarkupLanguages() { final Set<MarkupLanguage> markupLanguages = new HashSet<MarkupLanguage>(); loadMarkupLanguages(language -> { markupLanguages.add(language); return true; }); return filterDuplicates(markupLanguages); } protected  ServiceLocator(ClassLoader classLoader); static ServiceLocator getInstance(ClassLoader classLoader); static ServiceLocator getInstance(); MarkupLanguage getMarkupLanguage(final String languageName); Set<MarkupLanguage> getAllMarkupLanguages(); static void setImplementation(Class<? extends ServiceLocator> implementationClass); }
ServiceLocator { public Set<MarkupLanguage> getAllMarkupLanguages() { final Set<MarkupLanguage> markupLanguages = new HashSet<MarkupLanguage>(); loadMarkupLanguages(language -> { markupLanguages.add(language); return true; }); return filterDuplicates(markupLanguages); } protected  ServiceLocator(ClassLoader classLoader); static ServiceLocator getInstance(ClassLoader classLoader); static ServiceLocator getInstance(); MarkupLanguage getMarkupLanguage(final String languageName); Set<MarkupLanguage> getAllMarkupLanguages(); static void setImplementation(Class<? extends ServiceLocator> implementationClass);  }