### Question:
Service { public void advertiseService(CallServiceCallback cb) { this.ros.registerCallServiceCallback(this.name, cb); JsonObject call = Json.createObjectBuilder() .add(JRosbridge.FIELD_OP, JRosbridge.OP_CODE_ADVERTISE_SERVICE) .add(JRosbridge.FIELD_TYPE, this.type) .add(JRosbridge.FIELD_SERVICE, this.name).build(); this.ros.send(call); this.isAdvertised = true; } 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 testAdvertiseService() { DummyCallServiceCallback cb = new DummyCallServiceCallback(); s1.advertiseService(cb); assertNull(cb.latest); while (DummyHandler.latest == null) { Thread.yield(); } assertNotNull(DummyHandler.latest); assertEquals( "{\"op\":\"advertise_service\",\"type\":\"myType\"," + "\"service\":\"myService\"}", DummyHandler.latest.toString()); assertTrue(s1.isAdvertised()); ros.send(Json .createObjectBuilder() .add("echo", "{\"" + JRosbridge.FIELD_OP + "\":\"" + JRosbridge.OP_CODE_CALL_SERVICE + "\",\"" + JRosbridge.FIELD_ID + "\":\"myServiceId\",\"" + JRosbridge.FIELD_SERVICE + "\":\"myService\",\"" + JRosbridge.FIELD_ARGS + "\":{\"test1\":\"test2\"}}").build()); while (cb.latest == null) { Thread.yield(); } assertNotNull(cb.latest); assertEquals("{\"test1\":\"test2\"}", cb.latest.toString()); assertEquals("myServiceId", cb.latest.getId()); }