Hamcrest Optional

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

Лицензия

Лицензия

Группа

Группа

com.github.npathai
Идентификатор

Идентификатор

hamcrest-optional
Последняя версия

Последняя версия

2.0.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

Hamcrest Optional
A set of Hamcrest matchers for java.util.Optional.
Ссылка на сайт

Ссылка на сайт

https://github.com/npathai/hamcrest-optional/
Система контроля версий

Система контроля версий

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

Скачать hamcrest-optional

Как подключить последнюю версию

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

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.hamcrest : hamcrest-core jar 1.3

Модули Проекта

Данный проект не имеет модулей.

Hamcrest Optional

Travis CI build Coverage Status Maven Central MIT license

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

Maven Dependency

Version 2.0.0 - Latest

Changes

  • Methods renamed from hasValue to isPresentAndIs/isPresentAnd for better fluency.
<dependencies>
...
<dependency>
  <groupId>com.github.npathai</groupId>
  <artifactId>hamcrest-optional</artifactId>
  <version>2.0.0</version>
</dependency>
...
</dependencies>

Version 1.0

<dependencies>
...
<dependency>
  <groupId>com.github.npathai</groupId>
  <artifactId>hamcrest-optional</artifactId>
  <version>1.0</version>
</dependency>
...
</dependencies>

Usage

hamcrest-optional provides four matchers for Optional: isEmpty(), isPresent(), isPresentAndIs(Object) and isPresentAnd(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());

isPresentAndIs(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.isPresentAndIs;

Optional<String> optional = Optional.of("dummy value");
assertThat(optional, isPresentAndIs("dummy value"));

isPresentAnd(Matcher)

This matcher matches when the examined Optional contains a value that satisfies the specified matcher.

import static com.github.npathai.hamcrestopt.OptionalMatchers.isPresentAnd;
import static org.hamcrest.Matchers.startsWith;

Optional<String> optional = Optional.of("dummy value");
assertThat(optional, isPresentAnd(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 verify -Dgpg.skip.
  • 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.

Release Guide

  • Select a new version according to the Semantic Versioning 2.0.0 Standard.
  • Set the new version in pom.xml.
  • Commit the modified pom.xml.
  • Push the commit: git push origin master
  • Run mvn clean deploy with JDK 8.
  • Add a tag for the release: git tag hamcrest-optional-X.X.X
  • Push the tag: git push origin hamcrest-optional-X.X.X

Версии библиотеки

Версия
2.0.0
1.0