forked from mockito/mockito
/
StackTraceCleaner.java
53 lines (46 loc) · 1.82 KB
/
StackTraceCleaner.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Copyright (c) 2016 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.exceptions.stacktrace;
/**
* Decides if particular StackTraceElement is excluded from the human-readable stack trace output.
* Mockito stack trace filtering mechanism uses this information.
* <p>
* Excluding an element will make it not show in the cleaned stack trace.
* Not-excluding an element does not guarantee it will be shown (e.g. it depends on the implementation of
* {@linkplain org.mockito.internal.exceptions.stacktrace.StackTraceFilter Mockito internal cleaner}).
* <p>
* The implementations are required to be thread safe ; for example, make them stateless.
* <p>
* See also the {@linkplain org.mockito.internal.exceptions.stacktrace.DefaultStackTraceCleaner Mockito default implementation}
*/
public interface StackTraceCleaner {
/**
* Decides if element is included.
*
* @param candidate element of the actual stack trace
* @return whether the element should be excluded from cleaned stack trace.
*/
boolean isIn(StackTraceElement candidate);
/**
* It's recommended to override this method in subclasses to avoid potentially costly re-boxing operations.
*/
default boolean isIn(StackFrameMetadata candidate) {
return isIn(
new StackTraceElement(
candidate.getClassName(),
candidate.getMethodName(),
candidate.getFileName(),
candidate.getLineNumber()));
}
/**
* Very similar to the StackFrame class declared on the StackWalker api.
*/
interface StackFrameMetadata {
String getClassName();
String getMethodName();
String getFileName();
int getLineNumber();
}
}