Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Mockito's mock returns 0 when it should return null?

When there's some object with a boxed type property, the getter of the property returns 0. But this should return null, because the default value of the boxed type property is null. What is the problem here?

class Person {
    private Long id;

    public Long getId() {
        return id;
    }
}
...

@Mock Person person;

...
person.getId(); // 0 instead of null
like image 475
Sanghyun Lee Avatar asked Oct 28 '14 05:10

Sanghyun Lee


1 Answers

That's simply the chosen default value for primitive and wrapper types in the default Mockito answer.

like image 64
Brice Avatar answered Sep 22 '22 13:09

Brice