Skip to content

Commit b9d401b

Browse files
SONARJAVA-5624 Fix coverage of JTypeSymbol new code (#5194)
1 parent 83e06f7 commit b9d401b

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

java-frontend/src/test/java/org/sonar/java/model/JTypeSymbolTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.sonar.java.model.declaration.ClassTreeImpl;
2323
import org.sonar.java.model.declaration.MethodTreeImpl;
2424
import org.sonar.java.model.declaration.VariableTreeImpl;
25+
import org.sonar.plugins.java.api.semantic.Type;
2526

2627
import static org.assertj.core.api.Assertions.assertThat;
2728
import static org.junit.jupiter.api.Assertions.assertAll;
@@ -60,6 +61,17 @@ void superClass() {
6061
);
6162
}
6263

64+
@Test
65+
void testSuperClassWhenSemanticCanNotResolveObjectType() {
66+
var cu = test("interface I{}");
67+
var i = (ClassTreeImpl) cu.types().get(0);
68+
69+
JSema sematicThatCanNotResolveObjectType = spy(cu.sema);
70+
when(sematicThatCanNotResolveObjectType.resolveType("java.lang.Object")).thenReturn(null);
71+
var typeSymbol = new JTypeSymbol(sematicThatCanNotResolveObjectType, i.typeBinding);
72+
assertThat(typeSymbol.superClass()).isSameAs(Type.UNKNOWN);
73+
}
74+
6375
@Test
6476
void interfaces() {
6577
JavaTree.CompilationUnitTreeImpl cu = test("interface I { } class C implements I { }");

0 commit comments

Comments
 (0)