SentimentAnalysis { public Sentiment sentimentOf(String sentence) { final Sentiment sentiment = analyze(sentence); if (audit != null) { audit.record(sentence, sentiment); } return sentiment; } SentimentAnalysis(Lexicon lexicon, Trend audit);  SentimentAnalysis(Map<String, Sentiment> dictionary, Trend audit);  SentimentAnalysis(Map<String, Sentiment> dictionary); Sentiment sentimentOf(String sentence);  }
@Test public void should_return_neutral_by_default() { final Map<String, Sentiment> dictionary = Collections.emptyMap(); final SentimentAnalysis sa = new SentimentAnalysis(dictionary); assertEquals(Sentiment.NEUTRAL, sa.sentimentOf("Whazzup!!!")); }
@Test public void should_recognize_sadness_when_the_word_sad_is_in_the_sentence() { final Map<String, Sentiment> dictionary = Collections.singletonMap("sad", Sentiment.SAD); final SentimentAnalysis sa = new SentimentAnalysis(dictionary); assertEquals(Sentiment.SAD, sa.sentimentOf("It's sad js rulz the web world")); }
@Test public void should_recognize_happiness_when_the_word_wifi_is_in_the_sentence() { final Map<String, Sentiment> dictionary = Collections.singletonMap("wifi", Sentiment.HAPPY); final SentimentAnalysis sa = new SentimentAnalysis(dictionary); assertEquals(Sentiment.HAPPY, sa.sentimentOf("There's free wifi here")); }
@Test public void should_recognize_whatever_the_case_of_the_sentence() { final Map<String, Sentiment> dictionary = Collections.singletonMap("wifi", Sentiment.HAPPY); final SentimentAnalysis sa = new SentimentAnalysis(dictionary); assertEquals(Sentiment.HAPPY, sa.sentimentOf("There's free WIFI here")); }
@Test public void should_recognize_negation_of_sentiment() { final Map<String, Sentiment> dictionary = Collections.singletonMap("wifi", Sentiment.HAPPY); final SentimentAnalysis sa = new SentimentAnalysis(dictionary); assertEquals(Sentiment.SAD, sa.sentimentOf("There's no WIFI")); }
@Test public void should_recognize_double_negation_of_sentiment() { final Map<String, Sentiment> dictionary = Collections.singletonMap("wifi", Sentiment.HAPPY); final SentimentAnalysis sa = new SentimentAnalysis(dictionary); assertEquals(Sentiment.HAPPY, sa.sentimentOf("It's not true there's no WIFI")); }
@Test public void should_pick_the_most_optimistic_in_case_of_conflict() { final Map<String, Sentiment> dictionary = new HashMap<String, Sentiment>(); dictionary.put("kitten", Sentiment.HAPPY); dictionary.put("drunk", Sentiment.SAD); final SentimentAnalysis sa = new SentimentAnalysis(dictionary); assertEquals(Sentiment.HAPPY, sa.sentimentOf("Oh, look! A drunk kitten")); }
@Test public void actual_failing_case() { final Map<String, Sentiment> dictionary = new HashMap<String, Sentiment>(); dictionary.put("devoxx", Sentiment.HAPPY); dictionary.put("spring", Sentiment.SAD); final SentimentAnalysis sa = new SentimentAnalysis(dictionary); assertEquals(Sentiment.SAD, sa.sentimentOf("@tpierrain #devoxx spring")); }