package com.alexrnl.commons.arguments;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyObject;
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 isUsed;
		/** 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 isUsed.
		 * @return the attribute isUsed.
		 */
		public boolean isUsed () {
			return isUsed;
		}
		
		/**
		 * Set the attribute isUsed.
		 * @param isUsed the attribute isUsed.
		 */
		public void setUsed (final boolean isUsed) {
			this.isUsed = isUsed;
		}

		/**
		 * 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 () {
		fail("Not yet implemented"); // TODO
	}
	
	/**
	 * Test method for {@link Arguments#parse(Iterable)}.
	 */
	@Test
	public void testParseIterableOfString () {
		fail("Not yet implemented"); // TODO
	}
	
	/**
	 * Test method for {@link Arguments#usage(PrintStream)}.
	 */
	@Test
	public void testUsagePrintStream () {
		final PrintStream out = mock(PrintStream.class);
		arguments.usage(out);
		verify(out).println(anyObject());
	}
	
	/**
	 * Test method for {@link Arguments#usage()}.
	 */
	@Test
	public void testUsage () {
		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());
	}
}

@@ -113,58 +113,18 @@
 ert.
-fail;%0Aimport static org.mockito.Matchers.anyObject
+assertTrue
 ;%0Aim
@@ -776,19 +776,17 @@
 boolean 
-isU
+u
 sed;%0A%09%09/
@@ -1045,35 +1045,33 @@
 n the attribute 
-isU
+u
 sed.%0A%09%09 * @retur
@@ -1078,35 +1078,33 @@
 n the attribute 
-isU
+u
 sed.%0A%09%09 */%0A%09%09pub
@@ -1137,19 +1137,17 @@
 %09return 
-isU
+u
 sed;%0A%09%09%7D
@@ -1171,35 +1171,33 @@
 t the attribute 
-isU
+u
 sed.%0A%09%09 * @param
@@ -1197,19 +1197,17 @@
  @param 
-isU
+u
 sed the 
@@ -1216,19 +1216,17 @@
 tribute 
-isU
+u
 sed.%0A%09%09 
@@ -1265,19 +1265,17 @@
 boolean 
-isU
+u
 sed) %7B%0A%09
@@ -1285,20 +1285,16 @@
 his.
-isU
+u
 sed = 
-isU
+u
 sed;
@@ -1843,44 +1843,117 @@
 %7B%0A%09%09
-fail(%22Not yet implemented%22); // TODO
+arguments.parse(%22-u%22, %22-n%22, %22alex%22);%0A%09%09assertTrue(target.isUsed());%0A%09%09assertEquals(%22alex%22, target.getName());
 %0A%09%7D%0A
@@ -2076,47 +2076,161 @@
 %7B%0A%09%09
-fail(%22Not yet implemented%22); // TODO%0A%09%7D
+arguments.parse(%22--used%22, %22-n%22, %22alex%22);%0A%09%09assertTrue(target.isUsed());%0A%09%09assertEquals(%22alex%22, target.getName());%0A%09%7D%0A%09%0A%09// TODO add tests for error cases
 %0A%09%0A%09
@@ -2444,18 +2444,16 @@
 ln(a
-nyObject()
+rguments
 );%0A%09
@@ -2544,24 +2544,107 @@
 tUsage () %7B%0A
+%09%09// Nothing can really be done to check that the usage has been printed on stdout%0A
 %09%09arguments.

Complete tests implementation of Arguments class