UserMapper { public User convert(UserEntity user) { final User userItem = new User(); userItem.setEmail(user.getEmail()); userItem.setFirstName(user.getFirstname()); userItem.setLastName(user.getLastname()); userItem.setDisplayName(user.getDisplayName()); userItem.setId(user.getId()); userItem.setCustomFields(user.getCustomFields()); return userItem; }  User convert(UserEntity user); User convert(SearchableUser user); NewExternalUserEntity convert(RegisterUserInput input); RegisterUserEntity convert(FinalizeRegistrationInput input); UserLinks computeUserLinks(String basePath, Date updateDate);  }
@Test public void testConvertUserEntity() { Instant now = Instant.now(); Date nowDate = Date.from(now); UserEntity userEntity = new UserEntity(); userEntity.setCreatedAt(nowDate); userEntity.setEmail(USER_EMAIL); userEntity.setFirstname(USER_FIRSTNAME); userEntity.setId(USER_ID); userEntity.setLastConnectionAt(nowDate); userEntity.setLastname(USER_LASTNAME); userEntity.setPassword(USER_PASSWORD); userEntity.setPicture(USER_PICTURE); userEntity.setRoles(null); userEntity.setSource(USER_SOURCE); userEntity.setSourceId(USER_SOURCE_ID); userEntity.setStatus(USER_STATUS); userEntity.setUpdatedAt(nowDate); User responseUser = userMapper.convert(userEntity); assertNotNull(responseUser); assertEquals(USER_ID, responseUser.getId()); assertEquals(USER_EMAIL, responseUser.getEmail()); assertEquals(USER_FIRSTNAME, responseUser.getFirstName()); assertEquals(USER_LASTNAME, responseUser.getLastName()); assertEquals(USER_FIRSTNAME + ' ' + USER_LASTNAME, responseUser.getDisplayName()); }
@Test public void testConvertSearchableUser() { SearchableUser searchableUser = Mockito.mock(SearchableUser.class); Mockito.when(searchableUser.getDisplayName()).thenReturn(SEARCHABLE_USER_DISPLAY_NAME); Mockito.when(searchableUser.getEmail()).thenReturn(USER_EMAIL); Mockito.when(searchableUser.getFirstname()).thenReturn(USER_FIRSTNAME); Mockito.when(searchableUser.getId()).thenReturn(USER_ID); Mockito.when(searchableUser.getLastname()).thenReturn(USER_LASTNAME); Mockito.when(searchableUser.getReference()).thenReturn(SEARCHABLE_USER_REFERENCE); User responseUser = userMapper.convert(searchableUser); assertNotNull(responseUser); assertEquals(USER_ID, responseUser.getId()); assertEquals(USER_EMAIL, responseUser.getEmail()); assertEquals(USER_FIRSTNAME, responseUser.getFirstName()); assertEquals(USER_LASTNAME, responseUser.getLastName()); assertEquals(SEARCHABLE_USER_DISPLAY_NAME, responseUser.getDisplayName()); assertEquals(SEARCHABLE_USER_REFERENCE, responseUser.getReference()); }
@Test public void testConvertRegisterUserInput() { RegisterUserInput input = new RegisterUserInput(); input.setEmail(USER_EMAIL); input.setFirstname(USER_FIRSTNAME); input.setLastname(USER_LASTNAME); NewExternalUserEntity newExternalUserEntity = userMapper.convert(input); assertNotNull(newExternalUserEntity); assertEquals(USER_EMAIL, newExternalUserEntity.getEmail()); assertEquals(USER_FIRSTNAME, newExternalUserEntity.getFirstname()); assertEquals(USER_LASTNAME, newExternalUserEntity.getLastname()); }
@Test public void testConvertFinalizeRegistrationInput() { FinalizeRegistrationInput input = new FinalizeRegistrationInput(); input.setToken(USER_TOKEN); input.setPassword(USER_PASSWORD); input.setFirstname(USER_FIRSTNAME); input.setLastname(USER_LASTNAME); RegisterUserEntity registerUserEntity = userMapper.convert(input); assertNotNull(registerUserEntity); assertEquals(USER_TOKEN, registerUserEntity.getToken()); assertEquals(USER_PASSWORD, registerUserEntity.getPassword()); assertEquals(USER_FIRSTNAME, registerUserEntity.getFirstname()); assertEquals(USER_LASTNAME, registerUserEntity.getLastname()); }