TradeEventHandler implements EventHandler<JSONObject, TradeEventPayLoad>,
		EmailContentGenerator<JSONObject>, EventPayLoadToTweet<JSONObject, TradeEventPayLoad> { @Override @Subscribe @AllowConcurrentEvents public void handleEvent(TradeEventPayLoad payLoad) { Preconditions.checkNotNull(payLoad); if (!tradeEventsSupported.contains(payLoad.getEvent())) { return; } JSONObject jsonPayLoad = payLoad.getPayLoad(); long accountId = (Long) jsonPayLoad.get(OandaJsonKeys.accountId); tradeInfoService.refreshTradesForAccount(accountId); } TradeEventHandler(TradeInfoService<Long, String, Long> tradeInfoService,
			TransactionDataProvider<Long, Long, String> transactionDataProvider,
			InstrumentService<String> instrumentService); @Override @Subscribe @AllowConcurrentEvents void handleEvent(TradeEventPayLoad payLoad); @Override EmailPayLoad generate(EventPayLoad<JSONObject> payLoad); @Override String toTweet(TradeEventPayLoad payLoad);  }
@Test public void unSupportedTradeEvent() { JSONObject jsonPayLoad = mock(JSONObject.class); TradeEventPayLoad payLoad = new TradeEventPayLoad(TradeEvents.MIGRATE_TRADE_CLOSE, jsonPayLoad); @SuppressWarnings("unchecked") TradeInfoService<Long, String, Long> tradeInfoService = mock(TradeInfoService.class); TradeEventHandler eventHandler = new TradeEventHandler(tradeInfoService, null, null); eventHandler.handleEvent(payLoad); verify(tradeInfoService, times(0)).refreshTradesForAccount(OandaTestConstants.accountId); }
@Test public void tradeEvent() { JSONObject jsonPayLoad = mock(JSONObject.class); TradeEventPayLoad payLoad = new TradeEventPayLoad(TradeEvents.TAKE_PROFIT_FILLED, jsonPayLoad); when(jsonPayLoad.get(OandaJsonKeys.accountId)).thenReturn(OandaTestConstants.accountId); @SuppressWarnings("unchecked") TradeInfoService<Long, String, Long> tradeInfoService = mock(TradeInfoService.class); TradeEventHandler eventHandler = new TradeEventHandler(tradeInfoService, null, null); eventHandler.handleEvent(payLoad); verify(tradeInfoService, times(1)).refreshTradesForAccount(OandaTestConstants.accountId); }