Selaa lähdekoodia

Fix tests for Xcode 8 beta 4

onevcat 9 vuotta sitten
vanhempi
commit
73b69d05d6

+ 4 - 5
Demo/Kingfisher-OSX-Demo/Base.lproj/Main.storyboard

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
+<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11185.3" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11185.3"/>
     </dependencies>
     <scenes>
         <!--Application-->
@@ -693,7 +693,6 @@
                                             </connections>
                                         </collectionView>
                                     </subviews>
-                                    <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
                                 </clipView>
                                 <scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="9aw-c6-93q">
                                     <rect key="frame" x="1" y="144" width="233" height="15"/>
@@ -711,7 +710,7 @@
                                     <font key="font" metaFont="system"/>
                                 </buttonCell>
                                 <connections>
-                                    <action selector="clearCachePressed:" target="XfG-lQ-9wD" id="jak-pT-dz8"/>
+                                    <action selector="clearCachePressedWithSender:" target="XfG-lQ-9wD" id="lfl-RU-nX5"/>
                                 </connections>
                             </button>
                             <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Ejh-qu-qmy">
@@ -721,7 +720,7 @@
                                     <font key="font" metaFont="system"/>
                                 </buttonCell>
                                 <connections>
-                                    <action selector="reloadPressed:" target="XfG-lQ-9wD" id="kgi-1i-4tv"/>
+                                    <action selector="reloadPressedWithSender:" target="XfG-lQ-9wD" id="k24-Wi-NRd"/>
                                 </connections>
                             </button>
                         </subviews>

+ 5 - 16
Demo/Kingfisher-OSX-Demo/ViewController.swift

@@ -37,17 +37,6 @@ class ViewController: NSViewController {
         title = "Kingfisher"
     }
 
