package no.uio.ifi.trackfind;

import no.uio.ifi.trackfind.data.providers.DataProvider;
import no.uio.ifi.trackfind.services.TrackFindService;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;
import java.util.*;

import static org.mockito.BDDMockito.given;

@RunWith(SpringRunner.class)
@SpringBootTest
public class TrackFindApplicationTests {

    @MockBean
    private DataProvider ihecDataProvider;

    @Autowired
    private TrackFindService trackFindService;

    @SuppressWarnings("unchecked")
    @Test
    public void indexingTest() {
        Map<String, String> track = new HashMap<>();
        track.put("key", "value");
        Set<Map> data = Collections.singleton(track);
        given(ihecDataProvider.fetchData()).willReturn(data);
        trackFindService.updateIndex();
        Collection<Map> search = trackFindService.search("key: value");
        Assertions.assertThat(search).size().isEqualTo(1);
        Map map = search.iterator().next();
        Assertions.assertThat(map).containsEntry("key", "value");
    }

    @TestConfiguration
    static class TrackFindTestApplication {

        @Bean
        public Directory directory() throws IOException {
            return new RAMDirectory();
        }

    }


}

@@ -24,16 +24,59 @@
 kfind;%0A%0A
+import com.google.common.collect.Multimap;%0A
 import n
@@ -306,16 +306,41 @@
 rtions;%0A
+import org.junit.Before;%0A
 import o
@@ -798,9 +798,96 @@
 til.
-*
+Collection;%0Aimport java.util.Collections;%0Aimport java.util.HashMap;%0Aimport java.util.Map
 ;%0A%0Ai
@@ -1013,24 +1013,73 @@
 ionTests %7B%0A%0A
+    private static boolean setUpIsDone = false;%0A%0A
     @MockBea
@@ -1196,80 +1196,126 @@
    @
-SuppressWarnings(%22unchecked%22)%0A    @Test%0A    public void indexingTest() %7B
+Before%0A    public void setUp() %7B%0A        if (setUpIsDone) %7B%0A            return;%0A        %7D%0A        setUpIsDone = true;%0A
 %0A   
@@ -1411,24 +1411,55 @@
     
-Set%3CMap%3E data = 
+given(ihecDataProvider.fetchData()).willReturn(
 Coll
@@ -1482,16 +1482,17 @@
 n(track)
+)
 ;%0A      
@@ -1497,101 +1497,445 @@
     
-given(ihecDataProvider.fetchData()).willReturn(data);%0A        trackFindService.updateIndex();
+trackFindService.updateIndex();%0A    %7D%0A%0A    @Test%0A    public void metamodelTest() %7B%0A        Multimap%3CString, String%3E metamodel = trackFindService.getMetamodel();%0A        Assertions.assertThat(metamodel).isNotNull();%0A        Assertions.assertThat(metamodel.keySet()).contains(%22key%22);%0A        Assertions.assertThat(metamodel.get(%22key%22)).contains(%22value%22);%0A    %7D%0A%0A    @SuppressWarnings(%22unchecked%22)%0A    @Test%0A    public void indexingTest() %7B
 %0A   

Add metamodel unit-test.