Datasheet
String result = “PASSED”;
try {
m.invoke(o);
} catch(Exception ex) {
System.out.println(“Exception: “ + ex + “\n” + ex.getCause());
result = “FAILED”;
}
return(result);
}
public static void main(String [] args) {
if(args.length == 0) {
System.out.println(“Must specify class name (without an extension)”);
} else {
executeTests(args[0]);
}
}
}
Executing the preceding class on the StringUtility class provides the following output:
C:\>java TestFramework StringUtility
testConcat
----------------
Result: PASSED
testSubstring
----------------
Result: PASSED
The executeTests method obtains a handle to the TestParameters annotation from the class
and then invokes each method from the
testMethods() element of the annotation. This is a simple
implementation of the testing framework and can be extended to support the other elements of the
TestParameters annotation, such as writing results to a database instead of the screen. This is a practi-
cal example of using metadata — adding declarative information to Java source that can then be utilized
by external programs and/or doclets for generating documentation.
Important Java Utility Libraries
This section describes several key utility libraries in Java. These libraries are as follows:
❑ Java logging: A powerful logging system that is vital for providing meaningful error messages
to end users, developers, and people working in the field.
❑ Regular expressions: A powerful “miniature language” used to process strings in a variety of
ways, such as searching for substrings that match a particular pattern.
❑ Java preferences: A way to store and retrieve both system- and user-defined configuration
options.
34
Part I: Thinking Like a Java Developer
05_777106 ch01.qxp 11/28/06 10:43 PM Page 34