OCMockito capturing primitive types?

孤街醉人 提交于 2019-12-03 16:26:46

For primitive arguments, you have to do a little dance. Let's say we mocked NSMutableArray and wanted to verify calls to

- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject;

Instead of

[verify(mockArray) replaceObjectAtIndex:[argument capture] withObject:anything()];

which gives you the type conflict, we just have a dummy value (0 will do fine) but add an OCMockito call to override the matcher at a given argument index:

[[verify(mockArray) withMatcher:[argument capture] forArgument:0]
    replaceObjectAtIndex:0 withObject:anything()];

The argument index for -withMatcher:forArgument: is 0-based for the first argument, so this says, "For the first argument, ignore whatever was passed in and use this matcher instead."

There is also a method -withMatcher: which just does this on the first argument, so this example could be simplified to

[[verify(mockArray) withMatcher:[argument capture]]
    replaceObjectAtIndex:0 withObject:anything()];
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!