/**
* Verifies certain behavior happened at least once / exact number of times
* / never. E.g:
*
* <pre>
* verifyNew(ClassWithStaticMethod.class, times(5));
*
* verifyNew(ClassWithStaticMethod.class, atLeast(2));
*
* //you can use flexible argument matchers, e.g:
* verifyNew(ClassWithStaticMethod.class, atLeastOnce());
* </pre>
*
* <b>times(1) is the default</b> and can be omitted
* <p>
*
* @param mock
* to be verified
* @param mode
* times(x), atLeastOnce() or never()
*/
@SuppressWarnings("unchecked")
public static <T> ConstructorArgumentsVerification verifyNew(Class<?> mock, VerificationMode mode) {
if (mock == null) {
throw new IllegalArgumentException("Class to verify cannot be null");
} else if (mode == null) {
throw new IllegalArgumentException("Verify mode cannot be null");
}
NewInvocationControl<?> invocationControl = MockRepository.getNewInstanceControl(mock);
MockRepository.putAdditionalState("VerificationMode", POWERMOCKITO_CORE.wrapInMockitoSpecificVerificationMode(
mock, mode));
if (invocationControl == null) {
throw new IllegalStateException(String.format(NO_OBJECT_CREATION_ERROR_MESSAGE_TEMPLATE, Whitebox.getType(
mock).getName()));
}
try {
invocationControl.verify();
} finally {
MockRepository.removeAdditionalState("VerificationMode");
}
return new DefaultConstructorArgumentsVerfication<T>((NewInvocationControl<T>) invocationControl, mock);
}
PowerMockito.java 文件源码
java
阅读 36
收藏 0
点赞 0
评论 0
项目:powermock
作者:
评论列表
文章目录