Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

An Adapter to use Hamcrest Matchers as AssertJ Conditions

DZone's Guide to

An Adapter to use Hamcrest Matchers as AssertJ Conditions

· Java Zone ·
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

Following on from yesterday’s post on AssertJ, here’s a tiny github repo that I put together with some utilities for AssertJ.

The first is the script mentioned yesterday, tidied up a little and renamed.

The second is a little adapter class that allows you to use Hamcrest Matchers as AssertJ Conditions.  So, if you have some really complex Hamcrest matcher stuff, you can migrate it easily:

final String actual = "how now brown cow";
    assertThat(actual).is(matchedBy(Matchers.containsString("now brown")));

The adapter is provided by that “matchedBy” factory method.  But the github repo has a full README for details.

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}