Skip to content

Commit 8915ec4

Browse files
committed
(#42) HtHead can be broken. (tests to use Assertion)
1 parent a66e726 commit 8915ec4

File tree

1 file changed

+58
-53
lines changed

1 file changed

+58
-53
lines changed

src/test/java/org/cactoos/http/HtHeadTest.java

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@
3232
import org.cactoos.text.RepeatedText;
3333
import org.cactoos.text.ReplacedText;
3434
import org.cactoos.text.TextOf;
35-
import org.hamcrest.MatcherAssert;
3635
import org.hamcrest.Matchers;
3736
import org.hamcrest.core.IsEqual;
38-
import org.hamcrest.core.StringEndsWith;
3937
import org.junit.Test;
4038
import org.llorllale.cactoos.matchers.Assertion;
4139
import org.llorllale.cactoos.matchers.EndsWith;
@@ -54,64 +52,70 @@ public final class HtHeadTest {
5452

5553
@Test
5654
public void takesHeadOutOfHttpResponse() throws IOException {
57-
MatcherAssert.assertThat(
58-
new TextOf(
59-
new HtHead(
60-
new InputOf(
61-
new JoinedText(
62-
"\r\n",
63-
"HTTP/1.1 200 OK",
64-
"Content-type: text/plain",
65-
"",
66-
"Hello, dude!"
55+
new Assertion<>(
56+
"Header does not have 'text/plain'",
57+
() ->
58+
new TextOf(
59+
new HtHead(
60+
new InputOf(
61+
new JoinedText(
62+
"\r\n",
63+
"HTTP/1.1 200 OK",
64+
"Content-type: text/plain",
65+
"",
66+
"Hello, dude!"
67+
)
6768
)
6869
)
69-
)
70-
).asString(),
71-
new StringEndsWith("text/plain")
72-
);
70+
),
71+
new EndsWith("text/plain")
72+
).affirm();
7373
}
7474

7575
@Test
7676
public void emptyHeadOfHttpResponse() throws IOException {
77-
MatcherAssert.assertThat(
78-
new TextOf(
79-
new HtHead(
80-
new InputOf(
81-
new JoinedText(
82-
"\r\n",
83-
"",
84-
"",
85-
"Body"
77+
new Assertion<>(
78+
"Text does not have an empty string",
79+
() ->
80+
new TextOf(
81+
new HtHead(
82+
new InputOf(
83+
new JoinedText(
84+
"\r\n",
85+
"",
86+
"",
87+
"Body"
88+
)
8689
)
8790
)
88-
)
89-
),
91+
),
9092
new TextHasString("")
91-
);
93+
).affirm();
9294
}
9395

9496
@Test
9597
public void largeText() throws IOException {
9698
//@checkstyle MagicNumberCheck (1 lines)
9799
final byte[] bytes = new byte[18000];
98100
new Random().nextBytes(bytes);
99-
MatcherAssert.assertThat(
100-
new TextOf(
101-
new HtHead(
102-
new InputOf(
103-
new JoinedText(
104-
"\r\n",
105-
"HTTP/1.1 200 OK",
106-
"Content-type: text/plain",
107-
"",
108-
new TextOf(new BytesOf(bytes)).asString()
101+
new Assertion<>(
102+
"Header does not have text/plain header",
103+
() ->
104+
new TextOf(
105+
new HtHead(
106+
new InputOf(
107+
new JoinedText(
108+
"\r\n",
109+
"HTTP/1.1 200 OK",
110+
"Content-type: text/plain",
111+
"",
112+
new TextOf(new BytesOf(bytes)).asString()
113+
)
109114
)
110115
)
111-
)
112-
).asString(),
113-
new StringEndsWith("text/plain")
114-
);
116+
),
117+
new EndsWith("text/plain")
118+
).affirm();
115119
}
116120

117121
@Test
@@ -139,20 +143,21 @@ public void edgeOfTheBlockTearing() throws IOException {
139143
size
140144
)
141145
).affirm();
142-
new Assertion<Text>(
146+
new Assertion<>(
143147
String.format("Edge of the block tearing for size: %s", size),
144-
() -> new TextOf(
145-
new HtHead(
146-
new InputOf(
147-
new JoinedText(
148-
"\r\n",
149-
block.asString(),
150-
"",
151-
"body here"
148+
() ->
149+
new TextOf(
150+
new HtHead(
151+
new InputOf(
152+
new JoinedText(
153+
"\r\n",
154+
block.asString(),
155+
"",
156+
"body here"
157+
)
152158
)
153159
)
154-
)
155-
),
160+
),
156161
Matchers.allOf(
157162
new StartsWith("HTTP"),
158163
new TextHasString("OK\r\nReferer"),

0 commit comments

Comments
 (0)