Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mockito problem testing for a boolean value

 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic