Home | History | Annotate | Download | only in jcommander
      1 package com.beust.jcommander;
      2 
      3 import org.testng.annotations.Test;
      4 
      5 public class ValidatePropertiesWhenParsingTest {
      6   @Test
      7   public void f()
      8       throws Exception {
      9 
     10     JCommander cmd = new JCommander();
     11 
     12     cmd.addCommand("a", new A());
     13 //    cmd.addCommand("b", new B());
     14 
     15     cmd.parse(new String[] { "a", "-path", "myPathToHappiness" });
     16   }
     17 
     18   public static class MyPathValidator implements IParameterValidator {
     19 
     20     public void validate(String name, String value) throws ParameterException {
     21       throw new RuntimeException("I shouldn't be called for command A!");
     22     }
     23   }
     24 
     25   @Parameters
     26   public static class A {
     27 
     28     @Parameter(names = "-path")
     29     private String path = "W";
     30   }
     31 
     32   @Parameters
     33   public static class B {
     34 
     35     @Parameter(names = "-path", validateWith = MyPathValidator.class)
     36     private String path = "W";
     37   }
     38 
     39   public static void main(String[] args) throws Exception {
     40     new ValidatePropertiesWhenParsingTest().f();
     41   }
     42 }