Merge pull request #6323 from szpak/issues/6320-mockito-2.0.47-compatibility

* issues/6320-mockito-2.0.47-compatibility:
  Fix compatibility with Mockito 2.0
pull/6342/merge
Phillip Webb 8 years ago
commit 4742486d3e

@ -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();
}
}

Loading…
Cancel
Save