TweetFXTradeService { @Subscribe @AllowConcurrentEvents public void handleEvent(T payLoad) { EventPayLoadToTweet<K, T> eventPayLoadToTweet = this.eventPayLoadToTweetMap.get(payLoad.getEvent()); if (eventPayLoadToTweet != null) { try { String tweet = eventPayLoadToTweet.toTweet(payLoad); if (tweet != null) { twitter.timelineOperations().updateStatus(tweet); } } catch (Exception ex) { LOG.error("error encountered whilst handling payload->" + payLoad.getPayLoad(), ex); } } }  @Subscribe @AllowConcurrentEvents void handleEvent(T payLoad);  }
@SuppressWarnings("unchecked") @Test public void handleEvent() { Twitter twitter = mock(Twitter.class); Map<Event, EventPayLoadToTweet<JSONObject, TradeEventPayLoad>> eventPayLoadToTweetMap = Maps.newHashMap(); EventPayLoadToTweet<JSONObject, TradeEventPayLoad> handler = mock(EventPayLoadToTweet.class); eventPayLoadToTweetMap.put(TradeEvents.TAKE_PROFIT_FILLED, handler); TweetFXTradeService<JSONObject, TradeEventPayLoad> service = new TweetFXTradeService<JSONObject, TradeEventPayLoad>(); service.twitter = twitter; service.eventPayLoadToTweetMap = eventPayLoadToTweetMap; EventBus eventBus = new EventBus(); eventBus.register(service); JSONObject jsonPayload = mock(JSONObject.class); TradeEventPayLoad payload = new TradeEventPayLoad(TradeEvents.TAKE_PROFIT_FILLED, jsonPayload); String tweet = "hello Twitter"; when(handler.toTweet(payload)).thenReturn(tweet); TimelineOperations operations = mock(TimelineOperations.class); when(twitter.timelineOperations()).thenReturn(operations); eventBus.post(payload); verify(operations, times(1)).updateStatus(tweet); }