@Test public void interceptorsPreHandleExceptionTest() throws IOException { final String requestGood = "{\n" + " \"id\": 0,\n" + " \"jsonrpc\": \"2.0\",\n" + " \"method\": \"testMethod\",\n" + " \"params\": [\"test.cool\"]\n" + " }\n" + "}"; String exceptionMessage = "123"; String responseError = "{\"jsonrpc\":\"2.0\",\"id\":0,\"error\":{\"code\":-32001,\"message\":\"" + exceptionMessage + "\",\"data\":{\"exceptionTypeName\":\"java.lang.RuntimeException\",\"message\":\"" + exceptionMessage + "\"}}}"; // mockInterceptor.preHandle( anyObject(), anyObject(Method.class), eq(new ArrayList<JsonNode>() {{ add(mapper.readTree(requestGood).at("/params/0")); }}) ); expectLastCall().andThrow(new RuntimeException(exceptionMessage)); replay(mockInterceptor); jsonRpcServer.handleRequest(new ByteArrayInputStream(requestGood.getBytes(StandardCharsets.UTF_8)), byteArrayOutputStream); assertEquals(responseError, byteArrayOutputStream.toString("UTF-8").trim()); verify(mockInterceptor); }
mockInterceptor.preHandle( anyObject(), anyObject(Method.class),
interceptor.preHandle(target, methodArgs.method, methodArgs.arguments);