Search in sources :

Example 1 with LocationImpl

use of org.mockito.internal.debugging.LocationImpl in project mockito by mockito.

the class Reporter method noMoreInteractionsWanted.

public static MockitoAssertionError noMoreInteractionsWanted(Invocation undesired, List<VerificationAwareInvocation> invocations) {
    ScenarioPrinter scenarioPrinter = new ScenarioPrinter();
    String scenario = scenarioPrinter.print(invocations);
    return new NoInteractionsWanted(join("No interactions wanted here:", new LocationImpl(), "But found this interaction on mock '" + safelyGetMockName(undesired.getMock()) + "':", undesired.getLocation(), scenario));
}
Also used : LocationImpl(org.mockito.internal.debugging.LocationImpl) ScenarioPrinter(org.mockito.internal.exceptions.util.ScenarioPrinter)

Example 2 with LocationImpl

use of org.mockito.internal.debugging.LocationImpl in project mockito by mockito.

the class MockingProgressImpl method stubbingStarted.

public void stubbingStarted() {
    validateState();
    stubbingInProgress = new LocationImpl();
}
Also used : LocationImpl(org.mockito.internal.debugging.LocationImpl)

Example 3 with LocationImpl

use of org.mockito.internal.debugging.LocationImpl in project mockito by mockito.

the class ReturnsSmartNulls method answer.

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;
}
Also used : LocationImpl(org.mockito.internal.debugging.LocationImpl) Location(org.mockito.invocation.Location)

Example 4 with LocationImpl

use of org.mockito.internal.debugging.LocationImpl in project mockito by mockito.

the class LocationImplTest method shouldBeSafeInCaseForSomeReasonFilteredStackTraceIsEmpty.

@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);
}
Also used : StackTraceFilter(org.mockito.internal.exceptions.stacktrace.StackTraceFilter) LocationImpl(org.mockito.internal.debugging.LocationImpl) Test(org.junit.Test)

Example 5 with LocationImpl

use of org.mockito.internal.debugging.LocationImpl in project powermock by powermock.

the class MethodInterceptorFilter method intercept.

public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
    if (isEqualsMethod(method)) {
        return proxy == args[0];
    } else if (isHashCodeMethod(method)) {
        return hashCodeForMock(proxy);
    } else if (acrossJVMSerializationFeature.isWriteReplace(method)) {
        return acrossJVMSerializationFeature.writeReplace(proxy);
    }
    MockitoMethodProxy mockitoMethodProxy = createMockitoMethodProxy(methodProxy);
    new CGLIBHacker().setMockitoNamingPolicy(methodProxy);
    MockitoMethod mockitoMethod = createMockitoMethod(method);
    CleanTraceRealMethod realMethod = new CleanTraceRealMethod(mockitoMethodProxy);
    Invocation invocation = new InvocationImpl(proxy, mockitoMethod, args, SequenceNumber.next(), realMethod, new LocationImpl());
    return handler.handle(invocation);
}
Also used : MockitoMethod(org.mockito.internal.invocation.MockitoMethod) Invocation(org.mockito.invocation.Invocation) CleanTraceRealMethod(org.mockito.internal.invocation.realmethod.CleanTraceRealMethod) LocationImpl(org.mockito.internal.debugging.LocationImpl) MockitoMethodProxy(org.mockito.internal.creation.util.MockitoMethodProxy) InvocationImpl(org.mockito.internal.invocation.InvocationImpl)

Aggregations

LocationImpl (org.mockito.internal.debugging.LocationImpl)6 InvocationImpl (org.mockito.internal.invocation.InvocationImpl)2 CleanTraceRealMethod (org.mockito.internal.invocation.realmethod.CleanTraceRealMethod)2 Invocation (org.mockito.invocation.Invocation)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Test (org.junit.Test)1 MockitoAssertionError (org.mockito.exceptions.base.MockitoAssertionError)1 NotAMockException (org.mockito.exceptions.misusing.NotAMockException)1 InternalMockHandler (org.mockito.internal.InternalMockHandler)1 DelegatingMethod (org.mockito.internal.creation.DelegatingMethod)1 MockitoMethodProxy (org.mockito.internal.creation.util.MockitoMethodProxy)1 StackTraceFilter (org.mockito.internal.exceptions.stacktrace.StackTraceFilter)1 ScenarioPrinter (org.mockito.internal.exceptions.util.ScenarioPrinter)1 MockitoMethod (org.mockito.internal.invocation.MockitoMethod)1 RealMethod (org.mockito.internal.invocation.realmethod.RealMethod)1 Location (org.mockito.invocation.Location)1 MockHandler (org.mockito.invocation.MockHandler)1