UserService { public String switchLanguagePreference() { String preferredLocale = allSharedPreferences.fetchLanguagePreference(); if (ENGLISH_LOCALE.equals(preferredLocale)) { allSharedPreferences.saveLanguagePreference(KANNADA_LOCALE); return KANNADA_LANGUAGE; } else { allSharedPreferences.saveLanguagePreference(ENGLISH_LOCALE); return ENGLISH_LANGUAGE; } } UserService(Repository repository, AllSettings allSettings, AllSharedPreferences allSharedPreferences, HTTPAgent httpAgent, Session session,
                       DristhiConfiguration configuration, SaveANMLocationTask saveANMLocationTask); boolean isValidLocalLogin(String userName, String password); LoginResponse isValidRemoteLogin(String userName, String password); void localLogin(String userName, String password); void remoteLogin(String userName, String password, String anmLocation); boolean hasARegisteredUser(); void logout(); void logoutSession(); boolean hasSessionExpired(); String switchLanguagePreference();  }
@Test public void shouldSwitchLanguageToKannada() throws Exception { when(allSharedPreferences.fetchLanguagePreference()).thenReturn(ENGLISH_LOCALE); userService.switchLanguagePreference(); verify(allSharedPreferences).saveLanguagePreference(KANNADA_LOCALE); }
@Test public void shouldSwitchLanguageToEnglish() throws Exception { when(allSharedPreferences.fetchLanguagePreference()).thenReturn(KANNADA_LOCALE); userService.switchLanguagePreference(); verify(allSharedPreferences).saveLanguagePreference(ENGLISH_LOCALE); }