-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The signature of isA is completely wrong #27
Comments
"completely wrong" were Nat's exact words btw - nothing to do with me.... :-) |
This is interesting in conjunction with some of Nat's other discussions on the matter: |
It should be <T> Matcher<Object> isA(Class<T> expectedType, Matcher<? super T> downcastMatcher) |
Which is a matcher of object not T. That would do it I think.
|
I'll have a go at this soon... watch this space :) |
oddly all the angle brackets in the type signature didn't appear in the email i got from github... hence my comment about Object, not T - which you can see here but not in the email... |
I'm surprised this hasn't gotten more attention! This is a problem in the most obvious use case, i.e.
|
Has there ever been any progress on this issue? I made my own version of isA() to get around the issues discussed here. |
@EarthCitizen: would be nice to see it as a Gist. |
isA() is an alias for instanceOf() is it not? What about something like isClass() for exact Class matching? |
The method isA needs to create a Matcher for arbitrary objects to support matching of superclasses as is(instanceOf(...)) does to make both calls equivalent.
I've submitted an Pull Request (#127) to fix this. The behavior of |
Fixed |
Could you please give us an indication of which version this was/will be released for? Thanks. |
This change hasn't been released yet. I'm not a Hamcrest member so I can't tell when they plan to release the next one, but for now it looks like you'll have to build from source. Unfortunately master still has the version number listed as 2.0.0.0, so you'd probably have to change that in your build if you're going to add it to a local repo. |
Any hope of this eventually being released? |
I think the problem is that the version in |
|
junit:4.13 depend on hamcrest-core:1.3 also has this problem |
does |
feel free to raise PR with junit so v4.14 could be upgrade to the latest version, that being currently v1.x is dead and out of support |
public static org.hamcrest.Matcher isA(java.lang.Class type) {
return org.hamcrest.core.Is.isA(type);
}
means you have to cast the thing to the type you are asserting it should be. Really it should be a matcher of anything (Object) not T.
e.g.
class hierarchy Foo extends Bar
Bar thing = somemethod();
assertThat(thing, isA(Foo.class))
to assert that you are getting the right subclass back - yeah ok, it might not be the best test, but anyhow......
The text was updated successfully, but these errors were encountered: