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);" )); }
private String createWantedButNotInvokedMessage(DescribedInvocation wanted) { return join( "Wanted but not invoked:", wanted.toString(), new LocationImpl(), "" ); }
public void invocationListenerThrewException(InvocationListener listener, Throwable listenerThrowable) { throw new MockitoException(StringJoiner.join( "The invocation listener with type " + listener.getClass().getName(), "threw an exception : " + listenerThrowable.getClass().getName() + listenerThrowable.getMessage()), listenerThrowable); }
public void notAMockPassedToWhenMethod() { throw new NotAMockException(join( "Argument passed to when() is not a mock!", "Example of correct stubbing:", " doThrow(new RuntimeException()).when(mock).someMethod();" )); }
public void nullPassedToVerifyNoMoreInteractions() { throw new NullInsteadOfMockException(join( "Argument(s) passed is null!", "Examples of correct verifications:", " verifyNoMoreInteractions(mockOne, mockTwo);", " verifyZeroInteractions(mockOne, mockTwo);" )); }
public void notAMockPassedWhenCreatingInOrder() { throw 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 void mocksHaveToBePassedWhenCreatingInOrder() { throw new MockitoException(join( "Method requires argument(s)!", "Pass mocks that require verification in order.", "For example:", " InOrder inOrder = inOrder(mockOne, mockTwo);" )); }
public void inOrderRequiresFamiliarMock() { throw new MockitoException(join( "InOrder can only verify mocks that were passed in during creation of InOrder.", "For example:", " InOrder inOrder = inOrder(mockOne);", " inOrder.verify(mockOne).doStuff();" )); }
public void extraInterfacesDoesNotAcceptNullParameters() { throw new MockitoException(join( "extraInterfaces() does not accept null parameters." )); }
public void extraInterfacesAcceptsOnlyInterfaces(Class<?> wrongType) { throw new MockitoException(join( "extraInterfaces() accepts only interfaces.", "You passed following type: " + wrongType.getSimpleName() + " which is not an interface." )); }
public void cannotInitializeForInjectMocksAnnotation(String fieldName, Exception details) { throw new MockitoException(join("Cannot instantiate @InjectMocks field named '" + fieldName + "'.", "You haven't provided the instance at field declaration so I tried to construct the instance.", "However, I failed because: " + details.getMessage(), "Examples of correct usage of @InjectMocks:", " @InjectMocks Service service = new Service();", " @InjectMocks Service service;", " //also, don't forget about MockitoAnnotations.initMocks();", " //and... don't forget about some @Mocks for injection :)", ""), details); }
public void invalidArgumentRangeAtIdentityAnswerCreationTime() { throw new MockitoException(join("Invalid argument index.", "The index need to be a positive number that indicates the position of the argument to return.", "However it is possible to use the -1 value to indicates that the last argument should be", "returned.")); }
public void cannotMockFinalClass(Class<?> clazz) { throw new MockitoException(join( "Cannot mock/spy " + clazz.toString(), "Mockito cannot mock/spy following:", " - final classes", " - anonymous classes", " - primitive types" )); }
public void tooManyActualInvocationsInOrder(int wantedCount, int actualCount, DescribedInvocation wanted, Location firstUndesired) { String message = createTooManyInvocationsMessage(wantedCount, actualCount, wanted, firstUndesired); throw new VerificationInOrderFailure(join( "Verification in order failure:" + message )); }
public void neverWantedButInvoked(DescribedInvocation wanted, Location firstUndesired) { throw new NeverWantedButInvoked(join( wanted.toString(), "Never wanted here:", new LocationImpl(), "But invoked here:", firstUndesired, "" )); }
public void foundUnstubbed(InvocationMatcher unstubbed) { if (warnAboutUnstubbed) { logger.log(join( "This method was not stubbed ", unstubbed, unstubbed.getInvocation().getLocation(), "")); } }
public void incorrectUseOfApi() { throw new MockitoException(join( "Incorrect use of API detected here:", new LocationImpl(), "", "You probably stored a reference to OngoingStubbing returned by when() and called stubbing methods like thenReturn() on this reference more than once.", "Examples of correct usage:", " when(mock.isOk()).thenReturn(true).thenReturn(false).thenThrow(exception);", " when(mock.isOk()).thenReturn(true, false).thenThrow(exception);", "" )); }
public void reportNoSubMatchersFound(String additionalMatcherName) { throw new InvalidUseOfMatchersException(join( "No matchers found for additional matcher " + additionalMatcherName, new LocationImpl(), "" )); }
public int invalidArgumentPositionRangeAtInvocationTime(InvocationOnMock invocation, boolean willReturnLastParameter, int argumentIndex) { throw new MockitoException( join("Invalid argument index for the current invocation of method : ", " -> " + new MockUtil().getMockName(invocation.getMock()) + "." + invocation.getMethod().getName() + "()", "", (willReturnLastParameter ? "Last parameter wanted" : "Wanted parameter at position " + argumentIndex) + " but " + possibleArgumentTypesOf(invocation), "The index need to be a positive number that indicates a valid position of the argument in the invocation.", "However it is possible to use the -1 value to indicates that the last argument should be returned.", "")); }
public void noMoreInteractionsWanted(Invocation undesired, List<VerificationAwareInvocation> invocations) { ScenarioPrinter scenarioPrinter = new ScenarioPrinter(); String scenario = scenarioPrinter.print(invocations); throw new NoInteractionsWanted(join( "No interactions wanted here:", new LocationImpl(), "But found this interaction:", undesired.getLocation(), scenario )); }