//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// This file is a part of the 'esoco-lib' project.
// Copyright 2017 Elmar Sonnenschein, esoco GmbH, Flensburg, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//	  http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package de.esoco.lib.app;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;


/********************************************************************
 * Test of the {@link CommandLine} class.
 *
 * @author eso
 */
public class CommandLineTest
{
	//~ Methods ----------------------------------------------------------------

	/***************************************
	 * Test CommandLine(String[])
	 */
	@Test
	public void testCommandLine()
	{
		String[]    args = "-a_/b_-t1=123_-t2='ok ok'".split("_");
		CommandLine cl   = new CommandLine(args);

		assertOptions(cl);
	}

	/***************************************
	 * Test assignment only CommandLine(String[], String...)
	 */
	@Test
	public void testRequireOption()
	{
		String[]    args    = new String[] { "-val=test" };
		String[]    options = new String[] { "val=" };
		CommandLine cl	    = new CommandLine(args, options);

		assertEquals("test", cl.getOption("val"));

		try
		{
			args = new String[] { "-val" };
			cl   = new CommandLine(args, options);

			cl.requireOption("val");
			assertTrue("Mandatory option value missing", false);
		}
		catch (CommandLineException e)
		{
			// expected
		}
	}

	/***************************************
	 * Asserts the contents of a command line.
	 *
	 * @param cl The command line
	 */
	@SuppressWarnings("boxing")
	private void assertOptions(CommandLine cl)
	{
		assertTrue(cl.hasOption("a"));
		assertTrue(cl.hasOption("b"));
		assertFalse(cl.hasOption("c"));
		assertEquals(true, cl.getOption("a"));
		assertEquals(123, cl.getOption("t1"));
		assertEquals("ok ok", cl.getOption("t2"));
	}
}

@@ -1422,16 +1422,30 @@
 ='ok ok'
+_-t3_'a value'
 %22.split(
@@ -1507,18 +1507,296 @@
 sert
-Options(cl
+True(cl.hasOption(%22a%22));%0A%09%09assertTrue(cl.hasOption(%22b%22));%0A%09%09assertFalse(cl.hasOption(%22c%22));%0A%09%09assertEquals(Boolean.TRUE, cl.getOption(%22a%22));%0A%09%09assertEquals(Integer.valueOf(123), cl.getOption(%22t1%22));%0A%09%09assertEquals(%22ok ok%22, cl.getOption(%22t2%22));%0A%09%09assertEquals(%22a value%22, cl.getOption(%22t3%22)
 );%0A%09
@@ -2389,440 +2389,7 @@
 %7D%0A%09%7D
-%0A%0A%09/***************************************%0A%09 * Asserts the contents of a command line.%0A%09 *%0A%09 * @param cl The command line%0A%09 */%0A%09@SuppressWarnings(%22boxing%22)%0A%09private void assertOptions(CommandLine cl)%0A%09%7B%0A%09%09assertTrue(cl.hasOption(%22a%22));%0A%09%09assertTrue(cl.hasOption(%22b%22));%0A%09%09assertFalse(cl.hasOption(%22c%22));%0A%09%09assertEquals(true, cl.getOption(%22a%22));%0A%09%09assertEquals(123, cl.getOption(%22t1%22));%0A%09%09assertEquals(%22ok ok%22, cl.getOption(%22t2%22));%0A%09%7D
 %0A%7D%0A

Test condition added