Improved code efficiency, improved test for syntax highlighting
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package ut.com.atlassian.plugins.confluence;
|
package ut.com.atlassian.plugins.confluence;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -37,11 +38,6 @@ public class MarkdownFromURLUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarkdownRendering() throws MacroExecutionException, MalformedURLException {
|
public void testMarkdownRendering() throws MacroExecutionException, MalformedURLException {
|
||||||
//Mock methods for pageBuilderService.assembler().resources().requireWebResource("com.atlassian.plugins.confluence.markdown.confluence-markdown-macro:highlightjs");
|
|
||||||
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);
|
|
||||||
|
|
||||||
/*Test that markdown is correctly retrieved from a URL and rendered into HTML*/
|
/*Test that markdown is correctly retrieved from a URL and rendered into HTML*/
|
||||||
// Run the macro using a URL that points to a file containing test markdown,
|
// Run the macro using a URL that points to a file containing test markdown,
|
||||||
// then assert that *Italic* was correctly rendered into <em>Italic</em>
|
// then assert that *Italic* was correctly rendered into <em>Italic</em>
|
||||||
@@ -52,11 +48,6 @@ public class MarkdownFromURLUnitTest {
|
|||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testErrorHandling() throws MacroExecutionException, MalformedURLException {
|
public void testErrorHandling() throws MacroExecutionException, MalformedURLException {
|
||||||
//Mock methods for pageBuilderService.assembler().resources().requireWebResource("com.atlassian.plugins.confluence.markdown.confluence-markdown-macro:highlightjs");
|
|
||||||
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);
|
|
||||||
|
|
||||||
/*Test error handling of nonexistent URLs*/
|
/*Test error handling of nonexistent URLs*/
|
||||||
// Run the macro using a URL pointing to a file that does not exist,
|
// Run the macro using a URL pointing to a file that does not exist,
|
||||||
// then assert that the output of the macro is not an empty string
|
// then assert that the output of the macro is not an empty string
|
||||||
@@ -87,4 +78,11 @@ public class MarkdownFromURLUnitTest {
|
|||||||
String output3 = markdownMacro.execute(new HashMap(), input3, conversionContext);
|
String output3 = markdownMacro.execute(new HashMap(), input3, conversionContext);
|
||||||
assertThat(output3, is(not("")));
|
assertThat(output3, is(not("")));
|
||||||
}
|
}
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
//Mock methods for pageBuilderService.assembler().resources().requireWebResource("com.atlassian.plugins.confluence.markdown.confluence-markdown-macro:highlightjs");
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package ut.com.atlassian.plugins.confluence;
|
package ut.com.atlassian.plugins.confluence;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -33,12 +35,6 @@ public class MarkdownUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarkdownRendering() throws MacroExecutionException {
|
public void testMarkdownRendering() throws MacroExecutionException {
|
||||||
//Mock methods for pageBuilderService.assembler().resources().requireWebResource("com.atlassian.plugins.confluence.markdown.confluence-markdown-macro:highlightjs");
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
/*Test that markdown is correctly rendered into HTML*/
|
/*Test that markdown is correctly rendered into HTML*/
|
||||||
// Run the macro using input text of *Italic*,
|
// Run the macro using input text of *Italic*,
|
||||||
// then assert that *Italic* was correctly rendered into <em>Italic</em>
|
// then assert that *Italic* was correctly rendered into <em>Italic</em>
|
||||||
@@ -46,21 +42,24 @@ public class MarkdownUnitTest {
|
|||||||
String output = markdownMacro.execute(new HashMap(), "*Italic*", conversionContext);
|
String output = markdownMacro.execute(new HashMap(), "*Italic*", conversionContext);
|
||||||
assertTrue(Pattern.matches("[\\S\\s]*<em>Italic</em>[\\S\\s]*", output)); //Uses [\S\s] (anything that is either whitespace or not whitespace) instead of . (any character) because . does not match newline characters.
|
assertTrue(Pattern.matches("[\\S\\s]*<em>Italic</em>[\\S\\s]*", output)); //Uses [\S\s] (anything that is either whitespace or not whitespace) instead of . (any character) because . does not match newline characters.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSyntaxHighlighting() throws MacroExecutionException {
|
public void testSyntaxHighlighting() throws MacroExecutionException {
|
||||||
|
/*Test that the correct JavaScript is returned for highlight.js to work*/
|
||||||
|
// Run the macro using input of a line of code in a code block,
|
||||||
|
// then assert that a <code> block is returned.
|
||||||
|
// Intended only as a temporary test until I can program a better one
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
String output = markdownMacro.execute(new HashMap(), "`public class JavaClass {}`", conversionContext);
|
||||||
|
System.out.println(output);
|
||||||
|
assertTrue(Pattern.matches("[\\S\\s]*<code.*>public class JavaClass \\{\\}<\\/code>[\\S\\s]*", output));
|
||||||
|
assertTrue(Pattern.matches("[\\S\\s]*<script>\\sAJS\\.\\$\\('\\[data\\-macro\\-name=\"markdown\"\\] code'\\)\\.each\\(function\\(i, block\\) \\{\\s hljs\\.highlightBlock\\(block\\);\\s \\}\\);\\s<\\/script>[\\S\\s]*", output));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
//Mock methods for pageBuilderService.assembler().resources().requireWebResource("com.atlassian.plugins.confluence.markdown.confluence-markdown-macro:highlightjs");
|
//Mock methods for pageBuilderService.assembler().resources().requireWebResource("com.atlassian.plugins.confluence.markdown.confluence-markdown-macro:highlightjs");
|
||||||
Mockito.when(pageBuilderService.assembler()).thenReturn(webResourceAssembler);
|
Mockito.when(pageBuilderService.assembler()).thenReturn(webResourceAssembler);
|
||||||
Mockito.when(webResourceAssembler.resources()).thenReturn(requiredResources);
|
Mockito.when(webResourceAssembler.resources()).thenReturn(requiredResources);
|
||||||
Mockito.when(requiredResources.requireWebResource("com.atlassian.plugins.confluence.markdown.confluence-markdown-macro:highlightjs")).thenReturn(requiredResources);
|
Mockito.when(requiredResources.requireWebResource("com.atlassian.plugins.confluence.markdown.confluence-markdown-macro:highlightjs")).thenReturn(requiredResources);
|
||||||
|
|
||||||
|
|
||||||
/*Test that the correct JavaScript is returned for highlight.js to work*/
|
|
||||||
// Run the macro using input of a line of code in a code block,
|
|
||||||
// then assert that the correct JavaScript was returned.
|
|
||||||
// Intended only as a temporary test until I can program a better one
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
||||||
String output = markdownMacro.execute(new HashMap(), "'public class JavaClass {}'", conversionContext);
|
|
||||||
assertTrue(Pattern.matches("[\\S\\s]*<script>\\sAJS\\.\\$\\('\\[data\\-macro\\-name=\"markdown\"\\] code'\\)\\.each\\(function\\(i, block\\) \\{\\s hljs\\.highlightBlock\\(block\\);\\s \\}\\);\\s<\\/script>[\\S\\s]*", output));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user