TcpClient { public boolean applyAfterAspect(String callSitesKey, String aspectClass, String aspectMethod) throws IOException { Map obj = new LinkedHashMap(); obj.put("call", "applyAfterAspect"); obj.put("callSitesKey", callSitesKey); obj.put("aspectClass", aspectClass); obj.put("aspectMethod", aspectMethod); String stringResult = send(JSONValue.toJSONString(obj)); JSONObject jsonResult = (JSONObject) JSONValue.parse(stringResult); return isThatOk(jsonResult); } TcpClient(String hostname, int port);  TcpClient();  TcpClient(SocketChannel socketChannel); void disconnect(); List<String> getRegisteredCallSiteKeys(); String getNumberOfRegisteredCallSites(); String getCallSiteType(String target); boolean changeCallSiteTarget(String methodType, String oldTarget, String newTarget); boolean applyBeforeAspect(String callSitesKey, String aspectClass, String aspectMethod); boolean applyAfterAspect(String callSitesKey, String aspectClass, String aspectMethod);  }
@Test public void testApplyAfterAspect() throws Exception { final String expected_answer = "{\"result\":\"ok\",\"calledMethod\":\"applyAfterAspect\"}" + END_OF_INSTRUCTION; final String sent_call = "applyAfterAspect"; final String sent_callSitesKey = "HelloWorld.tick:(HelloWorld)void"; final String sent_aspectClass = "HelloWorld"; final String sent_aspectMethod = "onReturn"; SocketChannel socket = prepareRequestInjection(expected_answer); ArgumentCaptor<ByteBuffer> argument = forClass(ByteBuffer.class); TestableClient theClient = new TestableClient(socket); boolean ok = theClient.applyAfterAspect(sent_callSitesKey, sent_aspectClass, sent_aspectMethod); theClient.disconnect(); verify(socket).write(argument.capture()); String sent_message = getAnswerFromBuffer(argument.getValue()); JSONObject objIn = (JSONObject) JSONValue.parse(sent_message); assertEquals(sent_call, objIn.get("call")); assertEquals(sent_callSitesKey, objIn.get("callSitesKey")); assertEquals(sent_aspectClass, objIn.get("aspectClass")); assertEquals(sent_aspectMethod, objIn.get("aspectMethod")); assertTrue(ok); }