|
17 | 17 | package org.springframework.security.oauth2.client.web.server;
|
18 | 18 |
|
19 | 19 | import org.junit.jupiter.api.Test;
|
| 20 | +import reactor.core.publisher.Mono; |
20 | 21 |
|
21 | 22 | import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
|
22 | 23 | import org.springframework.mock.web.server.MockServerWebExchange;
|
23 | 24 | import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
|
24 | 25 | import org.springframework.security.oauth2.client.registration.ClientRegistration;
|
25 | 26 | import org.springframework.security.oauth2.client.registration.TestClientRegistrations;
|
26 | 27 | import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
| 28 | +import org.springframework.web.server.ServerWebExchange; |
27 | 29 | import org.springframework.web.server.WebSession;
|
28 |
| -import reactor.core.publisher.Mono; |
29 | 30 |
|
30 | 31 | import static org.assertj.core.api.Assertions.assertThat;
|
31 | 32 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
| 33 | +import static org.mockito.BDDMockito.given; |
32 | 34 | import static org.mockito.Mockito.mock;
|
33 |
| -import static org.mockito.Mockito.when; |
34 | 35 |
|
35 | 36 | /**
|
36 | 37 | * @author Rob Winch
|
@@ -203,25 +204,29 @@ public void removeAuthorizedClientWhenClient1Client2SavedAndClient1RemovedThenCl
|
203 | 204 | assertThat(loadedAuthorizedClient2).isNotNull();
|
204 | 205 | assertThat(loadedAuthorizedClient2).isSameAs(authorizedClient2);
|
205 | 206 | }
|
206 |
| - |
| 207 | + |
207 | 208 | @Test
|
208 | 209 | public void saveAuthorizedClientWhenSessionIsNullThenThrowIllegalArgumentException() {
|
209 |
| - MockServerWebExchange mockedExchange = mock(MockServerWebExchange.class); |
210 |
| - when(mockedExchange.getSession()).thenReturn(Mono.empty()); |
| 210 | + ServerWebExchange exchange = mock(ServerWebExchange.class); |
| 211 | + given(exchange.getSession()).willReturn(Mono.empty()); |
211 | 212 | OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(this.registration1, this.principalName1,
|
212 | 213 | mock(OAuth2AccessToken.class));
|
213 |
| - assertThatIllegalArgumentException().isThrownBy( |
214 |
| - () -> authorizedClientRepository.saveAuthorizedClient(authorizedClient, null, mockedExchange).block()) |
215 |
| - .withMessage("session cannot be null"); |
| 214 | + // @formatter:off |
| 215 | + assertThatIllegalArgumentException() |
| 216 | + .isThrownBy(() -> this.authorizedClientRepository.saveAuthorizedClient(authorizedClient, null, exchange).block()) |
| 217 | + .withMessage("session cannot be null"); |
| 218 | + // @formatter:on |
216 | 219 | }
|
217 |
| - |
| 220 | + |
218 | 221 | @Test
|
219 | 222 | public void removeAuthorizedClientWhenSessionIsNullThenThrowIllegalArgumentException() {
|
220 |
| - MockServerWebExchange mockedExchange = mock(MockServerWebExchange.class); |
221 |
| - when(mockedExchange.getSession()).thenReturn(Mono.empty()); |
222 |
| - assertThatIllegalArgumentException().isThrownBy( |
223 |
| - () -> authorizedClientRepository.removeAuthorizedClient(this.registrationId1, null, mockedExchange).block()) |
224 |
| - .withMessage("session cannot be null"); |
| 223 | + ServerWebExchange exchange = mock(ServerWebExchange.class); |
| 224 | + given(exchange.getSession()).willReturn(Mono.empty()); |
| 225 | + // @formatter:off |
| 226 | + assertThatIllegalArgumentException() |
| 227 | + .isThrownBy(() -> this.authorizedClientRepository.removeAuthorizedClient(this.registrationId1, null, exchange).block()) |
| 228 | + .withMessage("session cannot be null"); |
| 229 | + // @formatter:on |
225 | 230 | }
|
226 | 231 |
|
227 | 232 | }
|
0 commit comments