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 java.io.PrintWriter;
022: import java.util.Hashtable;
023: import junit.framework.Assert;
024: import org.apache.tools.ant.BuildFileTest;
025: import org.apache.tools.ant.Project;
026:
027: /**
028: */
029: public class AntStructureTest extends BuildFileTest {
030:
031: public AntStructureTest(String name) {
032: super (name);
033: }
034:
035: public void setUp() {
036: configureProject("src/etc/testcases/taskdefs/antstructure.xml");
037: }
038:
039: public void tearDown() {
040: executeTarget("tearDown");
041: }
042:
043: public void test1() {
044: expectBuildException("test1", "required argument not specified");
045: }
046:
047: public void testCustomPrinter() {
048: executeTarget("testCustomPrinter");
049: // can't access the booleans in MyPrinter here (even if they
050: // were static) since the MyPrinter instance that was used in
051: // the test has likely been loaded via a different classloader
052: // than this class. Therefore we make the printer assert its
053: // state and only check for the tail invocation.
054: assertLogContaining(MyPrinter.TAIL_CALLED);
055: }
056:
057: public static class MyPrinter implements
058: AntStructure.StructurePrinter {
059: private static final String TAIL_CALLED = "tail has been called";
060: private boolean headCalled = false;
061: private boolean targetCalled = false;
062: private boolean tailCalled = false;
063: private int elementCalled = 0;
064: private Project p;
065:
066: public void printHead(PrintWriter out, Project p,
067: Hashtable tasks, Hashtable types) {
068: Assert.assertTrue(!headCalled);
069: Assert.assertTrue(!targetCalled);
070: Assert.assertTrue(!tailCalled);
071: Assert.assertEquals(0, elementCalled);
072: headCalled = true;
073: }
074:
075: public void printTargetDecl(PrintWriter out) {
076: Assert.assertTrue(headCalled);
077: Assert.assertTrue(!targetCalled);
078: Assert.assertTrue(!tailCalled);
079: Assert.assertEquals(0, elementCalled);
080: targetCalled = true;
081: }
082:
083: public void printElementDecl(PrintWriter out, Project p,
084: String name, Class element) {
085: Assert.assertTrue(headCalled);
086: Assert.assertTrue(targetCalled);
087: Assert.assertTrue(!tailCalled);
088: elementCalled++;
089: this .p = p;
090: }
091:
092: public void printTail(PrintWriter out) {
093: Assert.assertTrue(headCalled);
094: Assert.assertTrue(targetCalled);
095: Assert.assertTrue(!tailCalled);
096: Assert.assertTrue(elementCalled > 0);
097: tailCalled = true;
098: p.log(TAIL_CALLED);
099: }
100: }
101: }
|