             url: nil,
             text: test_get_text_sentiment_invalid) {
                 
-                (error, sentiment) in
-                
-                let language = sentiment.language
-                
-                XCTAssertEqual(language, "unknown")
-                XCTAssertNil(sentiment.docSentiment)
+                (error, sentimentResponse) in
+                
+                XCTAssertNotNil(sentimentResponse.language)
+                
+                if let language = sentimentResponse.language {
+                    
+                    XCTAssertEqual(language, "unknown")
+                XCTAssertNil(sentimentResponse.docSentiment)
+                    
+                }
                 
                 invalidExpectation.fulfill()
                 

            url: "http://en.wikipedia.org/wiki/Vladimir_Putin",
            text: nil) {
                
                (error, sentiment) in
                
                XCTAssertNotNil(sentiment.docSentiment)
                
                if let docSentiment = sentiment.docSentiment {
                    
                    let sentimentMixed = docSentiment.mixed
                    let sentimentType = docSentiment.type
                    
                    XCTAssertEqual(sentimentMixed, "1")
                    XCTAssertEqual(sentimentType, "negative")
                    
                    validExpectation.fulfill()
                    
                }
                
        }

    
    func testInvalidHTMLGetTargetedSentiment() {
        
        let invalidExpectation = expectationWithDescription("invalid")
        
        let html = htmlDocumentFromURLString("http://www.sentimentAnalysisDotComShouldNotExist.com")
        
        var parameters = AlchemyLanguage.GetSentimentParameters()
        
        parameters.targets = "Putin"
        
        instance.getSentiment(requestType: .HTML,
            html: html,
            url: nil,
            text: nil,
            sentimentType: AlchemyLanguageConstants.SentimentType.Targeted,
            sentimentParameters: parameters) {
                
                (error, sentimentResponse) in
                
                let language = sentimentResponse.language
                
                XCTAssertEqual(language, "unknown")
                XCTAssertNil(sentimentResponse.docSentiment)
                
                invalidExpectation.fulfill()
                
        }
        
        waitForExpectationsWithTimeout(timeout, handler: { error in XCTAssertNil(error, "Timeout") })
        
    }
    
    func testURLGetTargetedSentiment() {
        
        let validExpectation = expectationWithDescription("valid")
        
        var parameters = AlchemyLanguage.GetSentimentParameters()
        
        parameters.targets = "Putin"
        
        instance.getSentiment(requestType: .URL,
            html: nil,
            url: "http://en.wikipedia.org/wiki/Vladimir_Putin",
            text: nil,
            sentimentType: AlchemyLanguageConstants.SentimentType.Targeted,
            sentimentParameters: parameters) {
                
                (error, sentimentResponse) in
                
                XCTAssertNotNil(sentimentResponse.sentimentResults?.first)
                
                if let sentimentResults = sentimentResponse.sentimentResults,
                    let first = sentimentResults.first,
                    let sentiment = first.sentiment {
                        
                        let sentimentMixed = sentiment.mixed
                        let sentimentScore = sentiment.score
                        let sentimentType = sentiment.type
                        
                        XCTAssertNotNil(sentimentMixed)
                        XCTAssertNotNil(sentimentScore)
                        
                        if let sentimentMixed = sentimentMixed {
                            
                            XCTAssertEqual(sentimentMixed, 1)
                            
                        }
                        
                        XCTAssertEqual(sentimentType, "negative")
                        
                        validExpectation.fulfill()
                        
                }
                
        }
        
        waitForExpectationsWithTimeout(timeout, handler: { error in XCTAssertNil(error, "Timeout") })
        
    }
    
    func testInvalidURLGetTargetedSentiment() {
        
        let invalidExpectation = expectationWithDescription("invalid")
        
        var parameters = AlchemyLanguage.GetSentimentParameters()
        
        parameters.targets = "Putin"
        
        instance.getSentiment(requestType: .URL,
            html: nil,
            url: "http://www.sentimentAnalysisDotComShouldNotExist.com",
            text: nil,
            sentimentType: AlchemyLanguageConstants.SentimentType.Targeted,
            sentimentParameters: parameters) {
                
                (error, sentimentResponse) in
                
                let language = sentimentResponse.language
                
                XCTAssertEqual(language, "unknown")
                XCTAssertNil(sentimentResponse.docSentiment)
                
                invalidExpectation.fulfill()
                
        }
        
        waitForExpectationsWithTimeout(timeout, handler: { error in XCTAssertNil(error, "Timeout") })
        
    }
    
    func testTextGetTargetedSentiment() {
        
        let validExpectation = expectationWithDescription("valid")
        
        var parameters = AlchemyLanguage.GetSentimentParameters()
        
        parameters.targets = "Putin"
        
        instance.getSentiment(requestType: .Text,
            html: nil,
            url: nil,
            text: test_get_entities_text_valid,
            sentimentType: AlchemyLanguageConstants.SentimentType.Targeted,
            sentimentParameters: parameters) {
                
                (error, sentimentResponse) in
                
                XCTAssertNotNil(sentimentResponse.sentimentResults?.first)
                
                if let sentimentResults = sentimentResponse.sentimentResults,
                    let first = sentimentResults.first,
                    let sentiment = first.sentiment {
                        
                        let sentimentMixed = sentiment.mixed
                        let sentimentScore = sentiment.score
                        let sentimentType = sentiment.type
                        
                        XCTAssertNotNil(sentimentScore)
                        
                        if let sentimentMixed = sentimentMixed {
                            
                            XCTAssertEqual(sentimentMixed, 1)
                            
                        }
                        
                        XCTAssertEqual(sentimentType, "negative")
                        
                        validExpectation.fulfill()
                        
                }
                
        }
        
        waitForExpectationsWithTimeout(timeout, handler: { error in XCTAssertNil(error, "Timeout") })
        
    }
    
    func testInvalidTextGetTargetedSentiment() {
        
        let invalidExpectation = expectationWithDescription("invalid")
        
        var parameters = AlchemyLanguage.GetSentimentParameters()
        
        parameters.targets = "Putin"
        
        instance.getSentiment(requestType: .Text,
            html: nil,
            url: nil,
            text: test_get_text_sentiment_invalid,
            sentimentType: AlchemyLanguageConstants.SentimentType.Targeted,
            sentimentParameters: parameters) {
                
                (error, sentimentResponse) in
                
                let language = sentimentResponse.language
                
                XCTAssertEqual(language, "unknown")
                XCTAssertNil(sentimentResponse.sentimentResults)
                
                invalidExpectation.fulfill()
                
        }
        
        waitForExpectationsWithTimeout(timeout, handler: { error in XCTAssertNil(error, "Timeout") })
        
    }
    
