LanguageService { @NonNull public static String getTitleCaseName(String name) { if (name == null || name.isEmpty()) { return ""; } String titleCaseName = ""; name = name.trim(); String[] tokens = name.split(" "); for (String token : tokens) { String lowerCaseName = token.toLowerCase(); titleCaseName += lowerCaseName.substring(0, 1).toUpperCase() + lowerCaseName.substring(1) + " "; } return titleCaseName.trim(); } 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 shouldReturnATitleCasedString() { String titleCasedString = LanguageService.getTitleCaseName("A title cased string"); assertEquals("A Title Cased String", titleCasedString); }
@Test public void shouldReturnEmptyStringIfNullPassedToGetTitleCaseName() { assertEquals("", LanguageService.getTitleCaseName(null)); }
@Test public void shouldReturnTitleCasedStringWhenSpaceAtFront() { String titleCasedString = LanguageService.getTitleCaseName(" A title cased string"); assertEquals("A Title Cased String", titleCasedString); }