2016-03-23 4 views
0

Ich erstelle eine Anwendung, die einige lokale Benachrichtigungen hinzufügt. Dies ist mein TestOCMockito/OCHamcrest Verify-Array enthält Objekteigenschaft

- (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()]; } 

Das ist richtig und Verifikation ist der Erfolg. Aber ich muss überprüfen, ob meine UILocalNotification Objekteigenschaft alertBody in ohneFreunde Array ist. Gibt es einen Weg dafür?

+0

Wissen Sie im Voraus, was 'alertBody' sein wird? Wie "@" ein "'? –

+0

In diesem Szenario gibt es keine Freunde, daher weiß ich, dass ** alertBody ** ein zufälliger Wert aus dem Array ** withoutFriends ** ist. – milczi

Antwort

1

Es gibt einen Matcher isIn, den ich sehe, ist missing from the README. Zusammen mit dem hasProperty Matcher können wir schreiben:

[verifyCount(application, times(1)) scheduleLocalNotification:hasProperty(@"alertBody", isIn(withoutFriends))]; 
+0

Danke! Es funktioniert super! – milczi

Verwandte Themen