Repository: SDWebImage/SDWebImage
File: Tests/Tests/SDCategoriesTests.m (Objective-C)

Code before:
    NSData *jpegData1 = [image sd_imageDataAsFormat:SDImageFormatJPEG compressionQuality:1];
    NSData *jpegData2 = [image sd_imageDataAsFormat:SDImageFormatJPEG compressionQuality:0.5];
    expect(jpegData1).notTo.beNil();
    expect(jpegData2).notTo.beNil();
    expect(jpegData1.length).notTo.equal(jpegData2.length);
}

- (void)test03UIImageGIFCategory {
    // Test invalid image data
    UIImage *image = [UIImage sd_imageWithGIFData:nil];
    expect(image).to.beNil();
    // Test valid image data
    NSData *data = [NSData dataWithContentsOfFile:[self testGIFPath]];
    image = [UIImage sd_imageWithGIFData:data];
    expect(image).notTo.beNil();
    expect(image.sd_isAnimated).beTruthy();
    expect(image.sd_imageFrameCount).equal(5);
}

- (void)test04UIViewWebCacheCategory {
    XCTestExpectation *expectation = [self expectationWithDescription:@"Completion is called with url is nil"];
    UIImageView *imageView = [[UIImageView alloc] init];
    SDImageCache *cache = [[SDImageCache alloc] initWithNamespace:@"Test"];
    cache.config.shouldUseWeakMemoryCache = YES;
    SDWebImageManager *imageManager = [[SDWebImageManager alloc] initWithCache:cache loader:[SDWebImageDownloader sharedDownloader]];
    [imageView sd_setImageWithURL:[NSURL URLWithString:kTestJPEGURL] placeholderImage:nil options:0 context:@{SDWebImageContextCustomManager:imageManager} progress:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        expect(image).notTo.beNil();
        [expectation fulfill];
    }];
    [self waitForExpectationsWithCommonTimeout];
    
}

- (void)test05UIViewWebCacheCategory {

    XCTestExpectation *expectation = [self expectationWithDescription:@"Completion is called with url is NSString"];
    
    UIImageView *imageView = [[UIImageView alloc] init];
    SDImageCache *cache = [[SDImageCache alloc] initWithNamespace:@"Test"];
    cache.config.shouldUseWeakMemoryCache = YES;
    SDWebImageManager *imageManager = [[SDWebImageManager alloc] initWithCache:cache loader:[SDWebImageDownloader sharedDownloader]];
    [imageView sd_setImageWithURL:kTestJPEGURL placeholderImage:nil options:0 context:@{SDWebImageContextCustomManager:imageManager} progress:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        expect(image).notTo.beNil();
        [expectation fulfill];
    }];
    [self waitForExpectationsWithCommonTimeout];
}


#pragma mark - Helper


Review comment (suggestion):
This params seems not `nil` ：）

Since you want to test `when sd_setImage(with:) pass a nil url`, you should use `nil` here, and inside the completion block, assert the `expect(image).to.beNil()`.

Code after:
    NSData *jpegData1 = [image sd_imageDataAsFormat:SDImageFormatJPEG compressionQuality:1];
    NSData *jpegData2 = [image sd_imageDataAsFormat:SDImageFormatJPEG compressionQuality:0.5];
    expect(jpegData1).notTo.beNil();
    expect(jpegData2).notTo.beNil();
    expect(jpegData1.length).notTo.equal(jpegData2.length);
}

- (void)test03UIImageGIFCategory {
    // Test invalid image data
    UIImage *image = [UIImage sd_imageWithGIFData:nil];
    expect(image).to.beNil();
    // Test valid image data
    NSData *data = [NSData dataWithContentsOfFile:[self testGIFPath]];
    image = [UIImage sd_imageWithGIFData:data];
    expect(image).notTo.beNil();
    expect(image.sd_isAnimated).beTruthy();
    expect(image.sd_imageFrameCount).equal(5);
}

#pragma mark - Helper

- (NSString *)testJPEGPath {
    NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
    return [testBundle pathForResource:@"TestImage" ofType:@"jpg"];
}

- (NSString *)testGIFPath {
    NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
    return [testBundle pathForResource:@"TestImage" ofType:@"gif"];
}

@end