Skip to content

Commit

Permalink
[#1571] add tests for variables in option defaultValue annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Feb 11, 2022
1 parent 135a3ff commit b9c65e4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/test/java/picocli/DefaultProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,29 @@ class App {
assertEquals(null, app1.a);
}

@Test
public void testDefaultValueWithVariable() {
@Command
class App {
@Option(names = "-a", defaultValue = "${VARIABLE:-555}")
int a;
}
System.setProperty("VARIABLE", "123");
App app1 = CommandLine.populateCommand(new App());
assertEquals(123, app1.a);
}

@Test
public void testDefaultValueWithVariableFallback() {
@Command
class App {
@Option(names = "-a", defaultValue = "${VARIABLE:-555}")
int a;
}
App app1 = CommandLine.populateCommand(new App());
assertEquals(555, app1.a);
}

static class DefaultProviderWithVariables implements IDefaultValueProvider {
static String value = "${VARIABLE:-555}";
public String defaultValue(ArgSpec argSpec) throws Exception {
Expand Down

0 comments on commit b9c65e4

Please sign in to comment.