/** * If the given object is null, and the debugging functionality is enabled, this method throws an * <code>AssertionFailure</code> in order to signal that an internal program post- or pre-condition failed. * <p/> * <p> Use this method whenever a valid state must be ensured within your sourcecode in order to safely continue the * program. * <p/> * <p> For example, the method can be used to ensure valid arguments passed to private and protected methods. * * @param object the object to test for non-null condition * * @throws AssertionFailure if <code>object</code> is null and the debugging functionality is enabled */ public static void assertNotNull(Object object) throws AssertionFailure { if (isEnabled()) { if (object == null) { handleAssertionFailed(UtilConstants.MSG_OBJECT_NULL); } } }
/** * If the <code>condition</code> is NOT true, and the debugging functionality is enabled, this method throws an * <code>AssertionFailure</code> in order to signal that an internal program post- or pre-condition failed. * <p/> * <p> Use this method whenever a valid state must be ensured within your sourcecode in order to safely continue the * program. * <p/> * <p> For example, the method can be used to ensure valid arguments passed to private and protected methods. * * @param condition the assert condition * * @throws AssertionFailure if <code>condition</code> evaluates to false and the debugging functionality is enabled */ public static void assertTrue(boolean condition) throws AssertionFailure { if (isEnabled()) { if (!condition) { handleAssertionFailed(null); } } }
/** * If the given String is null or empty, and the debugging functionality is enabled, this method throws an * <code>AssertionFailure</code> in order to signal that an internal program post- or pre-condition failed. * <p/> * <p> Use this method whenever a valid state must be ensured within your sourcecode in order to safely continue the * program. * <p/> * <p> For example, the method can be used to ensure valid arguments passed to private and protected methods. * * @param string the String to test for non-null and not empty condition * * @throws AssertionFailure if <code>String</code> is null or empty and the debugging functionality is enabled */ public static void assertNotNullOrEmpty(String string) throws AssertionFailure { if (isEnabled()) { if (string == null || string.length() < 1) { handleAssertionFailed(UtilConstants.MSG_STRING_NULL_OR_EMPTY); } } }
/** * If the <code>condition</code> is NOT true, and the debugging functionality is enabled, this method throws an * <code>AssertionFailure</code> in order to signal that an internal program post- or pre-condition failed. The * <code>AssertionFailure</code> will be created with the given error message string. * <p/> * <p> Use this method whenever a valid state must be ensured within your sourcecode in order to safely continue the * program. * <p/> * <p> For example, the method can be used to ensure valid arguments passed to private and protected methods. * * @param condition the assert condition * @param message an error message * * @throws AssertionFailure if <code>condition</code> evaluates to false and the debugging functionality is enabled */ public static void assertTrue(boolean condition, String message) throws AssertionFailure { if (isEnabled()) { if (!condition) { handleAssertionFailed(message); } } }