001: package de.java2html.commandline.test;
002:
003: import de.java2html.commandline.IJava2HtmlConversion;
004: import de.java2html.commandline.IllegalCommandlineParametersException;
005: import de.java2html.commandline.Java2HtmlCommandline;
006: import de.java2html.commandline.Java2HtmlDirectoryConversion;
007: import de.java2html.commandline.Java2HtmlFileConversion;
008: import de.java2html.converter.JavaSource2HTMLConverter;
009: import de.java2html.converter.JavaSource2TeXConverter;
010: import de.java2html.options.JavaSourceConversionOptions;
011: import de.java2html.options.JavaSourceStyleTable;
012: import de.java2html.test.BasicTestCase;
013:
014: /**
015: * @author Markus Gebhard
016: */
017: public class Java2HtmlCommandlineTest extends BasicTestCase {
018:
019: /* ------------------ File/Directory --------------- */
020:
021: public void testCreateDirectoryConverter()
022: throws IllegalCommandlineParametersException {
023: String[] arguments = new String[] { "-srcdir", "d:/src" };
024: IJava2HtmlConversion conversion = Java2HtmlCommandline
025: .createCommandlineConversion(arguments);
026: assertInstanceOf(Java2HtmlDirectoryConversion.class, conversion);
027: }
028:
029: public void testCreateFileConverter()
030: throws IllegalCommandlineParametersException {
031: String[] arguments = new String[] { "-srcfile",
032: "d:/src/test.java" };
033: IJava2HtmlConversion conversion = Java2HtmlCommandline
034: .createCommandlineConversion(arguments);
035: assertInstanceOf(Java2HtmlFileConversion.class, conversion);
036: }
037:
038: /* ------------------ Converter type --------------- */
039:
040: public void testHtmlIsDefaultConverter()
041: throws IllegalCommandlineParametersException {
042: String[] arguments = new String[] { "-srcfile",
043: "d:/src/test.java" };
044: IJava2HtmlConversion conversion = Java2HtmlCommandline
045: .createCommandlineConversion(arguments);
046: assertInstanceOf(JavaSource2HTMLConverter.class, conversion
047: .getConverter());
048: }
049:
050: public void testUsesSpecifiedConverter()
051: throws IllegalCommandlineParametersException {
052: String[] arguments = new String[] { "-srcfile",
053: "d:/src/test.java", "-converter", "TeX" };
054: IJava2HtmlConversion conversion = Java2HtmlCommandline
055: .createCommandlineConversion(arguments);
056: assertInstanceOf(JavaSource2TeXConverter.class, conversion
057: .getConverter());
058: }
059:
060: public void testUnknwonConverterThrowsException() {
061: final String[] arguments = new String[] { "-srcfile",
062: "d:/src/test.java", "-converter",
063: "UnknownConverterName" };
064: assertThrowsException(
065: IllegalCommandlineParametersException.class,
066: new IBlock() {
067: public void execute() throws Exception {
068: Java2HtmlCommandline
069: .createCommandlineConversion(arguments);
070: }
071: });
072: }
073:
074: /* ------------------ Style --------------- */
075: public void testUsesCorrectDefaultStyle()
076: throws IllegalCommandlineParametersException {
077: String[] arguments = new String[] { "-srcfile",
078: "d:/src/test.java" };
079: IJava2HtmlConversion conversion = Java2HtmlCommandline
080: .createCommandlineConversion(arguments);
081: assertEquals(JavaSourceStyleTable.getDefault(), conversion
082:
083: .getConversionOptions().getStyleTable());
084: }
085:
086: public void testUsesSpecifiedStyle()
087: throws IllegalCommandlineParametersException {
088: String[] arguments = new String[] { "-srcfile",
089: "d:/src/test.java", "-style", "Monochrome" };
090: IJava2HtmlConversion conversion = Java2HtmlCommandline
091: .createCommandlineConversion(arguments);
092: assertEquals(JavaSourceStyleTable
093: .getPredefinedTable("Monochrome"), conversion
094: .getConversionOptions().getStyleTable());
095: }
096:
097: public void testUnknownStyleThrowsException() {
098: final String[] arguments = new String[] { "-srcfile",
099: "d:/src/test.java", "-style", "UnknownStyleName" };
100: assertThrowsException(
101: IllegalCommandlineParametersException.class,
102: new IBlock() {
103: public void execute() throws Exception {
104: Java2HtmlCommandline
105: .createCommandlineConversion(arguments);
106: }
107: });
108: }
109:
110: /* ------------------ Options --------------- */
111:
112: public void testUsesDefaultTabs()
113: throws IllegalCommandlineParametersException {
114: String[] arguments = new String[] { "-srcfile",
115: "d:/src/test.java" };
116: IJava2HtmlConversion conversion = Java2HtmlCommandline
117: .createCommandlineConversion(arguments);
118: assertEquals(JavaSourceConversionOptions.getDefault()
119: .getTabSize(), conversion.getConversionOptions()
120: .getTabSize());
121:
122: }
123:
124: public void testUsesSpecifiedTabs()
125: throws IllegalCommandlineParametersException {
126: String[] arguments = new String[] { "-srcfile",
127: "d:/src/test.java", "-tabs", "5" };
128: IJava2HtmlConversion conversion = Java2HtmlCommandline
129: .createCommandlineConversion(arguments);
130: assertEquals(5, conversion.getConversionOptions().getTabSize());
131: }
132:
133: public void testIllegalTabsThrowsException() {
134: final String[] arguments = new String[] { "-srcfile",
135: "d:/src/test.java", "-tabs", "illegal" };
136: assertThrowsException(
137: IllegalCommandlineParametersException.class,
138: new IBlock() {
139: public void execute() throws Exception {
140: Java2HtmlCommandline
141: .createCommandlineConversion(arguments);
142: }
143: });
144: }
145:
146: public void testNegativeTabsThrowsException() {
147: final String[] arguments = new String[] { "-srcfile",
148: "d:/src/test.java", "-tabs", "-3" };
149: assertThrowsException(
150: IllegalCommandlineParametersException.class,
151: new IBlock() {
152: public void execute() throws Exception {
153: Java2HtmlCommandline
154: .createCommandlineConversion(arguments);
155: }
156: });
157: }
158:
159: /* ------------------ Misc --------------- */
160:
161: public void testUnsupportedArgumentThrowsException() {
162: assertIsIllegalCommandLineArguments(new String[] { "-anUnsupportedArgument" });
163: assertIsIllegalCommandLineArguments(new String[] { "-srcfile" });
164: assertIsIllegalCommandLineArguments(new String[] { "-srcfile",
165: "d:/src/test.java", "-filemask", "*.txt" });
166: assertIsIllegalCommandLineArguments(new String[] { "-srcfile",
167: "d:/src/test.java", "-copytotargetunprocessedfiles" });
168: assertIsIllegalCommandLineArguments(new String[] { "-srcdir",
169: "d:/src", "-copytotargetunprocessedfiles", "true" });
170: assertIsIllegalCommandLineArguments(new String[] { "-srcdir",
171: "d:/src", "-copytotargetunprocessedfiles", "-anything" });
172: }
173:
174: private static void assertIsIllegalCommandLineArguments(
175: final String[] arguments) {
176: assertThrowsException(
177: IllegalCommandlineParametersException.class,
178: new IBlock() {
179: public void execute() throws Exception {
180: Java2HtmlCommandline
181: .createCommandlineConversion(arguments);
182: }
183: });
184: }
185: }
|