无法使用OCMock

时间:2016-04-19 22:02:58

标签: objective-c ocmock

我在objC项目中使用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 *类型的对象,没有其他类实现或声明具有此名称的方法。

有什么问题?

1 个答案:

答案 0 :(得分:0)

我必须这样做才能解决问题

 [(DBNotificationManager*)[[mockDBNotificationManager stub] 
andReturn:[NotificationPolicy Never]] getNotificationPolicy];