KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > java2html > properties > test > ConversionOptionsPropertiesReaderTest


1 package de.java2html.properties.test;
2
3 import java.util.Properties JavaDoc;
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 /**
16  * @author Markus Gebhard
17  */

18 public class ConversionOptionsPropertiesReaderTest extends TestCase {
19   private ConversionOptionsPropertiesReader reader;
20
21   protected void setUp() throws Exception JavaDoc {
22     reader = new ConversionOptionsPropertiesReader();
23   }
24
25   public void testReadingEmptyProperties() throws IllegalPropertyValueException {
26     Properties JavaDoc properties = new Properties JavaDoc();
27     JavaSourceConversionOptions options = reader.read(properties);
28     assertEquals(JavaSourceConversionOptions.getDefault(), options);
29   }
30   
31   public void testUnknownPropertyIgnored() throws IllegalPropertyValueException {
32     Properties JavaDoc properties = new Properties JavaDoc();
33     properties.setProperty("_unsupportedkey_", "value"); //$NON-NLS-1$ //$NON-NLS-2$
34
JavaSourceConversionOptions options = reader.read(properties);
35     assertEquals(JavaSourceConversionOptions.getDefault(), options);
36   }
37   
38   public void testReadDefaultStyleTableName() throws IllegalPropertyValueException {
39     Properties JavaDoc properties = new Properties JavaDoc();
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 JavaDoc properties = new Properties JavaDoc();
49     properties.put(
50       IConversionOptionsConstants.DEFAULT_STYLE_NAME,
51       "not_existing_" + JavaSourceStyleTable.getDefaultKawaStyleTable().getName()); //$NON-NLS-1$
52
assertParsingPropertiesFails(properties);
53   }
54
55   private void assertParsingPropertiesFails(Properties JavaDoc properties) {
56     try {
57       reader.read(properties);
58       fail();
59     }
60     catch (IllegalPropertyValueException expected) {
61       //expected
62
}
63   }
64
65   public void testTabSize() throws IllegalPropertyValueException {
66     Properties JavaDoc properties = new Properties JavaDoc();
67     properties.put(IConversionOptionsConstants.TAB_SIZE, "9"); //$NON-NLS-1$
68
JavaSourceConversionOptions options = reader.read(properties);
69     assertEquals(9, options.getTabSize());
70   }
71
72   public void testIllegalTabSize() {
73     Properties JavaDoc properties = new Properties JavaDoc();
74     properties.put(IConversionOptionsConstants.TAB_SIZE, "illegal"); //$NON-NLS-1$
75
assertParsingPropertiesFails(properties);
76   }
77
78   public void testShowLineNumbers() throws IllegalPropertyValueException {
79     Properties JavaDoc properties = new Properties JavaDoc();
80     properties.put(IConversionOptionsConstants.SHOW_LINE_NUMBERS, "false"); //$NON-NLS-1$
81
JavaSourceConversionOptions options = reader.read(properties);
82     assertFalse(options.isShowLineNumbers());
83   }
84
85   public void testIllegalShowLineNumbers() {
86     Properties JavaDoc properties = new Properties JavaDoc();
87     properties.put(IConversionOptionsConstants.SHOW_LINE_NUMBERS, "illegal"); //$NON-NLS-1$
88
assertParsingPropertiesFails(properties);
89   }
90
91   public void testShowFileName() throws IllegalPropertyValueException {
92     Properties JavaDoc properties = new Properties JavaDoc();
93     properties.put(IConversionOptionsConstants.SHOW_FILE_NAME, "true"); //$NON-NLS-1$
94
JavaSourceConversionOptions options = reader.read(properties);
95     assertTrue(options.isShowFileName());
96   }
97
98   public void testIllegalShowFileName() {
99     Properties JavaDoc properties = new Properties JavaDoc();
100     properties.put(IConversionOptionsConstants.SHOW_FILE_NAME, "illegal"); //$NON-NLS-1$
101
assertParsingPropertiesFails(properties);
102   }
103
104   public void testShowTableBorder() throws IllegalPropertyValueException {
105     Properties JavaDoc properties = new Properties JavaDoc();
106     properties.put(IConversionOptionsConstants.SHOW_TABLE_BORDER, "true"); //$NON-NLS-1$
107
JavaSourceConversionOptions options = reader.read(properties);
108     assertTrue(options.isShowTableBorder());
109   }
110
111   public void testIllegalShowTableBorder() {
112     Properties JavaDoc properties = new Properties JavaDoc();
113     properties.put(IConversionOptionsConstants.SHOW_TABLE_BORDER, "illegal"); //$NON-NLS-1$
114
assertParsingPropertiesFails(properties);
115   }
116
117   public void testShowJava2HtmlLink() throws IllegalPropertyValueException {
118     Properties JavaDoc properties = new Properties JavaDoc();
119     properties.put(IConversionOptionsConstants.SHOW_JAVA2HTML_LINK, "true"); //$NON-NLS-1$
120
JavaSourceConversionOptions options = reader.read(properties);
121     assertTrue(options.isShowJava2HtmlLink());
122   }
123
124   public void testIllegalJava2HtmlLink() {
125     Properties JavaDoc properties = new Properties JavaDoc();
126     properties.put(IConversionOptionsConstants.SHOW_JAVA2HTML_LINK, "illegal"); //$NON-NLS-1$
127
assertParsingPropertiesFails(properties);
128   }
129   
130   public void testHorizontalAlignment() throws IllegalPropertyValueException {
131     Properties JavaDoc properties = new Properties JavaDoc();
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 JavaDoc properties = new Properties JavaDoc();
139     properties.put(IConversionOptionsConstants.HORIZONTAL_ALIGNMENT, "illegal"); //$NON-NLS-1$
140
assertParsingPropertiesFails(properties);
141   }
142
143   public void testColor() throws IllegalPropertyValueException {
144     Properties JavaDoc properties = new Properties JavaDoc();
145     properties.put(JavaSourceType.CODE.getName() + IConversionOptionsConstants.POSTFIX_COLOR, "255,255,255"); //$NON-NLS-1$
146
JavaSourceConversionOptions options = reader.read(properties);
147     assertEquals(RGB.WHITE, options.getStyleTable().get(JavaSourceType.CODE).getColor());
148   }
149
150   public void testIllegalColor() {
151     Properties JavaDoc properties = new Properties JavaDoc();
152     properties.put(JavaSourceType.CODE.getName() + IConversionOptionsConstants.POSTFIX_COLOR, "illegal"); //$NON-NLS-1$
153
assertParsingPropertiesFails(properties);
154   }
155
156   public void testBold() throws IllegalPropertyValueException {
157     Properties JavaDoc properties = new Properties JavaDoc();
158     properties.put(JavaSourceType.CODE.getName() + IConversionOptionsConstants.POSTFIX_BOLD, "true"); //$NON-NLS-1$
159
JavaSourceConversionOptions options = reader.read(properties);
160     assertTrue(options.getStyleTable().get(JavaSourceType.CODE).isBold());
161   }
162
163   public void testIllegalBold() {
164     Properties JavaDoc properties = new Properties JavaDoc();
165     properties.put(JavaSourceType.CODE.getName() + IConversionOptionsConstants.POSTFIX_BOLD, "illegal"); //$NON-NLS-1$
166
assertParsingPropertiesFails(properties);
167   }
168   
169   public void testItalic() throws IllegalPropertyValueException {
170     Properties JavaDoc properties = new Properties JavaDoc();
171     properties.put(JavaSourceType.CODE.getName() + IConversionOptionsConstants.POSTFIX_ITALIC, "true"); //$NON-NLS-1$
172
JavaSourceConversionOptions options = reader.read(properties);
173     assertTrue(options.getStyleTable().get(JavaSourceType.CODE).isItalic());
174   }
175
176   public void testIllegalItalic() {
177     Properties JavaDoc properties = new Properties JavaDoc();
178     properties.put(JavaSourceType.CODE.getName() + IConversionOptionsConstants.POSTFIX_ITALIC, "illegal"); //$NON-NLS-1$
179
assertParsingPropertiesFails(properties);
180   }
181 }
Popular Tags