org.llorllale.cactoos.matchers.TextHasString Java Examples

The following examples show how to use org.llorllale.cactoos.matchers.TextHasString. 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 File: Sha1DigestOfTest.java    From cactoos with 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 #2
Source File: SkipInputTest.java    From cactoos-http with 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 #3
Source File: HtBodyTest.java    From cactoos-http with 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 #4
Source File: HtTimedWireTest.java    From cactoos-http with 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 File: TextOfTest.java    From cactoos with 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 #6
Source File: Sha256DigestOfTest.java    From cactoos with 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 #7
Source File: HtKeepAliveResponseTest.java    From cactoos-http with 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 #8
Source File: InputOfTest.java    From cactoos with 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 #9
Source File: HtHeadTest.java    From cactoos-http with 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 #10
Source File: PaddedStartTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void noPaddingIfRequestedLengthIsNegative()  {
    new Assertion<>(
        "Shouldn't consider negative min length",
        new PaddedStart(
            new TextOf("x"),
            -1,
            '-'
        ),
        new TextHasString("x")
    ).affirm();
}
 
Example #11
Source File: RotatedTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void noRotateWhenEmpty() {
    new Assertion<>(
        "Rotate text when empty",
        new Rotated(
            new TextOf(""), 2
        ),
        new TextHasString("")
    ).affirm();
}
 
Example #12
Source File: TrimmedTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void convertsText() {
    new Assertion<>(
        "Can't trim a text",
        new Trimmed(new TextOf("  Hello!   \t ")),
        new TextHasString("Hello!")
    ).affirm();
}
 
Example #13
Source File: TrimmedRightTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void convertsText() {
    new Assertion<>(
        "Can't right trim a text",
        new TrimmedRight(new TextOf("  Hello!   \t ")),
        new TextHasString("  Hello!")
    ).affirm();
}
 
Example #14
Source File: TrimmedTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void trimmedBlankTextIsEmptyText() {
    new Assertion<>(
        "Can't trim a blank text",
        new Trimmed(new TextOf("  \t ")),
        new TextHasString("")
    ).affirm();
}
 
Example #15
Source File: PaddedStartTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void somePaddingIfOrigTextIsShorterThanRequestedLength() {
    new Assertion<>(
        "Should pad chars at start",
        new PaddedStart(
            new TextOf("x"),
            2,
            '-'
        ),
        new TextHasString("-x")
    ).affirm();
}
 
Example #16
Source File: PaddedStartTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void noPaddingIfOrigTextIsAsLongAsRequestedLength() {
    new Assertion<>(
        "Shouldn't pad the text",
        new PaddedStart(
            new TextOf("x"),
            1,
            '-'
        ),
        new TextHasString("x")
    ).affirm();
}
 
Example #17
Source File: Sha256DigestOfTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void checksumOfEmptyString() {
    new Assertion<>(
        "Can't calculate the empty string's SHA-256 checksum",
        new HexOf(
            new Sha256DigestOf(
                new InputOf("")
            )
        ),
        new TextHasString(
            // @checkstyle LineLengthCheck (1 lines)
            "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
        )
    ).affirm();
}
 
Example #18
Source File: ReversedTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void reverseText() {
    new Assertion<>(
        "Can't reverse a text",
        new Reversed(
            new TextOf("Hello!")
        ),
        new TextHasString("!olleH")
    ).affirm();
}
 
Example #19
Source File: SwappedCaseTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void swapText() {
    new Assertion<>(
        "Can't swap a text",
        new SwappedCase(
            new TextOf("HellO!")
        ),
        new TextHasString("hELLo!")
    ).affirm();
}
 
Example #20
Source File: JoinedTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void joinsTextsWitjStringDelimit() {
    new Assertion<>(
        "Can't join texts with String delimit",
        new Joined(
            " ",
            new TextOf("one"),
            new TextOf("two")
        ),
        new TextHasString("one two")
    ).affirm();
}
 
Example #21
Source File: JoinedTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void joinsTexts() {
    new Assertion<>(
        "Can't join texts",
        new Joined(
            new TextOf(" "),
            new TextOf("foo"),
            new TextOf("bar")
        ),
        new TextHasString("foo bar")
    ).affirm();
}
 
Example #22
Source File: JoinedTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void joinsStrings() {
    new Assertion<>(
        "Can't join strings",
        new Joined(" ", "hello", "world"),
        new TextHasString("hello world")
    ).affirm();
}
 
Example #23
Source File: AbbreviatedTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void abbreviatesText() {
    new Assertion<>(
        "Can't abbreviate a text",
        // @checkstyle MagicNumber (1 line)
        new Abbreviated("hello world", 8),
        new TextHasString("hello...")
    ).affirm();
}
 
Example #24
Source File: HeadOfTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void readsHeadOfShorterInput() throws Exception {
    final String input = "readsHeadOfShorterInput";
    new Assertion<>(
        "must limit to at most the number of available bytes",
        new TextOf(
            new HeadOf(
                new InputOf(input),
                35
            )
        ),
        new TextHasString(input)
    ).affirm();
}
 
Example #25
Source File: RotatedTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void noRotateWhenShiftZero() {
    final String nonrotate = "Cactoos!";
    new Assertion<>(
        "Rotate text shift zero",
        new Rotated(
            new TextOf(nonrotate), 0
        ),
        new TextHasString(nonrotate)
    ).affirm();
}
 
Example #26
Source File: RotatedTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void rotateRightText() {
    new Assertion<>(
        "Can't rotate text to right",
        new Rotated(
            new TextOf("Hello!"), 2
        ),
        new TextHasString("o!Hell")
    ).affirm();
}
 
Example #27
Source File: Sha256DigestOfTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void checksumOfString() {
    new Assertion<>(
        "Can't calculate the string's SHA-256 checksum",
        new HexOf(
            new Sha256DigestOf(
                new InputOf("Hello World!")
            )
        ),
        new TextHasString(
            // @checkstyle LineLengthCheck (1 lines)
            "7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069"
        )
    ).affirm();
}
 
Example #28
Source File: UpperTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void convertsString() {
    new Assertion<>(
        "Can't upper case a string",
        new Upper("World!"),
        new TextHasString("WORLD!")
    ).affirm();
}
 
Example #29
Source File: UpperTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void convertsText() {
    new Assertion<>(
        "Can't upper case a text",
        new Upper(new TextOf("Hello!")),
        new TextHasString("HELLO!")
    ).affirm();
}
 
Example #30
Source File: SubTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void cutTextWithStart() {
    new Assertion<>(
        "Can't cut a text with start",
        new Sub("cut here", 2),
        new TextHasString("t here")
    ).affirm();
}