com.sdm.quasar.client.core.common.util
Class Assertion

java.lang.Object
  extended bycom.sdm.quasar.client.core.common.util.Assertion

public final class Assertion
extends java.lang.Object

The class Assertion may be used to increase the software quality by testing for pre- and postconditions in method calls. An assertion consists of an atomic test for a certain condition that may fail.

If an assertion fails, the exception AssertException is thrown.

Example:


    
 Assertion.check(arg1 > 0 && arg1 <= 100, "range must be between 0 and 100");
 
 


Method Summary
static void check(boolean condition, java.lang.String message)
          This assertion method fails, when the given condition argument is false.
static void checkInterval(int lowerBound, int value, int upperBound, java.lang.String message)
          Checks, if the given value lies in the specified interval.
static void checkNotNull(java.lang.Object object, java.lang.String description)
          This assertion method fails, when the given object is null.
static void checkNull(java.lang.Object object, java.lang.String description)
          This assertion method fails, when the given object is non-null.
static void fail(java.lang.String message)
          This assertion method always fails.
static void fail(java.lang.String message, java.lang.Throwable cause)
          This assertion method always fails.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

check

public static void check(boolean condition,
                         java.lang.String message)
This assertion method fails, when the given condition argument is false.

Parameters:
condition - the condition that must be true
message - the message, that describes the assertion

checkNotNull

public static void checkNotNull(java.lang.Object object,
                                java.lang.String description)
This assertion method fails, when the given object is null.

Parameters:
object - the object, that must be non-null
description - the description of the value to be checked
See Also:
checkNull(java.lang.Object, java.lang.String)

checkNull

public static void checkNull(java.lang.Object object,
                             java.lang.String description)
This assertion method fails, when the given object is non-null.

Parameters:
object - the object, that must be null
description - the description of the value to be checked
See Also:
checkNotNull(java.lang.Object, java.lang.String)

checkInterval

public static void checkInterval(int lowerBound,
                                 int value,
                                 int upperBound,
                                 java.lang.String message)
Checks, if the given value lies in the specified interval. Throws an assertion, if the value is less than the lower bound or if the value is equals or more than the upper bound.

Parameters:
lowerBound - the lower bound
value - the value to check
upperBound - the upper bound
message - the message for the assertion

fail

public static void fail(java.lang.String message)
This assertion method always fails.

Parameters:
message - the message, that describes the reason for the failure

fail

public static void fail(java.lang.String message,
                        java.lang.Throwable cause)
This assertion method always fails.

Parameters:
message - the message that describes the reason for the failure
cause - the cause for the failure