/** * Convenience method to avoid code duplication in tests which extend this abstract test class. * * @return a fully populated ElementDetails instance for use in tests */ public static ConcreteElementDetails createTestElementDetails() { ConcreteElementDetails elementDetails = new ConcreteElementDetails(); elementDetails.setId("the id"); elementDetails.setStyles(StylesBuilder.getInitialValueStyles()); elementDetails.setElementName("the tag name"); return elementDetails; }
private void checkRender(boolean withStyle) throws Exception { ConcreteElementDetails elementDetails; if (withStyle) { elementDetails = new ConcreteElementDetails(); elementDetails.setElementName("the tag name"); elementDetails.setStyles(StylesBuilder.getEmptyStyles()); } else { elementDetails = null; } String content = "test menu item"; // Create the test DOM for the text buffer TestDOMOutputBuffer menuText = new TestDOMOutputBuffer(); menuText.appendEncoded(content); // Create the test text, label, and then the menu item final ConcreteMenuText text = new ConcreteMenuText(elementDetails); text.setText(menuText); final ConcreteMenuLabel label = new ConcreteMenuLabel(new ElementDetailsStub(), text); final ConcreteMenuItem item = new ConcreteMenuItem(new ElementDetailsStub(), label); item.setHref(new LiteralLinkAssetReference("the href")); item.setShortcut(new LiteralTextAssetReference("the shortcut")); String expectedContent = createExpectedContent(item); String expected = null; if (withStyle) { expected = "<test-span " + // "style-class=\"the style class\" " + "tag-name=\"the tag name\"" + ">" + expectedContent + "</test-span>"; } else { expected = expectedContent; } // Create test renderer object AbstractStyledTextMenuItemRenderer renderer = createRenderer(); // Generate the rendered result string String actual = getRenderOutputAsString(renderer, item); assertNotNull("The actual string should exist", actual); // Compare state and expected assertEquals("Strings should match", expected, actual); }