io.github.autsia.crowly.tests.SentimentTests.java Source code

Java tutorial

Introduction

Here is the source code for io.github.autsia.crowly.tests.SentimentTests.java

Source

/*
 * Copyright 2014 Dmytro Titov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.github.autsia.crowly.tests;

import io.github.autsia.crowly.config.TestConfig;
import io.github.autsia.crowly.services.sentiment.Sentiment;
import io.github.autsia.crowly.services.sentiment.impl.CrowlySentimentAnalyzer;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

/**
 * Created by Dmytro on 29.01.14 at 21:13
 * Project: crowly
 */
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = TestConfig.class)
@ActiveProfiles("test")
public class SentimentTests {

    protected CrowlySentimentAnalyzer crowlySentimentAnalyzer;

    @Test
    public void analyzePositive() throws Exception {
        Pair<Sentiment, Float> opinion = crowlySentimentAnalyzer.analyze("This movie is great.");
        Assert.assertEquals(Sentiment.POSITIVE, opinion.getLeft());
    }

    @Test
    public void analyzeNeutral() throws Exception {
        Pair<Sentiment, Float> opinion = crowlySentimentAnalyzer.analyze("This movie contains of three parts.");
        Assert.assertEquals(Sentiment.NEUTRAL, opinion.getLeft());
    }

    @Test
    public void analyzeNegative() throws Exception {
        Pair<Sentiment, Float> opinion = crowlySentimentAnalyzer.analyze("This movie is horrible.");
        Assert.assertEquals(Sentiment.NEGATIVE, opinion.getLeft());
    }

    @Autowired
    public void setCrowlySentimentAnalyzer(CrowlySentimentAnalyzer crowlySentimentAnalyzer) {
        this.crowlySentimentAnalyzer = crowlySentimentAnalyzer;
    }
}