I had the same problem and my solution was to change the standard layout response to null :
Person person; ... person = mock(Person.class, new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { return null; } }); person.getId();
(Not sure if you can set a default answer if you want to use @Mock annotation)
If for some reason you would like to set the default value for Long (and not, for example, Integer ), this should do the trick inside the answer method:
if(invocation.getMethod().getReturnType().equals(Long.class)){ return null; }else{ return Mockito.RETURNS_DEFAULTS.answer(invocation); }
LoPoBo
source share