@@ -0,0 +1,3183 @@
+package fr.insee.pogues.search;%0A%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0Aimport fr.insee.pogues.search.model.PoguesHit;%0Aimport fr.insee.pogues.search.model.PoguesItem;%0Aimport fr.insee.pogues.search.repository.PoguesItemRepository;%0Aimport fr.insee.pogues.search.repository.PoguesItemRepositoryImpl;%0Aimport org.elasticsearch.action.index.IndexRequestBuilder;%0Aimport org.elasticsearch.action.index.IndexResponse;%0Aimport org.elasticsearch.action.search.SearchRequestBuilder;%0Aimport org.elasticsearch.action.search.SearchResponse;%0Aimport org.elasticsearch.client.Client;%0Aimport org.elasticsearch.index.query.QueryBuilders;%0Aimport org.elasticsearch.search.SearchHit;%0Aimport org.elasticsearch.search.SearchHits;%0Aimport org.junit.Assert;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.mockito.InjectMocks;%0Aimport org.mockito.Mock;%0Aimport org.mockito.Mockito;%0A%0Aimport java.util.HashMap;%0Aimport java.util.List;%0A%0Aimport static org.mockito.Mockito.spy;%0Aimport static org.mockito.Mockito.when;%0Aimport static org.mockito.MockitoAnnotations.initMocks;%0A%0Apublic class TestSearchRepository %7B%0A%0A    @Mock%0A    Client client;%0A%0A    @InjectMocks%0A    PoguesItemRepository repository;%0A%0A    @Before%0A    public void setUp() %7B%0A        repository = spy(new PoguesItemRepositoryImpl()); // %3C- class under test%0A        initMocks(this);%0A    %7D%0A%0A    @Test%0A    public void saveTest() throws Exception %7B%0A        IndexResponse response = Mockito.mock(IndexResponse.class);%0A        when(response.toString()).thenReturn(%22response%22);%0A        IndexRequestBuilder irb = Mockito.mock(IndexRequestBuilder.class);%0A        PoguesItem item = new PoguesItem(%22foo%22, %22bar%22);%0A        ObjectMapper mapper = new ObjectMapper();%0A        byte%5B%5D data = mapper.writeValueAsBytes(item);%0A        when(irb.setSource(data)).thenReturn(irb);%0A        when(irb.get()).thenReturn(response);%0A        when(client.prepareIndex(null, %22anything%22, %22foo%22)).thenReturn(irb);%0A        Assert.assertEquals(response, repository.save(%22anything%22, item));%0A    %7D%0A%0A    @Test%0A    public void findByLabelTest() throws Exception %7B%0A        SearchResponse response = Mockito.mock(SearchResponse.class);%0A        SearchRequestBuilder srb = Mockito.mock(SearchRequestBuilder.class);%0A        SearchHits shs = Mockito.mock(SearchHits.class);%0A        SearchHit sh = Mockito.mock(SearchHit.class);%0A        when(client.prepareSearch(null)).thenReturn(srb);%0A        when(srb.setTypes(%22anything%22)).thenReturn(srb);%0A        when(srb.setQuery(QueryBuilders.matchQuery(%22label%22, %22bar%22))).thenReturn(srb);%0A        when(srb.get()).thenReturn(response);%0A        when(response.getHits()).thenReturn(shs);%0A        when(sh.getId()).thenReturn(%22foo%22);%0A        when(sh.getSource()).thenReturn(new HashMap%3CString, Object%3E()%7B%0A            %7B put(%22label%22, %22bar%22); %7D%0A        %7D);%0A        when(sh.getType()).thenReturn(%22anything%22);%0A        when(shs.getHits()).thenReturn(new SearchHit%5B%5D%7B%0A           sh%0A        %7D);%0A        List%3CPoguesHit%3E hits = repository.findByLabel(%22bar%22, %22anything%22);%0A        Assert.assertEquals(%22anything%22, hits.get(0).getType());%0A        Assert.assertEquals(%22bar%22, hits.get(0).getLabel());%0A        Assert.assertEquals(%22foo%22, hits.get(0).getId());%0A    %7D%0A%7D%0A

Add repository TU