回答編集履歴
1
コード
test
CHANGED
@@ -1 +1,101 @@
|
|
1
|
+
```ここに言語を入力
|
2
|
+
|
3
|
+
import static org.mockito.Matchers.*;
|
4
|
+
|
5
|
+
import static org.mockito.Mockito.*;
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
import org.junit.Before;
|
10
|
+
|
11
|
+
import org.junit.Test;
|
12
|
+
|
13
|
+
import org.mockito.Mockito;
|
14
|
+
|
15
|
+
import org.mockito.Spy;
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
public class MockTest {
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
@Spy
|
24
|
+
|
25
|
+
Sample1 sample1 = new Sample1();
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
@Before
|
30
|
+
|
31
|
+
public void init() {
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
@Test
|
38
|
+
|
39
|
+
public void testcase004() {
|
40
|
+
|
41
|
+
Sample2 sample2 = Mockito.spy(new Sample2());
|
42
|
+
|
43
|
+
sample1.sample2 = sample2;
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
doNothing().when(sample1.sample2).methodB(any(), any());
|
48
|
+
|
49
|
+
sample1.Y("c", "d");
|
50
|
+
|
51
|
+
verify(sample1.sample2, times(1)).methodB(eq("c"), eq("d"));
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
```
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
```ここに言語を入力
|
64
|
+
|
65
|
+
public class Sample2 {
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
public void methodB(String a, String b) {
|
70
|
+
|
1
|
-
|
71
|
+
System.out.print("called methodA" + a + b);
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
```
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
```ここに言語を入力
|
82
|
+
|
83
|
+
public class Sample1 {
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
public Sample2 sample2;
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
public void Y(String a, String b) {
|
92
|
+
|
93
|
+
sample2.methodB(a,b);
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
```
|