Search in sources :

Example 6 with IsTrue

use of org.llorllale.cactoos.matchers.IsTrue in project cactoos by yegor256.

the class TempFolderTest method createsDirectory.

@Test
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();
    }
}
Also used : IsTrue(org.llorllale.cactoos.matchers.IsTrue) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 7 with IsTrue

use of org.llorllale.cactoos.matchers.IsTrue in project cactoos by yegor256.

the class TempFolderTest method deletesNonEmptyDirectory.

@Test
void deletesNonEmptyDirectory() throws Exception {
    final TempFolder temp = new TempFolder();
    final Path root = temp.value();
    new ForEach<>(new ProcOf<String>(name -> {
        final Path dir = Files.createDirectories(new File(root.toFile(), name).toPath());
        new ForEach<>(new ProcOf<String>(filename -> {
            new TempFile(() -> dir, filename, "").value();
        })).exec(new IterableOf<>("file1.txt", "file2.txt", "file3.txt"));
    })).exec(new IterableOf<>("a", "b", "c", "d", "e"));
    temp.close();
    new Assertion<>("Can't delete not empty folder while closing", temp.value().toFile().exists(), new IsNot<>(new IsTrue())).affirm();
}
Also used : Path(java.nio.file.Path) ProcOf(org.cactoos.proc.ProcOf) IsNot(org.hamcrest.core.IsNot) IsTrue(org.llorllale.cactoos.matchers.IsTrue) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 8 with IsTrue

use of org.llorllale.cactoos.matchers.IsTrue in project cactoos by yegor256.

the class TempFolderTest method createDirectoryWithDirectoriesAndFiles.

@Test
void createDirectoryWithDirectoriesAndFiles() throws Exception {
    final TempFolder temp = new TempFolder();
    final Path root = temp.value();
    new ForEach<>(new ProcOf<String>(name -> {
        final Path dir = Files.createDirectories(new File(root.toFile(), name).toPath());
        new ForEach<>(new ProcOf<String>(filename -> {
            new TempFile(() -> dir, filename, "").value();
        })).exec(new IterableOf<>("1.txt", "2.txt", "3.txt"));
    })).exec(new IterableOf<>("1", "2", "3", "4", "5"));
    new Assertion<>("Directory contains files and sub directories", temp.value().toFile().exists(), new IsTrue()).affirm();
    temp.close();
}
Also used : Path(java.nio.file.Path) ProcOf(org.cactoos.proc.ProcOf) IsTrue(org.llorllale.cactoos.matchers.IsTrue) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 9 with IsTrue

use of org.llorllale.cactoos.matchers.IsTrue in project cactoos by yegor256.

the class WriterAsOutputStreamTest method writesToFileAndRemovesIt.

@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();
}
Also used : Path(java.nio.file.Path) IsNot(org.hamcrest.core.IsNot) IsTrue(org.llorllale.cactoos.matchers.IsTrue) LengthOf(org.cactoos.scalar.LengthOf) OutputStreamWriter(java.io.OutputStreamWriter) Test(org.junit.Test)

Example 10 with IsTrue

use of org.llorllale.cactoos.matchers.IsTrue in project cactoos by yegor256.

the class IteratorOfTest method nonEmptyIteratorDoesNotHaveNext.

@Test
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();
}
Also used : IsNot(org.hamcrest.core.IsNot) IsTrue(org.llorllale.cactoos.matchers.IsTrue) Test(org.junit.jupiter.api.Test)

Aggregations

IsTrue (org.llorllale.cactoos.matchers.IsTrue)10 Test (org.junit.jupiter.api.Test)8 IsNot (org.hamcrest.core.IsNot)5 File (java.io.File)3 Path (java.nio.file.Path)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ProcOf (org.cactoos.proc.ProcOf)2 TextOf (org.cactoos.text.TextOf)2 Test (org.junit.Test)2 OutputStreamWriter (java.io.OutputStreamWriter)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1 TimeoutException (java.util.concurrent.TimeoutException)1 InputOf (org.cactoos.io.InputOf)1 Endless (org.cactoos.iterable.Endless)1 And (org.cactoos.scalar.And)1 LengthOf (org.cactoos.scalar.LengthOf)1