Class ReturnsSmartNulls
- java.lang.Object
-
- org.mockito.internal.stubbing.defaultanswers.ReturnsSmartNulls
-
- All Implemented Interfaces:
java.io.Serializable
,Answer<java.lang.Object>
public class ReturnsSmartNulls extends java.lang.Object implements Answer<java.lang.Object>, java.io.Serializable
Optional Answer that can be used withMockito.mock(Class, Answer)
This implementation can be helpful when working with legacy code. Unstubbed methods often return null. If your code uses the object returned by an unstubbed call you get a NullPointerException. This implementation of Answer returns SmartNulls instead of nulls. SmartNull gives nicer exception message than NPE because it points out the line where unstubbed method was called. You just click on the stack trace.
ReturnsSmartNulls first tries to return ordinary return values (see
ReturnsMoreEmptyValues
) then it tries to return SmartNull. If the return type is not mockable (e.g. final) then ordinary null is returned.ReturnsSmartNulls will be probably the default return values strategy in Mockito 2.1.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ReturnsSmartNulls.ThrowsSmartNullPointer
-
Field Summary
Fields Modifier and Type Field Description private Answer<java.lang.Object>
delegate
private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description ReturnsSmartNulls()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
answer(InvocationOnMock invocation)
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
delegate
private final Answer<java.lang.Object> delegate
-
-
Method Detail
-
answer
public java.lang.Object answer(InvocationOnMock invocation) throws java.lang.Throwable
-
-