package ua.yandex.shad.autocomplete;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Matchers;
import org.mockito.Mock;

import org.mockito.runners.MockitoJUnitRunner;
import ua.yandex.shad.tries.Trie;
import ua.yandex.shad.tries.Tuple;

@RunWith(MockitoJUnitRunner.class)
public class PrefixMatchesTest {
    @Mock
    private Trie trie;

    @InjectMocks
    private PrefixMatches prefixMatches = new PrefixMatches();

    private Tuple first = new Tuple("one", 3);
    private Tuple second = new Tuple("apple", 5);

    @Test
    public void testLoad_noParameters_nothingAdded() {
        prefixMatches.load();

        verify(trie, never()).add(any(Tuple.class));
    }

    @Test
    public void testLoad_emptyString_nothingAdded() {
        String strings = "";

        prefixMatches.load(strings);

        verify(trie, never()).add(any(Tuple.class));
    }

    @Test
    public void testLoad_stringWithOneWord_wordAdded() {
        String strings = "one";

        prefixMatches.load(strings);

        verify(trie, times(1)).add(Matchers.eq(first));
        verify(trie).add(Matchers.eq(first));
    }

    @Test
    public void testLoad_stringWithTwoWordsSeparatedWithSpace_addedTwoWords() {
        String strings = "one apple";

        prefixMatches.load(strings);

        verify(trie, times(1)).add(Matchers.eq(first));
        verify(trie, times(1)).add(Matchers.eq(second));
        verify(trie, times(2)).add(any(Tuple.class));
        verify(trie).add(Matchers.eq(first));
        verify(trie).add(Matchers.eq(second));
    }

    @Test
    public void testLoad_stringWithTwoWordsSeparatedWithTab_addedTwoWords() {
        String strings = "one   apple";

        prefixMatches.load(strings);

        verify(trie, times(1)).add(Matchers.eq(first));
        verify(trie, times(1)).add(Matchers.eq(second));
        verify(trie, times(2)).add(any(Tuple.class));
        verify(trie).add(Matchers.eq(first));
    }

    @Test
    public void testLoad_twoStringsWithOneWordEach_addedTwoWords() {
        String[] strings = {"one", "apple"};

        prefixMatches.load(strings);

        verify(trie, times(1)).add(Matchers.eq(first));
        verify(trie, times(1)).add(Matchers.eq(second));
        verify(trie, times(2)).add(any(Tuple.class));
        verify(trie).add(Matchers.eq(first));
        verify(trie).add(Matchers.eq(second));
    }

    @Test
    public void testLoad_wordLengthIsLessThanTwoCharacters_nothingAdded() {
        String strings = "on";

        prefixMatches.load(strings);

        verify(trie, never()).add(any(Tuple.class));
    }

    @Test
    public void testContains_hitWord_positiveResult() {
        String word = "one";
        when(trie.contains("one")).thenReturn(true);

        assertTrue(prefixMatches.contains(word));
    }

    @Test
    public void testContains_missWord_negativeResult() {
        String word = "one";
        when(trie.contains("one")).thenReturn(false);

        assertFalse(prefixMatches.contains(word));
    }
}
@@ -758,44 +758,29 @@
 rify
-(trie, never()).add(any(Tuple.class)
+ZeroInteractions(trie
 );%0A 
@@ -935,44 +935,29 @@
 rify
-(trie, never()).add(any(Tuple.class)
+ZeroInteractions(trie
 );%0A 
@@ -1174,37 +1174,31 @@
 rify
-(trie).add(Matchers.eq(first)
+NoMoreInteractions(trie
 );%0A 
@@ -1501,138 +1501,31 @@
 rify
-(trie, times(2)).add(any(Tuple.class));%0A        verify(trie).add(Matchers.eq(first));%0A        verify(trie).add(Matchers.eq(second)
+NoMoreInteractions(trie
 );%0A 
@@ -1828,91 +1828,31 @@
 rify
-(trie, times(2)).add(any(Tuple.class));%0A        verify(trie).add(Matchers.eq(first)
+NoMoreInteractions(trie
 );%0A 
@@ -2151,138 +2151,31 @@
 rify
-(trie, times(2)).add(any(Tuple.class));%0A        verify(trie).add(Matchers.eq(first));%0A        verify(trie).add(Matchers.eq(second)
+NoMoreInteractions(trie
 );%0A 
@@ -2354,44 +2354,29 @@
 rify
-(trie, never()).add(any(Tuple.class)
+ZeroInteractions(trie
 );%0A 
@@ -2734,24 +2734,24 @@
 rn(false);%0A%0A
-
         asse
@@ -2794,10 +2794,691 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testDelete_hitWord_positiveResult() %7B%0A        String word = %22one%22;%0A        when(trie.delete(%22one%22)).thenReturn(true);%0A%0A        assertTrue(prefixMatches.delete(word));%0A    %7D%0A%0A    @Test%0A    public void testDelete_missWord_negativeResult() %7B%0A        String word = %22one%22;%0A        when(trie.delete(%22one%22)).thenReturn(false);%0A%0A        assertFalse(prefixMatches.delete(word));%0A    %7D%0A%0A    @Test%0A    public void testDelete_hitWord_deletedWord() %7B%0A        String word = %22one%22;%0A        String expectedWord = %22one%22;%0A%0A        prefixMatches.delete(word);%0A%0A        verify(trie, times(1)).delete(Matchers.eq(expectedWord));%0A        verifyNoMoreInteractions(trie);%0A    %7D
 %0A%7D

Add tests for delete method of PrefixMatches class. Now tests are RED.