1 package mockit;
2
3 import static org.junit.jupiter.api.Assertions.assertEquals;
4
5 import java.applet.Applet;
6 import java.awt.Component;
7
8 import org.junit.jupiter.api.Test;
9
10
11
12
13 final class MisusedFakingAPITest {
14
15
16
17
18 @Test
19 void fakeSameMethodTwiceWithReentrantFakesFromTwoDifferentFakeClasses() {
20 new MockUp<Applet>() {
21 @Mock
22 int getComponentCount(Invocation inv) {
23 int i = inv.proceed();
24 return i + 1;
25 }
26 };
27
28 int i = new Applet().getComponentCount();
29 assertEquals(1, i);
30
31 new MockUp<Applet>() {
32 @Mock
33 int getComponentCount(Invocation inv) {
34 int j = inv.proceed();
35 return j + 2;
36 }
37 };
38
39
40 int j = new Applet().getComponentCount();
41 assertEquals(5, j);
42 }
43
44
45
46
47 static final class AppletFake extends MockUp<Applet> {
48
49
50 final int componentCount;
51
52
53
54
55
56
57
58 AppletFake(int componentCount) {
59 this.componentCount = componentCount;
60 }
61
62
63
64
65
66
67
68
69
70 @Mock
71 int getComponentCount(Invocation inv) {
72 return componentCount;
73 }
74 }
75
76
77
78
79 @Test
80 void applyTheSameFakeForAClassTwice() {
81 new AppletFake(1);
82 new AppletFake(2);
83
84 assertEquals(2, new Applet().getComponentCount());
85 }
86
87
88
89
90 @Test
91 void fakeAPrivateMethod() {
92
93 new MockUp<Component>() {
94 @Mock
95 boolean checkCoalescing() {
96 return false;
97 }
98 };
99 }
100
101
102
103
104 @Test
105 public void fakeAPrivateConstructor() {
106
107 new MockUp<System>() {
108 @Mock
109 void $init() {
110 }
111 };
112 }
113 }