Every once in awhile, I need to remind myself the purpose of mocking or risk overcomplicating it. Mocking is meant to parrot what you’re looking for. Nothing more. You tell it how to answer when a call comes in and it repeats back what you told it to say. And that’s it.
So I was writing a new unit test. And I was complicating the thing. I blame it on the hour and fatigue. But that’s just excuses.
The project used java.net.HttpClient, which returns HttpResponse. But you can’t instantiate HttpResponse directly. So I switched all the code we’d written that day to use the Apache library instead. Because I could create all the mocks, and I could fill all the values, and I had lines and lines of code.
The next morning, my. partner quietly reminded me that I was making our work much hard than it needed to be.
All we had to do was tell the mock what we wanted returned. We didn’t have to create fields or attach objects or anything!

