@Test public void testValidateUserNullUsername() { when(jwtService.getUsername(TOKEN, SECRET)).thenReturn(null); assertNull(userService.validateUser(TOKEN, SECRET)); }
public User validateUser(String token, String secret) { String username = jwtService.getUsername(token, secret); if (username != null ) { User user = userRepository.findByUsername(username); if (user != null && token.equals(user.getToken()) && jwtService.isValid(token, secret)) { return user; } } return null; }
UserService { public User validateUser(String token, String secret) { String username = jwtService.getUsername(token, secret); if (username != null ) { User user = userRepository.findByUsername(username); if (user != null && token.equals(user.getToken()) && jwtService.isValid(token, secret)) { return user; } } return null; } }
UserService { public User validateUser(String token, String secret) { String username = jwtService.getUsername(token, secret); if (username != null ) { User user = userRepository.findByUsername(username); if (user != null && token.equals(user.getToken()) && jwtService.isValid(token, secret)) { return user; } } return null; }  }
UserService { public User validateUser(String token, String secret) { String username = jwtService.getUsername(token, secret); if (username != null ) { User user = userRepository.findByUsername(username); if (user != null && token.equals(user.getToken()) && jwtService.isValid(token, secret)) { return user; } } return null; }  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 validateUser(String token, String secret) { String username = jwtService.getUsername(token, secret); if (username != null ) { User user = userRepository.findByUsername(username); if (user != null && token.equals(user.getToken()) && jwtService.isValid(token, secret)) { return user; } } return null; }  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);  }