01—Architecture
The final branch (level-4-payment-gateway) shows the PlaceOrderUseCase at full scope: customer lookup, per-item stock checks, order creation, stock reservation, domain event publishing, and a call to an external payment gateway. The diagram is the level-4 dependency graph.
02—By the numbers
Each branch runs the same three tests — happy path, a rename, a private-method extraction — once with mocks, once with fakes. Numbers below are median wall-clock from the included benchmark script, run on the same machine for all branches.
03—The approach
Why fakes-first
Every branch ships a fake implementation of every collaborator — FakeCustomerRepository, FakeStockRepository, and so on — backed by an in-memory store. The mock-based tests are kept next to them so you can run both and watch which one breaks when you refactor.
Contract tests
An abstract CustomerRepositoryContractTest runs against both the fake and the JPA implementation. The two pass identically, so a divergence surfaces at test time, not in production.
Side effects get mocks, state gets fakes
The event publisher and the payment gateway are wrapped behind interfaces you control, and the tests assert on the side effect (a published event, a gateway call) — not on state. That's where mocks earn their place.
External system ownership
The payment gateway is the one place the project intentionally mocks a third-party type. Wrapping it behind your own interface is the only thing that keeps the rest of the suite from baking in library API shape.
04—The branches
Each branch builds on the previous one. The benchmark script (./scripts/benchmark.sh) runs the whole suite 30 times and reports median and p95.
-
00
mainREADME and the benchmark script. Nothing else. -
01
level-0-single-repositoryPlaceOrderUseCasewith one dependency. Mocks and fakes look identical here. -
02
level-1-two-repositoriesAddsStockRepository. The first timeverify(exactly = 1)lies after a private-method extraction. -
03
level-2-full-checkoutAddsOrderRepositoryand a full pre-validation pass. Fakes stop caring about call order. -
04
level-3-domain-eventsAdds the event publisher. Mocks do their actual job well here. -
05
level-4-payment-gatewayAdds the external payment gateway behind a wrapper interface.