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