public static MockitoException nullPassedToVerify() { return new NullInsteadOfMockException(join( "Argument passed to verify() should be a mock but is null!", "Examples of correct verifications:", " verify(mock).someMethod();", " verify(mock, times(10)).someMethod();", " verify(mock, atLeastOnce()).someMethod();", " not: verify(mock.someMethod());", "Also, if you use @Mock annotation don't miss initMocks()" )); }
public static MockitoException cannotCreateTimerWithNegativeDurationTime(long durationMillis) { return new FriendlyReminderException(join( "", "Don't panic! I'm just a friendly reminder!", "It is impossible for time to go backward, therefore...", "You cannot put negative value of duration: (" + durationMillis + ")", "as argument of timer methods (after(), timeout())", "" )); }
public static MockitoException notAMockPassedToWhenMethod() { return new NotAMockException(join( "Argument passed to when() is not a mock!", "Example of correct stubbing:", " doThrow(new RuntimeException()).when(mock).someMethod();" )); }
public static MockitoException missingMethodInvocation() { return new MissingMethodInvocationException(join( "when() requires an argument which has to be 'a method call on a mock'.", "For example:", " when(mock.getArticles()).thenReturn(articles);", "", "Also, this error might show up because:", "1. you stub either of: final/private/equals()/hashCode() methods.", " Those methods *cannot* be stubbed/verified.", " " + NON_PUBLIC_PARENT, "2. inside when() you don't call method on mock but on some other object.", "" )); }
public static MockitoException unfinishedVerificationException(Location location) { return new UnfinishedVerificationException(join( "Missing method call for verify(mock) here:", location, "", "Example of correct verification:", " verify(mock).doSomething()", "", "Also, this error might show up because you verify either of: final/private/equals()/hashCode() methods.", "Those methods *cannot* be stubbed/verified.", NON_PUBLIC_PARENT, "" )); }
public static MockitoException wrongTypeOfReturnValue(String expectedType, String actualType, String methodName) { return new WrongTypeOfReturnValue(join( actualType + " cannot be returned by " + methodName + "()", methodName + "() should return " + expectedType, "***", "If you're unsure why you're getting above error read on.", "Due to the nature of the syntax above problem might occur because:", "1. This exception *might* occur in wrongly written multi-threaded tests.", " Please refer to Mockito FAQ on limitations of concurrency testing.", "2. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies - ", " - with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.", "" )); }
public static MockitoException reportNoSubMatchersFound(String additionalMatcherName) { return new InvalidUseOfMatchersException(join( "No matchers found for additional matcher " + additionalMatcherName, new LocationImpl(), "" )); }
public static void redundantMockitoListener(String listenerType) { throw new RedundantListenerException(join( "Problems adding Mockito listener.", "Listener of type '" + listenerType + "' has already been added and not removed.", "It indicates that previous listener was not removed according to the API.", "When you add a listener, don't forget to remove the listener afterwards:", " Mockito.framework().removeListener(myListener);", "For more information, see the javadoc for RedundantListenerException class.")); }
public static void unfinishedMockingSession() { throw new UnfinishedMockingSessionException(join( "Unfinished mocking session detected.", "Previous MockitoSession was not concluded with 'finishMocking()'.", "For examples of correct usage see javadoc for MockitoSession class.")); } }
public static MockitoException nullPassedWhenCreatingInOrder() { return new NullInsteadOfMockException(join( "Argument(s) passed is null!", "Pass mocks that require verification in order.", "For example:", " InOrder inOrder = inOrder(mockOne, mockTwo);" )); }
public static MockitoException notAMockPassedToVerifyNoMoreInteractions() { return new NotAMockException(join( "Argument(s) passed is not a mock!", "Examples of correct verifications:", " verifyNoMoreInteractions(mockOne, mockTwo);", " verifyZeroInteractions(mockOne, mockTwo);", "" )); }
public static MockitoException atMostAndNeverShouldNotBeUsedWithTimeout() { return new FriendlyReminderException(join("", "Don't panic! I'm just a friendly reminder!", "timeout() should not be used with atMost() or never() because...", "...it does not make much sense - the test would have passed immediately in concurrency", "We kept this method only to avoid compilation errors when upgrading Mockito.", "In future release we will remove timeout(x).atMost(y) from the API.", "If you want to find out more please refer to issue 235", "")); }
public static MockitoException nullPassedToVerifyNoMoreInteractions() { return new NullInsteadOfMockException(join( "Argument(s) passed is null!", "Examples of correct verifications:", " verifyNoMoreInteractions(mockOne, mockTwo);", " verifyZeroInteractions(mockOne, mockTwo);" )); }
public static MockitoException notAMockPassedWhenCreatingInOrder() { return new NotAMockException(join( "Argument(s) passed is not a mock!", "Pass mocks that require verification in order.", "For example:", " InOrder inOrder = inOrder(mockOne, mockTwo);" )); }
public static MockitoException nullPassedToWhenMethod() { return new NullInsteadOfMockException(join( "Argument passed to when() is null!", "Example of correct stubbing:", " doThrow(new RuntimeException()).when(mock).someMethod();", "Also, if you use @Mock annotation don't miss initMocks()" )); }
public void notAMockPassedToVerifyNoMoreInteractions() { throw new NotAMockException(join( "Argument(s) passed is not a mock!", "Examples of correct verifications:", " verifyNoMoreInteractions(mockOne, mockTwo);", " verifyZeroInteractions(mockOne, mockTwo);", "" )); }
public void nullPassedWhenCreatingInOrder() { throw new NullInsteadOfMockException(join( "Argument(s) passed is null!", "Pass mocks that require verification in order.", "For example:", " InOrder inOrder = inOrder(mockOne, mockTwo);" )); }
public static MockitoException notAMockPassedToVerify(Class<?> type) { return new NotAMockException(join( "Argument passed to verify() is of type " + type.getSimpleName() + " and is not a mock!", "Make sure you place the parenthesis correctly!", "See the examples of correct verifications:", " verify(mock).someMethod();", " verify(mock, times(10)).someMethod();", " verify(mock, atLeastOnce()).someMethod();" )); }
public void nullPassedToWhenMethod() { throw new NullInsteadOfMockException(join( "Argument passed to when() is null!", "Example of correct stubbing:", " doThrow(new RuntimeException()).when(mock).someMethod();", "Also, if you use @Mock annotation don't miss initMocks()" )); }
public void nullPassedToVerify() { throw new NullInsteadOfMockException(join( "Argument passed to verify() should be a mock but is null!", "Examples of correct verifications:", " verify(mock).someMethod();", " verify(mock, times(10)).someMethod();", " verify(mock, atLeastOnce()).someMethod();", "Also, if you use @Mock annotation don't miss initMocks()" )); }