WordCountMP implements Cloneable { @MessageHandler public List<?> handleWord(Word word) { if(this.word != null) { if(!this.word.equals(word)) { logger.error("Expected "+this.word+" actually received "+word); return null; } } else { this.word = word; } this.count++; if(wordCount == null) { wordCount = new WordCount(this.word, count); } else { wordCount.setCount(this.count); } if(forward == null) { forward = new ArrayList<Object>(); forward.add(wordCount); forward.add(new Letter(this.word.getData().charAt(0))); } logger.info("received word \""+word+"\" count: "+count); return forward; }  @MessageHandler List<?> handleWord(Word word); @Override WordCountMP clone();  }
@Test public void handleWordTest1() { Word word = new Word("Test1"); List<?> list = mp.handleWord(word); Assert.assertNotNull(list); Assert.assertEquals(2, list.size()); for(Object data : list) { if(data instanceof WordCount) { WordCount wordCount = (WordCount)data; Assert.assertEquals(word, wordCount.getWord()); Assert.assertEquals(1, wordCount.getCount()); } else { Assert.assertEquals(new Character('T'), ((Letter)data).getLetterKey()); } } }
@Test public void handleWordTest2() { handleWordTest1(); Word word = new Word("Test2"); List<?> count = mp.handleWord(word); Assert.assertNull(count); }
@Test public void handleWordTest3() { handleWordTest2(); Word word = new Word("Test1"); List<?> list = mp.handleWord(word); Assert.assertNotNull(list); for(Object data : list) { if(data instanceof WordCount) { WordCount wordCount = (WordCount)data; Assert.assertEquals(word, wordCount.getWord()); Assert.assertEquals(2, wordCount.getCount()); } else { Assert.assertEquals(new Character('T'), ((Letter)data).getLetterKey()); } } }