LanguageService { public String getIsoForLanguage(String label) { if (label != null) { for (String isoCode : languageMap.keySet()) { if (languageMap.get(isoCode).contains(getTitleCaseName(label.trim()))) { return isoCode; } } } return INVALID_ISO_CODE; } LanguageService(LanguagesImportUtility langImportUtility); String getLanguageDisplayName(String isoCode); String getIsoForLanguage(String label); List<String> getLanguageNames(); @NonNull static String getTitleCaseName(String name); static final String INVALID_ISO_CODE; static final String INVALID_LANGUAGE_NAME; }
@Test public void shouldReturnCorrectIsoCodeForArabic() throws Exception { assertEquals("fa", languageService.getIsoForLanguage("Persian")); }
@Test public void shouldReturnCorrectIsoCodeForFarsi() throws Exception { assertEquals("fa", languageService.getIsoForLanguage("Farsi")); }
@Test public void shouldReturnCorrectIsoCodeForUncapitalizedLanguageName() throws Exception { assertEquals( "fa", languageService.getIsoForLanguage("farsi")); }
@Test public void shouldReturnInvalidIsoCodeForEmptyLanguageName() throws Exception { assertEquals(LanguageService.INVALID_ISO_CODE, languageService.getIsoForLanguage("")); }
@Test public void shouldReturnInvalidIsoCodeForNullLanguageName() throws Exception { assertEquals(LanguageService.INVALID_ISO_CODE, languageService.getIsoForLanguage(null)); }