Browse souce code repository at: https://github.com/jjYBdx4IL/java-evaluation/blob/master/src/test/java/org/apache/commons/cli/CommandLineParserTest.java
/*
 * #%L
 * Evaluation
 * %%
 * Copyright (C) 2016 Github jjYBdx4IL Projects
 * %%
 * #L%
 */
package org.apache.commons.cli;

import static org.junit.Assert.*;
import org.junit.Test;

/**
 *
 * @author Github jjYBdx4IL Projects
 */
public class CommandLineParserTest {

    private static final String[] TEST_ARGS = new String[]{"one", "-u", "url", "two"};

    @Test
    public void test1() throws ParseException {
        @SuppressWarnings("deprecation")
        CommandLineParser parser = new GnuParser();

        Options options = new Options();
        options.addOption("u", "url", true, "the URL");

        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("progname", options);

        CommandLine line = parser.parse(options, TEST_ARGS);

        assertTrue(line.hasOption("u"));
        assertTrue(line.hasOption("url"));
        assertEquals("url", line.getOptionValue("u"));
        assertEquals("url", line.getOptionValue("url"));

        String[] leftOver = line.getArgs();
        assertArrayEquals(new String[]{"one", "two"}, leftOver);
    }
}
-------------------------------------------------------------------------------
Test set: org.apache.commons.cli.CommandLineParserTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.003 s - in org.apache.commons.cli.CommandLineParserTest
test1  Time elapsed: 0 s