File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes Mockito problem testing for a boolean value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Mockito problem testing for a boolean value" Watch "Mockito problem testing for a boolean value" New topic
Author

Mockito problem testing for a boolean value

Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 576
I have a object a controller in which I set cachecontrol headers



In my test for testing this controller I pass in a mockResponse object.

I am trying to find ways to test that the headers have been set. In real life this would be


But in a mock response object this call would always default to false.

I thought this might work, but I dont think its correct for handling an checking boolean returns.



Thanks for any help Tony
Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 576
I think how mockito works in this case, is it checks was the method called with these parameters in this case



which works.

Now I come to my second problem.


will return

Argument(s) are different! Wanted:
mockResponse.setHeader(
"Last-Modified",
"Wed Sep 21 16:09:42 BST 2011"
);

Which is true as the string date representaion is different to the data the file was last modified.

I tried



This returns

org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
2 matchers expected, 1 recorded.
This exception may occur if matchers are combined with raw values:
//incorrect:
someMethod(anyObject(), "raw String");
When using matchers, all arguments have to be provided by matchers.
For example:
//correct:
someMethod(anyObject(), eq("String by matcher"));


Thanks for any help Tony
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mockito problem testing for a boolean value