lucacin (5) [Avatar] Offline
Listing 3.1 is labeled as "Stubbing" and in the code shown the class is called MailServiceStub. I think it's not correct as it's a Spy not a Stub according to previous definition.

Best regards and thanks for this great book
Ted M. Young (1) [Avatar] Offline
According to the definitions, it looks exactly like a Fake (because it is storing the message in memory, so provides working behavior). A stub would be something like

public class MailServiceStub implements MailService {

  void sendEmail(Message msg) {

  boolean hasSentMessage(Message msg) {
    return true;


This is injecting "predefined answers" to the hasSentMessage call.