jocarreira / hamcrest

Automatically exported from code.google.com/p/hamcrest
0 stars 0 forks source link

retarget instanceOf() and any() #52

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

Just had a chat with David Saff about this mess...

The killer for a typed instanceOf is that we can't do 

  assertThat(anObject, not(instanceOf(Number.class)));

but we also want in JMock to be able to do

  with(instanceOf(Integer.class))

and have it work without casting

David pointed out that we might be using the wrong clause and that instead we 
should use

  aMock.amethod(with(any(Integer.class)))

At the moment, this matcher ignores the actual value altogether, so the clause 
is misleading.

So, proposals:

1) instanceOf() to be defined in terms of Object
2) any() to check the type of the value passed to it and by implemented by 
InstanceOf

Original issue reported on code.google.com by smgfree...@gmail.com on 22 Nov 2008 at 12:14

GoogleCodeExporter commented 8 years ago
Would the signature: <T, B super T> Matcher<B> instanceOf(Class<T> type) work?

Original comment by nat.pr...@gmail.com on 22 Nov 2008 at 3:43

GoogleCodeExporter commented 8 years ago
sadly, it doesn't compile. There's a more fundamental problem which is that 
sometimes we want the binding to 
go one way and sometimes the other. David also suggested that we add a typed 
with() for the times we need it:

with(List.class, instanceOf(ArrayList.class))

but I'm not sure I like that.

Original comment by smgfree...@gmail.com on 22 Nov 2008 at 3:59

GoogleCodeExporter commented 8 years ago
I'd think we'd only want the binding to go upward from the type being compared
because otherwise the static type checking gives us all the info we're testing.

The "typed" with doesn't work with generic types (like List!) -- that's why 
jMock has
to rely on the Java compiler unifying the types.

Original comment by nat.pr...@gmail.com on 22 Nov 2008 at 5:59

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I've done some fixing in this are and checked it in

Original comment by smgfree...@gmail.com on 20 Dec 2008 at 8:58

GoogleCodeExporter commented 8 years ago

Original comment by smgfree...@gmail.com on 21 May 2009 at 10:46

GoogleCodeExporter commented 8 years ago

Original comment by smgfree...@gmail.com on 21 May 2009 at 10:46