@Test public void interceptorsPostHandleExceptionTest() 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 returnString = "test"; String responseError = "{\"jsonrpc\":\"2.0\",\"id\":0,\"error\":{\"code\":-32001,\"message\":\"" + exceptionMessage + "\",\"data\":{\"exceptionTypeName\":\"java.lang.RuntimeException\",\"message\":\"" + exceptionMessage + "\"}}}"; // expect(mockService.testMethod(mapper.readTree(requestGood).at("/params/0").asText())).andReturn(returnString); mockInterceptor.postHandle( anyObject(), anyObject(Method.class), eq(new ArrayList<JsonNode>() {{ add(mapper.readTree(requestGood).at("/params/0")); }}), eq(new TextNode(returnString)) ); expectLastCall().andThrow(new RuntimeException(exceptionMessage)); replay(mockService, mockInterceptor); jsonRpcServer.handleRequest(new ByteArrayInputStream(requestGood.getBytes(StandardCharsets.UTF_8)), byteArrayOutputStream); assertEquals(responseError, byteArrayOutputStream.toString("UTF-8").trim()); verify(mockService, mockInterceptor); }
expectLastCall().times(1); expect(mockService.overloadedMethod("test.cool", "test.ru")).andReturn("test.ru"); mockInterceptor.postHandle( anyObject(), anyObject(Method.class),
interceptor.postHandle(target, methodArgs.method, methodArgs.arguments, result);