-    override var representedObject: AnyObject? {
-        didSet {
-        // Update the view, if already loaded.
-        }
-        @IBAction func q(_ sender: AnyObject) {
-        }
-        @IBAction func clear(_ sender: AnyObject) {
-        }
-        @IBOutlet weak var clearCache: UIBarButtonItem!
-    }
-
     @IBAction func clearCachePressed(sender: AnyObject) {
         KingfisherManager.sharedManager.cache.clearMemoryCache()
         KingfisherManager.sharedManager.cache.clearDiskCache()
@@ -59,17 +48,17 @@ class ViewController: NSViewController {
 }
 
 extension ViewController: NSCollectionViewDataSource {
-    func collectionView(collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
+    func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
         return 10
     }
     
-    func collectionView(collectionView: NSCollectionView, itemForRepresentedObjectAtIndexPath indexPath: NSIndexPath) -> NSCollectionViewItem {
-        let item = collectionView.makeItemWithIdentifier("Cell", forIndexPath: indexPath)
+    func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
+        let item = collectionView.makeItem(withIdentifier: "Cell", for: indexPath)
         
-        let URL = NSURL(string: "https://raw.githubusercontent.com/onevcat/Kingfisher/master/images/kingfisher-\(indexPath.item + 1).jpg")!
+        let url = URL(string: "https://raw.githubusercontent.com/onevcat/Kingfisher/master/images/kingfisher-\(indexPath.item + 1).jpg")!
         
         item.imageView?.kf_showIndicatorWhenLoading = true
-        item.imageView?.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil,
+        item.imageView?.kf_setImageWithURL(url, placeholderImage: nil, optionsInfo: nil,
                                                    progressBlock: { receivedSize, totalSize in
                                                     print("\(indexPath.item + 1): \(receivedSize)/\(totalSize)")
                                                     },

+ 12 - 14
Demo/Kingfisher-tvOS-Demo/Base.lproj/Main.storyboard

@@ -1,8 +1,9 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder.AppleTV.Storyboard" version="3.0" toolsVersion="9059" systemVersion="15B42" targetRuntime="AppleTV" propertyAccessControl="none" useAutolayout="YES" initialViewController="RxR-mX-Zp2">
+<document type="com.apple.InterfaceBuilder.AppleTV.Storyboard" version="3.0" toolsVersion="11185.3" systemVersion="15G31" targetRuntime="AppleTV" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="RxR-mX-Zp2">
     <dependencies>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11151.4"/>
         <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
+        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <scenes>
         <!--Navigation Controller-->
@@ -12,7 +13,6 @@
                     <navigationBar key="navigationBar" contentMode="scaleToFill" id="RDr-bh-PDt">
                         <rect key="frame" x="0.0" y="0.0" width="1920" height="145"/>
                         <autoresizingMask key="autoresizingMask"/>
-                        <animations/>
                     </navigationBar>
                     <connections>
                         <segue destination="Oup-Jp-dod" kind="relationship" relationship="rootViewController" id="mjf-yd-QmD"/>
@@ -29,7 +29,6 @@
                     <collectionView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" id="Rqa-mv-V5P">
                         <rect key="frame" x="0.0" y="0.0" width="1920" height="1080"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
-                        <animations/>
                         <collectionViewFlowLayout key="collectionViewLayout" scrollDirection="horizontal" minimumLineSpacing="60" minimumInteritemSpacing="100" id="w8t-vE-Ny4">
                             <size key="itemSize" width="500" height="500"/>
                             <size key="headerReferenceSize" width="0.0" height="0.0"/>
@@ -38,21 +37,15 @@
                         </collectionViewFlowLayout>
                         <cells>
                             <collectionViewCell opaque="NO" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="collectionViewCell" id="DMI-eZ-MxY" customClass="CollectionViewCell" customModule="Kingfisher_tvOS_Demo" customModuleProvider="target">
-                                <rect key="frame" x="40" y="363" width="500" height="500"/>
+                                <frame key="frameInset" minX="40" minY="363" width="500" height="500"/>
                                 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                 <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
                                     <rect key="frame" x="0.0" y="0.0" width="500" height="500"/>
                                     <autoresizingMask key="autoresizingMask"/>
                                     <subviews>
-                                        <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="z1G-94-m4d">
-                                            <rect key="frame" x="8" y="8" width="484" height="484"/>
-                                            <animations/>
-                                        </imageView>
+                                        <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="z1G-94-m4d"/>
                                     </subviews>
-                                    <animations/>
-                                    <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
                                 </view>
-                                <animations/>
                                 <constraints>
                                     <constraint firstItem="z1G-94-m4d" firstAttribute="leading" secondItem="DMI-eZ-MxY" secondAttribute="leadingMargin" id="InY-A2-Rr2"/>
                                     <constraint firstAttribute="bottomMargin" secondItem="z1G-94-m4d" secondAttribute="bottom" id="ThB-Ig-1SK"/>
@@ -72,12 +65,12 @@
                     <navigationItem key="navigationItem" title="Title" id="73M-Nr-0wa">
                         <barButtonItem key="leftBarButtonItem" title="Clear Cache" id="DS6-ds-fQK">
                             <connections>
-                                <action selector="clearCache:" destination="Oup-Jp-dod" id="4gh-dN-9Hz"/>
+                                <action selector="clearCacheWithSender:" destination="Oup-Jp-dod" id="uyH-e1-e6Z"/>
                             </connections>
                         </barButtonItem>
                         <barButtonItem key="rightBarButtonItem" title="Reload" id="vsy-2H-Xfb">
                             <connections>
-                                <action selector="reload:" destination="Oup-Jp-dod" id="ne6-1l-ln8"/>
+                                <action selector="reloadWithSender:" destination="Oup-Jp-dod" id="oWW-jb-DIw"/>
                             </connections>
                         </barButtonItem>
                     </navigationItem>
@@ -87,4 +80,9 @@
             <point key="canvasLocation" x="539" y="887"/>
         </scene>
     </scenes>
+    <simulatedMetricsContainer key="defaultSimulatedMetrics">
+        <nil key="statusBar"/>
+        <simulatedOrientationMetrics key="orientation" orientation="landscapeRight"/>
+        <simulatedScreenMetrics key="destination"/>
+    </simulatedMetricsContainer>
 </document>

+ 2 - 3
Sources/ImageCache.swift

@@ -123,7 +123,7 @@ public class ImageCache {
         let dstPath = path ?? NSSearchPathForDirectoriesInDomains(.cachesDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).first!
         diskCachePath = (dstPath as NSString).appendingPathComponent(cacheName)
         
-        ioQueue = DispatchQueue(label: ioQueueName + name, attributes: DispatchQueue.Attributes.concurrent)
+        ioQueue = DispatchQueue(label: ioQueueName + name)
         processQueue = DispatchQueue(label: processQueueName + name, attributes: DispatchQueue.Attributes.concurrent)
         
         ioQueue.sync(execute: { () -> Void in
@@ -330,8 +330,7 @@ extension ImageCache {
     }
 
     /**
-    Clear disk cache. This is could be an async or sync operation.
-    Specify the way you want it by passing the `sync` parameter.
+    Clear disk cache.
     */
     public func clearDiskCache() {
         clearDiskCacheWithCompletionHandler(nil)

+ 2 - 2
Sources/ImageDownloader.swift

@@ -370,8 +370,8 @@ class ImageDownloaderSessionHandler: NSObject, URLSessionDataDelegate, Authentic
         
         // If server response is not 200,201 or 304, inform the callback handler with InvalidStatusCode error.
         // InvalidStatusCode error has userInfo which include statusCode and localizedString.
-        if let statusCode = (response as? NSHTTPURLResponse)?.statusCode, let URL = dataTask.originalRequest?.URL where statusCode != 200 && statusCode != 201 && statusCode != 304 {
-            callbackWithImage(nil, error: NSError(domain: KingfisherErrorDomain, code: KingfisherError.InvalidStatusCode.rawValue, userInfo: ["statusCode": statusCode, "localizedStringForStatusCode": NSHTTPURLResponse.localizedStringForStatusCode(statusCode)]), imageURL: URL, originalData: nil)
+        if let statusCode = (response as? HTTPURLResponse)?.statusCode, let URL = dataTask.originalRequest?.url, statusCode != 200 && statusCode != 201 && statusCode != 304 {
+            callbackWithImage(nil, error: NSError(domain: KingfisherErrorDomain, code: KingfisherError.InvalidStatusCode.rawValue, userInfo: ["statusCode": statusCode, "localizedStringForStatusCode": HTTPURLResponse.localizedString(forStatusCode: statusCode)]), imageURL: URL, originalData: nil)
         }
         
         completionHandler(Foundation.URLSession.ResponseDisposition.allow)

+ 1 - 1
Tests/KingfisherTests/ImageCacheTests.swift

@@ -231,7 +231,7 @@ class ImageCacheTests: XCTestCase {
         let expectation = self.expectation(description: "wait for retrieving image")
         self.cache.storeImage(testImage, originalData: testImageData, forKey: testKeys[0], toDisk: true) { () -> () in
             self.measure({ () -> Void in
-                for _ in 1 ..< 1000 {
+                for _ in 1 ..< 200 {
                     _ = self.cache.retrieveImageInDiskCacheForKey(testKeys[0])
                 }
             })

+ 19 - 7
Tests/KingfisherTests/ImageDownloaderTests.swift

@@ -161,12 +161,12 @@ class ImageDownloaderTests: XCTestCase {
     }
     
     func testServerInvalidStatusCode() {
-        let expectation = expectationWithDescription("wait for response which has invalid status code")
+        let expectation = self.expectation(description: "wait for response which has invalid status code")
         
         let URLString = testKeys[0]
-        stubRequest("GET", URLString).andReturn(404).withBody(testImageData)
+        _ = stubRequest("GET", URLString).andReturn(404)?.withBody(testImageData)
         
-        downloader.downloadImageWithURL(NSURL(string: URLString)!, options: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        downloader.downloadImageWithURL(URL(string: URLString)!, options: nil, progressBlock: { (receivedSize, totalSize) -> () in
             
         }) { (image, error, imageURL, data) -> () in
             XCTAssertNotNil(error, "There should be an error since server returning 404")
@@ -174,7 +174,7 @@ class ImageDownloaderTests: XCTestCase {
             XCTAssertEqual(error!.userInfo["statusCode"]! as? Int, 404, "The error should be InvalidStatusCode.")
             expectation.fulfill()
         }
-        waitForExpectationsWithTimeout(5, handler: nil)
+        waitForExpectations(timeout: 5, handler: nil)
     }
     
     // Since we could not receive one challage, no test for trusted hosts currently.
@@ -229,12 +229,19 @@ class ImageDownloaderTests: XCTestCase {
     func testDownloadEmptyURL() {
         let expectation = self.expectation(description: "wait for downloading error")
         
-        downloader.downloadImageWithURL(URL(string: "")!, progressBlock: { (receivedSize, totalSize) -> () in
+        downloader.requestModifier = { req in
+            req.url = nil
+        }
+        
+        let url = URL(string: "http://onevcat.com")
+        downloader.downloadImageWithURL(url!, progressBlock: { (receivedSize, totalSize) -> () in
             XCTFail("The progress block should not be called.")
             }) { (image, error, imageURL, originalData) -> () in
                 XCTAssertNotNil(error, "An error should happen for empty URL")
                 XCTAssertEqual(error!.code, KingfisherError.invalidURL.rawValue)
                 expectation.fulfill()
+                
+                self.downloader.requestModifier = nil
         }
         waitForExpectations(timeout: 5, handler: nil)
     }
@@ -274,7 +281,7 @@ class ImageDownloaderTests: XCTestCase {
         downloadTask!.cancel()
         _ = stub!.go()
         
-        DispatchQueue.main.after(when: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.09)) / Double(NSEC_PER_SEC)) { () -> Void in
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.09)) / Double(NSEC_PER_SEC)) { () -> Void in
             expectation.fulfill()
             XCTAssert(progressBlockIsCalled == false, "ProgressBlock should not be called since it is canceled.")
             XCTAssert(completionBlockIsCalled == true, "CompletionBlock should be called with error.")
@@ -284,7 +291,12 @@ class ImageDownloaderTests: XCTestCase {
     }
     
     func testDownloadTaskNil() {
-        let downloadTask = downloader.downloadImageWithURL(URL(string: "")!, progressBlock: nil, completionHandler: nil)
+        downloader.requestModifier = { req in
+            req.url = nil
+        }
+        let downloadTask = downloader.downloadImageWithURL(URL(string: "url")!, progressBlock: nil, completionHandler: nil)
         XCTAssertNil(downloadTask)
+        
+        downloader.requestModifier = nil
     }
 }

+ 3 - 2
Tests/KingfisherTests/ImagePrefetcherTests.swift

@@ -76,7 +76,7 @@ class ImagePrefetcherTests: XCTestCase {
                 XCTAssertEqual(completedResources.count, urls.count, "All resources prefetching should be completed.")
                 XCTAssertEqual(progressCalledCount, urls.count, "Progress should be called the same time of download count.")
                 for url in urls {
-                    XCTAssertTrue(KingfisherManager.sharedManager.cache.isImageCachedForKey(url.absoluteString!).cached)
+                    XCTAssertTrue(KingfisherManager.sharedManager.cache.isImageCachedForKey(url.absoluteString).cached)
                 }
         }
         
@@ -112,7 +112,8 @@ class ImagePrefetcherTests: XCTestCase {
         prefetcher.stop()
         
         let delayTime = DispatchTime.now() + Double(Int64(0.1 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
-        DispatchQueue.main.after(when: delayTime) {
+        
+        DispatchQueue.main.asyncAfter(deadline: delayTime) {
             responses.forEach { _ = $0!.go() }
         }
 

+ 12 - 12
Tests/KingfisherTests/ImageViewExtensionTests.swift

@@ -94,7 +94,7 @@ class ImageViewExtensionTests: XCTestCase {
         _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
         let URL = Foundation.URL(string: URLString)!
         
-        let customQueue = DispatchQueue(label: "com.kingfisher.testQueue", attributes: DispatchQueueAttributes.serial)
+        let customQueue = DispatchQueue(label: "com.kingfisher.testQueue")
         imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: [.callbackDispatchQueue(customQueue)], progressBlock: { (receivedSize, totalSize) -> () in
             XCTAssertTrue(Thread.isMainThread)
         }) { (image, error, cacheType, imageURL) -> () in
@@ -152,7 +152,7 @@ class ImageViewExtensionTests: XCTestCase {
 
         task.cancel()
         
-        DispatchQueue.main.after(when: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.09)) / Double(NSEC_PER_SEC)) { () -> Void in
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.09)) / Double(NSEC_PER_SEC)) { () -> Void in
             expectation.fulfill()
             XCTAssert(progressBlockIsCalled == false, "ProgressBlock should not be called since it is canceled.")
             XCTAssert(completionBlockIsCalled == false, "CompletionBlock should not be called since it is canceled.")
@@ -181,12 +181,12 @@ class ImageViewExtensionTests: XCTestCase {
                 completionBlockIsCalled = true
         }
         
-        DispatchQueue.main.after(when: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.1)) / Double(NSEC_PER_SEC)) { () -> Void in
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.1)) / Double(NSEC_PER_SEC)) { () -> Void in
             task.cancel()
             _ = stub!.go()
         }
 
-        DispatchQueue.main.after(when: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.2)) / Double(NSEC_PER_SEC)) { () -> Void in
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.2)) / Double(NSEC_PER_SEC)) { () -> Void in
             expectation.fulfill()
             XCTAssert(progressBlockIsCalled == false, "ProgressBlock should not be called since it is canceled.")
             XCTAssert(completionBlockIsCalled == true, "CompletionBlock should be called with error.")
@@ -227,11 +227,11 @@ class ImageViewExtensionTests: XCTestCase {
         }
         
         task1.cancel()
-        DispatchQueue.main.after(when: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.1)) / Double(NSEC_PER_SEC)) { () -> Void in
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.1)) / Double(NSEC_PER_SEC)) { () -> Void in
             _ = stub!.go()
         }
         
-        DispatchQueue.main.after(when: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.2)) / Double(NSEC_PER_SEC)) { () -> Void in
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.2)) / Double(NSEC_PER_SEC)) { () -> Void in
             expectation.fulfill()
             XCTAssert(task1Completion == false, "Task 1 should be not completed since it is cancelled before downloading started.")
             XCTAssert(task2Completion == true, "Task 2 should be completed.")
@@ -273,12 +273,12 @@ class ImageViewExtensionTests: XCTestCase {
                 task3Completion = true
         }
         
-        DispatchQueue.main.after(when: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.1)) / Double(NSEC_PER_SEC)) { () -> Void in
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.1)) / Double(NSEC_PER_SEC)) { () -> Void in
             task1.cancel()
             _ = stub!.go()
         }
         
