UserServiceImpl implements UserService { @Override public String getUserCharset(final Identity identity) { String charset; charset = WebappHelper.getDefaultCharset(); final PropertyImpl p = propertyManager.findProperty(identity, null, null, null, CHARSET); if (p != null) { charset = p.getStringValue(); if (!Charset.isSupported(charset)) { charset = WebappHelper.getDefaultCharset(); } } else { charset = WebappHelper.getDefaultCharset(); } return charset; } UserServiceImpl(); @Override User createUser(final String firstName, final String lastName, final String eMail); @Override User createAndPersistUser(final String firstName, final String lastName, final String email); @Override Identity findIdentityByEmail(final String email); @Override User findUserByEmail(final String email); @Override boolean userExist(final String email); @Override User loadUserByKey(final Long key); @Override void updateUser(final User usr); @Override void saveUser(final User user); @Override boolean updateUserFromIdentity(final Identity identity); @Override void setUserCharset(final Identity identity, final String charset); @Override String getUserCharset(final Identity identity); @Override void deleteUserProperties(User user); @Override boolean syntaxCheckOlatPassword(final String password); @Override boolean syntaxCheckOlatLogin(final String login); @Override UserPropertiesConfig getUserPropertiesConfig(); @Override List<UserPropertyHandler> getUserPropertyHandlersFor(final String usageIdentifyer, final boolean isAdministrativeUser); @Override List<UserPropertyHandler> getAllUserPropertyHandlers(); @Override boolean isMandatoryUserProperty(final String usageIdentifyer, final UserPropertyHandler propertyHandler); @Override boolean isUserViewReadOnly(final String usageIdentifyer, final UserPropertyHandler propertyHandler); @Override void setUserNameAndPasswordSyntaxChecker(final UserNameAndPasswordSyntaxChecker userNameAndPasswordSyntaxChecker); @Override void setUserPropertiesConfig(final UserPropertiesConfig userPropertiesConfig); @Override String getUserProperty(User user, String propertyName, Locale locale); @Override String getUserProperty(User user, String propertyName); @Override String getFirstAndLastname(User user); @Override void setUserProperty(final User user, final String propertyName, final String propertyValue); String getPropertyOrIdentityEnvAttribute(final User user, final String propertyName, final Locale locale);  }
@Test public void testGetUserCharset_PropertyDoesNotExist() { when(propertyManagerMock.findProperty(identityMock, null, null, null, UserServiceImpl.CHARSET)).thenReturn(null); String charsetValue = userServiceImpl.getUserCharset(identityMock); assertEquals("Wrong charset when no property exists, should return 'WebappHelper.getDefaultCharset()", charsetValue, WebappHelper.getDefaultCharset()); }
@Test public void testGetUserCharset_CharsetIsNotSupported() { String notSupportedCharset = "notSupportedCharset"; PropertyImpl propertyWithNotSupportedCharset = mock(PropertyImpl.class); when(propertyWithNotSupportedCharset.getStringValue()).thenReturn(notSupportedCharset); when(propertyManagerMock.findProperty(identityMock, null, null, null, UserServiceImpl.CHARSET)).thenReturn(propertyWithNotSupportedCharset); String charsetValue = userServiceImpl.getUserCharset(identityMock); assertEquals("Wrong charset when charset is not supported, should return 'WebappHelper.getDefaultCharset()", charsetValue, WebappHelper.getDefaultCharset()); }
@Test public void testGetUserCharset_CharsetIsSupported() { String supportedCharset = "UTF-8"; PropertyImpl propertyWithSupportedCharset = mock(PropertyImpl.class); when(propertyWithSupportedCharset.getStringValue()).thenReturn(supportedCharset); when(propertyManagerMock.findProperty(identityMock, null, null, null, UserServiceImpl.CHARSET)).thenReturn(propertyWithSupportedCharset); String charsetValue = userServiceImpl.getUserCharset(identityMock); assertEquals("Wrong charset when charset is supported, should return this value", charsetValue, supportedCharset); }