001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.junit;
043:
044: import junit.extensions.TestDecorator;
045: import java.io.*;
046: import org.netbeans.junit.diff.*;
047:
048: /**
049: * A Decorator for Tests. Use TestDecorator as the base class
050: * for defining new test decorators. Test decorator subclasses
051: * can be introduced to add behaviour before or after a test
052: * is run.
053: *
054: */
055:
056: import junit.framework.*;
057:
058: /** NetBeans extension to JUnit's TestDecorator class. Tests created
059: * with the help of this class can use method assertFile and can be
060: * filtered.
061: */
062: public class NbTestDecorator extends TestDecorator implements NbTest {
063:
064: /**
065: */
066: public NbTestDecorator(Test test) {
067: super (test);
068: }
069:
070: /**
071: * Sets active filter.
072: * @param filter Filter to be set as active for current test, null will reset filtering.
073: */
074: public void setFilter(Filter filter) {
075: //System.out.println("NbTestDecorator.setFilter()");
076: if (fTest instanceof NbTest) {
077: //System.out.println("NbTestDecorator.setFilter(): test="+fTest+" filter="+filter);
078: ((NbTest) fTest).setFilter(filter);
079: }
080: }
081:
082: /**
083: * Returns expected fail message.
084: * @return expected fail message if it's expected this test fail, null otherwise.
085: */
086: public String getExpectedFail() {
087: if (fTest instanceof NbTest) {
088: return ((NbTest) fTest).getExpectedFail();
089: } else {
090: return null;
091: }
092: }
093:
094: /**
095: * Checks if a test isn't filtered out by the active filter.
096: */
097: public boolean canRun() {
098: //System.out.println("NbTestDecorator.canRun()");
099: if (fTest instanceof NbTest) {
100: //System.out.println("fTest is NbTest");
101: return ((NbTest) fTest).canRun();
102: } else {
103: // standard JUnit tests can always run
104: return true;
105: }
106: }
107:
108: // additional asserts !!!!
109: // these methods only wraps functionality from asserts from NbTestCase,
110: // because java does not have multiinheritance :-)
111: // please see more documentatino in this file.
112:
113: /** for description, see this method in NbTestCase class
114: */
115: static public void assertFile(String message, String test,
116: String pass, String diff, Diff externalDiff) {
117: NbTestCase.assertFile(message, test, pass, diff, externalDiff);
118: }
119:
120: /** for description, see this method in NbTestCase class
121: */
122: static public void assertFile(String test, String pass,
123: String diff, Diff externalDiff) {
124: NbTestCase.assertFile(test, pass, diff, externalDiff);
125: }
126:
127: /** for description, see this method in NbTestCase class
128: */
129: static public void assertFile(String message, String test,
130: String pass, String diff) {
131: NbTestCase.assertFile(message, test, pass, diff);
132: }
133:
134: /** for description, see this method in NbTestCase class
135: */
136: static public void assertFile(String test, String pass, String diff) {
137: NbTestCase.assertFile(test, pass, diff);
138: }
139:
140: /** for description, see this method in NbTestCase class
141: */
142: static public void assertFile(String test, String pass) {
143: NbTestCase.assertFile(test, pass);
144: }
145:
146: /** for description, see this method in NbTestCase class
147: */
148: static public void assertFile(String message, File test, File pass,
149: File diff, Diff externalDiff) {
150: NbTestCase.assertFile(message, test, pass, diff, externalDiff);
151: }
152:
153: /** for description, see this method in NbTestCase class
154: */
155: static public void assertFile(File test, File pass, File diff,
156: Diff externalDiff) {
157: NbTestCase.assertFile(test, pass, diff, externalDiff);
158: }
159:
160: /** for description, see this method in NbTestCase class
161: */
162: static public void assertFile(String message, File test, File pass,
163: File diff) {
164: NbTestCase.assertFile(message, test, pass, diff);
165: }
166:
167: /** for description, see this method in NbTestCase class
168: */
169: static public void assertFile(File test, File pass, File diff) {
170: NbTestCase.assertFile(test, pass, diff);
171: }
172:
173: /** for description, see this method in NbTestCase class
174: */
175: static public void assertFile(File test, File pass) {
176: NbTestCase.assertFile(test, pass);
177: }
178:
179: }
|