Class ReturnsEmptyValues
java.lang.Object
org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues
- All Implemented Interfaces:
Serializable, Answer<Object>
Default answer of every Mockito mock.
- Returns appropriate primitive for primitive-returning methods
- Returns consistent values for primitive wrapper classes (e.g. int-returning method returns 0 and Integer-returning method returns 0, too)
- Returns empty collection for collection-returning methods (works for most commonly used collection types)
- Returns description of mock for toString() method
- Returns zero if references are equals otherwise non-zero for Comparable#compareTo(T other) method (see issue 184)
-
Returns an
java.util.Optional#empty() empty Optionalfor Optional. Similarly for primitive optional variants. -
Returns an
java.util.stream.Stream#empty() empty Streamfor Stream. Similarly for primitive stream variants. -
Returns an
java.time.Duration.ZERO zero Durationfor empty Duration andjava.time.Period.ZERO zero Periodfor empty Period. - Returns null for everything else
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionanswer(InvocationOnMock invocation) (package private) static ObjectreturnCommonEmptyValueFor(Class<?> type) Returns empty values for common known types, shared betweenReturnsEmptyValuesandReturnsDeepStubs.(package private) ObjectreturnValueFor(Class<?> type)
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
ReturnsEmptyValues
public ReturnsEmptyValues()
-
-
Method Details
-
answer
-
returnValueFor
-
returnCommonEmptyValueFor
Returns empty values for common known types, shared betweenReturnsEmptyValuesandReturnsDeepStubs.- Parameters:
type- the type to check- Returns:
- the empty value, or
null
-