Some reader favorites:
EJB fundamentals and session beans
Create a scrollable virtual desktop in Swing
Web services test code generator
Klaus Berg has recently released a test-code generator for JUnit-based Web service clients. If you're developing Web services
using Axis2 and XMLBeans this wizard could turn your JUnit test client coding into a powerful code generation process. It
also has uses for those using GUI-based testing tools like soapUI.
| Memory Analysis in Eclipse |
| Enterprise AJAX - Transcend the Hype |
Consequently, this month's Java Toolbox takes the name of the column literally and presents the set of generic tools we'll need to build the calculator -- little tools of general utility that should be of use for more than the current application. Specifically, I'll cover the following:
Assert
|
An implementation of an "assertion" that lets you implement pre- and postconditions. |
|---|---|
Tester
|
A class that aids in putting together automated unit tests. |
Bit_bucket
|
The Java equivalent of /dev/null, it throws away characters. |
Std
|
A "singleton" wrapper around standard input and output that makes it easy to access these two streams. |
Log
|
A convenient class for logging diagnostic messages. |
Align
|
A utility containing various methods for aligning text. |
Scrollable_text_area
|
A JTextArea that has scroll bars around it. |
Most of those classes are unrelated to one another, and none of them is significant enough to merit a article devoted exclusively to it, so lumping them all together in one place seems sensible. We've taken a quick look at a few of the tools in the past, but a review should prove helpful. Now, on to the tools.
TEXTBOX: TEXTBOX_HEAD: Build user interfaces for object-oriented systems: Read the whole series!
:END_TEXTBOX
Bertrand Meyer, the author of the Eiffel language, came up with the notion of pre- and postconditions, commonly called assertions. Eiffel, described in Object-Oriented Software Construction (see Resources) supports those concepts directly within the syntax of the language. Java, unfortunately, provides no such support.
The basic idea of a precondition or postcondition is that every method expects the world (the object that it's working on, the global state of the program, the arguments to the method, and so on) to be in a particular state when the method is called, and that every method will leave the world in a particular state. An assertion is a body of code that guarantees that those conditions hold and typically terminates the program with an exception toss if they do not. Assertions are typically implemented as debug-time tests and removed from the code entirely when the code goes into production. (The removal can be risky since you are modifying tested code, but on the other hand, the assertions can slow down the execution of a program noticeably.)