package org.pdxfinder.services.loader;

import static org.hamcrest.CoreMatchers.allOf;

import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.pdxfinder.BaseTest;
import org.pdxfinder.graph.dao.Marker;
import org.pdxfinder.services.DataImportService;
import org.pdxfinder.services.constants.DataUrl;
import org.pdxfinder.services.loader.envload.LoadMarkers;

import java.io.IOException;

import static org.junit.Assert.assertEquals;

import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doAnswer;


public class LoadMarkerTest extends BaseTest {

    @Mock
    private DataImportService dataImportService;

    @InjectMocks
    private LoadMarkers loadMarkers;

    private String hgncName = "TEST_MARKER_NAME";
    private String hgncSymbol = "TEST_MARKER_SYMBOL";

    private Marker marker = new Marker();

    @Before
    public void setup() {

        marker.setHgncSymbol(hgncSymbol);
        marker.setHgncName(hgncName);

        // given
        Marker expectedMarker = marker;
        doReturn(expectedMarker).when(dataImportService).saveMarker(expectedMarker);
    }


    @Test
    public void given_MarkerDataUrl_When_LoadGenesInvoked_Then_saveMarkers() throws IOException {

        // given
        String markerDataUrl = DataUrl.HUGO_FILE_URL.get();

        // When
        loadMarkers.loadGenes(markerDataUrl);

        // Then
        verify(dataImportService, atLeast(100)).saveMarker(any(Marker.class));

    }

    @Test
    public void given_WrongUrl_When_LoadGenesInvokedWithMalformedURL_then_noMarkerIsSaved() throws IOException {

        // given
        String malformedGeneURL = "genemaes.org";

        // When
        loadMarkers.loadGenes(malformedGeneURL);

        // Then
        verify(dataImportService, never()).saveMarker(any(Marker.class));

    }



}

@@ -37,56 +37,8 @@
 r;%0A%0A
-import static org.hamcrest.CoreMatchers.allOf;%0A%0A
 impo
@@ -416,243 +416,34 @@
 org.
-junit.Assert.assertEquals;%0A%0Aimport static org.mockito.Mockito.doReturn;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.never;%0Aimport static org.mockito.Mockito.any;%0Aimport static org.mockito.Mockito.atLeast
+mockito.Matchers.anyListOf
 ;%0Aim
@@ -478,18 +478,10 @@
 ito.
-doAnswer;%0A
+*;
 %0A%0Apu
@@ -1145,34 +1145,32 @@
 arkers() throws 
-IO
 Exception %7B%0A%0A   
@@ -1359,394 +1359,34 @@
 vice
-, atLeast(100)
 ).save
+All
 Marker
+s
 (any
-(Marker.class));%0A%0A    %7D%0A%0A    @Test%0A    public void given_WrongUrl_When_LoadGenesInvokedWithMalformedURL_then_noMarkerIsSaved() throws IOException %7B%0A%0A        // given%0A        String malformedGeneURL = %22genemaes.org%22;%0A%0A        // When%0A        loadMarkers.loadGenes(malformedGeneURL);%0A%0A        // Then%0A        verify(dataImportService, never()).saveMarker(any
+ListOf
 (Mar
@@ -1406,12 +1406,10 @@
 %0A    %7D%0A%0A
-%0A%0A
 %7D%0A

Fix unit tests