org.mockito.internal.debugging.LocationImpl Java Examples

The following examples show how to use org.mockito.internal.debugging.LocationImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Reporter.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void incorrectUseOfAdditionalMatchers(String additionalMatcherName, int expectedSubMatchersCount, Collection<LocalizedMatcher> matcherStack) {
    throw new InvalidUseOfMatchersException(join(
            "Invalid use of argument matchers inside additional matcher " + additionalMatcherName + " !",
            new LocationImpl(),
            "",
            expectedSubMatchersCount + " sub matchers expected, " + matcherStack.size() + " recorded:",
            locationsOf(matcherStack),
            "",
            "This exception may occur if matchers are combined with raw values:",
            "    //incorrect:",
            "    someMethod(AdditionalMatchers.and(isNotNull(), \"raw String\");",
            "When using matchers, all arguments have to be provided by matchers.",
            "For example:",
            "    //correct:",
            "    someMethod(AdditionalMatchers.and(isNotNull(), eq(\"raw String\"));",
            "",
            "For more info see javadoc for Matchers and AdditionalMatchers classes.",
            ""
    ));
}
 
Example #2
Source File: LocationImplTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void shouldBeSafeInCaseForSomeReasonFilteredStackTraceIsEmpty() {
    //given
    StackTraceFilter filterReturningEmptyArray = new StackTraceFilter() {
        @Override
        public StackTraceElement[] filter(StackTraceElement[] target, boolean keepTop) {
            return new StackTraceElement[0];
        }
    };

    //when
    String loc = new LocationImpl(filterReturningEmptyArray).toString();

    //then
    assertEquals("-> at <<unknown line>>", loc);
}
 
Example #3
Source File: Reporter.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void argumentsAreDifferent(String wanted, String actual, Location actualLocation) {
    String message = join("Argument(s) are different! Wanted:",
            wanted,
            new LocationImpl(),
            "Actual invocation has different arguments:",
            actual,
            actualLocation,
            ""
    );

    if (JUnitTool.hasJUnit()) {
        throw JUnitTool.createArgumentsAreDifferentException(message, wanted, actual);
    } else {
        throw new ArgumentsAreDifferent(message);
    }
}
 
Example #4
Source File: Reporter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
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
    ));
}
 
Example #5
Source File: ReturnsSmartNulls.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public Object answer(final InvocationOnMock invocation) throws Throwable {
    Object defaultReturnValue = delegate.answer(invocation);
    if (defaultReturnValue != null) {
        return defaultReturnValue;
    }
    Class<?> type = invocation.getMethod().getReturnType();
    if (!type.isPrimitive() && !Modifier.isFinal(type.getModifiers())) {
        final Location location = new LocationImpl();
        return Mockito.mock(type, new ThrowsSmartNullPointer(invocation, location));
    }
    return null;
}
 
Example #6
Source File: InvocationImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public InvocationImpl(Object mock, MockitoMethod mockitoMethod, Object[] args, int sequenceNumber, RealMethod realMethod) {
    this.method = mockitoMethod;
    this.mock = mock;
    this.realMethod = realMethod;
    this.arguments = ArgumentsProcessor.expandVarArgs(mockitoMethod.isVarArgs(), args);
    this.rawArguments = args;
    this.sequenceNumber = sequenceNumber;
    this.location = new LocationImpl();
}
 
Example #7
Source File: Reporter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void smartNullPointerException(String invocation, Location location) {
    throw new SmartNullPointerException(join(
            "You have a NullPointerException here:",
            new LocationImpl(),
            "because this method call was *not* stubbed correctly:",
            location,
            invocation,
            ""
    ));
}
 
Example #8
Source File: Reporter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void noMoreInteractionsWantedInOrder(Invocation undesired) {
    throw new VerificationInOrderFailure(join(
            "No interactions wanted here:",
            new LocationImpl(),
            "But found this interaction:",
            undesired.getLocation(),
            ""
    ));
}
 
Example #9
Source File: Reporter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
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);",
            ""
    ));
}
 
Example #10
Source File: Reporter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private String createTooLittleInvocationsMessage(org.mockito.internal.reporting.Discrepancy discrepancy, DescribedInvocation wanted,
                                                 Location lastActualInvocation) {
    String ending =
            (lastActualInvocation != null)? lastActualInvocation + "\n" : "\n";

    String message = join(
            wanted.toString(),
            "Wanted " + discrepancy.getPluralizedWantedCount() + ":",
            new LocationImpl(),
            "But was " + discrepancy.getPluralizedActualCount() + ":",
            ending
    );
    return message;
}
 
Example #11
Source File: Reporter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void neverWantedButInvoked(DescribedInvocation wanted, Location firstUndesired) {
    throw new NeverWantedButInvoked(join(
            wanted.toString(),
            "Never wanted here:",
            new LocationImpl(),
            "But invoked here:",
            firstUndesired,
            ""
    ));
}
 
Example #12
Source File: Reporter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private String createTooManyInvocationsMessage(int wantedCount, int actualCount, DescribedInvocation wanted,
                                               Location firstUndesired) {
    return join(
            wanted.toString(),
            "Wanted " + pluralize(wantedCount) + ":",
            new LocationImpl(),
            "But was " + pluralize(actualCount) + ". Undesired invocation:",
            firstUndesired,
            ""
    );
}
 
Example #13
Source File: Reporter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void wantedButNotInvokedInOrder(DescribedInvocation wanted, DescribedInvocation previous) {
    throw new VerificationInOrderFailure(join(
            "Verification in order failure",
            "Wanted but not invoked:",
            wanted.toString(),
            new LocationImpl(),
            "Wanted anywhere AFTER following interaction:",
            previous.toString(),
            previous.getLocation(),
            ""
    ));
}
 
Example #14
Source File: Reporter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private String createWantedButNotInvokedMessage(DescribedInvocation wanted) {
    return join(
            "Wanted but not invoked:",
            wanted.toString(),
            new LocationImpl(),
            ""
    );
}
 
Example #15
Source File: Reporter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void reportNoSubMatchersFound(String additionalMatcherName) {
    throw new InvalidUseOfMatchersException(join(
            "No matchers found for additional matcher " + additionalMatcherName,
            new LocationImpl(),
            ""
    ));
}
 
Example #16
Source File: LocalizedMatcher.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public LocalizedMatcher(Matcher actualMatcher) {
    this.actualMatcher = actualMatcher;
    this.location = new LocationImpl();
}
 
Example #17
Source File: MockingProgressImpl.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void stubbingStarted() {
    validateState();
    stubbingInProgress = new LocationImpl();
}
 
Example #18
Source File: LocationImplTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void shouldLocationNotContainGetStackTraceMethod() {
    assertContains("shouldLocationNotContainGetStackTraceMethod", new LocationImpl().toString());
}
 
Example #19
Source File: LocalizedMatcher.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public LocalizedMatcher(Matcher actualMatcher) {
    this.actualMatcher = actualMatcher;
    this.location = new LocationImpl();
}