public void validateExtraInterfaces(Class<?> classToMock, Collection<Class<?>> extraInterfaces) { if (extraInterfaces == null) { return; } for (Class<?> i : extraInterfaces) { if (classToMock == i) { throw extraInterfacesCannotContainMockedType(classToMock); } } }
private void validateInput(long durationMillis) { if (durationMillis < 0) { throw cannotCreateTimerWithNegativeDurationTime(durationMillis); } }
@Override public MockSettings defaultAnswer(Answer defaultAnswer) { this.defaultAnswer = defaultAnswer; if (defaultAnswer == null) { throw defaultAnswerDoesNotAcceptNullParameter(); } return this; }
@Override public void validateFor(InvocationOnMock invocation) { if (throwable == null) { throw cannotStubWithNullThrowable(); } if (throwable instanceof RuntimeException || throwable instanceof Error) { return; } if (!new InvocationInfo(invocation).isValidException(throwable)) { throw checkedExceptionInvalid(throwable); } } }
public VerificationMode atMost(int maxNumberOfInvocations) { throw atMostAndNeverShouldNotBeUsedWithTimeout(); }
@Override public void validateFor(InvocationOnMock invocation) { if (new InvocationInfo(invocation).isAbstract()) { throw cannotCallAbstractRealMethod(); } } }
/** * Build the identity answer to return the argument at the given position in the argument array. * * @param wantedArgumentPosition * The position of the argument identity to return in the invocation. Using <code>-1</code> indicates the last argument ({@link #LAST_ARGUMENT}). */ public ReturnsArgumentAt(int wantedArgumentPosition) { if (wantedArgumentPosition != LAST_ARGUMENT && wantedArgumentPosition < 0) { throw invalidArgumentRangeAtIdentityAnswerCreationTime(); } this.wantedArgumentPosition = wantedArgumentPosition; }
public void validateConstructorUse(boolean usingConstructor, SerializableMode mode) { if (usingConstructor && mode == SerializableMode.ACROSS_CLASSLOADERS) { throw usingConstructorWithFancySerializable(mode); } } }
private void assertMocksNotEmpty(Object[] mocks) { if (mocks == null || mocks.length == 0) { throw mocksHaveToBePassedToVerifyNoMoreInteractions(); } }
public static void unncessaryStubbingException(List<Invocation> unused) { throw formatUnncessaryStubbingException(null, unused); }
private static <T> void addListeners(T[] listeners, List<T> container, String method) { if (listeners == null) { throw methodDoesNotAcceptParameter(method, "null vararg array."); } for (T listener : listeners) { if (listener == null) { throw methodDoesNotAcceptParameter(method, "null listeners."); } container.add(listener); } }
void throwIfAlreadyAssigned(Field field, boolean alreadyAssigned) { if (alreadyAssigned) { throw moreThanOneAnnotationNotAllowed(field.getName()); } }
public void validateMockedType(Class<?> classToMock, Object spiedInstance) { if (classToMock == null || spiedInstance == null) { return; } if (!classToMock.equals(spiedInstance.getClass())) { throw mockedTypeIsInconsistentWithSpiedInstanceType(classToMock, spiedInstance); } }
@Override public MockSettings invocationListeners(InvocationListener... listeners) { if (listeners == null || listeners.length == 0) { throw invocationListenersRequiresAtLeastOneListener(); } addListeners(listeners, invocationListeners, "invocationListeners"); return this; }
public void validateState() { validateMostStuff(); //validate stubbing: if (stubbingInProgress != null) { Location temp = stubbingInProgress; stubbingInProgress = null; throw unfinishedStubbing(temp); } }
private void validateIndexWithinInvocationRange(InvocationOnMock invocation, int argumentPosition) { if (!wantedArgumentPositionIsValidForInvocation(invocation, argumentPosition)) { throw invalidArgumentPositionRangeAtInvocationTime(invocation, wantedArgumentPosition == LAST_ARGUMENT, wantedArgumentPosition); } }
public static MockitoAssertionError tooLittleActualInvocations(org.mockito.internal.reporting.Discrepancy discrepancy, DescribedInvocation wanted, List<Location> allLocations) { String message = createTooLittleInvocationsMessage(discrepancy, wanted, allLocations); return new TooLittleActualInvocations(message); }
@Override public void validateFor(InvocationOnMock invocation) { if (!new InvocationInfo(invocation).isVoid()) { throw onlyVoidMethodsCanBeSetToDoNothing(); } } }
public VerificationMode never() { throw atMostAndNeverShouldNotBeUsedWithTimeout(); }
@Override public Object callRealMethod() throws Throwable { if (!realMethod.isInvokable()) { throw cannotCallAbstractRealMethod(); } return realMethod.invoke(); }