public VerificationCollector assertLazily() { mockingProgress().setVerificationStrategy(new VerificationStrategy() { public VerificationMode maybeVerifyLazily(VerificationMode mode) { return new VerificationWrapper(mode); } }); return this; }
/** * For testing purposes only. Is not the part of main API. * * @return last invocation */ public Invocation getLastInvocation() { OngoingStubbingImpl ongoingStubbing = ((OngoingStubbingImpl) mockingProgress().pullOngoingStubbing()); List<Invocation> allInvocations = ongoingStubbing.getRegisteredInvocations(); return allInvocations.get(allInvocations.size() - 1); }
public <T> T mock(Class<T> typeToMock, MockSettings settings) { if (!MockSettingsImpl.class.isInstance(settings)) { throw new IllegalArgumentException("Unexpected implementation of '" + settings.getClass().getCanonicalName() + "'\n" + "At the moment, you cannot provide your own implementations of that class."); } MockSettingsImpl impl = MockSettingsImpl.class.cast(settings); MockCreationSettings<T> creationSettings = impl.build(typeToMock); T mock = createMock(creationSettings); mockingProgress().mockingStarted(mock, creationSettings); return mock; }
public MockitoFramework removeListener(MockitoListener listener) { Checks.checkNotNull(listener, "listener"); mockingProgress().removeListener(listener); return this; }
public MockitoFramework addListener(MockitoListener listener) { Checks.checkNotNull(listener, "listener"); mockingProgress().addListener(listener); return this; }
/** * int argument that does not match the given argument matcher. * <p> * See examples in javadoc for {@link AdditionalMatchers} class * * @param first * placeholder for the argument matcher. * @return <code>0</code>. */ public static int not(int first) { mockingProgress().getArgumentMatcherStorage().reportNot(); return 0; }
/** * double argument that does not match the given argument matcher. * <p> * See examples in javadoc for {@link AdditionalMatchers} class * * @param first * placeholder for the argument matcher. * @return <code>0</code>. */ public static double not(double first) { mockingProgress().getArgumentMatcherStorage().reportNot(); return 0; }
/** * boolean argument that does not match the given argument matcher. * <p> * See examples in javadoc for {@link AdditionalMatchers} class * * @param first * placeholder for the argument matcher. * @return <code>false</code>. */ public static boolean not(boolean first) { mockingProgress().getArgumentMatcherStorage().reportNot(); return false; }
/** * long argument that does not match the given argument matcher. * <p> * See examples in javadoc for {@link AdditionalMatchers} class * * @param first * placeholder for the argument matcher. * @return <code>0</code>. */ public static long not(long first) { mockingProgress().getArgumentMatcherStorage().reportNot(); return 0; }
/** * float argument that does not match the given argument matcher. * <p> * See examples in javadoc for {@link AdditionalMatchers} class * * @param first * placeholder for the argument matcher. * @return <code>0</code>. */ public static float not(float first) { mockingProgress().getArgumentMatcherStorage().reportNot(); return 0; }
/** * byte argument that does not match the given argument matcher. * <p> * See examples in javadoc for {@link AdditionalMatchers} class * * @param first * placeholder for the argument matcher. * @return <code>0</code>. */ public static byte not(byte first) { mockingProgress().getArgumentMatcherStorage().reportNot(); return 0; }
public void collectAndReport() throws MockitoAssertionError { mockingProgress().setVerificationStrategy(MockingProgressImpl.getDefaultVerificationStrategy()); if (this.numberOfFailures > 0) { String error = this.builder.toString(); this.resetBuilder(); throw new MockitoAssertionError(error); } }
private static <T> void reportMatcher(Matcher<T> matcher) { mockingProgress().getArgumentMatcherStorage().reportMatcher(new HamcrestArgumentMatcher<T>(matcher)); } }
public Stubber stubber(Strictness strictness) { MockingProgress mockingProgress = mockingProgress(); mockingProgress.stubbingStarted(); mockingProgress.resetOngoingStubbing(); return new StubberImpl(strictness); }
@Override public Stubber doThrow(Class<? extends Throwable> toBeThrown, Class<? extends Throwable>... nextToBeThrown) { Stubber stubber = doThrow(toBeThrown); if (nextToBeThrown == null) { mockingProgress().reset(); throw notAnException(); } for (Class<? extends Throwable> next : nextToBeThrown) { stubber = stubber.doThrow(next); } return stubber; }
@Override public OngoingStubbing<T> thenThrow(Class<? extends Throwable> throwableType) { if (throwableType == null) { mockingProgress().reset(); throw notAnException(); } return thenThrow(newInstance(throwableType)); }
public <T> OngoingStubbing<T> when(T methodCall) { MockingProgress mockingProgress = mockingProgress(); mockingProgress.stubbingStarted(); @SuppressWarnings("unchecked") OngoingStubbing<T> stubbing = (OngoingStubbing<T>) mockingProgress.pullOngoingStubbing(); if (stubbing == null) { mockingProgress.reset(); throw missingMethodInvocation(); } return stubbing; }
public <T> void reset(T... mocks) { MockingProgress mockingProgress = mockingProgress(); mockingProgress.validateState(); mockingProgress.reset(); mockingProgress.resetOngoingStubbing(); for (T m : mocks) { resetMock(m); } }
public void verifyNoMoreInteractionsInOrder(List<Object> mocks, InOrderContext inOrderContext) { mockingProgress().validateState(); VerificationDataInOrder data = new VerificationDataInOrderImpl(inOrderContext, VerifiableInvocationsFinder.find(mocks), null); VerificationModeFactory.noMoreInteractions().verifyInOrder(data); }
public <T> void clearInvocations(T... mocks) { MockingProgress mockingProgress = mockingProgress(); mockingProgress.validateState(); mockingProgress.reset(); mockingProgress.resetOngoingStubbing(); for (T m : mocks) { getInvocationContainer(m).clearInvocations(); } }