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
…(test cleanup)
  • Loading branch information
ilyakharlamov committed Jan 25, 2019
1 parent 1826c76 commit 2dce54a
Showing 1 changed file with 12 additions and 59 deletions.
71 changes: 12 additions & 59 deletions src/test/java/org/cactoos/io/JoinedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@
*/
package org.cactoos.io;

import java.io.DataInputStream;
import java.io.IOException;
import org.cactoos.bytes.HexOf;
import org.cactoos.iterable.IterableOf;
import org.cactoos.text.TextOf;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.TextHasString;
import org.llorllale.cactoos.matchers.InputHasContent;

/**
* Unit tests for {@link Joined}.
Expand All @@ -47,14 +43,12 @@ public final class JoinedTest {
public void joinsOk() {
new Assertion<>(
"Cannot properly join inputs",
() -> new TextOf(
new Joined(
new InputOf("first"),
new InputOf("second"),
new InputOf("third")
)
() -> new Joined(
new InputOf("first"),
new InputOf("second"),
new InputOf("third")
),
new TextHasString("firstsecondthird")
new InputHasContent("firstsecondthird")
).affirm();
}

Expand All @@ -65,55 +59,14 @@ public void joinsOk() {
public void fromIterable() {
new Assertion<>(
"Can't join iterable of inputs",
() -> new TextOf(
new Joined(
new IterableOf<>(
new InputOf("ab"),
new InputOf("cde"),
new InputOf("fghi")
)
)
),
new TextHasString("abcdefghi")
).affirm();
}

/**
* Must join inputs of the iterable bytes.
* @checkstyle MagicNumberCheck (20 lines)
* @throws Exception If an error occurs
*/
@Test
public void fromIterableInputOfBytes() throws Exception {
final byte[] result = new byte[6];
new DataInputStream(
new Joined(
() -> new Joined(
new IterableOf<>(
new InputOf(
new BytesOf(
(byte) 202,
(byte) 254,
(byte) 186,
(byte) 190
)
),
new InputOf(
new BytesOf(
(byte) 222,
(byte) 173
)
)
new InputOf("ab"),
new InputOf("cde"),
new InputOf("fghi")
)
).stream()
).readFully(result);
new Assertion<>(
"The merged stream does not equal to the expected sum of 2",
() -> result,
new IsEqual<>(
new HexOf(
new TextOf("CAFEBABEDEAD")
).asBytes()
)
),
new InputHasContent("abcdefghi")
).affirm();
}
}

0 comments on commit 2dce54a

Please sign in to comment.