OrderFilledEventHandler implements EventHandler<JSONObject, OrderEventPayLoad>,
		EmailContentGenerator<JSONObject> { @Override @Subscribe @AllowConcurrentEvents public void handleEvent(OrderEventPayLoad payLoad) { Preconditions.checkNotNull(payLoad); if (!orderEventsSupported.contains(payLoad.getEvent())) { return; } JSONObject jsonPayLoad = payLoad.getPayLoad(); long accountId = (Long) jsonPayLoad.get(OandaJsonKeys.accountId); tradeInfoService.refreshTradesForAccount(accountId); } OrderFilledEventHandler(TradeInfoService<Long, String, Long> tradeInfoService); @Override @Subscribe @AllowConcurrentEvents void handleEvent(OrderEventPayLoad payLoad); @Override EmailPayLoad generate(EventPayLoad<JSONObject> payLoad);  }
@Test public void unSupportedOrderEvent() { JSONObject jsonPayLoad = mock(JSONObject.class); OrderEventPayLoad payLoad = new OrderEventPayLoad(OrderEvents.ORDER_CANCEL, jsonPayLoad); @SuppressWarnings("unchecked") TradeInfoService<Long, String, Long> tradeInfoService = mock(TradeInfoService.class); OrderFilledEventHandler eventHandler = new OrderFilledEventHandler(tradeInfoService); eventHandler.handleEvent(payLoad); verify(tradeInfoService, times(0)).refreshTradesForAccount(OandaTestConstants.accountId); }
@Test public void orderEvent() { JSONObject jsonPayLoad = mock(JSONObject.class); OrderEventPayLoad payLoad = new OrderEventPayLoad(OrderEvents.ORDER_FILLED, jsonPayLoad); when(jsonPayLoad.get(OandaJsonKeys.accountId)).thenReturn(OandaTestConstants.accountId); @SuppressWarnings("unchecked") TradeInfoService<Long, String, Long> tradeInfoService = mock(TradeInfoService.class); OrderFilledEventHandler eventHandler = new OrderFilledEventHandler(tradeInfoService); eventHandler.handleEvent(payLoad); verify(tradeInfoService, times(1)).refreshTradesForAccount(OandaTestConstants.accountId); }