hamcrest Questions

2

Solved

I am in the process of converting some tests from Hamcrest to AssertJ. In Hamcrest I use the following snippet: assertThat(list, either(contains(Tags.SWEETS, Tags.HIGH)) .or(contains(Tags.SOUPS, ...
Gadoid asked 4/11, 2014 at 11:27

1

I have the following function: private Person findMax(List<Person> persons, Function<Person, ? extends Comparable> compare) { return persons.stream().max(Comparator.comparing(compare...
Linwoodlinz asked 6/3, 2015 at 11:54

3

Solved

In every version of JUnit I have tried (up to 4.8.1), a failing assertThat will display an error message that looks like: expected: [describeTo] got: [String representation of object] In other wo...
Bauske asked 12/10, 2010 at 14:15

1

Solved

I wrote a custom matcher to compare my objects. It all works except for the describeMismatchSafely method. I kept simplyfing and simplyfing, until I got this: public static TypeSafeMatcher<IMy...
Retreat asked 23/12, 2014 at 9:16

2

Solved

I am trying to find a definitive answer to using Hamcrest matchers in non test code. I have done a bit of research, and have some contrasting quotes: Hamcrest on Wikipedia: Hamcrest is a fra...
Lagting asked 11/11, 2014 at 1:37

2

I want to run this line of code: assertThat(contextPin.get(), equalTo(pinPage.getPinObjFromUi())); but I want to print to the log be informative meaning that I could know which fields were not e...
Bicapsular asked 17/7, 2014 at 16:2

3

Solved

I'm trying to work with ExpectedExceptions for JUnit. I tried already this: public class ExpectedTest { @Rule public ExpectedException thrown = ExpectedException.none(); @Test public void t...
Glenoid asked 10/4, 2014 at 13:21

3

Solved

I have two collections which I am trying to compare for equality in my unit tests, but I am struggling with the contains method. Here is what I have: @Test public void getAllItems() { Collection...
Flyaway asked 19/8, 2014 at 13:45

1

Solved

I am trying to write a custom matcher that navigates deep down the object graph to check an important property. assertThat( writeRequest, hasRole("admin") ); When this fails I'd like to see a me...
Equanimous asked 9/8, 2014 at 18:51

1

Solved

I run this line: List<String> ids = new List<String>() ids.add("id1"); ids.add("id2"); assertThat(ids, contains("id1")); but strangely it returns "fail". how can I fix this?
Unpeopled asked 12/8, 2014 at 11:14

1

Solved

I'm trying to make a test that checks if an a certain list has items and I don't care about the order. The way I want to be able to do this is by testing the item has a certain property with a cer...
Selig asked 16/7, 2014 at 8:45

2

Solved

List<String> list1 = getListOne(); List<String> list2 = getListTwo(); Given the code above, I want to use a JUnit assertThat() statement to assert that either list1 is empty or that l...
Dizon asked 3/7, 2014 at 17:20

2

Solved

I am learning Hamcrest 1.3 and I want to come up with an example for each Hamcrest static method in Matchers. The Javadoc helpfully already has examples for some methods. I tested the following con...
Miss asked 10/6, 2014 at 3:43

1

Solved

I would like to be able to assert that the annotation value matches the expected class: import org.junit.Test; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert....
Danelaw asked 7/6, 2014 at 2:15

1

Solved

The Problem I'm currently trying to use Hamcrest Matchers to assert that the list type being returned is of a specific type. For example, let's say I have the following List that is being returned...
Concerto asked 29/5, 2014 at 14:10

10

Solved

While unit testing some methods, there can be some scenarios where value of some parameters do not matter and can be any value. For example in this piece of code: public void method(String arg1, St...
Brattishing asked 7/1, 2014 at 7:24

1

Solved

I am trying to test if a collection has an item which toString() method returns a particular String. I tried do it using excellent Hamcrest matching classes, by combining contains with Matchers.has...
Cohby asked 28/3, 2014 at 18:10

4

Solved

I want to verify that a collection contains at least one non-null element. I have tried is(not(empty())), however this passes in the test below. import org.junit.Test; import java.util.ArrayList;...
Overhaul asked 28/8, 2013 at 20:21

3

Solved

I was browsing the junit ExpectedExceptions' javadoc and I can't understand where the startsWith in their example comes from (marked HERE in the code). I checked the CoreMatcher utility class but c...
Ilex asked 20/10, 2012 at 9:25

1

Solved

I want to check that a map contains a certain set of entries. It is allowed to contain other entries that are not in expectedMap. I currently have the following assertion: assertThat(expectedMap.e...
Jabez asked 17/1, 2014 at 12:45

1

Solved

This is related to Checking that a List is not empty in Hamcrest I have a question over that - If we can assert the list is not empty without using Hamcrest and just using JUnit as: assertFalse(l...
Gavra asked 29/1, 2014 at 14:8

2

Solved

I am trying to test the following controller method using the Spring MVC test API: @RequestMapping(value = "/preference/email", method = RequestMethod.GET, produces = "text/html") public String em...
Hylomorphism asked 20/9, 2013 at 15:2

7

Solved

I was just looking at the Java Hamcrest code on GitHub, and noticed they employed a strategy that seemed unintuitive and awkward, but it got me wondering if I'm missing something. I noticed in the...
Mamiemamma asked 20/12, 2013 at 22:16

7

Solved

I'd like to assert that List<Achievement> contains a member of type TestAchievement. Here's my assertion: List<Achievement> achievements; // Populated elsewhere assertThat(achievement...
Blastoderm asked 13/2, 2011 at 0:23

15

Ok, I'm frustrated! I've hunted around for a good number of hours and am still stumped. Environment: WinXP, Eclipse Galileo 3.5 (straight install - no extra plugins). So, I have a simple JUnit te...
Garonne asked 23/7, 2009 at 11:56

© 2022 - 2024 — McMap. All rights reserved.