Java Code Examples for org.llorllale.cactoos.matchers.TextHasString

The following examples show how to use org.llorllale.cactoos.matchers.TextHasString. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: cactoos-http   Source File: HtHeadTest.java    License: MIT License 6 votes vote down vote up
@Test
public void emptyHeadOfHttpResponse()  {
    new Assertion<>(
        "Text does not have an empty string",
        new TextOf(
            new HtHead(
                new InputOf(
                    new Joined(
                        "\r\n",
                        "",
                        "",
                        "Body"
                    )
                )
            )
        ),
        new TextHasString("")
    ).affirm();
}
 
Example 2
Source Project: cactoos-http   Source File: HtKeepAliveResponseTest.java    License: MIT License 6 votes vote down vote up
@Test
public void worksFineByInputReq() throws IOException {
    new FtRemote(new TkText("Hello, world!")).exec(
        home -> new Assertion<>(
            "The HTTP response contains 200 status code",
            new TextOf(
                new HtKeepAliveResponse(
                    new HtWire(home),
                    5000,
                    5,
                    new Get(home)
                )
            ),
            new TextHasString("HTTP/1.1 200 OK")
        ).affirm()
    );
}
 
Example 3
Source Project: cactoos   Source File: Sha1DigestOfTest.java    License: MIT License 6 votes vote down vote up
@Test
public void checksumFromFile() throws Exception {
    new Assertion<>(
        "Can't calculate the file's SHA-1 checksum",
        new HexOf(
            new Sha1DigestOf(
                new Sticky(
                    new InputOf(
                        new ResourceOf(
                            "org/cactoos/digest-calculation.txt"
                        ).stream()
                    )
                )
            )
        ),
        new TextHasString(
            "34f80bdab9b93af514004f127e440139aad63e2d"
        )
    ).affirm();
}
 
Example 4
Source Project: cactoos-http   Source File: HtTimedWireTest.java    License: MIT License 6 votes vote down vote up
@Test
public void worksFine() throws Exception {
    // @checkstyle MagicNumberCheck (1 line)
    final long timeout = 1000;
    new FtRemote(new TkText("Hello, world!")).exec(
        home -> MatcherAssert.assertThat(
            new TextOf(
                new HtResponse(
                    new HtTimedWire(new HtWire(home), timeout),
                    new Get(home)
                )
            ),
            new TextHasString("HTTP/1.1 200 ")
        )
    );
}
 
Example 5
Source Project: cactoos-http   Source File: HtBodyTest.java    License: MIT License 6 votes vote down vote up
@Test
public void takesBodyOutOfHttpResponse() {
    MatcherAssert.assertThat(
        new TextOf(
            new HtBody(
                new InputOf(
                    new Joined(
                        "\r\n",
                        "HTTP/1.1 200 OK",
                        "Content-type: text/plain",
                        "",
                        "Hello, dude!",
                        "How are you?"
                    )
                )
            )
        ),
        new TextHasString("Hello, dude!\r\nHow are you?")
    );
}
 
Example 6
Source Project: cactoos-http   Source File: SkipInputTest.java    License: MIT License 6 votes vote down vote up
@Test
public void skipsEverythingWhenEndingWithDelimiter() throws Exception {
    final String delimiter = "\r\n";
    MatcherAssert.assertThat(
        new TextOf(
            new SkipInput(
                new InputOf(
                    new Joined(
                        "",
                        "Hello dude! How are you?",
                        delimiter
                    )
                ),
                new BytesOf(delimiter)
            )
        ),
        new TextHasString("")
    );
}
 
Example 7
Source Project: cactoos   Source File: Sha256DigestOfTest.java    License: MIT License 6 votes vote down vote up
@Test
public void checksumFromFile() throws Exception {
    new Assertion<>(
        "Can't calculate the file's SHA-256 checksum",
        new HexOf(
            new Sha256DigestOf(
                new Sticky(
                    new InputOf(
                        new ResourceOf(
                            "org/cactoos/digest-calculation.txt"
                        ).stream()
                    )
                )
            )
        ),
        new TextHasString(
            // @checkstyle LineLengthCheck (1 lines)
            "c94451bd1476a3728669de11e22c645906d806e63a95c5797de1f3e84f126a3e"
        )
    ).affirm();
}
 
Example 8
Source Project: cactoos   Source File: TextOfTest.java    License: MIT License 6 votes vote down vote up
@Test
public void printsStackTrace() {
    new Assertion<>(
        "Can't print exception stacktrace",
        new TextOf(
            new IOException(
                "It doesn't work at all"
            )
        ),
        new TextHasString(
            new Joined(
                System.lineSeparator(),
                "java.io.IOException: It doesn't work at all",
                "\tat org.cactoos.text.TextOfTest"
            )
        )
    ).affirm();
}
 
Example 9
Source Project: cactoos   Source File: InputOfTest.java    License: MIT License 6 votes vote down vote up
@Test
public void readsStringUrl() throws IOException {
    new Assertion<>(
        "must fetch bytes from the HTTPS URL",
        new TextOf(
            new BytesOf(
                new InputOf(
                    new URL(
                        // @checkstyle LineLength (1 line)
                        "file:src/test/resources/org/cactoos/large-text.txt"
                    )
                )
            )
        ),
        new TextHasString("Lorem ipsum")
    ).affirm();
}
 
