<commit_before>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 <NAME>
 * 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<commit_msg>Reformat code.<commit_after>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 <NAME>
 * 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
{'fraction_non_alphanumeric': 0.08608870967741936, 'fraction_numerical': 0.00564516129032258, 'mean_word_length': 4.322961373390558, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4236308', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1427, 'n_words': 274}