1

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

Jon Reid
  • 20,545
  • 2
  • 64
  • 95
stan4th
  • 710
  • 1
  • 6
  • 19

1 Answers1

2

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])];
Jon Reid
  • 20,545
  • 2
  • 64
  • 95