Example 10
Source Project: cactoos-jdbc   Source File: QuerySimpleTest.java    License: MIT License 5 votes vote down vote up
@Test
public void withoutValues() throws Exception {
    MatcherAssert.assertThat(
        "Can't build a named query without values",
        new QuerySimple("SELECT * FROM employee"),
        new TextHasString("SELECT * FROM employee")
    );
}
 
Example 11
Source Project: cactoos-jdbc   Source File: QuerySimpleTest.java    License: MIT License 5 votes vote down vote up
@Test
public void valid() throws Exception {
    MatcherAssert.assertThat(
        "Can't build a simple named query",
        new QuerySimple(
            "INSERT INTO foo2 (name) VALUES (:name)",
            new ParamText("name", "Yegor Bugayenko")
        ),
        new TextHasString("INSERT INTO foo2 (name) VALUES (?)")
    );
}
 
Example 12
Source Project: cactoos   Source File: Md5DigestOfTest.java    License: MIT License 5 votes vote down vote up
@Test
public void checksumOfEmptyString() {
    new Assertion<>(
        "Can't calculate the empty string's MD5 checksum",
        new HexOf(
            new Md5DigestOf(
                new InputOf("")
            )
        ),
        new TextHasString(
            "d41d8cd98f00b204e9800998ecf8427e"
        )
    ).affirm();
}
 
Example 13
Source Project: cactoos-http   Source File: HtAutoClosedResponseTest.java    License: MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public void closesResponseAndThusSocketWhenEofIsReached() throws Exception {
    new FtRemote(new TkText("Hey")).exec(
        home -> {
            @SuppressWarnings("resource")
            final Socket socket = new Socket(
                home.getHost(),
                home.getPort()
            );
            try (InputStream ins = new HtAutoClosedResponse(
                new HtResponse(
                    new HtWire(() -> socket),
                    new Get(home)
                )
            ).stream()) {
                new Assertion<>(
                    "must have a response",
                    new TextOf(new ReadBytes(ins)),
                    new TextHasString("HTTP/1.1 200 OK")
                ).affirm();
                new Assertion<>(
                    "must close the response, thus the socket, after EOF",
                    socket.isClosed(),
                    new IsTrue()
                ).affirm();
                new Assertion<>(
                    "must behave as closed",
                    ins::available,
                    new Throws<>("Stream closed.", IOException.class)
                ).affirm();
                // @checkstyle IllegalCatchCheck (1 line)
            } catch (final Exception ex) {
                throw new IOException(ex);
            }
        }
    );
}
 
Example 14
Source Project: cactoos-http   Source File: HtKeepAliveResponseTest.java    License: MIT License 5 votes vote down vote up
@Test
public void worksFineByStringReq() throws IOException {
    new FtRemote(new TkText("Hello, dude!")).exec(
        home -> new Assertion<>(
            "The HTTP response contains 200 status code",
            new TextOf(
                new HtKeepAliveResponse(new HtWire(home), 5000, 5, "req1")
            ),
            new TextHasString("HTTP/1.1 200 OK")
        ).affirm()
    );
}
 
Example 15
Source Project: cactoos-http   Source File: HtResponseTest.java    License: MIT License 5 votes vote down vote up
@Test
public void worksFine() throws IOException {
    new FtRemote(new TkText("Hello, world!")).exec(
        home -> MatcherAssert.assertThat(
            new TextOf(
                new HtResponse(
                    new HtWire(home),
                    new Get(home)
                )
            ),
            new TextHasString("HTTP/1.1 200 OK")
        )
    );
}
 
Example 16
Source Project: cactoos-http   Source File: HtAutoRedirectTest.java    License: MIT License 5 votes vote down vote up
@Test
public void noRedirectionOnStatusOk() throws Exception {
    final String response = "HTTP/1.1 200 OK";
    MatcherAssert.assertThat(
        "Doesn't return status code OK",
        new TextOf(
            new HtAutoRedirect(
                new InputOf(
                    new TextOf(response)
                )
            )
        ),
        new TextHasString(response)
    );
}
 
Example 17
Source Project: cactoos-http   Source File: HtAutoRedirectTest.java    License: MIT License 5 votes vote down vote up
@Test
public void returnsRedirectResponseForNoLocation() throws Exception {
    final String response = "HTTP/1.1 300";
    MatcherAssert.assertThat(
        "Doesn't return redirection response code",
        new TextOf(
            new HtAutoRedirect(
                new InputOf(
                    new TextOf(response)
                )
            )
        ),
        new TextHasString(response)
    );
}
 
Example 18
Source Project: cactoos-http   Source File: HtWireTest.java    License: MIT License 5 votes vote down vote up
@Test
public void worksWithProvidedHostNameAndPort() throws IOException {
    new FtRemote(new TkText("Hello")).exec(
        home -> MatcherAssert.assertThat(
            new TextOf(
                new HtResponse(
                    new HtWire(home.getHost(), home.getPort()),
                    new Get(home)
                )
            ),
            new TextHasString("HTTP/1.1 200")
        )
    );
}
 
