WebSocketUtilImpl implements WebSocketUtil { @Override public void unSubscribeHandler(@NotNull String channel, @NotNull SubscriptionHandler handler) { if (!messageBus.isHandlerSubscribed(handler, channel)) { return; } try { messageBus.unsubscribe(channel, handler); } catch (WebSocketException e) { Log.error(getClass(), e); } } @Inject  WebSocketUtilImpl(MessageBus messageBus); @Override void subscribeHandler(@NotNull String channel, @NotNull SubscriptionHandler handler); @Override void unSubscribeHandler(@NotNull String channel, @NotNull SubscriptionHandler handler);  }
@Test public void handlerShouldBeUnSubscribed() throws Exception { when(messageBus.isHandlerSubscribed(handler, SOME_TEXT)).thenReturn(true); util.unSubscribeHandler(SOME_TEXT, handler); verify(messageBus).unsubscribe(SOME_TEXT, handler); }
@Test public void handlerShouldNotBeUnSubscribedIfItIsUnSubscribed() throws Exception { when(messageBus.isHandlerSubscribed(handler, SOME_TEXT)).thenReturn(false); util.unSubscribeHandler(SOME_TEXT, handler); verify(messageBus, never()).unsubscribe(anyString(), any(SubscriptionHandler.class)); }