package org.pdxfinder.commandline;

import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.pdxfinder.BaseTest;
import org.pdxfinder.services.constants.DataProvider;
import picocli.CommandLine;

import java.io.File;
import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.mockito.Mockito.*;


public class FinderCommandLineTest extends BaseTest {

    @Mock private FinderLoader finderLoader;
    @InjectMocks private FinderCommandLine.Load load;

    @Mock private FinderTransformer finderTransformer;
    @InjectMocks private FinderCommandLine.Transform transform;

    @Mock private FinderExporter finderExporter;
    @InjectMocks private FinderCommandLine.Export export;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        doNothing().when(this.finderLoader).run(
            anyListOf(DataProvider.class),
            any(File.class),
            anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean()
        );
    }

    /*
    @Test public void givenLoadOnlyMinimal_LoaderIsCalled() {
        String[] args = {"--only=Test_Minimal", "--data-dir=path/", "--keep-db"};
        int exitCode = new CommandLine(load).execute(args);
        assertEquals(0, exitCode);
        verify(this.finderLoader).run(
            anyListOf(DataProvider.class),
            any(File.class),
            anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean()
        );
        verifyNoMoreInteractions(this.finderLoader);
    }

    @Test public void givenLoadAll_callsLoader() {
        String[] args = {"--group=All", "--data-dir=path/", "--keep-db"};
        int exitCode = new CommandLine(load).execute(args);
        assertEquals(0, exitCode);
        verify(this.finderLoader).run(
            anyListOf(DataProvider.class),
            any(File.class),
            anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean()
        );
        verifyNoMoreInteractions(this.finderLoader);
    }
*/
    @Test public void givenTransform_When_exportAllisCalled_Then_callsTransformer() throws IOException {
        String[] args = {"--data-dir=path/", "-c=MUT"};
        int exitCode = new CommandLine(transform).execute(args);
        assertEquals(0, exitCode);
        verify(this.finderTransformer).run(
                any(File.class),
                any(),
                any(),
                any(File.class),
                any(),
                any()
        );
        verifyNoMoreInteractions(this.finderTransformer);
    }

    @Test public void givenTransform_When_cbioPortalIsCalled_Then_callsTransformer() throws IOException {
        String[] args = {"-c=MUT", "-f=/tmp"};
        int exitCode = new CommandLine(transform).execute(args);
        assertEquals(0, exitCode);
        verify(this.finderTransformer).run(
                any(),
                eq(null),
                eq(null),
                any(File.class),
                any(),
                any()
        );
        verifyNoMoreInteractions(this.finderTransformer);
    }

    @Test public void givenTransformer_WhenOnlyExportIsPassed_ThenLoadAllandIsHarmonizedAreFalse() throws IOException {
        String[] args = {"-a"};
        int exitCode = new CommandLine(export).execute(args);
        assertEquals(0, exitCode);
        verify(this.finderExporter).run(
                any(File.class),
                any(String.class),
                eq(true),
                eq(false)
        );
    }

    @Test public void givenTransformer_WhenExportAllandHarmonized_ThenLoadAllandIsHarmonizedAretrue() throws IOException {
        String[] args = {"-a", "-o"};
        int exitCode = new CommandLine(export).execute(args);
        assertEquals(0, exitCode);
        verify(this.finderExporter).run(
                any(File.class),
                any(String.class),
                eq(true),
                eq(true)
        );
    }


    @Test public void givenTransform_WhenTwoExclusiveArgumentsArepassed_Then_ReturnNonZeroExit() {
        String[] args = {"--data-dir=path/", "--export=test", "--all"};
        int exitCode = new CommandLine(transform).execute(args);
        assertNotEquals(0,exitCode);
    }





}
@@ -748,116 +748,8 @@
 m;%0A%0A
-    @Mock private FinderExporter finderExporter;%0A    @InjectMocks private FinderCommandLine.Export export;%0A%0A
     
