Skip to content

Commit

Permalink
(#1443) Use takes instead of external resource
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Apr 29, 2021
1 parent fd1b1ca commit b926999
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/test/java/org/cactoos/io/InputOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,8 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.cactoos.Text;
import org.cactoos.bytes.BytesOf;
import org.cactoos.text.TextOf;
import org.hamcrest.core.AllOf;
Expand All @@ -49,12 +44,16 @@
import org.llorllale.cactoos.matchers.EndsWith;
import org.llorllale.cactoos.matchers.HasContent;
import org.llorllale.cactoos.matchers.HasString;
import org.llorllale.cactoos.matchers.IsText;
import org.llorllale.cactoos.matchers.IsTrue;
import org.llorllale.cactoos.matchers.MatchesRegex;
import org.llorllale.cactoos.matchers.StartsWith;
import org.llorllale.cactoos.matchers.Verifies;
import org.takes.facets.fork.FkRegex;
import org.takes.facets.fork.TkFork;
import org.takes.http.FtRemote;
import org.takes.tk.TkHtml;
import org.takes.tk.TkText;

/**
* Test case for {@link InputOf}.
Expand All @@ -63,7 +62,7 @@
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
* @checkstyle ClassFanOutComplexityCheck (500 lines)
*/
@SuppressWarnings({ "PMD.TooManyMethods", "PMD.ExcessiveImports", "unchecked" })
@SuppressWarnings({"PMD.TooManyMethods", "PMD.ExcessiveImports", "unchecked"})
final class InputOfTest {
@Test
void readsAlternativeInputForFileCase() {
Expand Down Expand Up @@ -302,7 +301,7 @@ void readsEncodedStringFromReader() throws Exception {

@Test
void readsAnArrayOfBytes() throws Exception {
final byte[] bytes = new byte[] {(byte) 0xCA, (byte) 0xFE};
final byte[] bytes = new byte[]{(byte) 0xCA, (byte) 0xFE};
new Assertion<>(
"must read array of bytes",
new BytesOf(
Expand All @@ -323,18 +322,15 @@ void makesDataAvailable() throws Exception {
}

@Test
void readsSecureUrlContent() throws Exception {
new Assertion<>(
"Must read bytes from HTTPS URL",
new BytesOf(
new InputOf(
new URL(
"https://www.yegor256.com/robots.txt"
)
)
).asBytes(),
new Verifies<>(arr -> arr.length > 0)
).affirm();
void readsUrlContent() throws Exception {
final Text data = new TextOf("hello");
new FtRemote(new TkFork(new FkRegex("/", new TkText(data.asString())))).exec(
uri -> new Assertion<>(
"Must read bytes from HTTPS URL",
new TextOf(new InputOf(uri)),
new IsText(data)
).affirm()
);
}

}

0 comments on commit b926999

Please sign in to comment.