Skip to content

Commit

Permalink
added validation tests for exceptions in dispatch methods
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Feb 5, 2024
1 parent 12c925d commit 00546da
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,20 @@ protected void assertNoConformanceError(String body) throws Exception {
source.indexOf("Integer"), "Integer".length(),
"No", "can", "subclass", "Throwable");
}

@Test public void testDispatchMethodsThrownExceptionsOfTypeThrowable() throws Exception {
var source = "class Foo {\n"
+ " def dispatch foo(Object o) throws Integer {}\n"
+ " def dispatch foo(Number m) throws String {}\n"
+ "}";
XtendClass clazz = clazz(source);
helper.assertError(clazz, XTEND_FUNCTION, EXCEPTION_NOT_THROWABLE,
source.indexOf("Integer"), "Integer".length(),
"No", "can", "subclass", "Throwable");
helper.assertError(clazz, XTEND_FUNCTION, EXCEPTION_NOT_THROWABLE,
source.indexOf("String"), "String".length(),
"No", "can", "subclass", "Throwable");
}

@Test public void testExceptionsDeclaredTwiceOnConstructor() throws Exception {
var source = "import java.io.IOException class X { new () throws IOException, IOException { }}";
Expand All @@ -1711,6 +1725,24 @@ protected void assertNoConformanceError(String body) throws Exception {
source.lastIndexOf("IOException"), "IOException".length(),
"IOException", "declared", "twice");
}

@Test public void testExceptionsDeclaredTwiceOnDispatchMethods() throws Exception {
var source = "import java.io.IOException\n"
+ "import java.io.FileNotFoundException\n"
+ "\n"
+ "class Foo {\n"
+ " def dispatch foo(Object o) throws IOException, IOException {}\n"
+ " def dispatch foo(Number m) throws FileNotFoundException, FileNotFoundException {}\n"
+ "}\n"
+ "";
XtendClass clazz = clazz(source);
helper.assertError(clazz, XTEND_FUNCTION, EXCEPTION_DECLARED_TWICE,
source.lastIndexOf("IOException"), "IOException".length(),
"IOException", "declared", "twice");
helper.assertError(clazz, XTEND_FUNCTION, EXCEPTION_DECLARED_TWICE,
source.lastIndexOf("FileNotFoundException"), "FileNotFoundException".length(),
"FileNotFoundException", "declared", "twice");
}

@Test public void testExceptionsNotDeclaredTwiceOnFunction() throws Exception {
XtendClass clazz = clazz("import java.io.IOException class X {def foo() throws IOException, NullPointerException { }}");
Expand Down

0 comments on commit 00546da

Please sign in to comment.