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 11package com .cleancoder .args ;
22
3+ import java .util .Arrays ;
4+ import java .util .List ;
5+
36public class ArgsMain {
47
8+ private final List <String > givenArgs ;
9+
510 public ArgsMain (String [] givenArgs ) {
11+ this .givenArgs = Arrays .asList (givenArgs );
612 }
713
814 boolean isHelp () {
9- return true ;
15+ return givenArgs . contains ( "-h" ) ;
1016 }
1117}
Original file line number Diff line number Diff line change 33import org .assertj .core .util .Arrays ;
44import org .junit .Test ;
55
6- import static org .assertj .core .api .Assertions .assertThat ;
6+ import static org .assertj .core .api .Assertions .* ;
77
88public class ArgsTest {
99
1010 @ Test
11- public void testCreateWithNoSchemaOrArguments () {
11+ public void detectWhenHelpIsRequested () {
1212 ArgsMain args = new ArgsMain (Arrays .array ("-h" ));
1313
1414 boolean helpRequested = args .isHelp ();
@@ -24,4 +24,9 @@ public void detectWhenHelpIsNotRequested() {
2424
2525 assertThat (helpRequested ).isFalse ();
2626 }
27+
28+ @ Test
29+ public void shouldThrowIllegalArgumentExceptionOnUnknownArg () {
30+ assertThatIllegalArgumentException ().isThrownBy (() -> new ArgsMain (Arrays .array ("-u" )));
31+ }
2732}
You can’t perform that action at this time.
0 commit comments