Skip to content

Commit 55b0311

Browse files
bcorsoDagger Team
authored andcommitted
Adds DaggerSuperficialValidationTest test case for missing super interface types.
This CL adds test cases to DaggerSuperficialValidationTest that test missing super interface types. Previously, we were only testing missing super class types. Note: While adding these tests I uncovered a Javac bug (b/444278301), so I've added a TODO to keep track of this issue. One option is to try to implement a fix at the XProcessing layer. RELNOTES=N/A PiperOrigin-RevId: 806363551
1 parent ee59ebd commit 55b0311

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

javatests/dagger/internal/codegen/DaggerSuperficialValidationTest.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,74 @@ public void invalidSuperclassTypeParameterInTypeHierarchy() {
639639
});
640640
}
641641

642+
@Test
643+
public void invalidSupertypeInClass() {
644+
runTest(
645+
CompilerTests.javaSource(
646+
"test.Foo",
647+
"package test;",
648+
"",
649+
"final class Foo implements MissingType {}"),
650+
CompilerTests.kotlinSource(
651+
"test.Foo.kt",
652+
"package test",
653+
"",
654+
"class Foo : MissingType"),
655+
(processingEnv, superficialValidation) -> {
656+
XTypeElement foo = processingEnv.findTypeElement("test.Foo");
657+
if (processingEnv.getBackend() == XProcessingEnv.Backend.JAVAC) {
658+
// TODO: b/444278301 - Javac's model is missing the error types.
659+
superficialValidation.validateTypeHierarchyOf("type", foo, foo.getType());
660+
return;
661+
}
662+
ValidationException exception =
663+
assertThrows(
664+
ValidationException.KnownErrorType.class,
665+
() -> superficialValidation.validateTypeHierarchyOf("type", foo, foo.getType()));
666+
assertThat(exception)
667+
.hasMessageThat()
668+
.contains(
669+
NEW_LINES.join(
670+
"Validation trace:",
671+
" => element (CLASS): test.Foo",
672+
" => type (DECLARED type): test.Foo",
673+
" => type (ERROR supertype): MissingType"));
674+
});
675+
}
676+
677+
@Test
678+
public void invalidSupertypeInInterface() {
679+
runTest(
680+
CompilerTests.javaSource(
681+
"test.Foo",
682+
"package test;",
683+
"interface Foo extends MissingType {}"),
684+
CompilerTests.kotlinSource(
685+
"test.Foo.kt",
686+
"package test",
687+
"interface Foo : MissingType"),
688+
(processingEnv, superficialValidation) -> {
689+
XTypeElement foo = processingEnv.findTypeElement("test.Foo");
690+
if (processingEnv.getBackend() == XProcessingEnv.Backend.JAVAC) {
691+
// TODO: b/444278301 - Javac's model is missing the error types.
692+
superficialValidation.validateTypeHierarchyOf("type", foo, foo.getType());
693+
return;
694+
}
695+
ValidationException exception =
696+
assertThrows(
697+
ValidationException.KnownErrorType.class,
698+
() -> superficialValidation.validateTypeHierarchyOf("type", foo, foo.getType()));
699+
assertThat(exception)
700+
.hasMessageThat()
701+
.contains(
702+
NEW_LINES.join(
703+
"Validation trace:",
704+
" => element (INTERFACE): test.Foo",
705+
" => type (DECLARED type): test.Foo",
706+
" => type (ERROR supertype): MissingType"));
707+
});
708+
}
709+
642710
private void runTest(
643711
Source.JavaSource javaSource,
644712
Source.KotlinSource kotlinSource,

0 commit comments

Comments
 (0)