In the following example (mockito 1.10.19):
MyClass myClass = Mockito.mock(MyClass .class, RETURNS_DEFAULTS);
String s = myClass.getName();
Why does this result in s == null rather than an empty String?
It indeed promised null for a String in ReturnsEmptyValues. But it seems so obvious to return "" that I’m wondering if there is a reason for it not to.
EDIT: updated version to 1.10.19 from 1.8, because no documentation is available anymore for 1.8.
It wasn’t thought of at design time and now for stability reason, this behavior didn’t change.
There’s an non exposed answer called ReturnsMoreEmptyValues that returns as the type name suggests more empty values.
You could also take a look at the Mockito.RETURNS_SMART_NULLS answer that use ReturnsMoreEmptyValues internally and features more interesting debug informations.
Note this links to 1.10.19 version javadoc, however this behavior remains unchanged in version 2.x at the time of this writing.