1 /* 2 * Copyright (c) 2016 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 package org.mockito.internal.exceptions.stacktrace; 6 7 import org.mockito.exceptions.stacktrace.StackTraceCleaner; 8 9 /** 10 * This predicate is used to filter "good" {@link StackTraceElement}. Good 11 */ 12 public class DefaultStackTraceCleaner implements StackTraceCleaner { 13 14 @Override isIn(StackTraceElement e)15 public boolean isIn(StackTraceElement e) { 16 if (isFromMockitoRunner(e.getClassName()) || isFromMockitoRule(e.getClassName())) { 17 return true; 18 } else if (isMockDispatcher(e.getClassName()) || isFromMockito(e.getClassName())) { 19 return false; 20 } else { 21 return true; 22 } 23 } 24 isMockDispatcher(String className)25 private static boolean isMockDispatcher(String className) { 26 return (className.contains("$$EnhancerByMockitoWithCGLIB$$") || className.contains("$MockitoMock$")); 27 } 28 isFromMockito(String className)29 private static boolean isFromMockito(String className) { 30 return className.startsWith("org.mockito."); 31 } 32 isFromMockitoRule(String className)33 private static boolean isFromMockitoRule(String className) { 34 return className.startsWith("org.mockito.internal.junit.JUnitRule"); 35 } 36 isFromMockitoRunner(String className)37 private static boolean isFromMockitoRunner(String className) { 38 return className.startsWith("org.mockito.internal.runners.") 39 || className.startsWith("org.mockito.runners.") 40 || className.startsWith("org.mockito.junit."); 41 } 42 } 43