Questions tagged [hamcrest]

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.

Hamcrest has been ported to Java, C++, Objective-C, Python, PHP and Erlang.

It is included as part of JUnit to make assertions more readable (It is also called fluent API). Compare

assertNotEquals(-1, userName.indexOf("bob"));

to

assertThat(userName, containsString("bob"));
710 questions
0
votes
2 answers

Testing contents of a Relative Layout in Espresso

I have the following Structure: +------------>LinearLayout{id=2131689635, res-name=ll_monthly_advance_payments_container, | +------------->LinearLayout{id=2131689636, res-name=ll_monthly_advance_payments_list_container,…
0
votes
1 answer

How to use JUnit assertThat correctly?

I have a class called Calculator with the four basic operations of adding, subtracting, dividing and multiplying public class Calculator{ public int add(int a, int b) { return a + b; } public int subtract(int a,…
ricardoramos
  • 891
  • 3
  • 18
  • 35
0
votes
2 answers

Create Test case for sorted list of strings

I hava a list of strings and in my code I order this list. I want to write a unit test to ensure that the list has been orderer properly. my code @Test public void test() { List orderedList = new ArrayList(); …
FarFarAway
  • 1,017
  • 3
  • 14
  • 35
0
votes
1 answer

InvalidUseOfMatchersException

I'm busy with writing a Junit test with Mockito. Now I want to verify something like this: verify(event).fire( new DefaultMonitoringEventImpl( any(Class.class), any(MonitorEventType.class), MonitorEventLevel.ALL, anyString() ) ); I…
Bgvv1983
  • 1,256
  • 1
  • 13
  • 27
0
votes
0 answers

My custom matcher is not debuggable when running in intellij

I'm wondering if I have a syntax error or mistake? I have this assertion in my test: verify(myHttpClient).updateConfig(anyString(),anyString(), argThat(new OnlySpecificCountryInPropertiesHasChangedMatcher(countryGasStationConfig,…
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
0
votes
1 answer

Unit Tests Failure At Xcode 3.2.4, iOS 4.1 SDK Using Hamcrest Assertion

We upgraded to Xcode 3.2.4 with iOS 4.1 SDK, now our tests are failing. First because of this An internal error occurred when handling command output: -[XCBuildLogCommandInvocationSectionRecorder endMarker]: unrecognized selector sent to instance…
Noura
  • 722
  • 10
  • 24
0
votes
0 answers

Getting value of a JSON property using JSONpath

I have the following JSON and I need to check if the value of total is 10 using JSONPath: { "total": 10, "parkingSlots": [ { "type": "MOTORCYCLE", "empty": true, "spaceId": "1m60" }, { "type": "MOTORCYCLE", …
0
votes
2 answers

instanceOf vs sameInstance

I am programming a test class using Mockito. I have a class that has a method to return another class public BuilderClass build(){ return AnotherClass; } When I use assertThat(BuilderClass.build(), is(instanceOf(AnotherClass.class))); The…
Chema
  • 67
  • 4
  • 17
0
votes
1 answer

Duplicate entry: org/hamcrest/BaseDescription.class

There is another question that has an answer that does not work for me (as I don't have the library the selected answer has). I have searched through all my project for the BaseDescription and there is only 1 occurrence of the BaseDescription and…
Aggressor
  • 13,323
  • 24
  • 103
  • 182
0
votes
1 answer

error: package org.hamcrest does not exist Android Studio 1.5.1

I am using Android studio 1.5.1. My build.gradle looks like below allprojects { repositories { maven { url 'http://repo1.maven.org/maven2' } } } buildscript { repositories { jcenter() …
Deepu
  • 598
  • 6
  • 12
0
votes
1 answer

unit test for a method using generics

I took from this forum a following method and I cannot get my head around how to write a junit test. I looked in the forum for answers but have not found anything concrete. Hopefully someone knows? This is my method: public String replaceName(…
user5919106
0
votes
2 answers

Asserting values inside different custom objects using hamcrest

I'm quite new to using hamcrest for asserts, and I've already got a pretty nasty case to test. We've got 2 arraylists of different, custom objects: FilterItem and MyEnum. Both contain a property - let's say 'value' - which should be equal for the…
Patrick Kuijpers
  • 362
  • 1
  • 3
  • 8
0
votes
1 answer

Creating a Matcher for jUnit

The following code is designed to allow more natural assertions about the size of a stream. Matcher hasCount(int count) { return new TypeSafeDiagnosingMatcher() { protected boolean matchesSafely(Stream stream,…
sprinter
  • 27,148
  • 6
  • 47
  • 78
0
votes
1 answer

Android arraylist filter with hamcrest jar

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 List filter(Matcher matcher, Iterable iterable) { if (iterable ==…
Mohammad Rajob
  • 743
  • 1
  • 11
  • 29
0
votes
1 answer

IntelliJ IDEA why I don't see the method in import dialog? (have in project and if put with copy-past to class, it's accessible). Maven+Java project

I use 15.0.4 IDEA Coomunity edtition (same trouble was for at least for 2 versions). Actually, I clicked something wrong and need help. :-) So... In pom.xml I have in list of my dependencies: org.hamcrest