Scrivio Interview library
ScenarioIntermediate6 min read · updated 12 November 2026

A pull request adds tests that mock every collaborator, including value objects and the repository, and verify every call. How would you review it?

I would review it by asking what bugs these tests would catch and what refactors they would break. Tests that mock every collaborator and verify every call mirror the implementation, so they break on each refactor without catching real bugs. I would ask the author to construct value objects instead of mocking them, avoid mocking types we do not own, verify only the interactions that are the purpose of the code, and test the repository with a fake or a slice test such as @DataJpaTest.

Why this question is asked

Reviewing tests is harder than reviewing production code, because a bad test still passes, and a passing test looks like progress. Interviewers ask this scenario to see whether we can spot over-mocking, explain its cost convincingly, and guide a colleague towards better tests without simply rejecting their work. In this answer, we will look at an example of the pull request, go through each problem and the reason it matters, show the rewritten test, and finish with how to phrase the review so the author learns from it.

1The Pull Request Under Review

Let us make it concrete. The pull request adds a test for an OrderService.place() method. The service checks stock, calculates the total, saves the order and publishes an event. The test mocks everything, including the Money value object and the repository, and verifies every call.

Java
@Mock Money total;
@Mock OrderLine line;
@Mock OrderRepository repo;
@Mock StockClient stock;
@Mock EventPublisher events;
@InjectMocks OrderService service;
@Test
void placesOrder() {
when(line.price()).thenReturn(total);
when(total.add(any())).thenReturn(total);
when(stock.available("SKU-1")).thenReturn(true);
when(repo.save(any())).thenAnswer(inv -> inv.getArgument(0));
service.place(List.of(line));
verify(line).price();
verify(total).add(any());
verify(stock).available("SKU-1");
verify(repo).save(any());
verify(events).publish(any());
verifyNoMoreInteractions(line, total, stock, repo, events);
}

The first question a reviewer asks is simple: if place() calculated the wrong total, would this test fail? It would not. Money is mocked to return itself from add(), so the test cannot see any arithmetic at all. And if someone refactored the loop to sum prices with a stream, would it fail? Yes, because the verified call pattern changes. That combination, blind to bugs and sensitive to refactors, is the core finding.

2Problem 1: The Test Mirrors the Implementation

Every verify() line restates a line of place(). Together they say 'the code calls these methods in this way', which is just the implementation written a second time. Combined with verifyNoMoreInteractions, any change to how the work is done breaks the test, even when the result is the same. Over hundreds of tests, this is how teams end up afraid to refactor.

The fix is to decide what the method is for. place() exists to store a valid order with the right total and announce it. Those are the facts to check. How it gets there is the implementation's business.

3Problem 2: Value Objects Should Be Constructed, Not Mocked

Money and OrderLine are value objects: small, immutable objects defined by their values, with no external dependencies. They are cheap to build and their behaviour, such as adding two amounts, is exactly what we want to exercise. Mocking them replaces real logic with whatever the stub says, which is why the test above cannot notice a wrong total.

The rule for the review is that we mock things with behaviour we want to isolate, such as remote calls, never plain data. Building new OrderLine("SKU-1", 2, Money.of("9.99")) is shorter than stubbing it and makes the test meaningful.

4Problem 3: Types We Do Not Own and the Repository

If StockClient is our own interface wrapping an HTTP service, mocking it is fine: it is a boundary. If the test mocked RestClient or a JDBC type directly, I would ask for a wrapper, because a mock of a library encodes our assumptions about it.

The repository is a different case. OrderRepository is a Spring Data interface; mocking save() to return its argument tells us nothing about whether the entity maps correctly, whether constraints hold, or whether a query works. For the service test, an in-memory fake repository, a simple class backed by a map, gives real behaviour cheaply. For the mapping and queries, a @DataJpaTest slice against a real database with Testcontainers is the right place.

Review findings and suggestions
FindingCostSuggestion
Mocks Money and OrderLinecannot see wrong totalsconstruct real value objects
Verifies every callbreaks on any refactorassert results, verify only effects
verifyNoMoreInteractions on all mocksfails on harmless new callsremove; keep only real requirements
Mocks the repository's save()mapping and queries untestedin-memory fake, plus @DataJpaTest
Mocks StockClient (our wrapper)none, it is a boundarykeep

5The Rewritten Test

Here is what the test looks like after the suggestions. Value objects are real, the repository is a fake, the stock service is mocked because it is a remote boundary, and the only verification is the event, because publishing it is the purpose of the method and leaves no other trace.

