Skip to content

Commit 6fceecb

Browse files
committed
test: Interceptor can catch decorator failures
1 parent 09d5ef2 commit 6fceecb

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/test/java/com/retailsvc/http/internal/DispatchHandlerTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.retailsvc.http.internal;
22

3+
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
34
import static java.net.HttpURLConnection.HTTP_OK;
45
import static org.assertj.core.api.Assertions.assertThat;
56
import static org.mockito.ArgumentMatchers.any;
@@ -123,4 +124,33 @@ void interceptorObservesDecoratedResponse() throws Exception {
123124
assertThat(seen.get()).isNotNull();
124125
assertThat(seen.get().headers()).containsEntry("X-Stamped", "yes");
125126
}
127+
128+
@Test
129+
void interceptorCanCatchDecoratorFailure() throws Exception {
130+
RequestHandler ok = req -> Response.status(HTTP_OK);
131+
AtomicBoolean caught = new AtomicBoolean(false);
132+
RequestInterceptor catcher =
133+
(request, next) -> {
134+
try {
135+
return next.proceed();
136+
} catch (RuntimeException e) {
137+
caught.set(true);
138+
return Response.status(HTTP_INTERNAL_ERROR);
139+
}
140+
};
141+
ResponseDecorator boom =
142+
(req, resp) -> {
143+
throw new IllegalStateException("boom");
144+
};
145+
146+
HttpExchange ex = stubExchange();
147+
withRequest(
148+
"get-x",
149+
() -> {
150+
dispatcher(Map.of("get-x", ok), List.of(catcher), List.of(boom)).handle(ex);
151+
return null;
152+
});
153+
154+
assertThat(caught.get()).isTrue();
155+
}
126156
}

0 commit comments

Comments
 (0)