Fixed exception while logging in with unknown user

This commit is contained in:
Nanne Baars
2017-03-23 21:46:21 +01:00
parent 5156b05aac
commit 9833637abf
2 changed files with 30 additions and 1 deletions

View File

@ -0,0 +1,25 @@
package org.owasp.webgoat.users;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class UserServiceTest {
@Mock
private UserRepository userRepository;
@Test(expected = UsernameNotFoundException.class)
public void shouldThrowExceptionWhenUserIsNotFound() {
when(userRepository.findByUsername(any())).thenReturn(null);
UserService userService = new UserService(userRepository);
userService.loadUserByUsername("unknown");
}
}