: eval 'exec perl -w -S `echo $0 | sed "s/.*\///" ` ${1+"$@"}' if 0; @a=@ARGV; @flags=grep(/^-/,@a); @other=(); @other=grep(!/^-/,@a); if ( grep( /^-h(elp)?$/,@flags) || scalar(@other) != 1) { $scriptName = $0; $scriptName =~ s%^.*/%%; print <<"END"; Usage: $scriptName [-h -help] com.company.project.package.ClassName Print out a prototype of a new java class implementing junit.framework.TestCase. This imitates the style recommended by the "Java 2 Performance and Idiom Guide." Use the full package-qualified name of the class. END exit;} $Class="$a[0]"; $ClassTest="$a[0]Test"; $package = ""; if( $ClassTest =~ m/(^.*\.)/ ) { $package = $1; $ClassTest =~ s/$package//; $package =~ s/\.$//; } print <<"END"; package ${package}.test; import junit.framework.TestCase; import junit.framework.TestSuite; import $Class; /** Unit tests for $Class. */ public class $ClassTest extends TestCase { /** Run some test code. Any "public void test*()" method starting with "test" will be used \@throws Exception for any test failure. */ public void test$ClassTest () throws Exception { // $Class.main(new String[0]); // assert(true); } // OPTIONAL OPTIONAL OPTIONAL OPTIONAL OPTIONAL OPTIONAL OPTIONAL // Get private member private static Object get(Object obj, String fieldName) throws Exception { java.lang.reflect.Field field = obj.getClass().getDeclaredField(fieldName); field.setAccessible(true); return field.get(obj); } // Set private member private static void set(Object obj, String fieldName, Object value) throws Exception { java.lang.reflect.Field field = obj.getClass().getDeclaredField(fieldName); field.setAccessible(true); field.set(obj,value); } /* Initialize objects used by all test methods */ \@Override protected void setUp() throws Exception { super.setUp();} /* Destruction of stuff used by all tests: rarely necessary */ \@Override protected void tearDown() throws Exception { super.tearDown();} // NO NEED TO CHANGE THE FOLLOWING /** Standard constructor calls TestCase(name) constructor \@param name Name of junit Test. */ public $ClassTest(String name) {super (name);} /** This automatically generates a suite of all "test" methods. \@return A suite of all junit tests as a Test. */ public static junit.framework.Test suite() { try {assert false; throw new IllegalStateException("need -ea");} catch (AssertionError e) {} return new TestSuite($ClassTest.class); } /** Run all tests with text gui if this class main is invoked. \@param args Command-line arguments. \@throws Exception for any test failure. */ public static void main (String[] args) throws Exception { try {assert false; throw new IllegalStateException("need -ea");} catch (AssertionError e) {} junit.textui.TestRunner.run (suite()); } } END