org.llorllale.cactoos.matchers.IsTrue Java Examples

The following examples show how to use org.llorllale.cactoos.matchers.IsTrue. 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: AppTest.java    From jpeek with MIT License 6 votes vote down vote up
@Test
public void createsXmlReports(@TempDir final Path output) throws IOException {
    final Path input = Paths.get(".");
    new App(input, output).analyze();
    new Assertion<>(
        "Must LCOM.xml file exists",
        Files.exists(output.resolve("LCOM.xml")),
        new IsTrue()
    ).affirm();
    new Assertion<>(
        "Must create LCOM report",
        XSLDocument
            .make(
                AppTest.class.getResourceAsStream("xsl/metric.xsl")
            )
            .with(new ClasspathSources())
            .applyTo(new XMLDocument(output.resolve("LCOM.xml").toFile())),
        XhtmlMatchers.hasXPath("//xhtml:body")
    ).affirm();
}
 
Example #2
Source File: XslReportTest.java    From jpeek with MIT License 6 votes vote down vote up
@Test
public void createsXmlReport(@TempDir final Path output) throws IOException {
    new XslReport(
        new Skeleton(new FakeBase()).xml(), new XslCalculus(), new ReportData("LCOM")
    ).save(output);
    new Assertion<>(
        "Must LCOM.xml file exists",
        Files.exists(output.resolve("LCOM.xml")),
        new IsTrue()
    ).affirm();
    new Assertion<>(
        "Must LCOM.html file exists",
        Files.exists(output.resolve("LCOM.html")),
        new IsTrue()
    ).affirm();
}
 
Example #3
Source File: CloseableInputStreamTest.java    From cactoos-http with MIT License 6 votes vote down vote up
@Test
public void doesNotCloseTheStream() throws Exception {
    final CloseableInputStream closeable = new CloseableInputStream(
        new DeadInputStream()
    );
    new Assertion<>(
        "must not be marked as closed before close is called",
        closeable.wasClosed(),
        new IsNot<>(new IsTrue())
    ).affirm();
    closeable.close();
    new Assertion<>(
        "must be marked as closed after close is called",
        closeable.wasClosed(),
        new IsTrue()
    ).affirm();
}
 
Example #4
Source File: JoinedTest.java    From cactoos with MIT License 6 votes vote down vote up
@Test
public void containsAll() {
    new Assertion<>(
        "must contain all elements",
        new Joined<String>(
            new ListOf<>(JoinedTest.LITERAL_ONE, JoinedTest.LITERAL_THREE),
            new ListOf<>(JoinedTest.LITERAL_TWO, JoinedTest.LITERAL_FOUR)
        ).containsAll(
            new ListOf<>(
                JoinedTest.LITERAL_ONE,
                JoinedTest.LITERAL_TWO
            )
        ),
        new IsTrue()
    ).affirm();
}
 
Example #5
Source File: TempFolderTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void deletesDirectory() throws Exception {
    final TempFolder dir = new TempFolder(
        new Randomized('d', 'e', 'g').asString()
    );
    dir.close();
    new Assertion<>(
        "Can't delete folder while closing",
        !dir.value().toFile().exists(),
        new IsTrue()
    ).affirm();
}
 
Example #6
Source File: IterableOfTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void isNotEqualsToIterableWithMoreElements() {
    new Assertion<>(
        "Must compare iterables and second one is bigger",
        new IterableOf<>("a", "b").equals(new IterableOf<>("a")),
        new IsNot<>(new IsTrue())
    ).affirm();
}
 
Example #7
Source File: IterableOfTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void isNotEqualsToIterableWithLessElements() {
    new Assertion<>(
        "Must compare iterables and first one is bigger",
        new IterableOf<>("a").equals(new IterableOf<>("a", "b")),
        new IsNot<>(new IsTrue())
    ).affirm();
}
 
Example #8
Source File: TrueTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void asValue() throws Exception {
    new Assertion<>(
        "Must be True",
        new True().value(),
        new IsTrue()
    ).affirm();
}
 
Example #9
Source File: IteratorOfTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void emptyIteratorDoesNotHaveNext() {
    new Assertion<>(
        "Must create empty iterator",
        new IteratorOf<>().hasNext(),
        new IsNot<>(new IsTrue())
    ).affirm();
}
 
Example #10
Source File: IteratorOfTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void nonEmptyIteratorDoesNotHaveNext() {
    final Iterator<Integer> iterator = new IteratorOf<>(
        1, 2, 3
    );
    while (iterator.hasNext()) {
        iterator.next();
    }
    new Assertion<>(
        "Must create non empty iterator",
        iterator.hasNext(),
        new IsNot<>(new IsTrue())
    ).affirm();
}
 
