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

import no.uio.ifi.trackfind.backend.pojo.TfHub;
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.Collections;
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);
    }

    @Test
    public void getActiveTrackHubsTest() {
        Collection<TfHub> allTrackHubs = trackFindService.getActiveTrackHubs();
        assertThat(allTrackHubs).isNotEmpty().hasSize(1);
        TfHub hub = allTrackHubs.iterator().next();
        assertThat(hub.getRepository()).isEqualTo(TEST_DATA_PROVIDER);
        assertThat(hub.getName()).isEqualTo("active");
    }

    @Test
    public void getAllTrackHubsTest() {
        Collection<TfHub> allTrackHubs = trackFindService.getAllTrackHubs();
        assertThat(allTrackHubs).isNotEmpty().hasSize(1);
        TfHub hub = allTrackHubs.iterator().next();
        assertThat(hub.getRepository()).isEqualTo(TEST_DATA_PROVIDER);
        assertThat(hub.getName()).isEqualTo("inactive");
    }

    @Before
    public void setUp() {
        when(dataProvider.getName()).thenReturn(TEST_DATA_PROVIDER);
        when(dataProvider.getActiveTrackHubs()).thenReturn(Collections.singleton(new TfHub(TEST_DATA_PROVIDER, "active")));
        when(dataProvider.getAllTrackHubs()).thenReturn(Collections.singleton(new TfHub(TEST_DATA_PROVIDER, "inactive")));
        dataProviders.add(dataProvider);
    }

}

@@ -1641,30 +1641,24 @@
 dService.get
-Active
 TrackHubs();
@@ -1647,32 +1647,36 @@
 ce.getTrackHubs(
+true
 );%0A        asser
@@ -2012,27 +2012,24 @@
 dService.get
-All
 TrackHubs();
@@ -2026,16 +2026,21 @@
 ackHubs(
+false
 );%0A     

Fix TrackFindServiceTest