summaryrefslogtreecommitdiff
path: root/src/test/java/com/beust/jcommander/ValidatePropertiesWhenParsingTest.java
blob: 6a3a98f73bb22cefb8fdeb79b9909c603e39b4f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.beust.jcommander;

import org.testng.annotations.Test;

public class ValidatePropertiesWhenParsingTest {
  @Test
  public void f()
      throws Exception {

    JCommander cmd = new JCommander();

    cmd.addCommand("a", new A());
//    cmd.addCommand("b", new B());

    cmd.parse(new String[] { "a", "-path", "myPathToHappiness" });
  }

  public static class MyPathValidator implements IParameterValidator {

    public void validate(String name, String value) throws ParameterException {
      throw new RuntimeException("I shouldn't be called for command A!");
    }
  }

  @Parameters
  public static class A {

    @Parameter(names = "-path")
    private String path = "W";
  }

  @Parameters
  public static class B {

    @Parameter(names = "-path", validateWith = MyPathValidator.class)
    private String path = "W";
  }

  public static void main(String[] args) throws Exception {
    new ValidatePropertiesWhenParsingTest().f();
  }
}