@@ -79,7 +79,7 @@ public void foundValidatesArgumentId() {
7979 try {
8080 Args args = new Args ("x" , new String [0 ]);
8181 args .found ('y' );
82- fail ("Args constructor should have thrown exception." );
82+ fail ("found() should have thrown exception." );
8383 } catch (ArgsException e ) {
8484 assertThat (e .getErrorCode (), is (UNKNOWN_ARGUMENT_NAME ));
8585 assertThat (e .getErrorArgumentId (), is ('y' ));
@@ -98,7 +98,7 @@ public void getBooleanValidatesArgumentType() {
9898 try {
9999 Args args = new Args ("x#" , new String [0 ]);
100100 args .getBoolean ('x' );
101- fail ("Args constructor should have thrown exception." );
101+ fail ("getBoolean() should have thrown exception." );
102102 } catch (ArgsException e ) {
103103 assertThat (e .getErrorCode (), is (WRONG_ARGUMENT_TYPE ));
104104 assertThat (e .getErrorArgumentId (), is ('x' ));
@@ -136,6 +136,18 @@ public void missingInteger() {
136136 }
137137 }
138138
139+ @ Test
140+ public void getIntOrDefaultReturnsValue () throws ArgsException {
141+ Args args = new Args ("x#" , new String [] { "-x" , "42" });
142+ assertThat (args .getIntOrDefault ('x' , 21 ), is (42 ));
143+ }
144+
145+ @ Test
146+ public void getIntOrDefaultReturnsDefault () throws ArgsException {
147+ Args args = new Args ("x#" , new String [0 ]);
148+ assertThat (args .getIntOrDefault ('x' , 21 ), is (21 ));
149+ }
150+
139151 @ Test
140152 public void simpleDoublePresent () throws ArgsException {
141153 Args args = new Args ("x##" , new String [] { "-x" , "42.3" });
@@ -166,6 +178,18 @@ public void missingDouble() {
166178 }
167179 }
168180
181+ @ Test
182+ public void getDoubleOrDefaultReturnsValue () throws ArgsException {
183+ Args args = new Args ("x##" , new String [] { "-x" , "42" });
184+ assertThat (args .getDoubleOrDefault ('x' , 21 ), is (42.0 ));
185+ }
186+
187+ @ Test
188+ public void getDoubleOrDefaultReturnsDefault () throws ArgsException {
189+ Args args = new Args ("x##" , new String [0 ]);
190+ assertThat (args .getDoubleOrDefault ('x' , 21 ), is (21.0 ));
191+ }
192+
169193 @ Test
170194 public void simpleStringPresent () throws ArgsException {
171195 Args args = new Args ("x*" , new String [] { "-x" , "param" });
@@ -185,6 +209,18 @@ public void missingString() {
185209 }
186210 }
187211
212+ @ Test
213+ public void getStringOrDefaultReturnsValue () throws ArgsException {
214+ Args args = new Args ("x*" , new String [] { "-x" , "Fourty Two" });
215+ assertThat (args .getStringOrDefault ('x' , "Twenty One" ), is (equalTo ("Fourty Two" )));
216+ }
217+
218+ @ Test
219+ public void getStringOrDefaultReturnsDefault () throws ArgsException {
220+ Args args = new Args ("x*" , new String [0 ]);
221+ assertThat (args .getStringOrDefault ('x' , "Twenty One" ), is (equalTo ("Twenty One" )));
222+ }
223+
188224 @ Test
189225 public void simpleStringArrayPresent () throws ArgsException {
190226 Args args = new Args ("x[*]" , new String [] { "-x" , "alpha" });
0 commit comments