Class Reporter


  • public class Reporter
    extends java.lang.Object
    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 Detail

      • NON_PUBLIC_PARENT

        private static final java.lang.String NON_PUBLIC_PARENT
        See Also:
        Constant Field Values
    • Constructor Detail

      • Reporter

        private Reporter()
    • Method Detail

      • checkedExceptionInvalid

        public static MockitoException checkedExceptionInvalid​(java.lang.Throwable t)
      • cannotStubWithNullThrowable

        public static MockitoException cannotStubWithNullThrowable()
      • missingMethodInvocation

        public static MockitoException missingMethodInvocation()
      • unfinishedVerificationException

        public static MockitoException unfinishedVerificationException​(Location location)
      • notAMockPassedToVerify

        public static MockitoException notAMockPassedToVerify​(java.lang.Class<?> type)
      • notAMockPassedToWhenMethod

        public static MockitoException notAMockPassedToWhenMethod()
      • nullPassedToWhenMethod

        public static MockitoException nullPassedToWhenMethod()
      • mocksHaveToBePassedToVerifyNoMoreInteractions

        public static MockitoException mocksHaveToBePassedToVerifyNoMoreInteractions()
      • notAMockPassedToVerifyNoMoreInteractions

        public static MockitoException notAMockPassedToVerifyNoMoreInteractions()
      • nullPassedToVerifyNoMoreInteractions

        public static MockitoException nullPassedToVerifyNoMoreInteractions()
      • notAMockPassedWhenCreatingInOrder

        public static MockitoException notAMockPassedWhenCreatingInOrder()
      • nullPassedWhenCreatingInOrder

        public static MockitoException nullPassedWhenCreatingInOrder()
      • mocksHaveToBePassedWhenCreatingInOrder

        public static MockitoException mocksHaveToBePassedWhenCreatingInOrder()
      • inOrderRequiresFamiliarMock

        public static MockitoException inOrderRequiresFamiliarMock()
      • incorrectUseOfAdditionalMatchers

        public static MockitoException incorrectUseOfAdditionalMatchers​(java.lang.String additionalMatcherName,
                                                                        int expectedSubMatchersCount,
                                                                        java.util.Collection<LocalizedMatcher> matcherStack)
      • stubPassedToVerify

        public static MockitoException stubPassedToVerify​(java.lang.Object mock)
      • reportNoSubMatchersFound

        public static MockitoException reportNoSubMatchersFound​(java.lang.String additionalMatcherName)
      • locationsOf

        private static java.lang.Object locationsOf​(java.util.Collection<LocalizedMatcher> matchers)
      • argumentsAreDifferent

        public static java.lang.AssertionError argumentsAreDifferent​(java.lang.String wanted,
                                                                     java.util.List<java.lang.String> actualCalls,
                                                                     java.util.List<Location> actualLocations)
      • createWantedButNotInvokedMessage

        private static java.lang.String createWantedButNotInvokedMessage​(DescribedInvocation wanted)
      • createTooManyInvocationsMessage

        private static java.lang.String createTooManyInvocationsMessage​(int wantedCount,
                                                                        int actualCount,
                                                                        DescribedInvocation wanted,
                                                                        java.util.List<Location> invocations)
      • createAllLocationsMessage

        private static java.lang.String createAllLocationsMessage​(java.util.List<Location> locations)
      • createAllLocationsArgsMessage

        private static java.lang.String createAllLocationsArgsMessage​(java.util.List<Invocation> invocations)
      • createTooFewInvocationsMessage

        private static java.lang.String createTooFewInvocationsMessage​(Discrepancy discrepancy,
                                                                       DescribedInvocation wanted,
                                                                       java.util.List<Location> locations)
      • cannotMockClass

        public static MockitoException cannotMockClass​(java.lang.Class<?> clazz,
                                                       java.lang.String reason)
      • cannotStubVoidMethodWithAReturnValue

        public static MockitoException cannotStubVoidMethodWithAReturnValue​(java.lang.String methodName)
      • onlyVoidMethodsCanBeSetToDoNothing

        public static MockitoException onlyVoidMethodsCanBeSetToDoNothing()
      • wrongTypeOfReturnValue

        public static MockitoException wrongTypeOfReturnValue​(java.lang.String expectedType,
                                                              java.lang.String actualType,
                                                              java.lang.String methodName)
      • wrongTypeReturnedByDefaultAnswer

        public static MockitoException wrongTypeReturnedByDefaultAnswer​(java.lang.Object mock,
                                                                        java.lang.String expectedType,
                                                                        java.lang.String actualType,
                                                                        java.lang.String methodName)
      • smartNullPointerException

        public static MockitoException smartNullPointerException​(java.lang.String invocation,
                                                                 Location location)
      • noArgumentValueWasCaptured

        public static MockitoException noArgumentValueWasCaptured()
      • extraInterfacesDoesNotAcceptNullParameters

        public static MockitoException extraInterfacesDoesNotAcceptNullParameters()
      • extraInterfacesAcceptsOnlyInterfaces

        public static MockitoException extraInterfacesAcceptsOnlyInterfaces​(java.lang.Class<?> wrongType)
      • extraInterfacesCannotContainMockedType

        public static MockitoException extraInterfacesCannotContainMockedType​(java.lang.Class<?> wrongType)
      • extraInterfacesRequiresAtLeastOneInterface

        public static MockitoException extraInterfacesRequiresAtLeastOneInterface()
      • mockedTypeIsInconsistentWithSpiedInstanceType

        public static MockitoException mockedTypeIsInconsistentWithSpiedInstanceType​(java.lang.Class<?> mockedType,
                                                                                     java.lang.Object spiedInstance)
      • cannotCallAbstractRealMethod

        public static MockitoException cannotCallAbstractRealMethod()
      • moreThanOneAnnotationNotAllowed

        public static MockitoException moreThanOneAnnotationNotAllowed​(java.lang.String fieldName)
      • unsupportedCombinationOfAnnotations

        public static MockitoException unsupportedCombinationOfAnnotations​(java.lang.String undesiredAnnotationOne,
                                                                           java.lang.String undesiredAnnotationTwo)
      • cannotInitializeForSpyAnnotation

        public static MockitoException cannotInitializeForSpyAnnotation​(java.lang.String fieldName,
                                                                        java.lang.Exception details)
      • cannotInitializeForInjectMocksAnnotation

        public static MockitoException cannotInitializeForInjectMocksAnnotation​(java.lang.String fieldName,
                                                                                java.lang.String causeMessage)
      • atMostAndNeverShouldNotBeUsedWithTimeout

        public static MockitoException atMostAndNeverShouldNotBeUsedWithTimeout()
      • fieldInitialisationThrewException

        public static MockitoException fieldInitialisationThrewException​(java.lang.reflect.Field field,
                                                                         java.lang.Throwable details)
      • methodDoesNotAcceptParameter

        public static MockitoException methodDoesNotAcceptParameter​(java.lang.String method,
                                                                    java.lang.String parameter)
      • requiresAtLeastOneListener

        public static MockitoException requiresAtLeastOneListener​(java.lang.String method)
      • invocationListenerThrewException

        public static MockitoException invocationListenerThrewException​(InvocationListener listener,
                                                                        java.lang.Throwable listenerThrowable)
      • cannotInjectDependency

        public static MockitoException cannotInjectDependency​(java.lang.reflect.Field field,
                                                              java.lang.Object matchingMock,
                                                              java.lang.Exception details)
      • exceptionCauseMessageIfAvailable

        private static java.lang.String exceptionCauseMessageIfAvailable​(java.lang.Exception details)
      • mockedTypeIsInconsistentWithDelegatedInstanceType

        public static MockitoException mockedTypeIsInconsistentWithDelegatedInstanceType​(java.lang.Class<?> mockedType,
                                                                                         java.lang.Object delegatedInstance)
      • spyAndDelegateAreMutuallyExclusive

        public static MockitoException spyAndDelegateAreMutuallyExclusive()
      • invalidArgumentRangeAtIdentityAnswerCreationTime

        public static MockitoException invalidArgumentRangeAtIdentityAnswerCreationTime()
      • invalidArgumentPositionRangeAtInvocationTime

        public static MockitoException invalidArgumentPositionRangeAtInvocationTime​(InvocationOnMock invocation,
                                                                                    boolean willReturnLastParameter,
                                                                                    int argumentIndex)
      • possibleArgumentTypesOf

        private static java.lang.StringBuilder possibleArgumentTypesOf​(InvocationOnMock invocation)
      • wrongTypeOfArgumentToReturn

        public static MockitoException wrongTypeOfArgumentToReturn​(InvocationOnMock invocation,
                                                                   java.lang.String expectedType,
                                                                   java.lang.Class<?> actualType,
                                                                   int argumentIndex)
      • defaultAnswerDoesNotAcceptNullParameter

        public static MockitoException defaultAnswerDoesNotAcceptNullParameter()
      • serializableWontWorkForObjectsThatDontImplementSerializable

        public static MockitoException serializableWontWorkForObjectsThatDontImplementSerializable​(java.lang.Class<?> classToMock)
      • delegatedMethodHasWrongReturnType

        public static MockitoException delegatedMethodHasWrongReturnType​(java.lang.reflect.Method mockMethod,
                                                                         java.lang.reflect.Method delegateMethod,
                                                                         java.lang.Object mock,
                                                                         java.lang.Object delegate)
      • delegatedMethodDoesNotExistOnDelegate

        public static MockitoException delegatedMethodDoesNotExistOnDelegate​(java.lang.reflect.Method mockMethod,
                                                                             java.lang.Object mock,
                                                                             java.lang.Object delegate)
      • cannotCreateTimerWithNegativeDurationTime

        public static MockitoException cannotCreateTimerWithNegativeDurationTime​(long durationMillis)
      • inlineClassWithoutUnboxImpl

        public static MockitoException inlineClassWithoutUnboxImpl​(java.lang.Class<?> inlineClass,
                                                                   java.lang.Exception details)
      • formatUnncessaryStubbingException

        public static UnnecessaryStubbingException formatUnncessaryStubbingException​(java.lang.Class<?> testClass,
                                                                                     java.util.Collection<Invocation> unnecessaryStubbings)
      • unncessaryStubbingException

        public static void unncessaryStubbingException​(java.util.List<Invocation> unused)
      • potentialStubbingProblem

        public static void potentialStubbingProblem​(Invocation actualInvocation,
                                                    java.util.Collection<Invocation> argMismatchStubbings)
      • redundantMockitoListener

        public static void redundantMockitoListener​(java.lang.String listenerType)
      • unfinishedMockingSession

        public static void unfinishedMockingSession()
      • missingByteBuddyDependency

        public static void missingByteBuddyDependency​(java.lang.Throwable t)