Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Feb 21, 2019
2 parents df1f2f1 + 17d5d0b commit c7adbfe
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/takes/rs/RsPrint.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* <p>The class is immutable and thread-safe.
*
* @since 0.1
* @todo #804:30min Continue removing Guava's code from tests, starting
* @todo #888:30min Continue removing Guava's code from tests, starting
* with all the calls to Joiner by replacing them with Cactoos JoinedText
* and the use of cactoos-matchers TextIs or TextHasContent coupled with this
* class RsPrint as a Text as it was started in #804. When there is no more
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/org/takes/facets/cookies/RsWithCookieTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
*/
package org.takes.facets.cookies;

import com.google.common.base.Joiner;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.cactoos.text.JoinedText;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
Expand Down Expand Up @@ -118,16 +118,17 @@ public void rejectsInvalidValue() {
* Returns the joined cookie.
* @param cookies Cookies values
* @return Joined cookie
* @throws IOException when there is a problem
*/
private static String cookies(final String... cookies) {
private static String cookies(final String... cookies) throws IOException {
final List<String> list = new ArrayList<>(cookies.length + 3);
list.add("HTTP/1.1 200 OK");
for (final String cookie : cookies) {
list.add(String.format("Set-Cookie: %s;", cookie));
}
list.add("");
list.add("");
return Joiner.on("\r\n").join(list.iterator());
return new JoinedText("\r\n", list).asString();
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/org/takes/facets/fork/FkChainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
package org.takes.facets.fork;

import com.google.common.base.Joiner;
import org.cactoos.text.JoinedText;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
Expand Down Expand Up @@ -67,13 +67,14 @@ public void dispatchesByRegularExpression() throws Exception {
).route(new RqFake("GET", "/hey?yu")).get()
).print(),
Matchers.equalTo(
Joiner.on("\r\n").join(
new JoinedText(
"\r\n",
"HTTP/1.1 200 OK",
String.format("Content-Length: %s", body.length()),
"Content-Type: text/plain",
"",
body
)
).asString()
)
);
}
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/org/takes/facets/fork/TkConsumesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
*/
package org.takes.facets.fork;

import com.google.common.base.Joiner;
import java.io.IOException;
import java.util.Arrays;
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import org.cactoos.text.JoinedText;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
Expand Down Expand Up @@ -75,10 +75,11 @@ public void acceptsCorrectContentTypeRequest() throws IOException {
MatcherAssert.assertThat(
new RsPrint(response).print(),
Matchers.startsWith(
Joiner.on("\r\n").join(
new JoinedText(
"\r\n",
"HTTP/1.1 200 OK",
contenttype
)
).asString()
)
);
}
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/org/takes/facets/fork/TkForkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
package org.takes.facets.fork;

import com.google.common.base.Joiner;
import java.io.IOException;
import org.cactoos.text.JoinedText;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
Expand All @@ -51,13 +51,14 @@ public void dispatchesByRegularExpression() throws IOException {
)
).print(),
Matchers.equalTo(
Joiner.on("\r\n").join(
new JoinedText(
"\r\n",
"HTTP/1.1 200 OK",
String.format("Content-Length: %s", body.length()),
"Content-Type: text/plain",
"",
body
)
).asString()
)
);
}
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/org/takes/facets/fork/TkProducesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*/
package org.takes.facets.fork;

