1010
1111
1212#import < XCTest/XCTest.h>
13- #import < XCTestAsync/XCTestAsync.h>
1413#import < Expecta.h>
1514
1615#import " SDWebImageManager.h"
@@ -37,31 +36,37 @@ - (void)tearDown
3736}
3837
3938- (void )testThatDownloadInvokesCompletionBlockWithCorrectParamsAsync {
39+ __block XCTestExpectation *expectation = [self expectationWithDescription: @" Image download completes" ];
40+
4041 NSURL *originalImageURL = [NSURL URLWithString: @" http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.jpg?20120509154705" ];
4142
4243 [[SDWebImageManager sharedManager ] downloadImageWithURL: originalImageURL options: SDWebImageRefreshCached progress: nil completed: ^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
4344 expect (image).toNot .beNil ();
4445 expect (error).to .beNil ();
4546 expect (originalImageURL).to .equal (imageURL);
46-
47- XCAsyncSuccess ();
47+
48+ [expectation fulfill ];
49+ expectation = nil ;
4850 }];
49-
50- XCAsyncFailAfter ( kAsyncTestTimeout , @" Download image timed out " ) ;
51+
52+ [ self waitForExpectationsWithTimeout: kAsyncTestTimeout handler: nil ] ;
5153}
5254
5355- (void )testThatDownloadWithIncorrectURLInvokesCompletionBlockWithAnErrorAsync {
56+ __block XCTestExpectation *expectation = [self expectationWithDescription: @" Image download completes" ];
57+
5458 NSURL *originalImageURL = [NSURL URLWithString: @" http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.png" ];
5559
5660 [[SDWebImageManager sharedManager ] downloadImageWithURL: originalImageURL options: SDWebImageRefreshCached progress: nil completed: ^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
5761 expect (image).to .beNil ();
5862 expect (error).toNot .beNil ();
5963 expect (originalImageURL).to .equal (imageURL);
6064
61- XCAsyncSuccess ();
65+ [expectation fulfill ];
66+ expectation = nil ;
6267 }];
6368
64- XCAsyncFailAfter ( kAsyncTestTimeout , @" Download image timed out " ) ;
69+ [ self waitForExpectationsWithTimeout: kAsyncTestTimeout handler: nil ] ;
6570}
6671
6772@end
0 commit comments