Testing behavior through mock objects — part two of a three-part TDD exercise series, built around Caelum/Alura's PM-72 course.
Where part one covered plain unit tests, this step introduces test doubles: when collaborators (DAOs, mail senders, payment gateways) make a system costly to test directly, mocks let you simulate and verify the expected interactions.
| Type | Role |
|---|---|
Auction, Bid, User, Payment |
The auction domain model. |
Auctioneer |
Evaluates auctions. |
AuctionCloser |
Closes auctions older than a week. |
PaymentManager |
Generates payments for closed auctions. |
infra/ (MailSender, AuctionDao, repositories) |
Collaborators to mock. |
Write AuctionCloserTest so it proves the closer shuts auctions started over a
week ago — by mocking the DAO and injecting it through the constructor. Build up
from there.
mvn testPart one: UnitTestingFirstSteps. Part three: TestingWebApplicationWithSelenium.