Skip to content

A draft implementation of descriptive predicates based on JDK8

Notifications You must be signed in to change notification settings

valid4j/descriptive-predicates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

descriptive-predicates

A draft implementation for descriptive predicates based on JDK8.

Inspired by hamcrest.

Descriptive predicates consists of three important aspects;

  • it acts as a Predicate<T> for a type T,
  • it provides a descriptive message for that predicate, i.e. it has a descriptive toString(), and
  • it acts as a describer for a type T, i.e Function<T, String>

Descriptive predicates can be used wherever a regular Java 8 Predicate<T> can be used, but are particularly useful in some scenarios.

Testing, i.e:

verifyThat(result, greaterThan(4));

Input validation (i.e in production code):

validate(input, greaterThan(4), otherwiseThrowing(BadRequest.class));

Design by contract (i.e assertions in production code):

require(input, greaterThan(4));
...
ensure(output, greaterThan(5));

About

A draft implementation of descriptive predicates based on JDK8

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages