Repository: Alamofire/Alamofire
File: Tests/UploadTests.swift (Swift)

Code before:
            let contentType = request.value(forHTTPHeaderField: "Content-Type") {
            XCTAssertEqual(contentType, multipartFormData.contentType, "Content-Type header value should match")
        } else {
            XCTFail("Content-Type header value should not be nil")
        }
    }
    
    func testThatUploadingMultipartFormDataWithNotExistFileShouldFail() {
        // Given
        let urlString = "https://httpbin.org/post"
        let imageURL = URL(string: "file://not_exists_file.jpg")!

        let expectation = self.expectation(description: "multipart form data upload with wrong file should fail")
        var response: DataResponse<Data?, AFError>?

        // When
        let request = AF.upload(multipartFormData: { multipartFormData in
            multipartFormData.append(imageURL, withName: "upload_file")
        },
                                to: urlString,
                                usingThreshold: 0).response { resp in
            response = resp
            expectation.fulfill()
        }

        waitForExpectations(timeout: timeout, handler: nil)

        // Then
        let uploadable = request.uploadable
        XCTAssertNil(uploadable)
        XCTAssertTrue(response?.result.isSuccess == false)
    }

    #if os(macOS)
    func disabled_testThatUploadingMultipartFormDataOnBackgroundSessionWritesDataToFileToAvoidCrash() {
        // Given
        let manager: Session = {
            let identifier = "org.alamofire.uploadtests.\(UUID().uuidString)"
            let configuration = URLSessionConfiguration.background(withIdentifier: identifier)

            return Session(configuration: configuration)
        }()

        let urlString = "https://httpbin.org/post"
        let french = Data("français".utf8)
        let japanese = Data("日本語".utf8)

        let expectation = self.expectation(description: "multipart form data upload should succeed")

        var request: URLRequest?
        var response: HTTPURLResponse?

Review comment (suggestion):
```suggestion
        waitForExpectations(timeout: timeout)
```

`handler` is unnecessary when `nil`.

Code after:
            let contentType = request.value(forHTTPHeaderField: "Content-Type") {
            XCTAssertEqual(contentType, multipartFormData.contentType, "Content-Type header value should match")
        } else {
            XCTFail("Content-Type header value should not be nil")
        }
    }

    func testThatUploadingMultipartFormDataWithNonexistentFileThrowsAnError() {
        // Given
        let urlString = URL.makeHTTPBinURL(path: "post")
        let imageURL = URL(fileURLWithPath: "does_not_exist.jpg")

        let expectation = self.expectation(description: "multipart form data upload from nonexistent file should fail")
        var response: DataResponse<Data?, AFError>?

        // When
        let request = AF.upload(multipartFormData: { multipartFormData in
                                    multipartFormData.append(imageURL, withName: "upload_file")
                                },
                                to: urlString,
                                usingThreshold: 0).response { resp in
            response = resp
            expectation.fulfill()
        }

        waitForExpectations(timeout: timeout)

        // Then
        XCTAssertNil(request.uploadable)
        XCTAssertTrue(response?.result.isSuccess == false)
    }

    #if os(macOS)
    func disabled_testThatUploadingMultipartFormDataOnBackgroundSessionWritesDataToFileToAvoidCrash() {
        // Given
        let manager: Session = {
            let identifier = "org.alamofire.uploadtests.\(UUID().uuidString)"
            let configuration = URLSessionConfiguration.background(withIdentifier: identifier)

            return Session(configuration: configuration)
        }()

        let urlString = "https://httpbin.org/post"
        let french = Data("français".utf8)
        let japanese = Data("日本語".utf8)

        let expectation = self.expectation(description: "multipart form data upload should succeed")

        var request: URLRequest?
        var response: HTTPURLResponse?
        var data: Data?