01: package org.objectweb.celtix.tools.common;
02:
03: public class ToolWrapperGeneratorTest extends ToolTestBase {
04:
05: private final ToolWrapperGenerator generator = new ToolWrapperGenerator(
06: ToolDummy.class.getName());
07:
08: public void testGeneratorUsingDefaultClassLoader() {
09: ToolWrapperGenerator g = new ToolWrapperGenerator(
10: ToolDummy.class.getName());
11: assertNotNull(g);
12: }
13:
14: public void testGeneratorDelegatesToExternalClass() {
15:
16: generator.generate();
17: assertTrue("wrapper generator must delegate to tool class",
18: ToolDummy.mainInvoked);
19: }
20:
21: public void testGeneratorPassesAllArgumentsToExternalMain() {
22: String[] expectedArgs = { "-b", "foo", "-keep" };
23:
24: ToolConfig config = new ToolConfig(expectedArgs);
25:
26: generator.setConfiguration(config);
27: generator.generate();
28:
29: String[] actualArgs = ToolDummy.getArguments();
30:
31: assertEquals(expectedArgs.length, actualArgs.length);
32: for (int i = 0; i < actualArgs.length; i++) {
33: assertEquals(expectedArgs[i], actualArgs[i]);
34: }
35: }
36:
37: static final class ToolDummy {
38:
39: static boolean mainInvoked;
40: private static String[] arguments;
41:
42: private ToolDummy() {
43: //complete
44: }
45:
46: public static void main(String[] args) {
47: ToolDummy.arguments = args;
48: mainInvoked = true;
49: }
50:
51: public static boolean mainInvoked() {
52: return mainInvoked;
53: }
54:
55: public static String[] getArguments() {
56: return arguments;
57: }
58: }
59:
60: }
|