Skip to content

Commit b3d8853

Browse files
author
Sascha Hagedorn
committed
Fix test and add test for unknown property
1 parent 4cf8d3b commit b3d8853

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package com.cleancoder.args;
22

3+
import java.util.Arrays;
4+
import java.util.List;
5+
36
public 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
}

src/test/java/com/cleancoder/args/ArgsTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import org.assertj.core.util.Arrays;
44
import org.junit.Test;
55

6-
import static org.assertj.core.api.Assertions.assertThat;
6+
import static org.assertj.core.api.Assertions.*;
77

88
public 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
}

0 commit comments

Comments
 (0)