Top "Hamcrest" questions

Hamcrest is an open source library of constraint classes used to match objects and values, typically by other frameworks such as unit testing, mocking, or collections.

What is the alternative to using the Deprecated Hamcrest method is()?

I use the following code at the moment to assert on a boolean value, however the method org.hamcrest.Matchers.…

java unit-testing hamcrest
Hamcrest Date Matchers

I need to test before/after on dates in a certain test case. I'd like to use Hamcrest matchers if …

java date hamcrest
How to use Hamcrest to inspect Map items

I have been recently using Hamcrest library to write some tests and quite successful but now I need to do …

junit hamcrest
hamcrest hasItem and hasProperty, assert if a object with property value exists

import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.equalTo; assertThat(actual, …

java unit-testing hamcrest
Mockito's Matcher vs Hamcrest Matcher?

That's going to be an easy one, but I cannot find the difference between them and which one to use, …

java mockito hamcrest
How to assert Map contains Map with entry

I have a unit test that needs to check for a nested map value. I can get my assertion to …

java junit hamcrest
How to use Hamcrest in Java to test for a exception?

How do I use Hamcrest to test for an exception? According to a comment in https://code.google.com/p/…

java junit hamcrest
NoSuchMethodError with Hamcrest 1.3 & JUnit 4.11

Another instance of the NoSuchMethodError for the JUnit & Hamcrest combination. Offending code: assertThat(dirReader.document(0).getFields(), hasItem( new FeatureMatcher&…

maven junit junit4 maven-surefire-plugin hamcrest
Hamcrest with MockMvc: check that key exists but value may be null

I'm doing some tests with MockMvc, and I want to validate the structure of a JSON response. Specifically, I want …

java hamcrest jsonpath mockmvc
Is there a Hamcrest "for each" Matcher that asserts all elements of a Collection or Iterable match a single specific Matcher?

Given a Collection or Iterable of items, is there any Matcher (or combination of matchers) that will assert every item …

java hamcrest