diff --git a/Parse/Internal/Commands/CommandRunner/URLSession/Session/TaskDelegate/PFURLSessionJSONDataTaskDelegate.m b/Parse/Internal/Commands/CommandRunner/URLSession/Session/TaskDelegate/PFURLSessionJSONDataTaskDelegate.m index 4d6d5d642..7160d00a2 100644 --- a/Parse/Internal/Commands/CommandRunner/URLSession/Session/TaskDelegate/PFURLSessionJSONDataTaskDelegate.m +++ b/Parse/Internal/Commands/CommandRunner/URLSession/Session/TaskDelegate/PFURLSessionJSONDataTaskDelegate.m @@ -61,21 +61,25 @@ - (void)_taskDidFinish { return; } - if ([result isKindOfClass:[NSDictionary class]]) { - NSDictionary *resultDictionary = (NSDictionary *)result; - if (resultDictionary[@"error"]) { - NSMutableDictionary *errorDictionary = [NSMutableDictionary dictionaryWithDictionary:resultDictionary]; - errorDictionary[@"temporary"] = @(self.response.statusCode >= 500 || self.response.statusCode < 400); - self.error = [PFErrorUtilities errorFromResult:errorDictionary]; - [super _taskDidFinish]; - return; + if (self.response.statusCode >= 200) { + if (self.response.statusCode < 400) { + PFCommandResult *commandResult = [PFCommandResult commandResultWithResult:result + resultString:resultString + httpResponse:self.response]; + self.result = commandResult; + } else if ([result isKindOfClass:[NSDictionary class]]) { + NSDictionary *resultDictionary = (NSDictionary *)result; + if (resultDictionary[@"error"]) { + NSMutableDictionary *errorDictionary = [NSMutableDictionary dictionaryWithDictionary:resultDictionary]; + errorDictionary[@"temporary"] = @(self.response.statusCode >= 500 || self.response.statusCode < 400); + self.error = [PFErrorUtilities errorFromResult:errorDictionary]; + } } } - PFCommandResult *commandResult = [PFCommandResult commandResultWithResult:result - resultString:resultString - httpResponse:self.response]; - self.result = commandResult; + if (!self.result && !self.error) { + self.error = [PFErrorUtilities errorWithCode:kPFErrorInternalServer message:resultString]; + } [super _taskDidFinish]; } diff --git a/Tests/Unit/URLSessionDataTaskDelegateTests.m b/Tests/Unit/URLSessionDataTaskDelegateTests.m index 1df09b8e6..f152b58cc 100644 --- a/Tests/Unit/URLSessionDataTaskDelegateTests.m +++ b/Tests/Unit/URLSessionDataTaskDelegateTests.m @@ -70,11 +70,11 @@ - (void)testSuccess { NSData *chunkA = [@"{ \"foo\" :" dataUsingEncoding:NSUTF8StringEncoding]; NSData *chunkB = [@" \"bar\" }" dataUsingEncoding:NSUTF8StringEncoding]; - NSURLResponse *urlResponse = [[NSURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"] - MIMEType:@"application/json" - expectedContentLength:chunkA.length + chunkB.length - textEncodingName:@"UTF-8"]; - + NSHTTPURLResponse *urlResponse = [[NSHTTPURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"] + statusCode:200 + HTTPVersion:@"HTTP/1.1" + headerFields:nil]; + [delegate URLSession:mockedSession task:mockedTask didSendBodyData:5 diff --git a/Tests/Unit/URLSessionTests.m b/Tests/Unit/URLSessionTests.m index 83ff3a112..7d1cd6d8f 100644 --- a/Tests/Unit/URLSessionTests.m +++ b/Tests/Unit/URLSessionTests.m @@ -64,29 +64,29 @@ - (void)testConstructors { NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *URLSession = [NSURLSession sharedSession]; id delegate = PFStrictProtocolMock(@protocol(PFURLSessionDelegate)); - + PFURLSession *session = [[PFURLSession alloc] initWithConfiguration:configuration delegate:delegate]; XCTAssertNotNil(session); XCTAssertEqual((id)session.delegate, delegate); [session invalidateAndCancel]; - + session = [PFURLSession sessionWithConfiguration:configuration delegate:delegate]; XCTAssertNotNil(session); XCTAssertEqual((id)session.delegate, delegate); [session invalidateAndCancel]; - + session = [[PFURLSession alloc] initWithURLSession:URLSession delegate:delegate]; XCTAssertNotNil(URLSession); XCTAssertEqual((id)session.delegate, delegate); - + session = [PFURLSession sessionWithURLSession:URLSession delegate:delegate]; XCTAssertNotNil(session); XCTAssertEqual((id)session.delegate, delegate); - + PFAssertThrowsInconsistencyException([PFURLSession new]); } @@ -95,26 +95,26 @@ - (void)testPerformDataRequestSuccess { NSURLRequest *mockedURLRequest = PFStrictClassMock([NSURLRequest class]); PFRESTCommand *mockedCommand = PFStrictClassMock([PFRESTCommand class]); NSArray *mocks = @[ mockedURLSession, mockedURLRequest, mockedCommand ]; - + MockedSessionTask *mockedDataTask = [[MockedSessionTask alloc] init]; mockedDataTask.originalRequest = mockedURLRequest; - + __block id sessionDelegate = nil; - + OCMExpect([mockedURLSession dataTaskWithRequest:mockedURLRequest]).andReturn(mockedDataTask); - + mockedDataTask.taskIdentifier = 1337; - + @weakify(mockedDataTask); mockedDataTask.resumeBlock = ^{ @strongify(mockedDataTask); - + NSData *dataRecieved = [@"{ \"foo\": \"bar\" }" dataUsingEncoding:NSUTF8StringEncoding]; - NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"] - MIMEType:@"application/json" - expectedContentLength:dataRecieved.length - textEncodingName:@"UTF-8"]; - + NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"] + statusCode:200 + HTTPVersion:@"HTTP/1.1" + headerFields:nil]; + [sessionDelegate URLSession:mockedURLSession dataTask:(id)mockedDataTask didReceiveResponse:response @@ -122,17 +122,17 @@ - (void)testPerformDataRequestSuccess { XCTAssertEqual(disposition, NSURLSessionResponseAllow); }]; [sessionDelegate URLSession:mockedURLSession dataTask:(id)mockedDataTask didReceiveData:dataRecieved]; - + [sessionDelegate URLSession:mockedURLSession task:(id)mockedDataTask didCompleteWithError:nil]; }; - + id delegate = PFStrictProtocolMock(@protocol(PFURLSessionDelegate)); PFURLSession *session = [PFURLSession sessionWithURLSession:mockedURLSession delegate:delegate]; sessionDelegate = (id)session; - + OCMExpect([delegate urlSession:session willPerformURLRequest:mockedURLRequest]); OCMExpect([delegate urlSession:session didPerformURLRequest:mockedURLRequest withURLResponse:[OCMArg isNotNil]]); - + XCTestExpectation *expectation = [self currentSelectorTestExpectation]; [[session performDataURLRequestAsync:mockedURLRequest forCommand:mockedCommand cancellationToken:nil] continueWithBlock:^id(BFTask *task) { PFCommandResult *actualResult = task.result; @@ -141,7 +141,7 @@ - (void)testPerformDataRequestSuccess { return nil; }]; [self waitForTestExpectations]; - + OCMVerifyAll((id)mockedURLSession); OCMVerifyAll(delegate); [mocks makeObjectsPerformSelector:@selector(stopMocking)]; @@ -153,12 +153,12 @@ - (void)testPerformDataRequesPreCancel { PFRESTCommand *mockedCommand = PFStrictClassMock([PFRESTCommand class]); id delegate = PFStrictProtocolMock(@protocol(PFURLSessionDelegate)); NSArray *mocks = @[ mockedURLSession, mockedURLRequest, mockedCommand ]; - + BFCancellationTokenSource *cancellationTokenSource = [BFCancellationTokenSource cancellationTokenSource]; PFURLSession *session = [PFURLSession sessionWithURLSession:mockedURLSession delegate:delegate]; - + XCTestExpectation *expectation = [self currentSelectorTestExpectation]; - + [cancellationTokenSource cancel]; [[session performDataURLRequestAsync:mockedURLRequest forCommand:mockedCommand @@ -177,27 +177,27 @@ - (void)testPerformDataRequestCancellation { NSURLRequest *mockedURLRequest = PFStrictClassMock([NSURLRequest class]); PFRESTCommand *mockedCommand = PFStrictClassMock([PFRESTCommand class]); NSArray *mocks = @[ mockedURLSession, mockedURLRequest, mockedCommand ]; - + MockedSessionTask *mockedDataTask = [[MockedSessionTask alloc] init]; mockedDataTask.originalRequest = mockedURLRequest; - + BFCancellationTokenSource *cancellationTokenSource = [BFCancellationTokenSource cancellationTokenSource]; __block id sessionDelegate = nil; - + OCMExpect([mockedURLSession dataTaskWithRequest:mockedURLRequest]).andReturn(mockedDataTask); - + mockedDataTask.taskIdentifier = 1337; - + @weakify(mockedDataTask); mockedDataTask.resumeBlock = ^{ @strongify(mockedDataTask); - + NSData *dataRecieved = [@"{ \"foo\": \"bar\" }" dataUsingEncoding:NSUTF8StringEncoding]; NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"] MIMEType:@"application/json" expectedContentLength:dataRecieved.length textEncodingName:@"UTF-8"]; - + [sessionDelegate URLSession:mockedURLSession dataTask:(id)mockedDataTask didReceiveResponse:response @@ -206,24 +206,24 @@ - (void)testPerformDataRequestCancellation { }]; [sessionDelegate URLSession:mockedURLSession dataTask:(id)mockedDataTask didReceiveData:dataRecieved]; [cancellationTokenSource cancel]; - + [sessionDelegate URLSession:mockedURLSession task:(id)mockedDataTask didCompleteWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:nil]]; }; - + XCTestExpectation *cancelExpectation = [self expectationWithDescription:@"cancel"]; mockedDataTask.cancelBlock = ^{ [cancelExpectation fulfill]; }; - + id delegate = PFStrictProtocolMock(@protocol(PFURLSessionDelegate)); PFURLSession *session = [PFURLSession sessionWithURLSession:mockedURLSession delegate:delegate]; sessionDelegate = (id)session; - + OCMExpect([delegate urlSession:session willPerformURLRequest:mockedURLRequest]); OCMExpect([delegate urlSession:session didPerformURLRequest:mockedURLRequest withURLResponse:[OCMArg isNotNil]]); - + XCTestExpectation *expectation = [self currentSelectorTestExpectation]; [[session performDataURLRequestAsync:mockedURLRequest forCommand:mockedCommand @@ -233,7 +233,7 @@ - (void)testPerformDataRequestCancellation { return nil; }]; [self waitForTestExpectations]; - + OCMVerifyAll((id)mockedURLSession); OCMVerifyAll(delegate); [mocks makeObjectsPerformSelector:@selector(stopMocking)]; @@ -244,30 +244,30 @@ - (void)testPerformDataRequestError { NSURLRequest *mockedURLRequest = PFStrictClassMock([NSURLRequest class]); PFRESTCommand *mockedCommand = PFStrictClassMock([PFRESTCommand class]); NSArray *mocks = @[ mockedURLSession, mockedURLRequest, mockedCommand ]; - + MockedSessionTask *mockedDataTask = [[MockedSessionTask alloc] init]; mockedDataTask.originalRequest = mockedURLRequest; - + NSError *expectedError = [NSError errorWithDomain:PFParseErrorDomain code:1337 userInfo:nil]; __block id sessionDelegate = nil; - + OCMExpect([mockedURLSession dataTaskWithRequest:mockedURLRequest]).andReturn(mockedDataTask); - + mockedDataTask.taskIdentifier = 1337; - + @weakify(mockedDataTask); mockedDataTask.resumeBlock = ^{ @strongify(mockedDataTask); [sessionDelegate URLSession:mockedURLSession task:(id)mockedDataTask didCompleteWithError:expectedError]; }; - + id delegate = PFStrictProtocolMock(@protocol(PFURLSessionDelegate)); PFURLSession *session = [PFURLSession sessionWithURLSession:mockedURLSession delegate:delegate]; sessionDelegate = (id)session; - + OCMExpect([delegate urlSession:session willPerformURLRequest:mockedURLRequest]); OCMExpect([delegate urlSession:session didPerformURLRequest:mockedURLRequest withURLResponse:nil]); - + XCTestExpectation *expectation = [self currentSelectorTestExpectation]; [[session performDataURLRequestAsync:mockedURLRequest forCommand:mockedCommand cancellationToken:nil] continueWithBlock:^id(BFTask *task) { @@ -277,7 +277,7 @@ - (void)testPerformDataRequestError { return nil; }]; [self waitForTestExpectations]; - + OCMVerifyAll((id)mockedURLSession); OCMVerifyAll(delegate); [mocks makeObjectsPerformSelector:@selector(stopMocking)]; @@ -288,13 +288,13 @@ - (void)testFileUploadRequestPreCancel { NSURLRequest *mockedURLRequest = PFStrictClassMock([NSURLRequest class]); PFRESTCommand *mockedCommand = PFStrictClassMock([PFRESTCommand class]); NSArray *mocks = @[ mockedURLSession, mockedURLRequest, mockedCommand ]; - + BFCancellationTokenSource *cancellationTokenSource = [BFCancellationTokenSource cancellationTokenSource]; NSString *exampleFile = @"file.txt"; - + id delegate = PFStrictProtocolMock(@protocol(PFURLSessionDelegate)); PFURLSession *session = [PFURLSession sessionWithURLSession:mockedURLSession delegate:delegate]; - + XCTestExpectation *expectation = [self currentSelectorTestExpectation]; [cancellationTokenSource cancel]; [[session performFileUploadURLRequestAsync:mockedURLRequest @@ -318,26 +318,26 @@ - (void)testFileUploadSuccess { NSURLRequest *mockedURLRequest = PFStrictClassMock([NSURLRequest class]); PFRESTCommand *mockedCommand = PFStrictClassMock([PFRESTCommand class]); NSArray *mocks = @[ mockedURLSession, mockedURLRequest, mockedCommand ]; - + MockedSessionTask *mockedUploadTask = [[MockedSessionTask alloc] init]; mockedUploadTask.originalRequest = mockedURLRequest; - + NSString *exampleFile = @"file.txt"; __block id sessionDelegate = nil; - + OCMExpect([mockedURLSession uploadTaskWithRequest:mockedURLRequest fromFile:[NSURL fileURLWithPath:exampleFile]]).andReturn(mockedUploadTask); - + mockedUploadTask.taskIdentifier = 1337; - + @weakify(mockedUploadTask); mockedUploadTask.resumeBlock = ^{ @strongify(mockedUploadTask); NSData *dataToSend = [@"{ \"foo\": \"bar\" }" dataUsingEncoding:NSUTF8StringEncoding]; - NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"] - MIMEType:@"application/json" - expectedContentLength:dataToSend.length - textEncodingName:@"UTF-8"]; - + NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"] + statusCode:200 + HTTPVersion:@"HTTP/1.1" + headerFields:nil]; + for (NSUInteger progress = 0; progress < dataToSend.length; progress++) { [sessionDelegate URLSession:mockedURLSession task:(id)mockedUploadTask @@ -345,32 +345,32 @@ - (void)testFileUploadSuccess { totalBytesSent:progress totalBytesExpectedToSend:dataToSend.length]; } - + [sessionDelegate URLSession:mockedURLSession dataTask:(id)mockedUploadTask didReceiveResponse:response completionHandler:^(NSURLSessionResponseDisposition disposition) { XCTAssertEqual(disposition, NSURLSessionResponseAllow); }]; - + [sessionDelegate URLSession:mockedURLSession dataTask:(id)mockedUploadTask didReceiveData:dataToSend]; - + [sessionDelegate URLSession:mockedURLSession task:(id)mockedUploadTask didCompleteWithError:nil]; }; - + id delegate = PFStrictProtocolMock(@protocol(PFURLSessionDelegate)); PFURLSession *session = [PFURLSession sessionWithURLSession:mockedURLSession delegate:delegate]; sessionDelegate = (id)session; - + OCMExpect([delegate urlSession:session willPerformURLRequest:mockedURLRequest]); OCMExpect([delegate urlSession:session didPerformURLRequest:mockedURLRequest withURLResponse:[OCMArg isNotNil]]); - + __block int lastProgress = 0; - + XCTestExpectation *expectation = [self currentSelectorTestExpectation]; [[session performFileUploadURLRequestAsync:mockedURLRequest forCommand:mockedCommand @@ -387,7 +387,7 @@ - (void)testFileUploadSuccess { return nil; }]; [self waitForTestExpectations]; - + OCMVerifyAll((id)mockedURLSession); OCMVerifyAll(delegate); [mocks makeObjectsPerformSelector:@selector(stopMocking)]; @@ -399,28 +399,28 @@ - (void)testFileUploadRequestCancellation { NSURLRequest *mockedURLRequest = PFStrictClassMock([NSURLRequest class]); PFRESTCommand *mockedCommand = PFStrictClassMock([PFRESTCommand class]); NSArray *mocks = @[ mockedURLSession, mockedURLRequest, mockedCommand ]; - + MockedSessionTask *mockedUploadTask = [[MockedSessionTask alloc] init]; mockedUploadTask.originalRequest = mockedURLRequest; - + BFCancellationTokenSource *cancellationTokenSource = [BFCancellationTokenSource cancellationTokenSource]; NSString *exampleFile = @"file.txt"; __block id sessionDelegate = nil; - + OCMExpect([mockedURLSession uploadTaskWithRequest:mockedURLRequest fromFile:[NSURL fileURLWithPath:exampleFile]]).andReturn(mockedUploadTask); - + mockedUploadTask.taskIdentifier = 1337; - + @weakify(mockedUploadTask); mockedUploadTask.resumeBlock = ^{ @strongify(mockedUploadTask); - + NSData *dataToSend = [@"{ \"foo\": \"bar\" }" dataUsingEncoding:NSUTF8StringEncoding]; NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"] MIMEType:@"application/json" expectedContentLength:dataToSend.length textEncodingName:@"UTF-8"]; - + for (NSUInteger progress = 0; progress < dataToSend.length; progress++) { [sessionDelegate URLSession:mockedURLSession task:(id)mockedUploadTask @@ -428,39 +428,39 @@ - (void)testFileUploadRequestCancellation { totalBytesSent:progress totalBytesExpectedToSend:dataToSend.length]; } - + [sessionDelegate URLSession:mockedURLSession dataTask:(id)mockedUploadTask didReceiveResponse:response completionHandler:^(NSURLSessionResponseDisposition disposition) { XCTAssertEqual(disposition, NSURLSessionResponseAllow); }]; - + [sessionDelegate URLSession:mockedURLSession dataTask:(id)mockedUploadTask didReceiveData:dataToSend]; - + [cancellationTokenSource cancel]; - + [sessionDelegate URLSession:mockedURLSession task:(id)mockedUploadTask didCompleteWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:nil]]; }; - + XCTestExpectation *cancelExpectation = [self expectationWithDescription:@"cancel"]; mockedUploadTask.cancelBlock = ^{ [cancelExpectation fulfill]; }; - + id delegate = PFProtocolMock(@protocol(PFURLSessionDelegate)); PFURLSession *session = [PFURLSession sessionWithURLSession:mockedURLSession delegate:delegate]; sessionDelegate = (id)session; - + OCMExpect([delegate urlSession:session willPerformURLRequest:mockedURLRequest]); OCMExpect([delegate urlSession:session didPerformURLRequest:mockedURLRequest withURLResponse:[OCMArg isNotNil]]); - + __block int lastProgress = 0; - + XCTestExpectation *expectation = [self currentSelectorTestExpectation]; [[session performFileUploadURLRequestAsync:mockedURLRequest forCommand:mockedCommand @@ -476,7 +476,7 @@ - (void)testFileUploadRequestCancellation { return nil; }]; [self waitForTestExpectations]; - + OCMVerifyAll((id)mockedURLSession); OCMVerifyAll(delegate); [mocks makeObjectsPerformSelector:@selector(stopMocking)]; @@ -487,27 +487,26 @@ - (void)testCaching { NSURLRequest *mockedURLRequest = PFStrictClassMock([NSURLRequest class]); PFRESTCommand *mockedCommand = PFStrictClassMock([PFRESTCommand class]); NSArray *mocks = @[ mockedURLSession, mockedURLRequest, mockedCommand ]; - + MockedSessionTask *mockedDataTask = [[MockedSessionTask alloc] init]; mockedDataTask.originalRequest = mockedURLRequest; - + __block id sessionDelegate = nil; - + OCMStub([mockedURLSession dataTaskWithRequest:mockedURLRequest]).andReturn(mockedDataTask); - + mockedDataTask.taskIdentifier = 1337; @weakify(mockedDataTask); mockedDataTask.resumeBlock = ^{ @strongify(mockedDataTask); NSData *dataRecieved = [@"{ \"foo\": \"bar\" }" dataUsingEncoding:NSUTF8StringEncoding]; - NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"] - MIMEType:@"application/json" - expectedContentLength:dataRecieved.length - textEncodingName:@"UTF-8"]; - - NSCachedURLResponse *cachedResponse = - [[NSCachedURLResponse alloc] initWithResponse:response data:dataRecieved]; - + NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"] + statusCode:200 + HTTPVersion:@"HTTP/1.1" + headerFields:nil]; + NSCachedURLResponse *cachedResponse = [[NSCachedURLResponse alloc] initWithResponse:response + data:dataRecieved]; + [sessionDelegate URLSession:mockedURLSession dataTask:(id)mockedDataTask didReceiveResponse:response @@ -516,20 +515,20 @@ - (void)testCaching { }]; [sessionDelegate URLSession:mockedURLSession dataTask:(id)mockedDataTask didReceiveData:dataRecieved]; [sessionDelegate URLSession:mockedURLSession task:(id)mockedDataTask didCompleteWithError:nil]; - + [sessionDelegate URLSession:mockedURLSession dataTask:(id)mockedDataTask willCacheResponse:cachedResponse completionHandler:^(NSCachedURLResponse *cached) { XCTAssertNil(cached); }]; }; - + id delegate = PFProtocolMock(@protocol(PFURLSessionDelegate)); PFURLSession *session = [PFURLSession sessionWithURLSession:mockedURLSession delegate:delegate]; sessionDelegate = (id)session; - + OCMExpect([delegate urlSession:session willPerformURLRequest:mockedURLRequest]); OCMExpect([delegate urlSession:session didPerformURLRequest:mockedURLRequest withURLResponse:[OCMArg isNotNil]]); - + XCTestExpectation *expectation = [self currentSelectorTestExpectation]; [[session performDataURLRequestAsync:mockedURLRequest forCommand:mockedCommand cancellationToken:nil] continueWithBlock:^id(BFTask *task) { @@ -538,7 +537,7 @@ - (void)testCaching { return nil; }]; [self waitForTestExpectations]; - + OCMVerifyAll((id)mockedURLSession); OCMVerifyAll(delegate); [mocks makeObjectsPerformSelector:@selector(stopMocking)]; diff --git a/Tests/Unit/URLSessionUploadTaskDelegateTests.m b/Tests/Unit/URLSessionUploadTaskDelegateTests.m index a30f3ca53..fb803dde5 100644 --- a/Tests/Unit/URLSessionUploadTaskDelegateTests.m +++ b/Tests/Unit/URLSessionUploadTaskDelegateTests.m @@ -98,10 +98,10 @@ - (void)testUploadProgress { NSData *chunkA = [@"{ \"foo\" :" dataUsingEncoding:NSUTF8StringEncoding]; NSData *chunkB = [@" \"bar\" }" dataUsingEncoding:NSUTF8StringEncoding]; - NSURLResponse *urlResponse = [[NSURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"] - MIMEType:@"application/json" - expectedContentLength:chunkA.length + chunkB.length - textEncodingName:@"UTF-8"]; + NSHTTPURLResponse *urlResponse = [[NSHTTPURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"] + statusCode:200 + HTTPVersion:@"HTTP/1.1" + headerFields:nil]; for (int progress = 1; progress <= 10; progress++) { [delegate URLSession:mockedSession @@ -145,10 +145,10 @@ - (void)testSuccess { NSData *chunkA = [@"{ \"foo\" :" dataUsingEncoding:NSUTF8StringEncoding]; NSData *chunkB = [@" \"bar\" }" dataUsingEncoding:NSUTF8StringEncoding]; - NSURLResponse *urlResponse = [[NSURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"] - MIMEType:@"application/json" - expectedContentLength:chunkA.length + chunkB.length - textEncodingName:@"UTF-8"]; + NSHTTPURLResponse *urlResponse = [[NSHTTPURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"] + statusCode:200 + HTTPVersion:@"HTTP/1.1" + headerFields:nil]; [delegate URLSession:mockedSession task:mockedTask