|
52 | 52 | import static org.mockito.ArgumentMatchers.any;
|
53 | 53 | import static org.mockito.ArgumentMatchers.anyInt;
|
54 | 54 | import static org.mockito.BDDMockito.given;
|
55 |
| -import static org.mockito.Mockito.mock; |
56 |
| -import static org.mockito.Mockito.verify; |
57 |
| -import static org.mockito.Mockito.when; |
| 55 | +import static org.mockito.BDDMockito.mock; |
| 56 | +import static org.mockito.BDDMockito.verify; |
58 | 57 |
|
59 | 58 | /**
|
60 | 59 | * Tests for {@link JdbcUserDetailsManager}
|
@@ -373,21 +372,39 @@ public void createNewAuthenticationUsesNullPasswordToKeepPassordsSave() {
|
373 | 372 | @Test
|
374 | 373 | public void setUserDetailsMapperWithNullMapperThrowsException() {
|
375 | 374 | assertThatExceptionOfType(IllegalArgumentException.class)
|
376 |
| - .isThrownBy(() -> this.manager.setUserDetailsMapper(null)) |
377 |
| - .withMessage("userDetailsMapper cannot be null"); |
| 375 | + .isThrownBy(() -> this.manager.setUserDetailsMapper(null)) |
| 376 | + .withMessage("userDetailsMapper cannot be null"); |
378 | 377 | }
|
379 | 378 |
|
380 | 379 | @Test
|
381 | 380 | public void setUserDetailsMapperWithMockMapper() throws SQLException {
|
382 | 381 | RowMapper<UserDetails> mockMapper = mock(RowMapper.class);
|
383 |
| - when(mockMapper.mapRow(any(), anyInt())).thenReturn(joe); |
| 382 | + given(mockMapper.mapRow(any(), anyInt())).willReturn(joe); |
384 | 383 | this.manager.setUserDetailsMapper(mockMapper);
|
385 | 384 | insertJoe();
|
386 | 385 | UserDetails newJoe = this.manager.loadUserByUsername("joe");
|
387 | 386 | assertThat(joe).isEqualTo(newJoe);
|
388 | 387 | verify(mockMapper).mapRow(any(), anyInt());
|
389 | 388 | }
|
390 | 389 |
|
| 390 | + @Test |
| 391 | + public void setGrantedAuthorityMapperWithNullMapperThrowsException() { |
| 392 | + assertThatExceptionOfType(IllegalArgumentException.class) |
| 393 | + .isThrownBy(() -> this.manager.setGrantedAuthorityMapper(null)) |
| 394 | + .withMessage("grantedAuthorityMapper cannot be null"); |
| 395 | + } |
| 396 | + |
| 397 | + @Test |
| 398 | + public void setGrantedAuthorityMapperWithMockMapper() throws SQLException { |
| 399 | + RowMapper<GrantedAuthority> mockMapper = mock(RowMapper.class); |
| 400 | + GrantedAuthority mockAuthority = new SimpleGrantedAuthority("ROLE_MOCK"); |
| 401 | + given(mockMapper.mapRow(any(), anyInt())).willReturn(mockAuthority); |
| 402 | + this.manager.setGrantedAuthorityMapper(mockMapper); |
| 403 | + List<GrantedAuthority> authGroup = this.manager.findGroupAuthorities("GROUP_0"); |
| 404 | + assertThat(authGroup.get(0)).isEqualTo(mockAuthority); |
| 405 | + verify(mockMapper).mapRow(any(), anyInt()); |
| 406 | + } |
| 407 | + |
391 | 408 | private Authentication authenticateJoe() {
|
392 | 409 | UsernamePasswordAuthenticationToken auth = UsernamePasswordAuthenticationToken.authenticated("joe", "password",
|
393 | 410 | joe.getAuthorities());
|
|
0 commit comments