lucacin (5) [Avatar] Offline
#1
Hi,
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
#2
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.
Andy Gumbrecht (9) [Avatar] Offline
#3
Good catches! I really wish I'd seen this earlier.

Thanks for the feedback.

Andy.
274150 (1) [Avatar] Offline
#4
Well actually the line between spies and stubs are so thin, and a Spy is (or can be) considered a Stub as well, so usually, I call Stubs to any real Stub or Spy. If you want to read more about this topic in a different source of the book here is a link https://martinfowler.com/articles/mocksArentStubs.html

Notice this "Spies are stubs that also record ...."