@Test public void testLoadClassNotFound() throws MalformedURLException { final URL url = new URL("file: final AtomicBoolean wasThrown = new AtomicBoolean(); locator = new ServiceLocator(ServiceLocatorTest.class.getClassLoader()) { @Override protected Class<?> loadClass(ResourceDescriptor resource, String className) throws ClassNotFoundException { wasThrown.set(true); throw new ClassNotFoundException(className); } @Override protected List<ResourceDescriptor> discoverServiceResources() { return Collections.singletonList(new ResourceDescriptor(url)); } @Override protected List<String> readServiceClassNames(URL url) { return Collections.singletonList("test.TestLanguage"); } @Override void logFailure(String className, Exception e) { } }; Set<MarkupLanguage> languages = locator.getAllMarkupLanguages(); assertTrue(wasThrown.get()); assertNotNull(languages); assertTrue(languages.isEmpty()); }
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);  }