ZuluTrader101FXTweetHandler extends AbstractFXTweetHandler<String> { @Override public Collection<Tweet> findHistoricPnlTweetsForInstrument(TradeableInstrument<String> instrument) { String isoInstr = TradingConstants.HASHTAG + this.providerHelper.toIsoFormat(instrument.getInstrument()); SearchResults results = twitter.searchOperations().search( String.format("from:%s \"Closed Buy\" OR \"Closed Sell\" %s", getUserId(), isoInstr)); return results.getTweets(); } protected  ZuluTrader101FXTweetHandler(String userId); @Override FXTradeTweet<String> handleTweet(Tweet tweet); @Override Collection<Tweet> findHistoricPnlTweetsForInstrument(TradeableInstrument<String> instrument);  }
@Test public void findHistoricPnlTweetsForInstrumentTest() { AbstractFXTweetHandler<String> tweetHandler = new ZuluTrader101FXTweetHandler(userId); ProviderHelper providerHelper = mock(ProviderHelper.class); Twitter twitter = mock(Twitter.class); tweetHandler.providerHelper = providerHelper; tweetHandler.twitter = twitter; SearchOperations searchOperations = mock(SearchOperations.class); when(twitter.searchOperations()).thenReturn(searchOperations); TradeableInstrument<String> audusd = new TradeableInstrument<String>("AUD_USD"); when(providerHelper.toIsoFormat(eq("AUD_USD"))).thenReturn("AUDUSD"); SearchResults searchResults = returnHistoricPnlSearchResults(); String query = "from:ZuluTrader101 \"Closed Buy\" OR \"Closed Sell\" #AUDUSD"; when(searchOperations.search(eq(query))).thenReturn(searchResults); Collection<Tweet> tweets = tweetHandler.findHistoricPnlTweetsForInstrument(audusd); assertEquals(1, tweets.size()); }