From 07ffd9c2f91d9feb308b6b54944a3799e3c6f4f0 Mon Sep 17 00:00:00 2001 From: Jon Shier Date: Thu, 3 Aug 2023 13:46:23 -0400 Subject: [PATCH] Formatting. --- .swiftformat | 8 +-- Source/ImageFilter.swift | 14 ++--- Source/Request+AlamofireImage.swift | 6 +- Source/UIButton+AlamofireImage.swift | 8 +-- Source/UIImage+AlamofireImage.swift | 9 ++- Source/UIImageView+AlamofireImage.swift | 4 +- Tests/ImageCacheTests.swift | 32 +++++------ Tests/ImageDownloaderTests.swift | 28 ++++----- Tests/ImageFilterTests.swift | 24 ++++---- Tests/RequestTests.swift | 20 +++---- Tests/TestHelpers.swift | 2 +- Tests/UIButtonTests.swift | 76 ++++++++++++------------- Tests/UIImageTests.swift | 8 +-- Tests/UIImageViewTests.swift | 42 +++++++------- 14 files changed, 140 insertions(+), 141 deletions(-) diff --git a/.swiftformat b/.swiftformat index 463abd7..c6b71e8 100644 --- a/.swiftformat +++ b/.swiftformat @@ -2,7 +2,7 @@ --exclude Carthage --symlinks ignore ---swiftversion 5.3 +--swiftversion 5.5 # rules --enable isEmpty @@ -25,6 +25,6 @@ --nospaceoperators ..<, ... --selfrequired validate --stripunusedargs closure-only ---wraparguments after-first ---wrapcollections after-first ---wrapparameters after-first +--wraparguments preserve +--wrapcollections preserve +--wrapparameters preserve diff --git a/Source/ImageFilter.swift b/Source/ImageFilter.swift index b217e0c..e073a91 100644 --- a/Source/ImageFilter.swift +++ b/Source/ImageFilter.swift @@ -75,7 +75,7 @@ public protocol Roundable { extension ImageFilter where Self: Roundable { /// The unique idenitifier for an `ImageFilter` conforming to the `Roundable` protocol. public var identifier: String { - let radius = Int64(self.radius.rounded()) + let radius = Int64(radius.rounded()) return "\(type(of: self))-radius:(\(radius))" } } @@ -171,7 +171,7 @@ public struct ScaledToSizeFilter: ImageFilter, Sizable { /// The filter closure used to create the modified representation of the given image. public var filter: (Image) -> Image { { image in - image.af.imageScaled(to: self.size) + image.af.imageScaled(to: size) } } } @@ -195,7 +195,7 @@ public struct AspectScaledToFitSizeFilter: ImageFilter, Sizable { /// The filter closure used to create the modified representation of the given image. public var filter: (Image) -> Image { { image in - image.af.imageAspectScaled(toFit: self.size) + image.af.imageAspectScaled(toFit: size) } } } @@ -220,7 +220,7 @@ public struct AspectScaledToFillSizeFilter: ImageFilter, Sizable { /// The filter closure used to create the modified representation of the given image. public var filter: (Image) -> Image { { image in - image.af.imageAspectScaled(toFill: self.size) + image.af.imageAspectScaled(toFill: size) } } } @@ -253,14 +253,14 @@ public struct RoundedCornersFilter: ImageFilter, Roundable { /// The filter closure used to create the modified representation of the given image. public var filter: (Image) -> Image { { image in - image.af.imageRounded(withCornerRadius: self.radius, - divideRadiusByImageScale: self.divideRadiusByImageScale) + image.af.imageRounded(withCornerRadius: radius, + divideRadiusByImageScale: divideRadiusByImageScale) } } /// The unique idenitifier for an `ImageFilter` conforming to the `Roundable` protocol. public var identifier: String { - let radius = Int64(self.radius.rounded()) + let radius = Int64(radius.rounded()) return "\(type(of: self))-radius:(\(radius))-divided:(\(divideRadiusByImageScale))" } } diff --git a/Source/Request+AlamofireImage.swift b/Source/Request+AlamofireImage.swift index 21e515e..dd689fb 100644 --- a/Source/Request+AlamofireImage.swift +++ b/Source/Request+AlamofireImage.swift @@ -67,17 +67,17 @@ public final class ImageResponseSerializer: ResponseSerializer { contentTypes.insert("image/webp") } #endif - + if #available(macOS 10.13, iOS 11, tvOS 11, watchOS 4, *) { contentTypes.formUnion(["image/heic", "image/heif"]) } - + #if !os(watchOS) if #available(macOS 13.0, iOS 16.0, tvOS 16.0, *) { contentTypes.insert("image/avif") } #endif - + if #available(macOS 14.0, iOS 17.0, tvOS 17.0, watchOS 10.0, *) { contentTypes.insert("image/jxl") } diff --git a/Source/UIButton+AlamofireImage.swift b/Source/UIButton+AlamofireImage.swift index 894ddfd..394d66e 100644 --- a/Source/UIButton+AlamofireImage.swift +++ b/Source/UIButton+AlamofireImage.swift @@ -182,7 +182,7 @@ extension AlamofireExtension where ExtendedType: UIButton { cancelImageRequest(for: state) - let imageDownloader = self.imageDownloader ?? UIButton.af.sharedImageDownloader + let imageDownloader = imageDownloader ?? UIButton.af.sharedImageDownloader let imageCache = imageDownloader.imageCache // Use the image from the image cache if it exists @@ -253,7 +253,7 @@ extension AlamofireExtension where ExtendedType: UIButton { public func cancelImageRequest(for state: ControlState) { guard let receipt = imageRequestReceipt(for: state) else { return } - let imageDownloader = self.imageDownloader ?? UIButton.af.sharedImageDownloader + let imageDownloader = imageDownloader ?? UIButton.af.sharedImageDownloader imageDownloader.cancelRequest(with: receipt) setImageRequestReceipt(nil, for: state) @@ -351,7 +351,7 @@ extension AlamofireExtension where ExtendedType: UIButton { cancelBackgroundImageRequest(for: state) - let imageDownloader = self.imageDownloader ?? UIButton.af.sharedImageDownloader + let imageDownloader = imageDownloader ?? UIButton.af.sharedImageDownloader let imageCache = imageDownloader.imageCache // Use the image from the image cache if it exists @@ -422,7 +422,7 @@ extension AlamofireExtension where ExtendedType: UIButton { public func cancelBackgroundImageRequest(for state: ControlState) { guard let receipt = backgroundImageRequestReceipt(for: state) else { return } - let imageDownloader = self.imageDownloader ?? UIButton.af.sharedImageDownloader + let imageDownloader = imageDownloader ?? UIButton.af.sharedImageDownloader imageDownloader.cancelRequest(with: receipt) setBackgroundImageRequestReceipt(nil, for: state) diff --git a/Source/UIImage+AlamofireImage.swift b/Source/UIImage+AlamofireImage.swift index a2068ea..7dfa398 100644 --- a/Source/UIImage+AlamofireImage.swift +++ b/Source/UIImage+AlamofireImage.swift @@ -133,12 +133,11 @@ extension AlamofireExtension where ExtendedType: UIImage { public var containsAlphaComponent: Bool { let alphaInfo = type.cgImage?.alphaInfo - return ( + return alphaInfo == .first || - alphaInfo == .last || - alphaInfo == .premultipliedFirst || - alphaInfo == .premultipliedLast - ) + alphaInfo == .last || + alphaInfo == .premultipliedFirst || + alphaInfo == .premultipliedLast } /// Returns whether the image is opaque. diff --git a/Source/UIImageView+AlamofireImage.swift b/Source/UIImageView+AlamofireImage.swift index 027b421..f77cfe4 100644 --- a/Source/UIImageView+AlamofireImage.swift +++ b/Source/UIImageView+AlamofireImage.swift @@ -282,7 +282,7 @@ extension AlamofireExtension where ExtendedType: UIImageView { cancelImageRequest() - let imageDownloader = self.imageDownloader ?? UIImageView.af.sharedImageDownloader + let imageDownloader = imageDownloader ?? UIImageView.af.sharedImageDownloader let imageCache = imageDownloader.imageCache // Use the image from the image cache if it exists @@ -371,7 +371,7 @@ extension AlamofireExtension where ExtendedType: UIImageView { public func cancelImageRequest() { guard let activeRequestReceipt = activeRequestReceipt else { return } - let imageDownloader = self.imageDownloader ?? UIImageView.af.sharedImageDownloader + let imageDownloader = imageDownloader ?? UIImageView.af.sharedImageDownloader imageDownloader.cancelRequest(with: activeRequestReceipt) self.activeRequestReceipt = nil diff --git a/Tests/ImageCacheTests.swift b/Tests/ImageCacheTests.swift index 0530725..69e2ae8 100644 --- a/Tests/ImageCacheTests.swift +++ b/Tests/ImageCacheTests.swift @@ -61,7 +61,7 @@ final class ImageCacheTestCase: BaseTestCase { func testThatItCanAddImageToCacheWithIdentifier() { // Given - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") let identifier = "unicorn" // When @@ -75,7 +75,7 @@ final class ImageCacheTestCase: BaseTestCase { func testThatItCanAddImageToCacheWithRequestIdentifier() { // Given - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") let request = Endpoint.get.urlRequest let identifier = "-unicorn" @@ -137,7 +137,7 @@ final class ImageCacheTestCase: BaseTestCase { func testThatItCanRemoveImageFromCacheWithIdentifier() { // Given - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") let identifier = "unicorn" // When @@ -155,7 +155,7 @@ final class ImageCacheTestCase: BaseTestCase { func testThatItCanRemoveImageFromCacheWithRequestIdentifier() { // Given - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") let request = Endpoint.get.urlRequest let identifier = "unicorn" @@ -174,7 +174,7 @@ final class ImageCacheTestCase: BaseTestCase { func testThatItCanRemoveImagesFromCacheMatchingRequestIdentifier() { // Given - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") let request = Endpoint.get.urlRequest let identifier1 = "unicorn-100" @@ -201,7 +201,7 @@ final class ImageCacheTestCase: BaseTestCase { func testThatItCanRemoveAllImagesFromCache() { // Given - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") let identifier = "unicorn" // When @@ -221,7 +221,7 @@ final class ImageCacheTestCase: BaseTestCase { func testThatItRemovesAllImagesFromCacheWhenReceivingMemoryWarningNotification() { // Given - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") let identifier = "unicorn" // When @@ -245,7 +245,7 @@ final class ImageCacheTestCase: BaseTestCase { func testThatItCanFetchImageFromCacheWithIdentifier() { // Given - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") let identifier = "unicorn" // When @@ -260,7 +260,7 @@ final class ImageCacheTestCase: BaseTestCase { func testThatItCanFetchImageFromCacheWithRequestIdentifier() { // Given - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") let request = Endpoint.get.urlRequest let identifier = "unicorn" @@ -278,7 +278,7 @@ final class ImageCacheTestCase: BaseTestCase { func testThatItIncrementsMemoryUsageWhenAddingImageToCache() { // Given - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") let identifier = "unicorn" // When @@ -293,7 +293,7 @@ final class ImageCacheTestCase: BaseTestCase { func testThatItDecrementsMemoryUsageWhenRemovingImageFromCache() { // Given - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") let identifier = "unicorn" // When @@ -309,7 +309,7 @@ final class ImageCacheTestCase: BaseTestCase { func testThatItDecrementsMemoryUsageWhenRemovingAllImagesFromCache() { // Given - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") let identifier = "unicorn" // When @@ -327,7 +327,7 @@ final class ImageCacheTestCase: BaseTestCase { func testThatItPurgesImagesWhenMemoryCapacityIsReached() { // Given - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") let identifier = "unicorn" var memoryUsage: [UInt64] = [] @@ -347,7 +347,7 @@ final class ImageCacheTestCase: BaseTestCase { func testThatItPrioritizesImagesWithOldestLastAccessDatesDuringPurge() { // Given - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") let identifier = "unicorn" // When @@ -369,7 +369,7 @@ final class ImageCacheTestCase: BaseTestCase { func testThatAccessingCachedImageUpdatesLastAccessDate() { // Given - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") let identifier = "unicorn" // When @@ -400,7 +400,7 @@ final class ImageCacheThreadSafetyTests: BaseTestCase { func testMultipleReadsAndWrites() { // Given let cache = AutoPurgingImageCache(memoryCapacity: 1_000_000, preferredMemoryUsageAfterPurge: 100_000) - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") // When DispatchQueue.concurrentPerform(iterations: 100) { iteration in diff --git a/Tests/ImageDownloaderTests.swift b/Tests/ImageDownloaderTests.swift index eecc83e..858a4f3 100644 --- a/Tests/ImageDownloaderTests.swift +++ b/Tests/ImageDownloaderTests.swift @@ -121,7 +121,7 @@ final class ImageDownloaderTestCase: BaseTestCase { func testThatItCanDownloadAnImage() { // Given let downloader = ImageDownloader() - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") var response: AFIDataResponse? @@ -179,7 +179,7 @@ final class ImageDownloaderTestCase: BaseTestCase { // Given let downloader = ImageDownloader() - let expectation = self.expectation(description: "both downloads should succeed") + let expectation = expectation(description: "both downloads should succeed") expectation.expectedFulfillmentCount = 2 var completedDownloads = 0 @@ -227,7 +227,7 @@ final class ImageDownloaderTestCase: BaseTestCase { func testThatItCallsTheCompletionHandlerEvenWhenDownloadFails() { // Given let downloader = ImageDownloader() - let expectation = self.expectation(description: "download request should fail") + let expectation = expectation(description: "download request should fail") var response: AFIDataResponse? @@ -249,7 +249,7 @@ final class ImageDownloaderTestCase: BaseTestCase { // Given let downloader = ImageDownloader() let urlRequest = ThrowingURLRequestConvertible() - let expectation = self.expectation(description: "download request should fail") + let expectation = expectation(description: "download request should fail") var response: AFIDataResponse? @@ -281,7 +281,7 @@ final class ImageDownloaderTestCase: BaseTestCase { return downloader }() - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") var response: AFIDataResponse? @@ -309,7 +309,7 @@ final class ImageDownloaderTestCase: BaseTestCase { let scaledSize = CGSize(width: 100, height: 60) let filter = ScaledToSizeFilter(size: scaledSize) - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") var response: AFIDataResponse? @@ -484,7 +484,7 @@ final class ImageDownloaderTestCase: BaseTestCase { // Given let downloader = ImageDownloader() - let expectation = self.expectation(description: "download request should cancel") + let expectation = expectation(description: "download request should cancel") var response: AFIDataResponse? @@ -572,7 +572,7 @@ final class ImageDownloaderTestCase: BaseTestCase { // When for (index, imageRequest) in imageEndpoints.enumerated() { - let expectation = self.expectation(description: "Download \(index) should be cancelled: \(imageRequest)") + let expectation = expectation(description: "Download \(index) should be cancelled: \(imageRequest)") let receipt = downloader.download(imageRequest, completion: { response in switch response.result { @@ -591,7 +591,7 @@ final class ImageDownloaderTestCase: BaseTestCase { } for (index, imageRequest) in imageEndpoints.enumerated() { - let expectation = self.expectation(description: "Download \(index) should complete: \(imageRequest)") + let expectation = expectation(description: "Download \(index) should complete: \(imageRequest)") downloader.download(imageRequest, completion: { response in switch response.result { @@ -687,7 +687,7 @@ final class ImageDownloaderTestCase: BaseTestCase { // Given let downloader = ImageDownloader() - let expectation = self.expectation(description: "download request should succeed") + let expectation = expectation(description: "download request should succeed") var calledOnMainQueue = false @@ -707,7 +707,7 @@ final class ImageDownloaderTestCase: BaseTestCase { // Given let downloader = ImageDownloader() - let expectation = self.expectation(description: "download request should succeed") + let expectation = expectation(description: "download request should succeed") var calledOnMainQueue = false @@ -728,7 +728,7 @@ final class ImageDownloaderTestCase: BaseTestCase { let downloader = ImageDownloader() let urlRequest = ThrowingURLRequestConvertible() - let expectation = self.expectation(description: "download request should succeed") + let expectation = expectation(description: "download request should succeed") var calledOnMainQueue = false @@ -749,7 +749,7 @@ final class ImageDownloaderTestCase: BaseTestCase { let downloader = ImageDownloader() let filter = ThreadCheckFilter() - let expectation = self.expectation(description: "download request should succeed") + let expectation = expectation(description: "download request should succeed") // When downloader.download(.image(.jpeg), filter: filter, completion: { _ in @@ -823,7 +823,7 @@ final class ImageDownloaderTestCase: BaseTestCase { func testThatItCanDownloadImagesWhenNoImageCacheIsAvailable() { // Given let downloader = ImageDownloader(imageCache: nil) - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") var response: AFIDataResponse? diff --git a/Tests/ImageFilterTests.swift b/Tests/ImageFilterTests.swift index 1be039d..801f60e 100644 --- a/Tests/ImageFilterTests.swift +++ b/Tests/ImageFilterTests.swift @@ -100,7 +100,7 @@ final class ImageFilterTestCase: BaseTestCase { func testThatDynamicImageFilterReturnsCorrectFilteredImage() { // Given - let image = self.image(forResource: "pirate", withExtension: "jpg") + let image = image(forResource: "pirate", withExtension: "jpg") let filter = DynamicImageFilter("DynamicScaleToSizeFilter") { image in image.af.imageScaled(to: CGSize(width: 50.0, height: 50.0)) } @@ -118,7 +118,7 @@ final class ImageFilterTestCase: BaseTestCase { // TODO: Needs updates for latest rendering results. func _testThatDynamicCompositeImageFilterReturnsCorrectFilteredImage() { // Given - let image = self.image(forResource: "pirate", withExtension: "jpg") + let image = image(forResource: "pirate", withExtension: "jpg") let filter = DynamicCompositeImageFilter(ScaledToSizeFilter(size: largeSquareSize), RoundedCornersFilter(radius: 20)) @@ -136,7 +136,7 @@ final class ImageFilterTestCase: BaseTestCase { func testThatScaledToSizeFilterReturnsCorrectFilteredImage() { // Given - let image = self.image(forResource: "pirate", withExtension: "jpg") + let image = image(forResource: "pirate", withExtension: "jpg") let filter = ScaledToSizeFilter(size: squareSize) // When @@ -149,7 +149,7 @@ final class ImageFilterTestCase: BaseTestCase { func testThatAspectScaledToFitSizeFilterReturnsCorrectFilteredImage() { // Given - let image = self.image(forResource: "pirate", withExtension: "jpg") + let image = image(forResource: "pirate", withExtension: "jpg") let filter = AspectScaledToFitSizeFilter(size: squareSize) // When @@ -162,7 +162,7 @@ final class ImageFilterTestCase: BaseTestCase { func testThatAspectScaledToFillSizeFilterReturnsCorrectFilteredImage() { // Given - let image = self.image(forResource: "pirate", withExtension: "jpg") + let image = image(forResource: "pirate", withExtension: "jpg") let filter = AspectScaledToFillSizeFilter(size: squareSize) // When @@ -176,7 +176,7 @@ final class ImageFilterTestCase: BaseTestCase { // TODO: Needs updates for latest rendering results. func _testThatRoundedCornersFilterReturnsCorrectFilteredImage() { // Given - let image = self.image(forResource: "pirate", withExtension: "jpg") + let image = image(forResource: "pirate", withExtension: "jpg") let filter = RoundedCornersFilter(radius: 20, divideRadiusByImageScale: true) // When @@ -192,7 +192,7 @@ final class ImageFilterTestCase: BaseTestCase { func testThatCircleFilterReturnsCorrectFilteredImage() { // Given - let image = self.image(forResource: "pirate", withExtension: "jpg") + let image = image(forResource: "pirate", withExtension: "jpg") let filter = CircleFilter() // When @@ -205,7 +205,7 @@ final class ImageFilterTestCase: BaseTestCase { func testThatBlurFilterReturnsCorrectFilteredImage() { // Given - let image = self.image(forResource: "unicorn", withExtension: "png") + let image = image(forResource: "unicorn", withExtension: "png") let filter = BlurFilter(blurRadius: 8) // When @@ -226,7 +226,7 @@ final class ImageFilterTestCase: BaseTestCase { // TODO: Needs updates for latest rendering results. func _testThatScaledToSizeWithRoundedCornersFilterReturnsCorrectFilteredImage() { // Given - let image = self.image(forResource: "pirate", withExtension: "jpg") + let image = image(forResource: "pirate", withExtension: "jpg") let filter = ScaledToSizeWithRoundedCornersFilter(size: largeSquareSize, radius: 20) // When @@ -242,7 +242,7 @@ final class ImageFilterTestCase: BaseTestCase { // TODO: Needs updates for latest rendering results. func _testThatAspectScaledToFillSizeWithRoundedCornersFilterReturnsCorrectFilteredImage() { // Given - let image = self.image(forResource: "pirate", withExtension: "jpg") + let image = image(forResource: "pirate", withExtension: "jpg") let filter = AspectScaledToFillSizeWithRoundedCornersFilter(size: largeSquareSize, radius: 20) // When @@ -257,7 +257,7 @@ final class ImageFilterTestCase: BaseTestCase { func testThatScaledToSizeCircleFilterReturnsCorrectFilteredImage() { // Given - let image = self.image(forResource: "pirate", withExtension: "jpg") + let image = image(forResource: "pirate", withExtension: "jpg") let filter = ScaledToSizeCircleFilter(size: largeSquareSize) // When @@ -272,7 +272,7 @@ final class ImageFilterTestCase: BaseTestCase { func testThatAspectScaledToFillSizeCircleFilterReturnsCorrectFilteredImage() { // Given - let image = self.image(forResource: "pirate", withExtension: "jpg") + let image = image(forResource: "pirate", withExtension: "jpg") let filter = AspectScaledToFillSizeCircleFilter(size: largeSquareSize) // When diff --git a/Tests/RequestTests.swift b/Tests/RequestTests.swift index 1e39398..1b09f45 100644 --- a/Tests/RequestTests.swift +++ b/Tests/RequestTests.swift @@ -81,7 +81,7 @@ final class DataRequestTestCase: BaseTestCase { func testThatImageResponseSerializerCanDownloadAllUniversalImageTypes() { func download(_ imageType: Endpoint.Image) { // Given - let expectation = self.expectation(description: "Request should return \(imageType.rawValue) response image") + let expectation = expectation(description: "Request should return \(imageType.rawValue) response image") var response: AFDataResponse? @@ -123,7 +123,7 @@ final class DataRequestTestCase: BaseTestCase { guard #available(macOS 11, iOS 14, *) else { return } // Given - let expectation = self.expectation(description: "Request should return WebP response image") + let expectation = expectation(description: "Request should return WebP response image") var response: AFDataResponse? @@ -163,7 +163,7 @@ final class DataRequestTestCase: BaseTestCase { guard #available(macOS 13, iOS 16, tvOS 16, *) else { return } // Given - let expectation = self.expectation(description: "Request should return AVIF response image") + let expectation = expectation(description: "Request should return AVIF response image") var response: AFDataResponse? @@ -196,12 +196,12 @@ final class DataRequestTestCase: BaseTestCase { } #endif - + func testThatImageResponseSerializerCanDownloadJPEGXLImage() { guard #available(macOS 14, iOS 17, tvOS 17, watchOS 10, *) else { return } // Given - let expectation = self.expectation(description: "Request should return JPEG XL response image") + let expectation = expectation(description: "Request should return JPEG XL response image") var response: AFDataResponse? @@ -273,7 +273,7 @@ final class DataRequestTestCase: BaseTestCase { func testThatAttemptingToDownloadImageFromBadURLReturnsFailureResult() { // Given - let expectation = self.expectation(description: "Request should fail with bad URL") + let expectation = expectation(description: "Request should fail with bad URL") var response: AFDataResponse? @@ -295,7 +295,7 @@ final class DataRequestTestCase: BaseTestCase { func testThatAttemptingToDownloadUnsupportedImageTypeReturnsFailureResult() { // Given - let expectation = self.expectation(description: "Request should return pdf response image") + let expectation = expectation(description: "Request should return pdf response image") var response: AFDataResponse? @@ -323,7 +323,7 @@ final class DataRequestTestCase: BaseTestCase { func testThatAttemptingToSerializeEmptyDataReturnsFailureResult() { // Given - let expectation = self.expectation(description: "Request should download no bytes") + let expectation = expectation(description: "Request should download no bytes") var response: AFDataResponse? @@ -352,7 +352,7 @@ final class DataRequestTestCase: BaseTestCase { func testThatAttemptingToSerializeRandomStreamDataReturnsFailureResult() { // Given let randomBytes = 4 * 1024 * 1024 - let expectation = self.expectation(description: "Request should download random bytes") + let expectation = expectation(description: "Request should download random bytes") var response: AFDataResponse? @@ -380,7 +380,7 @@ final class DataRequestTestCase: BaseTestCase { func testThatAttemptingToSerializeJSONResponseIntoImageReturnsFailureResult() { // Given - let expectation = self.expectation(description: "Request should return JSON") + let expectation = expectation(description: "Request should return JSON") var response: AFDataResponse? diff --git a/Tests/TestHelpers.swift b/Tests/TestHelpers.swift index 7d88488..332a73d 100644 --- a/Tests/TestHelpers.swift +++ b/Tests/TestHelpers.swift @@ -277,7 +277,7 @@ extension Endpoint: URLRequestConvertible { var urlRequest: URLRequest { try! asURLRequest() } func asURLRequest() throws -> URLRequest { - var request = URLRequest(url: try asURL()) + var request = try URLRequest(url: asURL()) request.method = method request.headers = headers request.timeoutInterval = timeout diff --git a/Tests/UIButtonTests.swift b/Tests/UIButtonTests.swift index f9ff9d5..effdf0d 100644 --- a/Tests/UIButtonTests.swift +++ b/Tests/UIButtonTests.swift @@ -76,7 +76,7 @@ final class UIButtonTests: BaseTestCase { func testThatImageCanBeDownloadedFromURL() { // Given - let expectation = self.expectation(description: "image should download successfully") + let expectation = expectation(description: "image should download successfully") var imageDownloadComplete = false let button = TestButton { @@ -94,7 +94,7 @@ final class UIButtonTests: BaseTestCase { func testThatBackgroundImageCanBeDownloadedFromURL() { // Given - let expectation = self.expectation(description: "background image should download successfully") + let expectation = expectation(description: "background image should download successfully") var backgroundImageDownloadComplete = false let button = TestButton { @@ -112,7 +112,7 @@ final class UIButtonTests: BaseTestCase { func testThatImageCanBeCancelledAndDownloadedFromURL() { // Given - let expectation = self.expectation(description: "image should cancel and download successfully") + let expectation = expectation(description: "image should cancel and download successfully") let button = UIButton() var result: AFIResult? @@ -134,7 +134,7 @@ final class UIButtonTests: BaseTestCase { func testThatBackgroundImageCanBeCancelledAndDownloadedFromURL() { // Given - let expectation = self.expectation(description: "background image should cancel and download successfully") + let expectation = expectation(description: "background image should cancel and download successfully") let button = UIButton() var result: AFIResult? @@ -157,7 +157,7 @@ final class UIButtonTests: BaseTestCase { func testThatActiveImageRequestReceiptIsNilAfterImageDownloadCompletes() { // Given - let expectation = self.expectation(description: "image should download successfully") + let expectation = expectation(description: "image should download successfully") var imageDownloadComplete = false let button = TestButton { @@ -176,7 +176,7 @@ final class UIButtonTests: BaseTestCase { func testThatActiveBackgroundImageRequestReceiptIsNilAfterImageDownloadCompletes() { // Given - let expectation = self.expectation(description: "background image should download successfully") + let expectation = expectation(description: "background image should download successfully") var backgroundImageDownloadComplete = false let button = TestButton { @@ -196,7 +196,7 @@ final class UIButtonTests: BaseTestCase { func testThatMultipleImageRequestReceiptStatesCanBeDownloadedInParallel() { // Given let button = TestButton() - var url = self.url + var url = url // When let expectation1 = expectation(description: "background image should download successfully") @@ -268,7 +268,7 @@ final class UIButtonTests: BaseTestCase { func testThatMultipleBackgroundImageRequestReceiptStatesCanBeDownloadedInParallel() { // Given let button = TestButton() - var url = self.url + var url = url // When let expectation1 = expectation(description: "background image should download successfully") @@ -340,7 +340,7 @@ final class UIButtonTests: BaseTestCase { func testThatImageDownloaderOverridesSharedImageDownloader() { // Given - let expectation = self.expectation(description: "image should download successfully") + let expectation = expectation(description: "image should download successfully") var imageDownloadComplete = false let button = TestButton { @@ -368,7 +368,7 @@ final class UIButtonTests: BaseTestCase { func testThatCustomImageSerializerCanBeUsed() { // Given - let expectation = self.expectation(description: "image should download successfully") + let expectation = expectation(description: "image should download successfully") var imageDownloadComplete = false let button = TestButton { @@ -391,7 +391,7 @@ final class UIButtonTests: BaseTestCase { func testThatCustomImageSerializerCanBeUsedForBackgroundImage() { // Given - let expectation = self.expectation(description: "image should download successfully") + let expectation = expectation(description: "image should download successfully") var imageDownloadComplete = false let button = TestButton { @@ -420,7 +420,7 @@ final class UIButtonTests: BaseTestCase { let downloader = ImageDownloader.default let urlRequest = try! URLRequest(url: url.absoluteString, method: .get) - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") downloader.download(urlRequest, completion: { _ in expectation.fulfill() @@ -455,7 +455,7 @@ final class UIButtonTests: BaseTestCase { let button = UIButton() let downloader = ImageDownloader.default - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") downloader.download(endpoint, filter: CircleFilter(), completion: { _ in expectation.fulfill() @@ -473,7 +473,7 @@ final class UIButtonTests: BaseTestCase { func testThatImageCanBeCachedWithACustomCacheKey() { // Given - let expectation = self.expectation(description: "image should download and be cached with custom key") + let expectation = expectation(description: "image should download and be cached with custom key") let cacheKey = "cache-key" var imageCached = false @@ -492,7 +492,7 @@ final class UIButtonTests: BaseTestCase { func testThatBackgroundImageCanBeCachedWithACustomCacheKey() { // Given - let expectation = self.expectation(description: "image should download and be cached with custom key") + let expectation = expectation(description: "image should download and be cached with custom key") let cacheKey = "cache-key" var imageCached = false @@ -514,7 +514,7 @@ final class UIButtonTests: BaseTestCase { func testThatPlaceholderImageIsDisplayedUntilImageIsDownloadedFromURL() { // Given let placeholderImage = image(forResource: "pirate", withExtension: "jpg") - let expectation = self.expectation(description: "image should download successfully") + let expectation = expectation(description: "image should download successfully") var imageDownloadComplete = false var finalImageEqualsPlaceholderImage = false @@ -542,7 +542,7 @@ final class UIButtonTests: BaseTestCase { func testThatBackgroundPlaceholderImageIsDisplayedUntilImageIsDownloadedFromURL() { // Given let placeholderImage = image(forResource: "pirate", withExtension: "jpg") - let expectation = self.expectation(description: "image should download successfully") + let expectation = expectation(description: "image should download successfully") var backgroundImageDownloadComplete = false var finalBackgroundImageEqualsPlaceholderImage = false @@ -574,7 +574,7 @@ final class UIButtonTests: BaseTestCase { let downloader = ImageDownloader.default let urlRequest = try! URLRequest(url: url.absoluteString, method: .get) - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") downloader.download(urlRequest, completion: { _ in expectation.fulfill() @@ -597,7 +597,7 @@ final class UIButtonTests: BaseTestCase { let downloader = ImageDownloader.default let urlRequest = try! URLRequest(url: url.absoluteString, method: .get) - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") downloader.download(urlRequest, completion: { _ in expectation.fulfill() @@ -646,7 +646,7 @@ final class UIButtonTests: BaseTestCase { let size = CGSize(width: 20, height: 20) let filter = ScaledToSizeFilter(size: size) - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") var imageDownloadComplete = false let button = TestButton { @@ -672,7 +672,7 @@ final class UIButtonTests: BaseTestCase { let size = CGSize(width: 20, height: 20) let filter = ScaledToSizeFilter(size: size) - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") var imageDownloadComplete = false let button = TestButton { @@ -705,7 +705,7 @@ final class UIButtonTests: BaseTestCase { return request }() - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") var completionHandlerCalled = false var result: AFIResult? @@ -735,7 +735,7 @@ final class UIButtonTests: BaseTestCase { return request }() - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") var completionHandlerCalled = false var result: AFIResult? @@ -759,7 +759,7 @@ final class UIButtonTests: BaseTestCase { // Given let button = UIButton() - let expectation = self.expectation(description: "image download should complete") + let expectation = expectation(description: "image download should complete") var completionHandlerCalled = false var result: AFIResult? @@ -783,7 +783,7 @@ final class UIButtonTests: BaseTestCase { // Given let button = UIButton() - let expectation = self.expectation(description: "image download should complete") + let expectation = expectation(description: "image download should complete") var completionHandlerCalled = false var result: AFIResult? @@ -808,7 +808,7 @@ final class UIButtonTests: BaseTestCase { let button = UIButton() let urlRequest = ThrowingURLRequestConvertible() - let expectation = self.expectation(description: "image download should complete") + let expectation = expectation(description: "image download should complete") var completionHandlerCalled = false var result: AFIResult? @@ -833,7 +833,7 @@ final class UIButtonTests: BaseTestCase { let button = UIButton() let urlRequest = ThrowingURLRequestConvertible() - let expectation = self.expectation(description: "image download should complete") + let expectation = expectation(description: "image download should complete") var completionHandlerCalled = false var result: AFIResult? @@ -859,7 +859,7 @@ final class UIButtonTests: BaseTestCase { // Given let button = UIButton() - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") var completionHandlerCalled = false var result: AFIResult? @@ -887,7 +887,7 @@ final class UIButtonTests: BaseTestCase { // Given let button = UIButton() - let expectation = self.expectation(description: "background image download should succeed") + let expectation = expectation(description: "background image download should succeed") var completionHandlerCalled = false var result: AFIResult? @@ -914,7 +914,7 @@ final class UIButtonTests: BaseTestCase { func testThatActiveImageRequestIsAutomaticallyCancelledBySettingNewURL() { // Given let button = UIButton() - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") var completion1Called = false var completion2Called = false @@ -949,7 +949,7 @@ final class UIButtonTests: BaseTestCase { func testThatActiveBackgroundImageRequestIsAutomaticallyCancelledBySettingNewURL() { // Given let button = UIButton() - let expectation = self.expectation(description: "background image download should succeed") + let expectation = expectation(description: "background image download should succeed") var completion1Called = false var completion2Called = false @@ -984,7 +984,7 @@ final class UIButtonTests: BaseTestCase { func testThatActiveImageRequestCanBeCancelledAndRestartedSuccessfully() { // Given let button = UIButton() - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") expectation.expectedFulfillmentCount = 2 var completion1Called = false @@ -1023,7 +1023,7 @@ final class UIButtonTests: BaseTestCase { func testThatActiveBackgroundImageRequestCanBeCancelledAndRestartedSuccessfully() { // Given let button = UIButton() - let expectation = self.expectation(description: "background image download should succeed") + let expectation = expectation(description: "background image download should succeed") var completion1Called = false var completion2Called = false @@ -1060,7 +1060,7 @@ final class UIButtonTests: BaseTestCase { func testThatImageRequestCanBeCancelledAndButtonIsDeallocated() { // Given var button: UIButton? = UIButton() - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") var completionCalled: Bool? var buttonReleased: Bool? @@ -1086,7 +1086,7 @@ final class UIButtonTests: BaseTestCase { func testThatBackgroundImageRequestCanBeCancelledAndButtonIsDeallocated() { // Given var button: UIButton? = UIButton() - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") var completionCalled: Bool? var buttonReleased: Bool? @@ -1113,7 +1113,7 @@ final class UIButtonTests: BaseTestCase { func testThatImageBehindRedirectCanBeDownloaded() { // Given - let expectation = self.expectation(description: "image should download successfully") + let expectation = expectation(description: "image should download successfully") var imageDownloadComplete = false let button = TestButton { @@ -1132,7 +1132,7 @@ final class UIButtonTests: BaseTestCase { func testThatBackgroundImageBehindRedirectCanBeDownloaded() { // Given - let expectation = self.expectation(description: "image should download successfully") + let expectation = expectation(description: "image should download successfully") var backgroundImageDownloadComplete = false let button = TestButton { @@ -1153,7 +1153,7 @@ final class UIButtonTests: BaseTestCase { func testThatAcceptHeaderMatchesAcceptableContentTypes() { // Given - let expectation = self.expectation(description: "image should download successfully") + let expectation = expectation(description: "image should download successfully") var acceptField: String? var button: TestButton? diff --git a/Tests/UIImageTests.swift b/Tests/UIImageTests.swift index a2afde9..393de75 100644 --- a/Tests/UIImageTests.swift +++ b/Tests/UIImageTests.swift @@ -48,7 +48,7 @@ class UIImageTestCase: BaseTestCase { func testThatHundredsOfLargeImagesCanBeInitializedAcrossMultipleThreads() { // Given - let url = self.url(forResource: "huge_map", withExtension: "jpg") + let url = url(forResource: "huge_map", withExtension: "jpg") let data = try! Data(contentsOf: url) let lock = NSLock() @@ -57,7 +57,7 @@ class UIImageTestCase: BaseTestCase { // When for _ in 0..? @@ -488,7 +488,7 @@ final class UIImageViewTestCase: BaseTestCase { // Given let imageView = UIImageView() - let expectation = self.expectation(description: "image download should complete") + let expectation = expectation(description: "image download should complete") var completionHandlerCalled = false var result: AFIResult? @@ -517,7 +517,7 @@ final class UIImageViewTestCase: BaseTestCase { let imageView = UIImageView() let urlRequest = ThrowingURLRequestConvertible() - let expectation = self.expectation(description: "image download should complete") + let expectation = expectation(description: "image download should complete") var completionHandlerCalled = false var result: AFIResult? @@ -623,7 +623,7 @@ final class UIImageViewTestCase: BaseTestCase { // Given let imageView = UIImageView() - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") var completionHandlerCalled = false var result: AFIResult? @@ -651,7 +651,7 @@ final class UIImageViewTestCase: BaseTestCase { func testThatActiveRequestIsAutomaticallyCancelledBySettingNewURL() { // Given let imageView = UIImageView() - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") var completion1Called = false var completion2Called = false @@ -688,7 +688,7 @@ final class UIImageViewTestCase: BaseTestCase { func testThatActiveRequestCanBeCancelledAndRestartedSuccessfully() { // Given let imageView = UIImageView() - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") var completion1Called = false var completion2Called = false @@ -727,7 +727,7 @@ final class UIImageViewTestCase: BaseTestCase { func testThatActiveRequestCanBeCancelledAndImageViewIsDeallocated() { // Given var imageView: UIImageView? = UIImageView() - let expectation = self.expectation(description: "image download should succeed") + let expectation = expectation(description: "image download should succeed") var completionCalled: Bool? var imageViewReleased: Bool? @@ -753,7 +753,7 @@ final class UIImageViewTestCase: BaseTestCase { func testThatImageBehindRedirectCanBeDownloaded() { // Given - let expectation = self.expectation(description: "image should download successfully") + let expectation = expectation(description: "image should download successfully") var imageDownloadComplete = false let imageView = TestImageView { @@ -774,7 +774,7 @@ final class UIImageViewTestCase: BaseTestCase { func testThatAcceptHeaderMatchesAcceptableContentTypes() { // Given - let expectation = self.expectation(description: "image should download successfully") + let expectation = expectation(description: "image should download successfully") var acceptField: String? var imageView: TestImageView?