@Test public void transformationOfClassWithExistingManagedDependencies() { this.moduleNode.setPackage(new PackageNode("foo")); ClassNode cls = ClassHelper.make("MyClass"); this.moduleNode.addClass(cls); AnnotationNode annotation = new AnnotationNode( ClassHelper.make(DependencyManagementBom.class)); annotation.addMember("value", new ConstantExpression("test:parent:1.0.0")); cls.addAnnotation(annotation); this.transformation.visit(new ASTNode[] { this.moduleNode }, this.sourceUnit); assertThat(getValue().toString()) .isEqualTo("[test:parent:1.0.0, test:child:1.0.0]"); }
private AnnotationNode findAnnotation() { PackageNode packageNode = this.moduleNode.getPackage(); ClassNode bom = ClassHelper.make(DependencyManagementBom.class); if (packageNode != null) { if (!packageNode.getAnnotations(bom).isEmpty()) { return packageNode.getAnnotations(bom).get(0); } } if (!this.moduleNode.getClasses().isEmpty()) { return this.moduleNode.getClasses().get(0).getAnnotations(bom).get(0); } throw new IllegalStateException("No package or class node found"); }
@Test public void transformationOfClassWithExistingManagedDependencies() { this.moduleNode.setPackage(new PackageNode("foo")); ClassNode cls = ClassHelper.make("MyClass"); this.moduleNode.addClass(cls); AnnotationNode annotation = new AnnotationNode( ClassHelper.make(DependencyManagementBom.class)); annotation.addMember("value", new ConstantExpression("test:parent:1.0.0")); cls.addAnnotation(annotation); this.transformation.visit(new ASTNode[] { this.moduleNode }, this.sourceUnit); assertEquals("[test:parent:1.0.0, test:child:1.0.0]", getValue().toString()); }