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).
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic AssertionError
static MockitoException
static MockitoException
static MockitoException
cannotCreateTimerWithNegativeDurationTime
(long durationMillis) static MockitoException
cannotInitializeForInjectMocksAnnotation
(String fieldName, String causeMessage) static MockitoException
cannotInitializeForSpyAnnotation
(String fieldName, Exception details) static MockitoException
cannotInjectDependency
(Field field, Object matchingMock, Exception details) static MockitoException
cannotMockClass
(Class<?> clazz, String reason) static MockitoException
cannotStubVoidMethodWithAReturnValue
(String methodName) static MockitoException
static MockitoException
static MockitoException
private static String
createAllLocationsArgsMessage
(List<Invocation> invocations) private static String
createAllLocationsMessage
(List<Location> locations) private static String
createTooFewInvocationsMessage
(Discrepancy discrepancy, DescribedInvocation wanted, List<Location> locations) private static String
createTooManyInvocationsMessage
(int wantedCount, int actualCount, DescribedInvocation wanted, List<Location> invocations) private static String
static MockitoException
static MockitoException
delegatedMethodDoesNotExistOnDelegate
(Method mockMethod, Object mock, Object delegate) static MockitoException
delegatedMethodHasWrongReturnType
(Method mockMethod, Method delegateMethod, Object mock, Object delegate) private static String
static MockitoException
extraInterfacesAcceptsOnlyInterfaces
(Class<?> wrongType) static MockitoException
extraInterfacesCannotContainMockedType
(Class<?> wrongType) static MockitoException
static MockitoException
static MockitoException
fieldInitialisationThrewException
(Field field, Throwable details) static UnnecessaryStubbingException
formatUnncessaryStubbingException
(Class<?> testClass, Collection<Invocation> unnecessaryStubbings) static MockitoException
incorrectUseOfAdditionalMatchers
(String additionalMatcherName, int expectedSubMatchersCount, Collection<LocalizedMatcher> matcherStack) static MockitoException
static MockitoException
inlineClassWithoutUnboxImpl
(Class<?> inlineClass, Exception details) static MockitoException
static MockitoException
invalidArgumentPositionRangeAtInvocationTime
(InvocationOnMock invocation, boolean willReturnLastParameter, int argumentIndex) static MockitoException
static MockitoException
invalidUseOfMatchers
(int expectedMatchersCount, List<LocalizedMatcher> recordedMatchers) static MockitoException
invocationListenerThrewException
(InvocationListener listener, Throwable listenerThrowable) private static Object
locationsOf
(Collection<LocalizedMatcher> matchers) static MockitoException
methodDoesNotAcceptParameter
(String method, String parameter) static MockitoException
misplacedArgumentMatcher
(List<LocalizedMatcher> lastMatchers) static void
static MockitoException
static MockitoException
mockedTypeIsInconsistentWithDelegatedInstanceType
(Class<?> mockedType, Object delegatedInstance) static MockitoException
mockedTypeIsInconsistentWithSpiedInstanceType
(Class<?> mockedType, Object spiedInstance) static MockitoException
static MockitoException
static MockitoException
moreThanOneAnnotationNotAllowed
(String fieldName) static MockitoAssertionError
neverWantedButInvoked
(DescribedInvocation wanted, List<Invocation> invocations) static MockitoException
static MockitoAssertionError
noInteractionsWanted
(Object mock, List<VerificationAwareInvocation> invocations) static MockitoAssertionError
noMoreInteractionsWanted
(Invocation undesired, List<VerificationAwareInvocation> invocations) static MockitoAssertionError
noMoreInteractionsWantedInOrder
(Invocation undesired) static MockitoException
notAMockPassedToVerify
(Class<?> type) static MockitoException
static MockitoException
static MockitoException
static MockitoException
static MockitoException
static MockitoException
static MockitoException
static MockitoException
static MockitoException
private static StringBuilder
possibleArgumentTypesOf
(InvocationOnMock invocation) static void
potentialStubbingProblem
(Invocation actualInvocation, Collection<Invocation> argMismatchStubbings) static void
redundantMockitoListener
(String listenerType) static MockitoException
reportNoSubMatchersFound
(String additionalMatcherName) static MockitoException
requiresAtLeastOneListener
(String method) static MockitoException
serializableWontWorkForObjectsThatDontImplementSerializable
(Class<?> classToMock) static MockitoException
smartNullPointerException
(String invocation, Location location) static MockitoException
static MockitoException
stubPassedToVerify
(Object mock) static MockitoAssertionError
tooFewActualInvocations
(Discrepancy discrepancy, DescribedInvocation wanted, List<Location> allLocations) static MockitoAssertionError
tooFewActualInvocationsInOrder
(Discrepancy discrepancy, DescribedInvocation wanted, List<Location> locations) static MockitoAssertionError
tooManyActualInvocations
(int wantedCount, int actualCount, DescribedInvocation wanted, List<Location> locations) static MockitoAssertionError
tooManyActualInvocationsInOrder
(int wantedCount, int actualCount, DescribedInvocation wanted, List<Location> invocations) static void
static MockitoException
unfinishedStubbing
(Location location) static MockitoException
unfinishedVerificationException
(Location location) static void
unncessaryStubbingException
(List<Invocation> unused) static MockitoException
unsupportedCombinationOfAnnotations
(String undesiredAnnotationOne, String undesiredAnnotationTwo) static MockitoException
wantedAtMostX
(int maxNumberOfInvocations, int foundSize) static MockitoAssertionError
static MockitoAssertionError
wantedButNotInvoked
(DescribedInvocation wanted, List<? extends DescribedInvocation> invocations) static MockitoAssertionError
wantedButNotInvokedInOrder
(DescribedInvocation wanted, DescribedInvocation previous) static MockitoException
wrongTypeOfArgumentToReturn
(InvocationOnMock invocation, String expectedType, Class<?> actualType, int argumentIndex) static MockitoException
wrongTypeOfReturnValue
(String expectedType, String actualType, String methodName) static MockitoException
wrongTypeReturnedByDefaultAnswer
(Object mock, String expectedType, String actualType, String methodName)
-
Field Details
-
NON_PUBLIC_PARENT
- See Also:
-
-
Constructor Details
-
Reporter
private Reporter()
-
-
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
-
locationsOf
-
argumentsAreDifferent
-
wantedButNotInvoked
-
wantedButNotInvoked
public static MockitoAssertionError wantedButNotInvoked(DescribedInvocation wanted, List<? extends DescribedInvocation> invocations) -
createWantedButNotInvokedMessage
-
wantedButNotInvokedInOrder
public static MockitoAssertionError wantedButNotInvokedInOrder(DescribedInvocation wanted, DescribedInvocation previous) -
tooManyActualInvocations
public static MockitoAssertionError tooManyActualInvocations(int wantedCount, int actualCount, DescribedInvocation wanted, List<Location> locations) -
createTooManyInvocationsMessage
private static String createTooManyInvocationsMessage(int wantedCount, int actualCount, DescribedInvocation wanted, List<Location> invocations) -
neverWantedButInvoked
public static MockitoAssertionError neverWantedButInvoked(DescribedInvocation wanted, List<Invocation> invocations) -
tooManyActualInvocationsInOrder
public static MockitoAssertionError tooManyActualInvocationsInOrder(int wantedCount, int actualCount, DescribedInvocation wanted, List<Location> invocations) -
createAllLocationsMessage
-
createAllLocationsArgsMessage
-
createTooFewInvocationsMessage
private static String createTooFewInvocationsMessage(Discrepancy discrepancy, DescribedInvocation wanted, List<Location> locations) -
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) -
exceptionCauseMessageIfAvailable
-
mockedTypeIsInconsistentWithDelegatedInstanceType
public static MockitoException mockedTypeIsInconsistentWithDelegatedInstanceType(Class<?> mockedType, Object delegatedInstance) -
spyAndDelegateAreMutuallyExclusive
-
invalidArgumentRangeAtIdentityAnswerCreationTime
-
invalidArgumentPositionRangeAtInvocationTime
public static MockitoException invalidArgumentPositionRangeAtInvocationTime(InvocationOnMock invocation, boolean willReturnLastParameter, int argumentIndex) -
possibleArgumentTypesOf
-
wrongTypeOfArgumentToReturn
public static MockitoException wrongTypeOfArgumentToReturn(InvocationOnMock invocation, String expectedType, Class<?> actualType, int argumentIndex) -
defaultAnswerDoesNotAcceptNullParameter
-
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
-