Assuming I’ve a class with three methods, startCollection, add, endCollection.

One test case is: if start was not called, add should return an error.

I’ve mocked the persistency storing the state with an memory variant, and test it. All fine.

Now I’ve yet another class: a RestController. It also has 3 methods that call the relevant service methods and then maps the error to a status code + JSON error.

Here the very same is true. If a POST to add is performed, it should return an error if start wasn’t called. Here i can literally copy paste the mock object from above, inject it into the service, and inject the service in the controller.

But i feel weird having the same test twice. Only that the return is different.

Should the controller unit test simply not check that add returns an error when start isn’t called, but just that it maps the error and success successfully?