2016-04-19 48 views
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 *类型,没有其他类实现或声明具有该名称的方法。

出了什么问题?

回答

0

我不得不这样做是为了解决问题

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