1 package mockit;
2
3 import static org.junit.jupiter.api.Assertions.assertEquals;
4
5 import java.io.Serializable;
6
7 import mockit.MockingMultipleInterfacesTest.Dependency;
8
9 import org.junit.jupiter.api.Test;
10
11
12
13
14
15
16
17 final class MockingMultipleInterfacesTest<MultiMock extends Dependency & Runnable> {
18
19
20
21
22 interface Dependency {
23
24
25
26
27
28
29
30
31 String doSomething(boolean b);
32 }
33
34
35 @Mocked
36 MultiMock multiMock;
37
38
39
40
41 @Test
42 void mockFieldWithTwoInterfaces() {
43 new Expectations() {
44 {
45 multiMock.doSomething(false);
46 result = "test";
47 }
48 };
49
50 multiMock.run();
51 assertEquals("test", multiMock.doSomething(false));
52
53 new Verifications() {
54 {
55 multiMock.run();
56 }
57 };
58 }
59
60
61
62
63
64
65
66
67
68 @Test
69 <M extends Dependency & Serializable> void mockParameterWithTwoInterfaces(@Mocked final M mock) {
70 new Expectations() {
71 {
72 mock.doSomething(true);
73 result = "test";
74 }
75 };
76
77 assertEquals("test", mock.doSomething(true));
78 }
79
80
81
82
83 public interface Base {
84
85
86
87 void doSomething();
88 }
89
90
91
92
93 abstract static class Derived implements Base {
94
95
96
97 protected Derived() {
98 }
99 }
100
101
102
103
104 public abstract static class ToBeMocked extends Derived {
105 }
106
107
108
109
110
111
112
113 @Test
114 void mockAbstractMethodInheritedFromInterfaceImplementedBySuperClass(@Mocked final ToBeMocked mock) {
115 mock.doSomething();
116
117 new Verifications() {
118 {
119 mock.doSomething();
120 times = 1;
121 }
122 };
123 }
124 }