KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > antcontrib > logic > SwitchTest


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2002 Ant-Contrib project. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution, if
19  * any, must include the following acknowlegement:
20  * "This product includes software developed by the
21  * Ant-Contrib project (http://sourceforge.net/projects/ant-contrib)."
22  * Alternately, this acknowlegement may appear in the software itself,
23  * if and wherever such third-party acknowlegements normally appear.
24  *
25  * 4. The name Ant-Contrib must not be used to endorse or promote products
26  * derived from this software without prior written permission. For
27  * written permission, please contact
28  * ant-contrib-developers@lists.sourceforge.net.
29  *
30  * 5. Products derived from this software may not be called "Ant-Contrib"
31  * nor may "Ant-Contrib" appear in their names without prior written
32  * permission of the Ant-Contrib project.
33  *
34  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
35  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37  * DISCLAIMED. IN NO EVENT SHALL THE ANT-CONTRIB PROJECT OR ITS
38  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
41  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
42  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
43  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
44  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45  * SUCH DAMAGE.
46  * ====================================================================
47  */

48
49 package net.sf.antcontrib.logic;
50
51 import org.apache.tools.ant.BuildFileTest;
52
53 /**
54  * Testcase for <switch>.
55  *
56  * @author <a HREF="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
57  */

58 public class SwitchTest extends BuildFileTest {
59
60     public SwitchTest(String JavaDoc name) {
61         super(name);
62     }
63
64     public void setUp() {
65         configureProject("test/resources/logic/switch.xml");
66     }
67
68     public void testNoValue() {
69         expectSpecificBuildException("noValue", "no value",
70                                      "Value is missing");
71     }
72         
73     public void testNoChildren() {
74         expectSpecificBuildException("noChildren", "no children",
75                                      "No cases supplied");
76     }
77
78     public void testTwoDefaults() {
79         expectSpecificBuildException("twoDefaults", "two defaults",
80                                      "Cannot specify multiple default cases");
81     }
82
83     public void testNoMatch() {
84         expectSpecificBuildException("noMatch", "no match",
85                                      "No case matched the value foo"
86                                      + " and no default has been specified.");
87     }
88
89     public void testCaseNoValue() {
90         expectSpecificBuildException("caseNoValue", "<case> no value",
91                                      "Value is required for case.");
92     }
93
94     public void testDefault() {
95         executeTarget("testDefault");
96         assertTrue(getLog().indexOf("In default") > -1);
97         assertTrue(getLog().indexOf("baz") > -1);
98         assertEquals(-1, getLog().indexOf("${inner}"));
99         assertEquals(-1, getLog().indexOf("In case"));
100     }
101
102     public void testCase() {
103         executeTarget("testCase");
104         assertTrue(getLog().indexOf("In case") > -1);
105         assertTrue(getLog().indexOf("baz") > -1);
106         assertEquals(-1, getLog().indexOf("${inner}"));
107         assertEquals(-1, getLog().indexOf("In default"));
108     }
109
110     public void testCaseSensitive() {
111         executeTarget("testCaseSensitive");
112         assertTrue(getLog().indexOf("In default") > -1);
113         assertEquals(-1, getLog().indexOf("In case"));
114     }
115
116     public void testCaseInSensitive() {
117         executeTarget("testCaseInSensitive");
118         assertTrue(getLog().indexOf("In case") > -1);
119         assertEquals(-1, getLog().indexOf("In default"));
120     }
121
122 }
123
Popular Tags