1 package de.java2html.properties.test; 2 3 import java.util.Properties ; 4 5 import junit.framework.TestCase; 6 import de.java2html.javasource.JavaSourceType; 7 import de.java2html.options.HorizontalAlignment; 8 import de.java2html.options.IConversionOptionsConstants; 9 import de.java2html.options.JavaSourceConversionOptions; 10 import de.java2html.options.JavaSourceStyleTable; 11 import de.java2html.properties.ConversionOptionsPropertiesReader; 12 import de.java2html.properties.IllegalPropertyValueException; 13 import de.java2html.util.RGB; 14 15 18 public class ConversionOptionsPropertiesReaderTest extends TestCase { 19 private ConversionOptionsPropertiesReader reader; 20 21 protected void setUp() throws Exception { 22 reader = new ConversionOptionsPropertiesReader(); 23 } 24 25 public void testReadingEmptyProperties() throws IllegalPropertyValueException { 26 Properties properties = new Properties (); 27 JavaSourceConversionOptions options = reader.read(properties); 28 assertEquals(JavaSourceConversionOptions.getDefault(), options); 29 } 30 31 public void testUnknownPropertyIgnored() throws IllegalPropertyValueException { 32 Properties properties = new Properties (); 33 properties.setProperty("_unsupportedkey_", "value"); JavaSourceConversionOptions options = reader.read(properties); 35 assertEquals(JavaSourceConversionOptions.getDefault(), options); 36 } 37 38 public void testReadDefaultStyleTableName() throws IllegalPropertyValueException { 39 Properties properties = new Properties (); 40 properties.put( 41 IConversionOptionsConstants.DEFAULT_STYLE_NAME, 42 JavaSourceStyleTable.getDefaultKawaStyleTable().getName()); 43 JavaSourceConversionOptions options = reader.read(properties); 44 assertEquals(JavaSourceStyleTable.getDefaultKawaStyleTable(), options.getStyleTable()); 45 } 46 47 public void testReadIllegalDefaultStyleTableName() { 48 Properties properties = new Properties (); 49 properties.put( 50 IConversionOptionsConstants.DEFAULT_STYLE_NAME, 51 "not_existing_" + JavaSourceStyleTable.getDefaultKawaStyleTable().getName()); assertParsingPropertiesFails(properties); 53 } 54 55 private void assertParsingPropertiesFails(Properties properties) { 56 try { 57 reader.read(properties); 58 fail(); 59 } 60 catch (IllegalPropertyValueException expected) { 61 } 63 } 64 65 public void testTabSize() throws IllegalPropertyValueException { 66 Properties properties = new Properties (); 67 properties.put(IConversionOptionsConstants.TAB_SIZE, "9"); JavaSourceConversionOptions options = reader.read(properties); 69 assertEquals(9, options.getTabSize()); 70 } 71 72 public void testIllegalTabSize() { 73 Properties properties = new Properties (); 74 properties.put(IConversionOptionsConstants.TAB_SIZE, "illegal"); assertParsingPropertiesFails(properties); 76 } 77 78 public void testShowLineNumbers() throws IllegalPropertyValueException { 79 Properties properties = new Properties (); 80 properties.put(IConversionOptionsConstants.SHOW_LINE_NUMBERS, "false"); JavaSourceConversionOptions options = reader.read(properties); 82 assertFalse(options.isShowLineNumbers()); 83 } 84 85 public void testIllegalShowLineNumbers() { 86 Properties properties = new Properties (); 87 properties.put(IConversionOptionsConstants.SHOW_LINE_NUMBERS, "illegal"); assertParsingPropertiesFails(properties); 89 } 90 91 public void testShowFileName() throws IllegalPropertyValueException { 92 Properties properties = new Properties (); 93 properties.put(IConversionOptionsConstants.SHOW_FILE_NAME, "true"); JavaSourceConversionOptions options = reader.read(properties); 95 assertTrue(options.isShowFileName()); 96 } 97 98 public void testIllegalShowFileName() { 99 Properties properties = new Properties (); 100 properties.put(IConversionOptionsConstants.SHOW_FILE_NAME, "illegal"); assertParsingPropertiesFails(properties); 102 } 103 104 public void testShowTableBorder() throws IllegalPropertyValueException { 105 Properties properties = new Properties (); 106 properties.put(IConversionOptionsConstants.SHOW_TABLE_BORDER, "true"); JavaSourceConversionOptions options = reader.read(properties); 108 assertTrue(options.isShowTableBorder()); 109 } 110 111 public void testIllegalShowTableBorder() { 112 Properties properties = new Properties (); 113 properties.put(IConversionOptionsConstants.SHOW_TABLE_BORDER, "illegal"); assertParsingPropertiesFails(properties); 115 } 116 117 public void testShowJava2HtmlLink() throws IllegalPropertyValueException { 118 Properties properties = new Properties (); 119 properties.put(IConversionOptionsConstants.SHOW_JAVA2HTML_LINK, "true"); JavaSourceConversionOptions options = reader.read(properties); 121 assertTrue(options.isShowJava2HtmlLink()); 122 } 123 124 public void testIllegalJava2HtmlLink() { 125 Properties properties = new Properties (); 126 properties.put(IConversionOptionsConstants.SHOW_JAVA2HTML_LINK, "illegal"); assertParsingPropertiesFails(properties); 128 } 129 130 public void testHorizontalAlignment() throws IllegalPropertyValueException { 131 Properties properties = new Properties (); 132 properties.put(IConversionOptionsConstants.HORIZONTAL_ALIGNMENT, HorizontalAlignment.RIGHT.getName()); 133 JavaSourceConversionOptions options = reader.read(properties); 134 assertEquals(HorizontalAlignment.RIGHT, options.getHorizontalAlignment()); 135 } 136 137 public void testIllegalHorizontalAlignment() { 138 Properties properties = new Properties (); 139 properties.put(IConversionOptionsConstants.HORIZONTAL_ALIGNMENT, "illegal"); assertParsingPropertiesFails(properties); 141 } 142 143 public void testColor() throws IllegalPropertyValueException { 144 Properties properties = new Properties (); 145 properties.put(JavaSourceType.CODE.getName() + IConversionOptionsConstants.POSTFIX_COLOR, "255,255,255"); JavaSourceConversionOptions options = reader.read(properties); 147 assertEquals(RGB.WHITE, options.getStyleTable().get(JavaSourceType.CODE).getColor()); 148 } 149 150 public void testIllegalColor() { 151 Properties properties = new Properties (); 152 properties.put(JavaSourceType.CODE.getName() + IConversionOptionsConstants.POSTFIX_COLOR, "illegal"); assertParsingPropertiesFails(properties); 154 } 155 156 public void testBold() throws IllegalPropertyValueException { 157 Properties properties = new Properties (); 158 properties.put(JavaSourceType.CODE.getName() + IConversionOptionsConstants.POSTFIX_BOLD, "true"); JavaSourceConversionOptions options = reader.read(properties); 160 assertTrue(options.getStyleTable().get(JavaSourceType.CODE).isBold()); 161 } 162 163 public void testIllegalBold() { 164 Properties properties = new Properties (); 165 properties.put(JavaSourceType.CODE.getName() + IConversionOptionsConstants.POSTFIX_BOLD, "illegal"); assertParsingPropertiesFails(properties); 167 } 168 169 public void testItalic() throws IllegalPropertyValueException { 170 Properties properties = new Properties (); 171 properties.put(JavaSourceType.CODE.getName() + IConversionOptionsConstants.POSTFIX_ITALIC, "true"); JavaSourceConversionOptions options = reader.read(properties); 173 assertTrue(options.getStyleTable().get(JavaSourceType.CODE).isItalic()); 174 } 175 176 public void testIllegalItalic() { 177 Properties properties = new Properties (); 178 properties.put(JavaSourceType.CODE.getName() + IConversionOptionsConstants.POSTFIX_ITALIC, "illegal"); assertParsingPropertiesFails(properties); 180 } 181 } | Popular Tags |