/**
   * Test method for {@link
   * org.spdx.licenseTemplate.HtmlTemplateOutputHandler#endOptional(org.spdx.licenseTemplate.LicenseTemplateRule)}.
   *
   * @throws LicenseTemplateRuleException
   */
  @Test
  public void testEndOptional() throws LicenseTemplateRuleException {
    HtmlTemplateOutputHandler htoh = new HtmlTemplateOutputHandler();
    String optRuleName = "optionalRule";

    LicenseTemplateRule beginRule = new LicenseTemplateRule(optRuleName, RuleType.BEGIN_OPTIONAL);
    htoh.beginOptional(beginRule);

    LicenseTemplateRule endRule = new LicenseTemplateRule(optRuleName, RuleType.END_OPTIONAL);
    htoh.endOptional(endRule);
    String escapedEndRuleText = "</div>\n";
    assertTrue(htoh.getHtml().endsWith(escapedEndRuleText));
  }
  /**
   * Test method for {@link org.spdx.licenseTemplate.HtmlTemplateOutputHandler#getHtml()}.
   *
   * @throws LicenseTemplateRuleException
   */
  @Test
  public void testGetHtml() throws LicenseTemplateRuleException {
    HtmlTemplateOutputHandler htoh = new HtmlTemplateOutputHandler();
    String beginText = "Begin text\n";
    String escapedBeginText = "Begin text<br/>\n";
    htoh.normalText(beginText);

    String optRuleName = "optionalRule";

    LicenseTemplateRule beginRule = new LicenseTemplateRule(optRuleName, RuleType.BEGIN_OPTIONAL);
    htoh.beginOptional(beginRule);
    String optionalText = "Optional Text";
    htoh.optionalText(optionalText);
    String escapedBeginRuleText =
        "\n<div id=\"" + optRuleName + "\" class=\"optional-license-text\">\n";
    String escapedOptionalText = optionalText;

    String varRuleName = "testRule";
    String originalText = "Original \\ntext";
    String compareOriginalText = "Original <br/>\ntext";
    String matchText = "match text";
    String exampleText = "Example \\n text";
    LicenseTemplateRule normalRule =
        new LicenseTemplateRule(
            varRuleName, RuleType.VARIABLE, originalText, matchText, exampleText);
    String escapedVariableRuleText =
        "\n<span id=\""
            + varRuleName
            + "\" class=\"replacable-license-text\">"
            + compareOriginalText
            + "</span>\n";
    htoh.variableRule(normalRule);
    LicenseTemplateRule endRule = new LicenseTemplateRule(optRuleName, RuleType.END_OPTIONAL);
    htoh.endOptional(endRule);
    String escapedEndRuleText = "</div>\n";

    String lastLine = "\nLast Line.&";
    htoh.normalText(lastLine);
    String escapedLastLine = "<br/>\nLast Line.&amp;";

    String expectedValue =
        escapedBeginText
            + escapedBeginRuleText
            + escapedOptionalText
            + escapedVariableRuleText
            + escapedEndRuleText
            + escapedLastLine;

    assertEquals(expectedValue, htoh.getHtml());
  }