Wouldn't it be nice
if the mock could be told what method calls to expect from the object(s) being tested? Then you could test the object behavior from the other side as well: not just the response to a call (i.e., the return value and state change), but also what methods in the mock were called from the class being developed.
Wouldn't it be nice
if the mock could be told what value(s) to return from those calls? That would let you verify more complex interactions.
Wouldn't it be nice
if it could be told to return different values each time a method is called? Again, this would let you test even more complex interactions.
Wouldn't it be nice
if you could ask it to verify that everything that was expected to happen did, indeed, happen, and to throw an exception if any expectation was violated? Some conditions could be detected immediately (such as a method being called too many times, or with the wrong arguments), but some (such as a method not being called enough times) couldn't until the mock was asked to check what really happened against what was expected.
Wouldn't it be nice
if the mock threw an Exception as soon as it knew it was being used in a way that wasn't desired? That would report the failure as close to the point of failure as possible, making it easier and faster to find and fix the problem.
Wouldn't it be nice
if you had tools that made this easy and painless?
Wouldn't it be nice
if you could do all that? Well, (as you might have guessed), you can indeed do all of that with the tools we'll be talking about in the remainder of this chapter.