@SuppressWarnings("unchecked")
@Test
public void payLoadToTweet() {

	JSONObject jsonPayLoad = mock(JSONObject.class);
	TradeableInstrument<String> eurchf = new TradeableInstrument<String>("EUR_CHF");
	TradeEventPayLoad payLoad = new TradeEventPayLoad(TradeEvents.TAKE_PROFIT_FILLED, jsonPayLoad);
	when(jsonPayLoad.get(OandaJsonKeys.instrument)).thenReturn(eurchf.getInstrument());
	when(jsonPayLoad.get(OandaJsonKeys.units)).thenReturn(200l);
	when(jsonPayLoad.get(OandaJsonKeys.price)).thenReturn(1.10325);
	when(jsonPayLoad.get(OandaJsonKeys.tradeId)).thenReturn(OandaTestConstants.tradeId);
	when(jsonPayLoad.get(OandaJsonKeys.accountId)).thenReturn(OandaTestConstants.accountId);
	TransactionDataProvider<Long, Long, String> transactionDataProvider = mock(TransactionDataProvider.class);
	// test profit scenario with short
	Transaction<Long, Long, String> transaction = mock(Transaction.class);
	when(transactionDataProvider.getTransaction(OandaTestConstants.tradeId, OandaTestConstants.accountId))
			.thenReturn(transaction);
	when(transaction.getSide()).thenReturn(TradingSignal.SHORT);
	when(transaction.getPrice()).thenReturn(1.11);
	InstrumentService<String> instrumentService = mock(InstrumentService.class);
	when(instrumentService.getPipForInstrument(eq(eurchf))).thenReturn(0.0001);
	TradeEventHandler eventHandler = new TradeEventHandler(null, transactionDataProvider, instrumentService);
	String tweet = eventHandler.toTweet(payLoad);
	assertNotNull(tweet);
	assertEquals("Closed SHORT 200 units of #EURCHF@1.10325 for 67.5 pips.", tweet);
	// test loss scenario with short
	transaction = mock(Transaction.class);
	when(transactionDataProvider.getTransaction(OandaTestConstants.tradeId, OandaTestConstants.accountId))
			.thenReturn(transaction);
	when(transaction.getSide()).thenReturn(TradingSignal.SHORT);
	when(transaction.getPrice()).thenReturn(1.10);
	tweet = eventHandler.toTweet(payLoad);
	assertNotNull(tweet);
	assertEquals("Closed SHORT 200 units of #EURCHF@1.10325 for -32.5 pips.", tweet);
	// test profit scenario with long
	transaction = mock(Transaction.class);
	when(transactionDataProvider.getTransaction(OandaTestConstants.tradeId, OandaTestConstants.accountId))
			.thenReturn(transaction);
	when(transaction.getSide()).thenReturn(TradingSignal.LONG);
	when(transaction.getPrice()).thenReturn(1.10);
	tweet = eventHandler.toTweet(payLoad);
	assertNotNull(tweet);
	assertEquals("Closed LONG 200 units of #EURCHF@1.10325 for 32.5 pips.", tweet);
	// test loss scenario with long
	transaction = mock(Transaction.class);
	when(transactionDataProvider.getTransaction(OandaTestConstants.tradeId, OandaTestConstants.accountId))
			.thenReturn(transaction);
	when(transaction.getSide()).thenReturn(TradingSignal.LONG);
	when(transaction.getPrice()).thenReturn(1.11);
	tweet = eventHandler.toTweet(payLoad);
	assertNotNull(tweet);
	assertEquals("Closed LONG 200 units of #EURCHF@1.10325 for -67.5 pips.", tweet);
	when(transactionDataProvider.getTransaction(OandaTestConstants.tradeId, OandaTestConstants.accountId))
			.thenReturn(null);
	when(jsonPayLoad.get(OandaJsonKeys.side)).thenReturn("sell");
	tweet = eventHandler.toTweet(payLoad);
	assertNotNull(tweet);
	assertEquals("Closed LONG 200 units of #EURCHF@1.10325.", tweet);
	// unsupported event
	TradeEventPayLoad payload2 = new TradeEventPayLoad(TradeEvents.MIGRATE_TRADE_CLOSE, jsonPayLoad);
	assertNull(eventHandler.toTweet(payload2));
}