Comments (11)
The message isn't helpful, but the matching appears to be wrong too. You're asserting that the /bean/ has an item, not its strings property, so there's a type failure.
from javahamcrest.
But Bean implements Iterable<String>
, so that should be OK, no?
from javahamcrest.
oops. you're right. Missed that
from javahamcrest.
Looks like the hasItem Matcher does not describe a mismatch correctly.
--Nat
On Tuesday, March 12, 2013, James Shaw wrote:
https://gist.github.com/hertzsprung/5141786
Gives me
java.lang.AssertionError:
Expected: (hasProperty("myBoolean", ) and a collection containing "quux")
but: a collection containing "quux"even though the collection was empty.
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/31
.
from javahamcrest.
Running this example against the trunk of Hamcrest gives the following output:
java.lang.AssertionError:
Expected: (hasProperty("myBoolean", <true>) and a collection containing "quux")
but: a collection containing "quux" was empty
There are several fixes in the Hamcrest trunk that have not been released yet. I shall endeavour to push a new release soon (I keep threatening to do this, but somehow never sit down and do it).
from javahamcrest.
That still seems strange to me. How can an empty collection contain
anything? :)
On 13 Mar 2013 19:26, "Tom Denley" [email protected] wrote:
Running this example against the trunk of Hamcrest gives the following
output:java.lang.AssertionError:
Expected: (hasProperty("myBoolean", ) and a collection containing "quux")
but: a collection containing "quux" was emptyThere are several fixes in the Hamcrest trunk that have not been released
yet. I shall endeavour to push a new release soon (I keep threatening to do
this, but somehow never sit down and do it).—
Reply to this email directly or view it on GitHubhttps://github.com//issues/31#issuecomment-14862879
.[image: Web Bug from
https://github.com/notifications/beacon/IKuIsTejRivtv8yEN00ua_Q8EUxiDL46Oh7ZoalVDntonYGUxFtFvUxfqXq2RGQN.gif]
from javahamcrest.
This is a behaviour of the allOf
matcher: When one of the wrapped matchers fails, it prints first the failing matcher's description, then its mismatch description.
Often a matcher's mismatch description does not uniquely identify it, and so printing that on its own might make it hard for a user to determine which matcher amongst those wrapped in an allOf
actually caused the mismatch.
from javahamcrest.
I think it should not print the failing matcher's description alone but add some clarifying text to give context. E.g. 'clause () did not match: .
java.lang.AssertionError:
Expected: (hasProperty("myBoolean", <true>) and a collection containing "quux")
but: clause 2 (a collection containing "quux") did not match: was empty
And hasItem should print a better failure description. E.g. "the collection was empty".
from javahamcrest.
I've been thinking about increasing the descriptiveness of a few of the core matchers, particularly in mismatch scenarios, but I think @sf105 has reasonably strong feelings against increasing the verbosity of the library -- see 96e113d#commitcomment-2308318.
I actually improved this very mismatch to "was an empty collection" but Steve reversed this with e1995a6
I apologise If I'm misrepresenting you Steve, but I would value your opinion on this.
from javahamcrest.
Thanks for the feedback guys.
I've hit this again with some custom matchers; the diagnostics I get are along the lines of "expected object but was object array", rather than "expected object but was array".
If it's not sufficient to print the failing matcher's own mismatch description, then I would favour @npryce 's suggestion. Although, imho, it would read better without any clarifying text because matchers within allOf() tend to check for orthogonal features.
from javahamcrest.
I've just merged a PR that removes the "clarifying" text.
from javahamcrest.
Related Issues (20)
- assertThat(this.object, hasProperty("booleanName")) fails to match boolean types and renames the property HOT 1
- The matcher contains() is misleading HOT 2
- FR: Matching maps with various type HOT 1
- oss-fuzz integration
- Participitation in Hacktoberfest? HOT 1
- HasProperty Matcher doesn't work with Java Records HOT 4
- assertThat(Int::class.java, typeCompatibleWith(Number::class.java)) in kotlin always fails
- hamcrest matching on actual empty list fails with nosuchmethoderror HOT 1
- Test output Alignment
- record version fails the hasProperty HOT 2
- has property fails with non public class.. not sure if this correct as per java standards of property
- Double "close-to" matcher that uses the ULP.
- GraalVM Native Image support HOT 4
- Inquiry about Project Activity and Future Plans HOT 15
- Compatibility in java versions HOT 2
- Upgrade build to JDK 1.8 bytecode HOT 1
- Upgrade to latest Gradle HOT 1
- Publish to Maven Central using GitHub Actions HOT 6
- Hamcrest v3.1
- Hamcrest v4.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javahamcrest.