Hamcrest Optional

A set of Hamcrest matchers for java.util.Optional.

License

License

GroupId

GroupId

com.github.baev
ArtifactId

ArtifactId

hamcrest-optional
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Hamcrest Optional
A set of Hamcrest matchers for java.util.Optional.
Project URL

Project URL

https://github.com/npathai/hamcrest-optional/
Source Code Management

Source Code Management

https://github.com/baev/hamcrest-optional/

Download hamcrest-optional

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.baev/hamcrest-optional/ -->
<dependency>
    <groupId>com.github.baev</groupId>
    <artifactId>hamcrest-optional</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.baev/hamcrest-optional/
implementation 'com.github.baev:hamcrest-optional:1.0'
// https://jarcasting.com/artifacts/com.github.baev/hamcrest-optional/
implementation ("com.github.baev:hamcrest-optional:1.0")
'com.github.baev:hamcrest-optional:jar:1.0'
<dependency org="com.github.baev" name="hamcrest-optional" rev="1.0">
  <artifact name="hamcrest-optional" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.baev', module='hamcrest-optional', version='1.0')
)
libraryDependencies += "com.github.baev" % "hamcrest-optional" % "1.0"
[com.github.baev/hamcrest-optional "1.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.hamcrest : hamcrest-core jar 1.3

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Hamcrest Optional

release Maven Central build covarage

An extension to Java Hamcrest which provides matchers for java.util.Optional.

Usage

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).

isEmpty()

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

isPresent()

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

hasValue(Object)

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

hasValue(Matcher)

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

Development Guide

hamcrest-optional is build with Maven. If you want to contribute code then

  • Please write a test for your change.
  • Ensure that you don't break the build by running mvn test.
  • Fork the repo and create a pull request. (See Understanding the GitHub Flow)

hamcrest-optional supports Travis CI for continuous integration. Your pull request is automatically build by Travis CI.

Versions

Version
1.0