Added a unit test for markdown rendering functionality

This commit is contained in:
unknown
2018-08-22 14:15:25 -06:00
parent 27dcf6d8bf
commit bb8417e57b
5 changed files with 57 additions and 17 deletions

View File

@@ -24,7 +24,6 @@ import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.atlassian.webresource.api.assembler.PageBuilderService;
import org.springframework.beans.factory.annotation.Autowired;
import com.vladsch.flexmark.ast.Node;
import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughSubscriptExtension;
import com.vladsch.flexmark.ext.tables.TablesExtension;
@@ -41,7 +40,6 @@ import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.options.MutableDataSet;
import java.net.*;
import java.io.*;

View File

@@ -46,7 +46,6 @@ public class MarkdownMacro extends BaseMacro implements Macro
{
private final XhtmlContent xhtmlUtils;
private PageBuilderService pageBuilderService;
@Autowired
@@ -54,12 +53,7 @@ public class MarkdownMacro extends BaseMacro implements Macro
this.pageBuilderService = pageBuilderService;
this.xhtmlUtils = xhtmlUtils;
}
// public MarkdownMacro(XhtmlContent xhtmlUtils)
// {
// this.xhtmlUtils = xhtmlUtils;
// }
@Override
public BodyType getBodyType()
{
@@ -107,9 +101,8 @@ public class MarkdownMacro extends BaseMacro implements Macro
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
Node document = parser.parse(bodyContent);
String html = renderer.render(document ) + highlightjs; // "<p>This is <em>Sparta</em></p>\n"
String html = renderer.render(document ) + highlightjs;
return html;
}
@Override

View File

@@ -1,6 +0,0 @@
package com.atlassian.plugins.confluence.markdown;
public interface MyPluginComponent
{
String getName();
}

View File

@@ -0,0 +1,43 @@
package ut.com.atlassian.plugins.confluence;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertTrue;
import org.mockito.*;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.HashMap;
import java.util.regex.Pattern;
import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.macro.MacroExecutionException;
import com.atlassian.webresource.api.assembler.PageBuilderService;
import com.atlassian.webresource.api.assembler.RequiredResources;
import com.atlassian.webresource.api.assembler.WebResourceAssembler;
import com.atlassian.plugins.confluence.markdown.MarkdownMacro;
@RunWith (MockitoJUnitRunner.class)
public class MarkdownUnitTest {
@Mock
ConversionContext conversionContext;
@Mock
PageBuilderService pageBuilderService;
@Mock
WebResourceAssembler webResourceAssembler;
@Mock
RequiredResources requiredResources;
@InjectMocks
MarkdownMacro markdownMacro;
@Test
public void testMarkdownRendering() throws MacroExecutionException {
Mockito.when(pageBuilderService.assembler()).thenReturn(webResourceAssembler);
Mockito.when(webResourceAssembler.resources()).thenReturn(requiredResources);
Mockito.when(requiredResources.requireWebResource("com.atlassian.plugins.confluence.markdown.confluence-markdown-macro:highlightjs")).thenReturn(requiredResources);
@SuppressWarnings({ "rawtypes", "unchecked" })
String output = markdownMacro.execute(new HashMap(), "*Italic*", conversionContext);
assertTrue(Pattern.matches("<p><em>Italic</em></p>[\\S\\s]*", output));
}
}