Debian Codegraph @

test/src/net/sf/antcontrib/logic/IfTaskTest.java

raw symbols SCIP
1 /*
2 * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.antcontrib.logic;
17
18 import org.apache.tools.ant.BuildFileTest;
19
20 /**
21 * Testcase for <if>.
22 */
23 public class IfTaskTest extends BuildFileTest {
24
25 public IfTaskTest(String name) {
26 super(name);
27 }
28
29 public void setUp() {
30 configureProject("test/resources/logic/if.xml");
31 }
32
33 public void testNoCondition() {
34 expectSpecificBuildException("noCondition", "no condition",
35 "You must nest a condition into <if>");
36 }
37
38 public void testTwoConditions() {
39 expectSpecificBuildException("twoConditions", "two conditions",
40 "You must not nest more than one "
41 + "condition into <if>");
42 }
43
44 public void testNothingToDo() {
45 expectLog("nothingToDo", "");
46 }
47
48 public void testTwoThens() {
49 expectSpecificBuildException("twoThens", "two <then>s",
50 "You must not nest more than one "
51 + "<then> into <if>");
52 }
53
54 public void testTwoElses() {
55 expectSpecificBuildException("twoElses", "two <else>s",
56 "You must not nest more than one "
57 + "<else> into <if>");
58 }
59
60 public void testNormalOperation() {
61 executeTarget("normalOperation");
62 assertTrue(getLog().indexOf("In then") > -1);
63 assertTrue(getLog().indexOf("some value") > -1);
64 assertEquals(-1, getLog().indexOf("${inner}"));
65 assertEquals(-1, getLog().indexOf("In else"));
66 }
67
68 public void testNormalOperation2() {
69 executeTarget("normalOperation2");
70 assertTrue(getLog().indexOf("In else") > -1);
71 assertEquals(-1, getLog().indexOf("In then"));
72 }
73
74 public void testNoConditionInElseif() {
75 expectSpecificBuildException("noConditionInElseif", "no condition",
76 "You must nest a condition into <elseif>");
77 }
78
79 public void testTwoConditionInElseif() {
80 expectSpecificBuildException("twoConditionsInElseif", "two conditions",
81 "You must not nest more than one "
82 + "condition into <elseif>");
83 }
84
85 public void testNormalOperationElseif() {
86 executeTarget("normalOperationElseif");
87 assertTrue(getLog().indexOf("In elseif") > -1);
88 assertEquals(-1, getLog().indexOf("In then"));
89 assertEquals(-1, getLog().indexOf("In else-branch"));
90 }
91
92 public void testNormalOperationElseif2() {
93 executeTarget("normalOperationElseif2");
94 assertTrue(getLog().indexOf("In else-branch") > -1);
95 assertEquals(-1, getLog().indexOf("In then"));
96 assertEquals(-1, getLog().indexOf("In elseif"));
97 }
98
99 }