MockitoException.java revision e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7
1/*
2 * Copyright (c) 2007 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5
6package org.mockito.exceptions.base;
7
8import 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 *
14 * <p>
15 *     The stack trace is filtered from mockito calls if you are using {@link #getStackTrace()}.
16 *     For debugging purpose though you can still access the full stacktrace using {@link #getUnfilteredStackTrace()}.
17 *     However note that other calls related to the stackTrace will refer to the filter stacktrace.
18 * </p>
19 *
20 */
21public class MockitoException extends RuntimeException {
22
23    private static final long serialVersionUID = 1L;
24
25    private StackTraceElement[] unfilteredStackTrace;
26
27    // TODO lazy filtered stacktrace initialization
28    public MockitoException(String message, Throwable t) {
29        super(message, t);
30        filterStackTrace();
31    }
32
33    public MockitoException(String message) {
34        super(message);
35        filterStackTrace();
36    }
37
38    private void filterStackTrace() {
39        unfilteredStackTrace = getStackTrace();
40
41        ConditionalStackTraceFilter filter = new ConditionalStackTraceFilter();
42        filter.filter(this);
43    }
44
45    public StackTraceElement[] getUnfilteredStackTrace() {
46        return unfilteredStackTrace;
47    }
48}
49