回答編集履歴
2
typo
answer
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
|
2
|
+
> Utilクラスでコンストラクタの修飾子をprivateにしており、インスタンスが生成できずcheckメソッドのテストもできません。
|
3
|
+
|
1
4
|
Util#checkメソッドの定義はこう。
|
2
5
|
```java
|
3
6
|
public final class Util{
|
@@ -16,8 +19,10 @@
|
|
16
19
|
|
17
20
|
----
|
18
21
|
|
19
|
-
|
22
|
+
> privateメソッドの呼び出しを行う場合は上記のように記載するとあり、同様に書きましたが、
|
20
23
|
|
24
|
+
意味を理解せずに、同様にだけ書いてもそれは無理でしょう。どーしてもリフレクションを使いたいのであれば、こうかな。
|
25
|
+
|
21
26
|
```java
|
22
27
|
public void test() throws Exception {
|
23
28
|
Boolean expected = true;;
|
1
typo
answer
CHANGED
@@ -12,4 +12,17 @@
|
|
12
12
|
public void test() throws Exception{
|
13
13
|
Boolean actual = Util.check(null);
|
14
14
|
assertEquals(expected, actual);
|
15
|
+
```
|
16
|
+
|
17
|
+
----
|
18
|
+
|
19
|
+
どーしてもリフレクションを使いたいのであれば、こうかな。
|
20
|
+
|
21
|
+
```java
|
22
|
+
public void test() throws Exception {
|
23
|
+
Boolean expected = true;;
|
24
|
+
Method method = Util.class.getMethod("check", String.class);
|
25
|
+
Boolean actual = (Boolean) method.invoke(null, "null");
|
26
|
+
assertEquals(expected, actual);
|
27
|
+
}
|
15
28
|
```
|