0
我在一個objC項目上使用OCMock。不能使用OCMock存根方法
我有以下代碼:
DB_Account *Lena = [[DB_Account alloc] init];
Lena.niceName = @"Lena";
Lena.userId = @"Lena";
id mockStorageManager = OCMClassMock([V4_StorageManager class]);
[[[mockStorageManager stub] andReturn:Lena] getAccountByDBId:@1];
id mockDBNotificationManager = OCMClassMock([DBNotificationManager class]);
id partialV4DBNotificationManagerMock = OCMPartialMock([V4_DBNotificationManager manager]);
[[[mockDBNotificationManager stub] andReturn:(NotificationPolicy *)[NotificationPolicy Never]] getNotificationPolicy];
[[[partialV4DBNotificationManagerMock stub] andReturn:mockDBNotificationManager] dbNotificationManager];
BOOL shouldShow = [[V4_DBNotificationManager manager] showOnLoginExpired:Lena];
assertThatBool(shouldShow,is(isFalse()));
此代碼無法編譯上下面的行:
[[[mockDBNotificationManager stub] andReturn:(NotificationPolicy *)[NotificationPolicy Never]] getNotificationPolicy];
與此錯誤:
Error:(95, 5) multiple methods named 'getNotificationPolicy' found with mismatched result, parameter type or attributes
此方法返回一個對象NotificationPolicy *類型,沒有其他類實現或聲明具有該名稱的方法。
出了什麼問題?