@@ -1065,12 +1065,12 @@ - (void)testApplicationDidReceiveRemoteNotificationWithCompletionIsInvokedOnInte
1065
1065
id interceptor = OCMProtocolMock (@protocol (GULApplicationDelegate));
1066
1066
OCMExpect ([interceptor application: application
1067
1067
didReceiveRemoteNotification: notification
1068
- fetchCompletionHandler: completion ]);
1068
+ fetchCompletionHandler: [OCMArg isNotNil ] ]);
1069
1069
1070
1070
id interceptor2 = OCMProtocolMock (@protocol (GULApplicationDelegate));
1071
1071
OCMExpect ([interceptor2 application: application
1072
1072
didReceiveRemoteNotification: notification
1073
- fetchCompletionHandler: completion ]);
1073
+ fetchCompletionHandler: [OCMArg isNotNil ] ]);
1074
1074
1075
1075
GULTestAppDelegate *testAppDelegate = [[GULTestAppDelegate alloc ] init ];
1076
1076
OCMStub ([self .mockSharedApplication delegate ]).andReturn (testAppDelegate);
@@ -1087,7 +1087,108 @@ - (void)testApplicationDidReceiveRemoteNotificationWithCompletionIsInvokedOnInte
1087
1087
1088
1088
XCTAssertEqual (testAppDelegate.application , application);
1089
1089
XCTAssertEqual (testAppDelegate.remoteNotification , notification);
1090
- XCTAssertEqual (testAppDelegate.remoteNotificationCompletionHandler , completion);
1090
+ }
1091
+
1092
+ - (void )verifyCompletionCalledForObserverResult : (UIBackgroundFetchResult)observerResult1
1093
+ anotherObserverResult : (UIBackgroundFetchResult)observerResult2
1094
+ swizzledResult : (UIBackgroundFetchResult)swizzledResult
1095
+ expecredResult : (UIBackgroundFetchResult)expectedResult {
1096
+ NSDictionary *notification = @{};
1097
+ GULApplication *application = [GULApplication sharedApplication ];
1098
+
1099
+ XCTestExpectation *completionExpectation =
1100
+ [[XCTestExpectation alloc ] initWithDescription: @" Completion called once" ];
1101
+
1102
+ void (^completion)(UIBackgroundFetchResult) = ^(UIBackgroundFetchResult result) {
1103
+ XCTAssertEqual (result, expectedResult);
1104
+ [completionExpectation fulfill ];
1105
+ };
1106
+
1107
+ void (^onDidReceiveRemoteNotification1)(NSInvocation *invocation) = ^(NSInvocation *invocation) {
1108
+ void __unsafe_unretained (^localCompletionHandler)(UIBackgroundFetchResult) = nil ;
1109
+ [invocation getArgument: (void *)(&localCompletionHandler) atIndex: 4 ];
1110
+ XCTAssertNotNil (localCompletionHandler);
1111
+ localCompletionHandler (observerResult1);
1112
+ };
1113
+
1114
+ id interceptor = OCMProtocolMock (@protocol (GULApplicationDelegate));
1115
+ OCMExpect ([interceptor application: application
1116
+ didReceiveRemoteNotification: notification
1117
+ fetchCompletionHandler: [OCMArg isNotNil ]])
1118
+ .andDo (onDidReceiveRemoteNotification1);
1119
+
1120
+ void (^onDidReceiveRemoteNotification2)(NSInvocation *invocation) = ^(NSInvocation *invocation) {
1121
+ void __unsafe_unretained (^localCompletionHandler)(UIBackgroundFetchResult) = nil ;
1122
+ [invocation getArgument: (void *)(&localCompletionHandler) atIndex: 4 ];
1123
+ XCTAssertNotNil (localCompletionHandler);
1124
+ localCompletionHandler (observerResult2);
1125
+ };
1126
+
1127
+ id interceptor2 = OCMProtocolMock (@protocol (GULApplicationDelegate));
1128
+ OCMExpect ([interceptor2 application: application
1129
+ didReceiveRemoteNotification: notification
1130
+ fetchCompletionHandler: [OCMArg isNotNil ]])
1131
+ .andDo (onDidReceiveRemoteNotification2);
1132
+
1133
+ GULTestAppDelegate *testAppDelegate = [[GULTestAppDelegate alloc ] init ];
1134
+ OCMStub ([self .mockSharedApplication delegate ]).andReturn (testAppDelegate);
1135
+ [GULAppDelegateSwizzler proxyOriginalDelegateIncludingAPNSMethods ];
1136
+
1137
+ [GULAppDelegateSwizzler registerAppDelegateInterceptor: interceptor];
1138
+ [GULAppDelegateSwizzler registerAppDelegateInterceptor: interceptor2];
1139
+
1140
+ [testAppDelegate application: application
1141
+ didReceiveRemoteNotification: notification
1142
+ fetchCompletionHandler: completion];
1143
+ testAppDelegate.remoteNotificationCompletionHandler (swizzledResult);
1144
+ OCMVerifyAll (interceptor);
1145
+ OCMVerifyAll (interceptor2);
1146
+ [self waitForExpectations: @[ completionExpectation ] timeout: 0.1 ];
1147
+ }
1148
+
1149
+ - (void )testApplicationDidReceiveRemoteNotificationWithCompletionCompletionIsCalledOnce {
1150
+ [self verifyCompletionCalledForObserverResult: UIBackgroundFetchResultNoData
1151
+ anotherObserverResult: UIBackgroundFetchResultNoData
1152
+ swizzledResult: UIBackgroundFetchResultNoData
1153
+ expecredResult: UIBackgroundFetchResultNoData];
1154
+ }
1155
+
1156
+ - (void )
1157
+ testApplicationDidReceiveRemoteNotificationWithCompletionCompletionIsCalledOnce_HandleFailedState {
1158
+ [self verifyCompletionCalledForObserverResult: UIBackgroundFetchResultFailed
1159
+ anotherObserverResult: UIBackgroundFetchResultFailed
1160
+ swizzledResult: UIBackgroundFetchResultFailed
1161
+ expecredResult: UIBackgroundFetchResultFailed];
1162
+ }
1163
+
1164
+ - (void )testApplicationDidReceiveRemoteNotificationWithCompletionCompletionIsCalledOnce_NoData {
1165
+ [self verifyCompletionCalledForObserverResult: UIBackgroundFetchResultNoData
1166
+ anotherObserverResult: UIBackgroundFetchResultFailed
1167
+ swizzledResult: UIBackgroundFetchResultFailed
1168
+ expecredResult: UIBackgroundFetchResultNoData];
1169
+ }
1170
+ - (void )
1171
+ testApplicationDidReceiveRemoteNotificationWithCompletionCompletionIsCalledOnce_HandleNewDataState_OthersFailed {
1172
+ [self verifyCompletionCalledForObserverResult: UIBackgroundFetchResultNewData
1173
+ anotherObserverResult: UIBackgroundFetchResultFailed
1174
+ swizzledResult: UIBackgroundFetchResultFailed
1175
+ expecredResult: UIBackgroundFetchResultNewData];
1176
+ }
1177
+
1178
+ - (void )
1179
+ testApplicationDidReceiveRemoteNotificationWithCompletionCompletionIsCalledOnce_HandleNewDataState_OthersNoData {
1180
+ [self verifyCompletionCalledForObserverResult: UIBackgroundFetchResultNewData
1181
+ anotherObserverResult: UIBackgroundFetchResultNoData
1182
+ swizzledResult: UIBackgroundFetchResultNoData
1183
+ expecredResult: UIBackgroundFetchResultNewData];
1184
+ }
1185
+
1186
+ - (void )
1187
+ testApplicationDidReceiveRemoteNotificationWithCompletionCompletionIsCalledOnce_HandleNewDataState_OthersNoDataFailed {
1188
+ [self verifyCompletionCalledForObserverResult: UIBackgroundFetchResultNewData
1189
+ anotherObserverResult: UIBackgroundFetchResultNoData
1190
+ swizzledResult: UIBackgroundFetchResultFailed
1191
+ expecredResult: UIBackgroundFetchResultNewData];
1091
1192
}
1092
1193
1093
1194
- (void )testApplicationDidReceiveRemoteNotificationWithCompletionImplementationIsNotAdded {
0 commit comments