DefaultAuthenticationService implements AuthenticationService { @Override public boolean userPasswordCheck(final String username, final String password) { final UserEntity userEntity = userService.findByName(username); return userEntity != null && userService.matches(password, userEntity.getPassword()); } @Autowired  DefaultAuthenticationService(final UserService userService, final DateTimeService dateTimeService); @Override boolean userPasswordCheck(final String username, final String password); @Override String authenticationToken(final String username, final String password); @Override String anonymousToken();  }
@Test public void testUserPasswordCheck() { final UserEntity userEntity = new UserEntity(); userEntity.setPassword(VALID_PASSWORD); Mockito.when(mockUserService.findByName(VALID_USERNAME)).thenReturn(userEntity); Mockito.when(mockUserService.matches(VALID_PASSWORD, VALID_PASSWORD)).thenReturn(true); Assert.assertTrue(defaultAuthenticationService.userPasswordCheck(VALID_USERNAME, VALID_PASSWORD)); Mockito.verify(mockUserService).findByName(VALID_USERNAME); Mockito.verify(mockUserService).matches(VALID_PASSWORD, VALID_PASSWORD); }
@Test public void testUserCheckInvalidPassword() { final UserEntity userEntity = new UserEntity(); userEntity.setPassword(VALID_PASSWORD); Mockito.when(mockUserService.findByName(VALID_USERNAME)).thenReturn(userEntity); Mockito.when(mockUserService.matches(INVALID_PASSWORD, VALID_PASSWORD)).thenReturn(false); Assert.assertFalse(defaultAuthenticationService.userPasswordCheck(VALID_USERNAME, INVALID_PASSWORD)); Mockito.verify(mockUserService).findByName(VALID_USERNAME); Mockito.verify(mockUserService).matches(INVALID_PASSWORD, VALID_PASSWORD); }
@Test public void testUserCheckUserNotFound() { Mockito.when(mockUserService.findByName(VALID_USERNAME)).thenReturn(null); Assert.assertFalse(defaultAuthenticationService.userPasswordCheck(VALID_USERNAME, VALID_PASSWORD)); Mockito.verify(mockUserService).findByName(VALID_USERNAME); }