throw new IllegalArgumentException("Class to verify cannot be null"); NewInvocationControl<?> invocationControl = MockRepository.getNewInstanceControl(mock); if (invocationControl == null) { throw new IllegalStateException(String.format(NO_OBJECT_CREATION_ERROR_MESSAGE_TEMPLATE, Whitebox.getType(
private static void verifyNoMoreInteractions(Class<?>... types) { for (Class<?> type : types) { final MockitoMethodInvocationControl invocationHandler = (MockitoMethodInvocationControl) MockRepository .getStaticMethodInvocationControl(type); if (invocationHandler != null) { invocationHandler.verifyNoMoreInteractions(); } MockitoNewInvocationControl<?> newInvocationControl = (MockitoNewInvocationControl<?>) MockRepository.getNewInstanceControl(type); if (newInvocationControl != null) { newInvocationControl.verifyNoMoreInteractions(); } } } }
throw new IllegalArgumentException("Verify mode cannot be null"); NewInvocationControl<?> invocationControl = MockRepository.getNewInstanceControl(mock); MockRepository.putAdditionalState("VerificationMode", POWERMOCKITO_CORE.wrapInMockitoSpecificVerificationMode( mock, mode));
private static void verifyNoMoreInteractions(Class<?>... types) { for (Class<?> type : types) { final MockitoMethodInvocationControl invocationHandler = (MockitoMethodInvocationControl) MockRepository .getStaticMethodInvocationControl(type); if (invocationHandler != null) { invocationHandler.verifyNoMoreInteractions(); } MockitoNewInvocationControl<?> newInvocationControl = (MockitoNewInvocationControl<?>) MockRepository.getNewInstanceControl(type); if (newInvocationControl != null) { newInvocationControl.verifyNoMoreInteractions(); } } } }
@SuppressWarnings("UnusedDeclaration") public static Object newInstanceCall(Class<?> type, Object[] args, Class<?>[] sig) throws Throwable { final NewInvocationControl<?> newInvocationControl = MockRepository.getNewInstanceControl(type); if (newInvocationControl != null) {
private static synchronized void replay(Class<?>... types) { for (Class<?> type : types) { final MethodInvocationControl invocationHandler = MockRepository.getStaticMethodInvocationControl(type); if (invocationHandler != null) { invocationHandler.replay(); } NewInvocationControl<?> newInvocationControl = MockRepository.getNewInstanceControl(type); if (newInvocationControl != null) { newInvocationControl.replay(); } } }
public <T> DefaultConstructorArgumentsVerification<T> verifyNew(final Class<T> mock, final VerificationMode mode) { assertNotNull(mock, "Class to verify cannot be null"); assertNotNull(mode, "Verify mode cannot be null"); @SuppressWarnings("unchecked") MockitoNewInvocationControl<T> invocationControl = (MockitoNewInvocationControl<T>) MockRepository.getNewInstanceControl(mock); assertNotNull(invocationControl, String.format(NO_OBJECT_CREATION_ERROR_MESSAGE_TEMPLATE, Whitebox.getType(mock).getName())); invocationControl.verify(mode); //noinspection unchecked return new DefaultConstructorArgumentsVerification<T>((NewInvocationControl<T>) invocationControl, mock); }
private NewInvocationControl<OngoingStubbing<T>> createNewInvocationControl(final Class<T> type, final Class<T> unmockedType) { /* * Check if this type has been mocked before */ NewInvocationControl<OngoingStubbing<T>> newInvocationControl = (NewInvocationControl<OngoingStubbing<T>>) MockRepository.getNewInstanceControl(unmockedType); if (newInvocationControl == null) { newInvocationControl = createNewInvocationControl(mock); MockRepository.putNewInstanceControl(type, newInvocationControl); MockRepository.addObjectsToAutomaticallyReplayAndVerify(WhiteboxImpl.getOriginalUnmockedType(type)); } return newInvocationControl; }
/** * Reset a list of class mocks. */ public static synchronized void reset(Class<?>... classMocks) { for (Class<?> type : classMocks) { final MethodInvocationControl invocationHandler = MockRepository.getStaticMethodInvocationControl(type); if (invocationHandler != null) { invocationHandler.reset(); } NewInvocationControl<?> newInvocationControl = MockRepository.getNewInstanceControl(type); if (newInvocationControl != null) { try { newInvocationControl.reset(); } catch (AssertionError e) { NewInvocationControlAssertionError.throwAssertionErrorForNewSubstitutionFailure(e, type); } } } }
/** * Note: doesn't clear PowerMock state. */ private static synchronized void verifyClass(Class<?>... types) { for (Class<?> type : types) { final MethodInvocationControl invocationHandler = MockRepository.getStaticMethodInvocationControl(type); if (invocationHandler != null) { invocationHandler.verify(); } NewInvocationControl<?> newInvocationControl = MockRepository.getNewInstanceControl(type); if (newInvocationControl != null) { try { newInvocationControl.verify(); } catch (AssertionError e) { NewInvocationControlAssertionError.throwAssertionErrorForNewSubstitutionFailure(e, type); } } } }
.getNewInstanceControl(unmockedType); if (newInvocationControl == null) { InvocationSubstitute<T> mock = doMock(InvocationSubstitute.class, false, mockStrategy, null, (Method[]) null);
@SuppressWarnings({"unchecked", "rawtypes"}) private <T> OngoingStubbing<T> createNewSubstituteMock(Class<T> type, Class<?>[] parameterTypes, Object... arguments) throws Exception { if (type == null) { throw new IllegalArgumentException("type cannot be null"); } final Class<T> unmockedType = (Class<T>) WhiteboxImpl.getOriginalUnmockedType(type); if (parameterTypes == null) { WhiteboxImpl.findUniqueConstructorOrThrowException(type, arguments); } else { WhiteboxImpl.getConstructor(unmockedType, parameterTypes); } /* * Check if this type has been mocked before */ NewInvocationControl<OngoingStubbing<T>> newInvocationControl = (NewInvocationControl<OngoingStubbing<T>>) MockRepository.getNewInstanceControl(unmockedType); if (newInvocationControl == null) { InvocationSubstitute<T> mock = getMockCreator().createMock(InvocationSubstitute.class, false, false, null, null, (Method[]) null); newInvocationControl = createNewInvocationControl(mock); MockRepository.putNewInstanceControl(type, newInvocationControl); MockRepository.addObjectsToAutomaticallyReplayAndVerify(WhiteboxImpl.getOriginalUnmockedType(type)); } return newInvocationControl.expectSubstitutionLogic(arguments); }