|
|
|
@ -24,6 +24,7 @@ import java.util.Set;
|
|
|
|
|
import org.mockito.Answers;
|
|
|
|
|
import org.mockito.MockSettings;
|
|
|
|
|
import org.mockito.Mockito;
|
|
|
|
|
import org.mockito.stubbing.Answer;
|
|
|
|
|
|
|
|
|
|
import org.springframework.core.style.ToStringCreator;
|
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
@ -151,11 +152,19 @@ class MockDefinition extends Definition {
|
|
|
|
|
if (!this.extraInterfaces.isEmpty()) {
|
|
|
|
|
settings.extraInterfaces(this.extraInterfaces.toArray(new Class<?>[] {}));
|
|
|
|
|
}
|
|
|
|
|
settings.defaultAnswer(this.answer.get());
|
|
|
|
|
settings.defaultAnswer(getAnswer(this.answer));
|
|
|
|
|
if (this.serializable) {
|
|
|
|
|
settings.serializable();
|
|
|
|
|
}
|
|
|
|
|
return (T) Mockito.mock(this.classToMock, settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Answer<?> getAnswer(Answers answer) {
|
|
|
|
|
if (Answer.class.isInstance(answer)) {
|
|
|
|
|
// With Mockito 2.0 we can directly cast the answer
|
|
|
|
|
return (Answer<?>) ((Object) answer);
|
|
|
|
|
}
|
|
|
|
|
return answer.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|