package uk.ac.ebi.atlas.utils;

import org.junit.Before;
import org.junit.Test;
import org.springframework.web.client.RestTemplate;
import uk.ac.ebi.atlas.web.ApplicationProperties;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ArrayExpressClientTestIT {

    private ArrayExpressClient subject;

    private final static String EXPERIMENT_ACC = "E-MTAB-513";

    @Before
    public void initSubject() {
        RestTemplate restTemplate = new RestTemplate();

        //ToDo: better use injection
        ApplicationProperties applicationProperties = mock(ApplicationProperties.class);
        when(applicationProperties.getArrayExpressRestURL(EXPERIMENT_ACC)).thenReturn("http://www.ebi.ac.uk/arrayexpress/xml/v2/experiments?accession=E-MTAB-513");

        subject = new ArrayExpressClient(restTemplate, applicationProperties);

    }

    @Test
    public void testFetchExperimentName() throws Exception {
        String result = subject.fetchExperimentName(EXPERIMENT_ACC);
        assertThat(result, is("RNA-Seq of human individual tissues and mixture of 16 tissues (Illumina Body Map)"));
    }
}

@@ -73,16 +73,100 @@
 t.Test;%0A
+import org.mockito.invocation.InvocationOnMock;%0Aimport org.mockito.stubbing.Answer;%0A
 import o
@@ -357,16 +357,62 @@
 rtThat;%0A
+import static org.mockito.Matchers.anyString;%0A
 import s
@@ -919,202 +919,560 @@
 URL(
-EXPERIMENT_ACC)).thenReturn(%22http://www.ebi.ac.uk/arrayexpress/xml/v2/experiments?accession=E-MTAB-513%22);%0A%0A        subject = new ArrayExpressClient(restTemplate, applicationProperties);%0A
+anyString())).thenAnswer(arrayExpressUrl());%0A%0A        subject = new ArrayExpressClient(restTemplate, applicationProperties);%0A%0A    %7D%0A%0A    private static Answer%3CString%3E arrayExpressUrl() %7B%0A        return new Answer%3CString%3E() %7B%0A            public static final String AE2_URL = %22http://www.ebi.ac.uk/arrayexpress/xml/v2/experiments?accession=%22;%0A%0A            @Override%0A            public String answer(InvocationOnMock invocationOnMock) throws Throwable %7B%0A                return AE2_URL + invocationOnMock.getArguments()%5B0%5D;%0A            %7D%0A        %7D;
 %0A    %7D%0A%0A
     
@@ -1463,24 +1463,25 @@
   %7D;%0A    %7D%0A%0A
+%0A
     @Test%0A  
@@ -1523,25 +1523,8 @@
 me()
- throws Exception
  %7B%0A 
@@ -1714,10 +1714,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

refactor - to support tests for multiple experiments