JwtUserFactory { public static JwtUser create(User user) { return new JwtUser( user.getId(), user.getUsername(), user.getFirstname(), user.getLastname(), user.getPassword(), user.getEmail(), user.getEnabled(), user.getLastPasswordResetDate().getTime(), mapUserRolesToGrantedAuthorities(user.getRoles()), user.getRoles()); } private  JwtUserFactory(); static JwtUser create(User user);  }
@Test public void whenCreateCalledWithUserModelThenExpectJwtUserDetailsToBeReturned() { final User user = new User(); user.setId(USER_ID); user.setUsername(USERNAME); user.setPassword(PASSWORD); user.setFirstname(FIRSTNAME); user.setLastname(LASTNAME); user.setEmail(EMAIL); user.setEnabled(USER_ENABLED); user.setLastPasswordResetDate(LAST_PASSWORD_RESET_DATE); user.setRoles(createRoles(user)); final JwtUser userDetails = JwtUserFactory.create(user); assertEquals(USER_ID, userDetails.getId()); assertEquals(USERNAME, userDetails.getUsername()); assertEquals(PASSWORD, userDetails.getPassword()); assertEquals(FIRSTNAME, userDetails.getFirstname()); assertEquals(LASTNAME, userDetails.getLastname()); assertEquals(EMAIL, userDetails.getEmail()); assertEquals(USER_ENABLED, userDetails.isEnabled()); assertEquals(LAST_PASSWORD_RESET_DATE.getTime(), userDetails.getLastPasswordResetDate()); assertTrue(userDetails.getRoles().contains(RoleName.ROLE_ADMIN.name())); assertTrue(userDetails.getRoles().contains(RoleName.ROLE_USER.name())); assertTrue( userDetails .getAuthorities() .contains(new SimpleGrantedAuthority(RoleName.ROLE_ADMIN.name()))); assertTrue( userDetails .getAuthorities() .contains(new SimpleGrantedAuthority(RoleName.ROLE_USER.name()))); }