Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.baev:hamcrest-optional:1.0'
}
dependencies {
implementation("com.github.baev:hamcrest-optional:1.0")
}
<dependency>
<groupId>com.github.baev</groupId>
<artifactId>hamcrest-optional</artifactId>
<version>1.0</version>
</dependency>
libraryDependencies += "com.github.baev" % "hamcrest-optional" % "1.0"
:dependencies [[com.github.baev/hamcrest-optional "1.0"]]
An extension to Java Hamcrest which provides matchers for java.util.Optional
.
The artifact is available at Maven Central:
<dependency>
<groupId>com.github.baev</groupId>
<artifactId>hamcrest-optional</artifactId>
<version>1.0</version>
</dependency>
hamcrest-optional provides four matchers for Optional
: isEmpty()
,
isPresent()
, hasValue(Object)
and hasValue(Matcher)
.
This matcher matches when the examined Optional
contains no value.
import static com.github.npathai.hamcrestopt.OptionalMatchers.isEmpty;
Optional<Object> optional = Optional.empty();
assertThat(optional, isEmpty());
This matcher matches when the examined Optional
contains a value.
import static com.github.npathai.hamcrestopt.OptionalMatchers.isPresent;
Optional<String> optional = Optional.of("dummy value");
assertThat(optional, isPresent());
This matcher matches when the examined Optional
contains a value that is
logically equal to the specified object.
import static com.github.npathai.hamcrestopt.OptionalMatchers.hasValue;
Optional<String> optional = Optional.of("dummy value");
assertThat(optional, hasValue("dummy value"));
This matcher matches when the examined Optional
contains a value that
satisfies the specified matcher.
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")));
hamcrest-optional is build with Maven. If you want to contribute code then
mvn test
.hamcrest-optional supports Travis CI for continuous integration. Your pull request is automatically build by Travis CI.