01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.tools.ant.types;
19:
20: import org.apache.tools.ant.BuildFileTest;
21:
22: /**
23: * test assertion handling
24: */
25: public class AssertionsTest extends BuildFileTest {
26:
27: public AssertionsTest(String name) {
28: super (name);
29: }
30:
31: protected void setUp() throws Exception {
32: configureProject("src/etc/testcases/types/assertions.xml");
33: }
34:
35: protected void tearDown() throws Exception {
36: executeTarget("teardown");
37: }
38:
39: /**
40: * runs a test and expects an assertion thrown in forked code
41: * @param target
42: */
43: protected void expectAssertion(String target) {
44: expectBuildExceptionContaining(target,
45: "assertion not thrown in " + target, "Java returned: 1");
46: }
47:
48: public void testClassname() {
49: expectAssertion("test-classname");
50: }
51:
52: public void testPackage() {
53: expectAssertion("test-package");
54: }
55:
56: public void testEmptyAssertions() {
57: executeTarget("test-empty-assertions");
58: }
59:
60: public void testDisable() {
61: executeTarget("test-disable");
62: }
63:
64: public void testOverride() {
65: expectAssertion("test-override");
66: }
67:
68: public void testOverride2() {
69: executeTarget("test-override2");
70: }
71:
72: public void testReferences() {
73: expectAssertion("test-references");
74: }
75:
76: public void testMultipleAssertions() {
77: expectBuildExceptionContaining("test-multiple-assertions",
78: "multiple assertions rejected",
79: "Only one assertion declaration is allowed");
80: }
81:
82: public void testReferenceAbuse() {
83: expectBuildExceptionContaining("test-reference-abuse",
84: "reference abuse rejected", "You must not specify");
85: }
86:
87: public void testNofork() {
88: if (AssertionsTest.class.desiredAssertionStatus()) {
89: return; // ran Ant tests with -ea and this would fail spuriously
90: }
91: expectLogContaining("test-nofork",
92: "Assertion statements are currently ignored in non-forked mode");
93: }
94:
95: public void testJunit() {
96: executeTarget("test-junit");
97: }
98: }
|