From ce428e40c371f5293849733c31e0dcfd43b6ae33 Mon Sep 17 00:00:00 2001 From: Dave Camp Date: Thu, 28 Mar 2019 13:54:07 -0700 Subject: [PATCH] Replaced Alamofire Result type with AFResult typealias to Foundation.Result --- Alamofire.xcodeproj/project.pbxproj | 37 +-- Documentation/Usage.md | 8 +- Example/Source/DetailViewController.swift | 2 +- Source/AFResult.swift | 247 +++++++++++++++ Source/EventMonitor.swift | 10 +- Source/MultipartUpload.swift | 2 +- Source/ParameterEncoder.swift | 4 +- Source/Request.swift | 2 +- Source/RequestInterceptor.swift | 14 +- Source/Response.swift | 12 +- Source/ResponseSerialization.swift | 12 +- Source/Result.swift | 297 ------------------ Source/Validation.swift | 2 +- ...{ResultTests.swift => AFResultTests.swift} | 76 ++--- Tests/DownloadTests.swift | 2 +- Tests/NSLoggingEventMonitor.swift | 2 +- Tests/ParameterEncoderTests.swift | 78 ++--- Tests/RequestInterceptorTests.swift | 14 +- Tests/RequestTests.swift | 2 +- Tests/ResponseSerializationTests.swift | 118 +++---- Tests/ResponseTests.swift | 2 +- Tests/ServerTrustEvaluatorTests.swift | 134 ++++---- Tests/SessionTests.swift | 16 +- Tests/UploadTests.swift | 2 +- 24 files changed, 523 insertions(+), 572 deletions(-) create mode 100644 Source/AFResult.swift delete mode 100644 Source/Result.swift rename Tests/{ResultTests.swift => AFResultTests.swift} (84%) diff --git a/Alamofire.xcodeproj/project.pbxproj b/Alamofire.xcodeproj/project.pbxproj index 2e6d9cadb..128a31b88 100644 --- a/Alamofire.xcodeproj/project.pbxproj +++ b/Alamofire.xcodeproj/project.pbxproj @@ -27,9 +27,9 @@ 3107EA3820A11F9600445260 /* ResponseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8111E5E19A9674D0040E7D1 /* ResponseTests.swift */; }; 3107EA3920A11F9600445260 /* ResponseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8111E5E19A9674D0040E7D1 /* ResponseTests.swift */; }; 3107EA3A20A11F9700445260 /* ResponseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8111E5E19A9674D0040E7D1 /* ResponseTests.swift */; }; - 3107EA3C20A124E900445260 /* ResultTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA028C41B7466C500C84163 /* ResultTests.swift */; }; - 3107EA3D20A124EA00445260 /* ResultTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA028C41B7466C500C84163 /* ResultTests.swift */; }; - 3107EA3E20A124EB00445260 /* ResultTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA028C41B7466C500C84163 /* ResultTests.swift */; }; + 3107EA3C20A124E900445260 /* AFResultTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA028C41B7466C500C84163 /* AFResultTests.swift */; }; + 3107EA3D20A124EA00445260 /* AFResultTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA028C41B7466C500C84163 /* AFResultTests.swift */; }; + 3107EA3E20A124EB00445260 /* AFResultTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA028C41B7466C500C84163 /* AFResultTests.swift */; }; 3107EA3F20A1267C00445260 /* SessionDelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C9DCE771CB1BCE2003E6463 /* SessionDelegateTests.swift */; }; 3107EA4020A1267C00445260 /* SessionDelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C9DCE771CB1BCE2003E6463 /* SessionDelegateTests.swift */; }; 3107EA4120A1267D00445260 /* SessionDelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C9DCE771CB1BCE2003E6463 /* SessionDelegateTests.swift */; }; @@ -155,8 +155,8 @@ 4C0CB64B220CA8D600604EDC /* RedirectHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0CB64A220CA8D600604EDC /* RedirectHandlerTests.swift */; }; 4C0CB64C220CA8D600604EDC /* RedirectHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0CB64A220CA8D600604EDC /* RedirectHandlerTests.swift */; }; 4C0CB64D220CA8D600604EDC /* RedirectHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0CB64A220CA8D600604EDC /* RedirectHandlerTests.swift */; }; - 4C0E5BF81B673D3400816CCC /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0E5BF71B673D3400816CCC /* Result.swift */; }; - 4C0E5BF91B673D3400816CCC /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0E5BF71B673D3400816CCC /* Result.swift */; }; + 4C0E5BF81B673D3400816CCC /* AFResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0E5BF71B673D3400816CCC /* AFResult.swift */; }; + 4C0E5BF91B673D3400816CCC /* AFResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0E5BF71B673D3400816CCC /* AFResult.swift */; }; 4C1DC8541B68908E00476DE3 /* AFError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C1DC8531B68908E00476DE3 /* AFError.swift */; }; 4C1DC8551B68908E00476DE3 /* AFError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C1DC8531B68908E00476DE3 /* AFError.swift */; }; 4C23EB431B327C5B0090E0BC /* MultipartFormData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C23EB421B327C5B0090E0BC /* MultipartFormData.swift */; }; @@ -271,7 +271,7 @@ 4CE2724F1AF88FB500F1D59A /* ParameterEncoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE2724E1AF88FB500F1D59A /* ParameterEncoding.swift */; }; 4CE272501AF88FB500F1D59A /* ParameterEncoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE2724E1AF88FB500F1D59A /* ParameterEncoding.swift */; }; 4CEC605A1B745C9100E684F4 /* AFError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C1DC8531B68908E00476DE3 /* AFError.swift */; }; - 4CEC605B1B745C9100E684F4 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0E5BF71B673D3400816CCC /* Result.swift */; }; + 4CEC605B1B745C9100E684F4 /* AFResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0E5BF71B673D3400816CCC /* AFResult.swift */; }; 4CEC605C1B745C9B00E684F4 /* Alamofire.h in Headers */ = {isa = PBXBuildFile; fileRef = F8111E3819A95C8B0040E7D1 /* Alamofire.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4CEE82AD1C6813CF00E9C9F0 /* NetworkReachabilityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C3D00531C66A63000D1F709 /* NetworkReachabilityManager.swift */; }; 4CF626F91BA7CB3E0011A099 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CF626EF1BA7CB3E0011A099 /* Alamofire.framework */; }; @@ -279,7 +279,7 @@ 4CF627071BA7CBF60011A099 /* Alamofire.swift in Sources */ = {isa = PBXBuildFile; fileRef = F897FF4019AA800700AB5182 /* Alamofire.swift */; }; 4CF627081BA7CBF60011A099 /* AFError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C1DC8531B68908E00476DE3 /* AFError.swift */; }; 4CF6270A1BA7CBF60011A099 /* ParameterEncoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE2724E1AF88FB500F1D59A /* ParameterEncoding.swift */; }; - 4CF6270C1BA7CBF60011A099 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0E5BF71B673D3400816CCC /* Result.swift */; }; + 4CF6270C1BA7CBF60011A099 /* AFResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0E5BF71B673D3400816CCC /* AFResult.swift */; }; 4CF6270E1BA7CBF60011A099 /* MultipartFormData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C23EB421B327C5B0090E0BC /* MultipartFormData.swift */; }; 4CF6270F1BA7CBF60011A099 /* ResponseSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CDE2C451AF89FF300BABAE5 /* ResponseSerialization.swift */; }; 4CF627101BA7CBF60011A099 /* ServerTrustEvaluation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C811F8C1B51856D00E0F59A /* ServerTrustEvaluation.swift */; }; @@ -393,7 +393,7 @@ 4C0CB640220CA89400604EDC /* URLRequest+Alamofire.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "URLRequest+Alamofire.swift"; sourceTree = ""; }; 4C0CB645220CA8A400604EDC /* RedirectHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RedirectHandler.swift; sourceTree = ""; }; 4C0CB64A220CA8D600604EDC /* RedirectHandlerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RedirectHandlerTests.swift; sourceTree = ""; }; - 4C0E5BF71B673D3400816CCC /* Result.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = ""; }; + 4C0E5BF71B673D3400816CCC /* AFResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AFResult.swift; sourceTree = ""; }; 4C1DC8531B68908E00476DE3 /* AFError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AFError.swift; sourceTree = ""; }; 4C23EB421B327C5B0090E0BC /* MultipartFormData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MultipartFormData.swift; sourceTree = ""; }; 4C256A0521EEB69000AD5D87 /* RequestInterceptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestInterceptor.swift; sourceTree = ""; }; @@ -425,7 +425,7 @@ 4C9E88371F5FB3B0000BEC61 /* Alamofire 2.0 Migration Guide.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = "Alamofire 2.0 Migration Guide.md"; path = "Documentation/Alamofire 2.0 Migration Guide.md"; sourceTree = ""; }; 4C9E88381F5FB3B0000BEC61 /* Alamofire 3.0 Migration Guide.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = "Alamofire 3.0 Migration Guide.md"; path = "Documentation/Alamofire 3.0 Migration Guide.md"; sourceTree = ""; }; 4C9E88391F5FB3B0000BEC61 /* Alamofire 4.0 Migration Guide.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = "Alamofire 4.0 Migration Guide.md"; path = "Documentation/Alamofire 4.0 Migration Guide.md"; sourceTree = ""; }; - 4CA028C41B7466C500C84163 /* ResultTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResultTests.swift; sourceTree = ""; }; + 4CA028C41B7466C500C84163 /* AFResultTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AFResultTests.swift; sourceTree = ""; }; 4CB928281C66BFBC00CE5F08 /* Notifications.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = ""; }; 4CBD217F220B48AE008F1C59 /* RetryPolicyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RetryPolicyTests.swift; sourceTree = ""; }; 4CCB20681D4549E000C64D5B /* expired.badssl.com-leaf.cer */ = {isa = PBXFileReference; lastKnownFileType = file; path = "expired.badssl.com-leaf.cer"; sourceTree = ""; }; @@ -541,13 +541,13 @@ 4C256A4E1B09656A0065714F /* Core */ = { isa = PBXGroup; children = ( + 4CA028C41B7466C500C84163 /* AFResultTests.swift */, F8E6024419CB46A800A3E7F1 /* AuthenticationTests.swift */, F8111E5B19A9674D0040E7D1 /* DownloadTests.swift */, 31501E872196962A005829F2 /* ParameterEncoderTests.swift */, F8111E5C19A9674D0040E7D1 /* ParameterEncodingTests.swift */, F8111E5D19A9674D0040E7D1 /* RequestTests.swift */, F8111E5E19A9674D0040E7D1 /* ResponseTests.swift */, - 4CA028C41B7466C500C84163 /* ResultTests.swift */, 4C9DCE771CB1BCE2003E6463 /* SessionDelegateTests.swift */, F8D1C6F419D52968002E74FE /* SessionTests.swift */, F8111E5F19A9674D0040E7D1 /* UploadTests.swift */, @@ -710,6 +710,7 @@ isa = PBXGroup; children = ( 4C1DC8531B68908E00476DE3 /* AFError.swift */, + 4C0E5BF71B673D3400816CCC /* AFResult.swift */, 319917A9209CDCB000103A19 /* HTTPHeaders.swift */, 31727417218BAEC90039FFCC /* HTTPMethod.swift */, 4CB928281C66BFBC00CE5F08 /* Notifications.swift */, @@ -719,7 +720,6 @@ 31991790209CDA7F00103A19 /* Request.swift */, 319917A4209CDAC400103A19 /* RequestTaskMap.swift */, 31991791209CDA7F00103A19 /* Response.swift */, - 4C0E5BF71B673D3400816CCC /* Result.swift */, 31991792209CDA7F00103A19 /* Session.swift */, 31991793209CDA7F00103A19 /* SessionStateProvider.swift */, 31D83FCD20D5C29300D93E47 /* URLConvertible+URLRequestConvertible.swift */, @@ -1119,6 +1119,7 @@ developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -1315,7 +1316,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 4CF6270C1BA7CBF60011A099 /* Result.swift in Sources */, + 4CF6270C1BA7CBF60011A099 /* AFResult.swift in Sources */, 4CF627081BA7CBF60011A099 /* AFError.swift in Sources */, 3191B5771F5F53A6003960A8 /* Protector.swift in Sources */, 3199179A209CDA7F00103A19 /* Response.swift in Sources */, @@ -1378,7 +1379,7 @@ 3107EA4120A1267D00445260 /* SessionDelegateTests.swift in Sources */, 31C2B0EC20B271060089BA7C /* CacheTests.swift in Sources */, 3111CE9120A7EC27008315E2 /* NetworkReachabilityManagerTests.swift in Sources */, - 3107EA3E20A124EB00445260 /* ResultTests.swift in Sources */, + 3107EA3E20A124EB00445260 /* AFResultTests.swift in Sources */, 4CF627171BA7CC240011A099 /* ParameterEncodingTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1415,7 +1416,7 @@ 31991795209CDA7F00103A19 /* Request.swift in Sources */, 4CDE2C441AF89F0900BABAE5 /* Validation.swift in Sources */, 3199179D209CDA7F00103A19 /* Session.swift in Sources */, - 4C0E5BF91B673D3400816CCC /* Result.swift in Sources */, + 4C0E5BF91B673D3400816CCC /* AFResult.swift in Sources */, 3111CE8920A77944008315E2 /* EventMonitor.swift in Sources */, 31DADDFC224811ED0051390F /* AlamofireExtended.swift in Sources */, ); @@ -1441,7 +1442,7 @@ E4202FD21B667AA100C997FB /* ResponseSerialization.swift in Sources */, 4CB9282C1C66BFBC00CE5F08 /* Notifications.swift in Sources */, 4C0CB644220CA89400604EDC /* URLRequest+Alamofire.swift in Sources */, - 4CEC605B1B745C9100E684F4 /* Result.swift in Sources */, + 4CEC605B1B745C9100E684F4 /* AFResult.swift in Sources */, 4C256A0921EEB69000AD5D87 /* RequestInterceptor.swift in Sources */, 4C43669E1D7BB93D00C38AAD /* DispatchQueue+Alamofire.swift in Sources */, E4202FD41B667AA100C997FB /* Alamofire.swift in Sources */, @@ -1491,7 +1492,7 @@ 31991794209CDA7F00103A19 /* Request.swift in Sources */, 4CB928291C66BFBC00CE5F08 /* Notifications.swift in Sources */, 3199179C209CDA7F00103A19 /* Session.swift in Sources */, - 4C0E5BF81B673D3400816CCC /* Result.swift in Sources */, + 4C0E5BF81B673D3400816CCC /* AFResult.swift in Sources */, 3111CE8820A77843008315E2 /* EventMonitor.swift in Sources */, 31DADDFB224811ED0051390F /* AlamofireExtended.swift in Sources */, ); @@ -1526,7 +1527,7 @@ 3107EA3F20A1267C00445260 /* SessionDelegateTests.swift in Sources */, 31C2B0EA20B271040089BA7C /* CacheTests.swift in Sources */, 3111CE8F20A7EC26008315E2 /* NetworkReachabilityManagerTests.swift in Sources */, - 3107EA3C20A124E900445260 /* ResultTests.swift in Sources */, + 3107EA3C20A124E900445260 /* AFResultTests.swift in Sources */, F8111E6119A9674D0040E7D1 /* ParameterEncodingTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1560,7 +1561,7 @@ 3107EA4020A1267C00445260 /* SessionDelegateTests.swift in Sources */, 31C2B0EB20B271050089BA7C /* CacheTests.swift in Sources */, 3111CE9020A7EC27008315E2 /* NetworkReachabilityManagerTests.swift in Sources */, - 3107EA3D20A124EA00445260 /* ResultTests.swift in Sources */, + 3107EA3D20A124EA00445260 /* AFResultTests.swift in Sources */, 4C256A541B096C770065714F /* BaseTestCase.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Documentation/Usage.md b/Documentation/Usage.md index ee458c918..6521ad136 100644 --- a/Documentation/Usage.md +++ b/Documentation/Usage.md @@ -87,11 +87,11 @@ Alamofire.request("https://httpbin.org/get").response { response in } ``` -> We strongly encourage you to leverage the other response serializers taking advantage of `Response` and `Result` types. +> We strongly encourage you to leverage the other response serializers taking advantage of `Response` and `AFResult` types. #### Response Data Handler -The `responseData` handler uses the `responseDataSerializer` (the object that serializes the server data into some other type) to extract the `Data` returned by the server. If no errors occur and `Data` is returned, the response `Result` will be a `.success` and the `value` will be of type `Data`. +The `responseData` handler uses the `responseDataSerializer` (the object that serializes the server data into some other type) to extract the `Data` returned by the server. If no errors occur and `Data` is returned, the response `AFResult` will be a `.success` and the `value` will be of type `Data`. ```swift Alamofire.request("https://httpbin.org/get").responseData { response in @@ -105,7 +105,7 @@ Alamofire.request("https://httpbin.org/get").responseData { response in #### Response String Handler -The `responseString` handler uses the `responseStringSerializer` to convert the `Data` returned by the server into a `String` with the specified encoding. If no errors occur and the server data is successfully serialized into a `String`, the response `Result` will be a `.success` and the `value` will be of type `String`. +The `responseString` handler uses the `responseStringSerializer` to convert the `Data` returned by the server into a `String` with the specified encoding. If no errors occur and the server data is successfully serialized into a `String`, the response `AFResult` will be a `.success` and the `value` will be of type `String`. ```swift Alamofire.request("https://httpbin.org/get").responseString { response in @@ -118,7 +118,7 @@ Alamofire.request("https://httpbin.org/get").responseString { response in #### Response JSON Handler -The `responseJSON` handler uses the `responseJSONSerializer` to convert the `Data` returned by the server into an `Any` type using the specified `JSONSerialization.ReadingOptions`. If no errors occur and the server data is successfully serialized into a JSON object, the response `Result` will be a `.success` and the `value` will be of type `Any`. +The `responseJSON` handler uses the `responseJSONSerializer` to convert the `Data` returned by the server into an `Any` type using the specified `JSONSerialization.ReadingOptions`. If no errors occur and the server data is successfully serialized into a JSON object, the response `AFResult` will be a `.success` and the `value` will be of type `Any`. ```swift Alamofire.request("https://httpbin.org/get").responseJSON { response in diff --git a/Example/Source/DetailViewController.swift b/Example/Source/DetailViewController.swift index 27f654c21..17b61cd7a 100644 --- a/Example/Source/DetailViewController.swift +++ b/Example/Source/DetailViewController.swift @@ -76,7 +76,7 @@ class DetailViewController: UITableViewController { let start = CACurrentMediaTime() - let requestComplete: (HTTPURLResponse?, Result) -> Void = { response, result in + let requestComplete: (HTTPURLResponse?, AFResult) -> Void = { response, result in let end = CACurrentMediaTime() self.elapsedTime = end - start diff --git a/Source/AFResult.swift b/Source/AFResult.swift new file mode 100644 index 000000000..90eb39b2c --- /dev/null +++ b/Source/AFResult.swift @@ -0,0 +1,247 @@ +// +// AFResult.swift +// +// Copyright (c) 2014-2019 Alamofire Software Foundation (http://alamofire.org/) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +import Foundation + +public typealias AFResult = Result + +// MARK: - CustomStringConvertible + +extension AFResult: CustomStringConvertible { + /// The textual representation used when written to an output stream, which includes whether the result was a + /// success or failure. + public var description: String { + switch self { + case .success: + return "SUCCESS" + case .failure: + return "FAILURE" + } + } +} + +// MARK: - CustomDebugStringConvertible + +extension AFResult: CustomDebugStringConvertible { + /// The debug textual representation used when written to an output stream, which includes whether the result was a + /// success or failure in addition to the value or error. + public var debugDescription: String { + switch self { + case .success(let value): + return "SUCCESS: \(value)" + case .failure(let error): + return "FAILURE: \(error)" + } + } +} + +// MARK: - Functional APIs + +extension AFResult { + /// Initializes an `AFResult` from value or error. Returns `.failure` if the error is non-nil, `.success` otherwise. + /// + /// - Parameters: + /// - value: A value. + /// - error: An `Error`. + init(value: Success, error: Failure?) { + if let error = error { + self = .failure(error) + } else { + self = .success(value) + } + } + + /// Returns `true` if the result is a success, `false` otherwise. + var isSuccess: Bool { + switch self { + case .success: + return true + case .failure: + return false + } + } + + /// Returns `true` if the result is a failure, `false` otherwise. + var isFailure: Bool { + return !isSuccess + } + + /// Returns the success value, or throws the failure error. + /// + /// let possibleString: AFResult = .success("success") + /// try print(possibleString.unwrap()) + /// // Prints "success" + /// + /// let noString: AFResult = .failure(error) + /// try print(noString.unwrap()) + /// // Throws error + func unwrap() throws -> Success { + switch self { + case .success(let value): + return value + case .failure(let error): + throw error + } + } + + /// Evaluates the specified closure when the `AFResult` is a success, passing the unwrapped value as a parameter. + /// + /// Use the `flatMap` method with a closure that may throw an error. For example: + /// + /// let possibleData: AFResult = .success(Data(...)) + /// let possibleObject = possibleData.flatMap { + /// try JSONSerialization.jsonObject(with: $0) + /// } + /// + /// - parameter transform: A closure that takes the success value of the instance. + /// + /// - returns: An `AFResult` containing the result of the given closure. If this instance is a failure, returns the + /// same failure. + func flatMap(_ transform: (Success) throws -> T) -> AFResult { + switch self { + case .success(let value): + do { + return try .success(transform(value)) + } catch { + return .failure(error) + } + case .failure(let error): + return .failure(error) + } + } + + /// Evaluates the specified closure when the `AFResult` is a failure, passing the unwrapped error as a parameter. + /// + /// Use the `flatMapError` function with a closure that may throw an error. For example: + /// + /// let possibleData: AFResult = .success(Data(...)) + /// let possibleObject = possibleData.flatMapError { + /// try someFailableFunction(taking: $0) + /// } + /// + /// - Parameter transform: A throwing closure that takes the error of the instance. + /// + /// - Returns: An `AFResult` instance containing the result of the transform. If this instance is a success, returns + /// the same success. + func flatMapError(_ transform: (Failure) throws -> T) -> AFResult { + switch self { + case .failure(let error): + do { + return try .failure(transform(error)) + } catch { + return .failure(error) + } + case .success(let value): + return .success(value) + } + } + + /// Evaluates the specified closure when the `AFResult` is a success, passing the unwrapped value as a parameter. + /// + /// Use the `withValue` function to evaluate the passed closure. + /// + /// - Parameter closure: A closure that takes the success value of this instance. + /// - Returns: An `AFResult` instance, unmodified. + @discardableResult + func withValue(_ closure: (Success) throws -> Void) rethrows -> AFResult { + switch self { + case .success(let value): + try closure(value) + return .success(value) + case .failure(let error): + return .failure(error) + } + } + + /// Evaluates the specified closure when the `AFResult` is a failure, passing the unwrapped error as a parameter. + /// + /// Use the `withError` function to evaluate the passed closure. + /// + /// - Parameter closure: A closure that takes the success value of this instance. + /// - Returns: An `AFResult` instance, unmodified. + @discardableResult + func withError(_ closure: (Failure) throws -> Void) rethrows -> AFResult { + switch self { + case .failure(let error): + try closure(error) + return .failure(error) + case .success(let value): + return .success(value) + } + } + + /// Evaluates the specified closure when the `AFResult` is a success. + /// + /// Use the `ifSuccess` function to evaluate the passed closure without modifying the `AFResult` instance. + /// + /// - Parameter closure: A `Void` closure. + /// - Returns: This `AFResult` instance, unmodified. + @discardableResult + func ifSuccess(_ closure: () throws -> Void) rethrows -> AFResult { + switch self { + case .success(let value): + try closure() + return .success(value) + case .failure(let error): + return .failure(error) + } + } + + /// Evaluates the specified closure when the `AFResult` is a failure. + /// + /// Use the `ifFailure` function to evaluate the passed closure without modifying the `AFResult` instance. + /// + /// - Parameter closure: A `Void` closure. + /// - Returns: This `AFResult` instance, unmodified. + @discardableResult + func ifFailure(_ closure: () throws -> Void) rethrows -> AFResult { + switch self { + case .success(let value): + return .success(value) + case .failure(let error): + try closure() + return .failure(error) + } + } + + /// Returns the associated value if the result is a success, `nil` otherwise. + var value: Success? { + switch self { + case .success(let value): + return value + case .failure: + return nil + } + } + + /// Returns the associated error value if the result is a failure, `nil` otherwise. + var error: Error? { + switch self { + case .success: + return nil + case .failure(let error): + return error + } + } +} diff --git a/Source/EventMonitor.swift b/Source/EventMonitor.swift index bec74a6c9..1f5796203 100644 --- a/Source/EventMonitor.swift +++ b/Source/EventMonitor.swift @@ -166,7 +166,7 @@ public protocol EventMonitor { // MARK: DownloadRequest Events /// Event called when a `DownloadRequest`'s `URLSessionDownloadTask` finishes and the temporary file has been moved. - func request(_ request: DownloadRequest, didFinishDownloadingUsing task: URLSessionTask, with result: Result) + func request(_ request: DownloadRequest, didFinishDownloadingUsing task: URLSessionTask, with result: AFResult) /// Event called when a `DownloadRequest`'s `Destination` closure is called and creates the destination URL the /// downloaded file will be moved to. @@ -254,7 +254,7 @@ extension EventMonitor { public func request(_ request: UploadRequest, didCreateUploadable uploadable: UploadRequest.Uploadable) { } public func request(_ request: UploadRequest, didFailToCreateUploadableWithError error: Error) { } public func request(_ request: UploadRequest, didProvideInputStream stream: InputStream) { } - public func request(_ request: DownloadRequest, didFinishDownloadingUsing task: URLSessionTask, with result: Result) { } + public func request(_ request: DownloadRequest, didFinishDownloadingUsing task: URLSessionTask, with result: AFResult) { } public func request(_ request: DownloadRequest, didCreateDestinationURL url: URL) { } public func request(_ request: DownloadRequest, didValidateRequest urlRequest: URLRequest?, @@ -465,7 +465,7 @@ public final class CompositeEventMonitor: EventMonitor { performEvent { $0.request(request, didProvideInputStream: stream) } } - public func request(_ request: DownloadRequest, didFinishDownloadingUsing task: URLSessionTask, with result: Result) { + public func request(_ request: DownloadRequest, didFinishDownloadingUsing task: URLSessionTask, with result: AFResult) { performEvent { $0.request(request, didFinishDownloadingUsing: task, with: result) } } @@ -593,7 +593,7 @@ open class ClosureEventMonitor: EventMonitor { open var requestDidProvideInputStream: ((UploadRequest, InputStream) -> Void)? /// Closure called on the `request(_:didFinishDownloadingUsing:with:)` event. - open var requestDidFinishDownloadingUsingTaskWithResult: ((DownloadRequest, URLSessionTask, Result) -> Void)? + open var requestDidFinishDownloadingUsingTaskWithResult: ((DownloadRequest, URLSessionTask, AFResult) -> Void)? /// Closure called on the `request(_:didCreateDestinationURL:)` event. open var requestDidCreateDestinationURL: ((DownloadRequest, URL) -> Void)? @@ -754,7 +754,7 @@ open class ClosureEventMonitor: EventMonitor { requestDidProvideInputStream?(request, stream) } - open func request(_ request: DownloadRequest, didFinishDownloadingUsing task: URLSessionTask, with result: Result) { + open func request(_ request: DownloadRequest, didFinishDownloadingUsing task: URLSessionTask, with result: AFResult) { requestDidFinishDownloadingUsingTaskWithResult?(request, task, result) } diff --git a/Source/MultipartUpload.swift b/Source/MultipartUpload.swift index e5f0bbe83..d029cc6d4 100644 --- a/Source/MultipartUpload.swift +++ b/Source/MultipartUpload.swift @@ -28,7 +28,7 @@ open class MultipartUpload { /// Default memory threshold used when encoding `MultipartFormData`, in bytes. public static let encodingMemoryThreshold: UInt64 = 10_000_000 - lazy var result = Result { try build() } + lazy var result = AFResult { try build() } let isInBackgroundSession: Bool let multipartFormData: MultipartFormData diff --git a/Source/ParameterEncoder.swift b/Source/ParameterEncoder.swift index 95975944d..64ee415b5 100644 --- a/Source/ParameterEncoder.swift +++ b/Source/ParameterEncoder.swift @@ -164,7 +164,7 @@ open class URLEncodedFormParameterEncoder: ParameterEncoder { if destination.encodesParametersInURL(for: method), var components = URLComponents(url: url, resolvingAgainstBaseURL: false) { - let query: String = try Result { try encoder.encode(parameters) } + let query: String = try AFResult { try encoder.encode(parameters) } .mapError { AFError.parameterEncoderFailed(reason: .encoderFailed(error: $0)) }.unwrap() let newQueryString = [components.percentEncodedQuery, query].compactMap { $0 }.joinedWithAmpersands() components.percentEncodedQuery = newQueryString @@ -179,7 +179,7 @@ open class URLEncodedFormParameterEncoder: ParameterEncoder { request.httpHeaders.update(.contentType("application/x-www-form-urlencoded; charset=utf-8")) } - request.httpBody = try Result { try encoder.encode(parameters) } + request.httpBody = try AFResult { try encoder.encode(parameters) } .mapError { AFError.parameterEncoderFailed(reason: .encoderFailed(error: $0)) }.unwrap() } diff --git a/Source/Request.swift b/Source/Request.swift index c44e7101c..eaad5fbbe 100644 --- a/Source/Request.swift +++ b/Source/Request.swift @@ -902,7 +902,7 @@ open class DownloadRequest: Request { protectedMutableState.write { $0.fileURL = nil } } - func didFinishDownloading(using task: URLSessionTask, with result: Result) { + func didFinishDownloading(using task: URLSessionTask, with result: AFResult) { eventMonitor?.request(self, didFinishDownloadingUsing: task, with: result) result.withValue { url in protectedMutableState.write { $0.fileURL = url } } diff --git a/Source/RequestInterceptor.swift b/Source/RequestInterceptor.swift index 19e0c23ef..76366e10e 100644 --- a/Source/RequestInterceptor.swift +++ b/Source/RequestInterceptor.swift @@ -26,13 +26,13 @@ import Foundation /// A type that can inspect and optionally adapt a `URLRequest` in some manner if necessary. public protocol RequestAdapter { - /// Inspects and adapts the specified `URLRequest` in some manner and calls the completion handler with the Result. + /// Inspects and adapts the specified `URLRequest` in some manner and calls the completion handler with the AFResult. /// /// - Parameters: /// - urlRequest: The `URLRequest` to adapt. /// - session: The `Session` that will execute the `URLRequest`. /// - completion: The completion handler that must be called when adaptation is complete. - func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result) -> Void) + func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (AFResult) -> Void) } // MARK: - @@ -87,7 +87,7 @@ public protocol RequestRetrier { public protocol RequestInterceptor: RequestAdapter, RequestRetrier {} extension RequestInterceptor { - public func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result) -> Void) { + public func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (AFResult) -> Void) { completion(.success(urlRequest)) } @@ -101,7 +101,7 @@ extension RequestInterceptor { } } -public typealias AdaptHandler = (URLRequest, Session, _ completion: @escaping (Result) -> Void) -> Void +public typealias AdaptHandler = (URLRequest, Session, _ completion: @escaping (AFResult) -> Void) -> Void public typealias RetryHandler = (Request, Session, Error, _ completion: @escaping (RetryResult) -> Void) -> Void // MARK: - @@ -113,7 +113,7 @@ open class Adapter: RequestInterceptor { self.adaptHandler = adaptHandler } - open func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result) -> Void) { + open func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (AFResult) -> Void) { adaptHandler(urlRequest, session, completion) } } @@ -158,7 +158,7 @@ open class Interceptor: RequestInterceptor { self.retriers = retriers } - open func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result) -> Void) { + open func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (AFResult) -> Void) { adapt(urlRequest, for: session, using: adapters, completion: completion) } @@ -166,7 +166,7 @@ open class Interceptor: RequestInterceptor { _ urlRequest: URLRequest, for session: Session, using adapters: [RequestAdapter], - completion: @escaping (Result) -> Void) + completion: @escaping (AFResult) -> Void) { var pendingAdapters = adapters diff --git a/Source/Response.swift b/Source/Response.swift index 818906b4b..2bd5a7f06 100644 --- a/Source/Response.swift +++ b/Source/Response.swift @@ -42,7 +42,7 @@ public struct DataResponse { public let serializationDuration: TimeInterval /// The result of response serialization. - public let result: Result + public let result: AFResult /// Returns the associated value of the result if it is a success, `nil` otherwise. public var value: Value? { return result.value } @@ -58,13 +58,13 @@ public struct DataResponse { /// - data: The `Data` returned by the server. /// - metrics: The `URLSessionTaskMetrics` of the serialized response. /// - serializationDuration: The duration taken by serialization. - /// - result: The `Result` of response serialization. + /// - result: The `AFResult` of response serialization. public init(request: URLRequest?, response: HTTPURLResponse?, data: Data?, metrics: URLSessionTaskMetrics?, serializationDuration: TimeInterval, - result: Result) { + result: AFResult) { self.request = request self.response = response self.data = data @@ -224,7 +224,7 @@ public struct DownloadResponse { public let serializationDuration: TimeInterval /// The result of response serialization. - public let result: Result + public let result: AFResult /// Returns the associated value of the result if it is a success, `nil` otherwise. public var value: Value? { return result.value } @@ -242,7 +242,7 @@ public struct DownloadResponse { /// - resumeData: The resume `Data` generated if the request was cancelled. /// - metrics: The `URLSessionTaskMetrics` of the serialized response. /// - serializationDuration: The duration taken by serialization. - /// - result: The `Result` of response serialization. + /// - result: The `AFResult` of response serialization. public init( request: URLRequest?, response: HTTPURLResponse?, @@ -250,7 +250,7 @@ public struct DownloadResponse { resumeData: Data?, metrics: URLSessionTaskMetrics?, serializationDuration: TimeInterval, - result: Result) + result: AFResult) { self.request = request self.response = response diff --git a/Source/ResponseSerialization.swift b/Source/ResponseSerialization.swift index 13a3a474b..2806f4506 100644 --- a/Source/ResponseSerialization.swift +++ b/Source/ResponseSerialization.swift @@ -110,7 +110,7 @@ extension DataRequest { @discardableResult public func response(queue: DispatchQueue = .main, completionHandler: @escaping (DataResponse) -> Void) -> Self { appendResponseSerializer { - let result = Result(value: self.data, error: self.error) + let result = AFResult(value: self.data, error: self.error) let response = DataResponse(request: self.request, response: self.response, data: self.data, @@ -142,7 +142,7 @@ extension DataRequest { { appendResponseSerializer { let start = CFAbsoluteTimeGetCurrent() - let result = Result { try responseSerializer.serialize(request: self.request, + let result = AFResult { try responseSerializer.serialize(request: self.request, response: self.response, data: self.data, error: self.error) } @@ -176,7 +176,7 @@ extension DataRequest { didComplete = { completionHandler(response) } case .doNotRetryWithError(let retryError): - let result = Result.failure(retryError) + let result = AFResult.failure(retryError) let response = DataResponse(request: self.request, response: self.response, @@ -211,7 +211,7 @@ extension DownloadRequest { -> Self { appendResponseSerializer { - let result = Result(value: self.fileURL , error: self.error) + let result = AFResult(value: self.fileURL , error: self.error) let response = DownloadResponse(request: self.request, response: self.response, fileURL: self.fileURL, @@ -243,7 +243,7 @@ extension DownloadRequest { { appendResponseSerializer { let start = CFAbsoluteTimeGetCurrent() - let result = Result { try responseSerializer.serializeDownload(request: self.request, + let result = AFResult { try responseSerializer.serializeDownload(request: self.request, response: self.response, fileURL: self.fileURL, error: self.error) } @@ -276,7 +276,7 @@ extension DownloadRequest { didComplete = { completionHandler(response) } case .doNotRetryWithError(let retryError): - let result = Result.failure(retryError) + let result = AFResult.failure(retryError) let response = DownloadResponse(request: self.request, response: self.response, diff --git a/Source/Result.swift b/Source/Result.swift deleted file mode 100644 index f2b4c3fec..000000000 --- a/Source/Result.swift +++ /dev/null @@ -1,297 +0,0 @@ -// -// Result.swift -// -// Copyright (c) 2014-2018 Alamofire Software Foundation (http://alamofire.org/) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -import Foundation - -/// Used to represent whether a request was successful or encountered an error. -/// -/// - success: The request and all post processing operations were successful resulting in the serialization of the -/// provided associated value. -/// -/// - failure: The request encountered an error resulting in a failure. The associated values are the original data -/// provided by the server as well as the error that caused the failure. -public enum Result { - case success(Value) - case failure(Error) - - /// Initializes a `Result` from value or error. Returns `.failure` if the error is non-nil, `.success` otherwise. - /// - /// - Parameters: - /// - value: A value. - /// - error: An `Error`. - init(value: Value, error: Error?) { - if let error = error { - self = .failure(error) - } else { - self = .success(value) - } - } - - /// Returns `true` if the result is a success, `false` otherwise. - public var isSuccess: Bool { - guard case .success = self else { return false } - return true - } - - /// Returns `true` if the result is a failure, `false` otherwise. - public var isFailure: Bool { - return !isSuccess - } - - /// Returns the associated value if the result is a success, `nil` otherwise. - public var value: Value? { - guard case .success(let value) = self else { return nil } - return value - } - - /// Returns the associated error value if the result is a failure, `nil` otherwise. - public var error: Error? { - guard case .failure(let error) = self else { return nil } - return error - } -} - -// MARK: - CustomStringConvertible - -extension Result: CustomStringConvertible { - /// The textual representation used when written to an output stream, which includes whether the result was a - /// success or failure. - public var description: String { - switch self { - case .success: - return "SUCCESS" - case .failure: - return "FAILURE" - } - } -} - -// MARK: - CustomDebugStringConvertible - -extension Result: CustomDebugStringConvertible { - /// The debug textual representation used when written to an output stream, which includes whether the result was a - /// success or failure in addition to the value or error. - public var debugDescription: String { - switch self { - case .success(let value): - return "SUCCESS: \(value)" - case .failure(let error): - return "FAILURE: \(error)" - } - } -} - -// MARK: - Functional APIs - -extension Result { - /// Creates a `Result` instance from the result of a closure. - /// - /// A failure result is created when the closure throws, and a success result is created when the closure - /// succeeds without throwing an error. - /// - /// func someString() throws -> String { ... } - /// - /// let result = Result(value: { - /// return try someString() - /// }) - /// - /// // The type of result is Result - /// - /// The trailing closure syntax is also supported: - /// - /// let result = Result { try someString() } - /// - /// - parameter value: The closure to execute and create the result for. - public init(value: () throws -> Value) { - do { - self = try .success(value()) - } catch { - self = .failure(error) - } - } - - /// Returns the success value, or throws the failure error. - /// - /// let possibleString: Result = .success("success") - /// try print(possibleString.unwrap()) - /// // Prints "success" - /// - /// let noString: Result = .failure(error) - /// try print(noString.unwrap()) - /// // Throws error - public func unwrap() throws -> Value { - switch self { - case .success(let value): - return value - case .failure(let error): - throw error - } - } - - /// Evaluates the specified closure when the `Result` is a success, passing the unwrapped value as a parameter. - /// - /// Use the `map` method with a closure that does not throw. For example: - /// - /// let possibleData: Result = .success(Data()) - /// let possibleInt = possibleData.map { $0.count } - /// try print(possibleInt.unwrap()) - /// // Prints "0" - /// - /// let noData: Result = .failure(error) - /// let noInt = noData.map { $0.count } - /// try print(noInt.unwrap()) - /// // Throws error - /// - /// - parameter transform: A closure that takes the success value of the `Result` instance. - /// - /// - returns: A `Result` containing the result of the given closure. If this instance is a failure, returns the - /// same failure. - public func map(_ transform: (Value) -> T) -> Result { - switch self { - case .success(let value): - return .success(transform(value)) - case .failure(let error): - return .failure(error) - } - } - - /// Evaluates the specified closure when the `Result` is a success, passing the unwrapped value as a parameter. - /// - /// Use the `flatMap` method with a closure that may throw an error. For example: - /// - /// let possibleData: Result = .success(Data(...)) - /// let possibleObject = possibleData.flatMap { - /// try JSONSerialization.jsonObject(with: $0) - /// } - /// - /// - parameter transform: A closure that takes the success value of the instance. - /// - /// - returns: A `Result` containing the result of the given closure. If this instance is a failure, returns the - /// same failure. - public func flatMap(_ transform: (Value) throws -> T) -> Result { - switch self { - case .success(let value): - do { - return try .success(transform(value)) - } catch { - return .failure(error) - } - case .failure(let error): - return .failure(error) - } - } - - /// Evaluates the specified closure when the `Result` is a failure, passing the unwrapped error as a parameter. - /// - /// Use the `mapError` function with a closure that does not throw. For example: - /// - /// let possibleData: Result = .failure(someError) - /// let withMyError: Result = possibleData.mapError { MyError.error($0) } - /// - /// - Parameter transform: A closure that takes the error of the instance. - /// - Returns: A `Result` instance containing the result of the transform. If this instance is a success, returns - /// the same instance. - public func mapError(_ transform: (Error) -> T) -> Result { - guard case .failure(let error) = self else { return self } - return .failure(transform(error)) - } - - /// Evaluates the specified closure when the `Result` is a failure, passing the unwrapped error as a parameter. - /// - /// Use the `flatMapError` function with a closure that may throw an error. For example: - /// - /// let possibleData: Result = .success(Data(...)) - /// let possibleObject = possibleData.flatMapError { - /// try someFailableFunction(taking: $0) - /// } - /// - /// - Parameter transform: A throwing closure that takes the error of the instance. - /// - /// - Returns: A `Result` instance containing the result of the transform. If this instance is a success, returns - /// the same instance. - public func flatMapError(_ transform: (Error) throws -> T) -> Result { - switch self { - case .failure(let error): - do { - return try .failure(transform(error)) - } catch { - return .failure(error) - } - case .success: - return self - } - } - - /// Evaluates the specified closure when the `Result` is a success, passing the unwrapped value as a parameter. - /// - /// Use the `withValue` function to evaluate the passed closure without modifying the `Result` instance. - /// - /// - Parameter closure: A closure that takes the success value of this instance. - /// - Returns: This `Result` instance, unmodified. - @discardableResult - public func withValue(_ closure: (Value) throws -> Void) rethrows -> Result { - if case let .success(value) = self { try closure(value) } - - return self - } - - /// Evaluates the specified closure when the `Result` is a failure, passing the unwrapped error as a parameter. - /// - /// Use the `withError` function to evaluate the passed closure without modifying the `Result` instance. - /// - /// - Parameter closure: A closure that takes the success value of this instance. - /// - Returns: This `Result` instance, unmodified. - @discardableResult - public func withError(_ closure: (Error) throws -> Void) rethrows -> Result { - if case let .failure(error) = self { try closure(error) } - - return self - } - - /// Evaluates the specified closure when the `Result` is a success. - /// - /// Use the `ifSuccess` function to evaluate the passed closure without modifying the `Result` instance. - /// - /// - Parameter closure: A `Void` closure. - /// - Returns: This `Result` instance, unmodified. - @discardableResult - public func ifSuccess(_ closure: () throws -> Void) rethrows -> Result { - if isSuccess { try closure() } - - return self - } - - /// Evaluates the specified closure when the `Result` is a failure. - /// - /// Use the `ifFailure` function to evaluate the passed closure without modifying the `Result` instance. - /// - /// - Parameter closure: A `Void` closure. - /// - Returns: This `Result` instance, unmodified. - @discardableResult - public func ifFailure(_ closure: () throws -> Void) rethrows -> Result { - if isFailure { try closure() } - - return self - } -} diff --git a/Source/Validation.swift b/Source/Validation.swift index 4387cb894..d7623b219 100644 --- a/Source/Validation.swift +++ b/Source/Validation.swift @@ -31,7 +31,7 @@ extension Request { fileprivate typealias ErrorReason = AFError.ResponseValidationFailureReason /// Used to represent whether a validation succeeded or failed. - public typealias ValidationResult = Result + public typealias ValidationResult = AFResult fileprivate struct MIMEType { let type: String diff --git a/Tests/ResultTests.swift b/Tests/AFResultTests.swift similarity index 84% rename from Tests/ResultTests.swift rename to Tests/AFResultTests.swift index 16e3f4515..3a37eaae0 100644 --- a/Tests/ResultTests.swift +++ b/Tests/AFResultTests.swift @@ -1,5 +1,5 @@ // -// ResultTests.swift +// AFResultTests.swift // // Copyright (c) 2014-2018 Alamofire Software Foundation (http://alamofire.org/) // @@ -26,14 +26,14 @@ import Foundation import XCTest -class ResultTestCase: BaseTestCase { +class AFResultTestCase: BaseTestCase { let error = AFError.responseValidationFailed(reason: .unacceptableStatusCode(code: 404)) // MARK: - Is Success Tests func testThatIsSuccessPropertyReturnsTrueForSuccessCase() { // Given, When - let result = Result.success("success") + let result = AFResult.success("success") // Then XCTAssertTrue(result.isSuccess, "result is success should be true for success case") @@ -41,7 +41,7 @@ class ResultTestCase: BaseTestCase { func testThatIsSuccessPropertyReturnsFalseForFailureCase() { // Given, When - let result = Result.failure(error) + let result = AFResult.failure(error) // Then XCTAssertFalse(result.isSuccess, "result is success should be false for failure case") @@ -51,7 +51,7 @@ class ResultTestCase: BaseTestCase { func testThatIsFailurePropertyReturnsFalseForSuccessCase() { // Given, When - let result = Result.success("success") + let result = AFResult.success("success") // Then XCTAssertFalse(result.isFailure, "result is failure should be false for success case") @@ -59,7 +59,7 @@ class ResultTestCase: BaseTestCase { func testThatIsFailurePropertyReturnsTrueForFailureCase() { // Given, When - let result = Result.failure(error) + let result = AFResult.failure(error) // Then XCTAssertTrue(result.isFailure, "result is failure should be true for failure case") @@ -69,7 +69,7 @@ class ResultTestCase: BaseTestCase { func testThatValuePropertyReturnsValueForSuccessCase() { // Given, When - let result = Result.success("success") + let result = AFResult.success("success") // Then XCTAssertEqual(result.value ?? "", "success", "result value should match expected value") @@ -77,7 +77,7 @@ class ResultTestCase: BaseTestCase { func testThatValuePropertyReturnsNilForFailureCase() { // Given, When - let result = Result.failure(error) + let result = AFResult.failure(error) // Then XCTAssertNil(result.value, "result value should be nil for failure case") @@ -87,7 +87,7 @@ class ResultTestCase: BaseTestCase { func testThatErrorPropertyReturnsNilForSuccessCase() { // Given, When - let result = Result.success("success") + let result = AFResult.success("success") // Then XCTAssertNil(result.error, "result error should be nil for success case") @@ -95,7 +95,7 @@ class ResultTestCase: BaseTestCase { func testThatErrorPropertyReturnsErrorForFailureCase() { // Given, When - let result = Result.failure(error) + let result = AFResult.failure(error) // Then XCTAssertNotNil(result.error, "result error should not be nil for failure case") @@ -105,7 +105,7 @@ class ResultTestCase: BaseTestCase { func testThatDescriptionStringMatchesExpectedValueForSuccessCase() { // Given, When - let result = Result.success("success") + let result = AFResult.success("success") // Then XCTAssertEqual(result.description, "SUCCESS", "result description should match expected value for success case") @@ -113,7 +113,7 @@ class ResultTestCase: BaseTestCase { func testThatDescriptionStringMatchesExpectedValueForFailureCase() { // Given, When - let result = Result.failure(error) + let result = AFResult.failure(error) // Then XCTAssertEqual(result.description, "FAILURE", "result description should match expected value for failure case") @@ -123,7 +123,7 @@ class ResultTestCase: BaseTestCase { func testThatDebugDescriptionStringMatchesExpectedValueForSuccessCase() { // Given, When - let result = Result.success("success value") + let result = AFResult.success("success value") // Then XCTAssertEqual( @@ -135,7 +135,7 @@ class ResultTestCase: BaseTestCase { func testThatDebugDescriptionStringMatchesExpectedValueForFailureCase() { // Given, When - let result = Result.failure(error) + let result = AFResult.failure(error) // Then XCTAssertEqual( @@ -152,8 +152,8 @@ class ResultTestCase: BaseTestCase { let value = "success value" // When - let result1 = Result(value: { value }) - let result2 = Result { value } + let result1 = AFResult(catching: { value }) + let result2 = AFResult { value } // Then for result in [result1, result2] { @@ -167,8 +167,8 @@ class ResultTestCase: BaseTestCase { struct ResultError: Error {} // When - let result1 = Result(value: { throw ResultError() }) - let result2 = Result { throw ResultError() } + let result1 = AFResult(catching: { throw ResultError() }) + let result2 = AFResult { throw ResultError() } // Then for result in [result1, result2] { @@ -181,7 +181,7 @@ class ResultTestCase: BaseTestCase { func testThatUnwrapReturnsSuccessValue() { // Given - let result = Result.success("success value") + let result = AFResult.success("success value") // When let unwrappedValue = try? result.unwrap() @@ -195,7 +195,7 @@ class ResultTestCase: BaseTestCase { struct ResultError: Error {} // When - let result = Result.failure(ResultError()) + let result = AFResult.failure(ResultError()) // Then do { @@ -210,7 +210,7 @@ class ResultTestCase: BaseTestCase { func testThatMapTransformsSuccessValue() { // Given - let result = Result.success("success value") + let result = AFResult.success("success value") // When let mappedResult = result.map { $0.count } @@ -222,7 +222,7 @@ class ResultTestCase: BaseTestCase { func testThatMapPreservesFailureError() { // Given struct ResultError: Error {} - let result = Result.failure(ResultError()) + let result = AFResult.failure(ResultError()) // When let mappedResult = result.map { $0.count } @@ -239,7 +239,7 @@ class ResultTestCase: BaseTestCase { func testThatFlatMapTransformsSuccessValue() { // Given - let result = Result.success("success value") + let result = AFResult.success("success value") // When let mappedResult = result.map { $0.count } @@ -251,7 +251,7 @@ class ResultTestCase: BaseTestCase { func testThatFlatMapCatchesTransformationError() { // Given struct TransformError: Error {} - let result = Result.success("success value") + let result = AFResult.success("success value") // When let mappedResult = result.flatMap { _ in throw TransformError() } @@ -268,7 +268,7 @@ class ResultTestCase: BaseTestCase { // Given struct ResultError: Error {} struct TransformError: Error {} - let result = Result.failure(ResultError()) + let result = AFResult.failure(ResultError()) // When let mappedResult = result.flatMap { _ in throw TransformError() } @@ -287,7 +287,7 @@ class ResultTestCase: BaseTestCase { // Given struct ResultError: Error {} struct OtherError: Error { let error: Error } - let result: Result = .failure(ResultError()) + let result: AFResult = .failure(ResultError()) // When let mappedResult = result.mapError { OtherError(error: $0) } @@ -304,7 +304,7 @@ class ResultTestCase: BaseTestCase { // Given struct ResultError: Error {} struct OtherError: Error { let error: Error } - let result: Result = .success("success") + let result: AFResult = .success("success") // When let mappedResult = result.mapError { OtherError(error: $0) } @@ -317,7 +317,7 @@ class ResultTestCase: BaseTestCase { // Given struct ResultError: Error {} struct OtherError: Error { let error: Error } - let result: Result = .failure(ResultError()) + let result: AFResult = .failure(ResultError()) // When let mappedResult = result.flatMapError { OtherError(error: $0) } @@ -338,7 +338,7 @@ class ResultTestCase: BaseTestCase { init(error: Error) throws { throw ThrownError() } } struct ThrownError: Error {} - let result: Result = .failure(ResultError()) + let result: AFResult = .failure(ResultError()) // When let mappedResult = result.flatMapError { try OtherError(error: $0) } @@ -355,7 +355,7 @@ class ResultTestCase: BaseTestCase { func testWithValueExecutesWhenSuccess() { // Given - let result: Result = .success("success") + let result: AFResult = .success("success") var string = "failure" // When @@ -368,7 +368,7 @@ class ResultTestCase: BaseTestCase { func testWithValueDoesNotExecutesWhenFailure() { // Given struct ResultError: Error {} - let result: Result = .failure(ResultError()) + let result: AFResult = .failure(ResultError()) var string = "failure" // When @@ -381,7 +381,7 @@ class ResultTestCase: BaseTestCase { func testWithErrorExecutesWhenFailure() { // Given struct ResultError: Error {} - let result: Result = .failure(ResultError()) + let result: AFResult = .failure(ResultError()) var string = "success" // When @@ -393,7 +393,7 @@ class ResultTestCase: BaseTestCase { func testWithErrorDoesNotExecuteWhenSuccess() { // Given - let result: Result = .success("success") + let result: AFResult = .success("success") var string = "success" // When @@ -407,7 +407,7 @@ class ResultTestCase: BaseTestCase { func testIfSuccessExecutesWhenSuccess() { // Given - let result: Result = .success("success") + let result: AFResult = .success("success") var string = "failure" // When @@ -420,7 +420,7 @@ class ResultTestCase: BaseTestCase { func testIfSuccessDoesNotExecutesWhenFailure() { // Given struct ResultError: Error {} - let result: Result = .failure(ResultError()) + let result: AFResult = .failure(ResultError()) var string = "failure" // When @@ -433,7 +433,7 @@ class ResultTestCase: BaseTestCase { func testIfFailureExecutesWhenFailure() { // Given struct ResultError: Error {} - let result: Result = .failure(ResultError()) + let result: AFResult = .failure(ResultError()) var string = "success" // When @@ -445,7 +445,7 @@ class ResultTestCase: BaseTestCase { func testIfFailureDoesNotExecuteWhenSuccess() { // Given - let result: Result = .success("success") + let result: AFResult = .success("success") var string = "success" // When @@ -460,7 +460,7 @@ class ResultTestCase: BaseTestCase { func testFunctionalMethodsCanBeChained() { // Given struct ResultError: Error {} - let result: Result = .success("first") + let result: AFResult = .success("first") var string = "first" var success = false diff --git a/Tests/DownloadTests.swift b/Tests/DownloadTests.swift index 658f91aad..9337db533 100644 --- a/Tests/DownloadTests.swift +++ b/Tests/DownloadTests.swift @@ -22,7 +22,7 @@ // THE SOFTWARE. // -import Alamofire +@testable import Alamofire import Foundation import XCTest diff --git a/Tests/NSLoggingEventMonitor.swift b/Tests/NSLoggingEventMonitor.swift index 83a852ddf..ea352c4b7 100644 --- a/Tests/NSLoggingEventMonitor.swift +++ b/Tests/NSLoggingEventMonitor.swift @@ -184,7 +184,7 @@ public final class NSLoggingEventMonitor: EventMonitor { NSLog("Request: \(request), didProvideInputStream: \(stream)") } - public func request(_ request: DownloadRequest, didFinishDownloadingUsing task: URLSessionTask, with result: Result) { + public func request(_ request: DownloadRequest, didFinishDownloadingUsing task: URLSessionTask, with result: AFResult) { NSLog("Request: \(request), didFinishDownloadingUsing: \(task), withResult: \(result)") } diff --git a/Tests/ParameterEncoderTests.swift b/Tests/ParameterEncoderTests.swift index 55e0fa937..6af536437 100644 --- a/Tests/ParameterEncoderTests.swift +++ b/Tests/ParameterEncoderTests.swift @@ -22,7 +22,7 @@ // THE SOFTWARE. // -import Alamofire +@testable import Alamofire import XCTest final class JSONParameterEncoderTests: BaseTestCase { @@ -186,7 +186,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = FailingOptionalStruct(testedContainer: .keyed) // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertTrue(result.isFailure) @@ -198,7 +198,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = FailingOptionalStruct(testedContainer: .unkeyed) // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertTrue(result.isFailure) @@ -210,7 +210,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ["a": "a"] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "a=a") @@ -222,7 +222,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ["a": 1.0] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "a=1.0") @@ -234,7 +234,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters: [String: Float] = ["a": 1.0] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "a=1.0") @@ -246,7 +246,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters: [String: Int8] = ["a": 1] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "a=1") @@ -258,7 +258,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters: [String: Int16] = ["a": 1] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "a=1") @@ -270,7 +270,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters: [String: Int32] = ["a": 1] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "a=1") @@ -282,7 +282,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters: [String: Int64] = ["a": 1] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "a=1") @@ -294,7 +294,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters: [String: UInt] = ["a": 1] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "a=1") @@ -306,7 +306,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters: [String: UInt8] = ["a": 1] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "a=1") @@ -318,7 +318,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters: [String: UInt16] = ["a": 1] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "a=1") @@ -330,7 +330,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters: [String: UInt32] = ["a": 1] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "a=1") @@ -342,7 +342,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters: [String: UInt64] = ["a": 1] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "a=1") @@ -354,7 +354,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ["a": ["b": "b"]] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "a%5Bb%5D=b") @@ -366,7 +366,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = EncodableStruct() // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then let expected = "four%5B%5D=1&four%5B%5D=2&four%5B%5D=3&three=1&one=one&two=2&five%5Ba%5D=a&six%5Ba%5D%5Bb%5D=b&seven%5Ba%5D=a" @@ -379,7 +379,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ManuallyEncodableStruct() // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then let expected = "root%5B%5D%5B%5D=1&root%5B%5D%5B%5D=2&root%5B%5D%5B%5D=3&root%5B%5D%5Ba%5D%5Bstring%5D=string&root%5B%5D%5B%5D%5B%5D=1&root%5B%5D%5B%5D%5B%5D=2&root%5B%5D%5B%5D%5B%5D=3" @@ -392,7 +392,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = EncodableSuperclass() // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertQueryEqual(result.value, "two=2&one=one&three=1") @@ -404,7 +404,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = EncodableSubclass() // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then let expected = "four%5B%5D=1&four%5B%5D=2&four%5B%5D=3&two=2&five%5Ba%5D=a&five%5Bb%5D=b&three=1&one=one" @@ -417,7 +417,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ManuallyEncodableSubclass() // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then let expected = "five%5Ba%5D=a&five%5Bb%5D=b&four%5Bfour%5D=one&four%5Bfive%5D=2" @@ -430,7 +430,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = [1] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertFalse(result.isSuccess) @@ -442,7 +442,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = "string" // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertFalse(result.isSuccess) @@ -454,7 +454,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters: [String: String?] = ["string": nil] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertFalse(result.isSuccess) @@ -466,7 +466,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ["bool": true] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "bool=true") @@ -478,7 +478,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ["array": [1, 2]] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertQueryEqual(result.value, "array=1&array=2") @@ -490,7 +490,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ["spaces": "replace with spaces"] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "spaces=replace+with+spaces") @@ -504,7 +504,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ["allowed": "?/"] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "allowed=%3F%2F") @@ -518,7 +518,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { "numbers": "0123456789"] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertQueryEqual(result.value, @@ -533,7 +533,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ["reserved": "\(generalDelimiters)\(subDelimiters)"] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "reserved=%3A%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D") @@ -545,7 +545,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ["illegal": " \"#%<>[]\\^`{}|"] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "illegal=%20%22%23%25%3C%3E%5B%5D%5C%5E%60%7B%7D%7C") @@ -557,7 +557,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ["foo&bar": "baz&qux", "foobar": "bazqux"] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertQueryEqual(result.value, "foobar=bazqux&foo%26bar=baz%26qux") @@ -569,7 +569,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ["?foo?": "?bar?"] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "?foo?=?bar?") @@ -581,7 +581,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ["foo": "/bar/baz/qux"] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "foo=/bar/baz/qux") @@ -593,7 +593,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = [" foo ": " bar "] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "%20foo%20=%20bar%20") @@ -605,7 +605,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ["+foo+": "+bar+"] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "%2Bfoo%2B=%2Bbar%2B") @@ -617,7 +617,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ["percent%": "%25"] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then XCTAssertEqual(result.value, "percent%25=%2525") @@ -634,7 +634,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { ] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then let expectedParameterValues = [ @@ -653,7 +653,7 @@ final class URLEncodedFormEncoderTests: BaseTestCase { let parameters = ["chinese": String(repeating: "一二三四五六七八九十", count: repeatedCount)] // When - let result = Result { try encoder.encode(parameters) } + let result = AFResult { try encoder.encode(parameters) } // Then let escaped = String(repeating: "%E4%B8%80%E4%BA%8C%E4%B8%89%E5%9B%9B%E4%BA%94%E5%85%AD%E4%B8%83%E5%85%AB%E4%B9%9D%E5%8D%81", diff --git a/Tests/RequestInterceptorTests.swift b/Tests/RequestInterceptorTests.swift index ead3578dc..02fb9098d 100644 --- a/Tests/RequestInterceptorTests.swift +++ b/Tests/RequestInterceptorTests.swift @@ -89,7 +89,7 @@ final class AdapterTestCase: BaseTestCase { completion(.success(request)) } - var result: Result! + var result: AFResult! // When adapter.adapt(urlRequest, for: session) { result = $0 } @@ -131,7 +131,7 @@ final class AdapterTestCase: BaseTestCase { } } - var result: Result! + var result: AFResult! let completesExpectation = expectation(description: "adapter completes") @@ -183,7 +183,7 @@ final class RetrierTestCase: BaseTestCase { completion(.retry) } - var result: Result! + var result: AFResult! // When retrier.adapt(urlRequest, for: session) { result = $0 } @@ -272,7 +272,7 @@ final class InterceptorTestCase: BaseTestCase { let session = Session() let interceptor = Interceptor() - var result: Result! + var result: AFResult! // When interceptor.adapt(urlRequest, for: session) { result = $0 } @@ -290,7 +290,7 @@ final class InterceptorTestCase: BaseTestCase { let adapter = Adapter { urlRequest, _, completion in completion(.failure(MockError())) } let interceptor = Interceptor(adapters: [adapter]) - var result: Result! + var result: AFResult! // When interceptor.adapt(urlRequest, for: session) { result = $0 } @@ -309,7 +309,7 @@ final class InterceptorTestCase: BaseTestCase { let adapter2 = Adapter { urlRequest, _, completion in completion(.failure(MockError())) } let interceptor = Interceptor(adapters: [adapter1, adapter2]) - var result: Result! + var result: AFResult! // When interceptor.adapt(urlRequest, for: session) { result = $0 } @@ -331,7 +331,7 @@ final class InterceptorTestCase: BaseTestCase { } let interceptor = Interceptor(adapters: [adapter]) - var result: Result! + var result: AFResult! let completesExpectation = expectation(description: "interceptor completes") diff --git a/Tests/RequestTests.swift b/Tests/RequestTests.swift index e6d8b2742..eb839ad23 100644 --- a/Tests/RequestTests.swift +++ b/Tests/RequestTests.swift @@ -22,7 +22,7 @@ // THE SOFTWARE. // -import Alamofire +@testable import Alamofire import Foundation import XCTest diff --git a/Tests/ResponseSerializationTests.swift b/Tests/ResponseSerializationTests.swift index be52eec11..214d3de36 100644 --- a/Tests/ResponseSerializationTests.swift +++ b/Tests/ResponseSerializationTests.swift @@ -22,7 +22,7 @@ // THE SOFTWARE. // -import Alamofire +@testable import Alamofire import Foundation import XCTest @@ -40,7 +40,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let data = Data("data".utf8) // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: data, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: data, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -53,7 +53,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let serializer = DataResponseSerializer() // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: nil, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: nil, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -72,7 +72,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let serializer = DataResponseSerializer() // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: nil, error: error) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: nil, error: error) } // Then XCTAssertTrue(result.isFailure) @@ -92,7 +92,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let response = HTTPURLResponse(statusCode: 200) // When - let result = Result { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } // Then XCTAssertTrue(result.isFailure, "result is failure should be true") @@ -112,7 +112,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let response = HTTPURLResponse(statusCode: 204) // When - let result = Result { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -131,7 +131,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let serializer = DataResponseSerializer() // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: nil, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: nil, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -150,7 +150,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let serializer = StringResponseSerializer() // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: Data(), error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: Data(), error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -169,7 +169,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let data = Data("data".utf8) // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: data, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: data, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -182,7 +182,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let data = Data("data".utf8) // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: data, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: data, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -196,7 +196,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let response = HTTPURLResponse(statusCode: 200, headers: ["Content-Type": "image/jpeg; charset=utf-8"]) // When - let result = Result { try serializer.serialize(request: nil, response: response, data: data, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: response, data: data, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -210,7 +210,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let data = "random data".data(using: .utf32)! // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: data, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: data, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -232,7 +232,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let response = HTTPURLResponse(statusCode: 200, headers: ["Content-Type": "image/jpeg; charset=utf-8"]) // When - let result = Result { try serializer.serialize(request: nil, response: response, data: data, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: response, data: data, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -252,7 +252,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let serializer = StringResponseSerializer() // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: nil, error: error) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: nil, error: error) } // Then XCTAssertTrue(result.isFailure) @@ -272,7 +272,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let response = HTTPURLResponse(statusCode: 200) // When - let result = Result { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -292,7 +292,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let response = HTTPURLResponse(statusCode: 205) // When - let result = Result { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -311,7 +311,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let serializer = JSONResponseSerializer() // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: nil, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: nil, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -330,7 +330,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let serializer = JSONResponseSerializer() // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: Data(), error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: Data(), error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -350,7 +350,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let data = Data("{\"json\": true}".utf8) // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: data, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: data, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -364,7 +364,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let data = Data("definitely not valid json".utf8) // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: data, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: data, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -384,7 +384,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let serializer = JSONResponseSerializer() // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: nil, error: error) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: nil, error: error) } // Then XCTAssertTrue(result.isFailure) @@ -404,7 +404,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let response = HTTPURLResponse(statusCode: 200) // When - let result = Result { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -424,7 +424,7 @@ final class DataResponseSerializationTestCase: BaseTestCase { let response = HTTPURLResponse(statusCode: 204) // When - let result = Result { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -464,7 +464,7 @@ final class DecodableResponseSerializerTests: BaseTestCase { let serializer = DecodableResponseSerializer() // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: nil, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: nil, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -483,7 +483,7 @@ final class DecodableResponseSerializerTests: BaseTestCase { let serializer = DecodableResponseSerializer() // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: Data(), error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: Data(), error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -503,7 +503,7 @@ final class DecodableResponseSerializerTests: BaseTestCase { let serializer = DecodableResponseSerializer() // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: data, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: data, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -518,7 +518,7 @@ final class DecodableResponseSerializerTests: BaseTestCase { let data = Data("definitely not valid".utf8) // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: data, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: data, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -531,7 +531,7 @@ final class DecodableResponseSerializerTests: BaseTestCase { let serializer = DecodableResponseSerializer() // When - let result = Result { try serializer.serialize(request: nil, response: nil, data: nil, error: error) } + let result = AFResult { try serializer.serialize(request: nil, response: nil, data: nil, error: error) } // Then XCTAssertTrue(result.isFailure) @@ -551,7 +551,7 @@ final class DecodableResponseSerializerTests: BaseTestCase { let response = HTTPURLResponse(statusCode: 200) // When - let result = Result { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -571,7 +571,7 @@ final class DecodableResponseSerializerTests: BaseTestCase { let response = HTTPURLResponse(statusCode: 204) // When - let result = Result { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -585,7 +585,7 @@ final class DecodableResponseSerializerTests: BaseTestCase { let response = HTTPURLResponse(statusCode: 204) // When - let result = Result { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -599,7 +599,7 @@ final class DecodableResponseSerializerTests: BaseTestCase { let response = HTTPURLResponse(statusCode: 204) // When - let result = Result { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -613,7 +613,7 @@ final class DecodableResponseSerializerTests: BaseTestCase { let response = HTTPURLResponse(statusCode: 204) // When - let result = Result { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } + let result = AFResult { try serializer.serialize(request: nil, response: response, data: nil, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -657,7 +657,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = DataResponseSerializer() // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: jsonValidDataFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: jsonValidDataFileURL, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -670,7 +670,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = DataResponseSerializer() // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: jsonEmptyDataFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: jsonEmptyDataFileURL, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -689,7 +689,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = DataResponseSerializer() // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: nil, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: nil, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -708,7 +708,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = DataResponseSerializer() // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: invalidFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: invalidFileURL, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -727,7 +727,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = DataResponseSerializer() // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: nil, error: error) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: nil, error: error) } // Then XCTAssertTrue(result.isFailure) @@ -747,7 +747,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let response = HTTPURLResponse(statusCode: 200) // When - let result = Result { try serializer.serializeDownload(request: nil, response: response, fileURL: nil, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: response, fileURL: nil, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -767,7 +767,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let response = HTTPURLResponse(statusCode: 205) // When - let result = Result { try serializer.serializeDownload(request: nil, response: response, fileURL: jsonEmptyDataFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: response, fileURL: jsonEmptyDataFileURL, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -788,7 +788,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = StringResponseSerializer() // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: nil, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: nil, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -808,7 +808,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = StringResponseSerializer() // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: invalidFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: invalidFileURL, error: nil) } // Then XCTAssertEqual(result.isSuccess, false) @@ -827,7 +827,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = StringResponseSerializer() // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: stringEmptyDataFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: stringEmptyDataFileURL, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -846,7 +846,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = StringResponseSerializer() // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: stringUTF8DataFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: stringUTF8DataFileURL, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -859,7 +859,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = StringResponseSerializer(encoding: .utf8) // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: stringUTF8DataFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: stringUTF8DataFileURL, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -873,7 +873,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let response = HTTPURLResponse(statusCode: 200, headers: ["Content-Type": "image/jpeg; charset=utf-8"]) // When - let result = Result { try serializer.serializeDownload(request: nil, response: response, fileURL: stringUTF8DataFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: response, fileURL: stringUTF8DataFileURL, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -886,7 +886,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = StringResponseSerializer(encoding: .utf8) // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: stringUTF32DataFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: stringUTF32DataFileURL, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -907,7 +907,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let response = HTTPURLResponse(statusCode: 200, headers: ["Content-Type": "image/jpeg; charset=utf-8"]) // When - let result = Result { try serializer.serializeDownload(request: nil, response: response, fileURL: stringUTF32DataFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: response, fileURL: stringUTF32DataFileURL, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -927,7 +927,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = StringResponseSerializer() // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: nil, error: error) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: nil, error: error) } // Then XCTAssertTrue(result.isFailure) @@ -947,7 +947,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let response = HTTPURLResponse(statusCode: 200) // When - let result = Result { try serializer.serializeDownload(request: nil, response: response, fileURL: nil, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: response, fileURL: nil, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -967,7 +967,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let response = HTTPURLResponse(statusCode: 204) // When - let result = Result { try serializer.serializeDownload(request: nil, response: response, fileURL: stringEmptyDataFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: response, fileURL: stringEmptyDataFileURL, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -986,7 +986,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = JSONResponseSerializer() // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: nil, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: nil, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -1005,7 +1005,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = JSONResponseSerializer() // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: invalidFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: invalidFileURL, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -1024,7 +1024,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = JSONResponseSerializer() // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: jsonEmptyDataFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: jsonEmptyDataFileURL, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -1043,7 +1043,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = JSONResponseSerializer() // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: jsonValidDataFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: jsonValidDataFileURL, error: nil) } // Then XCTAssertTrue(result.isSuccess) @@ -1056,7 +1056,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = JSONResponseSerializer() // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: jsonInvalidDataFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: jsonInvalidDataFileURL, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -1076,7 +1076,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let serializer = JSONResponseSerializer() // When - let result = Result { try serializer.serializeDownload(request: nil, response: nil, fileURL: nil, error: error) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: nil, fileURL: nil, error: error) } // Then XCTAssertTrue(result.isFailure) @@ -1096,7 +1096,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let response = HTTPURLResponse(statusCode: 200) // When - let result = Result { try serializer.serializeDownload(request: nil, response: response, fileURL: nil, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: response, fileURL: nil, error: nil) } // Then XCTAssertTrue(result.isFailure) @@ -1116,7 +1116,7 @@ final class DownloadResponseSerializationTestCase: BaseTestCase { let response = HTTPURLResponse(statusCode: 205) // When - let result = Result { try serializer.serializeDownload(request: nil, response: response, fileURL: jsonEmptyDataFileURL, error: nil) } + let result = AFResult { try serializer.serializeDownload(request: nil, response: response, fileURL: jsonEmptyDataFileURL, error: nil) } // Then XCTAssertTrue(result.isSuccess) diff --git a/Tests/ResponseTests.swift b/Tests/ResponseTests.swift index f628383ce..3684ef441 100644 --- a/Tests/ResponseTests.swift +++ b/Tests/ResponseTests.swift @@ -22,7 +22,7 @@ // THE SOFTWARE. // -import Alamofire +@testable import Alamofire import Foundation import XCTest diff --git a/Tests/ServerTrustEvaluatorTests.swift b/Tests/ServerTrustEvaluatorTests.swift index ff2a57d58..42603c595 100644 --- a/Tests/ServerTrustEvaluatorTests.swift +++ b/Tests/ServerTrustEvaluatorTests.swift @@ -22,7 +22,7 @@ // THE SOFTWARE. // -import Alamofire +@testable import Alamofire import Foundation import XCTest @@ -386,7 +386,7 @@ class ServerTrustPolicyPerformDefaultEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -402,7 +402,7 @@ class ServerTrustPolicyPerformDefaultEvaluationTestCase: ServerTrustPolicyTestCa let serverTrustPolicy = DefaultTrustEvaluator(validateHost: false) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -416,7 +416,7 @@ class ServerTrustPolicyPerformDefaultEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -430,7 +430,7 @@ class ServerTrustPolicyPerformDefaultEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -444,7 +444,7 @@ class ServerTrustPolicyPerformDefaultEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -460,7 +460,7 @@ class ServerTrustPolicyPerformDefaultEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -476,7 +476,7 @@ class ServerTrustPolicyPerformDefaultEvaluationTestCase: ServerTrustPolicyTestCa let serverTrustPolicy = DefaultTrustEvaluator(validateHost: true) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -490,7 +490,7 @@ class ServerTrustPolicyPerformDefaultEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -504,7 +504,7 @@ class ServerTrustPolicyPerformDefaultEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -518,7 +518,7 @@ class ServerTrustPolicyPerformDefaultEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -532,7 +532,7 @@ class ServerTrustPolicyPerformDefaultEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -556,7 +556,7 @@ class ServerTrustPolicyPerformRevokedEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -572,7 +572,7 @@ class ServerTrustPolicyPerformRevokedEvaluationTestCase: ServerTrustPolicyTestCa let serverTrustPolicy = RevocationTrustEvaluator(validateHost: false) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -586,7 +586,7 @@ class ServerTrustPolicyPerformRevokedEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -600,7 +600,7 @@ class ServerTrustPolicyPerformRevokedEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -614,7 +614,7 @@ class ServerTrustPolicyPerformRevokedEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -630,7 +630,7 @@ class ServerTrustPolicyPerformRevokedEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -646,7 +646,7 @@ class ServerTrustPolicyPerformRevokedEvaluationTestCase: ServerTrustPolicyTestCa let serverTrustPolicy = RevocationTrustEvaluator() // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -660,7 +660,7 @@ class ServerTrustPolicyPerformRevokedEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -674,7 +674,7 @@ class ServerTrustPolicyPerformRevokedEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -688,7 +688,7 @@ class ServerTrustPolicyPerformRevokedEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -702,7 +702,7 @@ class ServerTrustPolicyPerformRevokedEvaluationTestCase: ServerTrustPolicyTestCa // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -725,7 +725,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { validateHost: false) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -741,7 +741,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { validateHost: false) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -757,7 +757,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { validateHost: false) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -775,7 +775,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { ) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -789,7 +789,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { let serverTrustPolicy = PinnedCertificatesTrustEvaluator(certificates: certificates, validateHost: false) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -803,7 +803,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { let serverTrustPolicy = PinnedCertificatesTrustEvaluator(certificates: certificates, validateHost: false) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -817,7 +817,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { let serverTrustPolicy = PinnedCertificatesTrustEvaluator(certificates: certificates, validateHost: false) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -833,7 +833,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { let serverTrustPolicy = PinnedCertificatesTrustEvaluator(certificates: certificates, acceptSelfSignedCertificates: true) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -847,7 +847,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { let serverTrustPolicy = PinnedCertificatesTrustEvaluator(certificates: certificates, acceptSelfSignedCertificates: true) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -861,7 +861,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { let serverTrustPolicy = PinnedCertificatesTrustEvaluator(certificates: certificates, acceptSelfSignedCertificates: true) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -879,7 +879,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { ) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -893,7 +893,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { let serverTrustPolicy = PinnedCertificatesTrustEvaluator(certificates: certificates) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -907,7 +907,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { let serverTrustPolicy = PinnedCertificatesTrustEvaluator(certificates: certificates) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -921,7 +921,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { let serverTrustPolicy = PinnedCertificatesTrustEvaluator(certificates: certificates) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -941,7 +941,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { ) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -959,7 +959,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { ) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -977,7 +977,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { ) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -995,7 +995,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { ) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -1013,7 +1013,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { ) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -1031,7 +1031,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { ) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1049,7 +1049,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { ) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1067,7 +1067,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { ) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1093,7 +1093,7 @@ class ServerTrustPolicyPinCertificatesTestCase: ServerTrustPolicyTestCase { ) // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1115,7 +1115,7 @@ class ServerTrustPolicyPinPublicKeysTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1130,7 +1130,7 @@ class ServerTrustPolicyPinPublicKeysTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1145,7 +1145,7 @@ class ServerTrustPolicyPinPublicKeysTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1160,7 +1160,7 @@ class ServerTrustPolicyPinPublicKeysTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -1175,7 +1175,7 @@ class ServerTrustPolicyPinPublicKeysTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1192,7 +1192,7 @@ class ServerTrustPolicyPinPublicKeysTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1207,7 +1207,7 @@ class ServerTrustPolicyPinPublicKeysTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1222,7 +1222,7 @@ class ServerTrustPolicyPinPublicKeysTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1237,7 +1237,7 @@ class ServerTrustPolicyPinPublicKeysTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -1252,7 +1252,7 @@ class ServerTrustPolicyPinPublicKeysTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1271,7 +1271,7 @@ class ServerTrustPolicyPinPublicKeysTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1288,7 +1288,7 @@ class ServerTrustPolicyPinPublicKeysTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -1305,7 +1305,7 @@ class ServerTrustPolicyPinPublicKeysTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1322,7 +1322,7 @@ class ServerTrustPolicyPinPublicKeysTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1339,7 +1339,7 @@ class ServerTrustPolicyPinPublicKeysTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1356,7 +1356,7 @@ class ServerTrustPolicyPinPublicKeysTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1373,7 +1373,7 @@ class ServerTrustPolicyDisableEvaluationTestCase: ServerTrustPolicyTestCase { let serverTrustPolicy = DisabledEvaluator() // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1386,7 +1386,7 @@ class ServerTrustPolicyDisableEvaluationTestCase: ServerTrustPolicyTestCase { let serverTrustPolicy = DisabledEvaluator() // When - let result = Result { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try serverTrustPolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1406,7 +1406,7 @@ class ServerTrustPolicyCompositeTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try compositePolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try compositePolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertTrue(result.isSuccess, "server trust should pass evaluation") @@ -1424,7 +1424,7 @@ class ServerTrustPolicyCompositeTestCase: ServerTrustPolicyTestCase { let compositePolicy = CompositeTrustEvaluator(evaluators: [defaultPolicy, revocationPolicy]) // When - let result = Result { try compositePolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try compositePolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") @@ -1440,7 +1440,7 @@ class ServerTrustPolicyCompositeTestCase: ServerTrustPolicyTestCase { // When setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust) - let result = Result { try compositePolicy.evaluate(serverTrust, forHost: host) } + let result = AFResult { try compositePolicy.evaluate(serverTrust, forHost: host) } // Then XCTAssertFalse(result.isSuccess, "server trust should not pass evaluation") diff --git a/Tests/SessionTests.swift b/Tests/SessionTests.swift index 81c5dd187..a5f7cc2d5 100644 --- a/Tests/SessionTests.swift +++ b/Tests/SessionTests.swift @@ -41,10 +41,10 @@ class SessionTestCase: BaseTestCase { self.throwsError = throwsError } - func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result) -> Void) { + func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (AFResult) -> Void) { adaptedCount += 1 - let result: Result = Result { + let result: AFResult = AFResult { guard !throwsError else { throw AFError.invalidURL(url: "") } var urlRequest = urlRequest @@ -68,10 +68,10 @@ class SessionTestCase: BaseTestCase { self.throwsError = throwsError } - func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result) -> Void) { + func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (AFResult) -> Void) { adaptedCount += 1 - let result: Result = Result { + let result: AFResult = AFResult { guard !throwsError else { throw AFError.invalidURL(url: "") } var urlRequest = urlRequest @@ -102,10 +102,10 @@ class SessionTestCase: BaseTestCase { var shouldRetry = true var retryDelay: TimeInterval? - func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result) -> Void) { + func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (AFResult) -> Void) { adaptCalledCount += 1 - let result: Result = Result { + let result: AFResult = AFResult { if throwsErrorOnFirstAdapt { throwsErrorOnFirstAdapt = false throw AFError.invalidURL(url: "/adapt/error/1") @@ -168,10 +168,10 @@ class SessionTestCase: BaseTestCase { var retryCount = 0 var retryErrors: [Error] = [] - func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result) -> Void) { + func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (AFResult) -> Void) { adaptCalledCount += 1 - let result: Result = Result { + let result: AFResult = AFResult { adaptedCount += 1 if adaptedCount == 1 { throw AFError.invalidURL(url: "") } diff --git a/Tests/UploadTests.swift b/Tests/UploadTests.swift index 4cd3e2f2d..fc91f989d 100644 --- a/Tests/UploadTests.swift +++ b/Tests/UploadTests.swift @@ -22,7 +22,7 @@ // THE SOFTWARE. // -import Alamofire +@testable import Alamofire import Foundation import XCTest