@@ -165,6 +165,26 @@ public void testGetParsedOptionValueWithOption() throws Exception {
165165 assertEquals ("foo" , cmd .getParsedOptionValue (optF ));
166166 }
167167
168+ @ Test
169+ public void testGetParsedOptionValueUsingDefault () throws Exception {
170+ final Options options = new Options ();
171+ final Option optI = Option .builder ("i" ).hasArg ().type (Number .class ).build ();
172+ final Option optF = Option .builder ("f" ).hasArg ().build ();
173+ options .addOption (optI );
174+ options .addOption (optF );
175+
176+ final CommandLineParser parser = new DefaultParser ();
177+ final CommandLine cmd = parser .parse (options , new String [] {"-i" , "123" });
178+
179+ assertEquals (123 , ((Number ) cmd .getParsedOptionValue (optI )).intValue ());
180+ assertEquals ("foo" , cmd .getParsedOptionValue (optF , "foo" ));
181+ assertEquals ("foo" , cmd .getParsedOptionValue (optF , ()->"foo" ));
182+ assertEquals ("foo" , cmd .getParsedOptionValue ("f" , "foo" ));
183+ assertEquals ("foo" , cmd .getParsedOptionValue ("f" , ()->"foo" ));
184+ assertEquals ("foo" , cmd .getParsedOptionValue ('f' , "foo" ));
185+ assertEquals ("foo" , cmd .getParsedOptionValue ('f' , ()->"foo" ));
186+ }
187+
168188 @ Test
169189 public void testNullhOption () throws Exception {
170190 final Options options = new Options ();
0 commit comments