Question

with the following unit test I'm using Mockito to mock NSUserDefaults but when I try to verify using OCHamcrest matcher to test that the param is an instance of an NSDictionary I get the warning:

Sending 'id{HCMatcher}' to parameter of incompatible type 'NSDictionary *'

NSUserDefaults *userDefaultsMock = mockClass([NSUserDefaults class]); 
//OR -- NSUserDefaults *userDefaultsMock = mock([[NSUserDefaults standardUserDefaults]class]);

Engineer *sut = [[Engineer alloc]init];

[given([userDefaultsMock stringForKey:@"engineerId"]) willReturn:@"02345"];

BOOL result = [sut setCurrentEngineerId:@"02345" userDefaults:userDefaultsMock];
[verify(userDefaultsMock) registerDefaults:instanceOf([NSDictionary class])];

Thanks

Was it helpful?

Solution

As the documentation says, "Typed arguments will issue a warning that the matcher is the wrong type. Just cast the matcher to id."

In your case,

[verify(userDefaultsMock) registerDefaults:(id)instanceOf([NSDictionary class])];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top