mlinhard / mockito

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

need <T> T anyInstance(Classs<T>) matcher with Type verification #267

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
The following is easy code to demonstrate the problem.

@Test
public void testAny() {
    Comparator x = mock(Comparator.class);
    x.compare(new Object(), new Object());
    verify(x).compare(any(String.class), any(String.class));
}

I know that in this example, adding the generic types to Comparator could 
expose a type issue, but slightly more elaborate examples without generics can 
result in the same problem

What is the expected output? What do you see instead?

What is expected is for the any() to do more than typesafe casting, but to 
actually match the type.  This test should intuitively fail, but it passes.

What version of the product are you using? On what operating system?
1.8.4, Windows XP

Please provide any additional information below.

I propose: T <T> anyInstance(Class<T>) matcher.  We have added one to our 
project.  I am not sure how resilient it is, but the code is attached.

Original issue reported on code.google.com by kandpwel...@gmail.com on 23 Jun 2011 at 4:07

Attachments:

GoogleCodeExporter commented 9 years ago
I just found T <T> isA(Class<T>).  I had only been looking at all of the 
anyXXX() methods for something that would work.  Thanks for a great product.

Original comment by kandpwel...@gmail.com on 23 Jun 2011 at 4:26

GoogleCodeExporter commented 9 years ago
Ok, cool, closing the non-bug then

Original comment by brice.du...@gmail.com on 23 Jun 2011 at 4:50