freepascal / mockito

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

Returns 0 (autoboxed?) for object Integer by default, expected null #88

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Insert mock service which has a method returning Integer object (not 
primitive) 
2. Output the return of it when called, it returns zero.

Appears to be a new Integer instance with a value of zero. 

What version of the product are you using? On what operating system?
Mockito 1.7, within TestNG on Java 1.5.0.11

Original issue reported on code.google.com by ssqos...@gmail.com on 26 May 2009 at 5:36

GoogleCodeExporter commented 9 years ago
Tried changing the return type to Number and the mock returns null.
Tried Double and the mock returned 0.0.

Note: This is with no stubbing on the mock, just a plain new mock creation and 
calling the methods on it.

Original comment by ssqos...@gmail.com on 26 May 2009 at 5:41

GoogleCodeExporter commented 9 years ago
Hi,

The compiler hides the difference between int and Integer and vice versa. 
Therefore
we decided to make the framework consistent and have zeros returned by default 
also
by Integer-returning methods. It was done in some very early version of 
Mockito. I
didn't think about Number though - it probably should also return 0.

Mockito by default tries to return 'nice' values to be transparent and 
unobtrusive.
Therefore zeros but not nulls because it is less likely you will hit NPE.

Original comment by szcze...@gmail.com on 26 May 2009 at 9:27

GoogleCodeExporter commented 9 years ago
Ok, that makes sense now. Although it is not what I (and my colleagues) would 
expect. 
I will pass this on.

Again, thanks for clearing this up

Original comment by ssqos...@gmail.com on 26 May 2009 at 10:45

GoogleCodeExporter commented 9 years ago
Ok cool.

I'll try to make it clearer in the FAQ or the documentation later.

Original comment by szcze...@gmail.com on 27 May 2009 at 12:35

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 9 Jul 2009 at 12:48

GoogleCodeExporter commented 9 years ago
Added info to the FAQ, closing this one.

Original comment by szcze...@gmail.com on 22 Sep 2009 at 9:10