/* 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_junit; import xbn.util.XBNTestCase; import xbn.XBNObject; import xbn.AssertException; import junit.framework.Test; import junit.framework.TestSuite; import junit.textui.TestRunner; public class JUTXBNObject extends XBNTestCase { //ENTIRE (and obvious to understand from the name) strings used four or more times private static final String sVAR_NAME = "varname"; private static final String sFUNC_NAME = "funcname"; private static final String sNOT_NULL = "not null"; private Dummy dummy = null; public JUTXBNObject(String s_name) { super(s_name); } public void test_throwAX() { try { dummy.pubThrowAX("hello"); xfail("pubThrowAX('hello') should throw an ax"); } catch(AssertException ax) { xassertEquals(ax.getMessage(), XBNObject.getXMsgPrefix() + dummy.getClass().getName() + ".hello"); } try { dummy.pubThrowAX(null); xfail("pubThrowAX(null) should throw an ax"); } catch(AssertException ax) { xassertEquals(ax.getMessage(), XBNObject.getXMsgPrefix() + dummy.getClass().getName() + ".null"); } try { dummy.pubThrowAX(""); xfail("pubThrowAX('') should throw an ax"); } catch(AssertException ax) { xassertEquals(ax.getMessage(), XBNObject.getXMsgPrefix() + dummy.getClass().getName() + "."); } } public void test_throwAXSpoof() { try { dummy.pubThrowAXSpoof("hello"); xfail("pubThrowAXSpoof('hello') should throw an ax"); } catch(AssertException ax) { xassertEquals(ax.getMessage(), XBNObject.getXMsgPrefix() + "hello"); } } public void test_throwAXIfNull() { try { dummy.pubThrowAXIfNull(null, sVAR_NAME, sFUNC_NAME); xfail("pubThrowAXIfNull(null, '" + sVAR_NAME + "', '" + sFUNC_NAME + "') should throw an ax"); } catch(AssertException ax) { xassertEquals(ax.getMessage(), XBNObject.getXMsgPrefix() + dummy.getClass().getName() + ".funcname: varname is null."); } try { dummy.pubThrowAXIfNull(sNOT_NULL, sVAR_NAME, sFUNC_NAME); xassertTrue(); } catch(AssertException ax) { xfail("pubThrowAXIfNull('" + sNOT_NULL + "', '" + sVAR_NAME + "', '" + sFUNC_NAME + "') should not throw an ax: " + ax.toString()); } try { //Just curious. Should be ignored. dummy.pubThrowAXIfNull(sNOT_NULL, null, null); xassertTrue(); } catch(AssertException ax) { xfail("pubThrowAXIfNull('" + sNOT_NULL + "', 'null', 'null') should not throw an ax: " + ax.toString()); } } public void test_throwAXIfBadStr() { try { dummy.pubThrowAXIfBadStr(null, sVAR_NAME, sFUNC_NAME); xfail("pubThrowAXIfBadStr(null, '" + sVAR_NAME + "', '" + sFUNC_NAME + "') should throw an ax"); } catch(AssertException ax) { xassertEquals(ax.getMessage(), XBNObject.getXMsgPrefix() + dummy.getClass().getName() + ".funcname: varname is null."); } try { dummy.pubThrowAXIfBadStr("", sVAR_NAME, sFUNC_NAME); xfail("pubThrowAXIfBadStr('', '" + sVAR_NAME + "', '" + sFUNC_NAME + "') should throw an ax"); } catch(AssertException ax) { xassertEquals(ax.getMessage(), XBNObject.getXMsgPrefix() + dummy.getClass().getName() + ".funcname: varname is zero characters in length."); } try { dummy.pubThrowAXIfBadStr(sNOT_NULL, sVAR_NAME, sFUNC_NAME); xassertTrue(); } catch(AssertException ax) { xfail("pubThrowAXIfBadStr('" + sNOT_NULL + "', '" + sVAR_NAME + "', '" + sFUNC_NAME + "') should not throw an ax: " + ax.toString()); } try { //Just curious. Should be ignored. dummy.pubThrowAXIfBadStr(sNOT_NULL, null, null); xassertTrue(); } catch(AssertException ax) { xfail("pubThrowAXIfBadStr('" + sNOT_NULL + "', 'null', 'null') should not throw an ax: " + ax.toString()); } } public void setUp() throws Exception { super.setUp(); dummy = new Dummy(); } public void tearDown() throws Exception { super.tearDown(); dummy = null; } public static Test suite() { TestSuite ts = new TestSuite(JUTXBNObject.class); return ts; } public static void main(String[] as_cmdLineParams) { TestRunner.run(suite()); printSummary(); } } class Dummy extends XBNObject { public Dummy() { } public void pubThrowAX(String s_tr) { throwAX(s_tr); } public void pubThrowAXSpoof(String s_tr) { throwAXSpoof(s_tr); } public void pubThrowAXIfNull(Object o_bject, String s_2, String s_3) { throwAXIfNull(o_bject, s_2, s_3); } public void pubThrowAXIfBadStr(String s_tr, String s_2, String s_3) { throwAXIfBadStr(s_tr, s_2, s_3); } }