-        DispatchQueue.main.after(when: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.2)) / Double(NSEC_PER_SEC)) { () -> Void in
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.2)) / Double(NSEC_PER_SEC)) { () -> Void in
             expectation.fulfill()
             XCTAssert(task1Completion == true, "Task 1 should be completed since task 2 and 3 are not cancelled and they are sharing the same downloading process.")
             XCTAssert(task2Completion == true, "Task 2 should be completed.")
@@ -323,14 +323,14 @@ class ImageViewExtensionTests: XCTestCase {
                 task3Completion = true
         }
         
-        DispatchQueue.main.after(when: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.1)) / Double(NSEC_PER_SEC)) { () -> Void in
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.1)) / Double(NSEC_PER_SEC)) { () -> Void in
             task1.cancel()
             task2.cancel()
             task3.cancel()
             _ = stub!.go()
         }
         
-        DispatchQueue.main.after(when: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.2)) / Double(NSEC_PER_SEC)) { () -> Void in
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.2)) / Double(NSEC_PER_SEC)) { () -> Void in
             expectation.fulfill()
             XCTAssert(task1Completion == true, "Task 1 should be completed with error.")
             XCTAssert(task2Completion == true, "Task 2 should be completed with error.")
@@ -430,7 +430,7 @@ class ImageViewExtensionTests: XCTestCase {
                 expectation.fulfill()
         }
         
-        DispatchQueue.main.after(when: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.1)) / Double(NSEC_PER_SEC)) { () -> Void in
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.1)) / Double(NSEC_PER_SEC)) { () -> Void in
             self.imageView.kf_cancelDownloadTask()
             _ = stub!.go()
         }
