Java Hamcrest matchers for files and directories.
Java 8+
<dependency>
<groupId>rocks.cleancode</groupId>
<artifactId>hamcrest-file</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
Five matchers are provided:
file()
/directory()
: matches an existing file or directoryreadable()
/writable()
/executable()
: matches file accessibility
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static rocks.cleancode.hamcrest.file.PathMatchers.directory;
import static rocks.cleancode.hamcrest.file.PathMatchers.file;
Path file = Paths.get("/path/to/file.txt");
Path dir = Paths.get("/path/to/directory");
assertThat(file, is(file()));
assertThat(dir, is(directory()));
import java.io.File;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static rocks.cleancode.hamcrest.file.FileMatchers.directory;
import static rocks.cleancode.hamcrest.file.FileMatchers.file;
File file = new File("/path/to/file.txt");
File dir = new File("/path/to/directory");
assertThat(file, is(file()));
assertThat(dir, is(directory()));
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static rocks.cleancode.hamcrest.file.PathMatchers.executable;
import static rocks.cleancode.hamcrest.file.PathMatchers.readable;
import static rocks.cleancode.hamcrest.file.PathMatchers.writable;
Path path = Paths.get("/path/to/readable/file.txt");
assertThat(path, is(readable()));
assertThat(path, is(writable()));
assertThat(path, is(executable()));
import java.io.File;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static rocks.cleancode.hamcrest.file.FileMatchers.executable;
import static rocks.cleancode.hamcrest.file.FileMatchers.readable;
import static rocks.cleancode.hamcrest.file.FileMatchers.writable;
File file = new File("/path/to/readable/file.txt");
assertThat(file, is(readable()));
assertThat(file, is(writable()));
assertThat(file, is(executable()));