summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/beust/jcommander/ValidatePropertiesWhenParsingTest.java
blob: e237d73b00b490096df1735a5625d4ecc8696986 (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
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.parse("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();
  }
}