Skip to content

Commit

Permalink
#2102 PropertiesDefaultProvider at first try to load properties from …
Browse files Browse the repository at this point in the history
…classpath

- addded test for read default values from resource classpath
  • Loading branch information
Lumír Návrat authored and remkop committed Sep 18, 2023
1 parent b4434f4 commit 6b047ae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/test/java/picocli/PropertiesDefaultProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ static class Subcommand {
@Parameters(index = "0", paramLabel = "qqq", descriptionKey = "xxx") int xxx;
}

@Test
public void testLoadFromResourceClasspathIfPropertySpecified() throws IOException {
Properties expected = new Properties();
expected.setProperty("aaa", "111");
expected.setProperty("bbb", "222");
expected.setProperty("ppp", "333");
expected.setProperty("xxx", "444");

MyApp myApp = new MyApp();
assertEquals(myApp.aaa, 0);
assertEquals(myApp.bbb, 0);
assertEquals(myApp.ppp, 0);
assertEquals(myApp.xxx, 0);
new CommandLine(myApp).parseArgs();

assertEquals(myApp.aaa, 111);
assertEquals(myApp.bbb, 222);
assertEquals(myApp.ppp, 333);
assertEquals(myApp.xxx, 444);
}

@Test
public void testLoadFromUserHomeCommandNameByDefault() throws IOException {
File f = new File(System.getProperty("user.home"), ".providertest.properties");
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/.providertest.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#exported from test
#Mon Sep 18 12:37:21 CEST 2023
aaa=111
ppp=333
bbb=222
xxx=444

0 comments on commit 6b047ae

Please sign in to comment.