import com.google.common.base.Joiner;
import java.io.IOException;
import java.util.Arrays;
import org.cactoos.text.JoinedText;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
Expand All @@ -42,6 +42,7 @@
/**
* Test case for {@link TkProduces}.
* @since 0.14
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
public final class TkProducesTest {

Expand Down Expand Up @@ -90,12 +91,12 @@ public void producesCorrectContentTypeResponse() throws IOException {
MatcherAssert.assertThat(
new RsPrint(response).print(),
Matchers.equalTo(
Joiner.on("\r\n").join(
"HTTP/1.1 200 OK",
new JoinedText(
"\r\n", "HTTP/1.1 200 OK",
"Content-Type: application/json",
"",
""
)
).asString()
)
);
}
Expand Down
69 changes: 40 additions & 29 deletions src/test/java/org/takes/http/BkBasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package org.takes.http;

import com.google.common.base.Joiner;
import com.jcabi.http.request.JdkRequest;
import com.jcabi.http.response.RestResponse;
import com.jcabi.matchers.RegexMatchers;
Expand All @@ -37,6 +36,8 @@
import java.net.URI;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicReference;
import org.cactoos.io.BytesOf;
import org.cactoos.text.JoinedText;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Ignore;
Expand Down Expand Up @@ -82,10 +83,10 @@ public final class BkBasicTest {
/**
* BkBasic can handle socket data.
*
* @throws IOException If some problem inside
* @throws Exception If some problem inside
*/
@Test
public void handlesSocket() throws IOException {
public void handlesSocket() throws Exception {
final MkSocket socket = BkBasicTest.createMockSocket();
final ByteArrayOutputStream baos = socket.bufferedOutput();
final String hello = "Hello World";
Expand Down Expand Up @@ -124,10 +125,10 @@ public void exec(final URI home) throws IOException {
/**
* BkBasic produces headers with addresses without slashes.
*
* @throws IOException If some problem inside
* @throws Exception If some problem inside
*/
@Test
public void addressesInHeadersAddedWithoutSlashes() throws IOException {
public void addressesInHeadersAddedWithoutSlashes() throws Exception {
final Socket socket = BkBasicTest.createMockSocket();
final AtomicReference<Request> ref = new AtomicReference<>();
new BkBasic(
Expand Down Expand Up @@ -211,7 +212,8 @@ public void run() {
)
) {
socket.getOutputStream().write(
Joiner.on(BkBasicTest.CRLF).join(
new JoinedText(
BkBasicTest.CRLF,
BkBasicTest.POST,
BkBasicTest.HOST,
"Content-Length: 11",
Expand All @@ -222,7 +224,7 @@ public void run() {
"Content-Length: 12",
"",
"Hello Second"
).getBytes()
).asString().getBytes()
);
final InputStream input = socket.getInputStream();
// @checkstyle MagicNumber (1 line)
Expand Down Expand Up @@ -273,12 +275,15 @@ public void run() {
)
) {
socket.getOutputStream().write(
Joiner.on(BkBasicTest.CRLF).join(
BkBasicTest.POST,
BkBasicTest.HOST,
"",
text
).getBytes()
new BytesOf(
new JoinedText(
BkBasicTest.CRLF,
BkBasicTest.POST,
BkBasicTest.HOST,
"",
text
)
).asBytes()
);
final InputStream input = socket.getInputStream();
// @checkstyle MagicNumber (1 line)
Expand Down Expand Up @@ -327,13 +332,16 @@ public void run() {
)
) {
socket.getOutputStream().write(
Joiner.on(BkBasicTest.CRLF).join(
BkBasicTest.POST,
BkBasicTest.HOST,
"Connection: Close",
"",
greetings
).getBytes()
new BytesOf(
new JoinedText(
BkBasicTest.CRLF,
BkBasicTest.POST,
BkBasicTest.HOST,
"Connection: Close",
"",
greetings
)
).asBytes()
);
final InputStream input = socket.getInputStream();
// @checkstyle MagicNumber (1 line)
Expand All @@ -354,18 +362,21 @@ public void run() {
* Creates Socket mock for reuse.
*
* @return Prepared Socket mock
* @throws IOException If some problem inside
* @throws Exception If some problem inside
*/
private static MkSocket createMockSocket() throws IOException {
private static MkSocket createMockSocket() throws Exception {
return new MkSocket(
new ByteArrayInputStream(
Joiner.on(BkBasicTest.CRLF).join(
"GET / HTTP/1.1",
BkBasicTest.HOST,
"Content-Length: 2",
"",
"hi"
).getBytes()
new BytesOf(
new JoinedText(
BkBasicTest.CRLF,
"GET / HTTP/1.1",
BkBasicTest.HOST,
"Content-Length: 2",
"",
"hi"
)
).asBytes()
)
);
}
Expand Down
19 changes: 12 additions & 7 deletions src/test/java/org/takes/misc/ConcatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
*/
package org.takes.misc;

import com.google.common.base.Joiner;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import org.cactoos.text.JoinedText;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
Expand All @@ -39,32 +40,36 @@ public final class ConcatTest {

/**
* Concat can concatenate.
* @throws IOException when there is a problem
*/
@Test
public void concatenates() {
public void concatenates() throws IOException {
MatcherAssert.assertThat(
Joiner.on(" ").join(
new JoinedText(
" ",
new Concat<String>(
Arrays.asList("one", "two"),
Arrays.asList("three", "four")
)
),
).asString(),
Matchers.equalTo("one two three four")
);
}

/**
* Concat can concatenate with empty list.
* @throws IOException when there is a problem
*/
@Test
public void concatenatesWithEmptyList() {
public void concatenatesWithEmptyList() throws IOException {
MatcherAssert.assertThat(
Joiner.on("+").join(
new JoinedText(
"+",
new Concat<String>(
Arrays.asList("five", "six"),
Collections.<String>emptyList()
)
),
).asString(),
Matchers.equalTo("five+six")
);
}
Expand Down
11 changes: 7 additions & 4 deletions src/test/java/org/takes/misc/TransformTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
*/
package org.takes.misc;

import com.google.common.base.Joiner;
import java.io.IOException;
import java.util.Arrays;
import org.cactoos.text.JoinedText;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
Expand All @@ -38,11 +39,13 @@ public final class TransformTest {

/**
* Transform can transform list.
* @throws IOException when there is a problem
*/
@Test
public void transformsList() {
public void transformsList() throws IOException {
MatcherAssert.assertThat(
Joiner.on(" ").join(
new JoinedText(
" ",
new Transform<String, String>(
Arrays.asList("one", "two", "three"),
new TransformAction<String, String>() {
Expand All @@ -52,7 +55,7 @@ public String transform(final String element) {
}
}
)
),
).asString(),
Matchers.equalTo("onet twot threet")
);
}
Expand Down

2 comments on commit c7adbfe

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on c7adbfe Feb 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 804-1f63803d disappeared from src/main/java/org/takes/rs/RsPrint.java, that's why I closed #888. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on c7adbfe Feb 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 888-1f63803d discovered in src/main/java/org/takes/rs/RsPrint.java and submitted as #968. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.