Shogun2AuthenticationProviderTest.java 文件源码

java
阅读 27 收藏 0 点赞 0 评论 0

项目:shogun2 作者:
/**
 * Tests whether a {@link DisabledException} is thrown when the user is not
 * active.
 */
@Test(expected=DisabledException.class)
public void authenticate_shouldThrowDisabledExceptionIfUserIsInactive() {

    // 1. Mock an authentication request object
    final String shogun2UserName = "user";
    final String correctPassword = "correctPassword";
    final User userToAuth = createUserMock(shogun2UserName, correctPassword);

    // set user as inactive
    userToAuth.setActive(false);

    // 2. Mock the auth request for the inactive user
    Authentication authRequest = mock(Authentication.class);
    when(authRequest.getName()).thenReturn(shogun2UserName);
    when(authRequest.getCredentials()).thenReturn(correctPassword);

    // 3. Mock the userDao
    when(userDao.findByAccountName(shogun2UserName)).thenReturn(userToAuth);

    // 4. Call the authenticate method with the mocked object to provoke
    // the expected DisabledException
    authProvider.authenticate(authRequest);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号