1 package de.java2html.plugin.jspwiki.test; 2 3 import java.util.HashMap ; 4 5 import junit.framework.TestCase; 6 7 import com.ecyrd.jspwiki.plugin.PluginException; 8 9 import de.java2html.JavaSourceConversionSettings; 10 import de.java2html.options.JavaSourceStyleTable; 11 import de.java2html.plugin.AbstractJava2HtmlPlugin; 12 import de.java2html.plugin.jspwiki.Java2HtmlPlugin; 13 14 17 public class Java2HtmlPluginTest extends TestCase { 18 private final static String SOURCE_CODE = "public class HelloWorld {\n" 19 + " public static void main(String args[]) {\n" 20 + " System.out.println(\"Hello World!\");\n" 21 + " }\n" 22 + "}"; 23 24 private final static String CONVERTED_HTML_DEFAULT_STYLE = AbstractJava2HtmlPlugin.convert( 25 SOURCE_CODE, 26 AbstractJava2HtmlPlugin.getDefaultSettings()); 27 28 private Java2HtmlPlugin plugin; 29 30 private static String CONVERTED_HTML_MONOCHROME_STYLE; 31 32 static { 33 JavaSourceConversionSettings monochromeOptions = AbstractJava2HtmlPlugin.getDefaultSettings(); 34 monochromeOptions.getConversionOptions().setStyleTable(JavaSourceStyleTable.getDefaultMonochromeStyleTable()); 35 CONVERTED_HTML_MONOCHROME_STYLE = AbstractJava2HtmlPlugin.convert(SOURCE_CODE, monochromeOptions); 36 } 37 38 protected void setUp() throws Exception { 39 plugin = new Java2HtmlPlugin(); 40 41 } 42 43 public void testThrowsUsageExceptionWhenNoSourceCodeGiven() { 44 try { 45 plugin.execute(null, new HashMap ()); 46 fail(); 47 } 48 catch (PluginException expected) { 49 assertEquals(Java2HtmlPlugin.DEFAULT_USAGE_MESSAGE, expected.getMessage()); 50 } 51 } 52 53 public void testConversionAsSourceParameter() throws PluginException { 54 HashMap map = new HashMap (); 55 map.put("source", SOURCE_CODE); 56 assertEquals(CONVERTED_HTML_DEFAULT_STYLE, plugin.execute(null, map)); 57 } 58 59 public void testConversionAsBodyParameter() throws PluginException { 60 HashMap map = new HashMap (); 61 map.put("_body", SOURCE_CODE); 62 assertEquals(CONVERTED_HTML_DEFAULT_STYLE, plugin.execute(null, map)); 63 } 64 65 public void testConversionAsBodyParameterWithLeadingNewLine() throws PluginException { 66 70 HashMap map = new HashMap (); 71 map.put("_body", "\n" + SOURCE_CODE); 72 assertEquals(CONVERTED_HTML_DEFAULT_STYLE, plugin.execute(null, map)); 73 } 74 75 87 public void testUsingDefaultStyleNameIsSameAsUsingDefaultStyle() throws PluginException { 88 HashMap map = new HashMap (); 89 map.put("source", SOURCE_CODE); 90 map.put("style", AbstractJava2HtmlPlugin 91 .getDefaultSettings().getConversionOptions().getStyleTable().getName()); 92 assertEquals(CONVERTED_HTML_DEFAULT_STYLE, plugin.execute(null, map)); 93 } 94 95 public void testUsingMonochromeStyle() throws PluginException { 96 HashMap map = new HashMap (); 97 map.put("source", SOURCE_CODE); 98 map.put("style", JavaSourceStyleTable.getDefaultMonochromeStyleTable().getName()); 99 assertEquals(CONVERTED_HTML_MONOCHROME_STYLE, plugin.execute(null, map)); 100 } 101 102 public void testUnsupportedConversionStyle() { 103 HashMap map = new HashMap (); 104 map.put("style", "a_definitely_not_existing_style"); 105 try { 106 plugin.execute(null, map); 107 } 108 catch (PluginException expected) { 109 } 111 } 112 } | Popular Tags |