Skip to content

Commit

Permalink
Simplified test case / class name;
Browse files Browse the repository at this point in the history
  • Loading branch information
MysterAitch committed Apr 26, 2019
1 parent e9274cc commit d313688
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
Expand Up @@ -7,33 +7,38 @@
import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedReferenceType;
import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.JavaSymbolSolver;
import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparser.Navigator;
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver;
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;


import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;


import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;


public class TypeResolutionWithSameNameTest extends AbstractResolutionTest { public class TypeResolutionWithSameNameTest extends AbstractResolutionTest {


@Test @Test
void testTypesWithSameNameInPackageAndNested() throws IOException { void testTypesWithSameNameInPackageAndNested() throws IOException {
Path srcPath = adaptPath("src/test/resources/TypeResolutionWithSameNameTest"); Path srcRootPath = adaptPath("src/test/resources/TypeResolutionWithSameNameTest");
JavaParserTypeSolver javaParserTypeSolver = new JavaParserTypeSolver(srcPath); Path extendingTypePath = adaptPath("src/test/resources/TypeResolutionWithSameNameTest/testresource/A.java");
StaticJavaParser.getConfiguration().setSymbolResolver(new JavaSymbolSolver(
new CombinedTypeSolver(new ReflectionTypeSolver(), javaParserTypeSolver)));


CompilationUnit cu = StaticJavaParser.parse( JavaParserTypeSolver javaParserTypeSolver = new JavaParserTypeSolver(srcRootPath);
adaptPath("src/test/resources/TypeResolutionWithSameNameTest/testresource/ExtendingType.java") StaticJavaParser
); .getConfiguration()
ClassOrInterfaceDeclaration extendingType = Navigator.demandClass(cu, "ExtendingType"); .setSymbolResolver(new JavaSymbolSolver(javaParserTypeSolver));
ClassOrInterfaceType implementedType = extendingType.getImplementedTypes(0);


CompilationUnit cu = StaticJavaParser.parse(extendingTypePath);
ClassOrInterfaceDeclaration extendingTypeClass = Navigator.demandClass(cu, "A");

// Attempt to resolve `DuplicateTypeName` from `class ExtendingType implements **DuplicateTypeName**`
ClassOrInterfaceType implementedType = extendingTypeClass.getImplementedTypes(0);
ResolvedReferenceType resolvedImplementedType = implementedType.resolve(); ResolvedReferenceType resolvedImplementedType = implementedType.resolve();


assertEquals("testresource.DuplicateTypeName", resolvedImplementedType.getQualifiedName()); // Verify qualified name matches the non-nested class in the same package.
// Note verbose assertions show both the "correct" expected value, and the erroneous value to be avoided.
String qualifiedName = resolvedImplementedType.getQualifiedName();
assertEquals("testresource.DuplicateTypeName", qualifiedName, "Error - not resolved to interface in separate file.");
assertNotEquals("testresource.ExtendingType.DuplicateTypeName", qualifiedName, "Error - resolved to nested class.");
} }
} }
@@ -0,0 +1,7 @@
package testresource;

public class A implements DuplicateTypeName {
class DuplicateTypeName extends A {

}
}

This file was deleted.

0 comments on commit d313688

Please sign in to comment.