File tree Expand file tree Collapse file tree
main/java/com/cleancoder/args
test/java/com/cleancoder/args Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,11 +9,16 @@ public class ArgsMain {
99
1010 public ArgsMain (String [] givenArgs ) {
1111 this .givenArgs = Arrays .asList (givenArgs );
12- if (this .givenArgs .contains ("-u" ))
12+
13+ if (this .givenArgs .stream ().anyMatch (arg -> !isAllowed (arg )))
1314 throw new IllegalArgumentException ("Parameter -u is not supported" );
1415 }
1516
1617 boolean isHelp () {
1718 return givenArgs .contains ("-h" );
1819 }
20+
21+ private boolean isAllowed (String arg ) {
22+ return arg .equals ("-h" );
23+ }
1924}
Original file line number Diff line number Diff line change @@ -27,7 +27,12 @@ public void detectWhenHelpIsNotRequested() {
2727
2828 @ Test
2929 public void shouldThrowIllegalArgumentExceptionOnUnknownArg () {
30- assertThatIllegalArgumentException ().isThrownBy (() -> new ArgsMain (Arrays .array ("-u" )));
31- assertThatIllegalArgumentException ().isThrownBy (() -> new ArgsMain (Arrays .array ("-k" )));
30+ assertThatIllegalArgumentException ()
31+ .isThrownBy (() -> new ArgsMain (Arrays .array ("-u" )))
32+ .withMessage ("Parameter -u is not supported" );
33+
34+ assertThatIllegalArgumentException ()
35+ .isThrownBy (() -> new ArgsMain (Arrays .array ("-k" )))
36+ .withMessage ("Parameter -k is not supported" );
3237 }
3338}
You can’t perform that action at this time.
0 commit comments