TcpClient { public boolean changeCallSiteTarget(String methodType, String oldTarget, String newTarget) throws IOException { Map obj = new LinkedHashMap(); obj.put("call", "changeCallSiteTarget"); obj.put("methodType", methodType); obj.put("oldTarget", oldTarget); obj.put("newTarget", newTarget); 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 testChangeCallSiteTarget() throws Exception { final String expected_answer = "{\"result\":\"ok\",\"calledMethod\":\"changeCallSiteTarget\"}" + END_OF_INSTRUCTION; final String sent_call = "changeCallSiteTarget"; final String sent_methodType = "virtual"; final String sent_oldTarget = "HelloWorld.tick:(HelloWorld)void"; final String sent_newTarget = "HelloWorld.tack:()V"; SocketChannel socket = prepareRequestInjection(expected_answer); ArgumentCaptor<ByteBuffer> argument = forClass(ByteBuffer.class); TestableClient theClient = new TestableClient(socket); boolean ok = theClient.changeCallSiteTarget(sent_methodType, sent_oldTarget, sent_newTarget); 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_methodType, objIn.get("methodType")); assertEquals(sent_oldTarget, objIn.get("oldTarget")); assertEquals(sent_newTarget, objIn.get("newTarget")); assertTrue(ok); }