AbstractWebMiddleware implements Middleware<HttpRequest, HttpResponse, NREQ, NRES> { protected HttpResponse castToHttpResponse(NRES objectResponse) { if (objectResponse == null) { return null; } else if (objectResponse instanceof HttpResponse) { return (HttpResponse) objectResponse; } else { throw new MisconfigurationException("web.RESPONSE_TYPE_MISMATCH"); } }    }
@Test void test() { AbstractWebMiddleware<HttpRequest, String> middleware = new AbstractWebMiddleware<HttpRequest, String>() { @Override public HttpResponse handle(HttpRequest request, MiddlewareChain<HttpRequest, String, ?, ?> chain) { return HttpResponse.of("hello"); } }; assertThatThrownBy(() -> middleware.castToHttpResponse("")) .isInstanceOf(MisconfigurationException.class); }