@(#)GenericJavaCodeStd.htm 1.3 - 07/27/05
The Generic UWF Maintenance Process (GUMP++) 1994-2001 The University
of West Florida. All rights reserved.
Permission is granted to reproduce and adapt this document provided
credit is given to the University of West Florida. This documentation is
provided "as is" and no warranty of fitness for any particular purpose
is made or implied.
This document is the Java Coding Standard document for the generic maintenance process architecture for the University of West Florida. It describes which Java Code Conventions should be used for the project. Coders should follow these conventions to the maximum extent possible in order to ensure a uniform appearance and improve maintainability.
Some classes, such as GUI classes, can't be unit tested automatically because they require user input or user examination of results.
Note specifically that assertions are intended for preconditions, post conditions and class invariants, but not for argument checking of public methods. Argument checks of public methods should instead throw an unchecked exception such as IllegalArgumentException.
When running tests, it is important to make sure that assertions are enabled. Otherwise these self checks will not be useful. To enable assertions the "java ..." command must be "java -ea ...". Use this form when running the command by hand or add the "-ea" parameter to your programming environment's run command. (In Eclipse 3.0 for example, choose "Run ..." from the Run menu, and create a configuration that has this parameter.)
To guarantee that assertions are enabled when running the unit test main() of each class, add a self check as in the following example main():
public static void main( String[] args ) {
// Error if unit tests are run without assertions enabled
boolean assertsEnabled = false;
assert assertsEnabled = true; // intentional side effect
if (!assertsEnabled)
throw new RuntimeException("Assertions must be enabled for unit tests");
//
// code to run the classTest() method here
// ...
System.exit(0);
}
January 2002
Lily Rakar
February 2002
Ryan Ingram, Lily Rakar
July 2005 - added material about assertions and unit test example.
Norman Wilde