/* XBN Java: Generically useful, non-GUI Java code. http://sourceforge.net/projects/xbnjava Copyright (C) 1997-2003, Jeff Epstein All rights reserved. Modifications: No Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * If modifications are made to source code then this license should indicate that fact in the "Modifications" section above. * Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [NOTE: This license contains NO advertising clause.] */ package xbn.util; import junit.framework.TestCase; /**

A JUnit TestCase with some XBN-specificizationizisims.

Source code:  XBNTestCase.java

JACTAF

Just A Call To Another Function, meaning that there should only be minimal tests for this function (the one that calls the other one).

@version 0.9b @author Jeff Epstein, http://sourceforge.net/projects/xbnjava. **/ public class XBNTestCase extends TestCase { private static final String sES = ""; private static int iGood = 0; private static int iBad = 0; private static int iGoodBeforeThisTC = 0; private static int iBadBeforeThisTC = 0; /**

Create an XBNTestCase.

**/ public XBNTestCase(String s_name) { super(s_name); } /**

Print a line of output to standard out. For the purposes of debugging.

Equal to System.out.println(s_message)

@param s_message The message to output. **/ protected final static void sopl(String s_message) { System.out.println(s_message); } /**

Print a line of output to standard out. For the purposes of debugging.

Equal to System.out.print(s_message)

@param s_message The message to output. **/ protected final static void sop(String s_message) { System.out.print(s_message); } public static void xassertTrue(boolean b_condition) { printStatusMarker(b_condition); xassertTrue(sES, b_condition); } public static void xassertFalse(boolean b_condition) { printStatusMarker(!b_condition); xassertFalse(sES, b_condition); } public static void xassertNotNull(java.lang.Object o_bject) { printStatusMarker(o_bject != null); xassertNotNull(sES, o_bject); } public static void xassertNotSame(java.lang.Object o_expected, java.lang.Object o_actual) { printStatusMarker(o_expected != o_actual); xassertNotSame(sES, o_expected, o_actual); } public static void xassertNull(java.lang.Object o_bject) { printStatusMarker(o_bject == null); xassertNull(sES, o_bject); } public static void xassertSame(java.lang.Object o_expected, java.lang.Object o_actual) { printStatusMarker(o_expected == o_actual); xassertSame(sES, o_expected, o_actual); } public static void xassertEquals(boolean b_expected, boolean b_actual) { printStatusMarker(b_expected == b_actual); xassertEquals(sES, b_expected, b_actual); } public static void xassertEquals(byte y_expected, byte y_actual) { printStatusMarker(y_expected == y_actual); xassertEquals(sES, y_expected, y_actual); } public static void xassertEquals(char c_expected, char c_actual) { printStatusMarker(c_expected == c_actual); xassertEquals(sES, c_expected, c_actual); } public static void xassertEquals(double d_expected, double d_actual, double d_delta) { xassertEquals(sES, d_expected, d_actual, d_delta); } public static void xassertEquals(float f_expected, float f_actual, float f_delta) { xassertEquals(sES, f_expected, f_actual, f_delta); } public static void xassertEquals(int i_expected, int i_actual) { printStatusMarker(i_expected == i_actual); xassertEquals(sES, i_expected, i_actual); } public static void xassertEquals(long l_expected, long l_actual) { printStatusMarker(l_expected == l_actual); xassertEquals(sES, l_expected, l_actual); } public static void xassertEquals(java.lang.Object o_expected, java.lang.Object o_actual) { xassertEquals(sES, o_expected, o_actual); } public static void xassertEquals(short r_expected, short r_actual) { xassertEquals(sES, r_expected, r_actual); } public static void xfail() { printStatusMarker(false); fail(); } public static void xassertTrue() { xassertTrue(":' )", true); } public static void xassertEquals(String s_expected, String s_actual) { printStatusMarker(areStringsEqual(s_expected, s_actual)); assertEquals("xpct='" + s_expected + "', actl='" + s_actual + "'", s_expected, s_actual); } public static void xassertEquals(String s_message, boolean b_expected, boolean b_actual) { printStatusMarker(b_expected == b_actual); if(b_expected != b_actual) { s_message = "xpctd=" + b_expected + ", actl=" + b_actual + ", " + s_message; } assertEquals(s_message, b_expected, b_actual); } public static void xassertEquals(String s_message, byte y_expected, byte y_actual) { printStatusMarker(y_expected == y_actual); if(y_expected != y_actual) { s_message = "xpctd=" + y_expected + ", actl=" + y_actual + ", " + s_message; } assertEquals(s_message, y_expected, y_actual); } public static void xassertEquals(String s_message, char c_expected, char c_actual) { printStatusMarker(c_expected == c_actual); //super func already appends "xpctd=XXX, actl=YYY" assertEquals(s_message, c_expected, c_actual); } public static void xassertEquals(String s_message, double d_expected, double d_actual, double d_delta) { printStatusMarker(d_expected == d_actual); //super func already appends "xpctd=XXX, actl=YYY" assertEquals(s_message, d_expected, d_actual, d_delta); } public static void xassertEquals(String s_message, float f_expected, float f_actual, float f_delta) { printStatusMarker(f_expected == f_actual); //super func already appends "xpctd=XXX, actl=YYY" assertEquals(s_message, f_expected, f_actual, f_delta); } public static void xassertEquals(String s_message, int i_expected, int i_actual) { printStatusMarker(i_expected == i_actual); //super func already appends "xpctd=XXX, actl=YYY" assertEquals(s_message, i_expected, i_actual); } public static void xassertEquals(String s_message, long l_expected, long l_actual) { printStatusMarker(l_expected == l_actual); //super func already appends "xpctd=XXX, actl=YYY" assertEquals(s_message, l_expected, l_actual); } public static void xassertEquals(String s_message, java.lang.Object o_expected, java.lang.Object o_actual) { printStatusMarker(o_expected == o_actual); //super func already appends "xpctd=XXX, actl=YYY" assertEquals(s_message, o_expected, o_actual); } public static void xassertEquals(String s_message, short r_expected, short r_actual) { printStatusMarker(r_expected == r_actual); //super func already appends "xpctd=XXX, actl=YYY" assertEquals(s_message, r_expected, r_actual); } public static void xassertEquals(String s_message, String s_expected, String s_actual) { printStatusMarker(areStringsEqual(s_expected, s_actual)); if(areStringsEqual(s_expected, s_actual)) { s_message = "xpctd='" + s_expected + "', actl='" + s_actual + "', " + s_message; } assertEquals(s_message, s_expected, s_actual); } public static void xassertFalse(String s_message, boolean b_condition) { printStatusMarker(!b_condition); //super func already appends "xpctd=XXX, actl=YYY" assertFalse(s_message, b_condition); } public static void xassertNotNull(String s_message, java.lang.Object o_bject) { printStatusMarker(o_bject != null); //super func already appends "xpctd=XXX, actl=YYY" assertNotNull(s_message, o_bject); } public static void xassertNotSame(String s_message, java.lang.Object o_expected, java.lang.Object o_actual) { printStatusMarker(o_expected != o_actual); if(o_expected == o_actual) { s_message = "xpctd=NOT [" + o_expected + "], actl=[" + o_actual + "], " + s_message; } assertNotSame(s_message, o_expected, o_actual); } public static void xassertNull(String s_message, java.lang.Object o_bject) { printStatusMarker(o_bject == null); if(o_bject != null) { s_message = "xpctd=null, actl=['" + o_bject + "'], " + s_message; } assertNull(s_message, o_bject); } public static void xassertSame(String s_message, java.lang.Object o_expected, java.lang.Object o_actual) { printStatusMarker(o_expected == o_actual); if(o_expected != o_actual) { s_message = "xpctd=[" + o_expected + "], actl=[" + o_actual + "], " + s_message; } assertSame(s_message, o_expected, o_actual); } public static void xassertTrue(String s_message, boolean b_condition) { printStatusMarker(b_condition); //super func already appends "xpctd=XXX, actl=YYY" assertTrue(s_message, b_condition); } public static void xfail(String s_message) { printStatusMarker(false); fail(s_message); } public static final int getGoodCount() { return iGood; } public static final int getBadCount() { return iBad; } public static final void printSummary() { System.out.println("Total sub tests: GOOD=" + getGoodCount() + ", BAD=" + getBadCount() + ", TOTAL=" + (getGoodCount() + getBadCount())); } protected void setUp() throws Exception { iGoodBeforeThisTC = getGoodCount(); iBadBeforeThisTC = getBadCount(); System.out.print(this.getClass().getName() + "." + getName() + "\n["); super.setUp(); } protected void tearDown() throws Exception { System.out.println("]\n\tThis good/bad: " + (getGoodCount() - iGoodBeforeThisTC) + "/" + (getBadCount() - iBadBeforeThisTC) + "\n\tTotal good/bad: " + getGoodCount() + "/" + getBadCount() + sES); super.tearDown(); } private static boolean areStringsEqual(String s_expected, String s_actual) { if(s_expected == null && s_actual == null) { return true; } else if((s_expected == null && s_actual != null) || (s_expected != null && s_actual == null)) { return false; } else { return s_expected.equals(s_actual); } } private static void printStatusMarker(boolean b_successOrFailure) { if(b_successOrFailure) { iGood++; System.out.print("."); } else { iBad++; System.out.print(" -- FAILURE -- "); } } }