Skip to content

Commit

Permalink
(#42) HtHead can be broken. (tests to use Assertion)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyakharlamov committed Jan 21, 2019
1 parent a66e726 commit 8915ec4
Showing 1 changed file with 58 additions and 53 deletions.
111 changes: 58 additions & 53 deletions src/test/java/org/cactoos/http/HtHeadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
import org.cactoos.text.RepeatedText;
import org.cactoos.text.ReplacedText;
import org.cactoos.text.TextOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.StringEndsWith;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.EndsWith;
Expand All @@ -54,64 +52,70 @@ public final class HtHeadTest {

@Test
public void takesHeadOutOfHttpResponse() throws IOException {
MatcherAssert.assertThat(
new TextOf(
new HtHead(
new InputOf(
new JoinedText(
"\r\n",
"HTTP/1.1 200 OK",
"Content-type: text/plain",
"",
"Hello, dude!"
new Assertion<>(
"Header does not have 'text/plain'",
() ->
new TextOf(
new HtHead(
new InputOf(
new JoinedText(
"\r\n",
"HTTP/1.1 200 OK",
"Content-type: text/plain",
"",
"Hello, dude!"
)
)
)
)
).asString(),
new StringEndsWith("text/plain")
);
),
new EndsWith("text/plain")
).affirm();
}

@Test
public void emptyHeadOfHttpResponse() throws IOException {
MatcherAssert.assertThat(
new TextOf(
new HtHead(
new InputOf(
new JoinedText(
"\r\n",
"",
"",
"Body"
new Assertion<>(
"Text does not have an empty string",
() ->
new TextOf(
new HtHead(
new InputOf(
new JoinedText(
"\r\n",
"",
"",
"Body"
)
)
)
)
),
),
new TextHasString("")
);
).affirm();
}

@Test
public void largeText() throws IOException {
//@checkstyle MagicNumberCheck (1 lines)
final byte[] bytes = new byte[18000];
new Random().nextBytes(bytes);
MatcherAssert.assertThat(
new TextOf(
new HtHead(
new InputOf(
new JoinedText(
"\r\n",
"HTTP/1.1 200 OK",
"Content-type: text/plain",
"",
new TextOf(new BytesOf(bytes)).asString()
new Assertion<>(
"Header does not have text/plain header",
() ->
new TextOf(
new HtHead(
new InputOf(
new JoinedText(
"\r\n",
"HTTP/1.1 200 OK",
"Content-type: text/plain",
"",
new TextOf(new BytesOf(bytes)).asString()
)
)
)
)
).asString(),
new StringEndsWith("text/plain")
);
),
new EndsWith("text/plain")
).affirm();
}

@Test
Expand Down Expand Up @@ -139,20 +143,21 @@ public void edgeOfTheBlockTearing() throws IOException {
size
)
).affirm();
new Assertion<Text>(
new Assertion<>(
String.format("Edge of the block tearing for size: %s", size),
() -> new TextOf(
new HtHead(
new InputOf(
new JoinedText(
"\r\n",
block.asString(),
"",
"body here"
() ->
new TextOf(
new HtHead(
new InputOf(
new JoinedText(
"\r\n",
block.asString(),
"",
"body here"
)
)
)
)
),
),
Matchers.allOf(
new StartsWith("HTTP"),
new TextHasString("OK\r\nReferer"),
Expand Down

0 comments on commit 8915ec4

Please sign in to comment.