diff --git a/AFNetworking/AFHTTPSessionManager.h b/AFNetworking/AFHTTPSessionManager.h index 3e0b9af49b..8072061f69 100644 --- a/AFNetworking/AFHTTPSessionManager.h +++ b/AFNetworking/AFHTTPSessionManager.h @@ -149,7 +149,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (nullable NSURLSessionDataTask *)GET:(NSString *)URLString parameters:(nullable id)parameters - success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success + success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success failure:(nullable void (^)(NSURLSessionDataTask * __nullable task, NSError *error))failure; /** @@ -179,7 +179,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (nullable NSURLSessionDataTask *)POST:(NSString *)URLString parameters:(nullable id)parameters - success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success + success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success failure:(nullable void (^)(NSURLSessionDataTask * __nullable task, NSError *error))failure; /** @@ -196,7 +196,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable NSURLSessionDataTask *)POST:(NSString *)URLString parameters:(nullable id)parameters constructingBodyWithBlock:(nullable void (^)(id formData))block - success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success + success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success failure:(nullable void (^)(NSURLSessionDataTask * __nullable task, NSError *error))failure; /** @@ -211,7 +211,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (nullable NSURLSessionDataTask *)PUT:(NSString *)URLString parameters:(nullable id)parameters - success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success + success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success failure:(nullable void (^)(NSURLSessionDataTask * __nullable task, NSError *error))failure; /** @@ -226,7 +226,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (nullable NSURLSessionDataTask *)PATCH:(NSString *)URLString parameters:(nullable id)parameters - success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success + success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success failure:(nullable void (^)(NSURLSessionDataTask * __nullable task, NSError *error))failure; /** @@ -241,7 +241,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (nullable NSURLSessionDataTask *)DELETE:(NSString *)URLString parameters:(nullable id)parameters - success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success + success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success failure:(nullable void (^)(NSURLSessionDataTask * __nullable task, NSError *error))failure; @end diff --git a/Tests/Tests/AFHTTPSessionManagerTests.m b/Tests/Tests/AFHTTPSessionManagerTests.m index dc810f2bfd..f816b9aa50 100644 --- a/Tests/Tests/AFHTTPSessionManagerTests.m +++ b/Tests/Tests/AFHTTPSessionManagerTests.m @@ -185,4 +185,46 @@ - (void)testThatSerializationErrorGeneratesErrorAndNullTaskForGET { } +# pragma mark - Rest Interface + +- (void)testThatSuccessBlockIsCalledFor200 { + XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"]; + [self.manager + GET:@"status/200" + parameters:nil + success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + [expectation fulfill]; + } + failure:nil]; + [self waitForExpectationsWithCommonTimeoutUsingHandler:nil]; +} + +- (void)testThatFailureBlockIsCalledFor404 { + XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"]; + [self.manager + GET:@"status/404" + parameters:nil + success:nil + failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) { + [expectation fulfill]; + }]; + [self waitForExpectationsWithCommonTimeoutUsingHandler:nil]; +} + +- (void)testThatResponseObjectIsEmptyFor204 { + __block id urlResponseObject = nil; + XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"]; + [self.manager + GET:@"status/204" + parameters:nil + success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + urlResponseObject = responseObject; + [expectation fulfill]; + } + failure:nil]; + [self waitForExpectationsWithCommonTimeoutUsingHandler:nil]; + XCTAssertNil(urlResponseObject); +} + + @end