@Test public void request() throws Exception { final Nats nats = new MockNats(); final String subject = "test"; final String response = "This is a response."; nats.subscribe(subject, new MessageHandler() { @Override public void onMessage(Message message) { message.reply(response); } }); final boolean[] flag = new boolean[] { false }; nats.request(subject, 1, TimeUnit.SECONDS, new MessageHandler() { @Override public void onMessage(Message message) { Assert.assertEquals(message.getBody(), response); flag[0] = true; } }); Assert.assertTrue(flag[0], "Request response handler was not invoked."); }
@Override public Request request(String subject, long timeout, TimeUnit unit, MessageHandler... messageHandlers) { return request(subject, "", timeout, unit, messageHandlers); }
MockNats implements Nats { @Override public Request request(String subject, long timeout, TimeUnit unit, MessageHandler... messageHandlers) { return request(subject, "", timeout, unit, messageHandlers); } }
MockNats implements Nats { @Override public Request request(String subject, long timeout, TimeUnit unit, MessageHandler... messageHandlers) { return request(subject, "", timeout, unit, messageHandlers); }  }
MockNats implements Nats { @Override public Request request(String subject, long timeout, TimeUnit unit, MessageHandler... messageHandlers) { return request(subject, "", timeout, unit, messageHandlers); }  @Override boolean isConnected(); @Override boolean isClosed(); @Override void close(); @Override void publish(String subject); @Override void publish(String subject, String body); @Override void publish(String subject, String body, String replyTo); @Override Registration publish(String subject, long period, TimeUnit unit); @Override Registration publish(String subject, String body, long period, TimeUnit unit); @Override Registration publish(final String subject, final String body, final String replyTo, long period, TimeUnit unit); @Override Subscription subscribe(String subject, MessageHandler... messageHandlers); @Override Subscription subscribe(String subject, String queueGroup, MessageHandler... messageHandlers); @Override Subscription subscribe(String subject, Integer maxMessages, MessageHandler... messageHandlers); @Override Subscription subscribe(String subject, String queueGroup, Integer maxMessages, MessageHandler... messageHandlers); @Override Request request(String subject, long timeout, TimeUnit unit, MessageHandler... messageHandlers); @Override Request request(String subject, String message, long timeout, TimeUnit unit, MessageHandler... messageHandlers); @Override Request request(final String subject, String message, long timeout, TimeUnit unit, final Integer maxReplies, MessageHandler... messageHandlers); }
MockNats implements Nats { @Override public Request request(String subject, long timeout, TimeUnit unit, MessageHandler... messageHandlers) { return request(subject, "", timeout, unit, messageHandlers); }  @Override boolean isConnected(); @Override boolean isClosed(); @Override void close(); @Override void publish(String subject); @Override void publish(String subject, String body); @Override void publish(String subject, String body, String replyTo); @Override Registration publish(String subject, long period, TimeUnit unit); @Override Registration publish(String subject, String body, long period, TimeUnit unit); @Override Registration publish(final String subject, final String body, final String replyTo, long period, TimeUnit unit); @Override Subscription subscribe(String subject, MessageHandler... messageHandlers); @Override Subscription subscribe(String subject, String queueGroup, MessageHandler... messageHandlers); @Override Subscription subscribe(String subject, Integer maxMessages, MessageHandler... messageHandlers); @Override Subscription subscribe(String subject, String queueGroup, Integer maxMessages, MessageHandler... messageHandlers); @Override Request request(String subject, long timeout, TimeUnit unit, MessageHandler... messageHandlers); @Override Request request(String subject, String message, long timeout, TimeUnit unit, MessageHandler... messageHandlers); @Override Request request(final String subject, String message, long timeout, TimeUnit unit, final Integer maxReplies, MessageHandler... messageHandlers);  }