GithubHelp home page GithubHelp logo

hartl3y94 / hamcrest-java-file Goto Github PK

View Code? Open in Web Editor NEW

This project forked from clean-code-rocks/hamcrest-java-file

0.0 0.0 0.0 41 KB

Java Hamcrest matchers for files and directories

License: GNU General Public License v3.0

Java 100.00%

hamcrest-java-file's Introduction

Hamcrest - File

Maven Central Javadoc Codecov License: GPL v3 Fossa

Java Hamcrest matchers for files and directories.

Requirement

Java 8+

Installation

Maven

<dependency>
    <groupId>rocks.cleancode</groupId>
    <artifactId>hamcrest-file</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <scope>test</scope>
</dependency>

Usage

Five matchers are provided:

  • file() / directory(): matches an existing file or directory
  • readable() / writable() / executable(): matches file accessibility

file() / directory()

For java.nio.file.Path

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()));

For java.io.File

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()));

readable() / writable() / executable()

For java.nio.file.Path

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()));

For java.io.File

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()));

hamcrest-java-file's People

Contributors

benjaminprevot avatar fossabot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.