• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2007 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 
6 package org.mockito.exceptions.base;
7 
8 import org.mockito.internal.exceptions.stacktrace.ConditionalStackTraceFilter;
9 
10 
11 /**
12  * Raised by mockito to emit an error either due to Mockito, or due to the User.
13  * All exception classes that inherit from this class will have the stack trace filtered.
14  * Filtering removes Mockito internal stack trace elements to provide clean stack traces and improve productivity.
15  * <p>
16  * The stack trace is filtered from mockito calls if you are using {@link #getStackTrace()}.
17  * For debugging purpose though you can still access the full stacktrace using {@link #getUnfilteredStackTrace()}.
18  * However note that other calls related to the stackTrace will refer to the filter stacktrace.
19  * <p>
20  * Advanced users and framework integrators can control stack trace filtering behavior
21  * via {@link org.mockito.plugins.StackTraceCleanerProvider} classpath plugin.
22  */
23 public class MockitoException extends RuntimeException {
24 
25     private static final long serialVersionUID = 1L;
26 
27     private StackTraceElement[] unfilteredStackTrace;
28 
29     // TODO lazy filtered stacktrace initialization
MockitoException(String message, Throwable t)30     public MockitoException(String message, Throwable t) {
31         super(message, t);
32         filterStackTrace();
33     }
34 
MockitoException(String message)35     public MockitoException(String message) {
36         super(message);
37         filterStackTrace();
38     }
39 
filterStackTrace()40     private void filterStackTrace() {
41         unfilteredStackTrace = getStackTrace();
42 
43         ConditionalStackTraceFilter filter = new ConditionalStackTraceFilter();
44         filter.filter(this);
45     }
46 
getUnfilteredStackTrace()47     public StackTraceElement[] getUnfilteredStackTrace() {
48         return unfilteredStackTrace;
49     }
50 }
51