Class ReturnsDeepStubs
- java.lang.Object
-
- org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs
-
- All Implemented Interfaces:
java.io.Serializable,Answer<java.lang.Object>
- Direct Known Subclasses:
ReturnsDeepStubs.ReturnsDeepStubsSerializationFallback
public class ReturnsDeepStubs extends java.lang.Object implements Answer<java.lang.Object>, java.io.Serializable
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> & 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classReturnsDeepStubs.DeeplyStubbedAnswerprivate static classReturnsDeepStubs.LazyHolderprivate static classReturnsDeepStubs.ReturnsDeepStubsSerializationFallback
-
Field Summary
Fields Modifier and Type Field Description private static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description ReturnsDeepStubs()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected GenericMetadataSupportactualParameterizedType(java.lang.Object mock)java.lang.Objectanswer(InvocationOnMock invocation)private java.lang.ObjectdeepStub(InvocationOnMock invocation, GenericMetadataSupport returnTypeGenericMetadata)private static ReturnsEmptyValuesdelegate()private static MockitoCoremockitoCore()private java.lang.ObjectnewDeepStubMock(GenericMetadataSupport returnTypeGenericMetadata, java.lang.Object parentMock)Creates a mock using the Generics Metadata.private MockSettingspropagateSerializationSettings(MockSettings mockSettings, MockCreationSettings parentMockSettings)private StubbedInvocationMatcherrecordDeepStubAnswer(java.lang.Object mock, InvocationContainerImpl container)private ReturnsDeepStubsreturnsDeepStubsAnswerUsing(GenericMetadataSupport returnTypeGenericMetadata)private MockSettingswithSettingsUsing(GenericMetadataSupport returnTypeGenericMetadata, MockCreationSettings<?> parentMockSettings)
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Method Detail
-
answer
public java.lang.Object answer(InvocationOnMock invocation) throws java.lang.Throwable
-
deepStub
private java.lang.Object deepStub(InvocationOnMock invocation, GenericMetadataSupport returnTypeGenericMetadata) throws java.lang.Throwable
- Throws:
java.lang.Throwable
-
newDeepStubMock
private java.lang.Object newDeepStubMock(GenericMetadataSupport returnTypeGenericMetadata, java.lang.Object parentMock)
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
ReturnsDeepStubsanswer 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(java.lang.Object mock, InvocationContainerImpl container)
-
actualParameterizedType
protected GenericMetadataSupport actualParameterizedType(java.lang.Object mock)
-
mockitoCore
private static MockitoCore mockitoCore()
-
delegate
private static ReturnsEmptyValues delegate()
-
-