Skip to content

Commit ae33ebe

Browse files
committed
#72: Joined throw the NoArgFoundException in case if source argument wasn't specified
1 parent a149a33 commit ae33ebe

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/main/java/io/github/dgroup/term4j/arg/Joined.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public Joined(final Arg<? extends Collection<X>> args, final X... items) {
5050
* Ctor.
5151
* @param args All command-line arguments.
5252
* @param items The items to be merged into original value.
53+
* @checkstyle AnonInnerLengthCheck (30 lines)
5354
*/
5455
public Joined(final Arg<? extends Collection<X>> args, final Collection<X> items) {
5556
super(new Arg<Collection<X>>() {
@@ -60,7 +61,13 @@ public String label() {
6061

6162
@Override
6263
public Collection<X> value() throws ArgNotFoundException {
63-
return new org.cactoos.collection.Joined<>(args.value(), items);
64+
final Collection<X> val;
65+
if (this.specifiedByUser()) {
66+
val = new org.cactoos.collection.Joined<>(args.value(), items);
67+
} else {
68+
val = items;
69+
}
70+
return val;
6471
}
6572

6673
@Override

src/test/java/io/github/dgroup/term4j/arg/JoinedTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,19 @@ public void value() {
6363
new ArgHave<>("Tom", "Mike", "Hank", "Bob", "Alex")
6464
).affirm();
6565
}
66+
67+
@Test
68+
public void absent() {
69+
new Assertion<>(
70+
"The source argument wasn't specified at all",
71+
new Joined<>(
72+
new Strings(
73+
"--users",
74+
new ListOf<>("--host", "host.com")
75+
),
76+
"Bob", "Alex"
77+
),
78+
new ArgHave<>("Bob", "Alex")
79+
).affirm();
80+
}
6681
}

0 commit comments

Comments
 (0)