public void testHelpOnEnv() throws CommandException, UnsupportedEncodingException {
   ByteArrayOutputStream os = new ByteArrayOutputStream();
   cmd.process(new String[] {"--tellmehow"}, System.in, os, System.err, null);
   String out = new String(os.toByteArray(), "UTF-8");
   assertTrue("contains additionalParams:\n" + out, out.contains(("MyParams")));
   assertTrue("contains short help:\n" + out, out.contains(("ShorterHelp")));
 }
 public void testParseWithoutParamFails() throws CommandException {
   try {
     cmd.process("-q");
     fail("Missing param for -q");
   } catch (CommandException ex) {
     // OK
     assertNull("No method called", methodCalled);
   }
 }
 public void testParseEnabledWithParamFails() {
   try {
     cmd.process("--enabled", "Param");
     fail("Parse shall not succeed");
   } catch (CommandException ex) {
     // oK
   }
   assertNull("parse not finished, enabled not set", methodCalled);
 }
 public void testParseAdditionalParam() throws CommandException {
   cmd.process("no", "-m", "Param");
   assertNotNull("Called", methodCalled);
   assertFalse("enabled not set", methodCalled.enabled);
   assertNotNull("additionalParams set", methodCalled.additionalParams);
   assertEquals("two", 2, methodCalled.additionalParams.length);
   assertEquals("no", methodCalled.additionalParams[0]);
   assertEquals("Param", methodCalled.additionalParams[1]);
 }
 public void testParseWithParam() throws CommandException {
   cmd.process("-qParam");
   assertNotNull("Method called", methodCalled);
   assertFalse("enabled not set", methodCalled.enabled);
   assertEquals("Param", methodCalled.withParam);
 }
 public void testParseEnabled() throws Exception {
   cmd.process("--on");
   assertNotNull("options processed", methodCalled);
   assertTrue("enabled set", methodCalled.enabled);
 }
 @Override
 protected void setUp() throws Exception {
   cmd = CommandLine.create(SampleOptions2.class);
   methodCalled = null;
   methodEnv = null;
 }
 public void testDefaultValueProvided() throws CommandException {
   cmd.process("--optional=value");
   assertNotNull("Options created", methodCalled);
   assertEquals("Set to value string", "value", methodCalled.defaultValue);
 }
 public void testHelp() throws CommandException {
   StringWriter w = new StringWriter();
   cmd.usage(new PrintWriter(w));
   assertTrue("contains additionalParams:\n" + w, w.toString().contains(("MyParams")));
   assertTrue("contains short help:\n" + w, w.toString().contains(("ShorterHelp")));
 }