void () { getTypeChooserManager().registerTypeChooser(MyAbstractElement.class, new MyTypeChooser()); try { MyElement element = createElement("<a/>"); element.addBarChild(); element.addFooChild(); element.addAbstractElement(MyFooConcreteElement.class); element.addAbstractElement(MyFooConcreteElement.class, 1); element.addAbstractElement(2, MyBarConcreteElement.class); Class[] classes = {MyBarConcreteElement.class, MyFooConcreteElement.class, MyBarConcreteElement.class, MyFooConcreteElement.class, MyFooConcreteElement.class}; final List<MyAbstractElement> abstractElements = element.getAbstractElements(); for (int i = 0; i < abstractElements.size(); i++) { MyAbstractElement abstractElement = abstractElements.get(i); assertTrue(i + " " + abstractElement.getClass(), classes[i].isInstance(abstractElement)); assertEquals(String.valueOf(i), classes[i].getName(), abstractElement.getXmlTag().getAttributeValue("foo")); } } finally { getTypeChooserManager().unregisterTypeChooser(MyAbstractElement.class); } }