hamcrest Questions

6

Solved

We have a custom class with several fields, for which we cannot override equals/hashcode methods for business domain reasons Nevertheless, during unit testing we should assert on whether a collect...
Eneidaenema asked 21/9, 2015 at 15:0

4

Is there a shorter version of the following assert statement using standard Hamcrest matchers? Collection<Element> collection = ... assertThat(collection, is(anyOf(nullValue(Collection.clas...
Odle asked 21/2, 2018 at 14:55

5

Solved

What is the opposite of contains? List<String> list = Arrays.asList("b", "a", "c"); // should fail, because "d" is not in the list expectedInList = new String[]{"a","b", "c", "d"}; Asse...
Account asked 12/10, 2016 at 14:37

2

Solved

We would like to assert that a list of custom objects contains an object with some of its fields having certain values, with a series of assertions like this assertThat(customObjectList, hasItem(h...
Suttles asked 7/10, 2015 at 8:48

4

Question Assume the following simple test: @Test public void test() throws Exception { Object value = 1; assertThat(value, greaterThan(0)); } The test won't compile, because "greaterThan" can...
Umbilical asked 20/7, 2017 at 20:1

1

Solved

I have an API that returns a JSON object that will be displayed in a UI. The order of the fields in the object matters because the UI wants to display the fields in that order. I want to write a un...
Irreformable asked 8/12, 2017 at 17:4

4

Solved

This 2013 post on SO asked how to use Hamcrest matchers to verify lists/collections invocations in Mockito. The accepted solution was to cast the Matcher to a (Collection). I'm trying to do somet...
Trouveur asked 26/10, 2015 at 17:5

1

Solved

I have the following collection: Set<DecisionGroup> parentDecisionGroups first of all in my test I need to check that this collection contains two objects with a given ids: assertThat(par...
Columbic asked 6/11, 2017 at 8:56

7

Solved

I'm trying to compare 2 lists: assertThat(actual.getList(), is(Matchers.containsInAnyOrder(expectedList))); But idea java: no suitable method found for assertThat(java.util.List<Agent>,o...
Nationality asked 7/2, 2014 at 10:0

7

When I look at the examples in the Assert class JavaDoc assertThat("Help! Integers don't work", 0, is(1)); // fails: // failure message: // Help! Integers don't work // expected: is <1...
Whiteman asked 9/11, 2009 at 13:56

1

Solved

Currently, whenever I need to fail a test in response to an exception thrown in another thread, I write something like this: package com.example; import java.util.ArrayList; import java.util.List...
Kellam asked 18/8, 2017 at 15:11

3

Solved

Has anyone integrated Hamcrest with TestNG so that its matchers can easily be used in TestNG assertions?
Sycamine asked 7/7, 2009 at 15:24

2

Solved

I'm new using hamcrest. While I'm discovering how to use it I have been a doubt about when to use is or equalTo. Is there any difference between is and equalTo, although it is conceptually or oca...
Bashibazouk asked 25/5, 2017 at 14:34

1

Solved

I have a stupid thing, but I really can´t see what am I missing: I have a test: @Test public void testeBerechneRendite() { get("/rendite?jahresnettomiete=8000&kaufpreis=100000&nebenkoste...
Tauten asked 8/2, 2017 at 18:51

1

Solved

tl;dr: These tests don't compile because the type parameters don't match. What changes should I make to make them compile and run correctly? https://github.com/wesleym/matchertest I have so...
Bellay asked 7/4, 2017 at 23:19

8

Solved

Another instance of the NoSuchMethodError for the JUnit & Hamcrest combination. Offending code: assertThat(dirReader.document(0).getFields(), hasItem( new FeatureMatcher<IndexableField, St...
Chromite asked 5/4, 2013 at 11:40

7

Solved

How would you refactor the following if the products can be returned in any order? List<Product> products = get_products("test_produc"); assertEquals(products.size(),3); assertEquals(p...
Sicard asked 10/3, 2017 at 9:10

2

Solved

I'm using the Hamcrest CoreMatcher classes as part of spring-test integration tests. My JSON looks like: {"data":[{"distanceInMiles":4,"id":"f97236ba-f4ef-4... And my integration test looks like...
Vainglorious asked 5/12, 2015 at 15:51

2

Solved

import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.equalTo; assertThat(actual, hasItem(hasProperty("id"...
Ventris asked 20/11, 2013 at 18:11

2

I'm trying to use Hamcrest, but constantly run into the following: Hamcrest matchers are shortcircuited, so for eg if I write: Assert.assertThat(list, everyItem(not(isIn(shouldNotBeInList)))); ...
Cotillion asked 13/10, 2016 at 8:25

1

I'm currently trying to get Espresso to match a UIElement by it's class and its text since it currently does not have a resource ID (I know, I know...). I'm not sure what the proper syntax for this...
Distinguished asked 30/8, 2016 at 23:52

3

Solved

With Hamcrest we can easily test that exists at least one item in a list with a specific property, e.g. List<Pojo> myList = .... MatcherAssert.assertThat(myList, Matchers.hasItem(Matchers.&...
Contour asked 13/4, 2015 at 15:40

1

Solved

I've implemented Daniele Bottilo's Drawable matcher from his medium post. Now I'd like to use it to test that my image view is not empty. I tried this: onView(withId(R.id.image)) .check( matche...
Herring asked 10/8, 2016 at 8:7

3

Solved

Given that: int[] a = {1, 2, 3, 4}; int[] b = {1, 2, 3, 4, 5}; How to asser that "a" is a subset of "b" using hamcrest matchers? The following works assertThat(Arrays.asList(b), hasItems(a));...
Keeshakeeshond asked 24/11, 2014 at 6:57

2

Solved

I've ran into an issue with hamcrest and mockito. Here is what I'm trying to do: public class A{ public void foo(List<B> arg){ return; } } public BMatcher extends BaseMatcher<B>{ ...
Tormentil asked 18/6, 2013 at 16:30

© 2022 - 2024 — McMap. All rights reserved.