Search in sources :

Example 1 with StackTraceFilter

use of org.mockito.internal.exceptions.stacktrace.StackTraceFilter in project powermock by powermock.

the class MockitoMethodInvocationControl method hasBeenCaughtByMockitoProxy.

private boolean hasBeenCaughtByMockitoProxy() {
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    StackTraceFilter filter = new StackTraceFilter();
    /*
        * We filter the stack-trace to check if "Mockito" exists as a stack trace element. (The filter method
        * remove all Mocktio stack trace elements). If the filtered stack trace length is not equal to the original stack trace length
        * this means that the call has been caught by Mockito.
        */
    final StackTraceElement[] filteredStackTrace = filter.filter(stackTrace, true);
    return filteredStackTrace.length != stackTrace.length;
}
Also used : StackTraceFilter(org.mockito.internal.exceptions.stacktrace.StackTraceFilter)

Example 2 with StackTraceFilter

use of org.mockito.internal.exceptions.stacktrace.StackTraceFilter 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)

Aggregations

StackTraceFilter (org.mockito.internal.exceptions.stacktrace.StackTraceFilter)2 Test (org.junit.Test)1 LocationImpl (org.mockito.internal.debugging.LocationImpl)1