         let result = waiter.wait(for: [expectation], timeout: 1)
         XCTAssertEqual(result, .completed)
     }
+    
+    func testExchangeRefreshToken_serverError() {
+        let waiter = XCTWaiter()
+        let expectation = self.expectation(description: "expects refreshed access token")
+        
+        let session = FakeURLSession { request in
+            let response = HTTPURLResponse(url: request.url!, statusCode: 500, httpVersion: nil, headerFields: nil)
+            return (nil, response, nil)
+        }
+        
+        let trakt = Trakt(credentials: credentials, session: session)
+        
+        let expiry = Date().addingTimeInterval(3600)
+        trakt.update(accessToken: "accessToken", refreshToken: "refreshToken", expiry: expiry)
+        
+        let task = trakt.exchangeRefreshToken { result in
+            if result.error != nil {
+                expectation.fulfill()
+            }
+        }
+        XCTAssertNotNil(task)
+        
+        let request = session.completedRequests.first!
+        XCTAssertEqual(request.url!, URL(string: "https://api.trakt.tv/oauth/token"))
+        XCTAssertEqual(request.httpMethod, "POST")
+        
+        let result = waiter.wait(for: [expectation], timeout: 1)
+        XCTAssertEqual(result, .completed)
+    }
 }

    
    func testExchangeAccessToken_failureEmptyJSON() {
        let waiter = XCTWaiter()
        let errorExpectation = expectation(description: "error expected")
        
        let session = FakeURLSession { request in
            let data = buildData(with: [:])
            let response = HTTPURLResponse(url: request.url!, statusCode: 200, httpVersion: nil, headerFields: nil)
            return (data, response, nil)
        }

    
    func testExchangeAccessToken_success() {
        let waiter = XCTWaiter()
        let tokenExpectation = expectation(description: "expects auth token")
        
        let session = FakeURLSession { request in
            let data = buildData(with: [ "refresh_token": "refreshNew", "expires_in": 3600, "access_token": "accessNew" ])
