Skip to content

Commit

Permalink
(yegor256#1035) org.cactoos.io.Joined: add a Ctor of Iterable<Input>
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyakharlamov committed Jan 22, 2019
1 parent de9031f commit 9efec7f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/java/org/cactoos/io/Joined.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,25 @@ public final class Joined implements Input {
*/
private final Iterable<Input> inputs;

/**
* Ctor.
* @param inputs Iterable of inputs
*/
public Joined(final Iterable<Input> inputs) {
this.inputs = inputs;
}

/**
* Ctor.
* @param first First input
* @param rest The rest
*/
public Joined(final Input first, final Input... rest) {
this.inputs = new org.cactoos.iterable.Joined<>(
first,
new IterableOf<>(rest)
this(
new org.cactoos.iterable.Joined<>(
first,
new IterableOf<>(rest)
)
);
}

Expand Down
21 changes: 21 additions & 0 deletions src/test/java/org/cactoos/io/JoinedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.cactoos.io;

import java.io.IOException;
import org.cactoos.iterable.IterableOf;
import org.cactoos.text.TextOf;
import org.hamcrest.MatcherAssert;
import org.junit.Test;
Expand Down Expand Up @@ -52,4 +53,24 @@ public void joinsOk() throws IOException {
new TextHasString("firstsecondthird")
);
}

/**
* Must join inputs of the iterable in the given order
*/
@Test
public void fromIterable() {
MatcherAssert.assertThat(
"Cannot join iterable of inputs",
new TextOf(
new Joined(
new IterableOf<>(
new InputOf("ab"),
new InputOf("cde"),
new InputOf("fghi")
)
)
),
new TextHasString("abcdefghi")
);
}
}

0 comments on commit 9efec7f

Please sign in to comment.