### Question:
ServiceLocator { public MarkupLanguage getMarkupLanguage(final String languageName) throws IllegalArgumentException { checkArgument(!Strings.isNullOrEmpty(languageName), "Must provide a languageName"); Pattern classNamePattern = Pattern.compile("\\s*([^\\s#]+)?#?.*"); final List<String> names = new ArrayList<>(); final List<MarkupLanguage> languages = new ArrayList<>(); final MarkupLanguage[] result = new MarkupLanguage[1]; loadMarkupLanguages(language -> { if (languageName.equals(language.getName())) { result[0] = language; return false; } languages.add(language); names.add(language.getName()); return true; }); if (result[0] != null) { return result[0]; } Matcher matcher = classNamePattern.matcher(languageName); if (matcher.matches()) { String className = matcher.group(1); if (className != null) { for (MarkupLanguage language : languages) { if (className.equals(language.getClass().getName())) { return language; } } try { Class<?> clazz = Class.forName(className, true, classLoader); if (MarkupLanguage.class.isAssignableFrom(clazz)) { MarkupLanguage instance = (MarkupLanguage) clazz.getConstructor().newInstance(); return instance; } } catch (Exception e) { } } } Collections.sort(names); StringBuilder buf = new StringBuilder(); for (String name : names) { if (buf.length() != 0) { buf.append(", "); } buf.append('\''); buf.append(name); buf.append('\''); } throw new IllegalArgumentException(MessageFormat.format(Messages.getString("ServiceLocator.4"), languageName, buf.length() == 0 ? Messages.getString("ServiceLocator.5") : Messages.getString("ServiceLocator.6") + buf)); } 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);  }### Answer:
@Test public void testUnknownLanguage() { setupServiceLocatorWithMockMarkupLanguage(true); assertThrows(IllegalArgumentException.class, () -> locator.getMarkupLanguage("No Such Language asdlkfjal;sjdf")); }
@Test public void testFQN() { MarkupLanguage markupLanguage = locator.getMarkupLanguage(MockMarkupLanguage.class.getName()); assertNotNull(markupLanguage); assertEquals(MockMarkupLanguage.class, markupLanguage.getClass()); }
@Test public void getMarkupLanguageNull() { IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> locator.getMarkupLanguage(null)); assertTrue(e.getMessage().contains("Must provide a languageName")); }
@Test public void getMarkupLanguageUnknown() { setupServiceLocatorWithMockMarkupLanguage(true); IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> locator.getMarkupLanguage("UnknownLanguage")); assertTrue(e.getMessage() .contains( "Cannot load markup language 'UnknownLanguage'. Known markup languages are 'MockMarkupLanguage'")); }