Last active
December 6, 2016 21:36
-
-
Save petermolnar-dev/9ab360eafa1fe1065a9e35b7f8e1d379 to your computer and use it in GitHub Desktop.
PMODownloaderTests.m - With KVO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <XCTest/XCTest.h> | |
#import "PMODownloader.h" | |
#import "PMODownloadNotifications.h" | |
@interface PMODownloaderTests : XCTestCase | |
@property (strong, nonatomic) PMODownloader *downloader; | |
@end | |
@implementation PMODownloaderTests | |
- (void)setUp { | |
[super setUp]; | |
self.downloader = [[PMODownloader alloc] init]; | |
} | |
- (void)tearDown { | |
self.downloader = nil; | |
[super tearDown]; | |
} | |
/** | |
Testing download OK. | |
*/ | |
- (void)testDownload { | |
XCTestExpectation *expectation = [self keyValueObservingExpectationForObject:self.downloader keyPath:@"downloadedData" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) { | |
[expectation fulfill]; | |
return true; | |
}]; | |
[self.downloader downloadDataFromURL:[NSURL URLWithString:@"https://upload.wikimedia.org/wikipedia/en/4/45/One_black_Pixel.png"]]; | |
[self waitForExpectationsWithTimeout:5.0 handler:^(NSError *error) { | |
if (error) { | |
NSLog(@"Timeout Error: %@", error); | |
} | |
}]; | |
} | |
/** | |
Testing the download failure wiht a nonexisting domain | |
*/ | |
- (void)testPictureAsyncDownloadFailed { | |
XCTestExpectation *expectation = [self expectationForNotification:PMODownloadFailed | |
object: nil | |
handler:^BOOL(NSNotification * _Nonnull notification) { | |
[expectation fulfill]; | |
return true; | |
}]; | |
[self.downloader downloadDataFromURL:[NSURL URLWithString:@"https://ThereIsNoSuCHDomainName/MssedUPName.png"]]; | |
[self waitForExpectationsWithTimeout:5.0 handler:^(NSError *error) { | |
if (error) { | |
NSLog(@"Timeout Error: %@", error); | |
} | |
}]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment