### Question:
Topic { public void subscribe(TopicCallback cb) { this.ros.registerTopicCallback(this.name, cb); this.callbacks.add(cb); String subscribeId = "subscribe:" + this.name + ":" + this.ros.nextId(); this.ids.add(subscribeId); JsonObject call = Json.createObjectBuilder() .add(JRosbridge.FIELD_OP, JRosbridge.OP_CODE_SUBSCRIBE) .add(JRosbridge.FIELD_ID, subscribeId) .add(JRosbridge.FIELD_TYPE, this.type) .add(JRosbridge.FIELD_TOPIC, this.name) .add(JRosbridge.FIELD_COMPRESSION, this.compression.toString()) .add(JRosbridge.FIELD_THROTTLE_RATE, this.throttleRate).build(); this.ros.send(call); this.isSubscribed = true; } Topic(Ros ros, String name, String type);  Topic(Ros ros, String name, String type,
			JRosbridge.CompressionType compression);  Topic(Ros ros, String name, String type, int throttleRate);  Topic(Ros ros, String name, String type,
			JRosbridge.CompressionType compression, int throttleRate); Ros getRos(); String getName(); String getType(); boolean isAdvertised(); boolean isSubscribed(); JRosbridge.CompressionType getCompression(); int getThrottleRate(); void subscribe(TopicCallback cb); void unsubscribe(); void advertise(); void unadvertise(); void publish(Message message);  }### Answer:
@Test public void testSubscribe() { DummyTopicCallback cb = new DummyTopicCallback(); t1.subscribe(cb); assertNull(cb.latest); ros.send(Json .createObjectBuilder() .add("echo", "{\"" + JRosbridge.FIELD_OP + "\":\"" + JRosbridge.OP_CODE_PUBLISH + "\",\"" + JRosbridge.FIELD_TOPIC + "\":\"myTopic1\",\"" + JRosbridge.FIELD_MESSAGE + "\":{\"test1\":\"test2\"}}").build()); while (cb.latest == null) { Thread.yield(); } assertNotNull(DummyHandler.latest); assertEquals( "{\"op\":\"subscribe\",\"id\":\"subscribe:myTopic1:0\",\"type\":\"myType1\"," + "\"topic\":\"myTopic1\",\"compression\":\"none\",\"throttle_rate\":0}", DummyHandler.latest.toString()); assertNotNull(cb.latest); assertEquals("{\"test1\":\"test2\"}", cb.latest.toString()); assertFalse(t1.isAdvertised()); assertTrue(t1.isSubscribed()); }