Java – why mockito returns_ Default does not return the default string?

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 instead of an empty string?

It does promise null for a string in returnsemptyvalues But returning "" seems obvious, and I wonder if there's any reason not to

Edit: updated from 1.8 to 1.10 19, because there are no documents available for 1.8

Solution

It was not considered in design, and now for stability reasons, this behavior has not changed

There is a non - public answer named returnsmoreemptyvalues, which is returned because the type name represents more null values

You can also view mockito. Com, which uses returnsmoreemptyvalues internally RETURNS_ SMART_ Nulls answers and provides more interesting debugging information

Please note that this link points to 1.10 Version 19 of Javadoc, but at the time of writing, this behavior is in version 2 Remains unchanged in X

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>