Writing tests

While keeping the old end-to-end test, create an interaction to verify the integration of BirthdayGreetingService and MessageSender:

  @Test 
  public void the_service_should_ask_the_messageSender() { 
    final Email address = 
      new Email("john@example.com"); 
    final Employee john = new Employee(address); 
    final MessageSender messageSender = 
      mock(MessageSender.class); 
 
    new BirthdayGreetingService(messageSender) 
      .greet(john); 
 
    verify(messageSender).send(address,          "Greetings on your birthday"); 
  } 

At this point, a new TweetMessageSender can be written, completing the last step of the algorithm.

Get Test-Driven Java Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.