/** * 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.&"; String expectedValue = escapedBeginText + escapedBeginRuleText + escapedOptionalText + escapedVariableRuleText + escapedEndRuleText + escapedLastLine; assertEquals(expectedValue, htoh.getHtml()); }
/** * Test method for {@link * org.spdx.licenseTemplate.HtmlTemplateOutputHandler#normalText(java.lang.String)}. */ @Test public void testNormalText() { String normalText = "normal text\t\nwith spec chars>"; String escapedNormalText = "normal text\t<br/>\nwith spec chars>"; HtmlTemplateOutputHandler htoh = new HtmlTemplateOutputHandler(); htoh.normalText(normalText); assertEquals(escapedNormalText, htoh.getHtml()); }