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);
  }
  /** Invoke the renderer using the item text as content and return the result as a String. */
  public static String getRenderOutputAsString(MenuItemBracketingRenderer renderer, MenuItem item)
      throws RendererException {

    TestDOMOutputBuffer buffer = new TestDOMOutputBuffer();

    if (renderer.open(buffer, item)) {

      buffer.transferContentsFrom(item.getLabel().getText().getText());

      renderer.close(buffer, item);
    }

    // Extract the output from the menu item rendering as a string.
    return DOMUtilities.toString(buffer.getRoot());
  }