質問編集履歴

1

投稿ミスの修正

2017/10/02 13:14

投稿

gu3.net
gu3.net

スコア11

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,11 @@
8
8
 
9
9
 
10
10
 
11
- 下記のように実装しましたが、Processbuilder.start()でNullPointerになっています。
11
+ 下記のように実装しましたが、NullPointerになっています。
12
+
13
+ CommandクラスをMock化しているので、sampleA内の`Cmd.execute`は実行されず、
14
+
15
+ when句で設定したResultが返却されると思っているのですが、どうやら実行されており、`Processbuilder.start`でエラーとなっています。
12
16
 
13
17
 
14
18
 
@@ -29,6 +33,52 @@
29
33
 
30
34
 
31
35
  ###該当のソースコード
36
+
37
+ ```java
38
+
39
+ @RunWith(SpringRunner.class)
40
+
41
+ @SpringBootTest
42
+
43
+ public class SampleATest {
44
+
45
+
46
+
47
+ private static final SampleA sampleA = new SampleA();
48
+
49
+
50
+
51
+ @Test
52
+
53
+ public void testExecuteCommand() throws Exception {
54
+
55
+ Method method = SampleA.class.getDeclaredMethod("executeCommand", Object.class, String.class);
56
+
57
+ method.setAccessible(true);
58
+
59
+
60
+
61
+ Result result = mock(Result.class);
62
+
63
+ Whitebox.setInternalState(result, "exitValue", 0);
64
+
65
+
66
+
67
+ Command command = spy(Command.class);
68
+
69
+ when(command.execute(anyObject(), anyObject())).thenReturn(result);
70
+
71
+
72
+
73
+ Result result2 = (Result) method.invoke(sampleA, obj, strs);
74
+
75
+ assertThat(result2.getExitValue(), is(0));
76
+
77
+ }
78
+
79
+ }
80
+
81
+ ```
32
82
 
33
83
  ```java
34
84
 
@@ -76,7 +126,7 @@
76
126
 
77
127
  try {
78
128
 
79
- result.exitValue = process.exitValue();
129
+ result.exitValue = process.exitValue();
80
130
 
81
131
  } finally {
82
132
 
@@ -94,20 +144,16 @@
94
144
 
95
145
  ```
96
146
 
97
- ```ここに言語を入力
98
-
99
- ここにご自身が実行したソースコードを書いてください
100
-
101
- ```
102
-
103
-
104
-
105
- ###試したこと
106
-
107
- 課題に対してアプローチしたことを記載してください
108
-
109
147
 
110
148
 
111
149
  ###補足情報(言語/FW/ツール等のバージョンなど)
112
150
 
151
+ * SpringBoot 1.5.x
152
+
113
- より詳細な情報
153
+ * JUnit 4.x
154
+
155
+ * Mockito 2.x
156
+
157
+
158
+
159
+ コードにマスクをしておりますので、不整合がありましたら申し訳ありません。