hamcrest

How do I simplify mockito/hamcrest argument matchers in test method?

家住魔仙堡 提交于 2019-12-13 02:41:19
问题 The test method below appear in a spring-guide tutorial. Is there a less convoluted syntax to write this test or how can I break it apart into smaller chunks? verify(orderService).createOrder( org.mockito.Matchers.<CreateOrderEvent>argThat( allOf( org.hamcrest.Matchers.<CreateOrderEvent> hasProperty("details", hasProperty("dateTimeOfSubmission", notNullValue())), org.hamcrest.Matchers.<CreateOrderEvent>hasProperty("details", hasProperty("name", equalTo(CUSTOMER_NAME))), org.hamcrest.Matchers.

How to apply a Hamcrest matcher to the property of a class under test?

随声附和 提交于 2019-12-12 18:33:05
问题 Is there a way to build a combined Hamcrest matcher which tests an object and the property of this object? - pseudo code: both( instanceof(MultipleFailureException.class) ).and( // pseudo code starts adapt( new Adapter<MultipleFailureException, Iterable<Throwable>() { public Iterable<Throwable> getAdapter(MultipleFailureException item) { return item.getFailures(); } }, // pseudo code ends everyItem(instanceOf(IllegalArgumentException.class)) ) ) Background: I have a JUnit test, which iterates

JMock- java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch()

眉间皱痕 提交于 2019-12-12 13:05:23
问题 I understand that the solution is to somehow make sure that Junit is loaded after hamcrest. I have an intellij project, in which I setup an external library, which contains both JUnit and JMock and hamcrest. How can I make sure that this error does not show up 回答1: You should make sure the compatibility of libraries(jars). If a class inside jar uses some method from class which is in another jar, and this used method is newly added and you are using old jar then definitely you will get java

TetsNG SoftAssert with Hamcrest matcher

老子叫甜甜 提交于 2019-12-12 09:07:15
问题 I want to use a Hamcrest matcher inside a TestNG test and with a soft assert specifically. How can I do this? I know that I can use Hamcrest's assertions inside a test like: assertThat(actual, containsInAnyOrder(expected)); But I can't understand how can I use TestNG soft assert method like this one: SoftAssert softAssert = new SoftAssert(); together with a Hamcrest matcher. Because I can't invoke the Hamcrest's assertThat on TestNG's softAssert like softAssert.assertThat(...) So, what is the

Conflicting overloads for Hamcrest matcher

此生再无相见时 提交于 2019-12-12 08:48:13
问题 The matcher IsIterableContainingInAnyOrder has two overloads for the static factory method containsInAnyOrder (both have the return type Matcher<java.lang.Iterable<? extends T>> ): containsInAnyOrder(java.util.Collection<Matcher<? super T>> itemMatchers) containsInAnyOrder(Matcher<? super T>... itemMatchers) Now consider the following program: import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; import static org.hamcrest.core.IsEqual.equalTo; import static

JSON arrays with duplicate items with Hamcrest and RestAssured

我的未来我决定 提交于 2019-12-12 04:05:43
问题 As a follow up question for my question in Dealing arrays with hamcrest and rest assured How can I use hamcrest with restassured so that I can test { "mobilenum": "+6519829340", "firstname": "Allen", "lastname": "Edwards", "location": "Singapore" "outbound": "YES" "count" : 15 }, { "mobilenum": "+6519829340", "firstname": "Allen", "lastname": "Edwards", "location": "Singapore" "outbound": "NO" "count" : 9 } That there exist two types of data, one containing mobilenum, firstname, etc having

Case Insensitive filtering with lambdaj

﹥>﹥吖頭↗ 提交于 2019-12-12 03:03:25
问题 I'm attempting to familiarize myself with lambdaj, and am unsure how the best way to solve this problem. Given the following test: @Test public void test() { final List<String> l1 = new ArrayList<>(); final List<String> l2 = new ArrayList<>(); l1.add("same"); l1.add("Upper"); l1.add("lower"); l2.add("same"); l2.add("upper"); l2.add("lower"); l2.add("extra"); final List<String> l3 = Lambda.filter(Matchers.not(Matchers.isIn(l1)), l2); Assert.assertThat("There should be one item in l3", l3.size(

Android arraylist filter with hamcrest jar

为君一笑 提交于 2019-12-12 01:36:05
问题 I have an android project, which have an custom object array list, now I want to filter that array list. But always I get zero (size of new array list). public static <T> List<T> filter(Matcher<?> matcher, Iterable<T> iterable) { if (iterable == null) return new LinkedList<T>(); else{ List<T> collected = new LinkedList<T>(); Iterator<T> iterator = iterable.iterator(); if (iterator == null) return collected; while (iterator.hasNext()) { T item = iterator.next(); if (matcher.matches(item))

Sonar complains about assertThat with nullValue

六月ゝ 毕业季﹏ 提交于 2019-12-11 16:47:49
问题 Having the test case using JUnit 4.12: import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; //... @Test public void testShouldReturnNull() { final Long result = getIdFunction.apply(null); assertThat(result, is(nullValue())); } Sonar says: Add at least one assertion to this test case. Why does Sonar says that there are no assertions and how it can be fixed? SonarQube v6.7 回答1: I've just found a solution for this case: Here should be used assertThat

RestAssured comparing Double with Hamcrest

≯℡__Kan透↙ 提交于 2019-12-11 07:28:50
问题 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&nebenkosten=500") .then().body(is(closeTo(0.079, 0.01))); } Error is: Response body doesn't match expectation. Expected: is a numeric value within <0.01> of <0.079> Actual: 0.07960199004975124 It seams I don`t understand the closeTo(double, double). From my understanding all numbers between 0.069 and 0.089 should be