@Test public void testOnlyController() { Reporter reporter = mock(Reporter.class); ComponentWorkbench workbench = mock(ComponentWorkbench.class); when(workbench.getType()).thenReturn(Type.getType(MyComponent.class)); when(workbench.getClassNode()).thenReturn(new ClassNode()); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { root = (Element) invocation.getArguments()[0]; return null; } }).when(workbench).setRoot(any(Element.class)); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { instance = (Element) invocation.getArguments()[0]; return null; } }).when(workbench).setInstance(any(Element.class)); WisdomControllerVisitor visitor = new WisdomControllerVisitor(workbench, reporter); visitor.visitEnd(); assertThat(root).isNotNull(); assertThat(root.getName()).isEqualTo("component"); assertThat(root.getAttribute("classname")).isEqualTo(MyComponent.class.getName()); assertThat(root.getElements("provides")).hasSize(1); assertThat(instance).isNotNull(); assertThat(instance.getAttribute("component")).isEqualTo(MyComponent.class.getName()); }
public void visitEnd() { String classname = workbench.getType().getClassName(); component.addAttribute(new Attribute("classname", classname)); component.addElement(ElementHelper.getProvidesElement(null)); if (!workbench.getClassNode().interfaces.contains(Type.getInternalName(Controller.class)) && !Type.getInternalName(DefaultController.class).equals(workbench.getClassNode().superName)) { reporter.warn("Cannot ensure that the class " + workbench.getType().getClassName() + " implements the " + Controller.class.getName() + " interface."); } if (workbench.getRoot() == null) { workbench.setRoot(component); workbench.setInstance(ElementHelper.declareInstance(workbench)); } else { reporter.error("Multiple 'component type' annotations on the class '{%s}'.", classname); reporter.warn("@Controller is ignored."); } }
WisdomControllerVisitor extends AnnotationVisitor { public void visitEnd() { String classname = workbench.getType().getClassName(); component.addAttribute(new Attribute("classname", classname)); component.addElement(ElementHelper.getProvidesElement(null)); if (!workbench.getClassNode().interfaces.contains(Type.getInternalName(Controller.class)) && !Type.getInternalName(DefaultController.class).equals(workbench.getClassNode().superName)) { reporter.warn("Cannot ensure that the class " + workbench.getType().getClassName() + " implements the " + Controller.class.getName() + " interface."); } if (workbench.getRoot() == null) { workbench.setRoot(component); workbench.setInstance(ElementHelper.declareInstance(workbench)); } else { reporter.error("Multiple 'component type' annotations on the class '{%s}'.", classname); reporter.warn("@Controller is ignored."); } } }
WisdomControllerVisitor extends AnnotationVisitor { public void visitEnd() { String classname = workbench.getType().getClassName(); component.addAttribute(new Attribute("classname", classname)); component.addElement(ElementHelper.getProvidesElement(null)); if (!workbench.getClassNode().interfaces.contains(Type.getInternalName(Controller.class)) && !Type.getInternalName(DefaultController.class).equals(workbench.getClassNode().superName)) { reporter.warn("Cannot ensure that the class " + workbench.getType().getClassName() + " implements the " + Controller.class.getName() + " interface."); } if (workbench.getRoot() == null) { workbench.setRoot(component); workbench.setInstance(ElementHelper.declareInstance(workbench)); } else { reporter.error("Multiple 'component type' annotations on the class '{%s}'.", classname); reporter.warn("@Controller is ignored."); } } WisdomControllerVisitor(ComponentWorkbench workbench, Reporter reporter); }
WisdomControllerVisitor extends AnnotationVisitor { public void visitEnd() { String classname = workbench.getType().getClassName(); component.addAttribute(new Attribute("classname", classname)); component.addElement(ElementHelper.getProvidesElement(null)); if (!workbench.getClassNode().interfaces.contains(Type.getInternalName(Controller.class)) && !Type.getInternalName(DefaultController.class).equals(workbench.getClassNode().superName)) { reporter.warn("Cannot ensure that the class " + workbench.getType().getClassName() + " implements the " + Controller.class.getName() + " interface."); } if (workbench.getRoot() == null) { workbench.setRoot(component); workbench.setInstance(ElementHelper.declareInstance(workbench)); } else { reporter.error("Multiple 'component type' annotations on the class '{%s}'.", classname); reporter.warn("@Controller is ignored."); } } WisdomControllerVisitor(ComponentWorkbench workbench, Reporter reporter); void visitEnd(); }
WisdomControllerVisitor extends AnnotationVisitor { public void visitEnd() { String classname = workbench.getType().getClassName(); component.addAttribute(new Attribute("classname", classname)); component.addElement(ElementHelper.getProvidesElement(null)); if (!workbench.getClassNode().interfaces.contains(Type.getInternalName(Controller.class)) && !Type.getInternalName(DefaultController.class).equals(workbench.getClassNode().superName)) { reporter.warn("Cannot ensure that the class " + workbench.getType().getClassName() + " implements the " + Controller.class.getName() + " interface."); } if (workbench.getRoot() == null) { workbench.setRoot(component); workbench.setInstance(ElementHelper.declareInstance(workbench)); } else { reporter.error("Multiple 'component type' annotations on the class '{%s}'.", classname); reporter.warn("@Controller is ignored."); } } WisdomControllerVisitor(ComponentWorkbench workbench, Reporter reporter); void visitEnd();  }