@@ -32,17 +32,17 @@ public class InstrumentationServiceImplTests extends ESTestCase {
32
32
static class TestTargetClass {}
33
33
34
34
interface TestChecker {
35
- void check$org_example_TestTargetClass$staticMethod (Class <?> clazz , int arg0 , String arg1 , Object arg2 );
35
+ void check$org_example_TestTargetClass$$ staticMethod (Class <?> clazz , int arg0 , String arg1 , Object arg2 );
36
36
37
- void check$$instanceMethodNoArgs (Class <?> clazz , TestTargetClass that );
37
+ void check$org_example_TestTargetClass $instanceMethodNoArgs (Class <?> clazz , TestTargetClass that );
38
38
39
- void check$$instanceMethodWithArgs (Class <?> clazz , TestTargetClass that , int x , int y );
39
+ void check$org_example_TestTargetClass $instanceMethodWithArgs (Class <?> clazz , TestTargetClass that , int x , int y );
40
40
}
41
41
42
42
interface TestCheckerOverloads {
43
- void check$org_example_TestTargetClass$staticMethodWithOverload (Class <?> clazz , int x , int y );
43
+ void check$org_example_TestTargetClass$$ staticMethodWithOverload (Class <?> clazz , int x , int y );
44
44
45
- void check$org_example_TestTargetClass$staticMethodWithOverload (Class <?> clazz , int x , String y );
45
+ void check$org_example_TestTargetClass$$ staticMethodWithOverload (Class <?> clazz , int x , String y );
46
46
}
47
47
48
48
interface TestCheckerCtors {
@@ -62,7 +62,7 @@ public void testInstrumentationTargetLookup() throws IOException {
62
62
equalTo (
63
63
new CheckMethod (
64
64
"org/elasticsearch/entitlement/instrumentation/impl/InstrumentationServiceImplTests$TestChecker" ,
65
- "check$org_example_TestTargetClass$staticMethod" ,
65
+ "check$org_example_TestTargetClass$$ staticMethod" ,
66
66
List .of ("Ljava/lang/Class;" , "I" , "Ljava/lang/String;" , "Ljava/lang/Object;" )
67
67
)
68
68
)
@@ -71,17 +71,11 @@ public void testInstrumentationTargetLookup() throws IOException {
71
71
assertThat (
72
72
checkMethods ,
73
73
hasEntry (
74
- equalTo (
75
- new MethodKey (
76
- "org/elasticsearch/entitlement/instrumentation/impl/InstrumentationServiceImplTests$TestTargetClass" ,
77
- "instanceMethodNoArgs" ,
78
- List .of ()
79
- )
80
- ),
74
+ equalTo (new MethodKey ("org/example/TestTargetClass" , "instanceMethodNoArgs" , List .of ())),
81
75
equalTo (
82
76
new CheckMethod (
83
77
"org/elasticsearch/entitlement/instrumentation/impl/InstrumentationServiceImplTests$TestChecker" ,
84
- "check$$instanceMethodNoArgs" ,
78
+ "check$org_example_TestTargetClass $instanceMethodNoArgs" ,
85
79
List .of (
86
80
"Ljava/lang/Class;" ,
87
81
"Lorg/elasticsearch/entitlement/instrumentation/impl/InstrumentationServiceImplTests$TestTargetClass;"
@@ -93,17 +87,11 @@ public void testInstrumentationTargetLookup() throws IOException {
93
87
assertThat (
94
88
checkMethods ,
95
89
hasEntry (
96
- equalTo (
97
- new MethodKey (
98
- "org/elasticsearch/entitlement/instrumentation/impl/InstrumentationServiceImplTests$TestTargetClass" ,
99
- "instanceMethodWithArgs" ,
100
- List .of ("I" , "I" )
101
- )
102
- ),
90
+ equalTo (new MethodKey ("org/example/TestTargetClass" , "instanceMethodWithArgs" , List .of ("I" , "I" ))),
103
91
equalTo (
104
92
new CheckMethod (
105
93
"org/elasticsearch/entitlement/instrumentation/impl/InstrumentationServiceImplTests$TestChecker" ,
106
- "check$$instanceMethodWithArgs" ,
94
+ "check$org_example_TestTargetClass $instanceMethodWithArgs" ,
107
95
List .of (
108
96
"Ljava/lang/Class;" ,
109
97
"Lorg/elasticsearch/entitlement/instrumentation/impl/InstrumentationServiceImplTests$TestTargetClass;" ,
@@ -127,7 +115,7 @@ public void testInstrumentationTargetLookupWithOverloads() throws IOException {
127
115
equalTo (
128
116
new CheckMethod (
129
117
"org/elasticsearch/entitlement/instrumentation/impl/InstrumentationServiceImplTests$TestCheckerOverloads" ,
130
- "check$org_example_TestTargetClass$staticMethodWithOverload" ,
118
+ "check$org_example_TestTargetClass$$ staticMethodWithOverload" ,
131
119
List .of ("Ljava/lang/Class;" , "I" , "Ljava/lang/String;" )
132
120
)
133
121
)
@@ -140,7 +128,7 @@ public void testInstrumentationTargetLookupWithOverloads() throws IOException {
140
128
equalTo (
141
129
new CheckMethod (
142
130
"org/elasticsearch/entitlement/instrumentation/impl/InstrumentationServiceImplTests$TestCheckerOverloads" ,
143
- "check$org_example_TestTargetClass$staticMethodWithOverload" ,
131
+ "check$org_example_TestTargetClass$$ staticMethodWithOverload" ,
144
132
List .of ("Ljava/lang/Class;" , "I" , "I" )
145
133
)
146
134
)
@@ -182,7 +170,7 @@ public void testInstrumentationTargetLookupWithCtors() throws IOException {
182
170
183
171
public void testParseCheckerMethodSignatureStaticMethod () {
184
172
var methodKey = InstrumentationServiceImpl .parseCheckerMethodSignature (
185
- "check$org_example_TestClass$staticMethod" ,
173
+ "check$org_example_TestClass$$ staticMethod" ,
186
174
new Type [] { Type .getType (Class .class ) }
187
175
);
188
176
@@ -191,7 +179,7 @@ public void testParseCheckerMethodSignatureStaticMethod() {
191
179
192
180
public void testParseCheckerMethodSignatureStaticMethodWithArgs () {
193
181
var methodKey = InstrumentationServiceImpl .parseCheckerMethodSignature (
194
- "check$org_example_TestClass$staticMethod" ,
182
+ "check$org_example_TestClass$$ staticMethod" ,
195
183
new Type [] { Type .getType (Class .class ), Type .getType ("I" ), Type .getType (String .class ) }
196
184
);
197
185
@@ -200,7 +188,7 @@ public void testParseCheckerMethodSignatureStaticMethodWithArgs() {
200
188
201
189
public void testParseCheckerMethodSignatureStaticMethodInnerClass () {
202
190
var methodKey = InstrumentationServiceImpl .parseCheckerMethodSignature (
203
- "check$org_example_TestClass$InnerClass$staticMethod" ,
191
+ "check$org_example_TestClass$InnerClass$$ staticMethod" ,
204
192
new Type [] { Type .getType (Class .class ) }
205
193
);
206
194
@@ -225,94 +213,80 @@ public void testParseCheckerMethodSignatureCtorWithArgs() {
225
213
assertThat (methodKey , equalTo (new MethodKey ("org/example/TestClass" , "<init>" , List .of ("I" , "java/lang/String" ))));
226
214
}
227
215
228
- public void testParseCheckerMethodSignatureIncorrectName () {
229
- var exception = assertThrows (
230
- IllegalArgumentException .class ,
231
- () -> InstrumentationServiceImpl .parseCheckerMethodSignature ("check$staticMethod" , new Type [] { Type .getType (Class .class ) })
232
- );
216
+ public void testParseCheckerMethodSignatureOneDollarSign () {
217
+ assertParseCheckerMethodSignatureThrows ("has incorrect name format" , "check$method" , Type .getType (Class .class ));
218
+ }
233
219
234
- assertThat (exception .getMessage (), containsString ("has incorrect name format" ));
220
+ public void testParseCheckerMethodSignatureMissingClass () {
221
+ assertParseCheckerMethodSignatureThrows ("has incorrect name format" , "check$$staticMethod" , Type .getType (Class .class ));
222
+ }
223
+
224
+ public void testParseCheckerMethodSignatureBlankClass () {
225
+ assertParseCheckerMethodSignatureThrows ("no class name" , "check$$$staticMethod" , Type .getType (Class .class ));
235
226
}
236
227
237
228
public void testParseCheckerMethodSignatureStaticMethodIncorrectArgumentCount () {
238
- var exception = assertThrows (
239
- IllegalArgumentException .class ,
240
- () -> InstrumentationServiceImpl .parseCheckerMethodSignature ("check$ClassName$staticMethod" , new Type [] {})
241
- );
242
- assertThat (exception .getMessage (), containsString ("It must have a first argument of Class<?> type" ));
229
+ assertParseCheckerMethodSignatureThrows ("It must have a first argument of Class<?> type" , "check$ClassName$staticMethod" );
243
230
}
244
231
245
232
public void testParseCheckerMethodSignatureStaticMethodIncorrectArgumentType () {
246
- var exception = assertThrows (
247
- IllegalArgumentException .class ,
248
- () -> InstrumentationServiceImpl .parseCheckerMethodSignature (
249
- "check$ClassName$staticMethod" ,
250
- new Type [] { Type .getType (String .class ) }
251
- )
233
+ assertParseCheckerMethodSignatureThrows (
234
+ "It must have a first argument of Class<?> type" ,
235
+ "check$ClassName$$staticMethod" ,
236
+ Type .getType (String .class )
252
237
);
253
- assertThat (exception .getMessage (), containsString ("It must have a first argument of Class<?> type" ));
254
238
}
255
239
256
240
public void testParseCheckerMethodSignatureInstanceMethod () {
257
241
var methodKey = InstrumentationServiceImpl .parseCheckerMethodSignature (
258
- "check$$instanceMethod" ,
242
+ "check$org_example_TestClass $instanceMethod" ,
259
243
new Type [] { Type .getType (Class .class ), Type .getType (TestTargetClass .class ) }
260
244
);
261
245
262
- assertThat (
263
- methodKey ,
264
- equalTo (
265
- new MethodKey (
266
- "org/elasticsearch/entitlement/instrumentation/impl/InstrumentationServiceImplTests$TestTargetClass" ,
267
- "instanceMethod" ,
268
- List .of ()
269
- )
270
- )
271
- );
246
+ assertThat (methodKey , equalTo (new MethodKey ("org/example/TestClass" , "instanceMethod" , List .of ())));
272
247
}
273
248
274
249
public void testParseCheckerMethodSignatureInstanceMethodWithArgs () {
275
250
var methodKey = InstrumentationServiceImpl .parseCheckerMethodSignature (
276
- "check$$instanceMethod" ,
251
+ "check$org_example_TestClass $instanceMethod" ,
277
252
new Type [] { Type .getType (Class .class ), Type .getType (TestTargetClass .class ), Type .getType ("I" ), Type .getType (String .class ) }
278
253
);
279
254
280
- assertThat (
281
- methodKey ,
282
- equalTo (
283
- new MethodKey (
284
- "org/elasticsearch/entitlement/instrumentation/impl/InstrumentationServiceImplTests$TestTargetClass" ,
285
- "instanceMethod" ,
286
- List .of ("I" , "java/lang/String" )
287
- )
288
- )
289
- );
255
+ assertThat (methodKey , equalTo (new MethodKey ("org/example/TestClass" , "instanceMethod" , List .of ("I" , "java/lang/String" ))));
290
256
}
291
257
292
258
public void testParseCheckerMethodSignatureInstanceMethodIncorrectArgumentTypes () {
293
- var exception = assertThrows (
294
- IllegalArgumentException .class ,
295
- () -> InstrumentationServiceImpl .parseCheckerMethodSignature ("check$$instanceMethod" , new Type [] { Type .getType (String .class ) })
259
+ assertParseCheckerMethodSignatureThrows (
260
+ "It must have a first argument of Class<?> type" ,
261
+ "check$org_example_TestClass$instanceMethod" ,
262
+ Type .getType (String .class )
296
263
);
297
- assertThat (exception .getMessage (), containsString ("It must have a first argument of Class<?> type" ));
298
264
}
299
265
300
266
public void testParseCheckerMethodSignatureInstanceMethodIncorrectArgumentCount () {
301
- var exception = assertThrows (
302
- IllegalArgumentException .class ,
303
- () -> InstrumentationServiceImpl .parseCheckerMethodSignature ("check$$instanceMethod" , new Type [] { Type .getType (Class .class ) })
267
+ assertParseCheckerMethodSignatureThrows (
268
+ "a second argument of the class containing the method to instrument" ,
269
+ "check$org_example_TestClass$instanceMethod" ,
270
+ Type .getType (Class .class )
304
271
);
305
- assertThat (exception .getMessage (), containsString ("a second argument of the class containing the method to instrument" ));
306
272
}
307
273
308
274
public void testParseCheckerMethodSignatureInstanceMethodIncorrectArgumentTypes2 () {
275
+ assertParseCheckerMethodSignatureThrows (
276
+ "a second argument of the class containing the method to instrument" ,
277
+ "check$org_example_TestClass$instanceMethod" ,
278
+ Type .getType (Class .class ),
279
+ Type .getType ("I" )
280
+ );
281
+ }
282
+
283
+ private static void assertParseCheckerMethodSignatureThrows (String messageText , String methodName , Type ... methodArgs ) {
309
284
var exception = assertThrows (
310
285
IllegalArgumentException .class ,
311
- () -> InstrumentationServiceImpl .parseCheckerMethodSignature (
312
- "check$$instanceMethod" ,
313
- new Type [] { Type .getType (Class .class ), Type .getType ("I" ) }
314
- )
286
+ () -> InstrumentationServiceImpl .parseCheckerMethodSignature (methodName , methodArgs )
315
287
);
316
- assertThat (exception .getMessage (), containsString ("a second argument of the class containing the method to instrument" ));
288
+
289
+ assertThat (exception .getMessage (), containsString (messageText ));
317
290
}
291
+
318
292
}
0 commit comments