Skip to content

Commit

Permalink
fixed files form Mockito #10
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Mar 7, 2017
1 parent ddc91b5 commit 888b8d3
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.mockito.internal.util.MockUtil;
import org.mockito.internal.util.reflection.GenericMetadataSupport;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.mock.MockCreationSettings;
import org.mockito.stubbing.Answer;

import java.io.IOException;
Expand Down Expand Up @@ -68,7 +69,7 @@ private Object deepStub(InvocationOnMock invocation, GenericMetadataSupport retu

// record deep stub answer
return recordDeepStubAnswer(
newDeepStubMock(returnTypeGenericMetadata),
newDeepStubMock(returnTypeGenericMetadata, invocation.getMock()),
container
);
}
Expand All @@ -84,22 +85,26 @@ private Object deepStub(InvocationOnMock invocation, GenericMetadataSupport retu
* @param parentMock The parent of the current deep stub mock.
* @return The mock
*/
private Object newDeepStubMock(GenericMetadataSupport returnTypeGenericMetadata) {
private Object newDeepStubMock(GenericMetadataSupport returnTypeGenericMetadata, Object parentMock) {
MockCreationSettings parentMockSettings = new MockUtil().getMockSettings(parentMock);
return mockitoCore().mock(
returnTypeGenericMetadata.rawType(),
withSettingsUsing(returnTypeGenericMetadata)
withSettingsUsing(returnTypeGenericMetadata, parentMockSettings)
);
}

private MockSettings withSettingsUsing(GenericMetadataSupport returnTypeGenericMetadata) {
private MockSettings withSettingsUsing(GenericMetadataSupport returnTypeGenericMetadata, MockCreationSettings parentMockSettings) {
MockSettings mockSettings = returnTypeGenericMetadata.hasRawExtraInterfaces() ?
withSettings().extraInterfaces(returnTypeGenericMetadata.rawExtraInterfaces())
: withSettings();

return mockSettings.serializable()
return propagateSerializationSettings(mockSettings, parentMockSettings)
.defaultAnswer(returnsDeepStubsAnswerUsing(returnTypeGenericMetadata));
}

private MockSettings propagateSerializationSettings(MockSettings mockSettings, MockCreationSettings parentMockSettings) {
return mockSettings.serializable(parentMockSettings.getSerializableMode());
}

private ReturnsDeepStubs returnsDeepStubsAnswerUsing(final GenericMetadataSupport returnTypeGenericMetadata) {
return new ReturnsDeepStubsSerializationFallback(returnTypeGenericMetadata);
Expand Down

0 comments on commit 888b8d3

Please sign in to comment.