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

Code before:
            adapted = true
            completion(.success(request))
        }

        var result: Result<URLRequest, Error>!

        // When
        adapter.adapt(urlRequest, for: session) { result = $0 }

        // Then
        XCTAssertTrue(adapted)
        XCTAssertTrue(result.isSuccess)
    }

    func testThatAdapterCallsAdaptHandlerWithStateAPI() {
        // Given
        let urlRequest = Endpoint().urlRequest
        let session = Session()
        var adapted = false

        let adapter = Adapter { request, _, completion in
            adapted = true
            completion(.success(request))
        }

        let state = RequestAdapterState(requestID: UUID(), session: session)

        var result: Result<URLRequest, Error>!

        // When
        adapter.adapt(urlRequest, using: state) { result = $0 }

        // Then
        XCTAssertTrue(adapted)
        XCTAssertTrue(result.isSuccess)
    }

    func testThatAdapterCallsRequestRetrierDefaultImplementationInProtocolExtension() {
        // Given
        let session = Session(startRequestsImmediately: false)
        let request = session.request(.default)

        let adapter = Adapter { request, _, completion in
            completion(.success(request))
        }

        var result: RetryResult!

        // When
        adapter.retry(request, for: session, dueTo: MockError()) { result = $0 }


Review comment (suggestion):
I would suggest capturing the `UUID` separately and then comparing the values returned from the adaptation to those provided in the `RequestAdapterState`, just to ensure they're round tripping appropriately.

Code after:
            adapted = true
            completion(.success(request))
        }

        var result: Result<URLRequest, Error>!

        // When
        adapter.adapt(urlRequest, for: session) { result = $0 }

        // Then
        XCTAssertTrue(adapted)
        XCTAssertTrue(result.isSuccess)
    }

    func testThatAdapterCallsAdaptHandlerWithStateAPI() {
        // Given
        class StateCaptureAdapter: Adapter {
            private(set) var urlRequest: URLRequest?
            private(set) var state: RequestAdapterState?

            override func adapt(_ urlRequest: URLRequest,
                                using state: RequestAdapterState,
                                completion: @escaping (Result<URLRequest, Error>) -> Void) {
                self.urlRequest = urlRequest
                self.state = state

                super.adapt(urlRequest, using: state, completion: completion)
            }
        }

        let urlRequest = Endpoint().urlRequest
        let session = Session()
        let requestID = UUID()

        var adapted = false

        let adapter = StateCaptureAdapter { urlRequest, _, completion in
            adapted = true
            completion(.success(urlRequest))
        }

        let state = RequestAdapterState(requestID: requestID, session: session)

        var result: Result<URLRequest, Error>!

        // When
        adapter.adapt(urlRequest, using: state) { result = $0 }

        // Then
        XCTAssertTrue(adapted)
        XCTAssertTrue(result.isSuccess)