use of spoon.test.annotation.testclasses.GlobalAnnotation in project spoon by INRIA.
the class PackageTest method testAddAnnotationToPackage.
@Test
public void testAddAnnotationToPackage() throws Exception {
// contract: Created package-info should used imports in auto-import
final Launcher spoon = new Launcher();
spoon.addInputResource("./src/test/java/spoon/test/pkg/testclasses/Foo.java");
spoon.getEnvironment().setAutoImports(true);
File outputDir = new File("./target/spoon-packageinfo");
spoon.getEnvironment().setSourceOutputDirectory(outputDir);
spoon.buildModel();
CtAnnotationType annotationType = (CtAnnotationType) spoon.getFactory().Annotation().get(GlobalAnnotation.class);
CtAnnotation annotation = spoon.getFactory().Core().createAnnotation();
annotation.setAnnotationType(annotationType.getReference());
CtPackage ctPackage = spoon.getFactory().Package().get("spoon.test.pkg.testclasses");
ctPackage.addAnnotation(annotation);
JavaOutputProcessor outputProcessor = spoon.createOutputWriter();
outputProcessor.process(ctPackage);
File packageInfo = new File(outputDir, "spoon/test/pkg/testclasses/package-info.java");
assertTrue(packageInfo.exists());
canBeBuilt(packageInfo, 8);
List<String> lines = Files.readAllLines(packageInfo.toPath());
assertFalse(lines.isEmpty());
for (String s : lines) {
if (s.trim().startsWith("import")) {
assertEquals("import spoon.test.annotation.testclasses.GlobalAnnotation;", s.trim());
}
if (s.trim().startsWith("@")) {
assertEquals("@GlobalAnnotation", s.trim());
}
}
}
Aggregations