 				expection.fulfill()
 		}
 		
-		waitForExpectationsWithTimeout(2, handler: nil)
+		waitForExpectations(timeout: 2, handler: nil)
 		
 	}
 	
 	func testReuseToken() {
 		
-		let expection = expectationWithDescription("All Done")
-		
-		let service = TeslaSwift()
-		service.useMockServer = true
-		
-		service.authenticate("user", password: "pass")
+		let expection = expectation(description: "All Done")
+		
+		let service = TeslaSwift()
+		service.useMockServer = true
+		
+		_ = service.authenticate("user", password: "pass")
 			.then {
 				(_) -> Void in
 				
 				service.checkToken().then { (response) -> Void in
 					
-					XCTAssertTrue(response.boolValue)
+					XCTAssertTrue(response)
 					expection.fulfill()
 					
-					}.error { (error) in
+					}.catch { (error) in
 						XCTFail("Token is not valid: \((error as NSError).description)")
 				}
 				
 		}
 		
-		waitForExpectationsWithTimeout(2, handler: nil)
+		waitForExpectations(timeout: 2, handler: nil)
 		
 	}
 	
 	func testGetVehicles() {
 		
-		let expection = expectationWithDescription("All Done")
-		
-		let service = TeslaSwift()
-		service.useMockServer = true
-		
-		service.authenticate("user", password: "pass")
+		let expection = expectation(description: "All Done")
+		
+		let service = TeslaSwift()
+		service.useMockServer = true
+		
+		_ = service.authenticate("user", password: "pass")
 			.then {
 				(_) -> Void in
 				service.getVehicles()

						
						expection.fulfill()
						
					}.error{ (error) in
						print(error)
						XCTFail((error as NSError).description)
				}
		}
		
		waitForExpectationsWithTimeout(2, handler: nil)
		
	}
	
	func testGetVehicleState() {
		
		let path = NSBundle(forClass: self.dynamicType).pathForResource("MobileAccess", ofType: "json")!
		let data = NSData(contentsOfFile: path)!
		stub(uri(Endpoint.MobileAccess(vehicleID: 1234567890).path), builder: jsonData(data))
		let path2 = NSBundle(forClass: self.dynamicType).pathForResource("ChargeState", ofType: "json")!
		let data2 = NSData(contentsOfFile: path2)!
		stub(uri(Endpoint.ChargeState(vehicleID: 1234567890).path), builder: jsonData(data2))
		let path3 = NSBundle(forClass: self.dynamicType).pathForResource("ClimateSettings", ofType: "json")!
		let data3 = NSData(contentsOfFile: path3)!
		stub(uri(Endpoint.ClimateState(vehicleID: 1234567890).path), builder: jsonData(data3))
		let path4 = NSBundle(forClass: self.dynamicType).pathForResource("DriveState", ofType: "json")!
		let data4 = NSData(contentsOfFile: path4)!
		stub(uri(Endpoint.DriveState(vehicleID: 1234567890).path), builder: jsonData(data4))
		let path5 = NSBundle(forClass: self.dynamicType).pathForResource("GuiSettings", ofType: "json")!
		let data5 = NSData(contentsOfFile: path5)!
		stub(uri(Endpoint.GuiSettings(vehicleID: 1234567890).path), builder: jsonData(data5))
		let path6 = NSBundle(forClass: self.dynamicType).pathForResource("VehicleState", ofType: "json")!
		let data6 = NSData(contentsOfFile: path6)!
		stub(uri(Endpoint.VehicleState(vehicleID: 1234567890).path), builder: jsonData(data6))
		
		let expection = expectationWithDescription("All Done")
		
		let service = TeslaSwift()
		service.useMockServer = true

				XCTAssertEqual(response.vehicleState?.darkRims, true)
				
				expection.fulfill()
			}.catch { (error) in
				print(error)
				XCTFail((error as NSError).description)
		}
		
		waitForExpectations(timeout: 2, handler: nil)
		
	}
	
	func testCommandWakeUp() {
		
		let stubPath = OHPathForFile("WakeUp.json", type(of: self))
		_ = stub(condition: isPath(Endpoint.command(vehicleID: 1234567890, command: .wakeUp).path)) {
			_ in
			return fixture(filePath: stubPath!, headers: self.headers)
		}
		
		let expection = expectation(description: "All Done")
		
		let service = TeslaSwift()
		service.useMockServer = true
		
		service.authenticate("user", password: "pass").then { (token) in
			service.getVehicles()
			}.then { (vehicles)  in
				service.sendCommandToVehicle(vehicles[0], command: .wakeUp)
			}.then { (response) -> Void in
				
				XCTAssertEqual(response.result, false)
				XCTAssertEqual(response.reason, "Test wakeup")
				
				expection.fulfill()
			}.catch { (error) in
				print(error)
				XCTFail((error as NSError).description)
		}
		
		waitForExpectations(timeout: 2, handler: nil)
	}
	
	func testCommandValetMode() {
		
		let options = ValetCommandOptions(valetActivated: true, pin: "1234")
		
		let stubPath = OHPathForFile("SetValetMode.json", type(of: self))
		_ = stub(condition: isPath(Endpoint.command(vehicleID: 1234567890, command: .valetMode(options: options)).path)) {
			_ in
			return fixture(filePath: stubPath!, headers: self.headers)
		}

		let expection = expectation(description: "All Done")
		
		let service = TeslaSwift()
		service.useMockServer = true
