Java 类org.mockito.invocation.Location 实例源码

项目:astor    文件:Reporter.java   
public void unfinishedStubbing(Location location) {
    throw new UnfinishedStubbingException(join(
            "Unfinished stubbing detected here:",
            location,
            "",
            "E.g. thenReturn() may be missing.",
            "Examples of correct stubbing:",
            "    when(mock.isOk()).thenReturn(true);",
            "    when(mock.isOk()).thenThrow(exception);",
            "    doThrow(exception).when(mock).someVoidMethod();",
            "Hints:",
            " 1. missing thenReturn()",
            " 2. you are trying to stub a final method, you naughty developer!",
            " 3: you are stubbing the behaviour of another mock inside before 'thenReturn' instruction if completed",
            ""
    ));
}
项目:astor    文件:Reporter.java   
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);
    }
}
项目:astor    文件:Reporter.java   
public void unfinishedVerificationException(Location location) {
    UnfinishedVerificationException exception = 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.",
            ""
    ));

    throw exception;
}
项目:astor    文件:Reporter.java   
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,
            ""
    );
}
项目:astor    文件:Reporter.java   
public void neverWantedButInvoked(DescribedInvocation wanted, Location firstUndesired) {
    throw new NeverWantedButInvoked(join(
            wanted.toString(),
            "Never wanted here:",
            new LocationImpl(),
            "But invoked here:",
            firstUndesired,
            ""
    ));
}
项目:astor    文件:Reporter.java   
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;
}
项目:astor    文件:Reporter.java   
public void tooLittleActualInvocationsInOrder(org.mockito.internal.reporting.Discrepancy discrepancy, DescribedInvocation wanted, Location lastActualLocation) {
    String message = createTooLittleInvocationsMessage(discrepancy, wanted, lastActualLocation);

    throw new VerificationInOrderFailure(join(
            "Verification in order failure:" + message
    ));
}
项目:astor    文件:Reporter.java   
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,
            ""
    ));
}
项目:astor    文件:InvocationsFinder.java   
public Location getLastLocation(List<Invocation> invocations) {
    if (invocations.isEmpty()) {
        return null;
    } else {
        Invocation last = invocations.get(invocations.size() - 1);
        return last.getLocation();
    }
}
项目:astor    文件:ReturnsSmartNulls.java   
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;
}
项目:astor    文件:MockingProgressImpl.java   
public void validateState() {
    validateMostStuff();

    //validate stubbing:
    if (stubbingInProgress != null) {
        Location temp = stubbingInProgress;
        stubbingInProgress = null;
        reporter.unfinishedStubbing(temp);
    }
}
项目:astor    文件:MockingProgressImpl.java   
private void validateMostStuff() {
    //State is cool when GlobalConfiguration is already loaded
    //this cannot really be tested functionally because I cannot dynamically mess up org.mockito.configuration.MockitoConfiguration class
    GlobalConfiguration.validate();

    if (verificationMode != null) {
        Location location = verificationMode.getLocation();
        verificationMode = null;
        reporter.unfinishedVerificationException(location);
    }

    getArgumentMatcherStorage().validateState();
}
项目:astor    文件:NumberOfInvocationsInOrderChecker.java   
public void check(List<Invocation> invocations, InvocationMatcher wanted, int wantedCount, InOrderContext context) {
    List<Invocation> chunk = finder.findMatchingChunk(invocations, wanted, wantedCount, context);

    int actualCount = chunk.size();

    if (wantedCount > actualCount) {
        Location lastInvocation = finder.getLastLocation(chunk);
        reporter.tooLittleActualInvocationsInOrder(new Discrepancy(wantedCount, actualCount), wanted, lastInvocation);
    } else if (wantedCount < actualCount) {
        Location firstUndesired = chunk.get(wantedCount).getLocation();
        reporter.tooManyActualInvocationsInOrder(wantedCount, actualCount, wanted, firstUndesired);
    }

    invocationMarker.markVerifiedInOrder(chunk, wanted, context);
}
项目:astor    文件:AtLeastXNumberOfInvocationsInOrderChecker.java   
public void check(List<Invocation> invocations, InvocationMatcher wanted, int wantedCount) {
    List<Invocation> chunk = finder.findAllMatchingUnverifiedChunks(invocations, wanted, orderingContext);

    int actualCount = chunk.size();

    if (wantedCount > actualCount) {
        Location lastLocation = finder.getLastLocation(chunk);
        reporter.tooLittleActualInvocationsInOrder(new AtLeastDiscrepancy(wantedCount, actualCount), wanted, lastLocation);
    }

    invocationMarker.markVerifiedInOrder(chunk, wanted, orderingContext);
}
项目:astor    文件:NonGreedyNumberOfInvocationsInOrderChecker.java   
public void check(List<Invocation> invocations, InvocationMatcher wanted, int wantedCount, InOrderContext context) {
    int actualCount = 0;
    Location lastLocation = null;
    while( actualCount < wantedCount ){
        Invocation next = finder.findFirstMatchingUnverifiedInvocation( invocations, wanted, context );
        if( next == null ){
            reporter.tooLittleActualInvocationsInOrder(new Discrepancy(wantedCount, actualCount), wanted, lastLocation );
        }
        marker.markVerified( next, wanted );
        context.markVerified( next );
        lastLocation = next.getLocation();
        actualCount++;
    }
}
项目:astor    文件:AtLeastXNumberOfInvocationsChecker.java   
public void check(List<Invocation> invocations, InvocationMatcher wanted, int wantedCount) {
    List<Invocation> actualInvocations = finder.findInvocations(invocations, wanted);

    int actualCount = actualInvocations.size();
    if (wantedCount > actualCount) {
        Location lastLocation = finder.getLastLocation(actualInvocations);
        reporter.tooLittleActualInvocations(new AtLeastDiscrepancy(wantedCount, actualCount), wanted, lastLocation);        
    }

    invocationMarker.markVerified(actualInvocations, wanted);
}
项目:astor    文件:InvocationsFinderTest.java   
@Test
public void shouldGetLastStackTrace() throws Exception {
    Location last = finder.getLastLocation(invocations);
    assertSame(differentMethodInvocation.getLocation(), last);

    assertNull(finder.getLastLocation(Collections.<Invocation>emptyList()));
}
项目:dexmaker    文件:InvocationHandlerAdapter.java   
private ProxyInvocation(Object proxy, Method method, Object[] rawArgs, DelegatingMethod
        mockitoMethod, int sequenceNumber, Location location) {
    this.rawArgs = rawArgs;
    this.proxy = proxy;
    this.method = method;
    this.sequenceNumber = sequenceNumber;
    this.location = location;
    args = ArgumentsProcessor.expandArgs(mockitoMethod, rawArgs);
}
项目:dexmaker    文件:InvocationHandlerAdapter.java   
private ProxyInvocation(Object proxy, Method method, Object[] rawArgs, DelegatingMethod
                        mockitoMethod, int sequenceNumber, Location location) {
    this.rawArgs = rawArgs;
    this.proxy = proxy;
    this.method = method;
    this.sequenceNumber = sequenceNumber;
    this.location = location;
    args = ArgumentsProcessor.expandArgs(mockitoMethod, rawArgs);
}
项目:astor    文件:Reporter.java   
public void tooManyActualInvocations(int wantedCount, int actualCount, DescribedInvocation wanted, Location firstUndesired) {
    String message = createTooManyInvocationsMessage(wantedCount, actualCount, wanted, firstUndesired);
    throw new TooManyActualInvocations(message);
}
项目:astor    文件:Reporter.java   
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
    ));
}
项目:astor    文件:Reporter.java   
public void tooLittleActualInvocations(org.mockito.internal.reporting.Discrepancy discrepancy, DescribedInvocation wanted, Location lastActualLocation) {
    String message = createTooLittleInvocationsMessage(discrepancy, wanted, lastActualLocation);

    throw new TooLittleActualInvocations(message);
}
项目:astor    文件:LocalizedMatcher.java   
public Location getLocation() {
    return location;
}
项目:astor    文件:InvocationMatcher.java   
public Location getLocation() {
    return invocation.getLocation();
}
项目:astor    文件:StubInfoImpl.java   
public Location stubbedAt() {
    return stubbedAt.getLocation();
}
项目:astor    文件:ReturnsSmartNulls.java   
public ThrowsSmartNullPointer(InvocationOnMock unstubbedInvocation, Location location) {
    this.unstubbedInvocation = unstubbedInvocation;
    this.location = location;
}
项目:astor    文件:Localized.java   
public Location getLocation() {
    return location;
}
项目:astor    文件:MissingInvocationCheckerTest.java   
@Override public void argumentsAreDifferent(String wanted, String actual, Location actualLocation) {
            this.wanted = wanted;
            this.actual = actual;
            this.actualLocation = actualLocation;
}
项目:astor    文件:MissingInvocationInOrderCheckerTest.java   
@Override public void argumentsAreDifferent(String wanted, String actual, Location actualLocation) {
    this.wantedString = wanted;
    this.actual = actual;
    this.actualLocation = actualLocation;
}
项目:astor    文件:NumberOfInvocationsCheckerTest.java   
@Override public void tooLittleActualInvocations(org.mockito.internal.reporting.Discrepancy discrepancy, DescribedInvocation wanted, Location lastActualLocation) {
            this.wantedCount = discrepancy.getWantedCount();
            this.actualCount = discrepancy.getActualCount();
            this.wanted = wanted;
            this.location = lastActualLocation;
}
项目:astor    文件:NumberOfInvocationsCheckerTest.java   
@Override public void tooManyActualInvocations(int wantedCount, int actualCount, DescribedInvocation wanted, Location firstUndesired) {
            this.wantedCount = wantedCount;
            this.actualCount = actualCount;
            this.wanted = wanted;
            this.location = firstUndesired;
}
项目:astor    文件:NumberOfInvocationsCheckerTest.java   
@Override
public void neverWantedButInvoked(DescribedInvocation wanted, Location firstUndesired) {
    this.wanted = wanted;
    this.location = firstUndesired;
}
项目:dexmaker    文件:InvocationHandlerAdapter.java   
@Override
public Location getLocation() {
    return location;
}
项目:dexmaker    文件:InterceptedInvocation.java   
@Override
public Location getLocation() {
    return location;
}
项目:dexmaker    文件:InvocationHandlerAdapter.java   
@Override
public Location getLocation() {
    return location;
}
项目:dexmaker    文件:InterceptedInvocation.java   
@Override
public Location getLocation() {
    return location;
}
项目:astor    文件:PrintableInvocation.java   
Location getLocation();