@Test public void testCreateUserToken() { User u = new User(USERNAME, ENCODED_PASS, SALT, ROLE); when(jwtService.createToken(USERNAME, SECRET, date)).thenReturn(TOKEN); when(userRepository.findByUsername(USERNAME)).thenReturn(u); when(userRepository.save(u)).thenReturn(u); User u2 = userService.createUserToken(USERNAME, SECRET); verify(userRepository).save(u); assertEquals(TOKEN, u2.getToken()); }
public User createUserToken(String username, String secret) { String token = jwtService.createToken(username, secret, dateGenerator.getExpirationDate()); User u = userRepository.findByUsername(username); u.setToken(token); return userRepository.save(u); }
UserService { public User createUserToken(String username, String secret) { String token = jwtService.createToken(username, secret, dateGenerator.getExpirationDate()); User u = userRepository.findByUsername(username); u.setToken(token); return userRepository.save(u); } }
UserService { public User createUserToken(String username, String secret) { String token = jwtService.createToken(username, secret, dateGenerator.getExpirationDate()); User u = userRepository.findByUsername(username); u.setToken(token); return userRepository.save(u); }  }
UserService { public User createUserToken(String username, String secret) { String token = jwtService.createToken(username, secret, dateGenerator.getExpirationDate()); User u = userRepository.findByUsername(username); u.setToken(token); return userRepository.save(u); }  void create(String username, String password, String role); User isLoginValid(String username, String pass); User findByUsername(String username); User createUserToken(String username, String secret); User validateUser(String token, String secret); }
UserService { public User createUserToken(String username, String secret) { String token = jwtService.createToken(username, secret, dateGenerator.getExpirationDate()); User u = userRepository.findByUsername(username); u.setToken(token); return userRepository.save(u); }  void create(String username, String password, String role); User isLoginValid(String username, String pass); User findByUsername(String username); User createUserToken(String username, String secret); User validateUser(String token, String secret);  }