com.revusky.niggle.util
Class Assert
java.lang.Object
|
+--com.revusky.niggle.util.Assert
- public class Assert
- extends java.lang.Object
A helper class that gives us functionality equivalent to C's stdlib
assert() macro. Note that assertions should be guarded within code
that is conditionally compiled. Try to keep to Eiffel's assertion
system. Use static variables defined in a globally used interface
class to control the inclusion/exclusion of the blocks of code that
contain our assertions. Fie on Joy & Gosling for not having built
this into the language.
- Author:
- Paul Murphy murphy@niggle.com
Method Summary |
static void |
assert(boolean b)
|
static void |
assert(boolean b,
java.lang.String msg)
The most basic assertion test - a boolean test with a message explaining it. |
static void |
canWriteToFile(java.lang.String filename)
convenient method that throws an IOException
if the file cannot be written to. |
static void |
hasContent(java.lang.String s)
Special assertion for Strings. |
static void |
rethrow(java.lang.Throwable t)
convenience method to rethrow an exception
as a RuntimeException. t is an instanceof
RuntimeException, it just rethrows, otherwise,
it throws a wrapped AssertionFailedException |
static void |
setFatal(boolean b)
Set fatal to true to cause system exit (JR) |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Assert
public Assert()
setFatal
public static void setFatal(boolean b)
- Set fatal to true to cause system exit (JR)
assert
public static void assert(boolean b,
java.lang.String msg)
- The most basic assertion test - a boolean test with a message explaining it.
assert
public static void assert(boolean b)
hasContent
public static void hasContent(java.lang.String s)
- Special assertion for Strings. Checks for a string
being non-null AND non-zero length. (JR)
rethrow
public static void rethrow(java.lang.Throwable t)
- convenience method to rethrow an exception
as a RuntimeException. t is an instanceof
RuntimeException, it just rethrows, otherwise,
it throws a wrapped AssertionFailedException
canWriteToFile
public static void canWriteToFile(java.lang.String filename)
throws java.io.IOException
- convenient method that throws an IOException
if the file cannot be written to. To get through this method,
either (a) the file exists and we can write to it
or (b) the file does not exist, but the directory exists
and can be written to, i.e. we can create the file there.
And otherwise, we get an exception.