package com.alexrnl.commons.arguments;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import java.io.PrintStream;

import org.junit.Before;
import org.junit.Test;

/**
 * Test suite for the {@link Arguments} class.
 * @author Alex
 */
public class ArgumentsTest {
	/** The arguments to test */
	private Arguments	arguments;
	/** The target for the parameters */
	private Target		target;
	
	/**
	 * A class representing the target for the argument parsing.
	 * @author Alex
	 */
	private static class Target {
		/** If the feature is used */
		@Param(names = {"-u","--used"}, description = "if the feature should be used", required = false)
		private boolean used;
		/** The name to use */
		@Param(names = {"-n"}, description = "the name of the object", required = true)
		private String	name;
		
		/**
		 * Constructor #1.<br />
		 * Default constructor.
		 */
		private Target () {
			super();
		}
		
		/**
		 * Return the attribute used.
		 * @return the attribute used.
		 */
		public boolean isUsed () {
			return used;
		}
		
		/**
		 * Set the attribute used.
		 * @param used the attribute used.
		 */
		public void setUsed (final boolean used) {
			this.used = used;
		}

		/**
		 * Return the attribute name.
		 * @return the attribute name.
		 */
		public String getName () {
			return name;
		}

		/**
		 * Set the attribute name.
		 * @param name the attribute name.
		 */
		public void setName (final String name) {
			this.name = name;
		}
	}
	
	/**
	 * Set up test attributes.
	 */
	@Before
	public void setUp () {
		target = new Target();
		arguments = new Arguments("manLau", target);
	}
	
	/**
	 * Test method for {@link Arguments#parse(String[])}.
	 */
	@Test
	public void testParseStringArray () {
		arguments.parse("-u", "-n", "alex");
		assertTrue(target.isUsed());
		assertEquals("alex", target.getName());
	}
	
	/**
	 * Test method for {@link Arguments#parse(Iterable)}.
	 */
	@Test
	public void testParseIterableOfString () {
		arguments.parse("--used", "-n", "alex");
		assertTrue(target.isUsed());
		assertEquals("alex", target.getName());
	}
	
	// TODO add tests for error cases
	
	/**
	 * Test method for {@link Arguments#usage(PrintStream)}.
	 */
	@Test
	public void testUsagePrintStream () {
		final PrintStream out = mock(PrintStream.class);
		arguments.usage(out);
		verify(out).println(arguments);
	}
	
	/**
	 * Test method for {@link Arguments#usage()}.
	 */
	@Test
	public void testUsage () {
		// Nothing can really be done to check that the usage has been printed on stdout
		arguments.usage();
	}
	
	/**
	 * Test method for {@link Arguments#toString()}.
	 */
	@Test
	public void testToString () {
		assertEquals("manLau usage as follow:\n" +
				"\t   -n\t\t\t\tthe name of the object\n" +
				"\t[  -u, --used\t\t\t\tif the feature should be used  ]",
				arguments.toString());
	}
}

@@ -1165,409 +1165,112 @@
 %09 * 
-Set the attribute used.%0A%09%09 * @param used the attribute used.%0A%09%09 */%0A%09%09public void setUsed (final boolean used) %7B%0A%09%09%09this.used = used;%0A%09%09%7D%0A%0A%09%09/**%0A%09%09 * Return the attribute name.%0A%09%09 * @return the attribute name.%0A%09%09 */%0A%09%09public String getName () %7B%0A%09%09%09return name;%0A%09%09%7D%0A%0A%09%09/**%0A%09%09 * Set the attribute name.%0A%09%09 * @param name the attribute name.%0A%09%09 */%0A%09%09public void setName (final String name) %7B%0A%09%09%09this.name =
+Return the attribute name.%0A%09%09 * @return the attribute name.%0A%09%09 */%0A%09%09public String getName () %7B%0A%09%09%09return
  nam

Remove setters in target class for tests