@@ -54,11 +54,14 @@ public class RuntimeHintsAgentTests {
54
54
55
55
private static Method toStringMethod ;
56
56
57
+ private static Method privateGreetMethod ;
58
+
57
59
58
60
@ BeforeAll
59
61
public static void classSetup () throws NoSuchMethodException {
60
62
defaultConstructor = String .class .getConstructor ();
61
63
toStringMethod = String .class .getMethod ("toString" );
64
+ privateGreetMethod = PrivateClass .class .getDeclaredMethod ("greet" );
62
65
}
63
66
64
67
@@ -79,6 +82,7 @@ private static Stream<Arguments> instrumentedReflectionMethods() {
79
82
Class .forName ("java.lang.String" );
80
83
}
81
84
catch (ClassNotFoundException e ) {
85
+ throw new RuntimeException (e );
82
86
}
83
87
}, MethodReference .of (Class .class , "forName" )),
84
88
Arguments .of ((Runnable ) () -> String .class .getClasses (), MethodReference .of (Class .class , "getClasses" )),
@@ -87,6 +91,7 @@ private static Stream<Arguments> instrumentedReflectionMethods() {
87
91
String .class .getConstructor ();
88
92
}
89
93
catch (NoSuchMethodException e ) {
94
+ throw new RuntimeException (e );
90
95
}
91
96
}, MethodReference .of (Class .class , "getConstructor" )),
92
97
Arguments .of ((Runnable ) () -> String .class .getConstructors (), MethodReference .of (Class .class , "getConstructors" )),
@@ -96,14 +101,16 @@ private static Stream<Arguments> instrumentedReflectionMethods() {
96
101
String .class .getDeclaredConstructor ();
97
102
}
98
103
catch (NoSuchMethodException e ) {
104
+ throw new RuntimeException (e );
99
105
}
100
106
}, MethodReference .of (Class .class , "getDeclaredConstructor" )),
101
107
Arguments .of ((Runnable ) () -> String .class .getDeclaredConstructors (), MethodReference .of (Class .class , "getDeclaredConstructors" )),
102
108
Arguments .of ((Runnable ) () -> {
103
109
try {
104
- String .class .getDeclaredField ("test " );
110
+ String .class .getDeclaredField ("value " );
105
111
}
106
112
catch (NoSuchFieldException e ) {
113
+ throw new RuntimeException (e );
107
114
}
108
115
}, MethodReference .of (Class .class , "getDeclaredField" )),
109
116
Arguments .of ((Runnable ) () -> String .class .getDeclaredFields (), MethodReference .of (Class .class , "getDeclaredFields" )),
@@ -112,12 +119,13 @@ private static Stream<Arguments> instrumentedReflectionMethods() {
112
119
String .class .getDeclaredMethod ("toString" );
113
120
}
114
121
catch (NoSuchMethodException e ) {
122
+ throw new RuntimeException (e );
115
123
}
116
124
}, MethodReference .of (Class .class , "getDeclaredMethod" )),
117
125
Arguments .of ((Runnable ) () -> String .class .getDeclaredMethods (), MethodReference .of (Class .class , "getDeclaredMethods" )),
118
126
Arguments .of ((Runnable ) () -> {
119
127
try {
120
- String .class .getField ("test " );
128
+ String .class .getField ("value " );
121
129
}
122
130
catch (NoSuchFieldException e ) {
123
131
}
@@ -128,6 +136,7 @@ private static Stream<Arguments> instrumentedReflectionMethods() {
128
136
String .class .getMethod ("toString" );
129
137
}
130
138
catch (NoSuchMethodException e ) {
139
+ throw new RuntimeException (e );
131
140
}
132
141
}, MethodReference .of (Class .class , "getMethod" )),
133
142
Arguments .of ((Runnable ) () -> String .class .getMethods (), MethodReference .of (Class .class , "getMethods" )),
@@ -136,20 +145,31 @@ private static Stream<Arguments> instrumentedReflectionMethods() {
136
145
classLoader .loadClass ("java.lang.String" );
137
146
}
138
147
catch (ClassNotFoundException e ) {
148
+ throw new RuntimeException (e );
139
149
}
140
150
}, MethodReference .of (ClassLoader .class , "loadClass" )),
141
151
Arguments .of ((Runnable ) () -> {
142
152
try {
143
153
defaultConstructor .newInstance ();
144
154
}
145
155
catch (Exception e ) {
156
+ throw new RuntimeException (e );
146
157
}
147
158
}, MethodReference .of (Constructor .class , "newInstance" )),
148
159
Arguments .of ((Runnable ) () -> {
149
160
try {
150
161
toStringMethod .invoke ("" );
151
162
}
152
163
catch (Exception e ) {
164
+ throw new RuntimeException (e );
165
+ }
166
+ }, MethodReference .of (Method .class , "invoke" )),
167
+ Arguments .of ((Runnable ) () -> {
168
+ try {
169
+ privateGreetMethod .invoke (new PrivateClass ());
170
+ }
171
+ catch (Exception e ) {
172
+ throw new RuntimeException (e );
153
173
}
154
174
}, MethodReference .of (Method .class , "invoke" ))
155
175
);
@@ -265,4 +285,12 @@ Stream<RecordedInvocation> recordedInvocations(HintType hintType) {
265
285
266
286
}
267
287
288
+ private static class PrivateClass {
289
+
290
+ private String greet () {
291
+ return "hello" ;
292
+ }
293
+
294
+ }
295
+
268
296
}
0 commit comments