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