Can I use Mockito to capture what was passed to the HttpServletResponse#sendError()
method? I can't figure out how to do that.
views:
96answers:
2
A:
You might want to look at Mockito spies (chapter 13). For objects you can't mock, you can sometimes examine their internals and stub certain methods this way.
If you can post some sample code, I can take a look at it.
Andy
2010-06-11 16:04:50
In this case I don't have a real object. I'm doing: mock(HttpServletResponse.class). In the code it calls the sendError() method. Maybe I just need to create my own mock implementation fo HttpServletResponse. I was hoping Mockito had a was to save any time sendError() was called so I could retrieve the results later on.
Dave
2010-06-11 20:39:52
Looking at the Spy docs showed me how simple this is: verify(res).sendError(404);Thanks.
Dave
2010-06-11 20:48:27
No problem. I have been wrestling with Mockito myself lately. It's amazing, except when it isn't.
Andy
2010-06-11 21:12:40
+1
A:
You should use the verify method on Mockito to do this. Usually mocking HttpResponse isn't a pleasant experience though.
verify(mockResponse, times(1)).sendError(..)
iwein
2010-06-14 17:49:31