Search in sources :

Example 1 with ProcOf

use of org.cactoos.proc.ProcOf 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 2 with ProcOf

use of org.cactoos.proc.ProcOf 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)

Aggregations

File (java.io.File)2 Path (java.nio.file.Path)2 ProcOf (org.cactoos.proc.ProcOf)2 Test (org.junit.jupiter.api.Test)2 IsTrue (org.llorllale.cactoos.matchers.IsTrue)2 IsNot (org.hamcrest.core.IsNot)1