forked from mockito/mockito
/
InvocationInfoExceptionTest.java
97 lines (75 loc) · 2.96 KB
/
InvocationInfoExceptionTest.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright (c) 2022 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.stubbing.answers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.mockito.internal.invocation.InvocationBuilder;
import org.mockito.invocation.Invocation;
import java.nio.charset.CharacterCodingException;
import java.util.Arrays;
import java.util.Collection;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(Parameterized.class)
public class InvocationInfoExceptionTest {
private final String methodName;
public InvocationInfoExceptionTest(final String methodName) {
this.methodName = methodName;
}
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(
new Object[][] {
{"throwException"},
{"parentThrowsException"},
{"grandParentThrowsException"},
{"interfaceThrowsException"},
{"grandInterfaceThrowsException"},
{"interfaceOfParentThrowsException"}
});
}
@Test
public void should_know_valid_throwables() throws Exception {
// when
final Invocation invocation =
new InvocationBuilder()
.method(methodName)
.mockClass(CurrentClass.class)
.toInvocation();
final InvocationInfo info = new InvocationInfo(invocation);
// then
assertThat(info.isValidException(new Exception())).isFalse();
assertThat(info.isValidException(new CharacterCodingException())).isTrue();
}
private abstract static class GrandParent {
public abstract void grandParentThrowsException() throws CharacterCodingException;
}
private interface InterfaceOfParent {
abstract void interfaceOfParentThrowsException() throws CharacterCodingException;
}
private abstract static class Parent extends GrandParent implements InterfaceOfParent {
public abstract void parentThrowsException() throws CharacterCodingException;
}
private interface GrandInterface {
void grandInterfaceThrowsException() throws CharacterCodingException;
}
private interface Interface extends GrandInterface {
void interfaceThrowsException() throws CharacterCodingException;
}
private static class CurrentClass extends Parent implements Interface {
public void throwException() throws CharacterCodingException {}
@Override
public void grandParentThrowsException() {}
@Override
public void parentThrowsException() {}
@Override
public void grandInterfaceThrowsException() {}
@Override
public void interfaceThrowsException() {}
@Override
public void interfaceOfParentThrowsException() {
}
}
}