Search in sources :

Example 1 with HasSize

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

the class ListOfTest method makesListFromMappedIterable.

@Test
public void makesListFromMappedIterable() throws Exception {
    final List<Integer> list = new ListOf<>(new Mapped<Integer>(i -> i + 1, new IterableOf<>(1, -1, 0, 1)));
    MatcherAssert.assertThat("Can't turn a mapped iterable into a list", list, new HasSize(4));
    MatcherAssert.assertThat("Can't turn a mapped iterable into a list, again", list, new HasSize(4));
}
Also used : List(java.util.List) MatcherAssert(org.hamcrest.MatcherAssert) HasSize(org.llorllale.cactoos.matchers.HasSize) IsEqual(org.hamcrest.core.IsEqual) IterableOf(org.cactoos.iterable.IterableOf) Test(org.junit.Test) Collections(java.util.Collections) Mapped(org.cactoos.iterable.Mapped) IterableOf(org.cactoos.iterable.IterableOf) HasSize(org.llorllale.cactoos.matchers.HasSize) Test(org.junit.Test)

Example 2 with HasSize

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

the class DirectoryTest method listsFilesInDirectoryByFile.

@Test
public void listsFilesInDirectoryByFile() throws Exception {
    final File file = this.folder.newFolder();
    final Path dir = file.toPath();
    dir.resolve("parent/child").toFile().mkdirs();
    Files.write(dir.resolve("parent/child/file"), "".getBytes());
    new Assertion<>("must list files in a directory represented by a file", new Directory(file), // @checkstyle MagicNumber (1 line)
    new HasSize(4)).affirm();
}
Also used : Path(java.nio.file.Path) HasSize(org.llorllale.cactoos.matchers.HasSize) File(java.io.File) Test(org.junit.Test)

Example 3 with HasSize

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

the class DirectoryTest method listsFilesAndFoldersInDirectory.

@Test
public void listsFilesAndFoldersInDirectory() throws IOException {
    final Path dir = this.folder.newFolder().toPath();
    dir.resolve("x/y").toFile().mkdirs();
    Files.write(dir.resolve("x/y/test"), "".getBytes());
    new Assertion<>("must list files in a directory represented by a path", new Directory(dir), // @checkstyle MagicNumber (1 line)
    new HasSize(4)).affirm();
}
Also used : Path(java.nio.file.Path) HasSize(org.llorllale.cactoos.matchers.HasSize) Test(org.junit.Test)

Example 4 with HasSize

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

the class ListOfTest method sizeTest.

@Test
public void sizeTest() throws Exception {
    final int size = 42;
    MatcherAssert.assertThat("Can't build a list with a certain size", new ListOf<>(Collections.nCopies(size, 0)), new HasSize(size));
}
Also used : HasSize(org.llorllale.cactoos.matchers.HasSize) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 HasSize (org.llorllale.cactoos.matchers.HasSize)4 Path (java.nio.file.Path)2 File (java.io.File)1 Collections (java.util.Collections)1 List (java.util.List)1 IterableOf (org.cactoos.iterable.IterableOf)1 Mapped (org.cactoos.iterable.Mapped)1 MatcherAssert (org.hamcrest.MatcherAssert)1 IsEqual (org.hamcrest.core.IsEqual)1