@@ -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,147 @@ - (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 )extracted : (UIApplication *)application
1093
+ completion : (void (^)(UIBackgroundFetchResult))completion
1094
+ notification : (NSDictionary *)notification
1095
+ testAppDelegate : (GULTestAppDelegate *)testAppDelegate {
1096
+ [testAppDelegate application: application
1097
+ didReceiveRemoteNotification: notification
1098
+ fetchCompletionHandler: completion];
1099
+ }
1100
+
1101
+ - (void )testApplicationDidReceiveRemoteNotificationWithCompletionCompletionIsCalledOnce {
1102
+ NSDictionary *notification = @{};
1103
+ GULApplication *application = [GULApplication sharedApplication ];
1104
+
1105
+ XCTestExpectation *completionExpectation =
1106
+ [[XCTestExpectation alloc ] initWithDescription: @" Completion called once" ];
1107
+ completionExpectation.assertForOverFulfill = YES ;
1108
+
1109
+ void (^completion)(UIBackgroundFetchResult) = ^(UIBackgroundFetchResult result) {
1110
+ [completionExpectation fulfill ];
1111
+ };
1112
+
1113
+ void (^onDidReceiveRemoteNotification)(NSInvocation *invocation) = ^(NSInvocation *invocation) {
1114
+ void __unsafe_unretained (^localCompletionHandler)(UIBackgroundFetchResult) = nil ;
1115
+ [invocation getArgument: (void *)(&localCompletionHandler) atIndex: 4 ];
1116
+ XCTAssertNotNil (localCompletionHandler);
1117
+ localCompletionHandler (UIBackgroundFetchResultNoData);
1118
+ };
1119
+
1120
+ id interceptor = OCMProtocolMock (@protocol (GULApplicationDelegate));
1121
+ OCMExpect ([interceptor application: application
1122
+ didReceiveRemoteNotification: notification
1123
+ fetchCompletionHandler: [OCMArg isNotNil ]])
1124
+ .andDo (onDidReceiveRemoteNotification);
1125
+
1126
+ id interceptor2 = OCMProtocolMock (@protocol (GULApplicationDelegate));
1127
+ OCMExpect ([interceptor2 application: application
1128
+ didReceiveRemoteNotification: notification
1129
+ fetchCompletionHandler: [OCMArg isNotNil ]])
1130
+ .andDo (onDidReceiveRemoteNotification);
1131
+
1132
+ GULTestAppDelegate *testAppDelegate = [[GULTestAppDelegate alloc ] init ];
1133
+ OCMStub ([self .mockSharedApplication delegate ]).andReturn (testAppDelegate);
1134
+ [GULAppDelegateSwizzler proxyOriginalDelegateIncludingAPNSMethods ];
1135
+
1136
+ [GULAppDelegateSwizzler registerAppDelegateInterceptor: interceptor];
1137
+ [GULAppDelegateSwizzler registerAppDelegateInterceptor: interceptor2];
1138
+
1139
+ [self extracted: application
1140
+ completion: completion
1141
+ notification: notification
1142
+ testAppDelegate: testAppDelegate];
1143
+ testAppDelegate.remoteNotificationCompletionHandler (UIBackgroundFetchResultNoData);
1144
+ OCMVerifyAll (interceptor);
1145
+ OCMVerifyAll (interceptor2);
1146
+ [self waitForExpectations: @[ completionExpectation ] timeout: 0.1 ];
1147
+ }
1148
+
1149
+ - (void )
1150
+ testApplicationDidReceiveRemoteNotificationWithCompletionCompletionIsCalledOnce_HandleFailedState {
1151
+ NSDictionary *notification = @{};
1152
+ GULApplication *application = [GULApplication sharedApplication ];
1153
+
1154
+ XCTestExpectation *completionExpectation =
1155
+ [[XCTestExpectation alloc ] initWithDescription: @" Completion called once" ];
1156
+ completionExpectation.assertForOverFulfill = YES ;
1157
+
1158
+ void (^completion)(UIBackgroundFetchResult) = ^(UIBackgroundFetchResult result) {
1159
+ XCTAssertEqual (result, UIBackgroundFetchResultFailed);
1160
+ [completionExpectation fulfill ];
1161
+ };
1162
+
1163
+ void (^onDidReceiveRemoteNotification)(NSInvocation *invocation) = ^(NSInvocation *invocation) {
1164
+ void __unsafe_unretained (^localCompletionHandler)(UIBackgroundFetchResult) = nil ;
1165
+ [invocation getArgument: (void *)(&localCompletionHandler) atIndex: 4 ];
1166
+ XCTAssertNotNil (localCompletionHandler);
1167
+ localCompletionHandler (UIBackgroundFetchResultFailed);
1168
+ };
1169
+
1170
+ id interceptor = OCMProtocolMock (@protocol (GULApplicationDelegate));
1171
+ OCMExpect ([interceptor application: application
1172
+ didReceiveRemoteNotification: notification
1173
+ fetchCompletionHandler: [OCMArg isNotNil ]])
1174
+ .andDo (onDidReceiveRemoteNotification);
1175
+
1176
+ GULTestAppDelegate *testAppDelegate = [[GULTestAppDelegate alloc ] init ];
1177
+ OCMStub ([self .mockSharedApplication delegate ]).andReturn (testAppDelegate);
1178
+ [GULAppDelegateSwizzler proxyOriginalDelegateIncludingAPNSMethods ];
1179
+
1180
+ [GULAppDelegateSwizzler registerAppDelegateInterceptor: interceptor];
1181
+
1182
+ [self extracted: application
1183
+ completion: completion
1184
+ notification: notification
1185
+ testAppDelegate: testAppDelegate];
1186
+ testAppDelegate.remoteNotificationCompletionHandler (UIBackgroundFetchResultFailed);
1187
+ OCMVerifyAll (interceptor);
1188
+ [self waitForExpectations: @[ completionExpectation ] timeout: 0.1 ];
1189
+ }
1190
+
1191
+ - (void )
1192
+ testApplicationDidReceiveRemoteNotificationWithCompletionCompletionIsCalledOnce_HandleNewDataState {
1193
+ NSDictionary *notification = @{};
1194
+ GULApplication *application = [GULApplication sharedApplication ];
1195
+
1196
+ XCTestExpectation *completionExpectation =
1197
+ [[XCTestExpectation alloc ] initWithDescription: @" Completion called once" ];
1198
+ completionExpectation.assertForOverFulfill = YES ;
1199
+
1200
+ void (^completion)(UIBackgroundFetchResult) = ^(UIBackgroundFetchResult result) {
1201
+ XCTAssertEqual (result, UIBackgroundFetchResultNewData);
1202
+ [completionExpectation fulfill ];
1203
+ };
1204
+
1205
+ void (^onDidReceiveRemoteNotification)(NSInvocation *invocation) = ^(NSInvocation *invocation) {
1206
+ void __unsafe_unretained (^localCompletionHandler)(UIBackgroundFetchResult) = nil ;
1207
+ [invocation getArgument: (void *)(&localCompletionHandler) atIndex: 4 ];
1208
+ XCTAssertNotNil (localCompletionHandler);
1209
+ localCompletionHandler (UIBackgroundFetchResultFailed);
1210
+ };
1211
+
1212
+ id interceptor = OCMProtocolMock (@protocol (GULApplicationDelegate));
1213
+ OCMExpect ([interceptor application: application
1214
+ didReceiveRemoteNotification: notification
1215
+ fetchCompletionHandler: [OCMArg isNotNil ]])
1216
+ .andDo (onDidReceiveRemoteNotification);
1217
+
1218
+ GULTestAppDelegate *testAppDelegate = [[GULTestAppDelegate alloc ] init ];
1219
+ OCMStub ([self .mockSharedApplication delegate ]).andReturn (testAppDelegate);
1220
+ [GULAppDelegateSwizzler proxyOriginalDelegateIncludingAPNSMethods ];
1221
+
1222
+ [GULAppDelegateSwizzler registerAppDelegateInterceptor: interceptor];
1223
+
1224
+ [self extracted: application
1225
+ completion: completion
1226
+ notification: notification
1227
+ testAppDelegate: testAppDelegate];
1228
+ testAppDelegate.remoteNotificationCompletionHandler (UIBackgroundFetchResultNewData);
1229
+ OCMVerifyAll (interceptor);
1230
+ [self waitForExpectations: @[ completionExpectation ] timeout: 0.1 ];
1091
1231
}
1092
1232
1093
1233
- (void )testApplicationDidReceiveRemoteNotificationWithCompletionImplementationIsNotAdded {
0 commit comments