O'Reilly logo

Test-Driven Java Development - Second Edition by Viktor Farcic, Alex Garcia

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required