Skip to content

Instantly share code, notes, and snippets.

@levantAJ
Created February 5, 2018 08:16
Show Gist options
  • Save levantAJ/1693c6ed6f6352201fcf9105807c8879 to your computer and use it in GitHub Desktop.
Save levantAJ/1693c6ed6f6352201fcf9105807c8879 to your computer and use it in GitHub Desktop.
Combination Tests
- (void)testCacheSnapshotCombinations {
for (int i = 0; i < 32; i++) {
@autoreleasepool {
//Given:
UIImage *snapshotImage = [UIImage new];
id image = OCMClassMock([UIImage class]);
OCMStub([image imageForView:OCMOCK_ANY]).andReturn(snapshotImage);
if (i & (1 << 0)) {
self.sut.bounds = CGRectMake(0, 0, 123, 456);
} else {
self.sut.bounds = CGRectZero;
}
if (i & (1 << 1)) {
self.sut.attributedText = [[NSAttributedString alloc] init];
} else {
self.sut.attributedText = nil;
}
if (i & (1 << 2)) {
self.sut.rawText = @"This is raw text";
} else {
self.sut.rawText = @""; // or empty
}
if (i & (1 << 3)) {
OCMStub([self.cacher cachedImageForParameter:OCMOCK_ANY]).andReturn(nil);
} else {
OCMStub([self.cacher cachedImageForParameter:OCMOCK_ANY]).andReturn(snapshotImage);
}
if (i & (1 << 4)) {
OCMStub([self.service hasEmojisForString:OCMOCK_ANY]).andReturn(YES);
} else {
OCMStub([self.service hasEmojisForString:OCMOCK_ANY]).andReturn(NO);
}
if (i != 31) {
OCMReject([image imageForView:OCMOCK_ANY]);
OCMReject([self.cacher cacheImage:OCMOCK_ANY forParameter:OCMOCK_ANY]);
}
//When:
[self.sut cacheSnapshot];
//Then:
if (i == 31) {
OCMVerify([image imageForView:self.sut]);
OCMVerify([self.cacher cacheImage:snapshotImage forParameter:OCMOCK_ANY]);
}
[image stopMocking];
}
[self tearDown];
[self setUp];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment