質問編集履歴
5
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
JUnitで単体テスト実装のため、総称型を引数に持つprivateメソッドをリフレクションで取得したいと考えています。
|
2
|
-
下記の場合、テストコードの
|
2
|
+
下記の場合、テストコードのgetDeclaredMethod()の第二引数には何を渡せばよいのでしょうか。
|
3
|
+
Class.classなど試してみたのですが、テストを実行するとNoSuchMethodExceptionとなってしまいました。
|
3
4
|
|
4
5
|
|
5
6
|
テスト対象コード
|
@@ -19,9 +20,9 @@
|
|
19
20
|
@Test
|
20
21
|
public void testHoge() {
|
21
22
|
Sample sample = new Sample();
|
22
|
-
Method method = sample.getClass().getDeclaredMethod("Hoge");
|
23
|
+
Method method = sample.getClass().getDeclaredMethod("Hoge", ???.class);
|
23
24
|
method.setAccessible(true);
|
24
|
-
method.invoke(sample,
|
25
|
+
method.invoke(sample, Sample.class);
|
25
26
|
}
|
26
27
|
|
27
28
|
}
|
4
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,14 +7,14 @@
|
|
7
7
|
```Java
|
8
8
|
public class Sample {
|
9
9
|
private void Hoge(Class<T> clazz) {
|
10
|
-
|
10
|
+
// なんやかんや
|
11
11
|
}
|
12
12
|
}
|
13
13
|
```
|
14
14
|
|
15
15
|
テストコード
|
16
16
|
```Java
|
17
|
-
public class
|
17
|
+
public class SampleTest {
|
18
18
|
|
19
19
|
@Test
|
20
20
|
public void testHoge() {
|
3
title
CHANGED
File without changes
|
body
CHANGED
@@ -19,7 +19,7 @@
|
|
19
19
|
@Test
|
20
20
|
public void testHoge() {
|
21
21
|
Sample sample = new Sample();
|
22
|
-
Method method = sample.getClass().getDeclaredMethod();
|
22
|
+
Method method = sample.getClass().getDeclaredMethod("Hoge");
|
23
23
|
method.setAccessible(true);
|
24
24
|
method.invoke(sample, ???);
|
25
25
|
}
|
2
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
**まだ編集中ですが誤って投稿してしまいました。**
|
2
|
-
**回答はまだして頂かなくて結構です。**
|
3
|
-
|
4
|
-
|
5
1
|
JUnitで単体テスト実装のため、総称型を引数に持つprivateメソッドをリフレクションで取得したいと考えています。
|
6
2
|
下記の場合、テストコードのmethod.invoke()の第二引数には何を渡せばよいのでしょうか。
|
7
3
|
|
@@ -9,20 +5,24 @@
|
|
9
5
|
テスト対象コード
|
10
6
|
|
11
7
|
```Java
|
12
|
-
public class Sample
|
8
|
+
public class Sample {
|
13
|
-
private void Hoge(Class<T> clazz)
|
9
|
+
private void Hoge(Class<T> clazz) {
|
14
10
|
|
15
|
-
|
11
|
+
}
|
16
|
-
|
12
|
+
}
|
17
13
|
```
|
18
14
|
|
19
15
|
テストコード
|
20
16
|
```Java
|
17
|
+
public class Sample {
|
18
|
+
|
21
|
-
@Test
|
19
|
+
@Test
|
22
|
-
public void testHoge()
|
20
|
+
public void testHoge() {
|
23
|
-
Sample sample = new Sample();
|
21
|
+
Sample sample = new Sample();
|
24
|
-
Method method = sample.getClass().getDeclaredMethod();
|
22
|
+
Method method = sample.getClass().getDeclaredMethod();
|
25
|
-
method.
|
23
|
+
method.setAccessible(true);
|
26
|
-
method.invoke(sample, ???
|
24
|
+
method.invoke(sample, ???);
|
27
|
-
|
25
|
+
}
|
26
|
+
|
27
|
+
}
|
28
28
|
```
|
1
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
**まだ編集中ですが誤って投稿してしまいました。**
|
2
|
+
**回答はまだして頂かなくて結構です。**
|
3
|
+
|
4
|
+
|
1
5
|
JUnitで単体テスト実装のため、総称型を引数に持つprivateメソッドをリフレクションで取得したいと考えています。
|
2
6
|
下記の場合、テストコードのmethod.invoke()の第二引数には何を渡せばよいのでしょうか。
|
3
7
|
|
@@ -17,7 +21,7 @@
|
|
17
21
|
@Test
|
18
22
|
public void testHoge() {
|
19
23
|
Sample sample = new Sample();
|
20
|
-
Method method = sample.getClass().
|
24
|
+
Method method = sample.getClass().getDeclaredMethod();
|
21
25
|
method.setAccessable??(true);
|
22
26
|
method.invoke(sample, ???.class);
|
23
27
|
}
|