@Test public void testHasAnnotation() throws IOException, ParseException { TypeSolver typeSolver = new ReflectionTypeSolver(); CompilationUnit cu = JavaParser.parse(adaptPath(new File("src/test/resources/Annotations.java.txt"))); JavaParserClassDeclaration ca = new JavaParserClassDeclaration(Navigator.demandClass(cu, "CA"), typeSolver); assertEquals(true, ca.hasAnnotation("foo.bar.MyAnnotation")); assertEquals(false, ca.hasAnnotation("foo.bar.MyAnnotation2")); assertEquals(false, ca.hasAnnotation("MyAnnotation")); assertEquals(false, ca.hasAnnotation("foo.bar.MyUnexistingAnnotation")); JavaParserClassDeclaration cb = new JavaParserClassDeclaration(Navigator.demandClass(cu, "CB"), typeSolver); assertEquals(true, cb.hasAnnotation("foo.bar.MyAnnotation")); assertEquals(true, cb.hasAnnotation("foo.bar.MyAnnotation2")); assertEquals(false, cb.hasAnnotation("MyAnnotation")); assertEquals(false, cb.hasAnnotation("foo.bar.MyUnexistingAnnotation")); }