package no.uio.ifi.trackfind.backend.services;

import no.uio.ifi.trackfind.backend.data.providers.DataProvider;
import no.uio.ifi.trackfind.backend.data.providers.ihec.IHECDataProvider;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Collection;
import java.util.HashSet;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

@RunWith(SpringRunner.class)
public class TrackFindServiceTest {

    private static final String TEST_DATA_PROVIDER = "TEST";

    @InjectMocks
    private TrackFindService trackFindService;

    @Spy
    private Collection<DataProvider> dataProviders = new HashSet<>();

    @Mock
    private IHECDataProvider dataProvider;

    @Test
    public void getDataProvidersTest() {
        Collection<DataProvider> dataProviders = trackFindService.getDataProviders();
        assertThat(dataProviders).isNotEmpty().hasSize(1);
        DataProvider dataProvider = dataProviders.iterator().next();
        assertThat(dataProvider.getName()).isEqualTo(TEST_DATA_PROVIDER);
    }

    @Test
    public void getDataProviderTest() {
        DataProvider dataProvider = trackFindService.getDataProvider(TEST_DATA_PROVIDER);
        assertThat(dataProvider.getName()).isEqualTo(TEST_DATA_PROVIDER);
    }

    @Before
    public void setUp() {
        when(dataProvider.getName()).thenReturn(TEST_DATA_PROVIDER);
        dataProviders.add(dataProvider);
    }

}

@@ -41,16 +41,61 @@
 vices;%0A%0A
+import no.uio.ifi.trackfind.backend.dao.Hub;%0A
 import n
@@ -478,16 +478,46 @@
 ection;%0A
+import java.util.Collections;%0A
 import j
@@ -1537,107 +1537,1088 @@
    @
-Before%0A    public void setUp() %7B%0A        when(dataProvider.getName()).thenReturn(TEST_DATA_PROVIDER
+Test%0A    public void getActiveTrackHubsTest() %7B%0A        Collection%3CHub%3E allTrackHubs = trackFindService.getActiveTrackHubs();%0A        assertThat(allTrackHubs).isNotEmpty().hasSize(1);%0A        Hub hub = allTrackHubs.iterator().next();%0A        assertThat(hub.getRepository()).isEqualTo(TEST_DATA_PROVIDER);%0A        assertThat(hub.getHub()).isEqualTo(%22active%22);%0A    %7D%0A%0A    @Test%0A    public void getAllTrackHubsTest() %7B%0A        Collection%3CHub%3E allTrackHubs = trackFindService.getAllTrackHubs();%0A        assertThat(allTrackHubs).isNotEmpty().hasSize(1);%0A        Hub hub = allTrackHubs.iterator().next();%0A        assertThat(hub.getRepository()).isEqualTo(TEST_DATA_PROVIDER);%0A        assertThat(hub.getHub()).isEqualTo(%22inactive%22);%0A    %7D%0A%0A    @Before%0A    public void setUp() %7B%0A        when(dataProvider.getName()).thenReturn(TEST_DATA_PROVIDER);%0A        when(dataProvider.getActiveTrackHubs()).thenReturn(Collections.singleton(new Hub(TEST_DATA_PROVIDER, %22active%22)));%0A        when(dataProvider.getAllTrackHubs()).thenReturn(Collections.singleton(new Hub(TEST_DATA_PROVIDER, %22inactive%22))
 );%0A 

Fix TrackFindServiceTest.