### Question:
Service { public void callService(ServiceRequest request, ServiceCallback cb) { String callServceId = "call_service:" + this.name + ":" + this.ros.nextId(); this.ros.registerServiceCallback(callServceId, cb); JsonObject call = Json.createObjectBuilder() .add(JRosbridge.FIELD_OP, JRosbridge.OP_CODE_CALL_SERVICE) .add(JRosbridge.FIELD_ID, callServceId) .add(JRosbridge.FIELD_TYPE, this.type) .add(JRosbridge.FIELD_SERVICE, this.name) .add(JRosbridge.FIELD_ARGS, request.toJsonObject()).build(); this.ros.send(call); } Service(Ros ros, String name, String type); Ros getRos(); String getName(); String getType(); boolean isAdvertised(); void callService(ServiceRequest request, ServiceCallback cb); void sendResponse(ServiceResponse response, String id); void advertiseService(CallServiceCallback cb); void unadvertiseService(); synchronized ServiceResponse callServiceAndWait(
			ServiceRequest request);  }### Answer:
@Test public void testCallService() { ServiceRequest req = new ServiceRequest("{\"test1\":\"test2\"}"); DummyServiceCallback cb = new DummyServiceCallback(); s1.callService(req, cb); while (DummyHandler.latest == null) { Thread.yield(); } assertNotNull(DummyHandler.latest); assertEquals(5, DummyHandler.latest.size()); assertEquals(JRosbridge.OP_CODE_CALL_SERVICE, DummyHandler.latest.getString(JRosbridge.FIELD_OP)); assertEquals("call_service:myService:0", DummyHandler.latest.getString(JRosbridge.FIELD_ID)); assertEquals("myType", DummyHandler.latest.getString(JRosbridge.FIELD_TYPE)); assertEquals("myService", DummyHandler.latest.getString(JRosbridge.FIELD_SERVICE)); assertEquals("{\"test1\":\"test2\"}", DummyHandler.latest .getJsonObject(JRosbridge.FIELD_ARGS).toString()); JsonObject toSend = Json .createObjectBuilder() .add("echo", Json.createObjectBuilder() .add(JRosbridge.FIELD_OP, JRosbridge.OP_CODE_SERVICE_RESPONSE) .add(JRosbridge.FIELD_ID, "call_service:myService:0") .add(JRosbridge.FIELD_RESULT, false) .add(JRosbridge.FIELD_VALUES, Json.createObjectBuilder() .add("test3", "test4").build()) .build().toString()).build(); ros.send(toSend); while (cb.latest == null) { Thread.yield(); } assertNotNull(cb.latest); assertEquals("{\"test3\":\"test4\"}", cb.latest.toString()); }