001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs;
020:
021: import org.apache.tools.ant.Project;
022: import junit.framework.TestCase;
023:
024: /**
025: * Testcase for <rmic>.
026: *
027: * @since Ant 1.5
028: */
029: public class RmicTest extends TestCase {
030:
031: private Project project;
032: private Rmic rmic;
033:
034: public RmicTest(String name) {
035: super (name);
036: }
037:
038: public void setUp() {
039: project = new Project();
040: project.init();
041: rmic = new Rmic();
042: rmic.setProject(project);
043: }
044:
045: /**
046: * Test nested compiler args.
047: */
048: public void testCompilerArg() {
049: String[] args = rmic.getCurrentCompilerArgs();
050: assertNotNull(args);
051: assertEquals("no args", 0, args.length);
052:
053: Rmic.ImplementationSpecificArgument arg = rmic
054: .createCompilerArg();
055: String ford = "Ford";
056: String prefect = "Prefect";
057: String testArg = ford + " " + prefect;
058: arg.setValue(testArg);
059: args = rmic.getCurrentCompilerArgs();
060: assertEquals("unconditional single arg", 1, args.length);
061: assertEquals(testArg, args[0]);
062:
063: arg.setCompiler("weblogic");
064: args = rmic.getCurrentCompilerArgs();
065: assertNotNull(args);
066: assertEquals(
067: "implementation is weblogic but build.rmic is null", 0,
068: args.length);
069:
070: project.setProperty("build.rmic", "sun");
071: args = rmic.getCurrentCompilerArgs();
072: assertNotNull(args);
073: assertEquals(
074: "implementation is weblogic but build.rmic is sun", 0,
075: args.length);
076:
077: project.setProperty("build.rmic", "weblogic");
078: args = rmic.getCurrentCompilerArgs();
079: assertEquals("both are weblogic", 1, args.length);
080: assertEquals(testArg, args[0]);
081: }
082:
083: /**
084: * Test compiler attribute.
085: */
086: public void testCompilerAttribute() {
087: // check defaults
088: String compiler = rmic.getCompiler();
089: assertNotNull(compiler);
090: assertEquals("expected sun or kaffe, but found " + compiler,
091: compiler, "default");
092:
093: project.setNewProperty("build.rmic", "weblogic");
094: compiler = rmic.getCompiler();
095: assertNotNull(compiler);
096: assertEquals("weblogic", compiler);
097:
098: // check attribute overrides build.compiler
099: rmic.setCompiler("kaffe");
100: compiler = rmic.getCompiler();
101: assertNotNull(compiler);
102: assertEquals("kaffe", compiler);
103: }
104: }
|