@@ -467,7 +467,7 @@ class ImageViewExtensionTests: XCTestCase {
                 XCTAssertEqual(self.imageView.image, image)
         }
         
-        DispatchQueue.main.after(when: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.1)) / Double(NSEC_PER_SEC)) { () -> Void in
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.1)) / Double(NSEC_PER_SEC)) { () -> Void in
             XCTAssertFalse(task1Complete, "Task 1 should not be completed since task 2 overrides it.")
             XCTAssertTrue(task2Complete, "Task 2 should be completed.")
 

+ 2 - 2
Tests/KingfisherTests/KingfisherManagerTests.swift

@@ -174,7 +174,7 @@ class KingfisherManagerTests: XCTestCase {
         
         let URL = Foundation.URL(string: URLString)!
         
-        let customQueue = DispatchQueue(label: "com.kingfisher.testQueue", attributes: DispatchQueueAttributes.serial)
+        let customQueue = DispatchQueue(label: "com.kingfisher.testQueue")
         manager.retrieveImageWithURL(URL, optionsInfo: [.callbackDispatchQueue(customQueue)], progressBlock: { _, _ in
             XCTAssertTrue(Thread.isMainThread)
             progressExpectation.fulfill()
@@ -197,7 +197,7 @@ class KingfisherManagerTests: XCTestCase {
         
         let URL = Foundation.URL(string: URLString)!
         
-        let customQueue = DispatchQueue(label: "com.kingfisher.testQueue", attributes: DispatchQueueAttributes.serial)
+        let customQueue = DispatchQueue(label: "com.kingfisher.testQueue")
         manager.retrieveImageWithURL(URL, optionsInfo: [.callbackDispatchQueue(customQueue)], progressBlock: { _, _ in
             //won't be called
             }, completionHandler: { _, error, _, _ in

+ 1 - 2
Tests/KingfisherTests/KingfisherOptionsInfoTests.swift

@@ -71,8 +71,7 @@ class KingfisherOptionsInfoTests: XCTestCase {
         let transition = ImageTransition.fade(0.5)
 #endif
             
-        let queue = DispatchQueue.global(attributes: DispatchQueue.GlobalAttributes.qosDefault)
-        
+        let queue = DispatchQueue.global(qos: .default)
         
         let options: KingfisherOptionsInfo = [
             .targetCache(cache),

+ 2 - 2
Tests/KingfisherTests/KingfisherTestHelper.swift

@@ -38,8 +38,8 @@ let testImageData = Data(base64Encoded: testImageString, options: [])
 
 let testImagePNGData = testImage.pngRepresentation()!
 let testImageJEPGData = testImage.jpegRepresentation(compressionQuality: 1.0)!
-let testImageGIFData = try! Data(contentsOf: URL(fileURLWithPath: Bundle(for: ImageExtensionTests.self).pathForResource("dancing-banana", ofType: "gif")!))
-let testImageSingleFrameGIFData = try! Data(contentsOf: URL(fileURLWithPath: Bundle(for: ImageExtensionTests.self).pathForResource("single-frame", ofType: "gif")!))
+let testImageGIFData = try! Data(contentsOf: URL(fileURLWithPath: Bundle(for: ImageExtensionTests.self).path(forResource: "dancing-banana", ofType: "gif")!))
+let testImageSingleFrameGIFData = try! Data(contentsOf: URL(fileURLWithPath: Bundle(for: ImageExtensionTests.self).path(forResource: "single-frame", ofType: "gif")!))
 
 let testKeys = ["http://stackoverflow.com/questions/11251340/convert-image-to-base64-string-in-ios-swift", "https://onevcat.com", "http://onevcat.com/content/images/2014/May/200.jpg", "http://onevcat.com/content/images/2014/May/200.jpg?fads#kj1asf"]
 

+ 2 - 2
Tests/KingfisherTests/NSButtonExtensionTests.swift

@@ -126,7 +126,7 @@ class NSButtonExtensionTests: XCTestCase {
             expectation.fulfill()
         }
         
-        DispatchQueue.main.after(when: DispatchTime.now() + 0.1) { 
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {
             self.button.kf_cancelImageDownloadTask()
             _ = stub!.go()
         }
@@ -150,7 +150,7 @@ class NSButtonExtensionTests: XCTestCase {
             expectation.fulfill()
         }
 
-        DispatchQueue.main.after(when: DispatchTime.now() + 0.1) {
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {
             self.button.kf_cancelAlternateImageDownloadTask()
             _ = stub!.go()
         }

+ 2 - 2
Tests/KingfisherTests/UIButtonExtensionTests.swift

@@ -125,7 +125,7 @@ class UIButtonExtensionTests: XCTestCase {
 
                 expectation.fulfill()
         }
-        DispatchQueue.main.after(when: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.1)) / Double(NSEC_PER_SEC)) { () -> Void in
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.1)) / Double(NSEC_PER_SEC)) { () -> Void in
             self.button.kf_cancelImageDownloadTask()
             _ = stub!.go()
         }
@@ -148,7 +148,7 @@ class UIButtonExtensionTests: XCTestCase {
                 
                 expectation.fulfill()
         }
-        DispatchQueue.main.after(when: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.1)) / Double(NSEC_PER_SEC)) { () -> Void in
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 0.1)) / Double(NSEC_PER_SEC)) { () -> Void in
             self.button.kf_cancelBackgroundImageDownloadTask()
             _ = stub!.go()
         }