|
28 | 28 | import java.util.stream.Stream;
|
29 | 29 |
|
30 | 30 | import static org.assertj.core.api.Assertions.assertThat;
|
| 31 | +import static org.mockito.ArgumentMatchers.anyString; |
| 32 | +import static org.mockito.ArgumentMatchers.same; |
31 | 33 | import static org.mockito.Mockito.mock;
|
| 34 | +import static org.mockito.Mockito.verify; |
| 35 | +import static org.mockito.Mockito.verifyNoInteractions; |
32 | 36 |
|
33 | 37 | class UnexpectedExceptionMapperTest {
|
34 | 38 |
|
| 39 | + private final Monitor monitor = mock(Monitor.class); |
| 40 | + private final UnexpectedExceptionMapper mapper = new UnexpectedExceptionMapper(monitor); |
| 41 | + |
35 | 42 | @ParameterizedTest
|
36 | 43 | @ArgumentsSource(JakartaApiExceptions.class)
|
| 44 | + void toResponse_jakartaExceptions(Throwable throwable, int expectedCode) { |
| 45 | + try (var response = mapper.toResponse(throwable)) { |
| 46 | + assertThat(response.getStatus()).isEqualTo(expectedCode); |
| 47 | + assertThat(response.getStatusInfo().getReasonPhrase()).isNotBlank(); |
| 48 | + assertThat(response.getEntity()).isNull(); |
| 49 | + verifyNoInteractions(monitor); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + @ParameterizedTest |
37 | 54 | @ArgumentsSource(JavaExceptions.class)
|
38 | 55 | void toResponse_unexpectedExceptions(Throwable throwable, int expectedCode) {
|
39 |
| - var mapper = new UnexpectedExceptionMapper(mock(Monitor.class)); |
40 |
| - |
41 | 56 | try (var response = mapper.toResponse(throwable)) {
|
42 | 57 | assertThat(response.getStatus()).isEqualTo(expectedCode);
|
43 | 58 | assertThat(response.getStatusInfo().getReasonPhrase()).isNotBlank();
|
44 | 59 | assertThat(response.getEntity()).isNull();
|
| 60 | + verify(monitor).severe(anyString(), same(throwable)); |
45 | 61 | }
|
46 | 62 | }
|
47 | 63 |
|
|
0 commit comments