vendredi 29 janvier 2016

Verify if a method was called with specific parameters

How can I verify if a certain method was called with specific parameters, but ignore all other invocations. Example

Configuration conf = mock(Configuration.class);
...

//Some code that calls conf methods
conf.set("ignore_me_1", "ignore_me_1") 
conf.set("ignore_me_2", "ignore_me_2")
conf.set("expected_key", "expected_value")  
....

//Now lets verify what was called - it will fail, becasue the other two invocations were not expected. 
verify(conf).set("expected_key", "expected_value") 

How can I tell mockito to ignore the unexpected invocations, and check only for the expected one ?

Here is the error I receive:

Argument(s) are different! Wanted:
abstractConfiguration.setProperty(
    "SOME_BOOL_PROPERTY",
    "false"
);
-> at .......

Actual invocation has different arguments:
abstractConfiguration.setProperty(
    "hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds",
    45000
);
-> at ......

Aucun commentaire:

Enregistrer un commentaire