Java
InMemoryOrders repo = new InMemoryOrders();
StockClient stock = mock(StockClient.class);
EventPublisher events = mock(EventPublisher.class);
OrderService service = new OrderService(repo, stock, events);
@Test
void storesOrderWithTotalAndPublishesIt() {
when(stock.available("SKU-1")).thenReturn(true);
Order order = service.place(List.of(new OrderLine("SKU-1", 2, Money.of("9.99"))));
assertEquals(Money.of("19.98"), order.total()); // real arithmetic
assertEquals(order, repo.findById(order.id()).orElseThrow()); // really stored
verify(events).publish(new OrderPlaced(order.id(), Money.of("19.98"))); // the one effect
}
@Test
void rejectsWhenOutOfStock() {
when(stock.available("SKU-1")).thenReturn(false);
assertThrows(OutOfStockException.class, () -> service.place(List.of(new OrderLine("SKU-1", 1, Money.of("9.99")))));
verifyNoInteractions(events); // requirement: nothing announced
}

Notice that this version would fail on a wrong total, on an order that is not stored, and on a missing event, and it would survive a refactor of the loop. The second test uses verifyNoInteractions on purpose, because 'no event for a rejected order' is a real rule.

6Writing the Review So the Author Learns

How we say it matters as much as what we say. I would start by acknowledging that the tests are there and cover the paths, then ask the key question in the review rather than state a verdict: 'If total calculation broke, which test would fail?' That lets the author discover the gap themselves. I would group the comments into the three or four findings above instead of twenty line comments, link to the team's testing standard if we have one, and offer to pair for half an hour on the first rewrite.

I would also not block on perfection. The essential changes are real value objects and dropping the verify-everything lines; moving repository checks into a @DataJpaTest can be a follow-up ticket if the pull request is otherwise ready.

Step throughHow I would run the review
  1. Ask: which bug would fail this test?let the author see the gap
  2. Group findings into three or four themesnot twenty line comments
  3. Show one rewritten testa concrete target
  4. Must-fix in this PR?
    YesValue objects real, drop verify-everythingNoRepository slice test as follow-up
  5. Offer to pair on the first rewriteteaching, not gatekeeping

5 steps in order. Play them, or step through them one at a time.

7Follow-up questions

What is a fake, and how is it different from a mock?

A fake is a working, simplified implementation, such as a repository backed by a HashMap. It has real behaviour we can rely on across calls, while a mock only returns what each stub says and records calls.

Should I insist on 100 percent removal of verify() in the PR?

No. Verifying an external effect, such as publishing an event or sending an email, is correct. The aim is to remove verification of internal steps, not all verification.

What if the team's existing tests all look like this?

Then the pull request is a symptom, and I would raise it with the team as a standard rather than make one author carry the change. New tests follow the better style, and old ones change when they are touched.

8Conclusion

In this answer, we reviewed a pull request whose tests mocked every collaborator and verified every call. We saw that such tests mirror the implementation, so they break on every refactor while missing real bugs like a wrong total. The review asks the author to construct value objects, keep mocks for boundaries such as remote clients, avoid mocking library types, verify only purposeful effects, and test the repository with a fake or a @DataJpaTest slice, and it does so with questions and an example rather than a list of rejections.

What to say in the interviewAbout 80 seconds aloud

Open with

My first question would be: which bug would these tests catch, and which refactor would break them? Here, because Money and OrderLine are mocked, a wrong total would pass, and because every call is verified plus verifyNoMoreInteractions, changing a loop to a stream would fail.

Then, if they want more

So the tests mirror the implementation and protect nothing. My concrete comments would be: construct value objects like Money and OrderLine instead of mocking them, since their logic is what we want to test. Keep mocks for real boundaries such as the stock client, and if anything mocks a library type like RestClient directly, wrap it in our own interface.

Assert on results, the total and the stored order, and verify only interactions that are the purpose of the code, such as publishing the OrderPlaced event. Drop verifyNoMoreInteractions unless no other calls is a real rule, like no event for a rejected order.

For the repository, use an in-memory fake in this test and a @DataJpaTest with Testcontainers for mapping and queries. I would phrase it as questions, show one rewritten test, mark only the essential changes as must-fix, and offer to pair on it.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A pull request adds tests that mock every collaborator, including value objects and the...": https://scrivio-interview-library.netlify.app/java/mocking/93e9dd89ad/