use of org.mockito.invocation.MockHandler in project powermock by powermock.
the class PowerMockitoStubberImpl method addAnswersForStubbing.
@SuppressWarnings("unchecked")
private void addAnswersForStubbing(MockitoMethodInvocationControl invocationControl) {
final MockHandler mockHandler = invocationControl.getInvocationHandler().getHandler();
final List list = Whitebox.getInternalState(this, List.class);
try {
Whitebox.invokeMethod(mockHandler, "setAnswersForStubbing", list);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.mockito.invocation.MockHandler in project mockito by mockito.
the class MockUtil method getMockHandler.
public static MockHandler<?> getMockHandler(Object mock) {
if (mock == null) {
throw new NotAMockException("Argument should be a mock, but is null!");
}
mock = resolve(mock);
MockHandler handler = mockMaker.getHandler(mock);
if (handler != null) {
return handler;
} else {
throw new NotAMockException("Argument should be a mock, but is: " + mock.getClass());
}
}
use of org.mockito.invocation.MockHandler in project mockito by mockito.
the class MockitoCore method verify.
public <T> T verify(T mock, VerificationMode mode) {
if (mock == null) {
throw nullPassedToVerify();
}
MockingDetails mockingDetails = mockingDetails(mock);
if (!mockingDetails.isMock()) {
throw notAMockPassedToVerify(mock.getClass());
}
assertNotStubOnlyMock(mock);
MockHandler handler = mockingDetails.getMockHandler();
mock = (T) VerificationStartedNotifier.notifyVerificationStarted(handler.getMockSettings().getVerificationStartedListeners(), mockingDetails);
MockingProgress mockingProgress = mockingProgress();
VerificationMode actualMode = mockingProgress.maybeVerifyLazily(mode);
mockingProgress.verificationStarted(new MockAwareVerificationMode(mock, actualMode, mockingProgress.verificationListeners()));
return mock;
}
use of org.mockito.invocation.MockHandler in project mockito by mockito.
the class MockedStaticImpl method verify.
@Override
public void verify(Verification verification, VerificationMode mode) {
assertNotClosed();
MockingDetails mockingDetails = Mockito.mockingDetails(control.getType());
MockHandler handler = mockingDetails.getMockHandler();
VerificationStartedNotifier.notifyVerificationStarted(handler.getMockSettings().getVerificationStartedListeners(), mockingDetails);
MockingProgress mockingProgress = mockingProgress();
VerificationMode actualMode = mockingProgress.maybeVerifyLazily(mode);
mockingProgress.verificationStarted(new MockAwareVerificationMode(control.getType(), actualMode, mockingProgress.verificationListeners()));
try {
verification.apply();
} catch (MockitoException | MockitoAssertionError e) {
throw e;
} catch (Throwable t) {
throw new MockitoException(join("An unexpected error occurred while verifying a static stub", "", "To correctly verify a stub, invoke a single static method of " + control.getType().getName() + " in the provided lambda.", "For example, if a method 'sample' was defined, provide a lambda or anonymous class containing the code", "", "() -> " + control.getType().getSimpleName() + ".sample()", "or", control.getType().getSimpleName() + "::sample"), t);
}
}
Aggregations