package uk.ac.ebi.quickgo.rest.search.results.transformer;

import uk.ac.ebi.quickgo.rest.search.request.converter.RESTFilterConverterFactory;

import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
 * @author Tony Wardell
 * Date: 09/10/2017
 * Time: 15:54
 * Created with IntelliJ IDEA.
 */
@RunWith(MockitoJUnitRunner.class) public class ValueInjectionToSingleResultTest {

    private static final String GO_NAME_REQUEST = "goName";
    private static final String TAXON_NAME_REQUEST = "taxonName";
    private final List<ResponseValueInjector<FakeResponseModel>> requiredInjectors = new ArrayList<>();
    @Mock private RESTFilterConverterFactory mockRestFetcher;
    @Mock private FakeValueInjector mockGoNameInjector;
    @Mock private FakeValueInjector mockTaxonNameInjector;
    private FakeResponseModel result;
    private ValueInjectionToSingleResult<FakeResponseModel> resultMutator;

    @Before public void setup() {

        when(mockGoNameInjector.getId()).thenReturn(GO_NAME_REQUEST);
        when(mockTaxonNameInjector.getId()).thenReturn(TAXON_NAME_REQUEST);
        requiredInjectors.add(mockGoNameInjector);
        requiredInjectors.add(mockTaxonNameInjector);
        result = new FakeResponseModel();
        resultMutator = new ValueInjectionToSingleResult<>(mockRestFetcher);
    }

    @Test(expected = IllegalArgumentException.class)
    public void nullArgumentForRestFilterConverterFactoryToConstructorThrowsException() {
        new ValueInjectionToSingleResult(null);
    }

    @Test public void everyInjectorUsedForEveryModel() {
        resultMutator.mutate(result, requiredInjectors);

        verify(mockGoNameInjector, times(1)).inject(mockRestFetcher, result);
        verify(mockTaxonNameInjector, times(1)).inject(mockRestFetcher, result);

    }


    /**
     * Used only for mocking purposes
     */
    private static class FakeValueInjector implements ResponseValueInjector<FakeResponseModel> {
        @Override public String getId() {
            return "fake id";
        }

        @Override public void inject(RESTFilterConverterFactory restFetcher, FakeResponseModel annotation) {
            // not implemented
        }
    }

    private static class FakeResponseModel {
    }
}

@@ -598,17 +598,17 @@
 r.class)
- 
+%0A
 public c
@@ -879,32 +879,36 @@
 t%3C%3E();%0A    @Mock
+%0A   
  private RESTFil
@@ -945,32 +945,36 @@
 tcher;%0A    @Mock
+%0A   
  private FakeVal
@@ -1013,16 +1013,20 @@
    @Mock
+%0A   
  private
@@ -1192,16 +1192,20 @@
  @Before
+%0A   
  public 
@@ -1219,17 +1219,16 @@
 tup() %7B%0A
-%0A
         
@@ -1803,16 +1803,20 @@
    @Test
+%0A   
  public 
@@ -2076,17 +2076,15 @@
 t);%0A
-%0A
     %7D%0A%0A
-%0A
     
@@ -2239,32 +2239,40 @@
        @Override
+%0A       
  public String g
@@ -2317,24 +2317,24 @@
 %0A        %7D%0A%0A
-
         @Ove
@@ -2338,16 +2338,24 @@
 Override
+%0A       
  public 

Reformat code.