package io.github.utplsql.cli;

import com.beust.jcommander.JCommander;
import io.github.utplsql.api.CustomTypes;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;

/**
 * Unit test for run command.
 */
public class RunCommandTest {

    private RunCommand createCommand(String... args) {
        RunCommand runCmd = new RunCommand();

        JCommander.newBuilder()
                .addObject(runCmd)
                .args(args)
                .build();

        return runCmd;
    }

    @Test
    public void reporterOptions_Default() {
        RunCommand runCmd = createCommand("run", "app/app");

        List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

        ReporterOptions reporterOptions1 = reporterOptionsList.get(0);
        Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName());
        Assert.assertNull(reporterOptions1.getOutputFileName());
        Assert.assertFalse(reporterOptions1.outputToFile());
        Assert.assertTrue(reporterOptions1.outputToScreen());
    }

    @Test
    public void reporterOptions_OneReporter() {
        RunCommand runCmd = createCommand("run", "app/app", "-f=ut_documentation_reporter", "-o=output.txt");

        List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

        ReporterOptions reporterOptions1 = reporterOptionsList.get(0);
        Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName());
        Assert.assertEquals(reporterOptions1.getOutputFileName(), "output.txt");
        Assert.assertTrue(reporterOptions1.outputToFile());
        Assert.assertFalse(reporterOptions1.outputToScreen());
    }

    @Test
    public void reporterOptions_OneReporterForceScreen() {
        RunCommand runCmd = createCommand("run", "app/app", "-f=ut_documentation_reporter", "-o=output.txt", "-s");

        List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

        ReporterOptions reporterOptions1 = reporterOptionsList.get(0);
        Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName());
        Assert.assertEquals(reporterOptions1.getOutputFileName(), "output.txt");
        Assert.assertTrue(reporterOptions1.outputToFile());
        Assert.assertTrue(reporterOptions1.outputToScreen());
    }

    @Test
    public void reporterOptions_OneReporterForceScreenInverse() {
        RunCommand runCmd = createCommand("run", "app/app", "-f=ut_documentation_reporter", "-s", "-o=output.txt");

        List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

        ReporterOptions reporterOptions1 = reporterOptionsList.get(0);
        Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName());
        Assert.assertEquals(reporterOptions1.getOutputFileName(), "output.txt");
        Assert.assertTrue(reporterOptions1.outputToFile());
        Assert.assertTrue(reporterOptions1.outputToScreen());
    }

    @Test
    public void reporterOptions_TwoReporters() {
        RunCommand runCmd = createCommand("run", "app/app",
                "-f=ut_documentation_reporter",
                "-f=ut_coverage_html_reporter", "-o=coverage.html", "-s");

        List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

        ReporterOptions reporterOptions1 = reporterOptionsList.get(0);
        Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName());
        Assert.assertNull(reporterOptions1.getOutputFileName());
        Assert.assertFalse(reporterOptions1.outputToFile());
        Assert.assertTrue(reporterOptions1.outputToScreen());

        ReporterOptions reporterOptions2 = reporterOptionsList.get(1);
        Assert.assertEquals(CustomTypes.UT_COVERAGE_HTML_REPORTER, reporterOptions2.getReporterName());
        Assert.assertEquals(reporterOptions2.getOutputFileName(), "coverage.html");
        Assert.assertTrue(reporterOptions2.outputToFile());
        Assert.assertTrue(reporterOptions2.outputToScreen());
    }

}

@@ -274,24 +274,27 @@
 mmand create
+Run
 Command(Stri
@@ -303,24 +303,24 @@
 ... args) %7B%0A
-
         RunC
@@ -590,32 +590,35 @@
 Cmd = create
+Run
 Command(
 %22run%22, %22app/
@@ -605,31 +605,24 @@
 Command(
-%22run%22, 
 %22app/app
 %22);%0A%0A   
@@ -613,16 +613,19 @@
 %22app/app
+@xe
 %22);%0A%0A   
@@ -1165,32 +1165,35 @@
 Cmd = create
+Run
 Command(
 %22run%22, %22app/
@@ -1176,39 +1176,32 @@
 eRunCommand(
-%22run%22, 
 %22app/app
 %22, %22-f=ut_do
@@ -1180,32 +1180,35 @@
 Command(%22app/app
+@xe
 %22, %22-f=ut_docume
@@ -1816,32 +1816,35 @@
 Cmd = create
+Run
 Command(
 %22run%22, %22app/
@@ -1827,39 +1827,32 @@
 eRunCommand(
-%22run%22, 
 %22app/app
 %22, %22-f=ut_do
@@ -1831,32 +1831,35 @@
 Command(%22app/app
+@xe
 %22, %22-f=ut_docume
@@ -2479,32 +2479,35 @@
 Cmd = create
+Run
 Command(
 %22run%22, %22app/
@@ -2494,31 +2494,24 @@
 Command(
-%22run%22, 
 %22app/app
 %22, %22-f=u
@@ -2502,16 +2502,19 @@
 %22app/app
+@xe
 %22, %22-f=u
@@ -3129,24 +3129,27 @@
 = create
+Run
 Command(
 %22run%22, %22
@@ -3144,23 +3144,16 @@
 and(
-%22run%22, 
 %22app/app
 %22,%0A 
@@ -3148,16 +3148,19 @@
 %22app/app
+@xe
 %22,%0A     

Fix RunCommand tests