Currently, Java Hamcrest uses version 1.6 and is integrated with many projects using an older version of Java.
Thus, features related to Java 8 will be added in future versions compatible with Java 8. The proposed solution was to have an extension library that supports it so that anyone who needs can use the extension library.
I am the author of Hamcrest Optional , and now it is available on the central server Maven.
Example: checking if an optional element contains a line starting with some value
import static com.github.npathai.hamcrestopt.OptionalMatchers.hasValue; import static org.hamcrest.Matchers.startsWith; Optional<String> optional = Optional.of("dummy value"); assertThat(optional, hasValue(startsWith("dummy")));
source share