Ensure that unknown annotations, such as typo'd `@nondeterministic`, will raise an exception.
This commit is contained in:
parent
70ac23ee01
commit
f212994c16
|
@ -31,6 +31,26 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class WhitelistLoaderTests extends ScriptTestCase {
|
public class WhitelistLoaderTests extends ScriptTestCase {
|
||||||
|
public void testUnknownAnnotations() {
|
||||||
|
Map<String, WhitelistAnnotationParser> parsers = new HashMap<>(WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS);
|
||||||
|
|
||||||
|
RuntimeException expected = expectThrows(RuntimeException.class, () -> {
|
||||||
|
WhitelistLoader.loadFromResourceFiles(Whitelist.class, parsers, "org.elasticsearch.painless.annotation.unknown");
|
||||||
|
});
|
||||||
|
assertEquals(
|
||||||
|
"invalid annotation: parser not found for [unknownAnnotation] [@unknownAnnotation]", expected.getCause().getMessage()
|
||||||
|
);
|
||||||
|
assertEquals(IllegalArgumentException.class, expected.getCause().getClass());
|
||||||
|
|
||||||
|
expected = expectThrows(RuntimeException.class, () -> {
|
||||||
|
WhitelistLoader.loadFromResourceFiles(Whitelist.class, parsers, "org.elasticsearch.painless.annotation.unknown_with_options");
|
||||||
|
});
|
||||||
|
assertEquals(
|
||||||
|
"invalid annotation: parser not found for [unknownAnootationWithMessage] [@unknownAnootationWithMessage[arg=\"arg value\"]]",
|
||||||
|
expected.getCause().getMessage()
|
||||||
|
);
|
||||||
|
assertEquals(IllegalArgumentException.class, expected.getCause().getClass());
|
||||||
|
}
|
||||||
|
|
||||||
public void testAnnotations() {
|
public void testAnnotations() {
|
||||||
Map<String, WhitelistAnnotationParser> parsers = new HashMap<>(WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS);
|
Map<String, WhitelistAnnotationParser> parsers = new HashMap<>(WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS);
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
# whitelist for annotation tests with unknown annotation
|
||||||
|
|
||||||
|
class org.elasticsearch.painless.AnnotationTestObject @no_import {
|
||||||
|
void unknownAnnotationMethod() @unknownAnnotation
|
||||||
|
void unknownAnnotationMethod() @unknownAnootationWithMessage[message="use another method"]
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
# whitelist for annotation tests with unknown annotation containing options
|
||||||
|
|
||||||
|
class org.elasticsearch.painless.AnnotationTestObject @no_import {
|
||||||
|
void unknownAnnotationMethod() @unknownAnootationWithMessage[arg="arg value"]
|
||||||
|
}
|
Loading…
Reference in New Issue