Example #11
Source File: ReaderAsBytesTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void readsAndClosesReader() throws Exception {
    final EmptyClosableReader reader = new EmptyClosableReader();
    new ReaderAsBytes(reader).asBytes();
    new Assertion<>(
        "Must close the reader after reading it",
        reader.isClosed(),
        new IsTrue()
    ).affirm();
}
 
Example #12
Source File: BytesOfTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void closesInputStream() throws Exception {
    final AtomicBoolean closed = new AtomicBoolean();
    final InputStream input = new ByteArrayInputStream(
        "how are you?".getBytes()
    );
    new TextOf(
        new InputOf(
            new InputStream() {
                @Override
                public int read() throws IOException {
                    return input.read();
                }

                @Override
                public void close() throws IOException {
                    input.close();
                    closed.set(true);
                }
            }
        ),
        StandardCharsets.UTF_8
    ).asString();
    new Assertion<>(
        "must close InputStream correctly",
        closed.get(),
        new IsTrue()
    ).affirm();
}
 
Example #13
Source File: TempFolderTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void createsDirectory() throws Exception {
    try (TempFolder folder = new TempFolder()) {
        final File dir = folder.value().toFile();
        new Assertion<>(
            "must create new directory",
            dir.exists() && dir.isDirectory(),
            new IsTrue()
        ).affirm();
    }
}
 
Example #14
Source File: NoNullsTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void testSuccessNotNullArg() {
    new Assertion<>(
        "Must contain not null argument",
        new NoNulls<>(
            new ListOf<>(1)
        ).contains(1),
        new IsTrue()
    ).affirm();
}
 
Example #15
Source File: WriterAsOutputStreamTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void writesToFileAndRemovesIt() throws Exception {
    final Path temp = this.folder.newFile().toPath();
    final String content = "Hello, товарищ! How are you?";
    try (OutputStreamWriter writer = new OutputStreamWriter(
        Files.newOutputStream(temp.toAbsolutePath()),
        StandardCharsets.UTF_8
    )) {
        new LengthOf(
            new TeeInput(
                new InputOf(content),
                new OutputTo(
                    new WriterAsOutputStream(
                        writer,
                        StandardCharsets.UTF_8,
                        // @checkstyle MagicNumber (1 line)
                        345
                    )
                )
            )
        ).value();
    }
    Files.delete(temp);
    new Assertion<>(
        "file must not exist anymore",
        Files.exists(temp),
        new IsNot<>(new IsTrue())
    ).affirm();
}
 
Example #16
Source File: MainTest.java    From jpeek with MIT License 5 votes vote down vote up
@Test
public void createsXmlReports(@TempDir final Path temp) throws IOException {
    final Path output = temp.resolve("x3");
    final Path input = Paths.get(".");
    Main.main("--sources", input.toString(), "--target", output.toString());
    new Assertion<>(
        "Must create LCOM5 report",
        Files.exists(output.resolve("LCOM5.xml")),
        new IsTrue()
    ).affirm();
}
 
Example #17
Source File: MainTest.java    From jpeek with MIT License 5 votes vote down vote up
@Test
public void createsXmlReportsIfOverwriteAndTargetExists(@TempDir final Path target)
    throws IOException {
    Main.main(
        "--sources", Paths.get(".").toString(),
        "--target", target.toString(),
        "--overwrite"
    );
    new Assertion<>(
        "Must exists LCOM5.xml",
        Files.exists(target.resolve("LCOM5.xml")),
        new IsTrue()
    ).affirm();
}
 
Example #18
Source File: AppTest.java    From jpeek with MIT License 5 votes vote down vote up
@Test
public void createsIndexHtml(@TempDir final Path output) throws IOException {
    final Path input = Paths.get(".");
    new App(input, output).analyze();
    new Assertion<>(
        "Must index.html file exists",
        Files.exists(output.resolve("index.html")),
        new IsTrue()
    ).affirm();
}
 
Example #19
Source File: StartsWithTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void emptyStartsWithEmpty() throws Exception {
    new Assertion<>(
        "Empty is not prefix of empty",
        new StartsWith(
            new TextOf(""),
            new TextOf("")
        ).value(),
        new IsTrue()
    ).affirm();
}
 
Example #20
Source File: HtWireTest.java    From cactoos-http with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public void closesSocketOnlyAfterResponseIsClosed() throws Exception {
    new FtRemote(new TkText("Hey")).exec(
        home -> {
            @SuppressWarnings("resource")
            final Socket socket = new Socket(
                home.getHost(),
                home.getPort()
            );
            try (InputStream ins = new HtWire(() -> socket).send(
                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 keep the socket open until response is closed",
                    socket.isClosed(),
                    new IsNot<>(new IsTrue())
                ).affirm();
                // @checkstyle IllegalCatchCheck (1 line)
            } catch (final Exception ex) {
                throw new IOException(ex);
            }
            new Assertion<>(
                "must close the socket once input response is closed",
                socket.isClosed(),
                new IsTrue()
            ).affirm();
        }
    );
}
 
