SignalFactoryFXTweetHandler extends AbstractFXTweetHandler<String> { @Override public Collection<Tweet> findHistoricPnlTweetsForInstrument(TradeableInstrument<String> instrument) { String isoInstr = this.providerHelper.toIsoFormat(instrument.getInstrument()); String query = String.format("Profit: OR Loss: from:%s", getUserId(), isoInstr); SearchResults results = twitter.searchOperations().search(query); List<Tweet> pnlTweets = results.getTweets(); List<Tweet> filteredPnlTweets = Lists.newArrayList(); for (Tweet pnlTweet : pnlTweets) { if (pnlTweet.getText().contains(isoInstr)) { filteredPnlTweets.add(pnlTweet); } } return filteredPnlTweets; } SignalFactoryFXTweetHandler(String userid); @Override FXTradeTweet<String> handleTweet(Tweet tweet); @Override Collection<Tweet> findHistoricPnlTweetsForInstrument(TradeableInstrument<String> instrument);  }
@Test public void findHistoricPnlTweetsForInstrumentTest() { AbstractFXTweetHandler<String> tweetHandler = new SignalFactoryFXTweetHandler(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> nzdusd = new TradeableInstrument<String>("NZD_USD"); when(providerHelper.toIsoFormat(eq("NZD_USD"))).thenReturn("NZDUSD"); SearchResults searchResults = returnHistoricPnlSearchResults(); String query = "Profit: OR Loss: from:SignalFactory"; when(searchOperations.search(eq(query))).thenReturn(searchResults); Collection<Tweet> tweets = tweetHandler.findHistoricPnlTweetsForInstrument(nzdusd); assertEquals(1, tweets.size()); }