MarkdownProcessor { public String markdownToHtml(String markdown, String projectName, String branchName, String path, Authentication authentication, Locale locale, String contextPath) { return markdownToHtml(markdown, projectName, branchName, path, authentication, locale, true, contextPath); }  String markdownToHtml(String markdown, String projectName, String branchName, String path,
			Authentication authentication, Locale locale, String contextPath); String markdownToHtml(String markdown, String projectName, String branchName, String path,
			Authentication authentication, Locale locale, boolean nonCacheableMacros, String contextPath); String headerMarkdownToHtml(String markdown, String projectName, String branchName, String path,
			Authentication authentication, Locale locale, String contextPath); String processNonCacheableMacros(String html, String projectName, String branchName, String path,
			Authentication authentication, Locale locale, String contextPath);  }
@Test public void markdownToHtml() { when(descriptor.isCacheable()).thenReturn(true); when(macro.getDescriptor()).thenReturn(descriptor); when(macro.createRunnable()).thenReturn(runnable); String macroHtml = "<div>macroHtml</div>"; when(runnable.getHtml(any(IMacroContext.class))).thenReturn(macroHtml); String cleanedMacroHtml = "<div>cleanedMacroHtml</div>"; when(runnable.cleanupHtml(anyString())).thenAnswer(new Answer<String>() { @Override public String answer(InvocationOnMock invocation) { String html = (String) invocation.getArguments()[0]; return StringUtils.replace(html, "macroHtml", "cleanedMacroHtml"); } }); when(macroFactory.get(MACRO)).thenReturn(macro); String markdown = "{{:header:}}*header*{{:/header:}}\n**foo**\n\n{{" + MACRO + "/}}\n\nbar\n"; String result = markdownProcessor.markdownToHtml(markdown, "project", "branch", DocumentrConstants.HOME_PAGE_NAME + "/bar", authentication, Locale.US, CONTEXT); String expectedHtml = "<p><strong>foo</strong></p>" + cleanedMacroHtml + "<p>bar</p>"; assertEquals(expectedHtml, removeTextRange(result)); }
@Test public void markdownToHtmlMustNotRenderNonCacheableMacros() { when(descriptor.isCacheable()).thenReturn(false); when(macro.getDescriptor()).thenReturn(descriptor); when(macroFactory.get(MACRO)).thenReturn(macro); String markdown = "**foo**\n\n{{" + MACRO + " " + PARAMS + "/}}\n\nbar\n"; String result = markdownProcessor.markdownToHtml(markdown, "project", "branch", DocumentrConstants.HOME_PAGE_NAME + "/bar", authentication, Locale.US, CONTEXT); String expectedHtml = "<p><strong>foo</strong></p><p>" + "__" + MarkdownProcessor.NON_CACHEABLE_MACRO_MARKER + "_1__" + MACRO + " " + PARAMS + "__" + MarkdownProcessor.NON_CACHEABLE_MACRO_BODY_MARKER + "__" + "__/" + MarkdownProcessor.NON_CACHEABLE_MACRO_MARKER + "_1__" + "</p><p>bar</p>"; assertEquals(expectedHtml, removeTextRange(result)); }