Example #21
Source File: AutoClosedInputStreamTest.java    From cactoos-http with MIT License 5 votes vote down vote up
@Test
public void autoClosesTheStream() throws Exception {
    final CloseableInputStream closeable = new CloseableInputStream(
        new DeadInputStream()
    );
    new ReadBytes(closeable).asBytes();
    new Assertion<>(
        "must not close the stream",
        closeable.wasClosed(),
        new IsNot<>(new IsTrue())
    ).affirm();
}
 
Example #22
Source File: ReadBytesTest.java    From cactoos-http with MIT License 5 votes vote down vote up
@Test
public void doesNotCloseTheStream() throws Exception {
    final CloseableInputStream closeable = new CloseableInputStream(
        new DeadInputStream()
    );
    new ReadBytes(new AutoClosedInputStream(closeable)).asBytes();
    new Assertion<>(
        "must autoclose the stream",
        closeable.wasClosed(),
        new IsTrue()
    ).affirm();
}
 
Example #23
Source File: JoinedTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void isEmpty() {
    new Assertion<>(
        "must be evaluated as an empty list",
        new Joined<String>(
            new ListOf<>(
                JoinedTest.LITERAL_ONE, JoinedTest.LITERAL_TWO
            ),
            new ListOf<>(
                JoinedTest.LITERAL_THREE, JoinedTest.LITERAL_FOUR
            )
        ).isEmpty(),
        new IsNot<>(new IsTrue())
    ).affirm();
}
 
Example #24
Source File: JoinedTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void contains() {
    new Assertion<>(
        "must contain element specified",
        new Joined<String>(
            new ListOf<>(
                JoinedTest.LITERAL_ONE, JoinedTest.LITERAL_TWO
            ),
            new ListOf<>(
                JoinedTest.LITERAL_THREE, JoinedTest.LITERAL_FOUR
            )
        ).contains(JoinedTest.LITERAL_THREE),
        new IsTrue()
    ).affirm();
}
 
Example #25
Source File: BehavesAsList.java    From cactoos with MIT License 5 votes vote down vote up
@Override
public boolean matchesSafely(final List<E> list) {
    new Assertion<>(
        "must contain at least one non-null element",
        list.get(0),
        new IsNot<>(new IsNull<>())
    ).affirm();
    new Assertion<>(
        "must have an index for the sample item",
        list.indexOf(this.sample),
        new MatcherOf<>(i -> i >= 0)
    ).affirm();
    new Assertion<>(
        "must have a last index for the sample item",
        list.lastIndexOf(this.sample),
        new MatcherOf<>(i -> i >= 0)
    ).affirm();
    new Assertion<>(
        "must have at least one element in list iterator",
        list.listIterator().hasNext(),
        new IsTrue()
    ).affirm();
    new Assertion<>(
        "must have at least one element in sublist iterator",
        list.subList(0, 1).iterator().hasNext(),
        new IsTrue()
    ).affirm();
    return new BehavesAsCollection<E>(this.sample).matchesSafely(list);
}
 
Example #26
Source File: HtAutoClosedResponseTest.java    From cactoos-http with 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 #27
Source File: StartsWithTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void textStartsWithEmpty() throws Exception {
    new Assertion<>(
        "Empty is not prefix of any string",
        new StartsWith(
            new TextOf("Any string"),
            new TextOf("")
        ).value(),
        new IsTrue()
    ).affirm();
}
 
Example #28
Source File: StartsWithTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void textStartsWithPrefix() throws Exception {
    new Assertion<>(
        "Foo is not prefix of FooBar",
        new StartsWith(
            "FooBar",
            "Foo"
        ).value(),
        new IsTrue()
    ).affirm();
}
 
Example #29
Source File: StartsWithTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void textStartsWithoutPrefix() throws Exception {
    new Assertion<>(
        "Baz is prefix of FooBarBaz",
        new StartsWith(
            "FooBarBaz",
            "Baz"
        ).value(),
        new IsNot<>(new IsTrue())
    ).affirm();
}
 
Example #30
Source File: BiFuncOfTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void convertsRunnableIntoBiFunc() throws Exception {
    final AtomicBoolean done = new AtomicBoolean(false);
    new Assertion<>(
        "Must convert runnable into bi-function",
        new BiFuncOf<String, Integer, Boolean>(
            () -> done.set(true),
            true
        ).apply("hello, world", 1),
        new IsTrue()
    ).affirm();
}