TradeEventHandler implements EventHandler<JSONObject, TradeEventPayLoad>,
		EmailContentGenerator<JSONObject>, EventPayLoadToTweet<JSONObject, TradeEventPayLoad> { @Override public EmailPayLoad generate(EventPayLoad<JSONObject> payLoad) { JSONObject jsonPayLoad = payLoad.getPayLoad(); TradeableInstrument<String> instrument = new TradeableInstrument<String>(jsonPayLoad.get( OandaJsonKeys.instrument).toString()); final String type = jsonPayLoad.get(OandaJsonKeys.type).toString(); final long accountId = (Long) jsonPayLoad.get(OandaJsonKeys.accountId); final double accountBalance = ((Number) jsonPayLoad.get(OandaJsonKeys.accountBalance)).doubleValue(); final long tradeId = (Long) jsonPayLoad.get(OandaJsonKeys.tradeId); final double pnl = ((Number) jsonPayLoad.get(OandaJsonKeys.pl)).doubleValue(); final double interest = ((Number) jsonPayLoad.get(OandaJsonKeys.interest)).doubleValue(); final long tradeUnits = (Long) jsonPayLoad.get(OandaJsonKeys.units); final String emailMsg = String .format("Trade event %s received for account %d. Trade id=%d. Pnl=%5.3f, Interest=%5.3f, Trade Units=%d. Account balance after the event=%5.2f", type, accountId, tradeId, pnl, interest, tradeUnits, accountBalance); final String subject = String.format("Trade event %s for %s", type, instrument.getInstrument()); return new EmailPayLoad(subject, emailMsg); } 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 generatePayLoad() { TradeEventHandler eventHandler = new TradeEventHandler(null, null, null); JSONObject jsonPayLoad = mock(JSONObject.class); EventPayLoad<JSONObject> payLoad = new TradeEventPayLoad(TradeEvents.TAKE_PROFIT_FILLED, jsonPayLoad); when(jsonPayLoad.get(OandaJsonKeys.instrument)).thenReturn("GBP_USD"); when(jsonPayLoad.get(OandaJsonKeys.type)).thenReturn(TradeEvents.TAKE_PROFIT_FILLED.name()); when(jsonPayLoad.get(OandaJsonKeys.accountId)).thenReturn(OandaTestConstants.accountId); when(jsonPayLoad.get(OandaJsonKeys.accountBalance)).thenReturn(100.00); when(jsonPayLoad.get(OandaJsonKeys.tradeId)).thenReturn(OandaTestConstants.tradeId); when(jsonPayLoad.get(OandaJsonKeys.pl)).thenReturn(22.45); when(jsonPayLoad.get(OandaJsonKeys.interest)).thenReturn(-1.45); when(jsonPayLoad.get(OandaJsonKeys.units)).thenReturn(10000L); EmailPayLoad emailPayLoad = eventHandler.generate(payLoad); assertEquals("Trade event TAKE_PROFIT_FILLED for GBP_USD", emailPayLoad.getSubject()); assertEquals( "Trade event TAKE_PROFIT_FILLED received for account 123456. Trade id=1800805337. Pnl=22.450, Interest=-1.450, Trade Units=10000. Account balance after the event=100.00", emailPayLoad.getBody()); }