Closed GoogleCodeExporter closed 9 years ago
This issue also occurs for Mockito 1.8.0-rc2.
Original comment by erik.bra...@gmail.com
on 19 Jun 2009 at 9:03
Hi, thanks a lot for the detailed description!
I looked at the implementation and here is how it works:
intMethod(int x);
verify(mock).intMethod(isA(int.class));
//isA() matcher returns null (most of the matcher-methods return null)
//java is autounboxing to int and the value to autounbox is null, hence NPE
This is related to all kinds of matchers that return null where args are
primitive.
Interestingly, this is very unusual case. For example, most people use anyInt()
instead of isA(int.class) because the first one is more explicit. After all, you
really want 'any int' and you're not interested in the type because the compiler
checks it for you.
What about fixing it? Fixing it requires the matcher methods to return
corresponding
primitive value in some cases instead of null. I'm not going to able to fix it
for
all matcher methods because usually the matcher method doesn't know the type of
argument. For example: public static <T> T eq(T value) doesn't know the type
(generic
T is erasured in runtime), therefore following code will always throw NPE:
verify(mock).intMethod(eq(new Integer(100)));
I'll try to fix it for some matcher methods that do have access to the arg type
(it's
minority, for example isA(Class<T> clazz)). For now though, please consider
using
anyInt() instead of isA(int.class).
Original comment by szcze...@gmail.com
on 19 Jun 2009 at 9:31
Original comment by szcze...@gmail.com
on 20 Oct 2009 at 7:44
This issue was closed by revision r1677.
Original comment by szcze...@gmail.com
on 9 Nov 2009 at 10:36
Original comment by szcze...@gmail.com
on 11 Nov 2009 at 1:33
Original comment by szcze...@gmail.com
on 11 Nov 2009 at 2:45
Original comment by brice.du...@gmail.com
on 2 Dec 2012 at 10:21
Original issue reported on code.google.com by
erik.bra...@gmail.com
on 19 Jun 2009 at 8:59Attachments: