/* 
 * Copyright (C) 2016 Hobrasoft s.r.o.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package cz.hobrasoft.pdfmu;

import cz.hobrasoft.pdfmu.error.ErrorType;
import org.junit.Assert;
import org.junit.Test;
import org.junit.contrib.java.lang.system.Assertion;

/**
 * @author Filip Bartek
 */
public class MainBasicTest extends MainTest {

    @Test
    public void testTooFewArguments() {
        exit.expectSystemExitWithStatus(ErrorType.PARSER_TOO_FEW_ARGUMENTS.getCode());
        Main.main(new String[]{});
        assert false;
    }

    @Test
    public void testVersion() {
        exit.expectSystemExitWithStatus(0);
        exit.checkAssertionAfterwards(new Assertion() {
            @Override
            public void checkAssertion() {
                // The terminating line break is introduced by Argparse4j
                Assert.assertEquals(String.format("%1$s\n", Main.getProjectVersion()),
                        systemOutRule.getLogWithNormalizedLineSeparator());
            }
        });
        Main.main(new String[]{"--version"});
        assert false;
    }

    @Test
    public void testHelp() {
        exit.expectSystemExitWithStatus(0);
        Main.main(new String[]{"--help"});
        assert false;
    }

    @Test
    public void testLegalNotice() {
        exit.expectSystemExitWithStatus(0);
        exit.checkAssertionAfterwards(new Assertion() {
            @Override
            public void checkAssertion() {
                Assert.assertEquals(Main.getLegalNotice(),
                        systemOutRule.getLogWithNormalizedLineSeparator());
            }
        });
        Main.main(new String[]{"--legal-notice"});
        assert false;
    }

}

@@ -751,314 +751,969 @@
 rt c
-z.hobrasoft.pdfmu.error.ErrorType;%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0Aimport org.junit.contrib.java.lang.system.Assertion;%0A%0A/**%0A * @author Filip Bartek%0A */%0Apublic class MainBasicTest extends MainTest %7B%0A%0A    @Test%0A    public void testTooFewArguments() %7B%0A        exit.expectSystemExitWithStatus(
+om.tngtech.java.junit.dataprovider.DataProvider;%0Aimport com.tngtech.java.junit.dataprovider.DataProviderRunner;%0Aimport com.tngtech.java.junit.dataprovider.UseDataProvider;%0Aimport cz.hobrasoft.pdfmu.error.ErrorType;%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0Aimport org.junit.contrib.java.lang.system.Assertion;%0Aimport org.junit.runner.RunWith;%0A%0A/**%0A * @author Filip Bartek%0A */%0A@RunWith(DataProviderRunner.class)%0Apublic class MainBasicTest extends MainTest %7B%0A%0A    @DataProvider%0A    public static Object%5B%5D%5B%5D dataProviderParserError() %7B%0A        return new Object%5B%5D%5B%5D%7B%0A            new Object%5B%5D%7Bnew String%5B%5D%7B%22--unrecognized-argument%22%7D, ErrorType.PARSER_UNRECOGNIZED_ARGUMENT.getCode()%7D,%0A            new Object%5B%5D%7Bnew String%5B%5D%7B%22--output-format%22, %22invalid-format%22%7D, ErrorType.PARSER_INVALID_CHOICE.getCode()%7D,%0A            new Object%5B%5D%7Bnew String%5B%5D%7B%22unrecognized-command%22%7D, ErrorType.PARSER_UNRECOGNIZED_COMMAND.getCode()%7D,%0A            new Object%5B%5D%7Bnew String%5B%5D%7B%7D, 
 Erro
@@ -1752,18 +1752,18 @@
 etCode()
-);
+%7D,
 %0A       
@@ -1767,32 +1767,297 @@
     
-Main.main(new String%5B%5D%7B%7D
+    new Object%5B%5D%7Bnew String%5B%5D%7B%22--output-format%22%7D, ErrorType.PARSER_EXPECTED_ONE_ARGUMENT.getCode()%7D%0A        %7D;%0A    %7D%0A%0A    @Test%0A    @UseDataProvider%0A    public void testParserError(String%5B%5D args, int exitStatus) %7B%0A        exit.expectSystemExitWithStatus(exitStatus);%0A        Main.main(args
 );%0A 

Test all parser errors