CopyTwitterStrategy implements TweetHarvester<T> { public synchronized void harvestAndTrade() { for (final String userId : tweetHandlerMap.keySet()) { this.executorService.submit(new Callable<Void>() { @Override public Void call() throws Exception { Collection<NewFXTradeTweet<T>> newTradeTweets = harvestNewTradeTweets(userId); for (NewFXTradeTweet<T> newTradeTweet : newTradeTweets) { Collection<CloseFXTradeTweet<T>> pnlTweets = harvestHistoricTradeTweets(userId, newTradeTweet.getInstrument()); TradingDecision<T> tradeDecision = analyseHistoricClosedTradesForInstrument(pnlTweets, newTradeTweet); if (tradeDecision.getSignal() != TradingSignal.NONE) { orderQueue.offer(tradeDecision); } } return null; } }); } }  @PostConstruct void init(); synchronized void harvestAndTrade(); @Override Collection<NewFXTradeTweet<T>> harvestNewTradeTweets(String userId); @Override Collection<CloseFXTradeTweet<T>> harvestHistoricTradeTweets(String userId,
			TradeableInstrument<T> instrument);  }
@Test public void harvestAndTradeTest() throws InterruptedException { CopyTwitterStrategy<String> copyTwitterStrategy = new CopyTwitterStrategy<String>(); FXTweetHandler<String> tweetHandlerFoo = createTweetHandlerFoo(copyTwitterStrategy); BlockingQueue<TradingDecision<String>> orderQueue = new LinkedBlockingQueue<TradingDecision<String>>(); copyTwitterStrategy.orderQueue = orderQueue; copyTwitterStrategy.init(); Tweet tweet1 = mock(Tweet.class); Collection<Tweet> footweets = Lists.newArrayList(tweet1); NewFXTradeTweet<String> newTrade = mock(NewFXTradeTweet.class); when(tweetHandlerFoo.findNewTweets()).thenReturn(footweets); when(tweetHandlerFoo.handleTweet(tweet1)).thenReturn(newTrade); when(newTrade.getAction()).thenReturn(TradingSignal.SHORT); TradeableInstrument<String> euraud = new TradeableInstrument<String>("EUR_AUD"); when(newTrade.getInstrument()).thenReturn(euraud); double[] profits = { 11.32, 17.7, 8.2, 19.0, 44.5, -11.0, 10, 25.5 }; Collection<CloseFXTradeTweet<String>> closedTrades = createClosedTrades(profits); footweets = Lists.newArrayList(); for (CloseFXTradeTweet<String> closeTradeTweet : closedTrades) { Tweet tweet = mock(Tweet.class); when(tweetHandlerFoo.handleTweet(tweet)).thenReturn(closeTradeTweet); footweets.add(tweet); } when(tweetHandlerFoo.findHistoricPnlTweetsForInstrument(euraud)).thenReturn(footweets); copyTwitterStrategy.harvestAndTrade(); TradingDecision<String> decision = orderQueue.take(); assertEquals(TradingSignal.SHORT, decision.getSignal()); assertEquals(euraud, decision.getInstrument()); }