Cirneco's Hamcrest Extensions for JDK8

An extension to make unit test easier with Hamcrest and Java8.

License

License

Categories

Categories

Java 8 Languages
GroupId

GroupId

it.ozimov
ArtifactId

ArtifactId

java8-hamcrest-matchers
Last Version

Last Version

1.3.0
Release Date

Release Date

Type

Type

jar
Description

Description

Cirneco's Hamcrest Extensions for JDK8
An extension to make unit test easier with Hamcrest and Java8.

Download java8-hamcrest-matchers

How to add to project

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

Dependencies

compile (4)

Group / Artifact Type Version
it.ozimov : java7-hamcrest-matchers jar 1.3.0
org.hamcrest : java-hamcrest jar 2.0.0.0
org.slf4j : slf4j-api jar 1.7.13
com.google.code.findbugs : jsr305 Optional jar 3.0.1

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.16.6

test (4)

Group / Artifact Type Version
it.ozimov : java7-hamcrest-matchers jar 1.3.0
org.javassist : javassist jar 3.20.0-GA
junit : junit jar 4.12
org.mockito : mockito-all jar 1.10.19

Project Modules

There are no modules declared in this project.

Cirneco logo Cirneco

Easy-to-use extensions for unit test libraries

Source Website: github.com/ozimov/cirneco
JavaDoc Website: ozimov.github.io/cirneco/
Wiki Website: github.com/ozimov/cirneco/wiki

Latest Release: 2.0.0
Latest Artifacts: it.ozimov:java7-hamcrest-matchers:jar:2.0.0, it.ozimov:java8-hamcrest-matchers:jar:2.0.0, it.ozimov:guava-hamcrest-matchers:jar:2.0.0, it.ozimov:mockito-helpers:jar:2.0.0
Continuous Integration:
Maven Central
Build Status Coverage Status codecov.io Codacy Badge

codecov.io

What is Cirneco?

Cirneco is a collection of libraries aimed to make unit test in Java cleaner and easier. The more code you have to write, the highest is the probability to do a mistake. Moreover, we like easy-to-read and concise code, where the method name already embeds all the semantics that you need to explain what you are assuming/asserting.

Hence, in Cirneco we aim to extend the most valuable toolkits for unit test to provide a better developing experience. The current version (Cirneco 2.0.0) only provides some extensions for Hamcrest for Java.

JDK compatibility

Since version 2.0.0, the API is JDK8 compatible.

Extended libraries

We provided some extensions of the Hamcrest library. There are some extra feature for fluent assertions that you may also want to checkout.

There is also a library for Mockito that provides for now only a captor for method results.

Moreover, we provide some []AssertJ](http://joel-costigliola.github.io/assertj/) utilities. Specifically, the JUnitSoftAssertionsRule is extended to support Guava matchers.

Hamcrest extensions

There are some interesting matchers based on Guava library. The next release will focus more on Guava collections and money (the plan would be to use Joda Money or to dirfectly provide the matchers for the JDK8 extension). To use the extensions for a JDK7 compliant project, you can embed the following dependency in your pom.xml

<dependency>
  <groupId>it.ozimov</groupId>
  <artifactId>hamcrest-matchers</artifactId>
  <version>2.0.0</version>
  <scope>test</scope>
</dependency>

There are matchers dedicated to Guava libraries that are JDK7-compliant, that you can import with the following dependency:

<dependency>
  <groupId>it.ozimov</groupId>
  <artifactId>guava-hamcrest-matchers</artifactId>
  <version>2.0.0</version>
  <scope>test</scope>
</dependency>

Some libraries are not using Hamcrest v.2.0.0.0. It may be necessary to explicity remove the dependency of older Hamcrest version. E.g. in a Spring Boot application:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-test</artifactId>
  <scope>test</scope>
  <exclusions>
    <exclusion>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-core</artifactId>
    </exclusion>
    <exclusion>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-library</artifactId>
    </exclusion>
  </exclusions>
</dependency>

Otherwise, just put the Cirneco dependencies before to import these dependencies. I suggest to use Maven dependency tree resolver to detect which library is shipped with Hamcrest 2.0.3.

Mockito extension

As a Mockito user maybe you observed that there are no captor implemented by default for the results provided for the method. In fact, you can only capture method arguments. In the Mockito extension we introduced an implementation of the result captor. To use the extension you can add the following dependency in your pom.xml

<dependency>
  <groupId>it.ozimov</groupId>
  <artifactId>mockito-helpers</artifactId>
  <version>2.0.0</version>
  <scope>test</scope>
</dependency>

AssertJ extension

AssertJ has some useful matchers for Guava users. If you love as we love the JUnit rule that exposes the assertions, i.e. JUnitSoftAssertions. We provide an extended rule, with the very same name, that add the Guava assertions provided by AssertJ.

To use the extension you can add the following dependency in your pom.xml

<dependency>
  <groupId>it.ozimov</groupId>
  <artifactId>assertj-guava</artifactId>
  <version>2.0.0</version>
  <scope>test</scope>
</dependency>

What does it mean Cirneco?

Maybe you are curious about the name Cirneco. Cirneco dell'Etna is a unique dog native of Sicily, Italy. It is very fast and agile, neat and friendly. A Cirneco is also excellent for hunting. So, all the quality we love to have in an API.

============================================== forthebadge forthebadge forthebadge forthebadge

it.ozimov

Ozimov

Versions

Version
1.3.0
1.2.0
1.1.2
1.1.1
1.1
1.0.2
1.0.1
1.0.0
0.11.0
0.10.0
0.9.0
0.8.1
0.8.0
0.7.0
0.6.1
0.6.0
0.5.0
0.4.2
0.4.1
0.4.0
0.3.0