StartLetterCountMP implements Cloneable { @MessageHandler public LetterCount handleFirstCharacter(Letter letter) { if(character != null) { if(!character.equals(letter.getLetterKey())) { logger.error("Expected letter "+character+" actually received "+letter.getLetterKey()); return null; } } else { this.character = letter.getLetterKey(); } if(letterCount == null) { this.letterCount = new LetterCount(letter, count); } count++; this.letterCount.setCount(count); logger.info("received letter "+character+" count "+count); return letterCount; }  @MessageHandler LetterCount handleFirstCharacter(Letter letter); @Override StartLetterCountMP clone();  }
@Test public void handleLetterTest1() { Letter letter = new Letter('T'); LetterCount letterCount = mp.handleFirstCharacter(letter); Assert.assertNotNull(letterCount); Assert.assertEquals(1, letterCount.getCount()); Assert.assertNotNull(letterCount.getLetter()); Assert.assertEquals(letter, letterCount.getLetter()); }
@Test public void handleLetterTest2() { handleLetterTest1(); Letter letter = new Letter('A'); LetterCount letterCount = mp.handleFirstCharacter(letter); Assert.assertNull(letterCount); }
@Test public void handleLetterTest3() { handleLetterTest2(); Letter letter = new Letter('T'); LetterCount letterCount = mp.handleFirstCharacter(letter); Assert.assertNotNull(letterCount); Assert.assertEquals(2, letterCount.getCount()); Assert.assertNotNull(letterCount.getLetter()); Assert.assertEquals(letter, letterCount.getLetter()); }