Index: trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java =================================================================== --- trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java (revision 228) +++ trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java (working copy) @@ -2,10 +2,10 @@ package org.punit.method.builder; -import java.io.*; -import java.util.*; +import java.io.Serializable; +import java.util.Collection; -import org.punit.convention.*; +import org.punit.convention.Convention; /** * Interface for test method builder. The method builder builds a list of Index: trunk/punit/src/org/punit/method/runner/MethodRunner.java =================================================================== --- trunk/punit/src/org/punit/method/runner/MethodRunner.java (revision 228) +++ trunk/punit/src/org/punit/method/runner/MethodRunner.java (working copy) @@ -1,12 +1,12 @@ package org.punit.method.runner; -import java.io.*; -import java.lang.reflect.*; -import java.util.*; +import java.io.Serializable; +import java.lang.reflect.Method; +import java.util.List; -import org.punit.convention.*; -import org.punit.runner.*; -import org.punit.watcher.*; +import org.punit.convention.Convention; +import org.punit.runner.RunnerProperties; +import org.punit.watcher.Watcher; public interface MethodRunner extends Serializable, Cloneable { /** @@ -14,21 +14,20 @@ * @param testInstance * @param method * @param params - * @return returns the exception if there is any during the execution. + * @throw the exception if there is any during the execution */ public void run(Object testInstance, Method method, Object[] params); /** * - * @param eventListeners List + * @param eventListeners List */ public void setEventListeners(List eventListeners); public void setRunnerProperties(RunnerProperties props); /** - * returns the watchers associated with this method runner. - * @return + * @return watchers associated with this method runner */ public List watchers(); Index: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java =================================================================== --- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java (revision 228) +++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java (working copy) @@ -2,17 +2,25 @@ package org.punit.method.runner; -import java.lang.reflect.*; -import java.util.*; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; -import org.punit.assertion.*; -import org.punit.convention.*; -import org.punit.events.*; -import org.punit.exception.*; -import org.punit.runner.*; -import org.punit.type.*; -import org.punit.util.*; -import org.punit.watcher.*; +import org.punit.assertion.Assert; +import org.punit.assertion.CodeRunner; +import org.punit.convention.Convention; +import org.punit.events.EventListener; +import org.punit.exception.ReflectionException; +import org.punit.runner.RunnerProperties; +import org.punit.type.Parameter; +import org.punit.type.Parameterizable; +import org.punit.type.Test; +import org.punit.util.ReflectionUtil; +import org.punit.util.Traverser; +import org.punit.util.TraverserUtil; +import org.punit.util.TypeUtil; +import org.punit.watcher.TimeWatcher; +import org.punit.watcher.Watcher; public abstract class AbstractMethodRunner implements MethodRunner { @@ -25,11 +33,11 @@ private RunnerProperties _runnerProperties; protected Convention _convention; - + private transient ToStopThread _toStopThread; - + private transient boolean _isLoop; - + protected transient Object _testInstance; protected transient Method _method; @@ -39,11 +47,11 @@ protected transient Class _class; protected transient Method _setUpMethod; - + protected transient Method _tearDownMethod; - + private transient Method _checkMethod; - + protected transient Class _expectedException; public AbstractMethodRunner() { @@ -110,21 +118,21 @@ } onMethodEnd(method, testInstance, params, throwable); } - + private void startToStopThread() { - if(_toStopThread != null) { + if (_toStopThread != null) { _toStopThread.start(); } } - + private void stopToStopThread() { - if(_toStopThread != null) { + if (_toStopThread != null) { _toStopThread.close(); } } private void runCheckMethod(Object testInstance, Object[] params) { - if(_checkMethod != null) { + if (_checkMethod != null) { ReflectionUtil.invokeMethod(_checkMethod, testInstance, params); } } @@ -133,7 +141,7 @@ final Object[] params) { TraverserUtil.traverse(eventListeners().iterator(), new Traverser() { public void traverse(Object obj) { - ((PUnitEventListener) obj).onMethodStart(method, testInstance, + ((EventListener) obj).onMethodStart(method, testInstance, params); } }); @@ -143,8 +151,8 @@ final Object[] params, final Throwable t) { TraverserUtil.traverse(eventListeners().iterator(), new Traverser() { public void traverse(Object obj) { - ((PUnitEventListener) obj).onMethodEnd(method, testInstance, - params, t, _watchers); + ((EventListener) obj).onMethodEnd(method, testInstance, params, + t, _watchers); } }); } @@ -157,17 +165,17 @@ _class = testInstance.getClass(); _params = params; _method = method; - _setUpMethod = _convention.getSetupMethod(_class); + _setUpMethod = _convention.getSetupMethod(_class); _tearDownMethod = _convention.getTearDownMethod(_class); _checkMethod = _convention.getCheckMethod(method); _expectedException = _convention.getExpectedException(method); - long toStop = _convention.toStop(_testInstance); - if (toStop > 0) { + long toWork = _convention.toWork(_testInstance); + if (toWork > 0) { _toStopThread = new ToStopThread(new Runnable() { public void run() { stop(); } - }, toStop); + }, toWork); _isLoop = true; } else { _isLoop = false; @@ -178,11 +186,11 @@ protected synchronized boolean isLoop() { return _isLoop; } - + protected synchronized void stop() { _isLoop = false; } - + /** * This method might be overriden by subclass. The runner may do some more * things during this step. @@ -190,7 +198,7 @@ */ protected void setUpBeforeWatchers(Object[] params) throws Throwable { if (TypeUtil.isPUnitTest(_class)) { - ((PUnitTest) _testInstance).setUpBeforeWatchers(); + ((Test) _testInstance).setUpBeforeWatchers(); } else if (TypeUtil.isPUnitParameterizableTest(_class)) { ((Parameterizable) _testInstance) .setUpBeforeWatchers((Parameter) params[0]); @@ -199,7 +207,7 @@ private void setUpAfterWatchers(Object[] params) throws Throwable { if (TypeUtil.isPUnitTest(_class)) { - ((PUnitTest) _testInstance).setUpAfterWatchers(); + ((Test) _testInstance).setUpAfterWatchers(); } else if (TypeUtil.isPUnitParameterizableTest(_class)) { ((Parameterizable) _testInstance) .setUpAfterWatchers((Parameter) params[0]); @@ -210,7 +218,7 @@ private void tearDownBeforeWatchers(Object[] params) throws Throwable { if (TypeUtil.isPUnitTest(_class)) { - ((PUnitTest) _testInstance).tearDownBeforeWatchers(); + ((Test) _testInstance).tearDownBeforeWatchers(); } else if (TypeUtil.isPUnitParameterizableTest(_class)) { ((Parameterizable) _testInstance) .tearDownBeforeWatchers((Parameter) params[0]); @@ -221,7 +229,7 @@ private void tearDownAfterWatchers(Object[] params) throws Throwable { if (TypeUtil.isPUnitTest(_class)) { - ((PUnitTest) _testInstance).tearDownAfterWatchers(); + ((Test) _testInstance).tearDownAfterWatchers(); } else if (TypeUtil.isPUnitParameterizableTest(_class)) { ((Parameterizable) _testInstance) .tearDownAfterWatchers((Parameter) params[0]); @@ -266,7 +274,7 @@ final Method method, final Object[] params) { TraverserUtil.traverse(eventListeners().iterator(), new Traverser() { public void traverse(Object obj) { - ((PUnitEventListener) obj).onWatchersStart(_watchers); + ((EventListener) obj).onWatchersStart(_watchers); } }); } @@ -276,7 +284,7 @@ final Object[] params) { TraverserUtil.traverse(eventListeners().iterator(), new Traverser() { public void traverse(Object obj) { - ((PUnitEventListener) obj).onWatcherStart(watcher); + ((EventListener) obj).onWatcherStart(watcher); } }); } @@ -297,7 +305,7 @@ final Method method, final Object[] params) { TraverserUtil.traverse(eventListeners().iterator(), new Traverser() { public void traverse(Object obj) { - ((PUnitEventListener) obj).onWatcherEnd(watcher); + ((EventListener) obj).onWatcherEnd(watcher); } }); } @@ -306,7 +314,7 @@ final Object[] params) { TraverserUtil.traverse(eventListeners().iterator(), new Traverser() { public void traverse(Object obj) { - ((PUnitEventListener) obj).onWatchersEnd(_watchers); + ((EventListener) obj).onWatchersEnd(_watchers); } }); } @@ -340,11 +348,11 @@ throw new ReflectionException(e); } } - + public void setConvention(Convention convention) { _convention = convention; } - + protected void runMethod() throws Throwable { if (_expectedException == null) { invokeMethod(); @@ -356,7 +364,7 @@ }); } } - + private void invokeMethod() throws Throwable { try { ReflectionUtil.invokeMethod(_method, _testInstance, _params); Index: trunk/punit/src/org/punit/type/PUnitTest.java =================================================================== --- trunk/punit/src/org/punit/type/PUnitTest.java (revision 228) +++ trunk/punit/src/org/punit/type/PUnitTest.java (working copy) @@ -1,40 +0,0 @@ -/* (C) Copyright 2007, by Andrew Zhang */ - -package org.punit.type; - -/** - * Marks this test as a punit test. It has more setUp/tearDown control than - * normal test class. - * - */ -public interface PUnitTest { - - /** - * This method will be invoked before all watchers start. - * - * @throws Exception - */ - public void setUpBeforeWatchers() throws Exception; - - /** - * This method will be invoked after all watchers start. - * - * @throws Exception - */ - public void setUpAfterWatchers() throws Exception; - - /** - * This method will be invoked before all watchers stop. - * - * @throws Exception - */ - public void tearDownBeforeWatchers() throws Exception; - - /** - * This method will be invoked after all watchers stop. - * - * @throws Exception - */ - public void tearDownAfterWatchers() throws Exception; - -} Index: trunk/punit/src/org/punit/type/Test.java =================================================================== --- trunk/punit/src/org/punit/type/Test.java (revision 0) +++ trunk/punit/src/org/punit/type/Test.java (revision 0) @@ -0,0 +1,40 @@ +/* (C) Copyright 2007, by Andrew Zhang */ + +package org.punit.type; + +/** + * Marks this test as a punit test. It has more setUp/tearDown control than + * normal test class. + * + */ +public interface Test { + + /** + * This method will be invoked before all watchers start. + * + * @throws Exception + */ + public void setUpBeforeWatchers() throws Exception; + + /** + * This method will be invoked after all watchers start. + * + * @throws Exception + */ + public void setUpAfterWatchers() throws Exception; + + /** + * This method will be invoked before all watchers stop. + * + * @throws Exception + */ + public void tearDownBeforeWatchers() throws Exception; + + /** + * This method will be invoked after all watchers stop. + * + * @throws Exception + */ + public void tearDownAfterWatchers() throws Exception; + +} Index: trunk/punit/src/org/punit/type/PUnitName.java =================================================================== --- trunk/punit/src/org/punit/type/PUnitName.java (revision 228) +++ trunk/punit/src/org/punit/type/PUnitName.java (working copy) @@ -1,15 +0,0 @@ -/* (C) Copyright 2007, by Andrew Zhang */ - -package org.punit.type; - -/** - * punit uses this name in the logger and result file. - * - */ -public interface PUnitName { - - /** - * @return returns the meaningful name of this object. - */ - public String punitName(); -} Index: trunk/punit/src/org/punit/type/Parameter.java =================================================================== --- trunk/punit/src/org/punit/type/Parameter.java (revision 227) +++ trunk/punit/src/org/punit/type/Parameter.java (working copy) @@ -2,9 +2,11 @@ package org.punit.type; +import org.punit.type.Parameterizable; + /** - * If a test implements parameterizable interface, the test method with this - * interface will be executed. + * If a test implements Parameterizable interface, the test + * method with this interface will be executed. * * @see Parameterizable * Index: trunk/punit/src/org/punit/type/Name.java =================================================================== --- trunk/punit/src/org/punit/type/Name.java (revision 0) +++ trunk/punit/src/org/punit/type/Name.java (revision 0) @@ -0,0 +1,15 @@ +/* (C) Copyright 2007, by Andrew Zhang */ + +package org.punit.type; + +/** + * punit uses this name in the logger and result file. + * + */ +public interface Name { + + /** + * @return returns the meaningful name of this object. + */ + public String punitName(); +} Index: trunk/punit/src/org/punit/type/VM.java =================================================================== --- trunk/punit/src/org/punit/type/VM.java (revision 228) +++ trunk/punit/src/org/punit/type/VM.java (working copy) @@ -2,7 +2,7 @@ package org.punit.type; -import java.io.*; +import java.io.Serializable; /** * This classes defines a virtual machine properties, includes the path and the @@ -11,7 +11,7 @@ * name will appear in the result files. * */ -public class VM implements PUnitName, Serializable { +public class VM implements Name, Serializable { private static final long serialVersionUID = 7903136094137840375L; Index: trunk/punit/src/org/punit/type/Parameterizable.java =================================================================== --- trunk/punit/src/org/punit/type/Parameterizable.java (revision 228) +++ trunk/punit/src/org/punit/type/Parameterizable.java (working copy) @@ -2,11 +2,12 @@ package org.punit.type; +import org.punit.type.Parameter; + /** - * If a test implements Parameterizable interface, the test method with only a - * Parameter Parameter (i.e. testFoo(Parameter p)) will be - * executed. - * + * If a test implements Parameterizable interface, the test + * method with only a Parameter argument (i.e. + * testFoo(Parameter p)) will be executed. */ public interface Parameterizable { Index: trunk/punit/src/org/punit/type/Loop.java =================================================================== --- trunk/punit/src/org/punit/type/Loop.java (revision 228) +++ trunk/punit/src/org/punit/type/Loop.java (working copy) @@ -8,12 +8,12 @@ */ public interface Loop { /** - * @return returns the time to stop the loop + * @return returns the time to loop */ - public long toStop(); + public long toWork(); /** - * @return returns the time to stop the loop + * @return returns the time to stop the test gracefully */ - public long toAbort(); + public long toStop(); } Index: trunk/punit/src/org/punit/type/PUnitTestSuite.java =================================================================== --- trunk/punit/src/org/punit/type/PUnitTestSuite.java (revision 228) +++ trunk/punit/src/org/punit/type/PUnitTestSuite.java (working copy) @@ -1,17 +0,0 @@ -/* (C) Copyright 2007, by Andrew Zhang */ - -package org.punit.type; - -/** - * Marks this test as a punit test suite. - * - */ -public interface PUnitTestSuite { - - /** - * returns the test classes or test suites included in this test suite. - * - * @return - */ - public Class[] testSuite(); -} Index: trunk/punit/src/org/punit/type/TestSuite.java =================================================================== --- trunk/punit/src/org/punit/type/TestSuite.java (revision 0) +++ trunk/punit/src/org/punit/type/TestSuite.java (revision 0) @@ -0,0 +1,15 @@ +/* (C) Copyright 2007, by Andrew Zhang */ + +package org.punit.type; + +/** + * Marks this test as a PUnit test suite. + * + */ +public interface TestSuite { + + /** + * @return the test classes or test suites included in this test suite + */ + public Class[] testSuite(); +} Index: trunk/punit/src/org/punit/convention/Convention.java =================================================================== --- trunk/punit/src/org/punit/convention/Convention.java (revision 228) +++ trunk/punit/src/org/punit/convention/Convention.java (working copy) @@ -2,8 +2,8 @@ package org.punit.convention; -import java.io.*; -import java.lang.reflect.*; +import java.io.Serializable; +import java.lang.reflect.Method; public interface Convention extends Serializable { @@ -44,7 +44,7 @@ public boolean isLoopTest(Object testInstance); + public long toWork(Object testInstance); + public long toStop(Object testInstance); - - public long toAbort(Object testInstance); } Index: trunk/punit/src/org/punit/convention/NameConvention.java =================================================================== --- trunk/punit/src/org/punit/convention/NameConvention.java (revision 228) +++ trunk/punit/src/org/punit/convention/NameConvention.java (working copy) @@ -120,16 +120,16 @@ return testInstance instanceof Loop; } - public long toAbort(Object testInstance) { + public long toStop(Object testInstance) { if(isLoopTest(testInstance)) { - return ((Loop) testInstance).toAbort(); + return ((Loop) testInstance).toStop(); } return 0; } - public long toStop(Object testInstance) { + public long toWork(Object testInstance) { if(isLoopTest(testInstance)) { - return ((Loop) testInstance).toStop(); + return ((Loop) testInstance).toWork(); } return 0; } Index: trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java =================================================================== --- trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java (revision 228) +++ trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java (working copy) @@ -2,11 +2,11 @@ package org.punit.reporter.stream.file; -import java.io.*; +import java.io.PrintStream; -import org.punit.reporter.stream.*; -import org.punit.runner.*; -import org.punit.util.*; +import org.punit.reporter.stream.StreamLogger; +import org.punit.runner.Runner; +import org.punit.util.ReporterUtil; public class FileLogger extends StreamLogger { Index: trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java =================================================================== --- trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java (revision 228) +++ trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java (working copy) @@ -2,16 +2,14 @@ package org.punit.reporter.stream.console; -import java.io.*; +import org.punit.reporter.stream.StreamLogger; -import org.punit.reporter.stream.*; - public class ConsoleLogger extends StreamLogger { private static final long serialVersionUID = 2691593175672418574L; - private void readObject(java.io.ObjectInputStream in) throws IOException, - ClassNotFoundException { + private void readObject(java.io.ObjectInputStream in) + throws java.io.IOException, ClassNotFoundException { _outStream = System.out; _errStream = System.err; } @@ -19,7 +17,7 @@ public ConsoleLogger() { super(System.out, System.err); } - + public boolean supportParentRunner() { return false; } Index: trunk/punit/src/org/punit/reporter/stream/StreamLogger.java =================================================================== --- trunk/punit/src/org/punit/reporter/stream/StreamLogger.java (revision 228) +++ trunk/punit/src/org/punit/reporter/stream/StreamLogger.java (working copy) @@ -2,20 +2,24 @@ package org.punit.reporter.stream; -import java.io.*; -import java.lang.reflect.*; -import java.util.*; -import java.util.logging.*; +import java.io.PrintStream; +import java.lang.reflect.Method; +import java.util.Iterator; +import java.util.List; +import java.util.logging.Level; -import org.punit.events.*; -import org.punit.message.*; -import org.punit.reporter.*; -import org.punit.runner.*; -import org.punit.type.*; -import org.punit.util.*; -import org.punit.watcher.*; +import org.punit.events.EventListener; +import org.punit.message.Messages; +import org.punit.reporter.TestResult; +import org.punit.runner.Runner; +import org.punit.type.TestSuite; +import org.punit.util.ReporterUtil; +import org.punit.util.Traverser; +import org.punit.util.TraverserUtil; +import org.punit.watcher.TimeWatcher; +import org.punit.watcher.Watcher; -public abstract class StreamLogger implements PUnitEventListener { +public abstract class StreamLogger implements EventListener { protected transient PrintStream _outStream; @@ -93,7 +97,7 @@ _timeWatcher.stop(); } - public void onSuiteStart(PUnitTestSuite suite) { + public void onSuiteStart(TestSuite suite) { StringBuffer sb = new StringBuffer(); sb.append(Messages.getString("logger.06")); //$NON-NLS-1$ sb.append(suite.getClass().getName()); @@ -201,7 +205,7 @@ // nothing needs to do } - public void onSuiteEnd(PUnitTestSuite suite) { + public void onSuiteEnd(TestSuite suite) { // nothing needs to do } @@ -212,5 +216,4 @@ public void onMethodStart(Method method, Object instance, Object[] params) { // nothing needs to do } - } \ No newline at end of file Index: trunk/punit/src/org/punit/reporter/TestResult.java =================================================================== --- trunk/punit/src/org/punit/reporter/TestResult.java (revision 228) +++ trunk/punit/src/org/punit/reporter/TestResult.java (working copy) @@ -1,15 +1,16 @@ /* (C) Copyright 2007, by Andrew Zhang */ package org.punit.reporter; -import java.lang.reflect.*; -import java.util.*; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; -import org.punit.events.*; -import org.punit.runner.*; -import org.punit.type.*; -import org.punit.watcher.*; +import org.punit.events.EventListener; +import org.punit.runner.Runner; +import org.punit.type.TestSuite; +import org.punit.watcher.Watcher; -public class TestResult implements PUnitEventListener { +public class TestResult implements EventListener { private static final long serialVersionUID = -5770657966003459019L; @@ -61,11 +62,11 @@ } - public void onSuiteEnd(PUnitTestSuite suite) { + public void onSuiteEnd(TestSuite suite) { } - public void onSuiteStart(PUnitTestSuite suite) { + public void onSuiteStart(TestSuite suite) { } @@ -88,5 +89,5 @@ public boolean supportParentRunner() { return false; } - + } Index: trunk/punit/src/org/punit/events/PUnitEventListener.java =================================================================== --- trunk/punit/src/org/punit/events/PUnitEventListener.java (revision 228) +++ trunk/punit/src/org/punit/events/PUnitEventListener.java (working copy) @@ -1,107 +0,0 @@ -/* (C) Copyright 2007, by Andrew Zhang */ - -package org.punit.events; - -import java.io.*; -import java.lang.reflect.*; -import java.util.*; - -import org.punit.runner.*; -import org.punit.type.*; -import org.punit.watcher.*; - -/** - * Event system for punit. The event listener can be installed by - * {@link PUnitEventRegsitry#addEventListener(PUnitEventListener)}. - * - * All punit runners implement {@link PUnitEventRegsitry}. - * - */ -public interface PUnitEventListener extends Serializable { - - /** - * It is triggered at the beginning of running the class. - * - * @param clazz - * the class to be run - * @param runner - * the runner who runs this class - */ - public void onRunnerStart(Class clazz, Runner runner); - - /** - * It is triggered at the end of running the class. - * - * @param clazz - * the class to be run - * @param runner - * the runner who runs this class - */ - public void onRunnerEnd(Class clazz, Runner runner); - - /** - * It is triggered when the test suite is to be executed. - * - */ - public void onSuiteStart(PUnitTestSuite suite); - - /** - * It is triggered after executing the test suite. - */ - public void onSuiteEnd(PUnitTestSuite suite); - - /** - * It is triggered when the test class is to be executed. - */ - public void onClassStart(Class clazz); - - /** - * It is triggered after executing the test class. - */ - public void onClassEnd(Class clazz); - - /** - * It is triggered when the method to be executed. - */ - public void onMethodStart(Method method, Object testInstance, - Object[] params); - - /** - * It is triggered after executing the method. - */ - public void onMethodEnd(Method method, Object testInstance, - Object[] params, Throwable t, List Watchers); - - /** - * It is triggered before all watchers start. - */ - public void onWatchersStart(List watchers); - - /** - * It is triggered after all watchers stop. - */ - public void onWatchersEnd(List watchers); - - /** - * It is triggered before this watcher starts. - */ - public void onWatcherStart(Watcher watcher); - - /** - * It is triggered after this watcher stops. - */ - public void onWatcherEnd(Watcher watcher); - - /** - * PUnit may executes test suites against different virtual machines. The - * runner who forks child virtual machine is called parent runner. Parent - * runner only notifies the events to the event listener who support parent - * runner. It is useful for logging and reporting system. For example, file - * logging does not care about it since the children virtual machine has - * given the output. - * - * @return returns true if this listener supports parent runner. - */ - public boolean supportParentRunner(); - -} Index: trunk/punit/src/org/punit/events/EventListener.java =================================================================== --- trunk/punit/src/org/punit/events/EventListener.java (revision 0) +++ trunk/punit/src/org/punit/events/EventListener.java (revision 0) @@ -0,0 +1,107 @@ +/* (C) Copyright 2007, by Andrew Zhang */ + +package org.punit.events; + +import java.io.Serializable; +import java.lang.reflect.Method; +import java.util.List; + +import org.punit.runner.Runner; +import org.punit.type.TestSuite; +import org.punit.watcher.Watcher; + +/** + * Event system for PUnit. The event listener can be installed by + * {@link EventRegistry#addEventListener(EventListener)}. + * + * All PUnit runners implement {@link EventRegistry}. + * + */ +public interface EventListener extends Serializable { + + /** + * Is triggered before running the class. + * + * @param clazz + * the class to be run + * @param runner + * the runner who runs this class + */ + public void onRunnerStart(Class clazz, Runner runner); + + /** + * Is triggered after running the class. + * + * @param clazz + * the class to be run + * @param runner + * the runner who runs this class + */ + public void onRunnerEnd(Class clazz, Runner runner); + + /** + * Is triggered when the test suite is to be executed. + * + */ + public void onSuiteStart(TestSuite suite); + + /** + * Is triggered after executing the test suite. + */ + public void onSuiteEnd(TestSuite suite); + + /** + * Is triggered when the test class is to be executed. + */ + public void onClassStart(Class clazz); + + /** + * Is triggered after executing the test class. + */ + public void onClassEnd(Class clazz); + + /** + * Is triggered when the method to be executed. + */ + public void onMethodStart(Method method, Object testInstance, + Object[] params); + + /** + * Is triggered after executing the method. + */ + public void onMethodEnd(Method method, Object testInstance, + Object[] params, Throwable t, List Watchers); + + /** + * Is triggered before all watchers start. + */ + public void onWatchersStart(List watchers); + + /** + * Is triggered after all watchers stop. + */ + public void onWatchersEnd(List watchers); + + /** + * Is triggered before this watcher starts. + */ + public void onWatcherStart(Watcher watcher); + + /** + * Is triggered after this watcher stops. + */ + public void onWatcherEnd(Watcher watcher); + + /** + * PUnit may execute test suites against different virtual machines. The + * runner who forks child virtual machine is called parent runner. Parent + * runner only notifies the events to the event listener who support parent + * runner. It is useful for logging and reporting system. For example, file + * logging does not care about it since the children virtual machine has + * given the output. + * + * @return true if this listener supports parent runner + */ + public boolean supportParentRunner(); + +} Index: trunk/punit/src/org/punit/events/PUnitEventRegsitry.java =================================================================== --- trunk/punit/src/org/punit/events/PUnitEventRegsitry.java (revision 228) +++ trunk/punit/src/org/punit/events/PUnitEventRegsitry.java (working copy) @@ -1,31 +0,0 @@ -/* (C) Copyright 2007, by Andrew Zhang */ - -package org.punit.events; - -import java.util.*; - -/** - * Interface for punit event registry center. It can accept/remove a event - * listener. - */ -public interface PUnitEventRegsitry { - - /** - * Adds a new event lisetner. - * - * @param listener - */ - public void addEventListener(PUnitEventListener listener); - - /** - * Removes a event lisetern. - * - * @param listener - */ - public void removeEventListener(PUnitEventListener listener); - - /** - * @return returns the registered event listeners. - */ - public List eventListeners(); -} Index: trunk/punit/src/org/punit/events/EventRegistry.java =================================================================== --- trunk/punit/src/org/punit/events/EventRegistry.java (revision 0) +++ trunk/punit/src/org/punit/events/EventRegistry.java (revision 0) @@ -0,0 +1,31 @@ +/* (C) Copyright 2007, by Andrew Zhang */ + +package org.punit.events; + +import java.util.List; + +/** + * Interface for PUnit event registry. It can accept/remove a event + * listener. + */ +public interface EventRegistry { + + /** + * Adds a new event listener. + * + * @param listener + */ + public void addEventListener(EventListener listener); + + /** + * Removes an event listener. + * + * @param listener + */ + public void removeEventListener(EventListener listener); + + /** + * @return returns the registered event listeners. + */ + public List eventListeners(); +} Index: trunk/punit/src/org/punit/assertion/Assert.java =================================================================== --- trunk/punit/src/org/punit/assertion/Assert.java (revision 228) +++ trunk/punit/src/org/punit/assertion/Assert.java (working copy) @@ -2,7 +2,7 @@ package org.punit.assertion; -import org.punit.message.*; +import org.punit.message.Messages; public class Assert { Index: trunk/punit/src/org/punit/runner/RunnerProperties.java =================================================================== --- trunk/punit/src/org/punit/runner/RunnerProperties.java (revision 228) +++ trunk/punit/src/org/punit/runner/RunnerProperties.java (working copy) @@ -2,9 +2,9 @@ package org.punit.runner; -import java.io.*; +import java.io.Serializable; -import org.punit.type.*; +import org.punit.type.VM; public class RunnerProperties implements Serializable { Index: trunk/punit/src/org/punit/runner/StreamReaderThread.java =================================================================== --- trunk/punit/src/org/punit/runner/StreamReaderThread.java (revision 228) +++ trunk/punit/src/org/punit/runner/StreamReaderThread.java (working copy) @@ -1,6 +1,9 @@ package org.punit.runner; -import java.io.*; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; class StreamReaderThread extends Thread { private InputStream _is; @@ -23,7 +26,7 @@ } _ps.println(string); } - } catch (IOException e) { + } catch (java.io.IOException e) { } } } Index: trunk/punit/src/org/punit/runner/ExecutorPool.java =================================================================== --- trunk/punit/src/org/punit/runner/ExecutorPool.java (revision 228) +++ trunk/punit/src/org/punit/runner/ExecutorPool.java (working copy) @@ -2,7 +2,7 @@ package org.punit.runner; -import java.io.*; +import java.io.Serializable; public interface ExecutorPool extends Serializable { public void execute(Runnable task); Index: trunk/punit/src/org/punit/runner/Runner.java =================================================================== --- trunk/punit/src/org/punit/runner/Runner.java (revision 228) +++ trunk/punit/src/org/punit/runner/Runner.java (working copy) @@ -2,16 +2,16 @@ package org.punit.runner; -import java.io.*; +import java.io.Serializable; -import org.punit.events.*; -import org.punit.method.builder.*; -import org.punit.method.runner.*; -import org.punit.reporter.*; -import org.punit.suite.builder.*; -import org.punit.type.*; +import org.punit.events.EventRegistry; +import org.punit.method.builder.TestMethodBuilder; +import org.punit.method.runner.MethodRunner; +import org.punit.reporter.TestResult; +import org.punit.suite.builder.TestSuiteBuilder; +import org.punit.type.Name; -public interface Runner extends PUnitEventRegsitry, PUnitName, Serializable, Cloneable { +public interface Runner extends EventRegistry, Name, Serializable, Cloneable { public int run(Class clazz); @@ -23,7 +23,7 @@ public MethodRunner methodRunner(); - public TestSuiteBuilder suiteBuiler(); + public TestSuiteBuilder suiteBuilder(); public TestResult testResult(); Index: trunk/punit/src/org/punit/runner/ConcurrentRunner.java =================================================================== --- trunk/punit/src/org/punit/runner/ConcurrentRunner.java (revision 228) +++ trunk/punit/src/org/punit/runner/ConcurrentRunner.java (working copy) @@ -1,11 +1,11 @@ /* (C) Copyright 2007, by Andrew Zhang */ package org.punit.runner; -import org.punit.message.*; -import org.punit.method.builder.*; -import org.punit.method.runner.*; -import org.punit.suite.builder.*; -import org.punit.util.*; +import org.punit.message.Messages; +import org.punit.method.builder.MethodBuilderImpl; +import org.punit.method.runner.ConcurrentMethodRunner; +import org.punit.suite.builder.TestSuiteBuilderImpl; +import org.punit.util.RunnerUtil; public class ConcurrentRunner extends AbstractRunner { Index: trunk/punit/src/org/punit/runner/AbstractRunner.java =================================================================== --- trunk/punit/src/org/punit/runner/AbstractRunner.java (revision 228) +++ trunk/punit/src/org/punit/runner/AbstractRunner.java (working copy) @@ -2,20 +2,32 @@ package org.punit.runner; -import java.io.*; -import java.lang.reflect.*; -import java.util.*; +import java.io.File; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; -import org.punit.convention.*; -import org.punit.events.*; -import org.punit.exception.*; -import org.punit.method.builder.*; -import org.punit.method.runner.*; -import org.punit.reporter.*; -import org.punit.reporter.stream.console.*; -import org.punit.suite.builder.*; -import org.punit.type.*; -import org.punit.util.*; +import org.punit.convention.Convention; +import org.punit.convention.NameConvention; +import org.punit.events.EventListener; +import org.punit.exception.IOException; +import org.punit.exception.ReflectionException; +import org.punit.method.builder.TestMethodBuilder; +import org.punit.method.runner.MethodRunner; +import org.punit.reporter.TestResult; +import org.punit.reporter.stream.console.ConsoleLogger; +import org.punit.suite.builder.TestSuiteBuilder; +import org.punit.suite.builder.TestSuiteLabel; +import org.punit.type.Parameter; +import org.punit.type.Parameterizable; +import org.punit.type.TestSuite; +import org.punit.type.VM; +import org.punit.util.IOUtil; +import org.punit.util.ReflectionUtil; +import org.punit.util.Traverser; +import org.punit.util.TraverserUtil; +import org.punit.util.TypeUtil; public abstract class AbstractRunner implements Runner { @@ -25,11 +37,11 @@ private MethodRunner _methodRunner; - // List + // List private final List _eventListeners = new ArrayList(); private TestResult _testResult = new TestResult(); - + private ConsoleLogger _consoleLogger = new ConsoleLogger(); private RunnerProperties _properties = new RunnerProperties(); @@ -69,7 +81,7 @@ setRunnerProperties(properties); return run(clazz); } - + private void runTestClasses(Object[] testClasses) { startExecutorPool(); for (int i = 0; i < testClasses.length; ++i) { @@ -119,7 +131,7 @@ try { p.waitFor(); } catch (InterruptedException e) { - throw new PUnitIOException(e); + throw new IOException(e); } deleteRunnerConfig(vm); deleteRunnerProperties(vm); @@ -140,7 +152,7 @@ final List newEventListener = new ArrayList(); TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() { public void traverse(Object obj) { - PUnitEventListener listener = ((PUnitEventListener) obj); + EventListener listener = ((EventListener) obj); if (listener.supportParentRunner()) { newEventListener.add(listener); } @@ -200,8 +212,7 @@ private void onRunnerStart(final Class clazz) { TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() { public void traverse(Object obj) { - ((PUnitEventListener) obj).onRunnerStart(clazz, - AbstractRunner.this); + ((EventListener) obj).onRunnerStart(clazz, AbstractRunner.this); } }); } @@ -213,8 +224,7 @@ private void onRunnerEnd(final Class clazz) { TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() { public void traverse(Object obj) { - ((PUnitEventListener) obj).onRunnerEnd(clazz, - AbstractRunner.this); + ((EventListener) obj).onRunnerEnd(clazz, AbstractRunner.this); } }); } @@ -235,7 +245,8 @@ } public void run() { - AbstractRunner runner = (AbstractRunner)AbstractRunner.this.clone(); + AbstractRunner runner = (AbstractRunner) AbstractRunner.this + .clone(); runner.runTestClassImpl(_clazz); } @@ -255,7 +266,7 @@ } finally { try { afterClass(clazz); - }catch (Throwable t) { + } catch (Throwable t) { // TODO: will be passed to onClassEnd } } @@ -264,23 +275,25 @@ private void beforeClass(Class clazz) { Method beforeClassMethod = _convention.getBeforeClassMethod(clazz); - if(beforeClassMethod != null) { - ReflectionUtil.invokeMethod(beforeClassMethod, null, new Object[] {}); + if (beforeClassMethod != null) { + ReflectionUtil.invokeMethod(beforeClassMethod, null, + new Object[] {}); } } - + private void afterClass(Class clazz) { Method afterClassMethod = _convention.getAfterClassMethod(clazz); - if(afterClassMethod != null) { - ReflectionUtil.invokeMethod(afterClassMethod, null, new Object[] {}); + if (afterClassMethod != null) { + ReflectionUtil + .invokeMethod(afterClassMethod, null, new Object[] {}); } } private void onSuite(final TestSuiteLabel suiteLabel) { TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() { public void traverse(Object obj) { - PUnitEventListener listener = ((PUnitEventListener) obj); - PUnitTestSuite suite = suiteLabel.suite(); + EventListener listener = ((EventListener) obj); + TestSuite suite = suiteLabel.suite(); if (suiteLabel.isStart()) { listener.onSuiteStart(suite); } else { @@ -293,7 +306,7 @@ private void onClassStart(final Class clazz) { TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() { public void traverse(Object obj) { - ((PUnitEventListener) obj).onClassStart(clazz); + ((EventListener) obj).onClassStart(clazz); } }); } @@ -301,7 +314,7 @@ private void onClassEnd(final Class clazz) { TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() { public void traverse(Object obj) { - ((PUnitEventListener) obj).onClassEnd(clazz); + ((EventListener) obj).onClassEnd(clazz); } }); } @@ -336,7 +349,7 @@ return _methodRunner; } - public TestSuiteBuilder suiteBuiler() { + public TestSuiteBuilder suiteBuilder() { return _testSuiteBuiler; } @@ -349,11 +362,11 @@ return _eventListeners; } - public void addEventListener(PUnitEventListener listener) { + public void addEventListener(EventListener listener) { _eventListeners.add(listener); } - public void removeEventListener(PUnitEventListener listener) { + public void removeEventListener(EventListener listener) { _eventListeners.remove(listener); } @@ -378,7 +391,7 @@ throw new ReflectionException(e); } } - + public TestResult testResult() { return _testResult; } Index: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java =================================================================== --- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java (revision 228) +++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java (working copy) @@ -2,9 +2,9 @@ package org.punit.suite.builder; -import java.io.*; +import java.io.Serializable; -import org.punit.convention.*; +import org.punit.convention.Convention; /** * Interface for test suite builder. Index: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java =================================================================== --- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java (revision 228) +++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java (working copy) @@ -39,7 +39,7 @@ if(_filter.isExcluded(clazz)) { return; } - PUnitTestSuite testSuite = (PUnitTestSuite) ReflectionUtil.newInstance(clazz); + TestSuite testSuite = (TestSuite) ReflectionUtil.newInstance(clazz); testClasses.add(new TestSuiteLabelImpl(testSuite, true)); Class[] suite = testSuite.testSuite(); for(int i = 0; i < suite.length; ++i) { @@ -57,7 +57,7 @@ private boolean isTestSuite(Class clazz) { - return PUnitTestSuite.class.isAssignableFrom(clazz); + return TestSuite.class.isAssignableFrom(clazz); } } Index: trunk/punit/src/org/punit/suite/builder/TestSuiteLabel.java =================================================================== --- trunk/punit/src/org/punit/suite/builder/TestSuiteLabel.java (revision 228) +++ trunk/punit/src/org/punit/suite/builder/TestSuiteLabel.java (working copy) @@ -14,7 +14,7 @@ /** * @return the test suite it represents */ - public PUnitTestSuite suite(); + public TestSuite suite(); /** * @return returns true if it represents the start of a test suite. Index: trunk/punit/src/org/punit/suite/builder/TestSuiteLabelImpl.java =================================================================== --- trunk/punit/src/org/punit/suite/builder/TestSuiteLabelImpl.java (revision 228) +++ trunk/punit/src/org/punit/suite/builder/TestSuiteLabelImpl.java (working copy) @@ -10,15 +10,15 @@ * @see TestSuiteLabel */ public class TestSuiteLabelImpl implements TestSuiteLabel { - private PUnitTestSuite _suite; + private TestSuite _suite; private boolean _isStart; - public TestSuiteLabelImpl(PUnitTestSuite suite, boolean isStart) { + public TestSuiteLabelImpl(TestSuite suite, boolean isStart) { _suite = suite; _isStart = isStart; } - public PUnitTestSuite suite() { + public TestSuite suite() { return _suite; } Index: trunk/punit/src/org/punit/util/TypeUtil.java =================================================================== --- trunk/punit/src/org/punit/util/TypeUtil.java (revision 228) +++ trunk/punit/src/org/punit/util/TypeUtil.java (working copy) @@ -7,7 +7,7 @@ public class TypeUtil { public static boolean isPUnitTest(Class clazz) { - return PUnitTest.class.isAssignableFrom(clazz); + return Test.class.isAssignableFrom(clazz); } public static boolean isPUnitParameterizableTest(Class clazz) { Index: trunk/punit/src/org/punit/util/ReporterUtil.java =================================================================== --- trunk/punit/src/org/punit/util/ReporterUtil.java (revision 228) +++ trunk/punit/src/org/punit/util/ReporterUtil.java (working copy) @@ -1,9 +1,11 @@ package org.punit.util; -import java.io.*; -import java.lang.reflect.*; +import java.io.File; +import java.lang.reflect.Method; -import org.punit.runner.*; +import org.punit.runner.Runner; +import org.punit.runner.RunnerConstants; +import org.punit.runner.RunnerProperties; public class ReporterUtil { public final static String LINE_SEPERATOR; Index: trunk/punit/src/org/punit/util/IOUtil.java =================================================================== --- trunk/punit/src/org/punit/util/IOUtil.java (revision 228) +++ trunk/punit/src/org/punit/util/IOUtil.java (working copy) @@ -2,24 +2,28 @@ package org.punit.util; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; -import org.punit.exception.*; +import org.punit.exception.IOException; public class IOUtil { public static String getCurrentPath() { try { return new File(".").getCanonicalPath(); //$NON-NLS-1$ - } catch (IOException e) { - throw new PUnitIOException(e); + } catch (java.io.IOException e) { + throw new IOException(e); } } public static Process exec(String command) { try { return Runtime.getRuntime().exec(command); - } catch (IOException e) { - throw new PUnitIOException(e); + } catch (java.io.IOException e) { + throw new IOException(e); } } @@ -30,14 +34,14 @@ oos = new ObjectOutputStream(fos); oos.writeObject(obj); oos.close(); - } catch (IOException e) { - throw new PUnitIOException(e); + } catch (java.io.IOException e) { + throw new IOException(e); } finally { if (oos != null) { try { oos.close(); - } catch (IOException e) { - throw new PUnitIOException(e); + } catch (java.io.IOException e) { + throw new IOException(e); } } } @@ -50,13 +54,13 @@ ois = new ObjectInputStream(fis); return ois.readObject(); } catch (Exception e) { - throw new PUnitIOException(e); + throw new IOException(e); } finally { if (ois != null) { try { ois.close(); - } catch (IOException e) { - throw new PUnitIOException(e); + } catch (java.io.IOException e) { + throw new IOException(e); } } } Index: trunk/punit/src/org/punit/util/MemoryUtil.java =================================================================== --- trunk/punit/src/org/punit/util/MemoryUtil.java (revision 228) +++ trunk/punit/src/org/punit/util/MemoryUtil.java (working copy) @@ -1,15 +1,25 @@ package org.punit.util; + public class MemoryUtil { private static Runtime _runtime = Runtime.getRuntime(); + private static long freeMemory() { + return _runtime.freeMemory(); + } + + public static long totalMemory() { + return _runtime.totalMemory(); + } + public static long usedMemory() { - return _runtime.totalMemory() - _runtime.freeMemory(); + return totalMemory() - freeMemory(); } public static void clear() { System.gc(); System.runFinalization(); } + } Index: trunk/punit/src/org/punit/util/RunnerUtil.java =================================================================== --- trunk/punit/src/org/punit/util/RunnerUtil.java (revision 228) +++ trunk/punit/src/org/punit/util/RunnerUtil.java (working copy) @@ -2,27 +2,75 @@ package org.punit.util; -import org.punit.message.*; -import org.punit.runner.*; +import java.io.File; +import org.punit.message.Messages; +import org.punit.runner.Runner; +import org.punit.runner.RunnerProperties; + public class RunnerUtil { - + private static final int MAX_ARGS = 3; - + public static void run(Runner runner, String[] args) { int length = args.length; if (length == 0 || length > MAX_ARGS) { - throw new IllegalArgumentException(Messages.getString("runner.05")); //$NON-NLS-1$ + throw new IllegalArgumentException(length + + Messages.getString("runner.arguments")); //$NON-NLS-1$ } Runner testRunner = runner; RunnerProperties properties = runner.properties(); Class testClass = ReflectionUtil.newClass(args[0]); - if(length >= 2) { + if (length >= 2) { testRunner = (Runner) IOUtil.getSerialiableObject(args[1]); } - if(length >= 3) { - properties = (RunnerProperties) IOUtil.getSerialiableObject(args[2]); + if (length >= 3) { + properties = (RunnerProperties) IOUtil + .getSerialiableObject(args[2]); } testRunner.run(testClass, properties); } + + private static final String BIN = File.separator + "bin"; //$NON-NLS-1$ + private static final String LIB = File.separator + "lib" + File.separator; //$NON-NLS-1$ + + public static String getVmLaunchString() { + return System.getProperty("java.home") + BIN + File.separator + + "java -cp " + generateClassPath(); + } + + private static String generateClassPath() { + StringBuffer sb = new StringBuffer(); + final String TEST_PATH = IOUtil.getCurrentPath(); + + // test project + sb.append(TEST_PATH); + sb.append(BIN); + sb.append(File.pathSeparator); + + // extension project + final String EXTENSION_PATH = TEST_PATH.replace( + "punit.test", "punit.extension"); //$NON-NLS-2$ + sb.append(EXTENSION_PATH); + sb.append(BIN); + sb.append(File.pathSeparator); + + // core project + sb.append(TEST_PATH.replaceAll("punit.test", "punit")); //$NON-NLS-2$ + sb.append(BIN); + sb.append(File.pathSeparator); + + // JUnit + sb.append(EXTENSION_PATH + LIB + "junit-4.3.1.jar"); //$NON-NLS-1$ + sb.append(File.pathSeparator); + + // reporting tools + sb.append(EXTENSION_PATH + LIB + "jcommon-1.0.9.jar"); //$NON-NLS-1$ + sb.append(File.pathSeparator); + sb.append(EXTENSION_PATH + LIB + "jfreechart-1.0.5.jar"); //$NON-NLS-1$ + sb.append(File.pathSeparator); + sb.append(EXTENSION_PATH + LIB + "itext-2.0.2.jar"); //$NON-NLS-1$ + return sb.toString(); + } + } Index: trunk/punit/src/org/punit/util/TraverserUtil.java =================================================================== --- trunk/punit/src/org/punit/util/TraverserUtil.java (revision 228) +++ trunk/punit/src/org/punit/util/TraverserUtil.java (working copy) @@ -1,6 +1,6 @@ package org.punit.util; -import java.util.*; +import java.util.Iterator; public class TraverserUtil { public static void traverse(Iterator iter, Traverser traverser) { Index: trunk/punit/src/org/punit/watcher/AbstractWatcher.java =================================================================== --- trunk/punit/src/org/punit/watcher/AbstractWatcher.java (revision 0) +++ trunk/punit/src/org/punit/watcher/AbstractWatcher.java (revision 0) @@ -0,0 +1,49 @@ +/* (C) Copyright 2007 */ + +package org.punit.watcher; + +import org.punit.exception.ReflectionException; + +abstract class AbstractWatcher implements Watcher { + + transient long _scale = 1; + + transient long _value; + + public void start() { + } + + public void stop() { + } + + public double value() { +// System.out.println("_value = " + _value + ", _scale = " + _scale); +// System.out.println("value() = " + (((double) _value) / _scale)); + return ((double) _value) / _scale; + } + + public String stringValue() { + if (_scale == 1) { + return _value + " " + unit(); + } else { + return value() + unit(); + } + } + + public Watcher cloneSelf() { + try { + return (Watcher) clone(); + } catch (CloneNotSupportedException e) { + throw new ReflectionException(e); + } + } + + public int hashCode() { + return getClass().hashCode(); + } + + public boolean equals(Object obj) { + return getClass() == obj.getClass(); + } + +} Property changes on: trunk/punit/src/org/punit/watcher/AbstractWatcher.java ___________________________________________________________________ Name: svn:executable + * Index: trunk/punit/src/org/punit/watcher/MemoryWatcher.java =================================================================== --- trunk/punit/src/org/punit/watcher/MemoryWatcher.java (revision 228) +++ trunk/punit/src/org/punit/watcher/MemoryWatcher.java (working copy) @@ -2,24 +2,23 @@ package org.punit.watcher; -import org.punit.exception.*; -import org.punit.message.*; -import org.punit.util.*; +import org.punit.message.Messages; +import org.punit.util.MemoryUtil; +import org.punit.util.ThreadUtil; -public class MemoryWatcher implements Watcher { +public class MemoryWatcher extends AbstractWatcher { - private static final long serialVersionUID = 3097358158872486298L; - + private static final long serialVersionUID = -8555763191477212847L; + private transient long _startUsedMemory; - private transient long _maxUsedMemory; - private transient boolean _stop; - + public void start() { _stop = false; MemoryUtil.clear(); - _maxUsedMemory = _startUsedMemory = MemoryUtil.usedMemory(); + _startUsedMemory = MemoryUtil.usedMemory(); + _value = 0; new MemoryWatcherThread("memory watcher thread").start(); //$NON-NLS-1$ } @@ -28,55 +27,31 @@ monitorMemory(); } - public double value() { - return _maxUsedMemory - _startUsedMemory; - } - private void monitorMemory() { - long usedMemory = MemoryUtil.usedMemory(); - if(usedMemory > _maxUsedMemory) { - _maxUsedMemory = usedMemory; + long usedMemory = MemoryUtil.usedMemory() - _startUsedMemory; + if (usedMemory > _value) { + _value = usedMemory; } } - + private class MemoryWatcherThread extends Thread { public MemoryWatcherThread(String threadName) { super(threadName); } - + public void run() { - while(!_stop) { + while (!_stop) { monitorMemory(); ThreadUtil.sleepIgnoreInterruption(10); } } } - - public String stringValue() { - return value() + unit(); - } - + public String punitName() { - return Messages.getString("watcher.03"); //$NON-NLS-1$ + return Messages.getString("watcher.memory"); //$NON-NLS-1$ } public String unit() { - return Messages.getString("watcher.01"); //$NON-NLS-1$ + return Messages.getString("watcher.bytes"); //$NON-NLS-1$ } - - public Watcher cloneSelf() { - try { - return (Watcher) clone(); - } catch (CloneNotSupportedException e) { - throw new ReflectionException(e); - } - } - - public int hashCode() { - return getClass().hashCode(); - } - - public boolean equals(Object obj) { - return getClass() == obj.getClass(); - } } Index: trunk/punit/src/org/punit/watcher/CustomWatcher.java =================================================================== --- trunk/punit/src/org/punit/watcher/CustomWatcher.java (revision 0) +++ trunk/punit/src/org/punit/watcher/CustomWatcher.java (revision 0) @@ -0,0 +1,97 @@ +/* (C) Copyright 2007, by Andrew Zhang */ + +package org.punit.watcher; + +import java.util.Iterator; + +import org.punit.method.runner.MethodRunner; + +/** + * Basic class for watchers triggered by internal test events such as a callback + * or an exception. + * + * Here is a custom watcher design. Register a special + */ +public class CustomWatcher extends AbstractWatcher { + + private static final long serialVersionUID = -497434829953274515L; + + private String _name; + + private String _unit; + + private transient static MethodRunner _methodRunner; + + public CustomWatcher(MethodRunner methodRunner, String name, String unit) { + this(methodRunner, name, unit, 1); + } + + public CustomWatcher(MethodRunner methodRunner, String name, String unit, + long scale) { + _methodRunner = methodRunner; + _name = name; + _methodRunner.addWatcher(this); + _scale = scale; + _unit = unit; + } + + public void start() { + } + + public void stop() { + } + + /** + * Updates all registered CustomWatcher for this method + * runner. + */ + public static synchronized void setResult(final String name, + final long value, final String unit, final long scale) { + Iterator iter = _methodRunner.watchers().iterator(); +// System.out.println(name + " " + value + " " + unit + " " + scale); + while (iter.hasNext()) { + try { + CustomWatcher watcher = (CustomWatcher) iter.next(); + if (watcher.punitName().equals(name)) { + watcher.setValue(value); + watcher._unit = unit; + watcher._scale = scale; + } + } catch (ClassCastException cce) { + } + } + } + + /** + * Updates all registered CustomWatcher for this method + * runner. + */ + public static synchronized void setResult(final String name, + final long value) { + Iterator iter = _methodRunner.watchers().iterator(); + while (iter.hasNext()) { + try { + CustomWatcher watcher = (CustomWatcher) iter.next(); + if (watcher.punitName().equals(name)) { + watcher.setValue(value); + } + } catch (ClassCastException cce) { + } + } + } + + /** + * Updates the value for this runner. + */ + void setValue(final long value) { + _value = value; + } + + public String punitName() { + return _name; + } + + public String unit() { + return _unit; + } +} Property changes on: trunk/punit/src/org/punit/watcher/CustomWatcher.java ___________________________________________________________________ Name: svn:executable + * Index: trunk/punit/src/org/punit/watcher/MinimumWatcher.java =================================================================== --- trunk/punit/src/org/punit/watcher/MinimumWatcher.java (revision 0) +++ trunk/punit/src/org/punit/watcher/MinimumWatcher.java (revision 0) @@ -0,0 +1,34 @@ +/* (C) Copyright 2007 */ + +package org.punit.watcher; + +import org.punit.method.runner.MethodRunner; + +/** + * The class accumulates the maximum reported value. + */ +public class MinimumWatcher extends CustomWatcher { + + private static final long serialVersionUID = 8981963600562662555L; + + public MinimumWatcher(MethodRunner methodRunner, String name, String unit) { + super(methodRunner, name, unit); + } + + public MinimumWatcher(MethodRunner methodRunner, String name, String unit, long scale) { + super(methodRunner, name, unit, scale); + } + + public void start() { + _value = Long.MAX_VALUE; + } + + /** + * Updates the value for this runner. + */ + void setValue(final long value) { + if (value < _value) { + _value = value; + } + } +} Property changes on: trunk/punit/src/org/punit/watcher/MinimumWatcher.java ___________________________________________________________________ Name: svn:executable + * Index: trunk/punit/src/org/punit/watcher/MaximumWatcher.java =================================================================== --- trunk/punit/src/org/punit/watcher/MaximumWatcher.java (revision 0) +++ trunk/punit/src/org/punit/watcher/MaximumWatcher.java (revision 0) @@ -0,0 +1,34 @@ +/* (C) Copyright 2007 */ + +package org.punit.watcher; + +import org.punit.method.runner.MethodRunner; + +/** + * The class accumulates the maximum reported value. + */ +public class MaximumWatcher extends CustomWatcher { + + private static final long serialVersionUID = 383142832201569299L; + + public MaximumWatcher(MethodRunner methodRunner, String name, String unit) { + super(methodRunner, name, unit); + } + + public MaximumWatcher(MethodRunner methodRunner, String name, String unit, long scale) { + super(methodRunner, name, unit, scale); + } + + public void start() { + _value = 0; + } + + /** + * Updates the value for this runner. + */ + void setValue(final long value) { + if (value > _value) { + _value = value; + } + } +} Property changes on: trunk/punit/src/org/punit/watcher/MaximumWatcher.java ___________________________________________________________________ Name: svn:executable + * Index: trunk/punit/src/org/punit/watcher/TimeWatcher.java =================================================================== --- trunk/punit/src/org/punit/watcher/TimeWatcher.java (revision 228) +++ trunk/punit/src/org/punit/watcher/TimeWatcher.java (working copy) @@ -2,55 +2,28 @@ package org.punit.watcher; -import org.punit.exception.*; -import org.punit.message.*; +import org.punit.message.Messages; -public class TimeWatcher implements Watcher { +public class TimeWatcher extends AbstractWatcher { - private static final long serialVersionUID = 1746326383277266047L; + private static final long serialVersionUID = -1374581076649027519L; private transient long _startTime; - - private transient long _endTime; - + public void start() { _startTime = System.nanoTime(); + _scale = 1000000; } public void stop() { - _endTime = System.nanoTime(); + _value = System.nanoTime() - _startTime; } - public double value() { - return (_endTime - _startTime)/1000000; - } - - public String stringValue() { - return value() + unit(); - } - public String punitName() { - return Messages.getString("watcher.04"); //$NON-NLS-1$ + return Messages.getString("watcher.time"); //$NON-NLS-1$ } - + public String unit() { - return Messages.getString("watcher.02"); //$NON-NLS-1$ + return Messages.getString("watcher.ms"); //$NON-NLS-1$ } - - public Watcher cloneSelf() { - try { - return (Watcher) clone(); - } catch (CloneNotSupportedException e) { - throw new ReflectionException(e); - } - } - - public int hashCode() { - return getClass().hashCode(); - } - - public boolean equals(Object obj) { - return getClass() == obj.getClass(); - } - } Index: trunk/punit/src/org/punit/watcher/Watcher.java =================================================================== --- trunk/punit/src/org/punit/watcher/Watcher.java (revision 228) +++ trunk/punit/src/org/punit/watcher/Watcher.java (working copy) @@ -2,22 +2,22 @@ package org.punit.watcher; -import java.io.*; +import java.io.Serializable; -import org.punit.type.*; +import org.punit.type.Name; -public interface Watcher extends PUnitName, Serializable, Cloneable { - +public interface Watcher extends Name, Serializable, Cloneable { + public void start(); public void stop(); public double value(); - + public String stringValue(); - + public String unit(); - + public Watcher cloneSelf(); - + } Index: trunk/punit/src/org/punit/exception/ConcurrentException.java =================================================================== --- trunk/punit/src/org/punit/exception/ConcurrentException.java (revision 228) +++ trunk/punit/src/org/punit/exception/ConcurrentException.java (working copy) @@ -2,10 +2,13 @@ package org.punit.exception; -import java.io.*; -import java.util.*; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.util.Vector; -import org.punit.util.*; +import org.punit.util.ReporterUtil; +import org.punit.util.Traverser; +import org.punit.util.TraverserUtil; /** * Exception for concurrent runner. There might be not only one exception thrown Index: trunk/punit/src/org/punit/exception/OutOfMemoryException.java =================================================================== --- trunk/punit/src/org/punit/exception/OutOfMemoryException.java (revision 0) +++ trunk/punit/src/org/punit/exception/OutOfMemoryException.java (revision 0) @@ -0,0 +1,15 @@ +/* (C) Copyright 2007, by Andrew Zhang */ + +package org.punit.exception; + +/** + * The root exception of all PUnit exception. + */ +public class OutOfMemoryException extends RuntimeException { + + private static final long serialVersionUID = -2694385721230707311L; + + public OutOfMemoryException(OutOfMemoryError e) { + super("Framework cannot reclaim its resources", e); + } +} Property changes on: trunk/punit/src/org/punit/exception/OutOfMemoryException.java ___________________________________________________________________ Name: svn:executable + * Index: trunk/punit/src/org/punit/exception/PUnitIOException.java =================================================================== --- trunk/punit/src/org/punit/exception/PUnitIOException.java (revision 228) +++ trunk/punit/src/org/punit/exception/PUnitIOException.java (working copy) @@ -1,15 +0,0 @@ -/* (C) Copyright 2007, by Andrew Zhang */ - -package org.punit.exception; - -/** - * Indicates an IO error. - */ -public class PUnitIOException extends PUnitException { - - private static final long serialVersionUID = 7098221975109413569L; - - public PUnitIOException(Throwable e) { - super(e); - } -} Index: trunk/punit/src/org/punit/exception/IOException.java =================================================================== --- trunk/punit/src/org/punit/exception/IOException.java (revision 0) +++ trunk/punit/src/org/punit/exception/IOException.java (revision 0) @@ -0,0 +1,15 @@ +/* (C) Copyright 2007, by Andrew Zhang */ + +package org.punit.exception; + +/** + * Indicates an IO error. + */ +public class IOException extends PUnitException { + + private static final long serialVersionUID = 7098221975109413569L; + + public IOException(Throwable e) { + super(e); + } +} Index: trunk/punit/src/org/punit/exception/PUnitException.java =================================================================== --- trunk/punit/src/org/punit/exception/PUnitException.java (revision 228) +++ trunk/punit/src/org/punit/exception/PUnitException.java (working copy) @@ -3,16 +3,18 @@ package org.punit.exception; /** - * The root exception of all punit exception. + * The root exception of all PUnit exception. */ +public abstract class PUnitException extends RuntimeException { -public abstract class PUnitException extends RuntimeException { - public PUnitException() { - } - + public PUnitException(Throwable e) { super(e); } + + public PUnitException(String message, Throwable e) { + super(message, e); + } } Index: trunk/punit/src/punit.properties =================================================================== --- trunk/punit/src/punit.properties (revision 228) +++ trunk/punit/src/punit.properties (working copy) @@ -9,11 +9,11 @@ runner.02=solo.param runner.03=concurrent runner.04=concurrent.param -runner.05=PUnitXXXRunner className [result path] -watcher.01=bytes -watcher.02=ms -watcher.03=memory -watcher.04=time +runner.arguments=\ arguments +watcher.bytes=bytes +watcher.ms=ms +watcher.memory=Memory +watcher.time=Time reporter.01=result reporter.02=overview PDFRender.01=PUnit result\n Index: trunk/punit.samples/src/samples/ListTestClass.java =================================================================== --- trunk/punit.samples/src/samples/ListTestClass.java (revision 228) +++ trunk/punit.samples/src/samples/ListTestClass.java (working copy) @@ -1,41 +1,42 @@ package samples; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.Vector; -import org.punit.type.*; +import org.punit.type.Concurrent; public class ListTestClass implements Concurrent { - - private static final int LIST_COUNT = 10000; - private static Object element = new Object(); - private Random indexGenerator = new Random();; - - public void testInsertArrayList() { - ArrayList arrayList = new ArrayList(LIST_COUNT); - insertSequence(arrayList); - insertRandom(arrayList); - } - - public void testInsertVector() { - Vector vector = new Vector(LIST_COUNT); - insertSequence(vector); - insertRandom(vector); - } - - @SuppressWarnings("unchecked") - public void insertSequence(List list) { - for (int i = 0; i < LIST_COUNT; ++i) { - list.add(element); - } - } - - @SuppressWarnings("unchecked") - public void insertRandom(List list) { - for (int i = 0; i < LIST_COUNT; ++i) { - list.add(indexGenerator .nextInt(LIST_COUNT),element); - } - } + private static final int LIST_COUNT = 10000; + private static Object element = new Object(); + private Random indexGenerator = new Random(); + + public void testInsertArrayList() { + ArrayList arrayList = new ArrayList(LIST_COUNT); + insertSequence(arrayList); + insertRandom(arrayList); + } + + public void testInsertVector() { + Vector vector = new Vector(LIST_COUNT); + insertSequence(vector); + insertRandom(vector); + } + + public void insertSequence(List list) { + for (int i = 0; i < LIST_COUNT; ++i) { + list.add(element); + } + } + + public void insertRandom(List list) { + for (int i = 0; i < LIST_COUNT; ++i) { + list.add(indexGenerator.nextInt(LIST_COUNT), element); + } + } + public int concurrentCount() { return 5; } Index: trunk/punit.samples/src/samples/LoopTestSample.java =================================================================== --- trunk/punit.samples/src/samples/LoopTestSample.java (revision 228) +++ trunk/punit.samples/src/samples/LoopTestSample.java (working copy) @@ -27,11 +27,11 @@ public void test2() { } - public long toAbort() { + public long toStop() { return TIMEOUT; } - public long toStop() { + public long toWork() { return TIMEOUT; } } Index: trunk/punit.samples/src/samples/MultiThreadRunnerSample.java =================================================================== --- trunk/punit.samples/src/samples/MultiThreadRunnerSample.java (revision 228) +++ trunk/punit.samples/src/samples/MultiThreadRunnerSample.java (working copy) @@ -1,20 +1,21 @@ /* (C) Copyright 2007, by Andrew Zhang */ package samples; -import org.punit.runner.*; +import org.punit.runner.ExecutorPoolImpl; +import org.punit.runner.SoloRunner; public class MultiThreadRunnerSample { public static void main(String[] args) { /* - * Users can use either PUnitSoloRunner or PUnitConcurrentRunner to run - * any test classes and test suites. The reporters can be configured by - * runner.addPUnitEventListener, including + * Users can use either SoloRunner or ConcurrentRunner + * to run any test classes and test suites. The reporters can be + * configured by runner.addtEventListener, including * Console(default)/File/Image/PDF. * * The result can be found in ./result/ folder. */ SoloRunner runner = new SoloRunner(); - // runner = new PUnitConcurrentRunner(); + // runner = new ConcurrentRunner(); runner.setExecutorPool(new ExecutorPoolImpl(10)); runner.run(AllTestSuite.class); } Index: trunk/punit.samples/src/samples/AllTestSuite.java =================================================================== --- trunk/punit.samples/src/samples/AllTestSuite.java (revision 228) +++ trunk/punit.samples/src/samples/AllTestSuite.java (working copy) @@ -2,11 +2,11 @@ package samples; -import org.punit.type.*; +import org.punit.type.TestSuite; -public class AllTestSuite implements PUnitTestSuite { +public class AllTestSuite implements TestSuite { - public Class[] testSuite() { + public Class[] testSuite() { return new Class[] { JUnitTestClass.class, SimpleTestClass.class, Index: trunk/punit.samples/src/samples/PUnitTestClass.java =================================================================== --- trunk/punit.samples/src/samples/PUnitTestClass.java (revision 228) +++ trunk/punit.samples/src/samples/PUnitTestClass.java (working copy) @@ -1,8 +1,8 @@ package samples; -import org.punit.type.*; +import org.punit.type.Test; -public class PUnitTestClass implements PUnitTest { +public class PUnitTestClass implements Test { public void setUpBeforeWatchers() throws Exception { System.out.println("This setup will not be caculated into the execution time"); //$NON-NLS-1$ Index: trunk/punit.samples/src/samples/LongTimeExecutionJUnitTestSuite.java =================================================================== --- trunk/punit.samples/src/samples/LongTimeExecutionJUnitTestSuite.java (revision 228) +++ trunk/punit.samples/src/samples/LongTimeExecutionJUnitTestSuite.java (working copy) @@ -1,6 +1,7 @@ package samples; -import junit.framework.*; +import junit.framework.Test; +import junit.framework.TestSuite; public class LongTimeExecutionJUnitTestSuite { @@ -8,16 +9,15 @@ public static Test suite() { TestSuite suite = new TestSuite("Test for long time execution"); //$NON-NLS-1$ // $JUnit-BEGIN$ - Class[] testCases = testCases(); - for (int i = 0; i < testCases.length; ++i) { - suite.addTestSuite(testCases[i]); + for (Class c: testSuite()) { + suite.addTestSuite(c); } // $JUnit-END$ return suite; } - public static Class[] testCases() { + public static final Class[] testSuite() { return new Class[] { LongTimeExecutionTest1.class, - LongTimeExecutionTest2.class, }; + LongTimeExecutionTest2.class }; } } Index: trunk/punit.samples/src/samples/ParamTestClass.java =================================================================== --- trunk/punit.samples/src/samples/ParamTestClass.java (revision 228) +++ trunk/punit.samples/src/samples/ParamTestClass.java (working copy) @@ -2,6 +2,7 @@ import org.punit.runner.*; import org.punit.type.*; +import org.punit.type.Parameter; public class ParamTestClass implements Parameterizable { Index: trunk/punit.samples/src/samples/LongTimeExecutionPUnitTestSuite.java =================================================================== --- trunk/punit.samples/src/samples/LongTimeExecutionPUnitTestSuite.java (revision 228) +++ trunk/punit.samples/src/samples/LongTimeExecutionPUnitTestSuite.java (working copy) @@ -2,10 +2,10 @@ import org.punit.type.*; -public class LongTimeExecutionPUnitTestSuite implements PUnitTestSuite{ +public class LongTimeExecutionPUnitTestSuite implements TestSuite{ - public Class[] testSuite() { - return LongTimeExecutionJUnitTestSuite.testCases(); + public Class[] testSuite() { + return LongTimeExecutionJUnitTestSuite.testSuite(); } } Index: trunk/punit.samples/src/samples/RunnerSamples.java =================================================================== --- trunk/punit.samples/src/samples/RunnerSamples.java (revision 228) +++ trunk/punit.samples/src/samples/RunnerSamples.java (working copy) @@ -1,24 +1,25 @@ /* (C) Copyright 2007, by Andrew Zhang */ package samples; -import org.punit.reporter.chart.*; -import org.punit.reporter.chart.image.*; -import org.punit.reporter.chart.pdf.*; -import org.punit.reporter.stream.file.*; -import org.punit.runner.*; +import org.punit.reporter.chart.OverviewReporter; +import org.punit.reporter.chart.image.ImageRender; +import org.punit.reporter.chart.pdf.PDFRender; +import org.punit.reporter.stream.file.FileLogger; +import org.punit.runner.ExecutorPoolImpl; +import org.punit.runner.SoloRunner; public class RunnerSamples { public static void main(String[] args) { /* - * Users can use either PUnitSoloRunner or PUnitConcurrentRunner to run - * any test classes and test suites. The reporters can be configured by - * runner.addPUnitEventListener, including - * Console(default)/File/Image/PDF. + * Users can use either SoloRunner or ConcurrentRunner + * to run any test classes and test suites. The reporters can be + * configured by runner.addEventListener(EventListener e), + * including Console(default)/File/Image/PDF. * * The result can be found in ./result/ folder. */ SoloRunner runner = new SoloRunner(); - // runner = new PUnitConcurrentRunner(); + // runner = new ConcurrentRunner(); runner.setExecutorPool(new ExecutorPoolImpl(5)); runner.addEventListener(new FileLogger()); runner.addEventListener(new OverviewReporter(new ImageRender())); Index: trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java =================================================================== --- trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java (revision 228) +++ trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java (working copy) @@ -18,6 +18,7 @@ return _delegate.getCheckMethod(method); } + @SuppressWarnings("unchecked") public boolean isExcluded(Class clazz) { return false; } @@ -51,6 +52,7 @@ return method.getAnnotation(Test.class); } + @SuppressWarnings("unchecked") public Method getAfterClassMethod(Class test) { Method method = AnnotationUtil.getMethodByAnnotation(test, AfterClass.class); if(method == null) { @@ -59,6 +61,7 @@ return method; } + @SuppressWarnings("unchecked") public Method getBeforeClassMethod(Class test) { Method method = AnnotationUtil.getMethodByAnnotation(test, BeforeClass.class); if(method == null) { @@ -67,6 +70,7 @@ return method; } + @SuppressWarnings("unchecked") public Method getSetupMethod(Class test) { Method method = AnnotationUtil.getMethodByAnnotation(test, Before.class); if(method == null) { @@ -75,6 +79,7 @@ return method; } + @SuppressWarnings("unchecked") public Method getTearDownMethod(Class test) { Method method = AnnotationUtil.getMethodByAnnotation(test, After.class); if(method == null) { @@ -83,11 +88,11 @@ return method; } - public long toAbort(Object testInstance) { + public long toStop(Object testInstance) { return 0; } - public long toStop(Object testInstance) { + public long toWork(Object testInstance) { return 0; } Index: trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java =================================================================== --- trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java (revision 228) +++ trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java (working copy) @@ -2,11 +2,17 @@ package org.punit.convention; -import java.lang.reflect.*; +import java.lang.reflect.Method; -import org.punit.annotation.*; -import org.punit.annotation.Test.*; -import org.punit.util.*; +import org.punit.annotation.After; +import org.punit.annotation.AfterClass; +import org.punit.annotation.Before; +import org.punit.annotation.BeforeClass; +import org.punit.annotation.Ignore; +import org.punit.annotation.Test; +import org.punit.annotation.Test.NoException; +import org.punit.util.AnnotationUtil; +import org.punit.util.ReflectionUtil; public class AnnotationConvention implements Convention { @@ -76,6 +82,7 @@ return (Test) clazz.getAnnotation(Test.class); } + @SuppressWarnings("unchecked") public Method getAfterClassMethod(Class test) { Method method = AnnotationUtil.getMethodByAnnotation(test, AfterClass.class); if(method == null) { @@ -84,6 +91,7 @@ return method; } + @SuppressWarnings("unchecked") public Method getBeforeClassMethod(Class test) { Method method = AnnotationUtil.getMethodByAnnotation(test, BeforeClass.class); if(method == null) { @@ -92,6 +100,7 @@ return method; } + @SuppressWarnings("unchecked") public Method getSetupMethod(Class test) { Method method = AnnotationUtil.getMethodByAnnotation(test, Before.class); if(method == null) { @@ -100,6 +109,7 @@ return method; } + @SuppressWarnings("unchecked") public Method getTearDownMethod(Class test) { Method method = AnnotationUtil.getMethodByAnnotation(test, After.class); if(method == null) { @@ -108,11 +118,11 @@ return method; } - public long toAbort(Object testInstance) { + public long toStop(Object testInstance) { return 0; } - public long toStop(Object testInstance) { + public long toWork(Object testInstance) { return 0; } Index: trunk/punit.extension/src/org/punit/reporter/chart/ChartUtil.java =================================================================== --- trunk/punit.extension/src/org/punit/reporter/chart/ChartUtil.java (revision 228) +++ trunk/punit.extension/src/org/punit/reporter/chart/ChartUtil.java (working copy) @@ -2,17 +2,23 @@ package org.punit.reporter.chart; -import java.awt.*; -import java.io.*; +import java.awt.Color; +import java.io.File; +import java.io.FileOutputStream; +import java.io.ObjectOutputStream; -import org.jfree.chart.*; -import org.jfree.chart.axis.*; -import org.jfree.chart.plot.*; -import org.jfree.chart.renderer.category.*; -import org.jfree.chart.title.*; -import org.jfree.data.category.*; -import org.jfree.ui.*; -import org.punit.exception.*; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.CategoryAxis; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.plot.CategoryPlot; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.renderer.category.LineAndShapeRenderer; +import org.jfree.chart.title.LegendTitle; +import org.jfree.data.category.CategoryDataset; +import org.jfree.data.category.DefaultCategoryDataset; +import org.jfree.ui.RectangleInsets; +import org.punit.exception.IOException; public class ChartUtil { @@ -62,14 +68,14 @@ oos = new ObjectOutputStream(fos); oos.writeObject(dataset); oos.close(); - } catch (IOException e) { - throw new PUnitIOException(e); + } catch (java.io.IOException e) { + throw new IOException(e); } finally { if (oos != null) { try { oos.close(); - } catch (IOException e) { - throw new PUnitIOException(e); + } catch (java.io.IOException e) { + throw new IOException(e); } } } Index: trunk/punit.extension/src/org/punit/reporter/chart/ChartRender.java =================================================================== --- trunk/punit.extension/src/org/punit/reporter/chart/ChartRender.java (revision 228) +++ trunk/punit.extension/src/org/punit/reporter/chart/ChartRender.java (working copy) @@ -2,10 +2,10 @@ package org.punit.reporter.chart; -import java.io.*; +import java.io.Serializable; -import org.jfree.chart.*; -import org.punit.runner.*; +import org.jfree.chart.JFreeChart; +import org.punit.runner.Runner; /** * Interface for rendering a chart. @@ -17,12 +17,12 @@ * @param clazz * @param runner */ - public void onRunnerStart(Class clazz, Runner runner); + public void onRunnerStart(Class clazz, Runner runner); /** * It is triggered the end of the runner. Some render may close itself. */ - public void onRunnerEnd(Class clazz, Runner runner); + public void onRunnerEnd(Class clazz, Runner runner); /** * Renders a chart. prefixFileName is the suggested name of this chart. Index: trunk/punit.extension/src/org/punit/reporter/chart/image/ImageRender.java =================================================================== --- trunk/punit.extension/src/org/punit/reporter/chart/image/ImageRender.java (revision 228) +++ trunk/punit.extension/src/org/punit/reporter/chart/image/ImageRender.java (working copy) @@ -2,14 +2,14 @@ package org.punit.reporter.chart.image; -import java.awt.image.*; -import java.io.*; +import java.awt.image.BufferedImage; +import java.io.File; -import javax.imageio.*; +import javax.imageio.ImageIO; -import org.jfree.chart.*; -import org.punit.reporter.chart.*; -import org.punit.runner.*; +import org.jfree.chart.JFreeChart; +import org.punit.reporter.chart.ChartRender; +import org.punit.runner.Runner; /** * ImageRender renders a chart as a image file. Each dataset will be rendered as @@ -60,16 +60,16 @@ try { ImageIO.write(chartImage, _format, new File(prefixFileName + _format)); - } catch (IOException e) { + } catch (java.io.IOException e) { e.printStackTrace(); } } - public void onRunnerStart(Class clazz, Runner runner) { + public void onRunnerStart(Class clazz, Runner runner) { // nothing needs to do } - public void onRunnerEnd(Class clazz, Runner runner) { + public void onRunnerEnd(Class clazz, Runner runner) { // nothing needs to do } Index: trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java =================================================================== --- trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java (revision 228) +++ trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java (working copy) @@ -2,32 +2,41 @@ package org.punit.reporter.chart; -import java.io.*; -import java.lang.reflect.*; -import java.util.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.ObjectInputStream; +import java.lang.reflect.Method; +import java.util.Hashtable; +import java.util.LinkedList; +import java.util.List; -import org.jfree.chart.*; -import org.jfree.data.category.*; -import org.punit.events.*; -import org.punit.exception.*; -import org.punit.message.*; -import org.punit.reporter.chart.image.*; -import org.punit.runner.*; -import org.punit.type.*; -import org.punit.util.*; -import org.punit.watcher.*; +import org.jfree.chart.JFreeChart; +import org.jfree.data.category.DefaultCategoryDataset; +import org.punit.events.EventListener; +import org.punit.exception.IOException; +import org.punit.message.Messages; +import org.punit.reporter.chart.image.ImageConstants; +import org.punit.runner.Runner; +import org.punit.runner.RunnerProperties; +import org.punit.type.TestSuite; +import org.punit.type.VM; +import org.punit.util.IOUtil; +import org.punit.util.ReporterUtil; +import org.punit.util.Traverser; +import org.punit.util.TraverserUtil; +import org.punit.watcher.Watcher; -public abstract class AbstractChartReporter implements PUnitEventListener { +public abstract class AbstractChartReporter implements EventListener { - private Hashtable _datasets = new Hashtable(); // + private Hashtable _datasets = new Hashtable(); - private LinkedList _currentSuiteStack = new LinkedList(); + private LinkedList _currentSuiteStack = new LinkedList(); protected ChartRender _render; protected transient RunnerProperties _runnerProperties; - protected transient Class _currentClass; + protected transient Class _currentClass; public AbstractChartReporter(ChartRender render) { _render = render; @@ -35,23 +44,21 @@ protected abstract DatasetKey getKey(Watcher watcher); - public void onRunnerStart(Class clazz, Runner runner) { + @SuppressWarnings("unchecked") + public void onRunnerStart(final Class clazz, Runner runner) { _runnerProperties = runner.properties(); if (!isIntermediate()) { _render.onRunnerStart(clazz, runner); } } + @SuppressWarnings("unchecked") public void onRunnerEnd(final Class clazz, final Runner runner) { - Set keySet = datasets().keySet(); - TraverserUtil.traverse(keySet.iterator(), new Traverser() { - public void traverse(Object obj) { - DatasetKey key = (DatasetKey) obj; - DefaultCategoryDataset dataset = getDataset(runner, key); - String fileName = generateResultFileNamePrefix(runner, key); - storeDataset(dataset, fileName, key); - } - }); + for (DatasetKey key : datasets().keySet()) { + DefaultCategoryDataset dataset = getDataset(runner, key); + String fileName = generateResultFileNamePrefix(runner, key); + storeDataset(dataset, fileName, key); + } if (!isIntermediate()) { _render.onRunnerEnd(clazz, runner); } @@ -92,13 +99,13 @@ ois = new ObjectInputStream(fis); return (DefaultCategoryDataset) ois.readObject(); } catch (Exception e) { - throw new PUnitIOException(e); + throw new IOException(e); } finally { if (ois != null) { try { ois.close(); - } catch (IOException e) { - throw new PUnitIOException(e); + } catch (java.io.IOException e) { + throw new IOException(e); } } IOUtil.deleteFile(childFileName); @@ -151,9 +158,8 @@ return _runnerProperties.isParent; } - private final DefaultCategoryDataset getDatasetOrNew(Object key) { - DefaultCategoryDataset dataset = (DefaultCategoryDataset) _datasets - .get(key); + private final DefaultCategoryDataset getDatasetOrNew(DatasetKey key) { + DefaultCategoryDataset dataset = _datasets.get(key); if (dataset == null) { dataset = new DefaultCategoryDataset(); putDataset(key, dataset); @@ -161,12 +167,11 @@ return dataset; } - @SuppressWarnings("unchecked") - protected final void putDataset(Object key, DefaultCategoryDataset dataset) { + protected final void putDataset(DatasetKey key, DefaultCategoryDataset dataset) { _datasets.put(key, dataset); } - protected final Hashtable datasets() { + protected final Hashtable datasets() { return _datasets; } @@ -174,27 +179,29 @@ return true; } + @SuppressWarnings("unchecked") public void onClassStart(Class clazz) { _currentClass = clazz; } + @SuppressWarnings("unchecked") public void onClassEnd(Class clazz) { _currentClass = null; } - @SuppressWarnings("unchecked") - public void onSuiteStart(PUnitTestSuite suite) { + public void onSuiteStart(TestSuite suite) { _currentSuiteStack.add(suite); } - public void onSuiteEnd(PUnitTestSuite suite) { + public void onSuiteEnd(TestSuite suite) { _currentSuiteStack.removeLast(); } - public PUnitTestSuite currentTestSuite() { - return (PUnitTestSuite) _currentSuiteStack.getLast(); + public TestSuite currentTestSuite() { + return _currentSuiteStack.getLast(); } + @SuppressWarnings("unchecked") public synchronized void onMethodEnd(final Method method, final Object testInstance, final Object[] params, final Throwable t, List watchers) { TraverserUtil.traverse(watchers.iterator(), new Traverser() { @@ -221,10 +228,12 @@ // nothing needs to do } + @SuppressWarnings("unchecked") public void onWatchersStart(List watchers) { // nothing needs to do } + @SuppressWarnings("unchecked") public void onWatchersEnd(List watchers) { // nothing needs to do } Index: trunk/punit.extension/src/org/punit/reporter/chart/TestClassReporter.java =================================================================== --- trunk/punit.extension/src/org/punit/reporter/chart/TestClassReporter.java (revision 228) +++ trunk/punit.extension/src/org/punit/reporter/chart/TestClassReporter.java (working copy) @@ -19,9 +19,9 @@ public static class DatasetKeyImpl implements DatasetKey { private Watcher _watcher; - private Class _clazz; + private Class _clazz; - public DatasetKeyImpl(Watcher watcher, Class clazz) { + public DatasetKeyImpl(Watcher watcher, Class clazz) { _watcher = watcher; _clazz = clazz; } Index: trunk/punit.extension/src/org/punit/reporter/chart/pdf/PDFRender.java =================================================================== --- trunk/punit.extension/src/org/punit/reporter/chart/pdf/PDFRender.java (revision 228) +++ trunk/punit.extension/src/org/punit/reporter/chart/pdf/PDFRender.java (working copy) @@ -2,19 +2,28 @@ package org.punit.reporter.chart.pdf; -import java.awt.*; +import java.awt.Graphics2D; import java.awt.Rectangle; -import java.io.*; +import java.io.FileOutputStream; -import org.jfree.chart.*; -import org.punit.exception.*; -import org.punit.message.*; -import org.punit.reporter.chart.*; -import org.punit.runner.*; -import org.punit.util.*; +import org.jfree.chart.JFreeChart; +import org.punit.exception.IOException; +import org.punit.message.Messages; +import org.punit.reporter.chart.ChartRender; +import org.punit.runner.Runner; +import org.punit.util.ReporterUtil; -import com.lowagie.text.*; -import com.lowagie.text.pdf.*; +import com.lowagie.text.Anchor; +import com.lowagie.text.BadElementException; +import com.lowagie.text.Chunk; +import com.lowagie.text.Document; +import com.lowagie.text.DocumentException; +import com.lowagie.text.Element; +import com.lowagie.text.ImgTemplate; +import com.lowagie.text.Paragraph; +import com.lowagie.text.pdf.DefaultFontMapper; +import com.lowagie.text.pdf.PdfTemplate; +import com.lowagie.text.pdf.PdfWriter; public class PDFRender implements ChartRender { @@ -37,7 +46,7 @@ _width = width; } - public void onRunnerStart(Class clazz, Runner runner) { + public void onRunnerStart(Class clazz, Runner runner) { String fileName = ReporterUtil.generateFileName(clazz, runner) + PDFConstants.POSTFIX; initPDFDocument(fileName); @@ -50,7 +59,7 @@ _writer = PdfWriter.getInstance(_document, new FileOutputStream( fileName)); } catch (Exception e) { - throw new PUnitIOException(e); + throw new IOException(e); } _document.open(); } @@ -64,14 +73,14 @@ try { _document.add(new ImgTemplate(template)); } catch (BadElementException e) { - throw new PUnitIOException(e); + throw new IOException(e); } catch (DocumentException e) { - throw new PUnitIOException(e); + throw new IOException(e); } _document.newPage(); } - public void onRunnerEnd(Class clazz, Runner runner) { + public void onRunnerEnd(Class clazz, Runner runner) { _document.close(); _writer.close(); } @@ -86,7 +95,7 @@ try { _document.add(paragraph); } catch (DocumentException e) { - throw new PUnitIOException(e); + throw new IOException(e); } _document.newPage(); } Index: trunk/punit.extension/src/org/punit/reporter/chart/TestSuiteReporter.java =================================================================== --- trunk/punit.extension/src/org/punit/reporter/chart/TestSuiteReporter.java (revision 228) +++ trunk/punit.extension/src/org/punit/reporter/chart/TestSuiteReporter.java (working copy) @@ -20,9 +20,9 @@ public static class DatasetKeyImpl implements DatasetKey { private Watcher _watcher; - private PUnitTestSuite _testSuite; + private TestSuite _testSuite; - public DatasetKeyImpl(Watcher watcher, PUnitTestSuite suite) { + public DatasetKeyImpl(Watcher watcher, TestSuite suite) { _watcher = watcher; _testSuite = suite; } Index: trunk/punit.extension/src/org/punit/reporter/chart/DatasetKey.java =================================================================== --- trunk/punit.extension/src/org/punit/reporter/chart/DatasetKey.java (revision 228) +++ trunk/punit.extension/src/org/punit/reporter/chart/DatasetKey.java (working copy) @@ -5,6 +5,6 @@ import org.punit.type.*; import org.punit.watcher.*; -public interface DatasetKey extends PUnitName { +public interface DatasetKey extends Name { public Watcher watcher(); } Index: trunk/punit.extension/src/org/punit/runner/ExecutorPoolImpl.java =================================================================== --- trunk/punit.extension/src/org/punit/runner/ExecutorPoolImpl.java (revision 228) +++ trunk/punit.extension/src/org/punit/runner/ExecutorPoolImpl.java (working copy) @@ -29,7 +29,7 @@ _pool.shutdown(); _pool.awaitTermination(Integer.MAX_VALUE, TimeUnit.SECONDS); } catch (InterruptedException e) { - throw new PUnitIOException(e); + throw new IOException(e); } } Index: trunk/punit.extension/src/org/punit/util/AnnotationUtil.java =================================================================== --- trunk/punit.extension/src/org/punit/util/AnnotationUtil.java (revision 228) +++ trunk/punit.extension/src/org/punit/util/AnnotationUtil.java (working copy) @@ -7,7 +7,7 @@ public class AnnotationUtil { - public static Method getMethodByAnnotation(Class clazz, Class annotationClass) { + public static Method getMethodByAnnotation(Class clazz, Class annotationClass) { Method[] methods = clazz.getDeclaredMethods(); for(int i = 0; i < methods.length; ++i) { Method method = methods[i]; Index: trunk/punit.test/src/tests/samples/VMsSample.java =================================================================== --- trunk/punit.test/src/tests/samples/VMsSample.java (revision 228) +++ trunk/punit.test/src/tests/samples/VMsSample.java (working copy) @@ -1,12 +1,12 @@ package tests.samples; -import java.io.*; +import java.io.File; -import org.punit.runner.*; -import org.punit.type.*; -import org.punit.util.*; +import org.punit.runner.SoloRunner; +import org.punit.type.VM; +import org.punit.util.IOUtil; -import tests.util.*; +import tests.util.TestUtil; public class VMsSample { Index: trunk/punit.test/src/tests/samples/PUnitTestCaseSample.java =================================================================== --- trunk/punit.test/src/tests/samples/PUnitTestCaseSample.java (revision 228) +++ trunk/punit.test/src/tests/samples/PUnitTestCaseSample.java (working copy) @@ -7,7 +7,7 @@ public class PUnitTestCaseSample { public static void main(String[] args) { - new SoloRunner().run(PUnitTestClass.class); + new SoloRunner().run(TestClass3.class); } } Index: trunk/punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java (working copy) @@ -40,7 +40,7 @@ } public void testBuildTestMethods3() { - Object[] methods = _builder.buildTestMethods(TestClass3.class) + Object[] methods = _builder.buildTestMethods(AlphabeticalTestClass.class) .toArray(); String[] names = TestUtil.toMethodNameArray(methods); AssertUtil.assertArray(names, new String[] { "test1", "test2", "testa", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ Index: trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractTestMethodRunnerTest.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractTestMethodRunnerTest.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractTestMethodRunnerTest.java (working copy) @@ -17,6 +17,7 @@ public class AbstractTestMethodRunnerTest extends TestCase { private MockTestMethodRunnerTest _mockRunner = new MockTestMethodRunnerTest(); + @SuppressWarnings("unchecked") public void testWatchers() { List watchers = _mockRunner.watchers(); assertEquals(1, watchers.size()); // time, and memory watchers Index: trunk/punit.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java (working copy) @@ -50,7 +50,7 @@ public void testGetExpectedException() { Method method; - Class exception; + Class exception; method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test1", new Class[] {}); //$NON-NLS-1$ exception = _filter.getExpectedException(method); @@ -72,7 +72,7 @@ assertEquals(test.concurrentCount(), count); method = ReflectionUtil.getMethod(AnnotationTestClass.class, "test1", new Class[] {}); //$NON-NLS-1$ - assertEquals(0, _filter.getConcurrentCount(new TestClass(), method)); + assertEquals(0, _filter.getConcurrentCount(new TestClass0(), method)); } public void testGetConcurrentCountClass() { Index: trunk/punit.test/src/tests/api/org/punit/convention/JUnitAnnotationConventionTest.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/convention/JUnitAnnotationConventionTest.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/convention/JUnitAnnotationConventionTest.java (working copy) @@ -56,7 +56,7 @@ public void testGetExpectedException() { Method method; - Class exception; + Class exception; method = ReflectionUtil.getMethod(JUnitAnnotationTestClass.class, "_test1", new Class[] {}); //$NON-NLS-1$ exception = _filter.getExpectedException(method); @@ -77,8 +77,8 @@ int count = _filter.getConcurrentCount(test, method); assertEquals(test.concurrentCount(), count); - method = ReflectionUtil.getMethod(TestClass.class, "test1", new Class[] {}); //$NON-NLS-1$ - assertEquals(0, _filter.getConcurrentCount(new TestClass(), method)); + method = ReflectionUtil.getMethod(TestClass0.class, "test1", new Class[] {}); //$NON-NLS-1$ + assertEquals(0, _filter.getConcurrentCount(new TestClass0(), method)); } public void testGetConcurrentCountClass() { Index: trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java (working copy) @@ -42,37 +42,37 @@ assertEquals(test.concurrentCount(), count); method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$ - assertEquals(0, _convention.getConcurrentCount(new TestClass(), method)); + assertEquals(0, _convention.getConcurrentCount(new TestClass0(), method)); } public void testGetSetUpMethod() { - assertNotNull(_convention.getSetupMethod(TestClass.class)); + assertNotNull(_convention.getSetupMethod(TestClass0.class)); assertNull(_convention.getSetupMethod(TestClass1.class)); } public void testGetTearDownMethod() { - assertNotNull(_convention.getTearDownMethod(TestClass.class)); + assertNotNull(_convention.getTearDownMethod(TestClass0.class)); assertNull(_convention.getTearDownMethod(TestClass1.class)); } public void testGetBeforeClass() { - assertNotNull(_convention.getBeforeClassMethod(TestClass.class)); + assertNotNull(_convention.getBeforeClassMethod(TestClass0.class)); assertNull(_convention.getBeforeClassMethod(TestClass1.class)); } public void testGetAfterClass() { - assertNotNull(_convention.getAfterClassMethod(TestClass.class)); + assertNotNull(_convention.getAfterClassMethod(TestClass0.class)); assertNull(_convention.getAfterClassMethod(TestClass1.class)); } public void testIsLoop() { assertTrue(_convention.isLoopTest(new LoopTestClass())); - assertFalse(_convention.isLoopTest(new TestClass())); + assertFalse(_convention.isLoopTest(new TestClass0())); } - public void testGetToStop() { - assertEquals(LoopTestClass.TIMEOUT, _convention.toStop(new LoopTestClass())); - assertEquals(0, _convention.toStop(new TestClass())); + public void testGetToWork() { + assertEquals(LoopTestClass.TIMEOUT, _convention.toWork(new LoopTestClass())); + assertEquals(0, _convention.toWork(new TestClass0())); } public void test1() { Index: trunk/punit.test/src/tests/api/org/punit/reporter/stream/StreamLoggerTest.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/reporter/stream/StreamLoggerTest.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/reporter/stream/StreamLoggerTest.java (working copy) @@ -1,13 +1,14 @@ package tests.api.org.punit.reporter.stream; -import java.io.*; -import java.util.logging.*; +import java.io.OutputStream; +import java.io.PrintStream; +import java.util.logging.Level; -import junit.framework.*; +import junit.framework.TestCase; -import org.punit.reporter.stream.console.*; +import org.punit.reporter.stream.console.ConsoleLogger; -import tests.util.*; +import tests.util.TestUtil; public class StreamLoggerTest extends TestCase { ConsoleLogger _logger = new ConsoleLogger(); Index: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java (working copy) @@ -1,53 +1,52 @@ package tests.api.org.punit.all; -import junit.framework.*; -import tests.api.org.punit.assertion.*; -import tests.api.org.punit.convention.*; -import tests.api.org.punit.exception.*; -import tests.api.org.punit.method.builder.*; -import tests.api.org.punit.method.runner.*; -import tests.api.org.punit.reporter.stream.*; -import tests.api.org.punit.runner.*; -import tests.api.org.punit.suite.builder.*; -import tests.api.org.punit.util.*; -import tests.api.org.punit.watcher.*; -import extension.tests.api.org.punit.reporter.chart.*; -import extension.tests.api.org.punit.runner.*; +import junit.framework.Test; +import junit.framework.TestSuite; +import tests.api.org.punit.assertion.AssertTest; +import tests.api.org.punit.convention.AnnotationFilterTest; +import tests.api.org.punit.convention.JUnitAnnotationConventionTest; +import tests.api.org.punit.convention.NameConventionFilterTest; +import tests.api.org.punit.exception.ConcurrentExceptionTest; +import tests.api.org.punit.method.builder.TestMethodBuilderTest; +import tests.api.org.punit.method.runner.AbstractTestMethodRunnerTest; +import tests.api.org.punit.reporter.stream.StreamLoggerTest; +import tests.api.org.punit.runner.AbstractRunnerTest; +import tests.api.org.punit.runner.ConcurrentRunnerTest; +import tests.api.org.punit.runner.ExecutorPoolTest; +import tests.api.org.punit.runner.SoloRunnerTest; +import tests.api.org.punit.suite.builder.TestSuiteBuilderTest; +import tests.api.org.punit.util.LoggerUtilTest; +import tests.api.org.punit.util.ReflectionUtilTest; +import tests.api.org.punit.watcher.CustomWatcherTest; +import tests.api.org.punit.watcher.MemoryWatcherTest; +import tests.api.org.punit.watcher.TimeWatcherTest; +import extension.tests.api.org.punit.reporter.chart.AbstractChartReporterTest; +import extension.tests.api.org.punit.runner.SoloRunnerExtensionTest; public class AllTests { - + + @SuppressWarnings("unchecked") public static Test suite() { TestSuite suite = new TestSuite("Test for tests.api.org.punit"); //$NON-NLS-1$ // $JUnit-BEGIN$ - Class[] testCases = testCases(); - for (int i = 0; i < testCases.length; ++i) { - suite.addTestSuite(testCases[i]); + for (Class testCase : testSuite()) { + suite.addTestSuite(testCase); } // $JUnit-END$ return suite; } - public static Class[] testCases() { - return new Class[] { - AbstractChartReporterTest.class, - AbstractRunnerTest.class, - AbstractTestMethodRunnerTest.class, - AssertTest.class, - AnnotationFilterTest.class, - ConcurrentExceptionTest.class, - ConcurrentRunnerTest.class, - ExecutorPoolTest.class, - JUnitAnnotationConventionTest.class, - LoggerUtilTest.class, - MemoryWatcherTest.class, - NameConventionFilterTest.class, - ReflectionUtilTest.class, - StreamLoggerTest.class, - SoloRunnerExtensionTest.class, - SoloRunnerTest.class, - TestMethodBuilderTest.class, - TestSuiteBuilderTest.class, - TimeWatcherTest.class, - }; + public static final Class[] testSuite() { + return new Class[] { AbstractChartReporterTest.class, + AbstractRunnerTest.class, AbstractTestMethodRunnerTest.class, + AssertTest.class, AnnotationFilterTest.class, + ConcurrentExceptionTest.class, ConcurrentRunnerTest.class, + ExecutorPoolTest.class, JUnitAnnotationConventionTest.class, + LoggerUtilTest.class, MemoryWatcherTest.class, + CustomWatcherTest.class, NameConventionFilterTest.class, + ReflectionUtilTest.class, StreamLoggerTest.class, + SoloRunnerExtensionTest.class, SoloRunnerTest.class, + TestMethodBuilderTest.class, TestSuiteBuilderTest.class, + TimeWatcherTest.class }; } } Index: trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java (working copy) @@ -3,14 +3,14 @@ import org.punit.runner.*; import org.punit.type.*; -public class PUnitAllTests implements PUnitTestSuite { +public class PUnitAllTests implements TestSuite { public static void main(String[] args) { new SoloRunner().run(PUnitAllTests.class); } - public Class[] testSuite() { - return AllTests.testCases(); + public Class[] testSuite() { + return AllTests.testSuite(); } } Index: trunk/punit.test/src/tests/api/org/punit/runner/MockPUnitEventListener.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/runner/MockPUnitEventListener.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/runner/MockPUnitEventListener.java (working copy) @@ -1,95 +0,0 @@ -package tests.api.org.punit.runner; - -import java.lang.reflect.*; -import java.util.*; - -import junit.framework.*; - -import org.punit.events.*; -import org.punit.runner.*; -import org.punit.type.*; -import org.punit.watcher.*; - -public class MockPUnitEventListener implements PUnitEventListener { - - private static final long serialVersionUID = 1L; - - public boolean onRunnerEnd; - public boolean onRunnerStart; - public boolean onClassEnd; - public boolean onClassStart; - public boolean onMethodEnd; - public boolean onMethodStart; - public boolean onWatcherEnd; - public boolean onWatcherStart; - public boolean onWatchersEnd; - public boolean onWatchersStart; - public boolean onSuiteEnd; - public boolean onSuiteStart; - - public void onRunnerEnd(Class clazz, Runner runner) { - onRunnerEnd = true; - } - - public void onRunnerStart(Class clazz, Runner runner) { - onRunnerStart = true; - } - - public void onClassEnd(Class clazz) { - onClassEnd = true; - } - - public void onClassStart(Class clazz) { - onClassStart = true; - } - - public void onMethodEnd(Method method, Object testInstance, Object[] params, Throwable t, List watchers) { - onMethodEnd = true; - } - - public void onMethodStart(Method method, Object testInstance, Object[] params) { - onMethodStart = true; - } - - public void onWatcherEnd(Watcher watcher) { - onWatcherEnd = true; - } - - public void onWatcherStart(Watcher watcher) { - onWatcherStart = true; - } - - public void onWatchersEnd(List watchers) { - onWatchersEnd = true; - } - - public void onWatchersStart(List watchers) { - onWatchersStart = true; - } - - public void onSuiteEnd(PUnitTestSuite suite) { - onSuiteEnd = true; - } - - public void onSuiteStart(PUnitTestSuite suite) { - onSuiteStart = true; - } - - public void assertAllEventsInvoked() { - Assert.assertTrue(onRunnerEnd); - Assert.assertTrue(onRunnerStart); - Assert.assertTrue(onClassEnd); - Assert.assertTrue(onClassStart); - Assert.assertTrue(onMethodEnd); - Assert.assertTrue(onMethodStart); - Assert.assertTrue(onWatcherEnd); - Assert.assertTrue(onWatcherStart); - Assert.assertTrue(onWatchersEnd); - Assert.assertTrue(onWatchersStart); - } - - public boolean supportParentRunner() { - return true; - } - -} Index: trunk/punit.test/src/tests/api/org/punit/runner/MockEventListener.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/runner/MockEventListener.java (revision 0) +++ trunk/punit.test/src/tests/api/org/punit/runner/MockEventListener.java (revision 0) @@ -0,0 +1,102 @@ +package tests.api.org.punit.runner; + +import java.lang.reflect.Method; +import java.util.List; + +import junit.framework.Assert; + +import org.punit.events.EventListener; +import org.punit.runner.Runner; +import org.punit.type.TestSuite; +import org.punit.watcher.Watcher; + +public class MockEventListener implements EventListener { + + private static final long serialVersionUID = 1L; + + private boolean _onRunnerEnd; + private boolean _onRunnerStart; + private boolean _onClassEnd; + private boolean _onClassStart; + private boolean _onMethodEnd; + private boolean _onMethodStart; + private boolean _onWatcherEnd; + private boolean _onWatcherStart; + private boolean _onWatchersEnd; + private boolean _onWatchersStart; + public boolean _onSuiteEnd; + public boolean _onSuiteStart; + + @SuppressWarnings("unchecked") + public void onRunnerEnd(Class clazz, Runner runner) { + _onRunnerEnd = true; + } + + @SuppressWarnings("unchecked") + public void onRunnerStart(Class clazz, Runner runner) { + _onRunnerStart = true; + } + + @SuppressWarnings("unchecked") + public void onClassEnd(Class clazz) { + _onClassEnd = true; + } + + @SuppressWarnings("unchecked") + public void onClassStart(Class clazz) { + _onClassStart = true; + } + + @SuppressWarnings("unchecked") + public void onMethodEnd(Method method, Object testInstance, Object[] params, Throwable t, List watchers) { + _onMethodEnd = true; + } + + public void onMethodStart(Method method, Object testInstance, Object[] params) { + _onMethodStart = true; + } + + public void onWatcherEnd(Watcher watcher) { + _onWatcherEnd = true; + } + + public void onWatcherStart(Watcher watcher) { + _onWatcherStart = true; + } + + @SuppressWarnings("unchecked") + public void onWatchersEnd(List watchers) { + _onWatchersEnd = true; + } + + @SuppressWarnings("unchecked") + public void onWatchersStart(List watchers) { + _onWatchersStart = true; + } + + public void onSuiteEnd(TestSuite suite) { + _onSuiteEnd = true; + } + + public void onSuiteStart(TestSuite suite) { + _onSuiteStart = true; + } + + public void assertAllEventsInvoked() { + Assert.assertTrue(_onRunnerEnd); + Assert.assertTrue(_onRunnerStart); + Assert.assertTrue(_onClassEnd); + Assert.assertTrue(_onClassStart); + Assert.assertTrue(_onMethodEnd); + Assert.assertTrue(_onMethodStart); + Assert.assertTrue(_onWatcherEnd); + Assert.assertTrue(_onWatcherStart); + Assert.assertTrue(_onWatchersEnd); + Assert.assertTrue(_onWatchersStart); + } + + public boolean supportParentRunner() { + return true; + } + +} Index: trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java (working copy) @@ -2,23 +2,27 @@ package tests.api.org.punit.runner; -import java.util.*; +import junit.framework.Assert; -import junit.framework.*; +import org.punit.convention.AnnotationConvention; +import org.punit.runner.SoloRunner; -import org.punit.convention.*; -import org.punit.runner.*; +import tests.api.org.punit.testclasses.AnnotationTestClass; +import tests.api.org.punit.testclasses.ConcurrentTestClass; +import tests.api.org.punit.testclasses.LoopTestClass; +import tests.api.org.punit.testclasses.ParameterizableTestClass; +import tests.api.org.punit.testclasses.TestClass0; +import tests.api.org.punit.testclasses.TestClass3; +import tests.api.org.punit.testclasses.TestSuiteClass; +import tests.util.TestUtil; -import tests.api.org.punit.testclasses.*; -import tests.util.*; - public class SoloRunnerTest extends AbstractRunnerTest { private SoloRunner _runner; protected void setUp() throws Exception { _runner = new SoloRunner(); - _eventListener = new MockPUnitEventListener(); + _eventListener = new MockEventListener(); _runner.addEventListener(_eventListener); } @@ -31,9 +35,9 @@ } public void testRunTest() { - TestClass.reset(); - _runner.run(TestClass.class); - TestClass.assertTestClassRun(); + TestClass0.reset(); + _runner.run(TestClass0.class); + TestClass0.assertTestClassRun(); _eventListener.assertAllEventsInvoked(); } @@ -52,9 +56,9 @@ } public void testRunPUnitTest() { - PUnitTestClass.reset(); - _runner.run(PUnitTestClass.class); - PUnitTestClass.assertPUnitTestClassRun(); + TestClass3.reset(); + _runner.run(TestClass3.class); + TestClass3.assertTestClassRun(); _eventListener.assertAllEventsInvoked(); } @@ -72,26 +76,26 @@ } public void testRunTestSuite() { - TestClass.reset(); - PUnitTestClass.reset(); + TestClass0.reset(); + TestClass3.reset(); _runner.run(TestSuiteClass.class); - TestClass.assertTestClassRun(); + TestClass0.assertTestClassRun(); - PUnitTestClass.reset(); - _runner.run(PUnitTestClass.class); - PUnitTestClass.assertPUnitTestClassRun(); + TestClass3.reset(); + _runner.run(TestClass3.class); + TestClass3.assertTestClassRun(); _eventListener.assertAllEventsInvoked(); - Assert.assertTrue(_eventListener.onSuiteEnd); - Assert.assertTrue(_eventListener.onSuiteStart); + Assert.assertTrue(_eventListener._onSuiteEnd); + Assert.assertTrue(_eventListener._onSuiteStart); } public void testSerializable() throws Exception { - _runner.addEventListener(new MockPUnitEventListener()); - List expectedListeners = _runner.eventListeners(); + _runner.addEventListener(new MockEventListener()); + int expectedListenersSize = _runner.eventListeners().size(); SoloRunner runner = (SoloRunner) TestUtil.getSerialiableObject(_runner); - List eventListeners = runner.eventListeners(); - assertEquals(expectedListeners.size(), eventListeners.size()); + int eventListenersSize = runner.eventListeners().size(); + assertEquals(expectedListenersSize, eventListenersSize); } Index: trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java (working copy) @@ -37,9 +37,9 @@ } public void testRunTest() { - TestClass.reset(); - _runner.run(TestClass.class); - TestClass.assertTestClassRun(); + TestClass0.reset(); + _runner.run(TestClass0.class); + TestClass0.assertTestClassRun(); } public void testRunAnnotationTest() { @@ -50,9 +50,9 @@ } public void testRunPUnitTest() { - PUnitTestClass.reset(); - _runner.run(PUnitTestClass.class); - PUnitTestClass.assertPUnitTestClassRun(); + TestClass3.reset(); + _runner.run(TestClass3.class); + TestClass3.assertTestClassRun(); } public void testRunParameterizable() throws Exception{ @@ -63,16 +63,17 @@ public void testRunTestSuite() { ConcurrentTestClass.reset(); - TestClass.reset(); - PUnitTestClass.reset(); + TestClass0.reset(); + TestClass3.reset(); _runner.run(TestSuiteClass.class); assertConcurrentTestClassRun(); - TestClass.assertTestClassRun(); - PUnitTestClass.assertPUnitTestClassRun(); + TestClass0.assertTestClassRun(); + TestClass3.assertTestClassRun(); } + @SuppressWarnings("unchecked") public void testSerializable() throws Exception { - _runner.addEventListener(new MockPUnitEventListener()); + _runner.addEventListener(new MockEventListener()); List expectedListeners = _runner.eventListeners(); ConcurrentRunner runner = (ConcurrentRunner) TestUtil.getSerialiableObject(_runner); List eventListeners = runner.eventListeners(); Index: trunk/punit.test/src/tests/api/org/punit/runner/AbstractRunnerTest.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/runner/AbstractRunnerTest.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/runner/AbstractRunnerTest.java (working copy) @@ -2,19 +2,19 @@ package tests.api.org.punit.runner; -import junit.framework.*; +import junit.framework.TestCase; -import org.punit.method.builder.*; -import org.punit.method.runner.*; -import org.punit.runner.*; -import org.punit.suite.builder.*; +import org.punit.method.builder.MethodBuilderImpl; +import org.punit.method.runner.SoloMethodRunner; +import org.punit.runner.AbstractRunner; +import org.punit.suite.builder.TestSuiteBuilderImpl; public class AbstractRunnerTest extends TestCase { - protected MockPUnitEventListener _eventListener = new MockPUnitEventListener(); + protected MockEventListener _eventListener = new MockEventListener(); public void testCloneSelf() throws Exception { - MockAbstractPUnitRunner runner = new MockAbstractPUnitRunner(); + MockAbstractRunner runner = new MockAbstractRunner(); AbstractRunner cloned = (AbstractRunner) runner.clone(); assertSame(runner.eventListeners(),cloned.eventListeners()); assertSame(runner.methodBuilder(), cloned.methodBuilder()); @@ -22,11 +22,11 @@ assertNotSame(runner.methodRunner().watchers(), cloned.methodRunner().watchers()); } - static class MockAbstractPUnitRunner extends AbstractRunner { + static class MockAbstractRunner extends AbstractRunner { private static final long serialVersionUID = 1L; - public MockAbstractPUnitRunner() { + public MockAbstractRunner() { super(new TestSuiteBuilderImpl(), new MethodBuilderImpl(), new SoloMethodRunner()); } Index: trunk/punit.test/src/tests/api/org/punit/suite/builder/TestSuiteBuilderTest.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/suite/builder/TestSuiteBuilderTest.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/suite/builder/TestSuiteBuilderTest.java (working copy) @@ -29,8 +29,8 @@ public void testBuildTestSuite1() { Object[] classes = _testSuiteBuidler.buildTestClasses(TestSuite1.class); - Class[] expectedClasses = new Class[] { TestClass1.class, - TestClass2.class, TestClass3.class }; + Class[] expectedClasses = new Class[] { TestClass1.class, + TestClass2.class, AlphabeticalTestClass.class }; assertEquals(expectedClasses.length + 2, classes.length); // suite labels @@ -47,8 +47,8 @@ public void testBuildTestSuite2() { Object[] classes = _testSuiteBuidler.buildTestClasses(TestSuite2.class); - Class[] expectedClasses = new Class[] { ExcludedTestClass1.class, TestClass4.class, - TestClass1.class, TestClass2.class, TestClass3.class, TestClass5.class }; + Class[] expectedClasses = new Class[] { ExcludedTestClass1.class, TestClass4.class, + TestClass1.class, TestClass2.class, AlphabeticalTestClass.class, TestClass5.class }; assertEquals(expectedClasses.length + 4, classes.length); // suite labels @@ -74,8 +74,8 @@ public void testBuildTestSuite2ByAnnotationFilter() { _testSuiteBuidler.setConvention(new AnnotationConvention()); Object[] classes = _testSuiteBuidler.buildTestClasses(TestSuite2.class); - Class[] expectedClasses = new Class[] { TestClass4.class, - TestClass1.class, TestClass2.class, TestClass3.class, TestClass5.class }; + Class[] expectedClasses = new Class[] { TestClass4.class, + TestClass1.class, TestClass2.class, AlphabeticalTestClass.class, TestClass5.class }; assertEquals(expectedClasses.length + 4, classes.length); // suite labels Index: trunk/punit.test/src/tests/api/org/punit/testclasses/AlphabeticalTestClass.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/AlphabeticalTestClass.java (revision 0) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/AlphabeticalTestClass.java (revision 0) @@ -0,0 +1,23 @@ +package tests.api.org.punit.testclasses; + +import org.punit.type.*; + +import tests.util.*; + +public class AlphabeticalTestClass implements Alphabetical { + public void test2() { + TestUtil.doSomething(); + } + + public void test1() { + TestUtil.doSomething(); + } + + public void testb() { + TestUtil.doSomething(); + } + + public void testa() { + TestUtil.doSomething(); + } +} Index: trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java (working copy) @@ -30,10 +30,12 @@ _tearDown = 0; } + @SuppressWarnings("unused") private void setUp() { _setUp++; } + @SuppressWarnings("unused") private void tearDown() { _tearDown++; } @@ -53,11 +55,11 @@ Assert.assertEquals(2, _tearDown); } - public long toAbort() { + public long toStop() { return TIMEOUT; } - public long toStop() { + public long toWork() { return TIMEOUT; } } Index: trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java (working copy) @@ -49,21 +49,25 @@ _afterClass = false; } + @SuppressWarnings("unused") @BeforeClass private static void beforeClassMethod() { _beforeClass = true; } + @SuppressWarnings("unused") @AfterClass private static void afterClassMethod() { _afterClass = true; } + @SuppressWarnings("unused") @Before private void before() { _setUp = true; } + @SuppressWarnings("unused") @After private void after() { _tearDown = true; Index: trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizableTestClass.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizableTestClass.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizableTestClass.java (working copy) @@ -1,10 +1,12 @@ package tests.api.org.punit.testclasses; -import junit.framework.*; +import junit.framework.Assert; -import org.punit.type.*; +import org.punit.type.Concurrent; +import org.punit.type.Parameter; +import org.punit.type.Parameterizable; -import tests.util.*; +import tests.util.TestUtil; public class ConcurrentParameterizableTestClass implements Parameterizable, Concurrent { @@ -53,7 +55,7 @@ _tearDownBefore = true; } - public synchronized void test1(Parameter1 p) { + public synchronized void test1(IntParameter p) { _test1 += p.value; TestUtil.doSomething(); } @@ -76,7 +78,7 @@ } public Parameter[] parameters() { - return new Parameter[] { new Parameter1(VALUE1), new Parameter1(VALUE2), }; + return new Parameter[] { new IntParameter(VALUE1), new IntParameter(VALUE2), }; } public int concurrentCount() { Index: trunk/punit.test/src/tests/api/org/punit/testclasses/Parameter1.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/Parameter1.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/Parameter1.java (working copy) @@ -1,15 +0,0 @@ -package tests.api.org.punit.testclasses; - -import org.punit.type.*; - -public class Parameter1 implements Parameter { - public int value; - - Parameter1(int i) { - value = i; - } - - public String toString() { - return String.valueOf(value); - } -} Index: trunk/punit.test/src/tests/api/org/punit/testclasses/ExcludedTestClass1.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/ExcludedTestClass1.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/ExcludedTestClass1.java (working copy) @@ -1,9 +1,9 @@ package tests.api.org.punit.testclasses; -import org.punit.annotation.*; -import org.punit.type.*; +import org.punit.annotation.Ignore; +import org.punit.type.Parameter; -import tests.util.*; +import tests.util.TestUtil; @Ignore public class ExcludedTestClass1 { @@ -35,6 +35,7 @@ TestUtil.doSomething(); } + @SuppressWarnings("unused") private void teste() { TestUtil.doSomething(); } Index: trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass.java (working copy) @@ -1,61 +0,0 @@ -/* (C) Copyright 2007, by Andrew Zhang */ - -package tests.api.org.punit.testclasses; - -import junit.framework.*; - -public class TestClass { - public static boolean _test1; - - public static boolean _test2; - - public static boolean _setUp; - - public static boolean _tearDown; - - private static boolean _beforeClass; - - private static boolean _afterClass; - - public static void reset() { - _test1 = false; - _test2 = false; - _setUp = false; - _tearDown = false; - _beforeClass = false; - _afterClass = false; - } - - private static void beforeClass() { - _beforeClass = true; - } - - private static void afterClass() { - _afterClass = true; - } - - private void setUp() { - _setUp = true; - } - - private void tearDown() { - _tearDown = true; - } - - private void test1() { - _test1 = true; - } - - public void test2() { - _test2 = true; - } - - public static void assertTestClassRun() { - Assert.assertFalse(_test1); - Assert.assertTrue(_test2); - Assert.assertTrue(_setUp); - Assert.assertTrue(_tearDown); - Assert.assertTrue(_beforeClass); - Assert.assertTrue(_afterClass); - } -} Index: trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java (working copy) @@ -1,8 +1,9 @@ package tests.api.org.punit.testclasses; -public class TestSuite1 implements org.punit.type.PUnitTestSuite { - public Class[] testSuite() { - return new Class[] { TestClass1.class, TestClass2.class, TestClass3.class, - }; - } +public class TestSuite1 implements org.punit.type.TestSuite { + public Class[] testSuite() { + return new Class[] { TestClass1.class, TestClass2.class, + AlphabeticalTestClass.class + }; } +} Index: trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java (working copy) @@ -1,10 +1,9 @@ package tests.api.org.punit.testclasses; -public class TestSuite2 implements org.punit.type.PUnitTestSuite { - public Class[] testSuite() { - return new Class[] { ExcludedTestClass1.class, TestClass4.class, TestSuite1.class, - TestClass5.class, - +public class TestSuite2 implements org.punit.type.TestSuite { + public Class[] testSuite() { + return new Class[] { ExcludedTestClass1.class, TestClass4.class, + TestSuite1.class, TestClass5.class }; } -} \ No newline at end of file +} Index: trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java (working copy) @@ -1,19 +1,14 @@ package tests.api.org.punit.testclasses; -import org.punit.type.*; +import org.punit.type.TestSuite; -public class TestSuiteClass implements PUnitTestSuite { +public class TestSuiteClass implements TestSuite { - public Class[] testSuite() { - return new Class[] { - TestClass.class, - PUnitTestClass.class, + public Class[] testSuite() { + return new Class[] { TestClass0.class, TestClass3.class, ConcurrentTestClass.class, - ConcurrentParameterizableTestClass.class, - JUnitTestClass.class, - ParameterizableTestClass.class, - PUnitTestClass.class, - TestClass1.class, - }; + ConcurrentParameterizableTestClass.class, JUnitTestClass.class, + ParameterizableTestClass.class, TestClass3.class, + TestClass1.class, }; } } Index: trunk/punit.test/src/tests/api/org/punit/testclasses/TestParameter.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/TestParameter.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestParameter.java (working copy) @@ -1,15 +0,0 @@ -package tests.api.org.punit.testclasses; - -import org.punit.type.*; - -public class TestParameter implements Parameter { - public int value; - - public TestParameter(int i) { - value = i; - } - - public String toString() { - return "param: " + value; //$NON-NLS-1$ - } -} \ No newline at end of file Index: trunk/punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java (revision 0) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java (revision 0) @@ -0,0 +1,66 @@ +/* (C) Copyright 2007, by Andrew Zhang */ + +package tests.api.org.punit.testclasses; + +import java.util.ArrayList; +import java.util.List; + +import org.punit.runner.SoloRunner; +import org.punit.type.Loop; +import org.punit.watcher.CustomWatcher; + +public class SetResultTestClass implements Runnable, Loop { + + public static final long TIMEOUT = 5000; + + private static final String SUPPORTED_THREADS = "Supported Number of Threads"; + + private boolean _stop; + + private List _threads = new ArrayList(); + + public static void main(String[] args) { + new SoloRunner().run(SetResultTestClass.class); + } + + @SuppressWarnings("unused") + private void setUp() { + _stop = false; + } + + @SuppressWarnings("unused") + private void tearDown() { + _stop = true; + this.notifyAll(); + for (Thread t : _threads) { + try { + t.join(); + } catch (InterruptedException ie) { + } + } + } + + public void testThreads() { + Thread t = new Thread(this); + _threads.add(t); + t.start(); + CustomWatcher.setResult(SUPPORTED_THREADS, _threads.size()); + } + + public void run() { + while (!_stop) { + try { + this.wait(); + } catch (InterruptedException ie) { + } + } + } + + public long toStop() { + return TIMEOUT; + } + + public long toWork() { + return TIMEOUT; + } +} Property changes on: trunk/punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java ___________________________________________________________________ Name: svn:executable + * Index: trunk/punit.test/src/tests/api/org/punit/testclasses/PUnitTestClass.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/PUnitTestClass.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/PUnitTestClass.java (working copy) @@ -1,87 +0,0 @@ -package tests.api.org.punit.testclasses; - -import junit.framework.*; - -import org.punit.type.*; - -import tests.util.*; - -public class PUnitTestClass implements PUnitTest { - public static boolean _test1; - - public static boolean _test2; - - public static boolean _setUp; - - public static boolean _tearDown; - - public static boolean _setUpAfterWatchers; - - public static boolean _setUpBeforeWatchers; - - public static boolean _tearDownAfterWatchers; - - public static boolean _tearDownBeforeWatchers; - - public static void reset() { - _test1 = false; - _test2 = false; - _setUp = false; - _tearDown = false; - _setUpAfterWatchers = false; - _setUpBeforeWatchers = false; - _tearDownAfterWatchers = false; - _tearDownBeforeWatchers = false; - - } - - private void setUp() { - _setUp = true; - } - - private void tearDown() { - _tearDown = true; - } - - private void test1() { - _test1 = true; - TestUtil.doSomething(); - } - - public void test2() { - _test2 = true; - TestUtil.doSomething(); - } - - public void test3(int i) { - TestUtil.doSomething(); - } - - public void setUpAfterWatchers() { - _setUpAfterWatchers = true; - } - - public void setUpBeforeWatchers() { - _setUpBeforeWatchers = true; - } - - public void tearDownAfterWatchers() { - _tearDownAfterWatchers = true; - } - - public void tearDownBeforeWatchers() { - _tearDownBeforeWatchers = true; - } - - public static void assertPUnitTestClassRun() { - Assert.assertFalse(_test1); - Assert.assertTrue(_test2); - Assert.assertFalse(_setUp); - Assert.assertFalse(_tearDown); - Assert.assertTrue(_setUpBeforeWatchers); - Assert.assertTrue(_setUpAfterWatchers); - Assert.assertTrue(_tearDownBeforeWatchers); - Assert.assertTrue(_tearDownAfterWatchers); - } - -} Index: trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass0.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass0.java (revision 0) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass0.java (revision 0) @@ -0,0 +1,66 @@ +/* (C) Copyright 2007, by Andrew Zhang */ + +package tests.api.org.punit.testclasses; + +import org.punit.assertion.Assert; + +public class TestClass0 { + public static boolean _test1; + + public static boolean _test2; + + public static boolean _setUp; + + public static boolean _tearDown; + + private static boolean _beforeClass; + + private static boolean _afterClass; + + public static void reset() { + _test1 = false; + _test2 = false; + _setUp = false; + _tearDown = false; + _beforeClass = false; + _afterClass = false; + } + + @SuppressWarnings("unused") + private static void beforeClass() { + _beforeClass = true; + } + + @SuppressWarnings("unused") + private static void afterClass() { + _afterClass = true; + } + + @SuppressWarnings("unused") + private void setUp() { + _setUp = true; + } + + @SuppressWarnings("unused") + private void tearDown() { + _tearDown = true; + } + + @SuppressWarnings("unused") + private void test1() { + _test1 = true; + } + + public void test2() { + _test2 = true; + } + + public static void assertTestClassRun() { + Assert.assertFalse(_test1); + Assert.assertTrue(_test2); + Assert.assertTrue(_setUp); + Assert.assertTrue(_tearDown); + Assert.assertTrue(_beforeClass); + Assert.assertTrue(_afterClass); + } +} Index: trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass1.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass1.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass1.java (working copy) @@ -1,8 +1,8 @@ package tests.api.org.punit.testclasses; -import org.punit.type.*; +import org.punit.type.Parameter; -import tests.util.*; +import tests.util.TestUtil; public class TestClass1 { public void test1() { @@ -33,6 +33,7 @@ TestUtil.doSomething(); } + @SuppressWarnings("unused") private void teste() { TestUtil.doSomething(); } Index: trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass3.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass3.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass3.java (working copy) @@ -1,23 +1,89 @@ package tests.api.org.punit.testclasses; -import org.punit.type.*; +import org.punit.assertion.Assert; +import org.punit.type.Test; -import tests.util.*; +import tests.util.TestUtil; -public class TestClass3 implements Alphabetical { - public void test2() { - TestUtil.doSomething(); +public class TestClass3 implements Test { + public static boolean _test1; + + public static boolean _test2; + + public static boolean _setUp; + + public static boolean _tearDown; + + public static boolean _setUpAfterWatchers; + + public static boolean _setUpBeforeWatchers; + + public static boolean _tearDownAfterWatchers; + + public static boolean _tearDownBeforeWatchers; + + public static void reset() { + _test1 = false; + _test2 = false; + _setUp = false; + _tearDown = false; + _setUpAfterWatchers = false; + _setUpBeforeWatchers = false; + _tearDownAfterWatchers = false; + _tearDownBeforeWatchers = false; + } - public void test1() { + @SuppressWarnings("unused") + private void setUp() { + _setUp = true; + } + + @SuppressWarnings("unused") + private void tearDown() { + _tearDown = true; + } + + @SuppressWarnings("unused") + private void test1() { + _test1 = true; TestUtil.doSomething(); } - public void testb() { + public void test2() { + _test2 = true; TestUtil.doSomething(); } - public void testa() { + public void test3(int i) { TestUtil.doSomething(); } + + public void setUpAfterWatchers() { + _setUpAfterWatchers = true; + } + + public void setUpBeforeWatchers() { + _setUpBeforeWatchers = true; + } + + public void tearDownAfterWatchers() { + _tearDownAfterWatchers = true; + } + + public void tearDownBeforeWatchers() { + _tearDownBeforeWatchers = true; + } + + public static void assertTestClassRun() { + Assert.assertFalse(_test1); + Assert.assertTrue(_test2); + Assert.assertFalse(_setUp); + Assert.assertFalse(_tearDown); + Assert.assertTrue(_setUpBeforeWatchers); + Assert.assertTrue(_setUpAfterWatchers); + Assert.assertTrue(_tearDownBeforeWatchers); + Assert.assertTrue(_tearDownAfterWatchers); + } + } Index: trunk/punit.test/src/tests/api/org/punit/testclasses/IntParameter.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/IntParameter.java (revision 0) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/IntParameter.java (revision 0) @@ -0,0 +1,15 @@ +package tests.api.org.punit.testclasses; + +import org.punit.type.Parameter; + +public class IntParameter implements Parameter { + public int value; + + public IntParameter(int i) { + value = i; + } + + public String toString() { + return "param: " + value; //$NON-NLS-1$ + } +} \ No newline at end of file Index: trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestClass.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestClass.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestClass.java (working copy) @@ -1,10 +1,11 @@ package tests.api.org.punit.testclasses; -import junit.framework.*; +import junit.framework.Assert; -import org.punit.type.*; +import org.punit.type.Parameter; +import org.punit.type.Parameterizable; -import tests.util.*; +import tests.util.TestUtil; public class ParameterizableTestClass implements Parameterizable { @@ -53,7 +54,7 @@ } - public void test1(Parameter1 p) { + public void test1(IntParameter p) { _test1 += p.value; TestUtil.doSomething(); } @@ -72,7 +73,7 @@ } public Parameter[] parameters() { - return new Parameter[] { new Parameter1(VALUE1), new Parameter1(VALUE2), }; + return new Parameter[] { new IntParameter(VALUE1), new IntParameter(VALUE2), }; } public static void assertTestClassRun() { Index: trunk/punit.test/src/tests/api/org/punit/util/IOUtilTest.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/util/IOUtilTest.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/util/IOUtilTest.java (working copy) @@ -1,34 +1,36 @@ package tests.api.org.punit.util; -import java.io.*; +import java.io.File; +import java.io.FileOutputStream; +import java.io.Serializable; -import org.punit.assertion.*; -import org.punit.exception.*; -import org.punit.util.*; +import junit.framework.TestCase; -import tests.util.*; +import org.punit.assertion.CodeRunner; +import org.punit.exception.IOException; +import org.punit.util.IOUtil; -import junit.framework.*; +import tests.util.AssertUtil; public class IOUtilTest extends TestCase { - public void testSerialize1() throws IOException { + public void testSerialize1() throws java.io.IOException { File file = File.createTempFile("test", "ser"); //$NON-NLS-1$//$NON-NLS-2$ file.deleteOnExit(); IOUtil.serialize(new SerializableClass1(), file.getCanonicalPath()); } - public void testSerialize2() throws IOException { + public void testSerialize2() throws java.io.IOException { final File file = File.createTempFile("test", "ser"); //$NON-NLS-1$//$NON-NLS-2$ file.deleteOnExit(); - AssertUtil.assertException(PUnitIOException.class, new CodeRunner() { + AssertUtil.assertException(IOException.class, new CodeRunner() { public void run() throws Throwable { IOUtil.serialize(new NonSerializableClass1(), file.getCanonicalPath()); } }); } - public void testgetSerializableObject() throws IOException { + public void testgetSerializableObject() throws java.io.IOException { File file = File.createTempFile("test", "ser"); //$NON-NLS-1$//$NON-NLS-2$ file.deleteOnExit(); String fileName = file.getCanonicalPath(); Index: trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java (working copy) @@ -13,7 +13,7 @@ public class ReflectionUtilTest extends TestCase { public void testNewClass() { - Class clazz = ReflectionUtil.newClass(Test1.class.getName()); + Class clazz = ReflectionUtil.newClass(Test1.class.getName()); assertSame(Test1.class, clazz); AssertUtil.assertException(ReflectionException.class, new CodeRunner() { public void run() throws Throwable { @@ -110,6 +110,7 @@ void test2() { } + @SuppressWarnings("unused") private void test3() { } @@ -119,6 +120,7 @@ static void test5_static() { } + @SuppressWarnings("unused") private static void test6_static() { } } @@ -126,10 +128,12 @@ private static class Test1 { public int value = 0; + @SuppressWarnings("unused") private void test1() { value = 10; } + @SuppressWarnings("unused") private void test2(int i) { value = i; } Index: trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java (revision 228) +++ trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java (working copy) @@ -1,16 +1,16 @@ package tests.api.org.punit.watcher; -import junit.framework.*; +import junit.framework.TestCase; -import org.punit.watcher.*; +import org.punit.watcher.MemoryWatcher; -import tests.util.*; +import tests.util.TestUtil; public class MemoryWatcherTest extends TestCase { private MemoryWatcher _watcher; - private static final int MEMORY_CONSUMPTION = 1024*1024; + private static final int MEMORY_CONSUMPTION = 1024 * 1024; protected void setUp() throws Exception { _watcher = new MemoryWatcher(); @@ -19,15 +19,11 @@ public void test() throws Exception { _watcher.start(); byte[] data = new byte[MEMORY_CONSUMPTION]; - for(int i = 0; i < data.length; ++i) { - data[i] = 42; - } _watcher.stop(); double memoryConsumed = _watcher.value(); // The following assertions are not safe in theory, but it works // practically. - assertTrue(memoryConsumed < data.length * 1.5); - assertTrue(memoryConsumed > data.length/2); + assertEquals(memoryConsumed / data.length, 1, 0.5); } public void testSerializable() throws Exception { Index: trunk/punit.test/src/tests/api/org/punit/watcher/CustomWatcherTest.java =================================================================== --- trunk/punit.test/src/tests/api/org/punit/watcher/CustomWatcherTest.java (revision 0) +++ trunk/punit.test/src/tests/api/org/punit/watcher/CustomWatcherTest.java (revision 0) @@ -0,0 +1,92 @@ +package tests.api.org.punit.watcher; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +import org.punit.method.runner.MethodRunner; +import org.punit.method.runner.SoloMethodRunner; +import org.punit.util.MemoryUtil; +import org.punit.watcher.*; + +import tests.util.TestUtil; + +public class CustomWatcherTest extends TestCase { + + private final String HEAP_WASTE = "Heap Waste"; //$NON-NLS-1$ + + private final String HEAP_UTILIZATION = "Heap Utilization"; //$NON-NLS-1$ + + private final double HEAP_WASTE_LIMIT = 1; + + private int CAPACITY = 128; + + private MaximumWatcher _maxWatcher; + private MinimumWatcher _minWatcher; + + protected void setUp() throws Exception { + MethodRunner methodRunner = new SoloMethodRunner(); + _minWatcher = new MinimumWatcher(methodRunner, HEAP_WASTE, "%"); + _maxWatcher = new MaximumWatcher(methodRunner, HEAP_UTILIZATION, "%"); + } + + public void test() throws Exception { + _minWatcher.start(); + _maxWatcher.start(); + allocateAll(); + _minWatcher.stop(); + _maxWatcher.stop(); + + assertEquals(0.0, _minWatcher.value(), HEAP_WASTE_LIMIT); + assertEquals(100.0, _maxWatcher.value(), HEAP_WASTE_LIMIT); + } + + void allocateAll() { + int size = 1; + List list = new ArrayList(CAPACITY); + MemoryUtil.clear(); + long allocated = MemoryUtil.usedMemory(); + + // increase the chunk size + try { + while (true) { + list.add(new byte[size]); + allocated += size; + size += size; + } + } catch (OutOfMemoryError oome) { + } + + // decrease the chunk size + while (size > 0) { + try { + while (true) { + list.add(new byte[size]); + allocated += size; + } + } catch (OutOfMemoryError oome) { + try { + setWatcherValue(allocated); + } catch (OutOfMemoryError oomex) { + return; + } + } + size = size / 2; + } + } + + private void setWatcherValue(long allocated) { + long total = MemoryUtil.totalMemory(); + CustomWatcher.setResult(HEAP_WASTE, (total - allocated) * 100, "%", + total); + CustomWatcher.setResult(HEAP_UTILIZATION, allocated * 100, "%", total); + } + + public void testSerializable() throws Exception { + MinimumWatcher minWatcher = (MinimumWatcher) TestUtil.getSerialiableObject(_minWatcher); + assertNotNull(minWatcher); + MaximumWatcher maxWatcher = (MaximumWatcher) TestUtil.getSerialiableObject(_maxWatcher); + assertNotNull(maxWatcher); + } +} Property changes on: trunk/punit.test/src/tests/api/org/punit/watcher/CustomWatcherTest.java ___________________________________________________________________ Name: svn:executable + * Index: trunk/punit.test/src/tests/util/AssertUtil.java =================================================================== --- trunk/punit.test/src/tests/util/AssertUtil.java (revision 228) +++ trunk/punit.test/src/tests/util/AssertUtil.java (working copy) @@ -1,11 +1,10 @@ package tests.util; -import java.util.*; +import java.util.Arrays; -import org.punit.assertion.*; import org.punit.assertion.Assert; +import org.punit.assertion.CodeRunner; - public class AssertUtil { public static void assertArray(Object[] array1, Object[] array2) { @@ -42,7 +41,8 @@ Assert.assertTrue(isInArray(o, array)); } - public static void assertException(Class throwable, CodeRunner code) { + public static void assertException(Class throwable, + CodeRunner code) { try { code.run(); Assert.fail(throwable + " expected!"); //$NON-NLS-1$ @@ -50,6 +50,7 @@ Assert.assertSame(throwable, e.getClass()); } } + private static boolean isInArray(Object o, Object[] array) { for (int i = 0; i < array.length; ++i) { if (o.equals(array[i])) { Index: trunk/punit.test/src/tests/util/TestUtil.java =================================================================== --- trunk/punit.test/src/tests/util/TestUtil.java (revision 228) +++ trunk/punit.test/src/tests/util/TestUtil.java (working copy) @@ -1,21 +1,28 @@ package tests.util; -import java.io.*; -import java.lang.reflect.*; -import java.util.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.lang.reflect.Method; +import java.util.Random; -import org.punit.util.*; +import org.punit.events.EventListener; +import org.punit.runner.SoloRunner; +import org.punit.type.VM; +import org.punit.util.RunnerUtil; +import org.punit.util.ThreadUtil; public class TestUtil { - + public static boolean runUnitTest = true; private TestUtil() { - + } - + private static Random _random = new Random(); - + public static Object getSerialiableObject(Object obj) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); @@ -25,7 +32,7 @@ ObjectInputStream fis = new ObjectInputStream(bais); return fis.readObject(); } - + public static String[] toMethodNameArray(Object[] methods) { String[] names = new String[methods.length]; for (int i = 0; i < methods.length; ++i) { @@ -33,23 +40,38 @@ } return names; } - + public static void consumeMemory(int length) { byte[] data = new byte[length]; - for(int i = 0, j = 0; i < data.length; ++i) { + for (int i = 0, j = 0; i < data.length; ++i) { ++j; } } - + public static void consumeTime(int time) { ThreadUtil.sleepIgnoreInterruption(time); } - + public static void doSomething() { - if(runUnitTest) { + if (runUnitTest) { return; } consumeTime(Math.abs(_random.nextInt()) % 500); consumeMemory(Math.abs(_random.nextInt()) % 100000); } + + @SuppressWarnings("unchecked") + public static void runVMs(Class clazz, EventListener[] listeners) { + runUnitTest = false; + final String THIS_VM = RunnerUtil.getVmLaunchString(); + final String NO_VERIFY = " -Xverify:none"; //$NON-NLS-1$ + + VM vm = new VM(THIS_VM, "VM"); //$NON-NLS-1$ + VM vm_noverify = new VM(THIS_VM + NO_VERIFY, "VM" + NO_VERIFY); //$NON-NLS-1$ + SoloRunner runner = new SoloRunner(); + for (EventListener e : listeners) { + runner.addEventListener(e); + } + runner.runVMs(clazz, new VM[] { vm, vm_noverify }); + } } Index: trunk/punit.test/src/extension/tests/samples/TestSuiteVMsSample.java =================================================================== --- trunk/punit.test/src/extension/tests/samples/TestSuiteVMsSample.java (revision 228) +++ trunk/punit.test/src/extension/tests/samples/TestSuiteVMsSample.java (working copy) @@ -1,98 +1,17 @@ package extension.tests.samples; -import java.io.*; +import org.punit.events.EventListener; +import org.punit.reporter.chart.TestSuiteReporter; +import org.punit.reporter.chart.pdf.PDFRender; -import org.punit.reporter.chart.*; -import org.punit.reporter.chart.pdf.*; -import org.punit.runner.*; -import org.punit.type.*; -import org.punit.util.*; +import tests.api.org.punit.testclasses.TestSuite2; +import tests.util.TestUtil; -import tests.api.org.punit.testclasses.*; -import tests.util.*; - public class TestSuiteVMsSample { - private static String CLASSPATH; - static { - CLASSPATH = generateClassPath(); + public static void main(String[] args) { + TestUtil.runVMs(TestSuite2.class, + new EventListener[] { new TestSuiteReporter(new PDFRender()) }); } - private static String HARMONY = "D:\\harmony_trunk\\harmony-jre-r530500\\bin\\java" + CLASSPATH; //$NON-NLS-1$ - private static String HARMONY_IBMVME = "D:\\harmony_trunk\\trunk\\deploy\\jdk\\jre\\bin\\java" + CLASSPATH; //$NON-NLS-1$ - private static String SUN = "D:\\tools\\jdk1.5.0_07\\bin\\java" + CLASSPATH; //$NON-NLS-1$ - - public static void main(String[] args) { - TestUtil.runUnitTest = false; - VM harmonyVM = new VM(SUN, "Harmony"); //$NON-NLS-1$ - VM harmonyIBMVM = new VM(HARMONY_IBMVME, "HarmonyIBM"); //$NON-NLS-1$ - VM sunVM = new VM(SUN, "SUN"); //$NON-NLS-1$ - SoloRunner runner = new SoloRunner(); - runner.addEventListener(new TestSuiteReporter(new PDFRender())); - runner.runVMs(TestSuite2.class, new VM[] { harmonyVM, sunVM }); - } - - private static String generateClassPath() { - StringBuffer sb = new StringBuffer(); - sb.append(" -cp "); //$NON-NLS-1$ - String currentPath = IOUtil.getCurrentPath(); - - // test project - sb.append(currentPath); - sb.append(File.separator); - sb.append("bin;"); //$NON-NLS-1$ - - // extension project - sb.append(currentPath.replaceAll("punit.test", "punit.extension")); //$NON-NLS-1$ //$NON-NLS-2$ - sb.append(File.separator); - sb.append("bin;"); //$NON-NLS-1$ - - // core project - sb.append(currentPath.replaceAll("punit.test", "punit")); //$NON-NLS-1$ //$NON-NLS-2$ - sb.append(File.separator); - sb.append("bin;"); //$NON-NLS-1$ - - // junit - sb.append("D:\\tools\\eclipse3.2\\plugins\\org.junit_3.8.1\\junit.jar;"); //$NON-NLS-1$ - sb.append("D:\\workspace_3.2\\punit.extension\\lib\\jcommon-1.0.9.jar;"); //$NON-NLS-1$ - sb.append("D:\\workspace_3.2\\punit.extension\\lib\\jfreechart-1.0.5.jar;"); //$NON-NLS-1$ - sb.append("D:\\workspace_3.2\\punit.extension\\lib\\itext-2.0.2.jar;"); //$NON-NLS-1$ - return sb.toString(); - } - - - public void test1() { - if(isSun()) { - TestUtil.consumeMemory(200000); - TestUtil.consumeTime(1000); - } else { - TestUtil.consumeMemory(200000); - TestUtil.consumeTime(2000); - } - } - - public void test2() { - if(isSun()) { - TestUtil.consumeMemory(100000); - TestUtil.consumeTime(2000); - } else { - TestUtil.consumeMemory(100000); - TestUtil.consumeTime(1000); - } - } - - public void test3() { - if(isSun()) { - TestUtil.consumeMemory(300000); - TestUtil.consumeTime(3000); - } else { - TestUtil.consumeMemory(200000); - TestUtil.consumeTime(2000); - } - } - - private boolean isSun() { -// return System.getProperty("java.vendor").indexOf("Sun") == -1; - return true; - } } Index: trunk/punit.test/src/extension/tests/samples/JUnitTestSample.java =================================================================== --- trunk/punit.test/src/extension/tests/samples/JUnitTestSample.java (revision 228) +++ trunk/punit.test/src/extension/tests/samples/JUnitTestSample.java (working copy) @@ -1,11 +1,11 @@ package extension.tests.samples; -import org.punit.reporter.chart.*; -import org.punit.reporter.chart.image.*; -import org.punit.runner.*; +import org.punit.reporter.chart.OverviewReporter; +import org.punit.reporter.chart.image.ImageRender; +import org.punit.runner.SoloRunner; -import tests.api.org.punit.testclasses.*; -import tests.util.*; +import tests.api.org.punit.testclasses.JUnitTestClass; +import tests.util.TestUtil; public class JUnitTestSample { Index: trunk/punit.test/src/extension/tests/samples/TestClassVMsSample.java =================================================================== --- trunk/punit.test/src/extension/tests/samples/TestClassVMsSample.java (revision 228) +++ trunk/punit.test/src/extension/tests/samples/TestClassVMsSample.java (working copy) @@ -1,96 +1,31 @@ package extension.tests.samples; -import java.io.*; +import org.punit.events.EventListener; +import org.punit.reporter.chart.TestClassReporter; +import org.punit.reporter.chart.image.ImageRender; -import org.punit.reporter.chart.*; -import org.punit.reporter.chart.image.*; -import org.punit.runner.*; -import org.punit.type.*; -import org.punit.util.*; +import tests.util.TestUtil; -import tests.util.*; - public class TestClassVMsSample { - - private static String CLASSPATH; - static { - CLASSPATH = generateClassPath(); + public static void main(String[] args) { + TestUtil.runVMs(TestClassVMsSample.class, + new EventListener[] { new TestClassReporter( + new ImageRender()) }); } - private static String HARMONY = "D:\\harmony_trunk\\harmony-jre-r530500\\bin\\java" + CLASSPATH; //$NON-NLS-1$ - private static String HARMONY_IBMVME = "D:\\harmony_trunk\\trunk\\deploy\\jdk\\jre\\bin\\java" + CLASSPATH; //$NON-NLS-1$ - private static String SUN = "D:\\tools\\jdk1.5.0_07\\bin\\java" + CLASSPATH; //$NON-NLS-1$ - - public static void main(String[] args) { - TestUtil.runUnitTest = false; - VM harmonyVM = new VM(SUN, "Harmony"); //$NON-NLS-1$ - VM harmonyIBMVM = new VM(HARMONY_IBMVME, "HarmonyIBM"); //$NON-NLS-1$ - VM sunVM = new VM(SUN, "SUN"); //$NON-NLS-1$ - SoloRunner runner = new SoloRunner(); - runner.addEventListener(new TestClassReporter(new ImageRender())); - runner.runVMs(TestClassVMsSample.class, new VM[] { harmonyVM, sunVM }); - } - - private static String generateClassPath() { - StringBuffer sb = new StringBuffer(); - sb.append(" -cp "); //$NON-NLS-1$ - String currentPath = IOUtil.getCurrentPath(); - - // test project - sb.append(currentPath); - sb.append(File.separator); - sb.append("bin;"); //$NON-NLS-1$ - - // extension project - sb.append(currentPath.replaceAll("punit.test", "punit.extension")); //$NON-NLS-1$ //$NON-NLS-2$ - sb.append(File.separator); - sb.append("bin;"); //$NON-NLS-1$ - - // core project - sb.append(currentPath.replaceAll("punit.test", "punit")); //$NON-NLS-1$ //$NON-NLS-2$ - sb.append(File.separator); - sb.append("bin;"); //$NON-NLS-1$ - - // junit - sb.append("D:\\tools\\eclipse3.2\\plugins\\org.junit_3.8.1\\junit.jar;"); //$NON-NLS-1$ - sb.append("D:\\workspace_3.2\\punit.extension\\lib\\jcommon-1.0.9.jar;"); //$NON-NLS-1$ - sb.append("D:\\workspace_3.2\\punit.extension\\lib\\jfreechart-1.0.5.jar;"); //$NON-NLS-1$ - return sb.toString(); - } - - public void test1() { - if(isSun()) { - TestUtil.consumeMemory(200000); - TestUtil.consumeTime(1000); - } else { - TestUtil.consumeMemory(200000); - TestUtil.consumeTime(2000); - } + TestUtil.consumeMemory(200000); + TestUtil.consumeTime(1000); } - + public void test2() { - if(isSun()) { - TestUtil.consumeMemory(100000); - TestUtil.consumeTime(2000); - } else { - TestUtil.consumeMemory(100000); - TestUtil.consumeTime(1000); - } + TestUtil.consumeMemory(100000); + TestUtil.consumeTime(1000); } - + public void test3() { - if(isSun()) { - TestUtil.consumeMemory(300000); - TestUtil.consumeTime(3000); - } else { - TestUtil.consumeMemory(200000); - TestUtil.consumeTime(2000); - } + TestUtil.consumeMemory(200000); + TestUtil.consumeTime(2000); } - - private boolean isSun() { -// return System.getProperty("java.vendor").indexOf("Sun") == -1; - return true; - } + } Index: trunk/punit.test/src/extension/tests/samples/OverviewVMsSample.java =================================================================== --- trunk/punit.test/src/extension/tests/samples/OverviewVMsSample.java (revision 228) +++ trunk/punit.test/src/extension/tests/samples/OverviewVMsSample.java (working copy) @@ -1,97 +1,16 @@ package extension.tests.samples; -import java.io.*; +import org.punit.events.EventListener; +import org.punit.reporter.chart.OverviewReporter; +import org.punit.reporter.chart.image.ImageRender; -import org.punit.reporter.chart.*; -import org.punit.reporter.chart.image.*; -import org.punit.runner.*; -import org.punit.type.*; -import org.punit.util.*; +import tests.api.org.punit.testclasses.TestSuiteClass; +import tests.util.TestUtil; -import tests.api.org.punit.testclasses.*; -import tests.util.*; - public class OverviewVMsSample { - - private static String CLASSPATH; - static { - CLASSPATH = generateClassPath(); + public static void main(String[] args) { + TestUtil.runVMs(TestSuiteClass.class, + new EventListener[] { new OverviewReporter( + new ImageRender()) }); } - - private static String HARMONY = "D:\\harmony_trunk\\harmony-jre-r530500\\bin\\java" + CLASSPATH; //$NON-NLS-1$ - private static String HARMONY_IBMVME = "D:\\harmony_trunk\\trunk\\deploy\\jdk\\jre\\bin\\java" + CLASSPATH; //$NON-NLS-1$ - private static String SUN = "D:\\tools\\jdk1.5.0_07\\bin\\java" + CLASSPATH; //$NON-NLS-1$ - - public static void main(String[] args) { - TestUtil.runUnitTest = false; - VM harmonyVM = new VM(SUN, "Harmony"); //$NON-NLS-1$ - VM harmonyIBMVM = new VM(HARMONY_IBMVME, "HarmonyIBM"); //$NON-NLS-1$ - VM sunVM = new VM(SUN, "SUN"); //$NON-NLS-1$ - SoloRunner runner = new SoloRunner(); - runner.addEventListener(new OverviewReporter(new ImageRender())); - runner.runVMs(TestSuiteClass.class, new VM[] { harmonyVM, sunVM }); - } - - private static String generateClassPath() { - StringBuffer sb = new StringBuffer(); - sb.append(" -cp "); //$NON-NLS-1$ - String currentPath = IOUtil.getCurrentPath(); - - // test project - sb.append(currentPath); - sb.append(File.separator); - sb.append("bin;"); //$NON-NLS-1$ - - // extension project - sb.append(currentPath.replaceAll("punit.test", "punit.extension")); //$NON-NLS-1$ //$NON-NLS-2$ - sb.append(File.separator); - sb.append("bin;"); //$NON-NLS-1$ - - // core project - sb.append(currentPath.replaceAll("punit.test", "punit")); //$NON-NLS-1$ //$NON-NLS-2$ - sb.append(File.separator); - sb.append("bin;"); //$NON-NLS-1$ - - // junit - sb.append("D:\\tools\\eclipse3.2\\plugins\\org.junit_3.8.1\\junit.jar;"); //$NON-NLS-1$ - sb.append("D:\\workspace_3.2\\punit.extension\\lib\\jcommon-1.0.9.jar;"); //$NON-NLS-1$ - sb.append("D:\\workspace_3.2\\punit.extension\\lib\\jfreechart-1.0.5.jar;"); //$NON-NLS-1$ - return sb.toString(); - } - - - public void test1() { - if(isSun()) { - TestUtil.consumeMemory(200000); - TestUtil.consumeTime(1000); - } else { - TestUtil.consumeMemory(200000); - TestUtil.consumeTime(2000); - } - } - - public void test2() { - if(isSun()) { - TestUtil.consumeMemory(100000); - TestUtil.consumeTime(2000); - } else { - TestUtil.consumeMemory(100000); - TestUtil.consumeTime(1000); - } - } - - public void test3() { - if(isSun()) { - TestUtil.consumeMemory(300000); - TestUtil.consumeTime(3000); - } else { - TestUtil.consumeMemory(200000); - TestUtil.consumeTime(2000); - } - } - - private boolean isSun() { -// return System.getProperty("java.vendor").indexOf("Sun") == -1; - return true; - } } Index: trunk/punit.test/src/extension/tests/api/org/punit/reporter/chart/AbstractChartReporterTest.java =================================================================== --- trunk/punit.test/src/extension/tests/api/org/punit/reporter/chart/AbstractChartReporterTest.java (revision 228) +++ trunk/punit.test/src/extension/tests/api/org/punit/reporter/chart/AbstractChartReporterTest.java (working copy) @@ -1,23 +1,23 @@ package extension.tests.api.org.punit.reporter.chart; -import java.util.*; +import java.util.NoSuchElementException; -import junit.framework.*; +import org.punit.assertion.CodeRunner; +import org.punit.reporter.chart.AbstractChartReporter; +import org.punit.reporter.chart.DatasetKey; +import org.punit.type.TestSuite; +import org.punit.watcher.Watcher; -import org.punit.assertion.*; -import org.punit.reporter.chart.*; -import org.punit.type.*; -import org.punit.watcher.*; +import tests.api.org.punit.testclasses.TestSuite1; +import tests.api.org.punit.testclasses.TestSuite2; +import tests.util.AssertUtil; -import tests.api.org.punit.testclasses.*; -import tests.util.*; - -public class AbstractChartReporterTest extends TestCase { +public class AbstractChartReporterTest extends junit.framework.TestCase { private MockChartReporter _reporter = new MockChartReporter(); public void testCurrentSuite() { - PUnitTestSuite suite1 = new TestSuite1(); - PUnitTestSuite suite2 = new TestSuite2(); + TestSuite suite1 = new TestSuite1(); + TestSuite suite2 = new TestSuite2(); _reporter.onSuiteStart(suite1); _reporter.onSuiteStart(suite2); assertSame(suite2, _reporter.currentTestSuite()); Index: trunk/punit.test/src/extension/tests/api/org/punit/runner/SoloRunnerExtensionTest.java =================================================================== --- trunk/punit.test/src/extension/tests/api/org/punit/runner/SoloRunnerExtensionTest.java (revision 228) +++ trunk/punit.test/src/extension/tests/api/org/punit/runner/SoloRunnerExtensionTest.java (working copy) @@ -1,14 +1,14 @@ package extension.tests.api.org.punit.runner; -import java.util.*; +import java.util.List; -import junit.framework.*; +import junit.framework.TestCase; -import org.punit.reporter.chart.*; -import org.punit.reporter.chart.image.*; -import org.punit.runner.*; +import org.punit.reporter.chart.OverviewReporter; +import org.punit.reporter.chart.image.ImageRender; +import org.punit.runner.SoloRunner; -import tests.util.*; +import tests.util.TestUtil; public class SoloRunnerExtensionTest extends TestCase { @@ -18,6 +18,7 @@ _runner = new SoloRunner(); } + @SuppressWarnings("unchecked") public void testSerializable() throws Exception { _runner.addEventListener(new OverviewReporter(new ImageRender())); List expectedListeners = _runner.eventListeners();