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, ...
1
I have the following function:
private Person findMax(List<Person> persons,
Function<Person, ? extends Comparable> compare) {
return persons.stream().max(Comparator.comparing(compare...
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...
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...
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...
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...
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...
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....
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...
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...
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...
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...
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
© 2022 - 2024 — McMap. All rights reserved.