Example 19
Source Project: cactoos   Source File: Md5DigestOfTest.java    License: MIT License 5 votes vote down vote up
@Test
public void checksumOfString() {
    new Assertion<>(
        "Can't calculate the string's MD5 checksum",
        new HexOf(
            new Md5DigestOf(
                new InputOf("Hello World!")
            )
        ),
        new TextHasString(
            "ed076287532e86365e841e92bfc50d8c"
        )
    ).affirm();
}
 
Example 20
Source Project: cactoos-http   Source File: GetTest.java    License: MIT License 5 votes vote down vote up
@Test
public void buildsRequestCorrectly() throws URISyntaxException {
    new Assertion<>(
        "Must build GET request correctly from URI",
        new TextOf(
            new Get(
                new URI(
                    "http://host/path/to/resource"
                )
            )
        ),
        new TextHasString("GET /path/to/resource HTTP/1.1\r\nHost: host")
    ).affirm();
}
 
Example 21
Source Project: cactoos   Source File: BytesOfTest.java    License: MIT License 5 votes vote down vote up
@Test
public void printsStackTraceFromArray() {
    new Assertion<>(
        "Can't print exception stacktrace from array",
        new TextOf(
            new BytesOf(
                new IOException("").getStackTrace()
            )
        ),
        new TextHasString("org.cactoos.io.BytesOfTest")
    ).affirm();
}
 
Example 22
Source Project: cactoos-http   Source File: SkipInputTest.java    License: MIT License 5 votes vote down vote up
@Test
public void skipsEverythingWhenNoDelimiter() throws Exception {
    MatcherAssert.assertThat(
        new TextOf(
            new SkipInput(
                new InputOf("Hello, dude! How are you?"),
                new BytesOf("\n")
            )
        ),
        new TextHasString("")
    );
}
 
Example 23
Source Project: cactoos   Source File: TextTest.java    License: MIT License 5 votes vote down vote up
@Test
public void okForNoNulls() {
    final String message = "Hello";
    new Assertion<>(
        "Must work with NoNulls",
        new NoNulls(
            new TextOf(message)
        ),
        new TextHasString(message)
    ).affirm();
}
 
Example 24
Source Project: cactoos   Source File: Sha1DigestOfTest.java    License: MIT License 5 votes vote down vote up
@Test
public void checksumOfEmptyString() {
    new Assertion<>(
        "Can't calculate the empty string's SHA-1 checksum",
        new HexOf(
            new Sha1DigestOf(
                new InputOf("")
            )
        ),
        new TextHasString(
            "da39a3ee5e6b4b0d3255bfef95601890afd80709"
        )
    ).affirm();
}
 
Example 25
Source Project: cactoos   Source File: TrimmedLeftTest.java    License: MIT License 5 votes vote down vote up
@Test
public void trimmedBlankTextIsEmptyText() {
    new Assertion<>(
        "Can't trim a blank text",
        new TrimmedLeft(new TextOf("  \t ")),
        new TextHasString("")
    ).affirm();
}
 
Example 26
Source Project: cactoos   Source File: HexOfTest.java    License: MIT License 5 votes vote down vote up
@Test
public void empytString() {
    new Assertion<>(
        "Can't represent an empty string as hexadecimal",
        new HexOf(
            new BytesOf("")
        ),
        new TextHasString("")
    ).affirm();
}
 
Example 27
Source Project: cactoos   Source File: HexOfTest.java    License: MIT License 5 votes vote down vote up
@Test
public void notEmpytString() throws IOException {
    new Assertion<>(
        "Can't represent a string as hexadecimal",
        new HexOf(
            new BytesOf("What's up, друг?")
        ),
        new TextHasString("5768617427732075702c20d0b4d180d183d0b33f")
    ).affirm();
}
 
Example 28
Source Project: cactoos   Source File: Base64EncodedTest.java    License: MIT License 5 votes vote down vote up
/**
 * Check text encodes using the Base64 encoding scheme.
 * @throws IOException If fails.
 */
@Test
public void checkEncode() throws IOException {
    new Assertion<>(
        "Can't encodes text using the Base64 encoding scheme",
        new Base64Encoded(
            "Hello!"
        ),
        new TextHasString(
            "SGVsbG8h"
        )
    ).affirm();
}
 
Example 29
Source Project: cactoos   Source File: FormattedTextTest.java    License: MIT License 5 votes vote down vote up
@Test
public void formatsText() {
    new Assertion<>(
        "Can't format a text",
        new FormattedText(
            "%d. Formatted %s", 1, "text"
        ),
        new TextHasString("1. Formatted text")
    ).affirm();
}
 
Example 30
Source Project: cactoos   Source File: FormattedTextTest.java    License: MIT License 5 votes vote down vote up
@Test
public void formatsTextWithObjects() {
    new Assertion<>(
        "Can't format a text with objects",
        new FormattedText(
            new TextOf("%d. Number as %s"),
            1,
            new String("string")
        ),
        new TextHasString("1. Number as string")
    ).affirm();
}