Package org.mockito.internal.exceptions
Class Reporter
java.lang.Object
org.mockito.internal.exceptions.Reporter
Reports verification and misusing errors.
One of the key points of mocking library is proper verification/exception messages. All messages in one place makes it easier to tune and amend them.
Reporter can be injected and therefore is easily testable.
Generally, exception messages are full of line breaks to make them easy to read (xunit plugins take only fraction of screen on modern IDEs).
-
Method Summary
Modifier and TypeMethodDescriptionstatic AssertionErrorargumentsAreDifferent(Invocation actualInvocation, MatchableInvocation matchableInvocation, String wanted, List<String> actualCalls, List<Location> actualLocations) static MockitoExceptionstatic MockitoExceptionstatic MockitoExceptioncannotCreateTimerWithNegativeDurationTime(long durationMillis) static MockitoExceptioncannotInitializeForInjectMocksAnnotation(String fieldName, String causeMessage) static MockitoExceptioncannotInitializeForSpyAnnotation(String fieldName, Exception details) static MockitoExceptioncannotInjectDependency(Field field, Object matchingMock, Exception details) static MockitoExceptioncannotMockClass(Class<?> clazz, String reason) static MockitoExceptioncannotStubVoidMethodWithAReturnValue(String methodName) static MockitoExceptionstatic MockitoExceptionstatic MockitoExceptionstatic MockitoExceptionstatic MockitoExceptiondelegatedMethodDoesNotExistOnDelegate(Method mockMethod, Object mock, Object delegate) static MockitoExceptiondelegatedMethodHasWrongReturnType(Method mockMethod, Method delegateMethod, Object mock, Object delegate) static MockitoExceptionextraInterfacesAcceptsOnlyInterfaces(Class<?> wrongType) static MockitoExceptionextraInterfacesCannotContainMockedType(Class<?> wrongType) static MockitoExceptionstatic MockitoExceptionstatic MockitoExceptionfieldInitialisationThrewException(Field field, Throwable details) static UnnecessaryStubbingExceptionformatUnncessaryStubbingException(Class<?> testClass, Collection<Invocation> unnecessaryStubbings) static MockitoExceptionincorrectUseOfAdditionalMatchers(String additionalMatcherName, int expectedSubMatchersCount, Collection<LocalizedMatcher> matcherStack) static MockitoExceptionstatic MockitoExceptioninlineClassWithoutUnboxImpl(Class<?> inlineClass, Exception details) static MockitoExceptionstatic MockitoExceptioninvalidArgumentPositionRangeAtInvocationTime(InvocationOnMock invocation, boolean willReturnLastParameter, int argumentIndex) static MockitoExceptionstatic MockitoExceptioninvalidUseOfMatchers(int expectedMatchersCount, List<LocalizedMatcher> recordedMatchers) static MockitoExceptioninvocationListenerThrewException(InvocationListener listener, Throwable listenerThrowable) static MockitoExceptionmethodDoesNotAcceptParameter(String method, String parameter) static MockitoExceptionmisplacedArgumentMatcher(List<LocalizedMatcher> lastMatchers) static voidstatic MockitoExceptionstatic MockitoExceptionmockedTypeIsInconsistentWithDelegatedInstanceType(Class<?> mockedType, Object delegatedInstance) static MockitoExceptionmockedTypeIsInconsistentWithSpiedInstanceType(Class<?> mockedType, Object spiedInstance) static MockitoExceptionstatic MockitoExceptionstatic MockitoExceptionmoreThanOneAnnotationNotAllowed(String fieldName) static MockitoExceptionmoreThanOneMockCandidate(Field field, Collection<?> mockCandidates) static MockitoAssertionErrorneverWantedButInvoked(DescribedInvocation wanted, List<Invocation> invocations) static MockitoExceptionstatic MockitoAssertionErrornoInteractionsWanted(Object mock, List<VerificationAwareInvocation> invocations) static MockitoAssertionErrornoMoreInteractionsWanted(Invocation undesired, List<VerificationAwareInvocation> invocations) static MockitoAssertionErrornoMoreInteractionsWantedInOrder(Invocation undesired) static MockitoExceptionnotAMockPassedToVerify(Class<?> type) static MockitoExceptionstatic MockitoExceptionstatic MockitoExceptionstatic MockitoExceptionstatic MockitoExceptionstatic MockitoExceptionstatic MockitoExceptionstatic MockitoExceptionstatic MockitoExceptionstatic voidpotentialStubbingProblem(Invocation actualInvocation, Collection<Invocation> argMismatchStubbings) static voidredundantMockitoListener(String listenerType) static MockitoExceptionreportNoSubMatchersFound(String additionalMatcherName) static MockitoExceptionrequiresAtLeastOneListener(String method) static MockitoExceptionserializableWontWorkForObjectsThatDontImplementSerializable(Class<?> classToMock) static MockitoExceptionsmartNullPointerException(String invocation, Location location) static MockitoExceptionstatic MockitoExceptionstatic MockitoExceptionstubPassedToVerify(Object mock) static MockitoAssertionErrortooFewActualInvocations(Discrepancy discrepancy, DescribedInvocation wanted, List<Location> allLocations) static MockitoAssertionErrortooFewActualInvocationsInOrder(Discrepancy discrepancy, DescribedInvocation wanted, List<Location> locations) static MockitoAssertionErrortooManyActualInvocations(int wantedCount, int actualCount, DescribedInvocation wanted, List<Location> locations) static MockitoAssertionErrortooManyActualInvocationsInOrder(int wantedCount, int actualCount, DescribedInvocation wanted, List<Location> invocations) static voidstatic MockitoExceptionunfinishedStubbing(Location location) static MockitoExceptionunfinishedVerificationException(Location location) static voidunncessaryStubbingException(List<Invocation> unused) static MockitoExceptionunsupportedCombinationOfAnnotations(String undesiredAnnotationOne, String undesiredAnnotationTwo) static MockitoExceptionwantedAtMostX(int maxNumberOfInvocations, int foundSize) static MockitoAssertionErrorstatic MockitoAssertionErrorwantedButNotInvoked(DescribedInvocation wanted, List<? extends DescribedInvocation> invocations) static MockitoAssertionErrorwantedButNotInvokedInOrder(DescribedInvocation wanted, DescribedInvocation previous) static MockitoExceptionwrongTypeOfArgumentToReturn(InvocationOnMock invocation, String expectedType, Class<?> actualType, int argumentIndex) static MockitoExceptionwrongTypeOfReturnValue(String expectedType, String actualType, String methodName) static MockitoExceptionwrongTypeReturnedByDefaultAnswer(Object mock, String expectedType, String actualType, String methodName)
-
Method Details
-
checkedExceptionInvalid
-
cannotStubWithNullThrowable
-
unfinishedStubbing
-
incorrectUseOfApi
-
missingMethodInvocation
-
unfinishedVerificationException
-
notAMockPassedToVerify
-
nullPassedToVerify
-
notAMockPassedToWhenMethod
-
nullPassedToWhenMethod
-
mocksHaveToBePassedToVerifyNoMoreInteractions
-
notAMockPassedToVerifyNoMoreInteractions
-
nullPassedToVerifyNoMoreInteractions
-
notAMockPassedWhenCreatingInOrder
-
nullPassedWhenCreatingInOrder
-
mocksHaveToBePassedWhenCreatingInOrder
-
inOrderRequiresFamiliarMock
-
invalidUseOfMatchers
public static MockitoException invalidUseOfMatchers(int expectedMatchersCount, List<LocalizedMatcher> recordedMatchers) -
incorrectUseOfAdditionalMatchers
public static MockitoException incorrectUseOfAdditionalMatchers(String additionalMatcherName, int expectedSubMatchersCount, Collection<LocalizedMatcher> matcherStack) -
stubPassedToVerify
-
reportNoSubMatchersFound
-
argumentsAreDifferent
public static AssertionError argumentsAreDifferent(Invocation actualInvocation, MatchableInvocation matchableInvocation, String wanted, List<String> actualCalls, List<Location> actualLocations) -
wantedButNotInvoked
-
wantedButNotInvoked
public static MockitoAssertionError wantedButNotInvoked(DescribedInvocation wanted, List<? extends DescribedInvocation> invocations) -
wantedButNotInvokedInOrder
public static MockitoAssertionError wantedButNotInvokedInOrder(DescribedInvocation wanted, DescribedInvocation previous) -
tooManyActualInvocations
public static MockitoAssertionError tooManyActualInvocations(int wantedCount, int actualCount, DescribedInvocation wanted, List<Location> locations) -
neverWantedButInvoked
public static MockitoAssertionError neverWantedButInvoked(DescribedInvocation wanted, List<Invocation> invocations) -
tooManyActualInvocationsInOrder
public static MockitoAssertionError tooManyActualInvocationsInOrder(int wantedCount, int actualCount, DescribedInvocation wanted, List<Location> invocations) -
tooFewActualInvocations
public static MockitoAssertionError tooFewActualInvocations(Discrepancy discrepancy, DescribedInvocation wanted, List<Location> allLocations) -
tooFewActualInvocationsInOrder
public static MockitoAssertionError tooFewActualInvocationsInOrder(Discrepancy discrepancy, DescribedInvocation wanted, List<Location> locations) -
noMoreInteractionsWanted
public static MockitoAssertionError noMoreInteractionsWanted(Invocation undesired, List<VerificationAwareInvocation> invocations) -
noMoreInteractionsWantedInOrder
-
noInteractionsWanted
public static MockitoAssertionError noInteractionsWanted(Object mock, List<VerificationAwareInvocation> invocations) -
cannotMockClass
-
cannotStubVoidMethodWithAReturnValue
-
onlyVoidMethodsCanBeSetToDoNothing
-
wrongTypeOfReturnValue
public static MockitoException wrongTypeOfReturnValue(String expectedType, String actualType, String methodName) -
wrongTypeReturnedByDefaultAnswer
public static MockitoException wrongTypeReturnedByDefaultAnswer(Object mock, String expectedType, String actualType, String methodName) -
wantedAtMostX
public static MoreThanAllowedActualInvocations wantedAtMostX(int maxNumberOfInvocations, int foundSize) -
misplacedArgumentMatcher
-
smartNullPointerException
-
noArgumentValueWasCaptured
-
extraInterfacesDoesNotAcceptNullParameters
-
extraInterfacesAcceptsOnlyInterfaces
-
extraInterfacesCannotContainMockedType
-
extraInterfacesRequiresAtLeastOneInterface
-
mockedTypeIsInconsistentWithSpiedInstanceType
public static MockitoException mockedTypeIsInconsistentWithSpiedInstanceType(Class<?> mockedType, Object spiedInstance) -
cannotCallAbstractRealMethod
-
cannotVerifyToString
-
moreThanOneAnnotationNotAllowed
-
unsupportedCombinationOfAnnotations
public static MockitoException unsupportedCombinationOfAnnotations(String undesiredAnnotationOne, String undesiredAnnotationTwo) -
cannotInitializeForSpyAnnotation
public static MockitoException cannotInitializeForSpyAnnotation(String fieldName, Exception details) -
cannotInitializeForInjectMocksAnnotation
public static MockitoException cannotInitializeForInjectMocksAnnotation(String fieldName, String causeMessage) -
atMostAndNeverShouldNotBeUsedWithTimeout
-
fieldInitialisationThrewException
-
methodDoesNotAcceptParameter
-
requiresAtLeastOneListener
-
invocationListenerThrewException
public static MockitoException invocationListenerThrewException(InvocationListener listener, Throwable listenerThrowable) -
cannotInjectDependency
public static MockitoException cannotInjectDependency(Field field, Object matchingMock, Exception details) -
moreThanOneMockCandidate
-
mockedTypeIsInconsistentWithDelegatedInstanceType
public static MockitoException mockedTypeIsInconsistentWithDelegatedInstanceType(Class<?> mockedType, Object delegatedInstance) -
spyAndDelegateAreMutuallyExclusive
-
invalidArgumentRangeAtIdentityAnswerCreationTime
-
invalidArgumentPositionRangeAtInvocationTime
public static MockitoException invalidArgumentPositionRangeAtInvocationTime(InvocationOnMock invocation, boolean willReturnLastParameter, int argumentIndex) -
wrongTypeOfArgumentToReturn
public static MockitoException wrongTypeOfArgumentToReturn(InvocationOnMock invocation, String expectedType, Class<?> actualType, int argumentIndex) -
defaultAnswerDoesNotAcceptNullParameter
-
strictnessDoesNotAcceptNullParameter
-
serializableWontWorkForObjectsThatDontImplementSerializable
public static MockitoException serializableWontWorkForObjectsThatDontImplementSerializable(Class<?> classToMock) -
delegatedMethodHasWrongReturnType
public static MockitoException delegatedMethodHasWrongReturnType(Method mockMethod, Method delegateMethod, Object mock, Object delegate) -
delegatedMethodDoesNotExistOnDelegate
public static MockitoException delegatedMethodDoesNotExistOnDelegate(Method mockMethod, Object mock, Object delegate) -
usingConstructorWithFancySerializable
-
cannotCreateTimerWithNegativeDurationTime
-
notAnException
-
inlineClassWithoutUnboxImpl
-
formatUnncessaryStubbingException
public static UnnecessaryStubbingException formatUnncessaryStubbingException(Class<?> testClass, Collection<Invocation> unnecessaryStubbings) -
unncessaryStubbingException
-
potentialStubbingProblem
public static void potentialStubbingProblem(Invocation actualInvocation, Collection<Invocation> argMismatchStubbings) -
redundantMockitoListener
-
unfinishedMockingSession
public static void unfinishedMockingSession() -
missingByteBuddyDependency
-