@@ -879,32 +879,36 @@
 un(%0A            
+    
 anyListOf(DataPr
@@ -926,32 +926,36 @@
 s),%0A            
+    
 any(File.class),
@@ -947,32 +947,36 @@
 ny(File.class),%0A
+    
             anyB
@@ -1048,15 +1048,8 @@
  %7D%0A%0A
-    /*%0A
     
@@ -1168,37 +1168,24 @@
 a-dir=path/%22
-, %22--keep-db%22
 %7D;%0A        i
@@ -1325,39 +1325,27 @@
     
+    
 anyList
-Of(DataProvider.class),%0A
+(),%0A    
     
@@ -1361,32 +1361,36 @@
 ny(File.class),%0A
+    
             anyB
@@ -1624,21 +1624,8 @@
 th/%22
-, %22--keep-db%22
 %7D;%0A 
@@ -1773,39 +1773,27 @@
     
+    
 anyList
-Of(DataProvider.class),%0A
+(),%0A    
     
@@ -1809,32 +1809,36 @@
 ny(File.class),%0A
+    
             anyB
@@ -1962,1938 +1962,533 @@
   %7D%0A
-*/%0A    @Test public void givenTransform_When_exportAllisCalled_Then_callsTransformer() throws IOException %7B%0A        String%5B%5D args = %7B%22--data-dir=path/%22, %22-c=MUT%22%7D;%0A        int exitCode = new CommandLine(transform).execute(args);%0A        assertEquals(0, exitCode);%0A        verify(this.finderTransformer).run(%0A                any(File.class),%0A                any(),%0A                any(),%0A                any(File.class),%0A                any(),%0A                any()%0A        );%0A        verifyNoMoreInteractions(this.finderTransformer);%0A    %7D%0A%0A    @Test public void givenTransform_When_cbioPortalIsCalled_Then_callsTransformer() throws IOException %7B%0A        String%5B%5D args = %7B%22-c=MUT%22, %22-f=/tmp%22%7D;%0A        int exitCode = new CommandLine(transform).execute(args);%0A        assertEquals(0, exitCode);%0A        verify(this.finderTransformer).run(%0A                any(),%0A                eq(null),%0A                eq(null),%0A                any(File.class),%0A                any(),%0A                any()%0A        );%0A        verifyNoMoreInteractions(this.finderTransformer);%0A    %7D%0A%0A    @Test public void givenTransformer_WhenOnlyExportIsPassed_ThenLoadAllandIsHarmonizedAreFalse() throws IOException %7B%0A        String%5B%5D args = %7B%22-a%22%7D;%0A        int exitCode = new CommandLine(export).execute(args);%0A        assertEquals(0, exitCode);%0A        verify(this.finderExporter).run(%0A                any(File.class),%0A                any(String.class),%0A                eq(true),%0A                eq(false)%0A        );%0A    %7D%0A%0A    @Test public void givenTransformer_WhenExportAllandHarmonized_ThenLoadAllandIsHarmonizedAretrue() throws IOException %7B%0A        String%5B%5D args = %7B%22-a%22, %22-o%22%7D;%0A        int exitCode = new CommandLine(export).execute(args);%0A        assertEquals(0, exitCode);%0A        verify(this.finderExporter).run(%0A                any(File.class),%0A                any(String.class),%0A                eq(true),%0A                eq(true)%0A        );%0A    %7D%0A
+%0A    @Test public void givenTransform_When_cbioPortalIsCalled_Then_callsTransformer() throws IOException %7B%0A        String%5B%5D args = %7B%22-c=MUT%22, %22-f=/tmp%22%7D;%0A        int exitCode = new CommandLine(transform).execute(args);%0A        assertEquals(0, exitCode);%0A        verify(this.finderTransformer).run(%0A                any(),%0A                eq(null),%0A                eq(null),%0A                any(File.class),%0A                any(),%0A                any()%0A        );%0A        verifyNoMoreInteractions(this.finderTransformer);%0A    %7D
 %0A%0A  

Fix tests