001: /* ====================================================================
002: The Jicarilla Software License
003:
004: Copyright (c) 2003 Leo Simons.
005: All rights reserved.
006:
007: Permission is hereby granted, free of charge, to any person obtaining
008: a copy of this software and associated documentation files (the
009: "Software"), to deal in the Software without restriction, including
010: without limitation the rights to use, copy, modify, merge, publish,
011: distribute, sublicense, and/or sell copies of the Software, and to
012: permit persons to whom the Software is furnished to do so, subject to
013: the following conditions:
014:
015: The above copyright notice and this permission notice shall be
016: included in all copies or substantial portions of the Software.
017:
018: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
020: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
021: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
022: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
023: TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
024: SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
025: ==================================================================== */
026: package org.jicarilla.lang;
027:
028: /**
029: * Basic wrapper around the <code>assert</code> keyword allowing pre-jdk-1.4
030: * applications to use them (by providing a different implementation for this
031: * class). Insipired (of course!) by the Assert class in <a
032: * href="http://www.junit.org">junit</a>.
033: *
034: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
035: * @version $Id: Assert.java,v 1.1 2004/03/23 13:37:56 lsimons Exp $
036: */
037: public final class Assert {
038: /**
039: * Makes sure an object reference does not contain null.
040: *
041: * @param object an object reference which should not contain null
042: *
043: * @throws AssertionError if the object reference contains null
044: */
045: public static void assertNotNull(final Object object) {
046: assertNotNull("argument may not be null", object);
047: }
048:
049: /**
050: * Makes sure an object reference does not contain null.
051: *
052: * @param message the message to use for the AssertionError if it is
053: * thrown
054: * @param object an object reference which should not contain null
055: *
056: * @throws AssertionError if the object reference contains null
057: */
058: public static void assertNotNull(final String message,
059: final Object object) {
060: doAssert(object != null, message);
061: //assert (object != null) : message;
062: }
063:
064: /**
065: * Makes sure a certain boolean value is true.
066: *
067: * @param expression the boolean value to test
068: *
069: * @throws AssertionError if the boolean value is false
070: */
071: public static void assertTrue(final boolean expression) {
072: assertTrue("condition must be true", expression);
073: }
074:
075: /**
076: * Makes sure a certain boolan value is true.
077: *
078: * @param message the message to use for the AssertionError if it is
079: * thrown
080: * @param expression the boolean value to test
081: *
082: * @throws AssertionError if the boolean value is false
083: */
084: public static void assertTrue(final String message,
085: final boolean expression) {
086: doAssert(expression, message);
087: //assert expression : message;
088: }
089:
090: /**
091: * Makes sure a certain boolean value is false.
092: *
093: * @param expression the boolean value to test
094: *
095: * @throws AssertionError if the boolean value is true
096: */
097: public static void assertFalse(final boolean expression) {
098: assertFalse("condition must be false", expression);
099: }
100:
101: /**
102: * Makes sure a certain boolan value is falsse.
103: *
104: * @param message the message to use for the AssertionError if it is
105: * thrown
106: * @param expression the boolean value to test
107: *
108: * @throws AssertionError if the boolean value is true
109: */
110: public static void assertFalse(final String message,
111: final boolean expression) {
112: assertTrue(message, !expression);
113: }
114:
115: /**
116: * Does the 'actual' assertion. Common helper method for the rest of the
117: * methods in this class.
118: *
119: * @param expression the boolean value to test
120: * @param msg the message to use for the AssertionError if it is thrown
121: *
122: * @throws AssertionError if the boolean value is false
123: */
124: protected static void doAssert(final boolean expression,
125: final String msg) {
126: if (!expression) {
127: throw new AssertionError(msg);
128: }
129: }
130: }
|