回答編集履歴
1
転載追記
test
CHANGED
@@ -1,3 +1,53 @@
|
|
1
1
|
ググっただけですが。
|
2
2
|
|
3
3
|
[JMockit使い方メモ - private メソッドをモック化する](https://qiita.com/opengl-8080/items/a49d4dae9067413ccdd6#private-%E3%83%A1%E3%82%BD%E3%83%83%E3%83%89%E3%82%92%E3%83%A2%E3%83%83%E3%82%AF%E5%8C%96%E3%81%99%E3%82%8B)
|
4
|
+
|
5
|
+
```Java
|
6
|
+
|
7
|
+
public class JmockitTest {
|
8
|
+
|
9
|
+
@Test
|
10
|
+
|
11
|
+
public void test() {
|
12
|
+
|
13
|
+
new MockUp<Hoge>() {
|
14
|
+
|
15
|
+
@Mock
|
16
|
+
|
17
|
+
private void privateMethod() {
|
18
|
+
|
19
|
+
System.out.println("mock");
|
20
|
+
|
21
|
+
}
|
22
|
+
|
23
|
+
};
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
Hoge hoge = new Hoge();
|
28
|
+
|
29
|
+
hoge.method();
|
30
|
+
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
public static class Hoge {
|
36
|
+
|
37
|
+
public void method() {
|
38
|
+
|
39
|
+
this.privateMethod();
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
private void privateMethod() {
|
44
|
+
|
45
|
+
System.out.println("privateMethod() is called.");
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
```
|