OCMockito / OCHamcrest 验证数组包含对象 属性
OCMockito / OCHamcrest verify array contains object property
我正在创建一个添加一些本地通知的应用程序。
这是我的测试
- (void)testFirstLogin {
//some initials array
NSArray *withoutFriends = @[@"a", @"b", @"c", @"e", @"f"];
NSArray *withFriends = @[@"v", @"w", @"x", @"y", @"z"];
//my service which add local notifications
LocalNotificationService *service = [LocalNotificationService sharedInstance];
service.lastLoginDate = nil;
//UIApplication mock
UIApplication *application = mock([UIApplication class]);
service.applictation = application;
//method which adds notifications
[service addNotificationScheduleFirstLoginWithNoFriendsArray:withoutFriends friendsExistArray:withFriends];
//In this method I create UILocalNotification
/*
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = text;
*/
//and add it to schedule
//[self.applictation scheduleLocalNotification:localNotification];
[verifyCount(application, times(1)) scheduleLocalNotification:anything()]; }
正确,验证成功。
但是我需要验证我的 UILocalNotification 对象 属性 alertBody 是否在 withoutFriends 数组中。
有办法吗?
有一个匹配器 isIn
,我看到它是 missing from the README。连同 hasProperty
匹配器,我们可以写成:
[verifyCount(application, times(1)) scheduleLocalNotification:hasProperty(@"alertBody", isIn(withoutFriends))];
我正在创建一个添加一些本地通知的应用程序。 这是我的测试
- (void)testFirstLogin {
//some initials array
NSArray *withoutFriends = @[@"a", @"b", @"c", @"e", @"f"];
NSArray *withFriends = @[@"v", @"w", @"x", @"y", @"z"];
//my service which add local notifications
LocalNotificationService *service = [LocalNotificationService sharedInstance];
service.lastLoginDate = nil;
//UIApplication mock
UIApplication *application = mock([UIApplication class]);
service.applictation = application;
//method which adds notifications
[service addNotificationScheduleFirstLoginWithNoFriendsArray:withoutFriends friendsExistArray:withFriends];
//In this method I create UILocalNotification
/*
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = text;
*/
//and add it to schedule
//[self.applictation scheduleLocalNotification:localNotification];
[verifyCount(application, times(1)) scheduleLocalNotification:anything()]; }
正确,验证成功。 但是我需要验证我的 UILocalNotification 对象 属性 alertBody 是否在 withoutFriends 数组中。 有办法吗?
有一个匹配器 isIn
,我看到它是 missing from the README。连同 hasProperty
匹配器,我们可以写成:
[verifyCount(application, times(1)) scheduleLocalNotification:hasProperty(@"alertBody", isIn(withoutFriends))];