|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2018 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
32 | 32 | import org.junit.jupiter.api.extension.ExtendWith;
|
33 | 33 | import org.mockito.Mock;
|
34 | 34 | import org.mockito.junit.jupiter.MockitoExtension;
|
35 |
| -import org.springframework.web.reactive.function.client.WebClientResponseException; |
36 | 35 | import reactor.core.publisher.Mono;
|
37 | 36 |
|
| 37 | +import org.springframework.web.reactive.function.client.WebClientResponseException; |
| 38 | + |
38 | 39 | import static org.assertj.core.api.Assertions.assertThat;
|
39 |
| -import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 40 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
40 | 41 | import static org.mockito.ArgumentMatchers.any;
|
41 | 42 | import static org.mockito.BDDMockito.given;
|
42 |
| -import static org.mockito.Mockito.doReturn; |
43 |
| -import static org.mockito.Mockito.doThrow; |
| 43 | +import static org.mockito.BDDMockito.willReturn; |
| 44 | +import static org.mockito.BDDMockito.willThrow; |
44 | 45 |
|
45 | 46 | /**
|
46 | 47 | * @author Rob Winch
|
@@ -168,14 +169,14 @@ public void getWhenNoMatchAndKeyIdMatchThenEmpty() {
|
168 | 169 | @Test
|
169 | 170 | public void getShouldRecoverAndReturnKeysAfterErrorCase() {
|
170 | 171 | given(this.matcher.matches(any())).willReturn(true);
|
171 |
| - this.source = new ReactiveRemoteJWKSource(Mono.fromSupplier(mockStringSupplier)); |
172 |
| - doThrow(WebClientResponseException.ServiceUnavailable.class).when(this.mockStringSupplier).get(); |
| 172 | + this.source = new ReactiveRemoteJWKSource(Mono.fromSupplier(this.mockStringSupplier)); |
| 173 | + willThrow(WebClientResponseException.ServiceUnavailable.class).given(this.mockStringSupplier).get(); |
173 | 174 | // first case: id provider has error state
|
174 |
| - assertThatThrownBy(() -> this.source.get(this.selector).block()) |
175 |
| - .isExactlyInstanceOf(WebClientResponseException.ServiceUnavailable.class); |
| 175 | + assertThatExceptionOfType(WebClientResponseException.ServiceUnavailable.class) |
| 176 | + .isThrownBy(() -> this.source.get(this.selector).block()); |
176 | 177 | // second case: id provider is healthy again
|
177 |
| - doReturn(this.server.url("/").toString()).when(this.mockStringSupplier).get(); |
178 |
| - var actual = this.source.get(this.selector).block(); |
| 178 | + willReturn(this.server.url("/").toString()).given(this.mockStringSupplier).get(); |
| 179 | + List<JWK> actual = this.source.get(this.selector).block(); |
179 | 180 | assertThat(actual).isNotEmpty();
|
180 | 181 | }
|
181 | 182 |
|
|
0 commit comments