Class ReturnsDeepStubs
java.lang.Object
org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs
- All Implemented Interfaces:
Serializable
,Answer<Object>
- Direct Known Subclasses:
ReturnsDeepStubs.ReturnsDeepStubsSerializationFallback
Returning deep stub implementation.
Will return previously created mock if the invocation matches.
Supports nested generic information, with this answer you can write code like this :
interface GenericsNest<K extends Comparable<K> invalid input: '&' Cloneable> extends Map<K, Set<Number>> {}
GenericsNest<?> mock = mock(GenericsNest.class, new ReturnsGenericDeepStubs());
Number number = mock.entrySet().iterator().next().getValue().iterator().next();
However this answer does not support generics information when the mock has been deserialized.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static class
private static class
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected GenericMetadataSupport
answer
(InvocationOnMock invocation) private Object
deepStub
(InvocationOnMock invocation, GenericMetadataSupport returnTypeGenericMetadata) private static ReturnsEmptyValues
delegate()
private static MockitoCore
private Object
newDeepStubMock
(GenericMetadataSupport returnTypeGenericMetadata, Object parentMock) Creates a mock using the Generics Metadata.private MockSettings
propagateSerializationSettings
(MockSettings mockSettings, MockCreationSettings parentMockSettings) private StubbedInvocationMatcher
recordDeepStubAnswer
(Object mock, InvocationContainerImpl container) private ReturnsDeepStubs
returnsDeepStubsAnswerUsing
(GenericMetadataSupport returnTypeGenericMetadata) private MockSettings
withSettingsUsing
(GenericMetadataSupport returnTypeGenericMetadata, MockCreationSettings<?> parentMockSettings)
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
ReturnsDeepStubs
public ReturnsDeepStubs()
-
-
Method Details
-
answer
-
deepStub
private Object deepStub(InvocationOnMock invocation, GenericMetadataSupport returnTypeGenericMetadata) throws Throwable - Throws:
Throwable
-
newDeepStubMock
Creates a mock using the Generics Metadata.- Finally as we want to mock the actual type, but we want to pass along the contextual generics meta-data that was resolved for the current return type, for this to happen we associate to the mock an new instance of
ReturnsDeepStubs
answer in which we will store the returned type generic metadata.- Parameters:
returnTypeGenericMetadata
- The metadata to use to create the new mock.parentMock
- The parent of the current deep stub mock.- Returns:
- The mock
- Finally as we want to mock the actual type, but we want to pass along the contextual generics meta-data that was resolved for the current return type, for this to happen we associate to the mock an new instance of
-
withSettingsUsing
private MockSettings withSettingsUsing(GenericMetadataSupport returnTypeGenericMetadata, MockCreationSettings<?> parentMockSettings) -
propagateSerializationSettings
private MockSettings propagateSerializationSettings(MockSettings mockSettings, MockCreationSettings parentMockSettings) -
returnsDeepStubsAnswerUsing
private ReturnsDeepStubs returnsDeepStubsAnswerUsing(GenericMetadataSupport returnTypeGenericMetadata) -
recordDeepStubAnswer
private StubbedInvocationMatcher recordDeepStubAnswer(Object mock, InvocationContainerImpl container) -
actualParameterizedType
-
mockitoCore
-
delegate
-