Thread: Re: [P-unit-devel] SF.net SVN: p-unit: [152] trunk/punit (Page 3)
Status: Beta
Brought to you by:
zhanghuangzhu
|
From: Richard L. <ric...@gm...> - 2007-05-24 14:43:50
|
Hello Andrew, I don't think you need to remove them. ;-) Richard. On 5/24/07, zha...@us... <zha...@us...> wrote: > Revision: 152 > http://p-unit.svn.sourceforge.net/p-unit/?rev=152&view=rev > Author: zhanghuangzhu > Date: 2007-05-24 05:00:54 -0700 (Thu, 24 May 2007) > > Log Message: > ----------- > Andrew Zhang: fixed the compiler errors. > > Removed Paths: > ------------- > trunk/punit/build.xml > trunk/punit.extension/build.xml > > Deleted: trunk/punit/build.xml > =================================================================== > --- trunk/punit/build.xml 2007-05-24 11:30:08 UTC (rev 151) > +++ trunk/punit/build.xml 2007-05-24 12:00:54 UTC (rev 152) > @@ -1,41 +0,0 @@ > -<project name="p-unit" default="dist" basedir="."> > - <description> > - p-unit build system > - </description> > - <!-- set global properties for this build --> > - <property name="src" location="src"/> > - <property name="build" location="build"/> > - <property name="dist" location="../dist"/> > - <property name="project.name" value="p-unit"/> > - <property name="project.version" value="0.10-dev"/> > - <property name="punit.jar" value="${project.name}-${project.version}.jar"/> > - > - <target name="init"> > - <!-- Create the time stamp --> > - <tstamp/> > - <!-- Create the build directory structure used by compile --> > - <mkdir dir="${build}"/> > - </target> > - > - <target name="compile" depends="init" > - description="compile the source " > > - <!-- Compile the java code from ${src} into ${build} --> > - <javac srcdir="${src}" destdir="${build}"/> > - </target> > - > - <target name="dist" depends="compile" > - description="generate the distribution" > > - <!-- Create the distribution directory --> > - <mkdir dir="${dist}"/> > - > - <!-- Put everything in ${build} into the project.name-${DSTAMP}.jar file --> > - <jar jarfile="${dist}/${punit.jar}" basedir="${build}"/> > - </target> > - > - <target name="clean" > - description="clean up" > > - <!-- Delete the ${build} and ${dist} directory trees --> > - <delete dir="${build}"/> > - <delete dir="${dist}"/> > - </target> > -</project> > \ No newline at end of file > > Deleted: trunk/punit.extension/build.xml > =================================================================== > --- trunk/punit.extension/build.xml 2007-05-24 11:30:08 UTC (rev 151) > +++ trunk/punit.extension/build.xml 2007-05-24 12:00:54 UTC (rev 152) > @@ -1,44 +0,0 @@ > -<project name="p-unit-extension" default="dist" basedir="."> > - <description> > - p-unit-extension build system > - </description> > - <!-- set global properties for this build --> > - <import file="../punit/build.xml" /> > - <property name="src" location="src"/> > - <property name="build" location="build"/> > - <property name="p-unit-extension.jar" value="p-unit-extension-${project.version}.jar"/> > - > - <target name="init"> > - <!-- Create the time stamp --> > - <tstamp/> > - <!-- Create the build directory structure used by compile --> > - <mkdir dir="${build}"/> > - </target> > - > - <target name="compile" depends="init" > - description="compile the source " > > - <!-- Compile the java code from ${src} into ${build} --> > - <javac srcdir="${src}" destdir="${build}"> > - <classpath> > - <pathelement path="${punit.jar}"/> > - <fileset dir="lib"> > - <include name="**/*.jar" /> > - </fileset> > - </classpath> > - </javac> > - </target> > - > - <target name="dist" depends="compile" > - description="generate the distribution" > > - <!-- Create the distribution directory --> > - <mkdir dir="${dist}"/> > - <jar jarfile="${dist}/${p-unit-extension.jar}" basedir="${build}"/> > - </target> > - > - <target name="clean" > - description="clean up" > > - <!-- Delete the ${build} and ${dist} directory trees --> > - <delete dir="${build}"/> > - <delete dir="${dist}"/> > - </target> > -</project> > \ No newline at end of file > > > This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > P-unit-devel mailing list > P-u...@li... > https://lists.sourceforge.net/lists/listinfo/p-unit-devel > -- Richard Liang |
|
From: <zha...@us...> - 2007-05-24 16:29:24
|
Revision: 154
http://p-unit.svn.sourceforge.net/p-unit/?rev=154&view=rev
Author: zhanghuangzhu
Date: 2007-05-24 09:29:25 -0700 (Thu, 24 May 2007)
Log Message:
-----------
Andrew Zhang: Added watchers in the parameters of onMethodEnd.
Modified Paths:
--------------
trunk/punit/src/org/punit/events/PUnitEventListener.java
trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
trunk/punit.test/src/tests/api/org/punit/runner/MockPUnitEventListener.java
Modified: trunk/punit/src/org/punit/events/PUnitEventListener.java
===================================================================
--- trunk/punit/src/org/punit/events/PUnitEventListener.java 2007-05-24 14:46:00 UTC (rev 153)
+++ trunk/punit/src/org/punit/events/PUnitEventListener.java 2007-05-24 16:29:25 UTC (rev 154)
@@ -70,7 +70,7 @@
* It is triggered after executing the method.
*/
public void onMethodEnd(Method method, Object testInstance,
- Object[] params, Throwable t);
+ Object[] params, Throwable t, List Watchers);
/**
* It is triggered before all watchers start.
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-24 14:46:00 UTC (rev 153)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-24 16:29:25 UTC (rev 154)
@@ -74,7 +74,7 @@
log(ReporterUtil.simpleMethodName(method, params), Level.INFO);
}
- public void onMethodEnd(Method method, Object instance, Object[] params, Throwable t) {
+ public void onMethodEnd(Method method, Object instance, Object[] params, Throwable t, List watchers) {
_summary.countMethod();
logln(Level.INFO);
if (t != null) {
Modified: trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-24 14:46:00 UTC (rev 153)
+++ trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-24 16:29:25 UTC (rev 154)
@@ -105,7 +105,7 @@
private void onMethodEnd(final Method method, final Object testInstance, final Object[] params, final Throwable t) {
TraverserUtil.traverse(runnerEventListeners().iterator(), new Traverser() {
public void traverse(Object obj) {
- ((PUnitEventListener) obj).onMethodEnd(method, testInstance, params, t);
+ ((PUnitEventListener) obj).onMethodEnd(method, testInstance, params, t, _watchers);
}
});
}
Modified: trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2007-05-24 14:46:00 UTC (rev 153)
+++ trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2007-05-24 16:29:25 UTC (rev 154)
@@ -220,7 +220,7 @@
_currentParams = params;
}
- public void onMethodEnd(Method method, Object testInstance, Object[] params, Throwable t) {
+ public void onMethodEnd(Method method, Object testInstance, Object[] params, Throwable t, List watchers) {
_currentMethod = null;
_currentInstance = null;
_currentParams = null;
Modified: trunk/punit.test/src/tests/api/org/punit/runner/MockPUnitEventListener.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/MockPUnitEventListener.java 2007-05-24 14:46:00 UTC (rev 153)
+++ trunk/punit.test/src/tests/api/org/punit/runner/MockPUnitEventListener.java 2007-05-24 16:29:25 UTC (rev 154)
@@ -41,7 +41,7 @@
onClassStart = true;
}
- public void onMethodEnd(Method method, Object testInstance, Object[] params, Throwable t) {
+ public void onMethodEnd(Method method, Object testInstance, Object[] params, Throwable t, List watchers) {
onMethodEnd = true;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-24 17:13:32
|
Revision: 155
http://p-unit.svn.sourceforge.net/p-unit/?rev=155&view=rev
Author: zhanghuangzhu
Date: 2007-05-24 10:13:33 -0700 (Thu, 24 May 2007)
Log Message:
-----------
Andrew Zhang: Added watchers in the onMethodEnd event.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/runner/method/TestMethodRunner.java
trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
trunk/punit.samples/src/samples/ListTestClass.java
trunk/punit.samples/src/samples/vms/ListVMTest.java
trunk/punit.samples/src/samples/vms/VMConfig.java
Property Changed:
----------------
trunk/punit.samples/
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-24 16:29:25 UTC (rev 154)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-24 17:13:33 UTC (rev 155)
@@ -35,7 +35,7 @@
_testSuiteBuiler = testSuiteBuiler;
_testMethodBuilder = testMethodBuilder;
_testMethodRunner = testMethodRunner;
- _testMethodRunner.setRunner(this);
+ _testMethodRunner.setEventListeners(_eventListeners);
registerLoggerListeners();
}
@@ -226,14 +226,41 @@
Parameterizable pInstance = (Parameterizable) testInstance;
Parameter[] params = pInstance.parameters();
for (int i = 0; i < params.length; ++i) {
- _testMethodRunner.run(testInstance, method,
- new Object[] { params[i] });
+ runTestMethod(testInstance, method, new Object[] { params[i] });
}
} else {
- _testMethodRunner.run(testInstance, method, new Object[] {});
+ runTestMethod(testInstance, method, new Object[] {});
}
}
+ private void runTestMethod(Object testInstance, Method method, Object[] params) {
+ onMethodStart(method, testInstance, params);
+ Throwable throwable = null;
+ if(!_properties.isParent) {
+ throwable = _testMethodRunner.run(testInstance, method, params);
+ }
+ onMethodEnd(method, testInstance, params, throwable);
+ }
+
+ private void onMethodStart(final Method method, final Object testInstance, final Object[] params) {
+ TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ ((PUnitEventListener) obj).onMethodStart(method, testInstance, params);
+ }
+ });
+ }
+
+ private void onMethodEnd(final Method method, final Object testInstance, final Object[] params, final Throwable t) {
+ final List watchers = _testMethodRunner.watchers();
+ TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ ((PUnitEventListener) obj).onMethodEnd(method, testInstance, params, t, watchers);
+ }
+ });
+ }
+
+
+
private Collection buildTestMethod(Class testClass) {
return _testMethodBuilder.buildTestMethods(testClass);
}
Modified: trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-24 16:29:25 UTC (rev 154)
+++ trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-24 17:13:33 UTC (rev 155)
@@ -16,11 +16,11 @@
protected List _watchers = new ArrayList(); // <Watcher>
- private Runner _runner;
-
private MemoryWatcher _memoryWatcher = new MemoryWatcher();
private TimeWatcher _timeWatcher = new TimeWatcher();
+
+ private List _eventListeners; // List <PUnitEventListener>
protected transient Object _testInstance;
@@ -39,6 +39,10 @@
_watchers.add(_timeWatcher);
}
+ public void setEventListeners(List eventListeners) {
+ _eventListeners = eventListeners;
+ }
+
public void addWatcher(Watcher watcher) {
_watchers.add(watcher);
}
@@ -55,21 +59,13 @@
_watchers.remove(_memoryWatcher);
}
- public void setRunner(Runner runner) {
- _runner = runner;
- }
-
- public void run(Object testInstance, Method method, Object[] params) {
+ public Throwable run(Object testInstance, Method method, Object[] params) {
Throwable throwable = null;
try {
- onMethodStart(method, testInstance, params);
init(testInstance, method, params);
setUpBeforeWatchers(params);
startWatchers(testInstance, method, params);
setUpAfterWatchers(params);
- if(isParentRunner()) {
- return;
- }
runImpl();
} catch (Throwable t) {
throwable = t;
@@ -86,30 +82,10 @@
throwable = t;
}
}
- onMethodEnd(method, testInstance, params, throwable);
}
+ return throwable;
}
- private boolean isParentRunner() {
- return _runner.properties().isParent;
- }
-
- private void onMethodStart(final Method method, final Object testInstance, final Object[] params) {
- TraverserUtil.traverse(runnerEventListeners().iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((PUnitEventListener) obj).onMethodStart(method, testInstance, params);
- }
- });
- }
-
- private void onMethodEnd(final Method method, final Object testInstance, final Object[] params, final Throwable t) {
- TraverserUtil.traverse(runnerEventListeners().iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((PUnitEventListener) obj).onMethodEnd(method, testInstance, params, t, _watchers);
- }
- });
- }
-
protected abstract void runImpl() throws Throwable;
protected final void init(Object testInstance, Method method,
@@ -242,11 +218,12 @@
}
private List runnerEventListeners() {
- return _runner.eventListeners();
+ return _eventListeners;
}
public List watchers() {
return _watchers;
}
+
}
Modified: trunk/punit/src/org/punit/runner/method/TestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/TestMethodRunner.java 2007-05-24 16:29:25 UTC (rev 154)
+++ trunk/punit/src/org/punit/runner/method/TestMethodRunner.java 2007-05-24 17:13:33 UTC (rev 155)
@@ -4,20 +4,23 @@
import java.lang.reflect.*;
import java.util.*;
-import org.punit.runner.*;
import org.punit.watcher.*;
public interface TestMethodRunner extends Serializable{
/**
- * Runs the test method, and returns the watcher values.
- *
- * @param clazz
+ * Runs the test method.
+ * @param testInstance
* @param method
- * @return
+ * @param params
+ * @return returns the exception if there is any during the execution.
*/
- public void run(Object testInstance, Method method, Object[] params);
+ public Throwable run(Object testInstance, Method method, Object[] params);
- public void setRunner(Runner runner);
+ /**
+ *
+ * @param eventListeners List <PUnitEventListener>
+ */
+ public void setEventListeners(List eventListeners);
/**
* returns the watchers associated with this method runner.
Modified: trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2007-05-24 16:29:25 UTC (rev 154)
+++ trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2007-05-24 17:13:33 UTC (rev 155)
@@ -18,44 +18,28 @@
import org.punit.watcher.*;
public abstract class AbstractChartReporter implements PUnitEventListener {
-
- private Hashtable datasets = new Hashtable(); // <DatasetKey, DefaultCategoryDataset>
-
+
+ private Hashtable datasets = new Hashtable(); // <DatasetKey,
+
+ // DefaultCategoryDataset>
+
private LinkedList _currentSuiteStack = new LinkedList();
-
+
protected ChartRender _render;
-
+
protected transient RunnerProperties _runnerProperties;
protected transient Class _currentClass;
- protected transient Method _currentMethod;
-
- protected transient Object _currentInstance;
-
- private transient Object[] _currentParams;
-
public AbstractChartReporter(ChartRender render) {
_render = render;
}
protected abstract DatasetKey getKey(Watcher watcher);
-
- public void onWatcherEnd(Watcher watcher) {
- DatasetKey key = getKey(watcher);
- DefaultCategoryDataset dataset = getDatasetOrNew(key);
- if(isParentRunner()) {
- return;
- }
- double value = watcher.value();
- String yname = _currentInstance.getClass().getSimpleName();
- String xname = ReporterUtil.simpleMethodName(_currentMethod, _currentParams);
- dataset.addValue(value, yname, xname); // value, y, x
- }
-
+
public void onRunnerStart(Class clazz, Runner runner) {
_runnerProperties = runner.properties();
- if(!isIntermediate()) {
+ if (!isIntermediate()) {
_render.onRunnerStart(clazz, runner);
}
}
@@ -70,12 +54,13 @@
storeDataset(dataset, fileName, key);
}
});
- if(!isIntermediate()) {
+ if (!isIntermediate()) {
_render.onRunnerEnd(clazz, runner);
}
}
- private DefaultCategoryDataset getDataset(final Runner runner, DatasetKey key) {
+ private DefaultCategoryDataset getDataset(final Runner runner,
+ DatasetKey key) {
DefaultCategoryDataset dataset;
if (isParentRunner()) {
dataset = generateDatasetFromChildrenVMs(runner, key);
@@ -84,21 +69,25 @@
}
return dataset;
}
-
- private DefaultCategoryDataset generateDatasetFromChildrenVMs(final Runner runner, DatasetKey key) {
+
+ private DefaultCategoryDataset generateDatasetFromChildrenVMs(
+ final Runner runner, DatasetKey key) {
String childFileNamePrefix = generateResultFileNamePrefix(runner, key);
final VM[] vms = _runnerProperties.vms;
DefaultCategoryDataset dataset = getDatasetOrNew(key);
for (int i = 0; i < vms.length; ++i) {
String vmname = vms[i].punitName();
- String childFileName = generateIntermediateFileName(childFileNamePrefix, vmname);
- DefaultCategoryDataset childDataset = consumeChildData(runner, childFileName);
- dataset = ChartUtil.appendDataset(dataset, childDataset, vmname);
+ String childFileName = generateIntermediateFileName(
+ childFileNamePrefix, vmname);
+ DefaultCategoryDataset childDataset = consumeChildData(runner,
+ childFileName);
+ dataset = ChartUtil.appendDataset(dataset, childDataset, vmname);
}
return dataset;
}
-
- private DefaultCategoryDataset consumeChildData(final Runner runner,String childFileName) {
+
+ private DefaultCategoryDataset consumeChildData(final Runner runner,
+ String childFileName) {
ObjectInputStream ois = null;
try {
FileInputStream fis = new FileInputStream(childFileName);
@@ -117,25 +106,29 @@
IOUtil.deleteFile(childFileName);
}
}
-
- private void storeDataset(DefaultCategoryDataset dataset, String prefixFileName, DatasetKey key) {
+
+ private void storeDataset(DefaultCategoryDataset dataset,
+ String prefixFileName, DatasetKey key) {
if (isIntermediate()) {
- String fileName = generateIntermediateFileName(prefixFileName, _runnerProperties.vmName);
+ String fileName = generateIntermediateFileName(prefixFileName,
+ _runnerProperties.vmName);
ChartUtil.storeDatasetAsObject(dataset, new File(fileName));
} else {
String title = key.punitName();
String yLegendText = watcherLegend(key.watcher());
- JFreeChart chart = ChartUtil.generateChartFromDataset(title, yLegendText, dataset);
+ JFreeChart chart = ChartUtil.generateChartFromDataset(title,
+ yLegendText, dataset);
_render.renderChart(chart, prefixFileName);
}
}
-
- private static String generateIntermediateFileName(String prefix, String vmName) {
+ private static String generateIntermediateFileName(String prefix,
+ String vmName) {
return prefix + vmName + ImageConstants.SER;
}
- private final String generateResultFileNamePrefix(Runner runner, DatasetKey key) {
+ private final String generateResultFileNamePrefix(Runner runner,
+ DatasetKey key) {
StringBuffer sb = new StringBuffer();
sb.append(Messages.getString("reporter.01")); //$NON-NLS-1$
sb.append(File.separator);
@@ -147,11 +140,11 @@
sb.append("."); //$NON-NLS-1$
return sb.toString();
}
-
+
private static String watcherLegend(Watcher watcher) {
- return watcher.punitName()+ " [" + watcher.unit() + "]"; //$NON-NLS-1$//$NON-NLS-2$
+ return watcher.punitName() + " [" + watcher.unit() + "]"; //$NON-NLS-1$//$NON-NLS-2$
}
-
+
protected final boolean isIntermediate() {
return _runnerProperties.isIntermediate;
}
@@ -159,10 +152,11 @@
protected final boolean isParentRunner() {
return _runnerProperties.isParent;
}
-
+
protected final DefaultCategoryDataset getDatasetOrNew(Object key) {
- DefaultCategoryDataset dataset = (DefaultCategoryDataset) datasets.get(key);
- if(dataset == null) {
+ DefaultCategoryDataset dataset = (DefaultCategoryDataset) datasets
+ .get(key);
+ if (dataset == null) {
dataset = new DefaultCategoryDataset();
putDataset(key, dataset);
}
@@ -172,15 +166,15 @@
protected final void putDataset(Object key, DefaultCategoryDataset dataset) {
datasets.put(key, dataset);
}
-
+
protected final Hashtable datasets() {
return datasets;
}
-
+
public boolean supportParentRunner() {
return true;
}
-
+
public void onClassStart(Class clazz) {
_currentClass = clazz;
}
@@ -188,23 +182,27 @@
public void onClassEnd(Class clazz) {
_currentClass = null;
}
-
+
public void onSuiteStart(PUnitTestSuite suite) {
_currentSuiteStack.add(suite);
}
-
+
public void onSuiteEnd(PUnitTestSuite suite) {
_currentSuiteStack.removeLast();
}
-
+
public PUnitTestSuite currentTestSuite() {
return (PUnitTestSuite) _currentSuiteStack.getLast();
}
-
+
public void onWatcherStart(Watcher watcher) {
// nothing needs to do
}
-
+
+ public void onWatcherEnd(Watcher watcher) {
+ // nothing needs to do
+ }
+
public void onWatchersStart(List watchers) {
// nothing needs to do
}
@@ -213,18 +211,27 @@
// nothing needs to do
}
-
- public void onMethodStart(Method method, Object testInstance, Object[] params) {
- _currentMethod = method;
- _currentInstance = testInstance;
- _currentParams = params;
+ public void onMethodStart(Method method, Object testInstance,
+ Object[] params) {
+ // nothing needs to do
}
- public void onMethodEnd(Method method, Object testInstance, Object[] params, Throwable t, List watchers) {
- _currentMethod = null;
- _currentInstance = null;
- _currentParams = null;
+ public void onMethodEnd(final Method method, final Object testInstance,
+ final Object[] params, final Throwable t, List watchers) {
+ TraverserUtil.traverse(watchers.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ Watcher watcher = (Watcher) obj;
+ DatasetKey key = getKey(watcher);
+ DefaultCategoryDataset dataset = getDatasetOrNew(key);
+ if (isParentRunner()) {
+ return;
+ }
+ double value = watcher.value();
+ String yname = testInstance.getClass().getSimpleName();
+ String xname = ReporterUtil.simpleMethodName(method, params);
+ dataset.addValue(value, yname, xname); // value, y, x
+ }
+ });
}
-
}
Property changes on: trunk/punit.samples
___________________________________________________________________
Name: svn:ignore
+ result
Modified: trunk/punit.samples/src/samples/ListTestClass.java
===================================================================
--- trunk/punit.samples/src/samples/ListTestClass.java 2007-05-24 16:29:25 UTC (rev 154)
+++ trunk/punit.samples/src/samples/ListTestClass.java 2007-05-24 17:13:33 UTC (rev 155)
@@ -6,7 +6,7 @@
public class ListTestClass implements Concurrent {
- private static final int LIST_COUNT = 100000;
+ private static final int LIST_COUNT = 10000;
private static Object element = new Object();
private Random indexGenerator = new Random();;
Modified: trunk/punit.samples/src/samples/vms/ListVMTest.java
===================================================================
--- trunk/punit.samples/src/samples/vms/ListVMTest.java 2007-05-24 16:29:25 UTC (rev 154)
+++ trunk/punit.samples/src/samples/vms/ListVMTest.java 2007-05-24 17:13:33 UTC (rev 155)
@@ -16,7 +16,6 @@
public static void main(String[] args) {
PUnitSoloRunner runner = new PUnitSoloRunner();
runner.addPUnitEventListener(new OverviewReporter(new ImageRender()));
- runner.runVMs(ListTestClass.class, new VM[] { VMConfig.DRLVM,
- VMConfig.SUNVM });
+ runner.runVMs(ListTestClass.class, new VM[] { VMConfig.IBMVME, VMConfig.SUNVM });
}
}
Modified: trunk/punit.samples/src/samples/vms/VMConfig.java
===================================================================
--- trunk/punit.samples/src/samples/vms/VMConfig.java 2007-05-24 16:29:25 UTC (rev 154)
+++ trunk/punit.samples/src/samples/vms/VMConfig.java 2007-05-24 17:13:33 UTC (rev 155)
@@ -6,9 +6,9 @@
private static String CLASSPATH = " -cp d:\\workspace_3.2\\punit.samples\\bin;d:\\workspace_3.2\\punit\\bin;d:\\workspace_3.2\\punit.extension\\bin;D:\\workspace_3.2\\punit.extension\\lib\\jcommon-1.0.9.jar;D:\\workspace_3.2\\punit.extension\\lib\\jfreechart-1.0.5.jar;"; //$NON-NLS-1$
- private static String DRLVM_PATH = "D:\\harmony_trunk\\harmony-jre-r530500\\bin\\java" + CLASSPATH; //$NON-NLS-1$
+ private static String DRLVM_PATH = "D:\\harmony-jre-r530500\\bin\\java" + CLASSPATH; //$NON-NLS-1$
- private static String IBMVME_PATH = "D:\\harmony_trunk\\trunk\\deploy\\jdk\\jre\\bin\\java" + CLASSPATH; //$NON-NLS-1$
+ private static String IBMVME_PATH = "D:\\harmony\\trunk\\deploy\\jdk\\jre\\bin\\java" + CLASSPATH; //$NON-NLS-1$
private static String SUN_PATH = "D:\\tools\\jdk1.5.0_07\\bin\\java" + CLASSPATH; //$NON-NLS-1$
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-24 20:00:20
|
Revision: 157
http://p-unit.svn.sourceforge.net/p-unit/?rev=157&view=rev
Author: zhanghuangzhu
Date: 2007-05-24 12:59:58 -0700 (Thu, 24 May 2007)
Log Message:
-----------
Andrew Zhang: refactored stream report system. Now we are ready for concurrency.
Modified Paths:
--------------
trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java
trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java
trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
trunk/punit/src/org/punit/runner/method/ConcurrentTestMethodRunner.java
trunk/punit/src/org/punit/watcher/MemoryWatcher.java
trunk/punit.test/src/tests/api/org/punit/reporter/stream/PUnitStreamListenerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentRunnerTest.java
Added Paths:
-----------
trunk/punit/src/org/punit/reporter/stream/TestResult.java
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-24 17:44:38 UTC (rev 156)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-24 19:59:58 UTC (rev 157)
@@ -15,25 +15,25 @@
import org.punit.watcher.*;
public abstract class StreamLoggerListener implements PUnitEventListener {
-
- protected transient PrintStream _ps;
- protected transient Summary _summary;
+ protected transient PrintStream _outStream;
- private transient boolean _watchersStart;
+ protected transient PrintStream _errStream;
+ protected transient TestResult _result;
+
public Level _level = Level.FINE;
public StreamLoggerListener() {
}
- public StreamLoggerListener(PrintStream ps) {
- _ps = ps;
+ public StreamLoggerListener(PrintStream out, PrintStream err) {
+ _outStream = out;
+ _errStream = err;
}
public void onRunnerStart(Class clazz, Runner runner) {
- _summary = new Summary();
- _summary.start();
+ _result = new TestResult();
StringBuffer sb = new StringBuffer();
sb.append("["); //$NON-NLS-1$
sb.append(runner.punitName());
@@ -46,10 +46,37 @@
}
public void onRunnerEnd(Class clazz, Runner runner) {
- _summary.stop();
- _summary.log(this);
+ logResult();
}
+ public void logResult() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(Messages.getString("logger.02")); //$NON-NLS-1$
+ sb.append(_result.methodCount());
+ sb.append(", "); //$NON-NLS-1$
+ sb.append(Messages.getString("logger.03")); //$NON-NLS-1$
+ List failures = _result.failures();
+ int failuresCount = failures.size();
+ sb.append(failuresCount);
+ sb.append(" ("); //$NON-NLS-1$
+ if (failuresCount == 0) {
+ sb.append(Messages.getString("logger.04")); //$NON-NLS-1$
+ } else {
+ sb.append(Messages.getString("logger.05")); //$NON-NLS-1$
+ }
+ sb.append(") "); //$NON-NLS-1$
+ sb.append(ReporterUtil.LINE_SEPERATOR);
+ logErr(sb.toString(), Level.INFO);
+ TraverserUtil.traverse(failures.iterator(), new Traverser() {
+ int count = 0;
+
+ public void traverse(Object obj) {
+ logErr(++count + ")", Level.INFO); //$NON-NLS-1$
+ ((Throwable) obj).printStackTrace(_errStream);
+ }
+ });
+ }
+
public void onSuiteStart(PUnitTestSuite suite) {
StringBuffer sb = new StringBuffer();
sb.append(Messages.getString("logger.06")); //$NON-NLS-1$
@@ -57,63 +84,48 @@
sb.append(ReporterUtil.LINE_SEPERATOR);
log(sb.toString(), Level.INFO);
}
-
- public void onSuiteEnd(PUnitTestSuite suite) {
-
- }
-
- public void onClassStart(Class clazz) {
- log(clazz.getName() + ReporterUtil.LINE_SEPERATOR, Level.INFO);
- }
- public void onClassEnd(Class clazz) {
+ public void onClassStart(Class clazz) {
+ logln(clazz.getName(), Level.INFO);
}
- public void onMethodStart(Method method, Object instance, Object[] params) {
- log(ReporterUtil.simpleMethodName(method, params), Level.INFO);
+ public void onMethodEnd(Method method, Object instance, Object[] params,
+ Throwable t, List watchers) {
+ logTestMethodResult(method, params, watchers, t);
+ _result.countMethod();
+ if (t != null) {
+ _result.addThrowable(t);
+ }
}
- public void onMethodEnd(Method method, Object instance, Object[] params, Throwable t, List watchers) {
- _summary.countMethod();
+ private void logTestMethodResult(Method method, Object[] params, List watchers, Throwable t) {
+ log(ReporterUtil.simpleMethodName(method, params), Level.INFO);
+ if (watchers.size() > 0) {
+ final Iterator iter = watchers.iterator();
+ Watcher watcher = (Watcher) iter.next();
+ log(" - [" + watcher.stringValue(), Level.FINE); //$NON-NLS-1$
+ TraverserUtil.traverse(watchers.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ Watcher watcher = (Watcher) obj;
+ log("," + watcher.stringValue(), Level.FINE); //$NON-NLS-1$
+ }
+ });
+ log("]", Level.INFO); //$NON-NLS-1$
+ }
logln(Level.INFO);
- if (t != null) {
+ if(t != null) {
logln(t.toString(), Level.INFO);
- _summary.addThrowable(t);
}
}
- public void onWatchersStart(List watchers) {
- _watchersStart = true;
+ public void setStream(PrintStream out, PrintStream err) {
+ _outStream = out;
+ _errStream = err;
}
- public void onWatcherStart(Watcher watcher) {
- }
-
- public void onWatchersEnd(List watchers) {
- log("]", Level.FINE); //$NON-NLS-1$
- }
-
- public void onWatcherEnd(Watcher watcher) {
- String watchValue = watcher.stringValue();
- if (_watchersStart) {
- log(" - [" + watchValue, Level.FINE); //$NON-NLS-1$
- } else {
- log("," + watcher.stringValue(), Level.FINE); //$NON-NLS-1$
- }
- _watchersStart = false;
- }
-
- public void setLogLevel(Level level) {
- _level = level;
- }
-
- public void setOutputStream(PrintStream ps) {
- _ps = ps;
- }
-
public PrintStream printStream() {
- return _ps;
+ return _outStream;
}
public void logln(Level level) {
@@ -125,67 +137,54 @@
}
public void log(String message, Level level) {
- if (_ps == null) {
+ log(_outStream, message, level);
+ }
+
+ public void logErr(String message, Level level) {
+ log(_errStream, message, level);
+ }
+
+ public void log(PrintStream ps, String message, Level level) {
+ if (ps == null) {
return;
}
if (level.intValue() < _level.intValue()) {
return;
}
- _ps.print(message);
- _ps.flush();
+ ps.print(message);
+ ps.flush();
}
- static class Summary {
- private int _methodCount;
+ public void setLogLevel(Level level) {
+ _level = level;
+ }
- private TimeWatcher _timeWatcher = new TimeWatcher();
+ public void onWatchersStart(List watchers) {
+ // nothing needs to do
+ }
- private List _throwableList = new ArrayList();
+ public void onWatcherStart(Watcher watcher) {
+ // nothing needs to do
+ }
- public void countMethod() {
- ++_methodCount;
- }
+ public void onWatchersEnd(List watchers) {
+ // nothing needs to do
+ }
- public void start() {
- _timeWatcher.start();
- _methodCount = 0;
- _throwableList.clear();
- }
+ public void onWatcherEnd(Watcher watcher) {
+ // nothing needs to do
+ }
- public void stop() {
- _timeWatcher.stop();
- }
+ public void onSuiteEnd(PUnitTestSuite suite) {
+ // nothing needs to do
+ }
+
+ public void onClassEnd(Class clazz) {
+ // nothing needs to do
+ }
- public void log(final StreamLoggerListener logger) {
- StringBuffer sb = new StringBuffer();
- sb.append(Messages.getString("logger.02")); //$NON-NLS-1$
- sb.append(_methodCount);
- sb.append(", "); //$NON-NLS-1$
- sb.append(Messages.getString("logger.03")); //$NON-NLS-1$
- int failures = _throwableList.size();
- sb.append(failures);
- sb.append(" ("); //$NON-NLS-1$
- if (failures == 0) {
- sb.append(Messages.getString("logger.04")); //$NON-NLS-1$
- } else {
- sb.append(Messages.getString("logger.05")); //$NON-NLS-1$
- }
- sb.append(") "); //$NON-NLS-1$
- sb.append(_timeWatcher.stringValue());
- sb.append(ReporterUtil.LINE_SEPERATOR);
- logger.log(sb.toString(), Level.INFO);
- TraverserUtil.traverse(_throwableList.iterator(), new Traverser() {
- int count = 0;
- public void traverse(Object obj) {
- logger.log(++count + ")", Level.INFO); //$NON-NLS-1$
- ((Throwable) obj).printStackTrace(logger._ps);
- }
- });
- }
-
- public void addThrowable(Throwable t) {
- _throwableList.add(t);
- }
+ public void onMethodStart(Method method, Object instance, Object[] params) {
+ // nothing needs to do
}
}
\ No newline at end of file
Added: trunk/punit/src/org/punit/reporter/stream/TestResult.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/TestResult.java (rev 0)
+++ trunk/punit/src/org/punit/reporter/stream/TestResult.java 2007-05-24 19:59:58 UTC (rev 157)
@@ -0,0 +1,27 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.reporter.stream;
+
+import java.util.*;
+
+public class TestResult {
+ private int _methodCount;
+
+ private List _failures = new ArrayList();
+
+ public synchronized void countMethod() {
+ ++_methodCount;
+ }
+
+ public synchronized void addThrowable(Throwable t) {
+ _failures.add(t);
+ }
+
+ public int methodCount() {
+ return _methodCount;
+ }
+
+ public List failures() {
+ return _failures;
+ }
+}
Modified: trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java 2007-05-24 17:44:38 UTC (rev 156)
+++ trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java 2007-05-24 19:59:58 UTC (rev 157)
@@ -12,11 +12,11 @@
private void readObject(java.io.ObjectInputStream in) throws IOException,
ClassNotFoundException {
- _ps = System.err;
+ _outStream = System.err;
}
public ConsoleLogger() {
- super(System.err);
+ super(System.out, System.err);
}
public boolean supportParentRunner() {
Modified: trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java 2007-05-24 17:44:38 UTC (rev 156)
+++ trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java 2007-05-24 19:59:58 UTC (rev 157)
@@ -16,7 +16,7 @@
String fileName = ReporterUtil.generateFileName(clazz, runner) + ".txt"; //$NON-NLS-1$
try {
PrintStream ps = new PrintStream(fileName);
- setOutputStream(ps);
+ setStream(ps, ps);
} catch (Exception e) {
throw new IllegalStateException(e);
}
@@ -25,7 +25,7 @@
public void onRunnerEnd(Class clazz, Runner runner) {
super.onRunnerEnd(clazz, runner);
- _ps.close();
+ _outStream.close();
}
public boolean supportParentRunner() {
Modified: trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-24 17:44:38 UTC (rev 156)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-24 19:59:58 UTC (rev 157)
@@ -5,6 +5,7 @@
import org.punit.builder.suite.*;
import org.punit.message.*;
import org.punit.runner.method.*;
+import org.punit.util.*;
public class PUnitConcurrentRunner extends PUnitAbstractRunner {
@@ -12,6 +13,10 @@
private static final int DEFAULT_CONCURRENT_COUNT = 10;
+ public static void main(String[] args) {
+ RunnerUtil.run(new PUnitConcurrentRunner(), args);
+ }
+
public PUnitConcurrentRunner() {
this(PUnitConcurrentRunner.DEFAULT_CONCURRENT_COUNT);
}
Modified: trunk/punit/src/org/punit/runner/method/ConcurrentTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/ConcurrentTestMethodRunner.java 2007-05-24 17:44:38 UTC (rev 156)
+++ trunk/punit/src/org/punit/runner/method/ConcurrentTestMethodRunner.java 2007-05-24 19:59:58 UTC (rev 157)
@@ -56,14 +56,15 @@
}
_threads = new TestMethodThread[threadCount];
for (int i = 0; i < _threads.length; ++i) {
- _threads[i] = new TestMethodThread(this);
+ _threads[i] = new TestMethodThread(this, "punit concurrent method runner"); //$NON-NLS-1$
}
}
private class TestMethodThread extends Thread {
ConcurrentTestMethodRunner _runner;
- public TestMethodThread(ConcurrentTestMethodRunner runner) {
+ public TestMethodThread(ConcurrentTestMethodRunner runner, String threadName) {
+ super(threadName);
_runner = runner;
}
Modified: trunk/punit/src/org/punit/watcher/MemoryWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-24 17:44:38 UTC (rev 156)
+++ trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-24 19:59:58 UTC (rev 157)
@@ -19,7 +19,7 @@
_stop = false;
MemoryUtil.clear();
_maxUsedMemory = _startUsedMemory = MemoryUtil.usedMemory();
- new MemoryWatcherThread().start();
+ new MemoryWatcherThread("memory watcher thread").start(); //$NON-NLS-1$
}
public void stop() {
@@ -39,6 +39,10 @@
}
private class MemoryWatcherThread extends Thread {
+ public MemoryWatcherThread(String threadName) {
+ super(threadName);
+ }
+
public void run() {
while(!_stop) {
monitorMemory();
Modified: trunk/punit.test/src/tests/api/org/punit/reporter/stream/PUnitStreamListenerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/reporter/stream/PUnitStreamListenerTest.java 2007-05-24 17:44:38 UTC (rev 156)
+++ trunk/punit.test/src/tests/api/org/punit/reporter/stream/PUnitStreamListenerTest.java 2007-05-24 19:59:58 UTC (rev 157)
@@ -19,7 +19,7 @@
protected void setUp() throws Exception {
_mockPrintStream = new MockPrintStream(System.err);
- _logger.setOutputStream(_mockPrintStream);
+ _logger.setStream(_mockPrintStream, _mockPrintStream);
}
public void test1() {
Modified: trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentRunnerTest.java 2007-05-24 17:44:38 UTC (rev 156)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentRunnerTest.java 2007-05-24 19:59:58 UTC (rev 157)
@@ -19,7 +19,7 @@
}
public void testMain() {
- PUnitSoloRunner.main(new String[] {TestSuiteClass.class.getName()});
+ PUnitConcurrentRunner.main(new String[] {TestSuiteClass.class.getName()});
}
public void testRun() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-27 08:16:41
|
Revision: 161
http://p-unit.svn.sourceforge.net/p-unit/?rev=161&view=rev
Author: zhanghuangzhu
Date: 2007-05-27 01:16:42 -0700 (Sun, 27 May 2007)
Log Message:
-----------
Andrew Zhang: Disabled memory by default. Refactored some method name, and add ExecutionPoolSample.
Modified Paths:
--------------
trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java
Added Paths:
-----------
trunk/punit.samples/src/samples/ExecutorPoolSample.java
trunk/punit.samples/src/samples/LongTimeExecutionJUnitTestSuite.java
trunk/punit.samples/src/samples/LongTimeExecutionPUnitTestSuite.java
trunk/punit.samples/src/samples/LongTimeExecutionTest1.java
trunk/punit.samples/src/samples/LongTimeExecutionTest2.java
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-25 13:36:58 UTC (rev 160)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -23,6 +23,8 @@
protected transient TestResult _result;
public Level _level = Level.FINE;
+
+ private TimeWatcher _timeWatcher;
public StreamLoggerListener() {
}
@@ -33,6 +35,7 @@
}
public void onRunnerStart(Class clazz, Runner runner) {
+ startTimeWatcher();
_result = new TestResult();
StringBuffer sb = new StringBuffer();
sb.append("["); //$NON-NLS-1$
@@ -45,11 +48,17 @@
log(sb.toString(), Level.INFO);
}
+ private void startTimeWatcher() {
+ _timeWatcher = new TimeWatcher();
+ _timeWatcher.start();
+ }
+
public void onRunnerEnd(Class clazz, Runner runner) {
logResult();
}
public void logResult() {
+ stopTimeWatcher();
StringBuffer sb = new StringBuffer();
sb.append(Messages.getString("logger.02")); //$NON-NLS-1$
sb.append(_result.methodCount());
@@ -64,7 +73,8 @@
} else {
sb.append(Messages.getString("logger.05")); //$NON-NLS-1$
}
- sb.append(") "); //$NON-NLS-1$
+ sb.append(") - "); //$NON-NLS-1$
+ sb.append(_timeWatcher.stringValue());
sb.append(ReporterUtil.LINE_SEPERATOR);
logErr(sb.toString(), Level.INFO);
TraverserUtil.traverse(failures.iterator(), new Traverser() {
@@ -77,6 +87,10 @@
});
}
+ private void stopTimeWatcher() {
+ _timeWatcher.stop();
+ }
+
public void onSuiteStart(PUnitTestSuite suite) {
StringBuffer sb = new StringBuffer();
sb.append(Messages.getString("logger.06")); //$NON-NLS-1$
@@ -105,7 +119,7 @@
final Iterator iter = watchers.iterator();
Watcher watcher = (Watcher) iter.next();
log(" - [" + watcher.stringValue(), Level.FINE); //$NON-NLS-1$
- TraverserUtil.traverse(watchers.iterator(), new Traverser() {
+ TraverserUtil.traverse(iter, new Traverser() {
public void traverse(Object obj) {
Watcher watcher = (Watcher) obj;
log("," + watcher.stringValue(), Level.FINE); //$NON-NLS-1$
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-25 13:36:58 UTC (rev 160)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -290,15 +290,15 @@
return _testMethodBuilder.buildTestMethods(testClass);
}
- public TestMethodBuilder testMethodBuilder() {
+ public TestMethodBuilder methodBuilder() {
return _testMethodBuilder;
}
- public TestMethodRunner testMethodRunner() {
+ public TestMethodRunner methodRunner() {
return _testMethodRunner;
}
- public TestSuiteBuilder testSuiteBuiler() {
+ public TestSuiteBuilder suiteBuiler() {
return _testSuiteBuiler;
}
Modified: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java 2007-05-25 13:36:58 UTC (rev 160)
+++ trunk/punit/src/org/punit/runner/Runner.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -16,10 +16,10 @@
public RunnerProperties properties();
- public TestMethodBuilder testMethodBuilder();
+ public TestMethodBuilder methodBuilder();
- public TestMethodRunner testMethodRunner();
+ public TestMethodRunner methodRunner();
- public TestSuiteBuilder testSuiteBuiler();
+ public TestSuiteBuilder suiteBuiler();
}
Modified: trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-25 13:36:58 UTC (rev 160)
+++ trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -15,8 +15,6 @@
public abstract class AbstractTestMethodRunner implements TestMethodRunner {
protected List _watchers = new ArrayList(); // <Watcher>
-
- private MemoryWatcher _memoryWatcher = new MemoryWatcher();
private TimeWatcher _timeWatcher = new TimeWatcher();
@@ -37,7 +35,6 @@
protected transient Method _setUpMethod;
public AbstractTestMethodRunner() {
- _watchers.add(_memoryWatcher);
_watchers.add(_timeWatcher);
}
@@ -60,11 +57,7 @@
public void removeTimeWatcher() {
_watchers.remove(_timeWatcher);
}
-
- public void removeMemoryWatcher() {
- _watchers.remove(_memoryWatcher);
- }
-
+
public void run(Object testInstance, Method method, Object[] params) {
onMethodStart(method, testInstance, params);
Throwable throwable = null;
Added: trunk/punit.samples/src/samples/ExecutorPoolSample.java
===================================================================
--- trunk/punit.samples/src/samples/ExecutorPoolSample.java (rev 0)
+++ trunk/punit.samples/src/samples/ExecutorPoolSample.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -0,0 +1,11 @@
+package samples;
+
+import org.punit.runner.*;
+
+public class ExecutorPoolSample {
+ public static void main(String[] args) {
+ PUnitSoloRunner runner = new PUnitSoloRunner();
+ runner.setExecutorPool(new PUnitExecutorPool(2));
+ runner.run(LongTimeExecutionPUnitTestSuite.class);
+ }
+}
Added: trunk/punit.samples/src/samples/LongTimeExecutionJUnitTestSuite.java
===================================================================
--- trunk/punit.samples/src/samples/LongTimeExecutionJUnitTestSuite.java (rev 0)
+++ trunk/punit.samples/src/samples/LongTimeExecutionJUnitTestSuite.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -0,0 +1,22 @@
+package samples;
+
+import junit.framework.*;
+
+public class LongTimeExecutionJUnitTestSuite {
+
+ 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]);
+ }
+ // $JUnit-END$
+ return suite;
+ }
+
+ public static Class[] testCases() {
+ return new Class[] { LongTimeExecutionTest1.class,
+ LongTimeExecutionTest2.class, };
+ }
+}
Added: trunk/punit.samples/src/samples/LongTimeExecutionPUnitTestSuite.java
===================================================================
--- trunk/punit.samples/src/samples/LongTimeExecutionPUnitTestSuite.java (rev 0)
+++ trunk/punit.samples/src/samples/LongTimeExecutionPUnitTestSuite.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -0,0 +1,11 @@
+package samples;
+
+import org.punit.type.*;
+
+public class LongTimeExecutionPUnitTestSuite implements PUnitTestSuite{
+
+ public Class[] suite() {
+ return LongTimeExecutionJUnitTestSuite.testCases();
+ }
+
+}
Added: trunk/punit.samples/src/samples/LongTimeExecutionTest1.java
===================================================================
--- trunk/punit.samples/src/samples/LongTimeExecutionTest1.java (rev 0)
+++ trunk/punit.samples/src/samples/LongTimeExecutionTest1.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -0,0 +1,22 @@
+package samples;
+
+import junit.framework.*;
+
+public class LongTimeExecutionTest1 extends TestCase {
+ public void test1() throws Exception {
+ Thread.sleep(5000);
+ }
+
+ public void test2() throws Exception {
+ Thread.sleep(5000);
+ }
+
+ public void testA() throws Exception {
+ Thread.sleep(5000);
+ }
+
+ public void testB() throws Exception {
+ Thread.sleep(5000);
+ }
+
+}
Added: trunk/punit.samples/src/samples/LongTimeExecutionTest2.java
===================================================================
--- trunk/punit.samples/src/samples/LongTimeExecutionTest2.java (rev 0)
+++ trunk/punit.samples/src/samples/LongTimeExecutionTest2.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -0,0 +1,22 @@
+package samples;
+
+import junit.framework.*;
+
+public class LongTimeExecutionTest2 extends TestCase {
+ public void test1() throws Exception {
+ Thread.sleep(5000);
+ }
+
+ public void test2() throws Exception {
+ Thread.sleep(5000);
+ }
+
+ public void testA() throws Exception {
+ Thread.sleep(5000);
+ }
+
+ public void testB() throws Exception {
+ Thread.sleep(5000);
+ }
+
+}
Modified: trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java 2007-05-25 13:36:58 UTC (rev 160)
+++ trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -12,16 +12,8 @@
public void testWatchers() {
List watchers = _mockRunner.watchers();
- assertEquals(2, watchers.size()); // time, and memory watchers
+ assertEquals(1, watchers.size()); // time, and memory watchers
- _mockRunner.removeMemoryWatcher();
- watchers = _mockRunner.watchers();
- assertEquals(1, watchers.size());
-
- _mockRunner.removeMemoryWatcher();
- watchers = _mockRunner.watchers();
- assertEquals(1, watchers.size());
-
_mockRunner.removeTimeWatcher();
watchers = _mockRunner.watchers();
assertEquals(0, watchers.size());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-27 08:18:24
|
Revision: 162
http://p-unit.svn.sourceforge.net/p-unit/?rev=162&view=rev
Author: zhanghuangzhu
Date: 2007-05-27 01:18:25 -0700 (Sun, 27 May 2007)
Log Message:
-----------
Andrew Zhang: refactored *TestMethodRunner name.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java
Added Paths:
-----------
trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java
trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java
trunk/punit/src/org/punit/runner/method/MethodRunner.java
trunk/punit/src/org/punit/runner/method/SoloMethodRunner.java
Removed Paths:
-------------
trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/runner/method/ConcurrentTestMethodRunner.java
trunk/punit/src/org/punit/runner/method/SoloTestMethodRunner.java
trunk/punit/src/org/punit/runner/method/TestMethodRunner.java
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-27 08:16:42 UTC (rev 161)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-27 08:18:25 UTC (rev 162)
@@ -21,7 +21,7 @@
private TestMethodBuilder _testMethodBuilder;
- private TestMethodRunner _testMethodRunner;
+ private MethodRunner _testMethodRunner;
// List <PUnitEventListener>
private final List _eventListeners = new ArrayList();
@@ -34,7 +34,7 @@
public PUnitAbstractRunner(TestSuiteBuilder testSuiteBuiler,
TestMethodBuilder testMethodBuilder,
- TestMethodRunner testMethodRunner) {
+ MethodRunner testMethodRunner) {
_testSuiteBuiler = testSuiteBuiler;
_testMethodBuilder = testMethodBuilder;
_testMethodRunner = testMethodRunner;
@@ -294,7 +294,7 @@
return _testMethodBuilder;
}
- public TestMethodRunner methodRunner() {
+ public MethodRunner methodRunner() {
return _testMethodRunner;
}
Modified: trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-27 08:16:42 UTC (rev 161)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-27 08:18:25 UTC (rev 162)
@@ -22,7 +22,7 @@
}
public PUnitConcurrentRunner(int concurrentCount) {
- super(new PUnitTestSuiteBuilder(), new PUnitTestMethodBuilder(), new ConcurrentTestMethodRunner(concurrentCount));
+ super(new PUnitTestSuiteBuilder(), new PUnitTestMethodBuilder(), new ConcurrentMethodRunner(concurrentCount));
}
public String punitName() {
Modified: trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitSoloRunner.java 2007-05-27 08:16:42 UTC (rev 161)
+++ trunk/punit/src/org/punit/runner/PUnitSoloRunner.java 2007-05-27 08:18:25 UTC (rev 162)
@@ -18,7 +18,7 @@
public PUnitSoloRunner() {
super(new PUnitTestSuiteBuilder(), new PUnitTestMethodBuilder(),
- new SoloTestMethodRunner());
+ new SoloMethodRunner());
}
Modified: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java 2007-05-27 08:16:42 UTC (rev 161)
+++ trunk/punit/src/org/punit/runner/Runner.java 2007-05-27 08:18:25 UTC (rev 162)
@@ -18,7 +18,7 @@
public TestMethodBuilder methodBuilder();
- public TestMethodRunner methodRunner();
+ public MethodRunner methodRunner();
public TestSuiteBuilder suiteBuiler();
Copied: trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java (from rev 161, trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java 2007-05-27 08:18:25 UTC (rev 162)
@@ -0,0 +1,257 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.runner.method;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+import org.punit.events.*;
+import org.punit.exception.*;
+import org.punit.runner.*;
+import org.punit.type.*;
+import org.punit.util.*;
+import org.punit.watcher.*;
+
+public abstract class AbstractMethodRunner implements MethodRunner {
+
+ protected List _watchers = new ArrayList(); // <Watcher>
+
+ private TimeWatcher _timeWatcher = new TimeWatcher();
+
+ private List _eventListeners; // List <PUnitEventListener>
+
+ private RunnerProperties _runnerProperties;
+
+ protected transient Object _testInstance;
+
+ protected transient Method _method;
+
+ protected transient Object[] _params;
+
+ protected transient Class _class;
+
+ protected transient Method _tearDownMethod;
+
+ protected transient Method _setUpMethod;
+
+ public AbstractMethodRunner() {
+ _watchers.add(_timeWatcher);
+ }
+
+ public void setEventListeners(List eventListeners) {
+ _eventListeners = eventListeners;
+ }
+
+ public void setRunnerProperties(RunnerProperties props) {
+ _runnerProperties = props;
+ }
+
+ public void addWatcher(Watcher watcher) {
+ _watchers.add(watcher);
+ }
+
+ public void removeWatcher(Watcher watcher) {
+ _watchers.remove(watcher);
+ }
+
+ public void removeTimeWatcher() {
+ _watchers.remove(_timeWatcher);
+ }
+
+ public void run(Object testInstance, Method method, Object[] params) {
+ onMethodStart(method, testInstance, params);
+ Throwable throwable = null;
+ try {
+ if(needsRunMethod()) {
+ init(testInstance, method, params);
+ setUpBeforeWatchers(params);
+ startWatchers(testInstance, method, params);
+ setUpAfterWatchers(params);
+ runImpl();
+ } else {
+ startWatchers(testInstance, method, params);
+ }
+ } catch (Throwable t) {
+ throwable = t;
+ } finally {
+ try {
+ if(needsRunMethod()) {
+ tearDownBeforeWatchers(params);
+ }
+ } catch (Throwable t) {
+ throwable = t;
+ } finally {
+ try {
+ stopWatchers(testInstance, method, params);
+ if(needsRunMethod()) {
+ tearDownAfterWatchers(params);
+ }
+ } catch (Throwable t) {
+ throwable = t;
+ }
+ }
+ }
+ onMethodEnd(method, testInstance, params, throwable);
+ }
+
+ private void onMethodStart(final Method method, final Object testInstance, final Object[] params) {
+ TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ ((PUnitEventListener) obj).onMethodStart(method, testInstance, params);
+ }
+ });
+ }
+
+ private void onMethodEnd(final Method method, final Object testInstance, 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);
+ }
+ });
+ }
+
+
+ protected abstract void runImpl() throws Throwable;
+
+ protected final void init(Object testInstance, Method method,
+ Object[] params) {
+ _testInstance = testInstance;
+ _class = testInstance.getClass();
+ _params = params;
+ _method = method;
+ _setUpMethod = ReflectionUtil.getMethodAndSetAccessible(_testInstance
+ .getClass(), "setUp", new Class[] {}); //$NON-NLS-1$
+ _tearDownMethod = ReflectionUtil.getMethodAndSetAccessible(
+ _testInstance.getClass(), "tearDown", new Class[] {}); //$NON-NLS-1$
+ }
+
+ /**
+ * This method might be overriden by subclass. The runner may do some more
+ * things during this step.
+ *
+ */
+ protected void setUpBeforeWatchers(Object[] params) throws Throwable {
+ if (TypeUtil.isPUnitTest(_class)) {
+ ((PUnitTest) _testInstance).setUpBeforeWatchers();
+ } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
+ ((Parameterizable) _testInstance).setUpBeforeWatchers((Parameter)params[0]);
+ }
+ }
+
+ private void setUpAfterWatchers(Object[] params) throws Throwable {
+ if (TypeUtil.isPUnitTest(_class)) {
+ ((PUnitTest) _testInstance).setUpAfterWatchers();
+ } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
+ ((Parameterizable) _testInstance).setUpAfterWatchers((Parameter)params[0]);
+ } else {
+ setUp();
+ }
+ }
+
+ private void tearDownBeforeWatchers(Object[] params) throws Throwable {
+ if (TypeUtil.isPUnitTest(_class)) {
+ ((PUnitTest) _testInstance).tearDownBeforeWatchers();
+ } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
+ ((Parameterizable) _testInstance).tearDownBeforeWatchers((Parameter)params[0]);
+ } else {
+ tearDown();
+ }
+ }
+
+ private void tearDownAfterWatchers(Object[] params) throws Throwable {
+ if (TypeUtil.isPUnitTest(_class)) {
+ ((PUnitTest) _testInstance).tearDownAfterWatchers();
+ } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
+ ((Parameterizable) _testInstance).tearDownAfterWatchers((Parameter)params[0]);
+ }
+ }
+
+ private void setUp() throws Throwable {
+ if (_setUpMethod != null) {
+ try {
+ ReflectionUtil.invokeMethod(_setUpMethod, _testInstance,
+ new Object[] {});
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+ }
+
+ private void tearDown() throws Throwable {
+ if (_tearDownMethod != null) {
+ try {
+ ReflectionUtil.invokeMethod(_tearDownMethod, _testInstance,
+ new Object[] {});
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+ }
+
+ protected final void startWatchers(final Object testInstance, final Method method, final Object[] params) {
+ onWatchersStart(testInstance, method, params);
+ TraverserUtil.traverse(_watchers.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ Watcher watcher = (Watcher) obj;
+ onWatcherStart(watcher, testInstance, method, params);
+ watcher.start();
+ }
+ });
+ }
+
+ private void onWatchersStart(final Object testInstance, final Method method, final Object[] params) {
+ TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ ((PUnitEventListener) obj).onWatchersStart(_watchers);
+ }
+ });
+ }
+
+ private void onWatcherStart(final Watcher watcher, final Object testInstance, final Method method, final Object[] params) {
+ TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ ((PUnitEventListener) obj).onWatcherStart(watcher);
+ }
+ });
+ }
+
+ protected final void stopWatchers(final Object testInstance, final Method method, final Object[] params) {
+ TraverserUtil.traverse(_watchers.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ Watcher watcher = (Watcher) obj;
+ watcher.stop();
+ onWatcherEnd(watcher, testInstance, method, params);
+ }
+ });
+ onWatchersEnd(testInstance, method, params);
+ }
+
+ private void onWatcherEnd(final Watcher watcher, final Object testInstance, final Method method, final Object[] params) {
+ TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ ((PUnitEventListener) obj).onWatcherEnd(watcher);
+ }
+ });
+ }
+
+ private void onWatchersEnd(final Object testInstance, final Method method, final Object[] params) {
+ TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ ((PUnitEventListener) obj).onWatchersEnd(_watchers);
+ }
+ });
+ }
+
+ private List eventListeners() {
+ return _eventListeners;
+ }
+
+ public List watchers() {
+ return _watchers;
+ }
+
+ public boolean needsRunMethod() {
+ return !_runnerProperties.isParent;
+ }
+
+}
Deleted: trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-27 08:16:42 UTC (rev 161)
+++ trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-27 08:18:25 UTC (rev 162)
@@ -1,257 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.runner.method;
-
-import java.lang.reflect.*;
-import java.util.*;
-
-import org.punit.events.*;
-import org.punit.exception.*;
-import org.punit.runner.*;
-import org.punit.type.*;
-import org.punit.util.*;
-import org.punit.watcher.*;
-
-public abstract class AbstractTestMethodRunner implements TestMethodRunner {
-
- protected List _watchers = new ArrayList(); // <Watcher>
-
- private TimeWatcher _timeWatcher = new TimeWatcher();
-
- private List _eventListeners; // List <PUnitEventListener>
-
- private RunnerProperties _runnerProperties;
-
- protected transient Object _testInstance;
-
- protected transient Method _method;
-
- protected transient Object[] _params;
-
- protected transient Class _class;
-
- protected transient Method _tearDownMethod;
-
- protected transient Method _setUpMethod;
-
- public AbstractTestMethodRunner() {
- _watchers.add(_timeWatcher);
- }
-
- public void setEventListeners(List eventListeners) {
- _eventListeners = eventListeners;
- }
-
- public void setRunnerProperties(RunnerProperties props) {
- _runnerProperties = props;
- }
-
- public void addWatcher(Watcher watcher) {
- _watchers.add(watcher);
- }
-
- public void removeWatcher(Watcher watcher) {
- _watchers.remove(watcher);
- }
-
- public void removeTimeWatcher() {
- _watchers.remove(_timeWatcher);
- }
-
- public void run(Object testInstance, Method method, Object[] params) {
- onMethodStart(method, testInstance, params);
- Throwable throwable = null;
- try {
- if(needsRunMethod()) {
- init(testInstance, method, params);
- setUpBeforeWatchers(params);
- startWatchers(testInstance, method, params);
- setUpAfterWatchers(params);
- runImpl();
- } else {
- startWatchers(testInstance, method, params);
- }
- } catch (Throwable t) {
- throwable = t;
- } finally {
- try {
- if(needsRunMethod()) {
- tearDownBeforeWatchers(params);
- }
- } catch (Throwable t) {
- throwable = t;
- } finally {
- try {
- stopWatchers(testInstance, method, params);
- if(needsRunMethod()) {
- tearDownAfterWatchers(params);
- }
- } catch (Throwable t) {
- throwable = t;
- }
- }
- }
- onMethodEnd(method, testInstance, params, throwable);
- }
-
- private void onMethodStart(final Method method, final Object testInstance, final Object[] params) {
- TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((PUnitEventListener) obj).onMethodStart(method, testInstance, params);
- }
- });
- }
-
- private void onMethodEnd(final Method method, final Object testInstance, 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);
- }
- });
- }
-
-
- protected abstract void runImpl() throws Throwable;
-
- protected final void init(Object testInstance, Method method,
- Object[] params) {
- _testInstance = testInstance;
- _class = testInstance.getClass();
- _params = params;
- _method = method;
- _setUpMethod = ReflectionUtil.getMethodAndSetAccessible(_testInstance
- .getClass(), "setUp", new Class[] {}); //$NON-NLS-1$
- _tearDownMethod = ReflectionUtil.getMethodAndSetAccessible(
- _testInstance.getClass(), "tearDown", new Class[] {}); //$NON-NLS-1$
- }
-
- /**
- * This method might be overriden by subclass. The runner may do some more
- * things during this step.
- *
- */
- protected void setUpBeforeWatchers(Object[] params) throws Throwable {
- if (TypeUtil.isPUnitTest(_class)) {
- ((PUnitTest) _testInstance).setUpBeforeWatchers();
- } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
- ((Parameterizable) _testInstance).setUpBeforeWatchers((Parameter)params[0]);
- }
- }
-
- private void setUpAfterWatchers(Object[] params) throws Throwable {
- if (TypeUtil.isPUnitTest(_class)) {
- ((PUnitTest) _testInstance).setUpAfterWatchers();
- } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
- ((Parameterizable) _testInstance).setUpAfterWatchers((Parameter)params[0]);
- } else {
- setUp();
- }
- }
-
- private void tearDownBeforeWatchers(Object[] params) throws Throwable {
- if (TypeUtil.isPUnitTest(_class)) {
- ((PUnitTest) _testInstance).tearDownBeforeWatchers();
- } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
- ((Parameterizable) _testInstance).tearDownBeforeWatchers((Parameter)params[0]);
- } else {
- tearDown();
- }
- }
-
- private void tearDownAfterWatchers(Object[] params) throws Throwable {
- if (TypeUtil.isPUnitTest(_class)) {
- ((PUnitTest) _testInstance).tearDownAfterWatchers();
- } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
- ((Parameterizable) _testInstance).tearDownAfterWatchers((Parameter)params[0]);
- }
- }
-
- private void setUp() throws Throwable {
- if (_setUpMethod != null) {
- try {
- ReflectionUtil.invokeMethod(_setUpMethod, _testInstance,
- new Object[] {});
- } catch (ReflectionException e) {
- throw e.getCause();
- }
- }
- }
-
- private void tearDown() throws Throwable {
- if (_tearDownMethod != null) {
- try {
- ReflectionUtil.invokeMethod(_tearDownMethod, _testInstance,
- new Object[] {});
- } catch (ReflectionException e) {
- throw e.getCause();
- }
- }
- }
-
- protected final void startWatchers(final Object testInstance, final Method method, final Object[] params) {
- onWatchersStart(testInstance, method, params);
- TraverserUtil.traverse(_watchers.iterator(), new Traverser() {
- public void traverse(Object obj) {
- Watcher watcher = (Watcher) obj;
- onWatcherStart(watcher, testInstance, method, params);
- watcher.start();
- }
- });
- }
-
- private void onWatchersStart(final Object testInstance, final Method method, final Object[] params) {
- TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((PUnitEventListener) obj).onWatchersStart(_watchers);
- }
- });
- }
-
- private void onWatcherStart(final Watcher watcher, final Object testInstance, final Method method, final Object[] params) {
- TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((PUnitEventListener) obj).onWatcherStart(watcher);
- }
- });
- }
-
- protected final void stopWatchers(final Object testInstance, final Method method, final Object[] params) {
- TraverserUtil.traverse(_watchers.iterator(), new Traverser() {
- public void traverse(Object obj) {
- Watcher watcher = (Watcher) obj;
- watcher.stop();
- onWatcherEnd(watcher, testInstance, method, params);
- }
- });
- onWatchersEnd(testInstance, method, params);
- }
-
- private void onWatcherEnd(final Watcher watcher, final Object testInstance, final Method method, final Object[] params) {
- TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((PUnitEventListener) obj).onWatcherEnd(watcher);
- }
- });
- }
-
- private void onWatchersEnd(final Object testInstance, final Method method, final Object[] params) {
- TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((PUnitEventListener) obj).onWatchersEnd(_watchers);
- }
- });
- }
-
- private List eventListeners() {
- return _eventListeners;
- }
-
- public List watchers() {
- return _watchers;
- }
-
- public boolean needsRunMethod() {
- return !_runnerProperties.isParent;
- }
-
-}
Copied: trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java (from rev 157, trunk/punit/src/org/punit/runner/method/ConcurrentTestMethodRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java 2007-05-27 08:18:25 UTC (rev 162)
@@ -0,0 +1,81 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.runner.method;
+
+import org.punit.exception.*;
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class ConcurrentMethodRunner extends AbstractMethodRunner {
+
+ private static final long serialVersionUID = 6423244395038097893L;
+
+ private transient TestMethodThread[] _threads;
+
+ private ConcurrentException _concurrentException = new ConcurrentException();
+
+ private int _concurrentCount;
+
+ public ConcurrentMethodRunner(int concurrentCount) {
+ _concurrentCount = concurrentCount;
+ }
+
+ protected void runImpl() throws Throwable {
+ startThreads();
+ joinThreads();
+ if (_concurrentException.size() > 0) {
+ throw _concurrentException;
+ }
+ }
+
+ protected void runMethod() throws Throwable {
+ ReflectionUtil.invokeMethod(_method, _testInstance, _params);
+ }
+
+ private void startThreads() {
+ for (int i = 0; i < _threads.length; ++i) {
+ _threads[i].start();
+ }
+ }
+
+ private void joinThreads() {
+ for (int i = 0; i < _threads.length; ++i) {
+ try {
+ _threads[i].join();
+ } catch (InterruptedException e) {
+ _concurrentException.add(e);
+ }
+ }
+ }
+
+ protected void setUpBeforeWatchers(Object[] params) throws Throwable {
+ super.setUpBeforeWatchers(params);
+ int threadCount = _concurrentCount;
+ if(_testInstance instanceof Concurrent) {
+ threadCount = ((Concurrent)_testInstance).concurrentCount();
+ }
+ _threads = new TestMethodThread[threadCount];
+ for (int i = 0; i < _threads.length; ++i) {
+ _threads[i] = new TestMethodThread(this, "punit concurrent method runner"); //$NON-NLS-1$
+ }
+ }
+
+ private class TestMethodThread extends Thread {
+ ConcurrentMethodRunner _runner;
+
+ public TestMethodThread(ConcurrentMethodRunner runner, String threadName) {
+ super(threadName);
+ _runner = runner;
+ }
+
+ public void run() {
+ try {
+ _runner.runMethod();
+ } catch (ReflectionException e) {
+ _concurrentException.add(e.getCause());
+ } catch (Throwable t) {
+ _concurrentException.add(t);
+ }
+ }
+ }
+}
Deleted: trunk/punit/src/org/punit/runner/method/ConcurrentTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/ConcurrentTestMethodRunner.java 2007-05-27 08:16:42 UTC (rev 161)
+++ trunk/punit/src/org/punit/runner/method/ConcurrentTestMethodRunner.java 2007-05-27 08:18:25 UTC (rev 162)
@@ -1,81 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.runner.method;
-
-import org.punit.exception.*;
-import org.punit.type.*;
-import org.punit.util.*;
-
-public class ConcurrentTestMethodRunner extends AbstractTestMethodRunner {
-
- private static final long serialVersionUID = 6423244395038097893L;
-
- private transient TestMethodThread[] _threads;
-
- private ConcurrentException _concurrentException = new ConcurrentException();
-
- private int _concurrentCount;
-
- public ConcurrentTestMethodRunner(int concurrentCount) {
- _concurrentCount = concurrentCount;
- }
-
- protected void runImpl() throws Throwable {
- startThreads();
- joinThreads();
- if (_concurrentException.size() > 0) {
- throw _concurrentException;
- }
- }
-
- protected void runMethod() throws Throwable {
- ReflectionUtil.invokeMethod(_method, _testInstance, _params);
- }
-
- private void startThreads() {
- for (int i = 0; i < _threads.length; ++i) {
- _threads[i].start();
- }
- }
-
- private void joinThreads() {
- for (int i = 0; i < _threads.length; ++i) {
- try {
- _threads[i].join();
- } catch (InterruptedException e) {
- _concurrentException.add(e);
- }
- }
- }
-
- protected void setUpBeforeWatchers(Object[] params) throws Throwable {
- super.setUpBeforeWatchers(params);
- int threadCount = _concurrentCount;
- if(_testInstance instanceof Concurrent) {
- threadCount = ((Concurrent)_testInstance).concurrentCount();
- }
- _threads = new TestMethodThread[threadCount];
- for (int i = 0; i < _threads.length; ++i) {
- _threads[i] = new TestMethodThread(this, "punit concurrent method runner"); //$NON-NLS-1$
- }
- }
-
- private class TestMethodThread extends Thread {
- ConcurrentTestMethodRunner _runner;
-
- public TestMethodThread(ConcurrentTestMethodRunner runner, String threadName) {
- super(threadName);
- _runner = runner;
- }
-
- public void run() {
- try {
- _runner.runMethod();
- } catch (ReflectionException e) {
- _concurrentException.add(e.getCause());
- } catch (Throwable t) {
- _concurrentException.add(t);
- }
- }
- }
-}
Copied: trunk/punit/src/org/punit/runner/method/MethodRunner.java (from rev 156, trunk/punit/src/org/punit/runner/method/TestMethodRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/method/MethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/method/MethodRunner.java 2007-05-27 08:18:25 UTC (rev 162)
@@ -0,0 +1,37 @@
+package org.punit.runner.method;
+
+import java.io.*;
+import java.lang.reflect.*;
+import java.util.*;
+
+import org.punit.runner.*;
+import org.punit.watcher.*;
+
+public interface MethodRunner extends Serializable{
+ /**
+ * Runs the test method.
+ * @param testInstance
+ * @param method
+ * @param params
+ * @return returns the exception if there is any during the execution.
+ */
+ public void run(Object testInstance, Method method, Object[] params);
+
+ /**
+ *
+ * @param eventListeners List <PUnitEventListener>
+ */
+ public void setEventListeners(List eventListeners);
+
+ public void setRunnerProperties(RunnerProperties props);
+
+ /**
+ * returns the watchers associated with this method runner.
+ * @return
+ */
+ public List watchers();
+
+ public void addWatcher(Watcher watcher);
+
+ public void removeWatcher(Watcher watcher);
+}
Copied: trunk/punit/src/org/punit/runner/method/SoloMethodRunner.java (from rev 154, trunk/punit/src/org/punit/runner/method/SoloTestMethodRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/method/SoloMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/method/SoloMethodRunner.java 2007-05-27 08:18:25 UTC (rev 162)
@@ -0,0 +1,20 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.runner.method;
+
+import org.punit.exception.*;
+import org.punit.util.*;
+
+public class SoloMethodRunner extends AbstractMethodRunner {
+
+ private static final long serialVersionUID = 3278612571978181393L;
+
+ protected void runImpl() throws Throwable {
+ try {
+ ReflectionUtil.invokeMethod(_method, _testInstance, _params);
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+
+}
Deleted: trunk/punit/src/org/punit/runner/method/SoloTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/SoloTestMethodRunner.java 2007-05-27 08:16:42 UTC (rev 161)
+++ trunk/punit/src/org/punit/runner/method/SoloTestMethodRunner.java 2007-05-27 08:18:25 UTC (rev 162)
@@ -1,20 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.runner.method;
-
-import org.punit.exception.*;
-import org.punit.util.*;
-
-public class SoloTestMethodRunner extends AbstractTestMethodRunner {
-
- private static final long serialVersionUID = 3278612571978181393L;
-
- protected void runImpl() throws Throwable {
- try {
- ReflectionUtil.invokeMethod(_method, _testInstance, _params);
- } catch (ReflectionException e) {
- throw e.getCause();
- }
- }
-
-}
Deleted: trunk/punit/src/org/punit/runner/method/TestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/TestMethodRunner.java 2007-05-27 08:16:42 UTC (rev 161)
+++ trunk/punit/src/org/punit/runner/method/TestMethodRunner.java 2007-05-27 08:18:25 UTC (rev 162)
@@ -1,37 +0,0 @@
-package org.punit.runner.method;
-
-import java.io.*;
-import java.lang.reflect.*;
-import java.util.*;
-
-import org.punit.runner.*;
-import org.punit.watcher.*;
-
-public interface TestMethodRunner extends Serializable{
- /**
- * Runs the test method.
- * @param testInstance
- * @param method
- * @param params
- * @return returns the exception if there is any during the execution.
- */
- public void run(Object testInstance, Method method, Object[] params);
-
- /**
- *
- * @param eventListeners List <PUnitEventListener>
- */
- public void setEventListeners(List eventListeners);
-
- public void setRunnerProperties(RunnerProperties props);
-
- /**
- * returns the watchers associated with this method runner.
- * @return
- */
- public List watchers();
-
- public void addWatcher(Watcher watcher);
-
- public void removeWatcher(Watcher watcher);
-}
Modified: trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java 2007-05-27 08:16:42 UTC (rev 161)
+++ trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java 2007-05-27 08:18:25 UTC (rev 162)
@@ -23,7 +23,7 @@
assertEquals(1, watchers.size());
}
- static class MockTestMethodRunnerTest extends AbstractTestMethodRunner {
+ static class MockTestMethodRunnerTest extends AbstractMethodRunner {
protected void runImpl() throws Throwable {
throw new UnsupportedOperationException();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-27 09:12:07
|
Revision: 163
http://p-unit.svn.sourceforge.net/p-unit/?rev=163&view=rev
Author: zhanghuangzhu
Date: 2007-05-27 02:12:08 -0700 (Sun, 27 May 2007)
Log Message:
-----------
Andrew Zhang: add clone method in Runner so that the output is correct.
Modified Paths:
--------------
trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java
trunk/punit/src/org/punit/runner/method/MethodRunner.java
trunk/punit/src/org/punit/watcher/MemoryWatcher.java
trunk/punit/src/org/punit/watcher/TimeWatcher.java
trunk/punit/src/org/punit/watcher/Watcher.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloRunnerTest.java
Added Paths:
-----------
trunk/punit.test/src/tests/api/org/punit/runner/AbstractRunnerTest.java
Removed Paths:
-------------
trunk/punit.test/src/tests/api/org/punit/runner/AbstractPUnitRunnerTest.java
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-27 08:18:25 UTC (rev 162)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-27 09:12:08 UTC (rev 163)
@@ -114,23 +114,30 @@
}
private void logTestMethodResult(Method method, Object[] params, List watchers, Throwable t) {
- log(ReporterUtil.simpleMethodName(method, params), Level.INFO);
+ final StringBuffer sb = new StringBuffer();
+ String simpleMethodName = ReporterUtil.simpleMethodName(method, params);
+ sb.append(simpleMethodName);
if (watchers.size() > 0) {
final Iterator iter = watchers.iterator();
Watcher watcher = (Watcher) iter.next();
- log(" - [" + watcher.stringValue(), Level.FINE); //$NON-NLS-1$
+ sb.append(" - ["); //$NON-NLS-1$
+ sb.append(watcher.stringValue());
TraverserUtil.traverse(iter, new Traverser() {
public void traverse(Object obj) {
Watcher watcher = (Watcher) obj;
- log("," + watcher.stringValue(), Level.FINE); //$NON-NLS-1$
+ sb.append(","); //$NON-NLS-1$
+ sb.append(watcher.stringValue());
}
});
- log("]", Level.INFO); //$NON-NLS-1$
+ sb.append("]"); //$NON-NLS-1$
}
- logln(Level.INFO);
+
+ sb.append(ReporterUtil.LINE_SEPERATOR);
if(t != null) {
- logln(t.toString(), Level.INFO);
+ sb.append(t.toString());
+ sb.append(ReporterUtil.LINE_SEPERATOR);
}
+ log(sb.toString(), Level.INFO);
}
public void setStream(PrintStream out, PrintStream err) {
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-27 08:18:25 UTC (rev 162)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-27 09:12:08 UTC (rev 163)
@@ -21,7 +21,7 @@
private TestMethodBuilder _testMethodBuilder;
- private MethodRunner _testMethodRunner;
+ private MethodRunner _methodRunner;
// List <PUnitEventListener>
private final List _eventListeners = new ArrayList();
@@ -29,17 +29,16 @@
private ConsoleLogger _consoleLogger = new ConsoleLogger();
private RunnerProperties _properties = new RunnerProperties();
-
+
private ExecutorPool _executorPool;
public PUnitAbstractRunner(TestSuiteBuilder testSuiteBuiler,
- TestMethodBuilder testMethodBuilder,
- MethodRunner testMethodRunner) {
+ TestMethodBuilder testMethodBuilder, MethodRunner testMethodRunner) {
_testSuiteBuiler = testSuiteBuiler;
_testMethodBuilder = testMethodBuilder;
- _testMethodRunner = testMethodRunner;
- _testMethodRunner.setEventListeners(_eventListeners);
- _testMethodRunner.setRunnerProperties(_properties);
+ _methodRunner = testMethodRunner;
+ _methodRunner.setEventListeners(_eventListeners);
+ _methodRunner.setRunnerProperties(_properties);
registerLoggerListeners();
}
@@ -67,19 +66,19 @@
public void setExecutorPool(ExecutorPool pool) {
_executorPool = pool;
}
-
+
private void startExecutorPool() {
- if(_executorPool != null) {
+ if (_executorPool != null) {
_executorPool.start();
}
}
private void waitExecutorPoolTermination() {
- if(_executorPool != null) {
+ if (_executorPool != null) {
_executorPool.join();
}
}
-
+
public void run(Class clazz, RunnerProperties properties) {
setRunnerProperties(properties);
run(clazz);
@@ -87,7 +86,7 @@
private void setRunnerProperties(RunnerProperties properties) {
_properties = properties;
- _testMethodRunner.setRunnerProperties(_properties);
+ _methodRunner.setRunnerProperties(_properties);
}
public void runVMs(Class clazz, VM[] vms) {
@@ -206,7 +205,7 @@
}
private void runTestClass(final Class clazz) {
- if(_executorPool == null) {
+ if (_executorPool == null) {
runTestClassImpl(clazz);
} else {
_executorPool.execute(new RunTestClassTask(clazz));
@@ -219,13 +218,14 @@
public RunTestClassTask(Class clazz) {
_clazz = clazz;
}
-
+
public void run() {
- runTestClassImpl(_clazz);
+ PUnitAbstractRunner runner = (PUnitAbstractRunner)PUnitAbstractRunner.this.clone();
+ runner.runTestClassImpl(_clazz);
}
-
+
}
-
+
private void runTestClassImpl(final Class clazz) {
onClassStart(clazz);
Collection testMethods = buildTestMethod(clazz);
@@ -283,7 +283,7 @@
private void runTestMethod(Object testInstance, Method method,
Object[] params) {
- _testMethodRunner.run(testInstance, method, params);
+ _methodRunner.run(testInstance, method, params);
}
private Collection buildTestMethod(Class testClass) {
@@ -295,7 +295,7 @@
}
public MethodRunner methodRunner() {
- return _testMethodRunner;
+ return _methodRunner;
}
public TestSuiteBuilder suiteBuiler() {
@@ -333,4 +333,14 @@
private boolean isTestSuiteLabel(Object testClass) {
return testClass instanceof TestSuiteLabel;
}
+
+ public Object clone() {
+ try {
+ PUnitAbstractRunner runner = (PUnitAbstractRunner) super.clone();
+ runner._methodRunner = (MethodRunner) _methodRunner.clone();
+ return runner;
+ } catch (CloneNotSupportedException e) {
+ throw new ReflectionException(e);
+ }
+ }
}
Modified: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java 2007-05-27 08:18:25 UTC (rev 162)
+++ trunk/punit/src/org/punit/runner/Runner.java 2007-05-27 09:12:08 UTC (rev 163)
@@ -1,3 +1,5 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
package org.punit.runner;
import java.io.*;
@@ -8,7 +10,7 @@
import org.punit.runner.method.*;
import org.punit.type.*;
-public interface Runner extends PUnitEventRegsitry, PUnitName, Serializable {
+public interface Runner extends PUnitEventRegsitry, PUnitName, Serializable, Cloneable {
public void run(Class clazz);
Modified: trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java 2007-05-27 08:18:25 UTC (rev 162)
+++ trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java 2007-05-27 09:12:08 UTC (rev 163)
@@ -14,12 +14,12 @@
public abstract class AbstractMethodRunner implements MethodRunner {
- protected List _watchers = new ArrayList(); // <Watcher>
-
+ protected ArrayList _watchers = new ArrayList(); // <Watcher>
+
private TimeWatcher _timeWatcher = new TimeWatcher();
-
+
private List _eventListeners; // List <PUnitEventListener>
-
+
private RunnerProperties _runnerProperties;
protected transient Object _testInstance;
@@ -41,28 +41,28 @@
public void setEventListeners(List eventListeners) {
_eventListeners = eventListeners;
}
-
+
public void setRunnerProperties(RunnerProperties props) {
_runnerProperties = props;
}
-
+
public void addWatcher(Watcher watcher) {
_watchers.add(watcher);
}
-
+
public void removeWatcher(Watcher watcher) {
_watchers.remove(watcher);
}
-
+
public void removeTimeWatcher() {
_watchers.remove(_timeWatcher);
}
-
+
public void run(Object testInstance, Method method, Object[] params) {
onMethodStart(method, testInstance, params);
Throwable throwable = null;
try {
- if(needsRunMethod()) {
+ if (needsRunMethod()) {
init(testInstance, method, params);
setUpBeforeWatchers(params);
startWatchers(testInstance, method, params);
@@ -75,7 +75,7 @@
throwable = t;
} finally {
try {
- if(needsRunMethod()) {
+ if (needsRunMethod()) {
tearDownBeforeWatchers(params);
}
} catch (Throwable t) {
@@ -83,7 +83,7 @@
} finally {
try {
stopWatchers(testInstance, method, params);
- if(needsRunMethod()) {
+ if (needsRunMethod()) {
tearDownAfterWatchers(params);
}
} catch (Throwable t) {
@@ -93,24 +93,27 @@
}
onMethodEnd(method, testInstance, params, throwable);
}
-
- private void onMethodStart(final Method method, final Object testInstance, final Object[] params) {
+
+ private void onMethodStart(final Method method, final Object testInstance,
+ final Object[] params) {
TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
public void traverse(Object obj) {
- ((PUnitEventListener) obj).onMethodStart(method, testInstance, params);
+ ((PUnitEventListener) obj).onMethodStart(method, testInstance,
+ params);
}
});
}
- private void onMethodEnd(final Method method, final Object testInstance, final Object[] params, final Throwable t) {
+ private void onMethodEnd(final Method method, final Object testInstance,
+ 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);
+ ((PUnitEventListener) obj).onMethodEnd(method, testInstance,
+ params, t, _watchers);
}
});
}
-
protected abstract void runImpl() throws Throwable;
protected final void init(Object testInstance, Method method,
@@ -134,7 +137,8 @@
if (TypeUtil.isPUnitTest(_class)) {
((PUnitTest) _testInstance).setUpBeforeWatchers();
} else if (TypeUtil.isPUnitParameterizableTest(_class)) {
- ((Parameterizable) _testInstance).setUpBeforeWatchers((Parameter)params[0]);
+ ((Parameterizable) _testInstance)
+ .setUpBeforeWatchers((Parameter) params[0]);
}
}
@@ -142,7 +146,8 @@
if (TypeUtil.isPUnitTest(_class)) {
((PUnitTest) _testInstance).setUpAfterWatchers();
} else if (TypeUtil.isPUnitParameterizableTest(_class)) {
- ((Parameterizable) _testInstance).setUpAfterWatchers((Parameter)params[0]);
+ ((Parameterizable) _testInstance)
+ .setUpAfterWatchers((Parameter) params[0]);
} else {
setUp();
}
@@ -151,8 +156,9 @@
private void tearDownBeforeWatchers(Object[] params) throws Throwable {
if (TypeUtil.isPUnitTest(_class)) {
((PUnitTest) _testInstance).tearDownBeforeWatchers();
- } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
- ((Parameterizable) _testInstance).tearDownBeforeWatchers((Parameter)params[0]);
+ } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
+ ((Parameterizable) _testInstance)
+ .tearDownBeforeWatchers((Parameter) params[0]);
} else {
tearDown();
}
@@ -161,9 +167,10 @@
private void tearDownAfterWatchers(Object[] params) throws Throwable {
if (TypeUtil.isPUnitTest(_class)) {
((PUnitTest) _testInstance).tearDownAfterWatchers();
- } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
- ((Parameterizable) _testInstance).tearDownAfterWatchers((Parameter)params[0]);
- }
+ } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
+ ((Parameterizable) _testInstance)
+ .tearDownAfterWatchers((Parameter) params[0]);
+ }
}
private void setUp() throws Throwable {
@@ -188,7 +195,8 @@
}
}
- protected final void startWatchers(final Object testInstance, final Method method, final Object[] params) {
+ protected final void startWatchers(final Object testInstance,
+ final Method method, final Object[] params) {
onWatchersStart(testInstance, method, params);
TraverserUtil.traverse(_watchers.iterator(), new Traverser() {
public void traverse(Object obj) {
@@ -199,15 +207,18 @@
});
}
- private void onWatchersStart(final Object testInstance, final Method method, final Object[] params) {
+ private void onWatchersStart(final Object testInstance,
+ final Method method, final Object[] params) {
TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
public void traverse(Object obj) {
((PUnitEventListener) obj).onWatchersStart(_watchers);
}
});
}
-
- private void onWatcherStart(final Watcher watcher, final Object testInstance, final Method method, final Object[] params) {
+
+ private void onWatcherStart(final Watcher watcher,
+ final Object testInstance, final Method method,
+ final Object[] params) {
TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
public void traverse(Object obj) {
((PUnitEventListener) obj).onWatcherStart(watcher);
@@ -215,7 +226,8 @@
});
}
- protected final void stopWatchers(final Object testInstance, final Method method, final Object[] params) {
+ protected final void stopWatchers(final Object testInstance,
+ final Method method, final Object[] params) {
TraverserUtil.traverse(_watchers.iterator(), new Traverser() {
public void traverse(Object obj) {
Watcher watcher = (Watcher) obj;
@@ -226,15 +238,17 @@
onWatchersEnd(testInstance, method, params);
}
- private void onWatcherEnd(final Watcher watcher, final Object testInstance, final Method method, final Object[] params) {
+ private void onWatcherEnd(final Watcher watcher, final Object testInstance,
+ final Method method, final Object[] params) {
TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
public void traverse(Object obj) {
((PUnitEventListener) obj).onWatcherEnd(watcher);
}
});
}
-
- private void onWatchersEnd(final Object testInstance, final Method method, final Object[] params) {
+
+ private void onWatchersEnd(final Object testInstance, final Method method,
+ final Object[] params) {
TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
public void traverse(Object obj) {
((PUnitEventListener) obj).onWatchersEnd(_watchers);
@@ -253,5 +267,22 @@
public boolean needsRunMethod() {
return !_runnerProperties.isParent;
}
-
+
+ public Object clone() {
+ try {
+ final AbstractMethodRunner methodRunner = (AbstractMethodRunner) super
+ .clone();
+ methodRunner._watchers = (ArrayList) _watchers.clone();
+ methodRunner._watchers.clear();
+ TraverserUtil.traverse(_watchers.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ Watcher watcher = (Watcher) obj;
+ methodRunner.addWatcher(watcher.cloneSelf());
+ }
+ });
+ return methodRunner;
+ } catch (CloneNotSupportedException e) {
+ throw new ReflectionException(e);
+ }
+ }
}
Modified: trunk/punit/src/org/punit/runner/method/MethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/MethodRunner.java 2007-05-27 08:18:25 UTC (rev 162)
+++ trunk/punit/src/org/punit/runner/method/MethodRunner.java 2007-05-27 09:12:08 UTC (rev 163)
@@ -7,7 +7,7 @@
import org.punit.runner.*;
import org.punit.watcher.*;
-public interface MethodRunner extends Serializable{
+public interface MethodRunner extends Serializable, Cloneable {
/**
* Runs the test method.
* @param testInstance
@@ -34,4 +34,6 @@
public void addWatcher(Watcher watcher);
public void removeWatcher(Watcher watcher);
+
+ public Object clone();
}
Modified: trunk/punit/src/org/punit/watcher/MemoryWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-27 08:18:25 UTC (rev 162)
+++ trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-27 09:12:08 UTC (rev 163)
@@ -2,6 +2,7 @@
package org.punit.watcher;
+import org.punit.exception.*;
import org.punit.message.*;
import org.punit.util.*;
@@ -62,4 +63,12 @@
public String unit() {
return Messages.getString("watcher.01"); //$NON-NLS-1$
}
+
+ public Watcher cloneSelf() {
+ try {
+ return (Watcher) clone();
+ } catch (CloneNotSupportedException e) {
+ throw new ReflectionException(e);
+ }
+ }
}
Modified: trunk/punit/src/org/punit/watcher/TimeWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/TimeWatcher.java 2007-05-27 08:18:25 UTC (rev 162)
+++ trunk/punit/src/org/punit/watcher/TimeWatcher.java 2007-05-27 09:12:08 UTC (rev 163)
@@ -2,6 +2,7 @@
package org.punit.watcher;
+import org.punit.exception.*;
import org.punit.message.*;
public class TimeWatcher implements Watcher {
@@ -35,4 +36,12 @@
public String unit() {
return Messages.getString("watcher.02"); //$NON-NLS-1$
}
+
+ public Watcher cloneSelf() {
+ try {
+ return (Watcher) clone();
+ } catch (CloneNotSupportedException e) {
+ throw new ReflectionException(e);
+ }
+ }
}
Modified: trunk/punit/src/org/punit/watcher/Watcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/Watcher.java 2007-05-27 08:18:25 UTC (rev 162)
+++ trunk/punit/src/org/punit/watcher/Watcher.java 2007-05-27 09:12:08 UTC (rev 163)
@@ -1,3 +1,5 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
package org.punit.watcher;
import java.io.*;
@@ -4,7 +6,7 @@
import org.punit.type.*;
-public interface Watcher extends PUnitName, Serializable {
+public interface Watcher extends PUnitName, Serializable, Cloneable {
public void start();
@@ -16,4 +18,6 @@
public String unit();
+ public Watcher cloneSelf();
+
}
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-27 08:18:25 UTC (rev 162)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-27 09:12:08 UTC (rev 163)
@@ -26,6 +26,7 @@
public static Class[] testCases() {
return new Class[] {
AbstractChartReporterTest.class,
+ AbstractRunnerTest.class,
AbstractTestMethodRunnerTest.class,
ConcurrentExceptionTest.class,
LoggerUtilTest.class,
Deleted: trunk/punit.test/src/tests/api/org/punit/runner/AbstractPUnitRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/AbstractPUnitRunnerTest.java 2007-05-27 08:18:25 UTC (rev 162)
+++ trunk/punit.test/src/tests/api/org/punit/runner/AbstractPUnitRunnerTest.java 2007-05-27 09:12:08 UTC (rev 163)
@@ -1,9 +0,0 @@
-package tests.api.org.punit.runner;
-
-import junit.framework.*;
-
-public abstract class AbstractPUnitRunnerTest extends TestCase {
-
- protected MockPUnitEventListener _eventListener = new MockPUnitEventListener();
-
-}
\ No newline at end of file
Copied: trunk/punit.test/src/tests/api/org/punit/runner/AbstractRunnerTest.java (from rev 90, trunk/punit.test/src/tests/api/org/punit/runner/AbstractPUnitRunnerTest.java)
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/AbstractRunnerTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/AbstractRunnerTest.java 2007-05-27 09:12:08 UTC (rev 163)
@@ -0,0 +1,37 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.runner;
+
+import org.punit.builder.method.*;
+import org.punit.builder.suite.*;
+import org.punit.runner.*;
+import org.punit.runner.method.*;
+
+import junit.framework.*;
+
+public class AbstractRunnerTest extends TestCase {
+
+ protected MockPUnitEventListener _eventListener = new MockPUnitEventListener();
+
+ public void testCloneSelf() throws Exception {
+ MockAbstractPUnitRunner runner = new MockAbstractPUnitRunner();
+ PUnitAbstractRunner cloned = (PUnitAbstractRunner) runner.clone();
+ assertSame(runner.eventListeners(),cloned.eventListeners());
+ assertSame(runner.methodBuilder(), cloned.methodBuilder());
+ assertNotSame(runner.methodRunner(), cloned.methodRunner());
+ assertNotSame(runner.methodRunner().watchers(), cloned.methodRunner().watchers());
+ }
+
+ static class MockAbstractPUnitRunner extends PUnitAbstractRunner {
+
+ public MockAbstractPUnitRunner() {
+ super(new PUnitTestSuiteBuilder(), new PUnitTestMethodBuilder(),
+ new SoloMethodRunner());
+ }
+
+ public String punitName() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+}
\ No newline at end of file
Modified: trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloRunnerTest.java 2007-05-27 08:18:25 UTC (rev 162)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloRunnerTest.java 2007-05-27 09:12:08 UTC (rev 163)
@@ -9,7 +9,7 @@
import tests.api.org.punit.testclasses.*;
import tests.util.*;
-public class PUnitSoloRunnerTest extends AbstractPUnitRunnerTest {
+public class PUnitSoloRunnerTest extends AbstractRunnerTest {
private PUnitSoloRunner _runner;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-27 09:15:20
|
Revision: 164
http://p-unit.svn.sourceforge.net/p-unit/?rev=164&view=rev
Author: zhanghuangzhu
Date: 2007-05-27 02:15:20 -0700 (Sun, 27 May 2007)
Log Message:
-----------
Andrew Zhang: Simplify runner name.
Modified Paths:
--------------
trunk/punit.samples/src/samples/ExecutorPoolSample.java
trunk/punit.samples/src/samples/JUnitTestClass.java
trunk/punit.samples/src/samples/MultiThreadRunnerSample.java
trunk/punit.samples/src/samples/ParamTestClass.java
trunk/punit.samples/src/samples/RunnerSamples.java
trunk/punit.samples/src/samples/SimpleTestClass.java
trunk/punit.samples/src/samples/vms/ListVMTest.java
trunk/punit.test/src/extension/tests/api/org/punit/runner/PUnitSoloRunnerTest.java
trunk/punit.test/src/extension/tests/samples/JUnitTestSample.java
trunk/punit.test/src/extension/tests/samples/OverviewVMsSample.java
trunk/punit.test/src/extension/tests/samples/PUnitTestSuiteSample.java
trunk/punit.test/src/extension/tests/samples/TestClassVMsSample.java
trunk/punit.test/src/extension/tests/samples/TestSuiteVMsSample.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java
trunk/punit.test/src/tests/api/org/punit/runner/AbstractRunnerTest.java
trunk/punit.test/src/tests/samples/ConcurrentParameterizableTestSample.java
trunk/punit.test/src/tests/samples/ConcurrentTestSample.java
trunk/punit.test/src/tests/samples/JUnitTestSample.java
trunk/punit.test/src/tests/samples/PUnitTestCaseSample.java
trunk/punit.test/src/tests/samples/PUnitTestSuiteSample.java
trunk/punit.test/src/tests/samples/ParameterizableTestSample.java
trunk/punit.test/src/tests/samples/SimpleTestSample.java
trunk/punit.test/src/tests/samples/VMsSample.java
Added Paths:
-----------
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit/src/org/punit/runner/ConcurrentRunner.java
trunk/punit/src/org/punit/runner/SoloRunner.java
trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/ExecutorPoolTest.java
trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
Removed Paths:
-------------
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitExecutorPoolTest.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloRunnerTest.java
Copied: trunk/punit/src/org/punit/runner/AbstractRunner.java (from rev 163, trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-05-27 09:15:20 UTC (rev 164)
@@ -0,0 +1,346 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.runner;
+
+import java.io.*;
+import java.lang.reflect.*;
+import java.util.*;
+
+import org.punit.builder.method.*;
+import org.punit.builder.suite.*;
+import org.punit.events.*;
+import org.punit.exception.*;
+import org.punit.reporter.stream.console.*;
+import org.punit.runner.method.*;
+import org.punit.type.*;
+import org.punit.util.*;
+
+public abstract class AbstractRunner implements Runner {
+
+ private TestSuiteBuilder _testSuiteBuiler;
+
+ private TestMethodBuilder _testMethodBuilder;
+
+ private MethodRunner _methodRunner;
+
+ // List <PUnitEventListener>
+ private final List _eventListeners = new ArrayList();
+
+ private ConsoleLogger _consoleLogger = new ConsoleLogger();
+
+ private RunnerProperties _properties = new RunnerProperties();
+
+ private ExecutorPool _executorPool;
+
+ public AbstractRunner(TestSuiteBuilder testSuiteBuiler,
+ TestMethodBuilder testMethodBuilder, MethodRunner testMethodRunner) {
+ _testSuiteBuiler = testSuiteBuiler;
+ _testMethodBuilder = testMethodBuilder;
+ _methodRunner = testMethodRunner;
+ _methodRunner.setEventListeners(_eventListeners);
+ _methodRunner.setRunnerProperties(_properties);
+ registerLoggerListeners();
+ }
+
+ public void run(Class clazz) {
+ initResultFolder();
+ onRunnerStart(clazz);
+ Object[] testClasses = _testSuiteBuiler.buildTestClasses(clazz);
+ runTestClasses(testClasses);
+ onRunnerEnd(clazz);
+ }
+
+ private void runTestClasses(Object[] testClasses) {
+ startExecutorPool();
+ for (int i = 0; i < testClasses.length; ++i) {
+ Object testClass = testClasses[i];
+ if (isTestSuiteLabel(testClass)) {
+ onSuite(((TestSuiteLabel) testClass));
+ } else {
+ runTestClass((Class) testClass);
+ }
+ }
+ waitExecutorPoolTermination();
+ }
+
+ public void setExecutorPool(ExecutorPool pool) {
+ _executorPool = pool;
+ }
+
+ private void startExecutorPool() {
+ if (_executorPool != null) {
+ _executorPool.start();
+ }
+ }
+
+ private void waitExecutorPoolTermination() {
+ if (_executorPool != null) {
+ _executorPool.join();
+ }
+ }
+
+ public void run(Class clazz, RunnerProperties properties) {
+ setRunnerProperties(properties);
+ run(clazz);
+ }
+
+ private void setRunnerProperties(RunnerProperties properties) {
+ _properties = properties;
+ _methodRunner.setRunnerProperties(_properties);
+ }
+
+ public void runVMs(Class clazz, VM[] vms) {
+ initResultFolder();
+ _properties.isParent = true;
+ _properties.vms = vms;
+ for (int i = 0; i < vms.length; ++i) {
+ VM vm = vms[i];
+ storeRunnerConfig(vm);
+ storeRunnerProperties(vm);
+ String command = generateVMCommand(clazz, vm);
+ Process p = IOUtil.exec(command);
+ readErrorStream(p);
+ readOutputStream(p);
+ try {
+ p.waitFor();
+ } catch (InterruptedException e) {
+ throw new PUnitIOException(e);
+ }
+ deleteRunnerConfig(vm);
+ deleteRunnerProperties(vm);
+ }
+ filterNonParentEventListeners();
+ run(clazz);
+ }
+
+ private void readOutputStream(Process p) {
+ new StreamReaderThread(p.getInputStream(), false).start();
+ }
+
+ private void readErrorStream(Process p) {
+ new StreamReaderThread(p.getErrorStream(), true).start();
+ }
+
+ private void filterNonParentEventListeners() {
+ final List newEventListener = new ArrayList();
+ TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ PUnitEventListener listener = ((PUnitEventListener) obj);
+ if (listener.supportParentRunner()) {
+ newEventListener.add(listener);
+ }
+ }
+ });
+ _eventListeners.clear();
+ _eventListeners.addAll(newEventListener);
+ }
+
+ private void deleteRunnerProperties(VM vm) {
+ IOUtil.deleteFile(runnerPropertiesFileName(vm));
+ }
+
+ private void deleteRunnerConfig(VM vm) {
+ IOUtil.deleteFile(runnerConfigFileName(vm));
+ }
+
+ private void storeRunnerProperties(VM vm) {
+ RunnerProperties properties = new RunnerProperties();
+ properties.vmName = vm.punitName();
+ properties.isIntermediate = true;
+ IOUtil.serialize(properties, runnerPropertiesFileName(vm));
+ }
+
+ private void storeRunnerConfig(VM vm) {
+ IOUtil.serialize(this, runnerConfigFileName(vm));
+ }
+
+ private String runnerConfigFileName(VM vm) {
+ return RunnerConstants.RESULT_FOLDER + File.separator + vm.punitName()
+ + ".cfg"; //$NON-NLS-1$
+ }
+
+ private String runnerPropertiesFileName(VM vm) {
+ return RunnerConstants.RESULT_FOLDER + File.separator + vm.punitName()
+ + ".props"; //$NON-NLS-1$
+ }
+
+ public RunnerProperties properties() {
+ return _properties;
+ }
+
+ private String generateVMCommand(Class clazz, VM vm) {
+ final StringBuffer sb = new StringBuffer();
+ sb.append(vm.path());
+ sb.append(" "); //$NON-NLS-1$
+ sb.append(this.getClass().getName());
+ sb.append(" "); //$NON-NLS-1$
+ sb.append(clazz.getName());
+ sb.append(" "); //$NON-NLS-1$
+ sb.append(runnerConfigFileName(vm));
+ sb.append(" "); //$NON-NLS-1$
+ sb.append(runnerPropertiesFileName(vm));
+ return sb.toString();
+ }
+
+ private void onRunnerStart(final Class clazz) {
+ TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ ((PUnitEventListener) obj).onRunnerStart(clazz,
+ AbstractRunner.this);
+ }
+ });
+ }
+
+ private void initResultFolder() {
+ new File(RunnerConstants.RESULT_FOLDER).mkdir();
+ }
+
+ private void onRunnerEnd(final Class clazz) {
+ TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ ((PUnitEventListener) obj).onRunnerEnd(clazz,
+ AbstractRunner.this);
+ }
+ });
+ }
+
+ private void runTestClass(final Class clazz) {
+ if (_executorPool == null) {
+ runTestClassImpl(clazz);
+ } else {
+ _executorPool.execute(new RunTestClassTask(clazz));
+ }
+ }
+
+ private class RunTestClassTask implements Runnable {
+ private Class _clazz;
+
+ public RunTestClassTask(Class clazz) {
+ _clazz = clazz;
+ }
+
+ public void run() {
+ AbstractRunner runner = (AbstractRunner)AbstractRunner.this.clone();
+ runner.runTestClassImpl(_clazz);
+ }
+
+ }
+
+ private void runTestClassImpl(final Class clazz) {
+ onClassStart(clazz);
+ Collection testMethods = buildTestMethod(clazz);
+ TraverserUtil.traverse(testMethods.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ Method method = (Method) obj;
+ runTestMethod(clazz, method);
+ }
+ });
+ onClassEnd(clazz);
+ }
+
+ 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();
+ if (suiteLabel.isStart()) {
+ listener.onSuiteStart(suite);
+ } else {
+ listener.onSuiteEnd(suite);
+ }
+ }
+ });
+ }
+
+ private void onClassStart(final Class clazz) {
+ TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ ((PUnitEventListener) obj).onClassStart(clazz);
+ }
+ });
+ }
+
+ private void onClassEnd(final Class clazz) {
+ TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ ((PUnitEventListener) obj).onClassEnd(clazz);
+ }
+ });
+ }
+
+ private void runTestMethod(Class clazz, Method method) {
+ Object testInstance = ReflectionUtil.newInstance(clazz);
+ if (TypeUtil.isPUnitParameterizableTest(clazz)) {
+ Parameterizable pInstance = (Parameterizable) testInstance;
+ Parameter[] params = pInstance.parameters();
+ for (int i = 0; i < params.length; ++i) {
+ runTestMethod(testInstance, method, new Object[] { params[i] });
+ }
+ } else {
+ runTestMethod(testInstance, method, new Object[] {});
+ }
+ }
+
+ private void runTestMethod(Object testInstance, Method method,
+ Object[] params) {
+ _methodRunner.run(testInstance, method, params);
+ }
+
+ private Collection buildTestMethod(Class testClass) {
+ return _testMethodBuilder.buildTestMethods(testClass);
+ }
+
+ public TestMethodBuilder methodBuilder() {
+ return _testMethodBuilder;
+ }
+
+ public MethodRunner methodRunner() {
+ return _methodRunner;
+ }
+
+ public TestSuiteBuilder suiteBuiler() {
+ return _testSuiteBuiler;
+ }
+
+ private void registerLoggerListeners() {
+ addPUnitEventListener(_consoleLogger);
+ }
+
+ public List eventListeners() {
+ return _eventListeners;
+ }
+
+ public void addPUnitEventListener(PUnitEventListener listener) {
+ _eventListeners.add(listener);
+ }
+
+ public void removePUnitEventListener(PUnitEventListener listener) {
+ _eventListeners.remove(listener);
+ }
+
+ public void removeConsoleLogger() {
+ removePUnitEventListener(_consoleLogger);
+ }
+
+ public ConsoleLogger consoleLogger() {
+ return _consoleLogger;
+ }
+
+ public void addTestInterfaces(Class[] interfaces) {
+ _testMethodBuilder.addTestInterfaces(interfaces);
+ }
+
+ private boolean isTestSuiteLabel(Object testClass) {
+ return testClass instanceof TestSuiteLabel;
+ }
+
+ public Object clone() {
+ try {
+ AbstractRunner runner = (AbstractRunner) super.clone();
+ runner._methodRunner = (MethodRunner) _methodRunner.clone();
+ return runner;
+ } catch (CloneNotSupportedException e) {
+ throw new ReflectionException(e);
+ }
+ }
+}
Copied: trunk/punit/src/org/punit/runner/ConcurrentRunner.java (from rev 162, trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/ConcurrentRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/ConcurrentRunner.java 2007-05-27 09:15:20 UTC (rev 164)
@@ -0,0 +1,32 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+package org.punit.runner;
+
+import org.punit.builder.method.*;
+import org.punit.builder.suite.*;
+import org.punit.message.*;
+import org.punit.runner.method.*;
+import org.punit.util.*;
+
+public class ConcurrentRunner extends AbstractRunner {
+
+ private static final long serialVersionUID = -7193902024861434576L;
+
+ private static final int DEFAULT_CONCURRENT_COUNT = 10;
+
+ public static void main(String[] args) {
+ RunnerUtil.run(new ConcurrentRunner(), args);
+ }
+
+ public ConcurrentRunner() {
+ this(ConcurrentRunner.DEFAULT_CONCURRENT_COUNT);
+ }
+
+ public ConcurrentRunner(int concurrentCount) {
+ super(new PUnitTestSuiteBuilder(), new PUnitTestMethodBuilder(), new ConcurrentMethodRunner(concurrentCount));
+ }
+
+ public String punitName() {
+ return Messages.getString("runner.03"); //$NON-NLS-1$
+ }
+
+}
Deleted: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-27 09:12:08 UTC (rev 163)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-27 09:15:20 UTC (rev 164)
@@ -1,346 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.runner;
-
-import java.io.*;
-import java.lang.reflect.*;
-import java.util.*;
-
-import org.punit.builder.method.*;
-import org.punit.builder.suite.*;
-import org.punit.events.*;
-import org.punit.exception.*;
-import org.punit.reporter.stream.console.*;
-import org.punit.runner.method.*;
-import org.punit.type.*;
-import org.punit.util.*;
-
-public abstract class PUnitAbstractRunner implements Runner {
-
- private TestSuiteBuilder _testSuiteBuiler;
-
- private TestMethodBuilder _testMethodBuilder;
-
- private MethodRunner _methodRunner;
-
- // List <PUnitEventListener>
- private final List _eventListeners = new ArrayList();
-
- private ConsoleLogger _consoleLogger = new ConsoleLogger();
-
- private RunnerProperties _properties = new RunnerProperties();
-
- private ExecutorPool _executorPool;
-
- public PUnitAbstractRunner(TestSuiteBuilder testSuiteBuiler,
- TestMethodBuilder testMethodBuilder, MethodRunner testMethodRunner) {
- _testSuiteBuiler = testSuiteBuiler;
- _testMethodBuilder = testMethodBuilder;
- _methodRunner = testMethodRunner;
- _methodRunner.setEventListeners(_eventListeners);
- _methodRunner.setRunnerProperties(_properties);
- registerLoggerListeners();
- }
-
- public void run(Class clazz) {
- initResultFolder();
- onRunnerStart(clazz);
- Object[] testClasses = _testSuiteBuiler.buildTestClasses(clazz);
- runTestClasses(testClasses);
- onRunnerEnd(clazz);
- }
-
- private void runTestClasses(Object[] testClasses) {
- startExecutorPool();
- for (int i = 0; i < testClasses.length; ++i) {
- Object testClass = testClasses[i];
- if (isTestSuiteLabel(testClass)) {
- onSuite(((TestSuiteLabel) testClass));
- } else {
- runTestClass((Class) testClass);
- }
- }
- waitExecutorPoolTermination();
- }
-
- public void setExecutorPool(ExecutorPool pool) {
- _executorPool = pool;
- }
-
- private void startExecutorPool() {
- if (_executorPool != null) {
- _executorPool.start();
- }
- }
-
- private void waitExecutorPoolTermination() {
- if (_executorPool != null) {
- _executorPool.join();
- }
- }
-
- public void run(Class clazz, RunnerProperties properties) {
- setRunnerProperties(properties);
- run(clazz);
- }
-
- private void setRunnerProperties(RunnerProperties properties) {
- _properties = properties;
- _methodRunner.setRunnerProperties(_properties);
- }
-
- public void runVMs(Class clazz, VM[] vms) {
- initResultFolder();
- _properties.isParent = true;
- _properties.vms = vms;
- for (int i = 0; i < vms.length; ++i) {
- VM vm = vms[i];
- storeRunnerConfig(vm);
- storeRunnerProperties(vm);
- String command = generateVMCommand(clazz, vm);
- Process p = IOUtil.exec(command);
- readErrorStream(p);
- readOutputStream(p);
- try {
- p.waitFor();
- } catch (InterruptedException e) {
- throw new PUnitIOException(e);
- }
- deleteRunnerConfig(vm);
- deleteRunnerProperties(vm);
- }
- filterNonParentEventListeners();
- run(clazz);
- }
-
- private void readOutputStream(Process p) {
- new StreamReaderThread(p.getInputStream(), false).start();
- }
-
- private void readErrorStream(Process p) {
- new StreamReaderThread(p.getErrorStream(), true).start();
- }
-
- private void filterNonParentEventListeners() {
- final List newEventListener = new ArrayList();
- TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
- public void traverse(Object obj) {
- PUnitEventListener listener = ((PUnitEventListener) obj);
- if (listener.supportParentRunner()) {
- newEventListener.add(listener);
- }
- }
- });
- _eventListeners.clear();
- _eventListeners.addAll(newEventListener);
- }
-
- private void deleteRunnerProperties(VM vm) {
- IOUtil.deleteFile(runnerPropertiesFileName(vm));
- }
-
- private void deleteRunnerConfig(VM vm) {
- IOUtil.deleteFile(runnerConfigFileName(vm));
- }
-
- private void storeRunnerProperties(VM vm) {
- RunnerProperties properties = new RunnerProperties();
- properties.vmName = vm.punitName();
- properties.isIntermediate = true;
- IOUtil.serialize(properties, runnerPropertiesFileName(vm));
- }
-
- private void storeRunnerConfig(VM vm) {
- IOUtil.serialize(this, runnerConfigFileName(vm));
- }
-
- private String runnerConfigFileName(VM vm) {
- return RunnerConstants.RESULT_FOLDER + File.separator + vm.punitName()
- + ".cfg"; //$NON-NLS-1$
- }
-
- private String runnerPropertiesFileName(VM vm) {
- return RunnerConstants.RESULT_FOLDER + File.separator + vm.punitName()
- + ".props"; //$NON-NLS-1$
- }
-
- public RunnerProperties properties() {
- return _properties;
- }
-
- private String generateVMCommand(Class clazz, VM vm) {
- final StringBuffer sb = new StringBuffer();
- sb.append(vm.path());
- sb.append(" "); //$NON-NLS-1$
- sb.append(this.getClass().getName());
- sb.append(" "); //$NON-NLS-1$
- sb.append(clazz.getName());
- sb.append(" "); //$NON-NLS-1$
- sb.append(runnerConfigFileName(vm));
- sb.append(" "); //$NON-NLS-1$
- sb.append(runnerPropertiesFileName(vm));
- return sb.toString();
- }
-
- private void onRunnerStart(final Class clazz) {
- TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((PUnitEventListener) obj).onRunnerStart(clazz,
- PUnitAbstractRunner.this);
- }
- });
- }
-
- private void initResultFolder() {
- new File(RunnerConstants.RESULT_FOLDER).mkdir();
- }
-
- private void onRunnerEnd(final Class clazz) {
- TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((PUnitEventListener) obj).onRunnerEnd(clazz,
- PUnitAbstractRunner.this);
- }
- });
- }
-
- private void runTestClass(final Class clazz) {
- if (_executorPool == null) {
- runTestClassImpl(clazz);
- } else {
- _executorPool.execute(new RunTestClassTask(clazz));
- }
- }
-
- private class RunTestClassTask implements Runnable {
- private Class _clazz;
-
- public RunTestClassTask(Class clazz) {
- _clazz = clazz;
- }
-
- public void run() {
- PUnitAbstractRunner runner = (PUnitAbstractRunner)PUnitAbstractRunner.this.clone();
- runner.runTestClassImpl(_clazz);
- }
-
- }
-
- private void runTestClassImpl(final Class clazz) {
- onClassStart(clazz);
- Collection testMethods = buildTestMethod(clazz);
- TraverserUtil.traverse(testMethods.iterator(), new Traverser() {
- public void traverse(Object obj) {
- Method method = (Method) obj;
- runTestMethod(clazz, method);
- }
- });
- onClassEnd(clazz);
- }
-
- 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();
- if (suiteLabel.isStart()) {
- listener.onSuiteStart(suite);
- } else {
- listener.onSuiteEnd(suite);
- }
- }
- });
- }
-
- private void onClassStart(final Class clazz) {
- TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((PUnitEventListener) obj).onClassStart(clazz);
- }
- });
- }
-
- private void onClassEnd(final Class clazz) {
- TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((PUnitEventListener) obj).onClassEnd(clazz);
- }
- });
- }
-
- private void runTestMethod(Class clazz, Method method) {
- Object testInstance = ReflectionUtil.newInstance(clazz);
- if (TypeUtil.isPUnitParameterizableTest(clazz)) {
- Parameterizable pInstance = (Parameterizable) testInstance;
- Parameter[] params = pInstance.parameters();
- for (int i = 0; i < params.length; ++i) {
- runTestMethod(testInstance, method, new Object[] { params[i] });
- }
- } else {
- runTestMethod(testInstance, method, new Object[] {});
- }
- }
-
- private void runTestMethod(Object testInstance, Method method,
- Object[] params) {
- _methodRunner.run(testInstance, method, params);
- }
-
- private Collection buildTestMethod(Class testClass) {
- return _testMethodBuilder.buildTestMethods(testClass);
- }
-
- public TestMethodBuilder methodBuilder() {
- return _testMethodBuilder;
- }
-
- public MethodRunner methodRunner() {
- return _methodRunner;
- }
-
- public TestSuiteBuilder suiteBuiler() {
- return _testSuiteBuiler;
- }
-
- private void registerLoggerListeners() {
- addPUnitEventListener(_consoleLogger);
- }
-
- public List eventListeners() {
- return _eventListeners;
- }
-
- public void addPUnitEventListener(PUnitEventListener listener) {
- _eventListeners.add(listener);
- }
-
- public void removePUnitEventListener(PUnitEventListener listener) {
- _eventListeners.remove(listener);
- }
-
- public void removeConsoleLogger() {
- removePUnitEventListener(_consoleLogger);
- }
-
- public ConsoleLogger consoleLogger() {
- return _consoleLogger;
- }
-
- public void addTestInterfaces(Class[] interfaces) {
- _testMethodBuilder.addTestInterfaces(interfaces);
- }
-
- private boolean isTestSuiteLabel(Object testClass) {
- return testClass instanceof TestSuiteLabel;
- }
-
- public Object clone() {
- try {
- PUnitAbstractRunner runner = (PUnitAbstractRunner) super.clone();
- runner._methodRunner = (MethodRunner) _methodRunner.clone();
- return runner;
- } catch (CloneNotSupportedException e) {
- throw new ReflectionException(e);
- }
- }
-}
Deleted: trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-27 09:12:08 UTC (rev 163)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-27 09:15:20 UTC (rev 164)
@@ -1,32 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-package org.punit.runner;
-
-import org.punit.builder.method.*;
-import org.punit.builder.suite.*;
-import org.punit.message.*;
-import org.punit.runner.method.*;
-import org.punit.util.*;
-
-public class PUnitConcurrentRunner extends PUnitAbstractRunner {
-
- private static final long serialVersionUID = -7193902024861434576L;
-
- private static final int DEFAULT_CONCURRENT_COUNT = 10;
-
- public static void main(String[] args) {
- RunnerUtil.run(new PUnitConcurrentRunner(), args);
- }
-
- public PUnitConcurrentRunner() {
- this(PUnitConcurrentRunner.DEFAULT_CONCURRENT_COUNT);
- }
-
- public PUnitConcurrentRunner(int concurrentCount) {
- super(new PUnitTestSuiteBuilder(), new PUnitTestMethodBuilder(), new ConcurrentMethodRunner(concurrentCount));
- }
-
- public String punitName() {
- return Messages.getString("runner.03"); //$NON-NLS-1$
- }
-
-}
Deleted: trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitSoloRunner.java 2007-05-27 09:12:08 UTC (rev 163)
+++ trunk/punit/src/org/punit/runner/PUnitSoloRunner.java 2007-05-27 09:15:20 UTC (rev 164)
@@ -1,29 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.runner;
-
-import org.punit.builder.method.*;
-import org.punit.builder.suite.*;
-import org.punit.message.*;
-import org.punit.runner.method.*;
-import org.punit.util.*;
-
-public class PUnitSoloRunner extends PUnitAbstractRunner {
-
- private static final long serialVersionUID = 5938649527831492676L;
-
- public static void main(String[] args) {
- RunnerUtil.run(new PUnitSoloRunner(), args);
- }
-
- public PUnitSoloRunner() {
- super(new PUnitTestSuiteBuilder(), new PUnitTestMethodBuilder(),
- new SoloMethodRunner());
-
- }
-
- public String punitName() {
- return Messages.getString("runner.01"); //$NON-NLS-1$
- }
-
-}
Copied: trunk/punit/src/org/punit/runner/SoloRunner.java (from rev 162, trunk/punit/src/org/punit/runner/PUnitSoloRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/SoloRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/SoloRunner.java 2007-05-27 09:15:20 UTC (rev 164)
@@ -0,0 +1,29 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.runner;
+
+import org.punit.builder.method.*;
+import org.punit.builder.suite.*;
+import org.punit.message.*;
+import org.punit.runner.method.*;
+import org.punit.util.*;
+
+public class SoloRunner extends AbstractRunner {
+
+ private static final long serialVersionUID = 5938649527831492676L;
+
+ public static void main(String[] args) {
+ RunnerUtil.run(new SoloRunner(), args);
+ }
+
+ public SoloRunner() {
+ super(new PUnitTestSuiteBuilder(), new PUnitTestMethodBuilder(),
+ new SoloMethodRunner());
+
+ }
+
+ public String punitName() {
+ return Messages.getString("runner.01"); //$NON-NLS-1$
+ }
+
+}
Modified: trunk/punit.samples/src/samples/ExecutorPoolSample.java
===================================================================
--- trunk/punit.samples/src/samples/ExecutorPoolSample.java 2007-05-27 09:12:08 UTC (rev 163)
+++ trunk/punit.samples/src/samples/ExecutorPoolSample.java 2007-05-27 09:15:20 UTC (rev 164)
@@ -4,7 +4,7 @@
public class ExecutorPoolSample {
public static void main(String[] args) {
- PUnitSoloRunner runner = new PUnitSoloRunner();
+ SoloRunner runner = new SoloRunner();
runner.setExecutorPool(new PUnitExecutorPool(2));
runner.run(LongTimeExecutionPUnitTestSuite.class);
}
Modified: trunk/punit.samples/src/samples/JUnitTestClass.java
===================================================================
--- trunk/punit.samples/src/samples/JUnitTestClass.java 2007-05-27 09:12:08 UTC (rev 163)
+++ trunk/punit.samples/src/samples/JUnitTestClass.java 2007-05-27 09:15:20 UTC (rev 164)
@@ -9,7 +9,7 @@
public class JUnitTestClass extends TestCase {
public static void main(String[] args) {
- new PUnitSoloRunner().run(JUnitTestClass.class);
+ new SoloRunner().run(JUnitTestClass.class);
}
protected void setUp() throws Exception {
Modified: trunk/punit.samples/src/samples/MultiThreadRunnerSample.java
===================================================================
--- trunk/punit.samples/src/samples/MultiThreadRunnerSample.java 2007-05-27 09:12:08 UTC (rev 163)
+++ trunk/punit.samples/src/samples/MultiThreadRunnerSample.java 2007-05-27 09:15:20 UTC (rev 164)
@@ -13,7 +13,7 @@
*
* The result can be found in ./result/ folder.
*/
- PUnitSoloRunner runner = new PUnitSoloRunner();
+ SoloRunner runner = new SoloRunner();
// runner = new PUnitConcurrentRunner();
runner.setExecutorPool(new PUnitExecutorPool(10));
runner.run(AllTestSuite.class);
Modified: trunk/punit.samples/src/samples/ParamTestClass.java
===================================================================
--- trunk/punit.samples/src/samples/ParamTestClass.java 2007-05-27 09:12:08 UTC (rev 163)
+++ trunk/punit.samples/src/samples/ParamTestClass.java 2007-05-27 09:15:20 UTC (rev 164)
@@ -6,7 +6,7 @@
public class ParamTestClass implements Parameterizable {
public static void main(String[] args) {
- new PUnitSoloRunner().run(ParamTestClass.class);
+ new SoloRunner().run(ParamTestClass.class);
}
public Parameter[] parameters() {
Modified: trunk/punit.samples/src/samples/RunnerSamples.java
===================================================================
--- trunk/punit.samples/src/samples/RunnerSamples.java 2007-05-27 09:12:08 UTC (rev 163)
+++ trunk/punit.samples/src/samples/RunnerSamples.java 2007-05-27 09:15:20 UTC (rev 164)
@@ -17,7 +17,7 @@
*
* The result can be found in ./result/ folder.
*/
- PUnitSoloRunner runner = new PUnitSoloRunner();
+ SoloRunner runner = new SoloRunner();
// runner = new PUnitConcurrentRunner();
runner.setExecutorPool(new PUnitExecutorPool(5));
runner.addPUnitEventListener(new FileLogger());
Modified: trunk/punit.samples/src/samples/SimpleTestClass.java
===================================================================
--- trunk/punit.samples/src/samples/SimpleTestClass.java 2007-05-27 09:12:08 UTC (rev 163)
+++ trunk/punit.samples/src/samples/SimpleTestClass.java 2007-05-27 09:15:20 UTC (rev 164)
@@ -7,7 +7,7 @@
publi...
[truncated message content] |
|
From: <zha...@us...> - 2007-05-27 09:23:44
|
Revision: 165
http://p-unit.svn.sourceforge.net/p-unit/?rev=165&view=rev
Author: zhanghuangzhu
Date: 2007-05-27 02:23:45 -0700 (Sun, 27 May 2007)
Log Message:
-----------
Andrew Zhang: refactored class names.
Modified Paths:
--------------
trunk/punit/src/org/punit/events/PUnitEventListener.java
trunk/punit/src/org/punit/events/PUnitEventRegsitry.java
trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java
trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit/src/org/punit/runner/ConcurrentRunner.java
trunk/punit/src/org/punit/runner/SoloRunner.java
trunk/punit.samples/src/samples/RunnerSamples.java
trunk/punit.samples/src/samples/vms/ListVMTest.java
trunk/punit.test/src/extension/tests/api/org/punit/runner/PUnitSoloRunnerTest.java
trunk/punit.test/src/extension/tests/samples/JUnitTestSample.java
trunk/punit.test/src/extension/tests/samples/OverviewVMsSample.java
trunk/punit.test/src/extension/tests/samples/PUnitTestSuiteSample.java
trunk/punit.test/src/extension/tests/samples/TestClassVMsSample.java
trunk/punit.test/src/extension/tests/samples/TestSuiteVMsSample.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestSuiteBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/runner/AbstractRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
Added Paths:
-----------
trunk/punit/src/org/punit/builder/method/AbstractTestMethodBuilder.java
trunk/punit/src/org/punit/builder/method/TestMethodBuilderImpl.java
trunk/punit/src/org/punit/builder/suite/TestSuiteBuilderImpl.java
trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
Removed Paths:
-------------
trunk/punit/src/org/punit/builder/method/PUnitAbstractTestMethodBuilder.java
trunk/punit/src/org/punit/builder/method/PUnitTestMethodBuilder.java
trunk/punit/src/org/punit/builder/suite/PUnitTestSuiteBuilder.java
trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
Copied: trunk/punit/src/org/punit/builder/method/AbstractTestMethodBuilder.java (from rev 154, trunk/punit/src/org/punit/builder/method/PUnitAbstractTestMethodBuilder.java)
===================================================================
--- trunk/punit/src/org/punit/builder/method/AbstractTestMethodBuilder.java (rev 0)
+++ trunk/punit/src/org/punit/builder/method/AbstractTestMethodBuilder.java 2007-05-27 09:23:45 UTC (rev 165)
@@ -0,0 +1,80 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.builder.method;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+import org.punit.type.*;
+
+/**
+ * This class is the basic implementation for <code>TestMethodBuilder</code>
+ * interface.
+ *
+ */
+public abstract class AbstractTestMethodBuilder implements
+ TestMethodBuilder {
+
+ protected final HashSet _testMethodNames = new HashSet();
+
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @param method
+ * @return
+ */
+ protected abstract boolean isTestMethod(Method method);
+
+ /**
+ * @see TestMethodBuilder#buildTestMethods(Class)
+ */
+ public Collection buildTestMethods(Class testClass) {
+ Collection testMethods = null;
+ if (isAlphabetical(testClass)) {
+ testMethods = new TreeSet(
+ new AlphabeticalMethodNameComparator());
+ } else {
+ testMethods = new ArrayList();
+ }
+ Class clazz = testClass;
+ while (clazz != Object.class) {
+ Method[] methods = clazz.getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ Method method = methods[i];
+ if (isTestMethod(method)) {
+ testMethods.add(method);
+ }
+ }
+ clazz = clazz.getSuperclass();
+ }
+ return testMethods;
+ }
+
+ private boolean isAlphabetical(Class testClass) {
+ return Alphabetical.class.isAssignableFrom(testClass);
+ }
+
+ private static class AlphabeticalMethodNameComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ Method m1 = (Method) o1;
+ Method m2 = (Method) o2;
+ return m1.getName().compareTo(m2.getName());
+ }
+ }
+
+ /**
+ * @see TestMethodBuilder#addTestInterfaces(Class[])
+ */
+ public void addTestInterfaces(Class[] classes) {
+ for (int i = 0; i < classes.length; ++i) {
+ addTestInterface(classes[i]);
+ }
+ }
+
+ private void addTestInterface(Class testInterface) {
+ Method[] methods = testInterface.getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ _testMethodNames.add(methods[i].getName());
+ }
+ }
+}
Deleted: trunk/punit/src/org/punit/builder/method/PUnitAbstractTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/method/PUnitAbstractTestMethodBuilder.java 2007-05-27 09:15:20 UTC (rev 164)
+++ trunk/punit/src/org/punit/builder/method/PUnitAbstractTestMethodBuilder.java 2007-05-27 09:23:45 UTC (rev 165)
@@ -1,80 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.builder.method;
-
-import java.lang.reflect.*;
-import java.util.*;
-
-import org.punit.type.*;
-
-/**
- * This class is the basic implementation for <code>TestMethodBuilder</code>
- * interface.
- *
- */
-public abstract class PUnitAbstractTestMethodBuilder implements
- TestMethodBuilder {
-
- protected final HashSet _testMethodNames = new HashSet();
-
- /**
- * Judges whether this method is a test method.
- *
- * @param method
- * @return
- */
- protected abstract boolean isTestMethod(Method method);
-
- /**
- * @see TestMethodBuilder#buildTestMethods(Class)
- */
- public Collection buildTestMethods(Class testClass) {
- Collection testMethods = null;
- if (isAlphabetical(testClass)) {
- testMethods = new TreeSet(
- new AlphabeticalMethodNameComparator());
- } else {
- testMethods = new ArrayList();
- }
- Class clazz = testClass;
- while (clazz != Object.class) {
- Method[] methods = clazz.getDeclaredMethods();
- for (int i = 0; i < methods.length; ++i) {
- Method method = methods[i];
- if (isTestMethod(method)) {
- testMethods.add(method);
- }
- }
- clazz = clazz.getSuperclass();
- }
- return testMethods;
- }
-
- private boolean isAlphabetical(Class testClass) {
- return Alphabetical.class.isAssignableFrom(testClass);
- }
-
- private static class AlphabeticalMethodNameComparator implements Comparator {
- public int compare(Object o1, Object o2) {
- Method m1 = (Method) o1;
- Method m2 = (Method) o2;
- return m1.getName().compareTo(m2.getName());
- }
- }
-
- /**
- * @see TestMethodBuilder#addTestInterfaces(Class[])
- */
- public void addTestInterfaces(Class[] classes) {
- for (int i = 0; i < classes.length; ++i) {
- addTestInterface(classes[i]);
- }
- }
-
- private void addTestInterface(Class testInterface) {
- Method[] methods = testInterface.getDeclaredMethods();
- for (int i = 0; i < methods.length; ++i) {
- _testMethodNames.add(methods[i].getName());
- }
- }
-}
Deleted: trunk/punit/src/org/punit/builder/method/PUnitTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/method/PUnitTestMethodBuilder.java 2007-05-27 09:15:20 UTC (rev 164)
+++ trunk/punit/src/org/punit/builder/method/PUnitTestMethodBuilder.java 2007-05-27 09:23:45 UTC (rev 165)
@@ -1,78 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.builder.method;
-
-import java.lang.reflect.*;
-
-import org.punit.type.*;
-import org.punit.util.*;
-
-/**
- * The default test method builder of punit.
- *
- */
-public class PUnitTestMethodBuilder extends PUnitAbstractTestMethodBuilder {
-
- private static final long serialVersionUID = -6490270178427969475L;
-
- /**
- * Judges whether this method is a test method.
- *
- * @return returns true if the test modifier, name, and parameter conform to
- * the convention of a test method.
- */
- protected boolean isTestMethod(Method method) {
- return isModifierValid(method) && isNameValid(method)
- && isParamValid(method);
- }
-
- /**
- * Judeges whether the modifier of is method conforms to the convention of a
- * test method.
- *
- * @param method
- * to be judged
- * @return returns true if this method is public and non static.
- */
- protected boolean isModifierValid(Method method) {
- return ReflectionUtil.isPublic(method)
- && !ReflectionUtil.isStatic(method);
- }
-
- /**
- * Judeges whether the name of is method conforms to the convention of a
- * test method.
- *
- * @param method
- * to be judged
- * @return returns true if the name of this method starts with "test", or
- * the name is in the list of test interfaces which are added by
- * <code>TestMethodBuilder.addTestInterfaces</code>
- */
- protected boolean isNameValid(Method method) {
- String name = method.getName();
- return name.startsWith("test") || _testMethodNames.contains(name); //$NON-NLS-1$
- }
-
- /**
- * Judges whether the paramaters of this method conforms to the convention
- * of a test method.
- *
- * @param method
- * @return returns true if the parameter length is zero and the test class
- * is not marked as <code>Parameterizable</code>, or the
- * parameter length is 1, and the parameter is assignable from
- * <code>Parameter</code>.
- */
- protected boolean isParamValid(Method method) {
- Class clazz = method.getDeclaringClass();
- Class[] params = method.getParameterTypes();
- if (TypeUtil.isPUnitParameterizableTest((clazz))) {
- return params.length == 1
- && Parameter.class.isAssignableFrom(params[0]);
- } else {
- return params.length == 0;
- }
- }
-
-}
Copied: trunk/punit/src/org/punit/builder/method/TestMethodBuilderImpl.java (from rev 154, trunk/punit/src/org/punit/builder/method/PUnitTestMethodBuilder.java)
===================================================================
--- trunk/punit/src/org/punit/builder/method/TestMethodBuilderImpl.java (rev 0)
+++ trunk/punit/src/org/punit/builder/method/TestMethodBuilderImpl.java 2007-05-27 09:23:45 UTC (rev 165)
@@ -0,0 +1,78 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.builder.method;
+
+import java.lang.reflect.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+/**
+ * The default test method builder of punit.
+ *
+ */
+public class TestMethodBuilderImpl extends AbstractTestMethodBuilder {
+
+ private static final long serialVersionUID = -6490270178427969475L;
+
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @return returns true if the test modifier, name, and parameter conform to
+ * the convention of a test method.
+ */
+ protected boolean isTestMethod(Method method) {
+ return isModifierValid(method) && isNameValid(method)
+ && isParamValid(method);
+ }
+
+ /**
+ * Judeges whether the modifier of is method conforms to the convention of a
+ * test method.
+ *
+ * @param method
+ * to be judged
+ * @return returns true if this method is public and non static.
+ */
+ protected boolean isModifierValid(Method method) {
+ return ReflectionUtil.isPublic(method)
+ && !ReflectionUtil.isStatic(method);
+ }
+
+ /**
+ * Judeges whether the name of is method conforms to the convention of a
+ * test method.
+ *
+ * @param method
+ * to be judged
+ * @return returns true if the name of this method starts with "test", or
+ * the name is in the list of test interfaces which are added by
+ * <code>TestMethodBuilder.addTestInterfaces</code>
+ */
+ protected boolean isNameValid(Method method) {
+ String name = method.getName();
+ return name.startsWith("test") || _testMethodNames.contains(name); //$NON-NLS-1$
+ }
+
+ /**
+ * Judges whether the paramaters of this method conforms to the convention
+ * of a test method.
+ *
+ * @param method
+ * @return returns true if the parameter length is zero and the test class
+ * is not marked as <code>Parameterizable</code>, or the
+ * parameter length is 1, and the parameter is assignable from
+ * <code>Parameter</code>.
+ */
+ protected boolean isParamValid(Method method) {
+ Class clazz = method.getDeclaringClass();
+ Class[] params = method.getParameterTypes();
+ if (TypeUtil.isPUnitParameterizableTest((clazz))) {
+ return params.length == 1
+ && Parameter.class.isAssignableFrom(params[0]);
+ } else {
+ return params.length == 0;
+ }
+ }
+
+}
Deleted: trunk/punit/src/org/punit/builder/suite/PUnitTestSuiteBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/suite/PUnitTestSuiteBuilder.java 2007-05-27 09:15:20 UTC (rev 164)
+++ trunk/punit/src/org/punit/builder/suite/PUnitTestSuiteBuilder.java 2007-05-27 09:23:45 UTC (rev 165)
@@ -1,50 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.builder.suite;
-
-import java.util.*;
-
-import org.punit.type.*;
-import org.punit.util.*;
-
-public class PUnitTestSuiteBuilder implements TestSuiteBuilder {
-
- private static final long serialVersionUID = 633363267326297920L;
-
- /**
- * @see TestSuiteBuilder#buildTestClasses(Class)
- */
- public Object[] buildTestClasses(Class clazz) {
- List testClasses = new ArrayList();
- buildTestClasses(testClasses, clazz);
- return testClasses.toArray();
- }
-
- private void buildTestClasses(List testClasses, Class clazz) {
- if(isTestSuite(clazz)) {
- buildTestClassFromTestSuite(testClasses, clazz);
- } else {
- buildTestClassesFromClass(testClasses, clazz);
- }
- }
-
- private void buildTestClassFromTestSuite(List testClasses, Class clazz) {
- PUnitTestSuite testSuite = (PUnitTestSuite) ReflectionUtil.newInstance(clazz);
- testClasses.add(new TestSuiteLabelImpl(testSuite, true));
- Class[] suite = testSuite.suite();
- for(int i = 0; i < suite.length; ++i) {
- buildTestClasses(testClasses, suite[i]);
- }
- testClasses.add(new TestSuiteLabelImpl(testSuite, false));
- }
-
- private void buildTestClassesFromClass(List testClasses, Class clazz) {
- testClasses.add(clazz);
- }
-
-
- private boolean isTestSuite(Class clazz) {
- return PUnitTestSuite.class.isAssignableFrom(clazz);
- }
-
-}
Copied: trunk/punit/src/org/punit/builder/suite/TestSuiteBuilderImpl.java (from rev 154, trunk/punit/src/org/punit/builder/suite/PUnitTestSuiteBuilder.java)
===================================================================
--- trunk/punit/src/org/punit/builder/suite/TestSuiteBuilderImpl.java (rev 0)
+++ trunk/punit/src/org/punit/builder/suite/TestSuiteBuilderImpl.java 2007-05-27 09:23:45 UTC (rev 165)
@@ -0,0 +1,50 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.builder.suite;
+
+import java.util.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class TestSuiteBuilderImpl implements TestSuiteBuilder {
+
+ private static final long serialVersionUID = 633363267326297920L;
+
+ /**
+ * @see TestSuiteBuilder#buildTestClasses(Class)
+ */
+ public Object[] buildTestClasses(Class clazz) {
+ List testClasses = new ArrayList();
+ buildTestClasses(testClasses, clazz);
+ return testClasses.toArray();
+ }
+
+ private void buildTestClasses(List testClasses, Class clazz) {
+ if(isTestSuite(clazz)) {
+ buildTestClassFromTestSuite(testClasses, clazz);
+ } else {
+ buildTestClassesFromClass(testClasses, clazz);
+ }
+ }
+
+ private void buildTestClassFromTestSuite(List testClasses, Class clazz) {
+ PUnitTestSuite testSuite = (PUnitTestSuite) ReflectionUtil.newInstance(clazz);
+ testClasses.add(new TestSuiteLabelImpl(testSuite, true));
+ Class[] suite = testSuite.suite();
+ for(int i = 0; i < suite.length; ++i) {
+ buildTestClasses(testClasses, suite[i]);
+ }
+ testClasses.add(new TestSuiteLabelImpl(testSuite, false));
+ }
+
+ private void buildTestClassesFromClass(List testClasses, Class clazz) {
+ testClasses.add(clazz);
+ }
+
+
+ private boolean isTestSuite(Class clazz) {
+ return PUnitTestSuite.class.isAssignableFrom(clazz);
+ }
+
+}
Modified: trunk/punit/src/org/punit/events/PUnitEventListener.java
===================================================================
--- trunk/punit/src/org/punit/events/PUnitEventListener.java 2007-05-27 09:15:20 UTC (rev 164)
+++ trunk/punit/src/org/punit/events/PUnitEventListener.java 2007-05-27 09:23:45 UTC (rev 165)
@@ -12,7 +12,7 @@
/**
* Event system for punit. The event listener can be installed by
- * {@link PUnitEventRegsitry#addPUnitEventListener(PUnitEventListener)}.
+ * {@link PUnitEventRegsitry#addEventListener(PUnitEventListener)}.
*
* All punit runners implement {@link PUnitEventRegsitry}.
*
Modified: trunk/punit/src/org/punit/events/PUnitEventRegsitry.java
===================================================================
--- trunk/punit/src/org/punit/events/PUnitEventRegsitry.java 2007-05-27 09:15:20 UTC (rev 164)
+++ trunk/punit/src/org/punit/events/PUnitEventRegsitry.java 2007-05-27 09:23:45 UTC (rev 165)
@@ -15,14 +15,14 @@
*
* @param listener
*/
- public void addPUnitEventListener(PUnitEventListener listener);
+ public void addEventListener(PUnitEventListener listener);
/**
* Removes a event lisetern.
*
* @param listener
*/
- public void removePUnitEventListener(PUnitEventListener listener);
+ public void removeEventListener(PUnitEventListener listener);
/**
* @return returns the registered event listeners.
Copied: trunk/punit/src/org/punit/reporter/stream/StreamLogger.java (from rev 163, trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java)
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLogger.java (rev 0)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2007-05-27 09:23:45 UTC (rev 165)
@@ -0,0 +1,215 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.reporter.stream;
+
+import java.io.*;
+import java.lang.reflect.*;
+import java.util.*;
+import java.util.logging.*;
+
+import org.punit.events.*;
+import org.punit.message.*;
+import org.punit.runner.*;
+import org.punit.type.*;
+import org.punit.util.*;
+import org.punit.watcher.*;
+
+public abstract class StreamLogger implements PUnitEventListener {
+
+ protected transient PrintStream _outStream;
+
+ protected transient PrintStream _errStream;
+
+ protected transient TestResult _result;
+
+ public Level _level = Level.FINE;
+
+ private TimeWatcher _timeWatcher;
+
+ public StreamLogger() {
+ }
+
+ public StreamLogger(PrintStream out, PrintStream err) {
+ _outStream = out;
+ _errStream = err;
+ }
+
+ public void onRunnerStart(Class clazz, Runner runner) {
+ startTimeWatcher();
+ _result = new TestResult();
+ StringBuffer sb = new StringBuffer();
+ sb.append("["); //$NON-NLS-1$
+ sb.append(runner.punitName());
+ sb.append("] "); //$NON-NLS-1$
+ sb.append(Messages.getString("logger.01")); //$NON-NLS-1$
+ sb.append(" "); //$NON-NLS-1$
+ sb.append(clazz.getName());
+ sb.append(ReporterUtil.LINE_SEPERATOR);
+ log(sb.toString(), Level.INFO);
+ }
+
+ private void startTimeWatcher() {
+ _timeWatcher = new TimeWatcher();
+ _timeWatcher.start();
+ }
+
+ public void onRunnerEnd(Class clazz, Runner runner) {
+ logResult();
+ }
+
+ public void logResult() {
+ stopTimeWatcher();
+ StringBuffer sb = new StringBuffer();
+ sb.append(Messages.getString("logger.02")); //$NON-NLS-1$
+ sb.append(_result.methodCount());
+ sb.append(", "); //$NON-NLS-1$
+ sb.append(Messages.getString("logger.03")); //$NON-NLS-1$
+ List failures = _result.failures();
+ int failuresCount = failures.size();
+ sb.append(failuresCount);
+ sb.append(" ("); //$NON-NLS-1$
+ if (failuresCount == 0) {
+ sb.append(Messages.getString("logger.04")); //$NON-NLS-1$
+ } else {
+ sb.append(Messages.getString("logger.05")); //$NON-NLS-1$
+ }
+ sb.append(") - "); //$NON-NLS-1$
+ sb.append(_timeWatcher.stringValue());
+ sb.append(ReporterUtil.LINE_SEPERATOR);
+ logErr(sb.toString(), Level.INFO);
+ TraverserUtil.traverse(failures.iterator(), new Traverser() {
+ int count = 0;
+
+ public void traverse(Object obj) {
+ logErr(++count + ")", Level.INFO); //$NON-NLS-1$
+ ((Throwable) obj).printStackTrace(_errStream);
+ }
+ });
+ }
+
+ private void stopTimeWatcher() {
+ _timeWatcher.stop();
+ }
+
+ public void onSuiteStart(PUnitTestSuite suite) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(Messages.getString("logger.06")); //$NON-NLS-1$
+ sb.append(suite.getClass().getName());
+ sb.append(ReporterUtil.LINE_SEPERATOR);
+ log(sb.toString(), Level.INFO);
+ }
+
+
+ public void onClassStart(Class clazz) {
+ logln(clazz.getName(), Level.INFO);
+ }
+
+ public void onMethodEnd(Method method, Object instance, Object[] params,
+ Throwable t, List watchers) {
+ logTestMethodResult(method, params, watchers, t);
+ _result.countMethod();
+ if (t != null) {
+ _result.addThrowable(t);
+ }
+ }
+
+ private void logTestMethodResult(Method method, Object[] params, List watchers, Throwable t) {
+ final StringBuffer sb = new StringBuffer();
+ String simpleMethodName = ReporterUtil.simpleMethodName(method, params);
+ sb.append(simpleMethodName);
+ if (watchers.size() > 0) {
+ final Iterator iter = watchers.iterator();
+ Watcher watcher = (Watcher) iter.next();
+ sb.append(" - ["); //$NON-NLS-1$
+ sb.append(watcher.stringValue());
+ TraverserUtil.traverse(iter, new Traverser() {
+ public void traverse(Object obj) {
+ Watcher watcher = (Watcher) obj;
+ sb.append(","); //$NON-NLS-1$
+ sb.append(watcher.stringValue());
+ }
+ });
+ sb.append("]"); //$NON-NLS-1$
+ }
+
+ sb.append(ReporterUtil.LINE_SEPERATOR);
+ if(t != null) {
+ sb.append(t.toString());
+ sb.append(ReporterUtil.LINE_SEPERATOR);
+ }
+ log(sb.toString(), Level.INFO);
+ }
+
+ public void setStream(PrintStream out, PrintStream err) {
+ _outStream = out;
+ _errStream = err;
+ }
+
+ public PrintStream outPrintStream() {
+ return _outStream;
+ }
+
+ public PrintStream errPrintStream() {
+ return _errStream;
+ }
+
+ public void logln(Level level) {
+ log(ReporterUtil.LINE_SEPERATOR, level);
+ }
+
+ public void logln(String message, Level level) {
+ log(message + ReporterUtil.LINE_SEPERATOR, level);
+ }
+
+ public void log(String message, Level level) {
+ log(_outStream, message, level);
+ }
+
+ public void logErr(String message, Level level) {
+ log(_errStream, message, level);
+ }
+
+ public void log(PrintStream ps, String message, Level level) {
+ if (ps == null) {
+ return;
+ }
+ if (level.intValue() < _level.intValue()) {
+ return;
+ }
+ ps.print(message);
+ ps.flush();
+ }
+
+ public void setLogLevel(Level level) {
+ _level = level;
+ }
+
+ public void onWatchersStart(List watchers) {
+ // nothing needs to do
+ }
+
+ public void onWatcherStart(Watcher watcher) {
+ // nothing needs to do
+ }
+
+ public void onWatchersEnd(List watchers) {
+ // nothing needs to do
+ }
+
+ public void onWatcherEnd(Watcher watcher) {
+ // nothing needs to do
+ }
+
+ public void onSuiteEnd(PUnitTestSuite suite) {
+ // nothing needs to do
+ }
+
+ public void onClassEnd(Class clazz) {
+ // nothing needs to do
+ }
+
+ public void onMethodStart(Method method, Object instance, Object[] params) {
+ // nothing needs to do
+ }
+
+}
\ No newline at end of file
Deleted: trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-27 09:15:20 UTC (rev 164)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-27 09:23:45 UTC (rev 165)
@@ -1,215 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.reporter.stream;
-
-import java.io.*;
-import java.lang.reflect.*;
-import java.util.*;
-import java.util.logging.*;
-
-import org.punit.events.*;
-import org.punit.message.*;
-import org.punit.runner.*;
-import org.punit.type.*;
-import org.punit.util.*;
-import org.punit.watcher.*;
-
-public abstract class StreamLoggerListener implements PUnitEventListener {
-
- protected transient PrintStream _outStream;
-
- protected transient PrintStream _errStream;
-
- protected transient TestResult _result;
-
- public Level _level = Level.FINE;
-
- private TimeWatcher _timeWatcher;
-
- public StreamLoggerListener() {
- }
-
- public StreamLoggerListener(PrintStream out, PrintStream err) {
- _outStream = out;
- _errStream = err;
- }
-
- public void onRunnerStart(Class clazz, Runner runner) {
- startTimeWatcher();
- _result = new TestResult();
- StringBuffer sb = new StringBuffer();
- sb.append("["); //$NON-NLS-1$
- sb.append(runner.punitName());
- sb.append("] "); //$NON-NLS-1$
- sb.append(Messages.getString("logger.01")); //$NON-NLS-1$
- sb.append(" "); //$NON-NLS-1$
- sb.append(clazz.getName());
- sb.append(ReporterUtil.LINE_SEPERATOR);
- log(sb.toString(), Level.INFO);
- }
-
- private void startTimeWatcher() {
- _timeWatcher = new TimeWatcher();
- _timeWatcher.start();
- }
-
- public void onRunnerEnd(Class clazz, Runner runner) {
- logResult();
- }
-
- public void logResult() {
- stopTimeWatcher();
- StringBuffer sb = new StringBuffer();
- sb.append(Messages.getString("logger.02")); //$NON-NLS-1$
- sb.append(_result.methodCount());
- sb.append(", "); //$NON-NLS-1$
- sb.append(Messages.getString("logger.03")); //$NON-NLS-1$
- List failures = _result.failures();
- int failuresCount = failures.size();
- sb.append(failuresCount);
- sb.append(" ("); //$NON-NLS-1$
- if (failuresCount == 0) {
- sb.append(Messages.getString("logger.04")); //$NON-NLS-1$
- } else {
- sb.append(Messages.getString("logger.05")); //$NON-NLS-1$
- }
- sb.append(") - "); //$NON-NLS-1$
- sb.append(_timeWatcher.stringValue());
- sb.append(ReporterUtil.LINE_SEPERATOR);
- logErr(sb.toString(), Level.INFO);
- TraverserUtil.traverse(failures.iterator(), new Traverser() {
- int count = 0;
-
- public void traverse(Object obj) {
- logErr(++count + ")", Level.INFO); //$NON-NLS-1$
- ((Throwable) obj).printStackTrace(_errStream);
- }
- });
- }
-
- private void stopTimeWatcher() {
- _timeWatcher.stop();
- }
-
- public void onSuiteStart(PUnitTestSuite suite) {
- StringBuffer sb = new StringBuffer();
- sb.append(Messages.getString("logger.06")); //$NON-NLS-1$
- sb.append(suite.getClass().getName());
- sb.append(ReporterUtil.LINE_SEPERATOR);
- log(sb.toString(), Level.INFO);
- }
-
-
- public void onClassStart(Class clazz) {
- logln(clazz.getName(), Level.INFO);
- }
-
- public void onMethodEnd(Method method, Object instance, Object[] params,
- Throwable t, List watchers) {
- logTestMethodResult(method, params, watchers, t);
- _result.countMethod();
- if (t != null) {
- _result.addThrowable(t);
- }
- }
-
- private void logTestMethodResult(Method method, Object[] params, List watchers, Throwable t) {
- final StringBuffer sb = new StringBuffer();
- String simpleMethodName = ReporterUtil.simpleMethodName(method, params);
- sb.append(simpleMethodName);
- if (watchers.size() > 0) {
- final Iterator iter = watchers.iterator();
- Watcher watcher = (Watcher) iter.next();
- sb.append(" - ["); //$NON-NLS-1$
- sb.append(watcher.stringValue());
- TraverserUtil.traverse(iter, new Traverser() {
- public void traverse(Object obj) {
- Watcher watcher = (Watcher) obj;
- sb.append(","); //$NON-NLS-1$
- sb.append(watcher.stringValue());
- }
- });
- sb.append("]"); //$NON-NLS-1$
- }
-
- sb.append(ReporterUtil.LINE_SEPERATOR);
- if(t != null) {
- sb.append(t.toString());
- sb.append(ReporterUtil.LINE_SEPERATOR);
- }
- log(sb.toString(), Level.INFO);
- }
-
- public void setStream(PrintStream out, PrintStream err) {
- _outStream = out;
- _errStream = err;
- }
-
- public PrintStream outPrintStream() {
- return _outStream;
- }
-
- public PrintStream errPrintStream() {
- return _errStream;
- }
-
- public void logln(Level level) {
- log(ReporterUtil.LINE_SEPERATOR, level);
- }
-
- public void logln(String message, Level level) {
- log(message + ReporterUtil.LINE_SEPERATOR, level);
- }
-
- public void log(String message, Level level) {
- log(_outStream, message, level);
- }
-
- public void logErr(String message, Level level) {
- log(_errStream, message, level);
- }
-
- public void log(PrintStream ps, String message, Level level) {
- if (ps == null) {
- return;
- }
- if (level.intValue() < _level.intValue()) {
- return;
- }
- ps.print(message);
- ps.flush();
- }
-
- public void setLogLevel(Level level) {
- _level = level;
- }
-
- public void onWatchersStart(List watchers) {
- // nothing needs to do
- }
-
- public void onWatcherStart(Watcher watcher) {
- // nothing needs to do
- }
-
- public void onWatchersEnd(List watchers) {
- // nothing needs to do
- }
-
- public void onWatcherEnd(Watcher watcher) {
- // nothing needs to do
- }
-
- public void onSuiteEnd(PUnitTestSuite suite) {
- // nothing needs to do
- }
-
- public void onClassEnd(Class clazz) {
- // nothing needs to do
- }
-
- public void onMethodStart(Method method, Object instance, Object[] params) {
- // nothing needs to do
- }
-
-}
\ No newline at end of file
Modified: trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java 2007-05-27 09:15:20 UTC (rev 164)
+++ trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java 2007-05-27 09:23:45 UTC (rev 165)
@@ -6,7 +6,7 @@
import org.punit.reporter.stream.*;
-public class ConsoleLogger extends StreamLoggerListener {
+public class ConsoleLogger extends StreamLogger {
private static final long serialVersionUID = 2691593175672418574L;
Modified: trunk/punit/src/org/pun...
[truncated message content] |
|
From: <zha...@us...> - 2007-05-29 21:10:26
|
Revision: 170
http://p-unit.svn.sourceforge.net/p-unit/?rev=170&view=rev
Author: zhanghuangzhu
Date: 2007-05-29 14:10:22 -0700 (Tue, 29 May 2007)
Log Message:
-----------
Andrew Zhang: added some assert methods.
Modified Paths:
--------------
trunk/punit/src/org/punit/assertion/Assert.java
trunk/punit/src/punit.properties
trunk/punit.test/src/tests/api/org/punit/assertion/AssertTest.java
Modified: trunk/punit/src/org/punit/assertion/Assert.java
===================================================================
--- trunk/punit/src/org/punit/assertion/Assert.java 2007-05-29 15:09:43 UTC (rev 169)
+++ trunk/punit/src/org/punit/assertion/Assert.java 2007-05-29 21:10:22 UTC (rev 170)
@@ -12,6 +12,12 @@
}
}
+ public static void assertNotSame(Object expected, Object actual) {
+ if (expected == actual) {
+ fail(Messages.getString("Assert.2") + expected); //$NON-NLS-1$
+ }
+ }
+
public static void assertEquals(Object expected, Object actual) {
if (!expected.equals(actual)) {
fail(expected, actual);
Modified: trunk/punit/src/punit.properties
===================================================================
--- trunk/punit/src/punit.properties 2007-05-29 15:09:43 UTC (rev 169)
+++ trunk/punit/src/punit.properties 2007-05-29 21:10:22 UTC (rev 170)
@@ -20,3 +20,4 @@
PDFRender.02=the open source performance benchmark framework\n
Assert.0=Excepted
Assert.1=, but
+Assert.2=expected not the same:
Modified: trunk/punit.test/src/tests/api/org/punit/assertion/AssertTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/assertion/AssertTest.java 2007-05-29 15:09:43 UTC (rev 169)
+++ trunk/punit.test/src/tests/api/org/punit/assertion/AssertTest.java 2007-05-29 21:10:22 UTC (rev 170)
@@ -8,6 +8,7 @@
import org.punit.assertion.Assert;
public class AssertTest extends TestCase {
+
public void testAssertSame() {
Object o1 = new Object();
Assert.assertSame(o1, o1);
@@ -18,6 +19,17 @@
// expected
}
}
+
+ public void testAssertNotSame() {
+ Object o1 = new Object();
+ Object o2 = new Object();
+ Assert.assertNotSame(o1, o2);
+ try {
+ Assert.assertNotSame(o1, o1);
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
public void testAssertEquals() {
String s1 = new String("1"); //$NON-NLS-1$
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-30 06:55:06
|
Revision: 171
http://p-unit.svn.sourceforge.net/p-unit/?rev=171&view=rev
Author: zhanghuangzhu
Date: 2007-05-29 23:55:07 -0700 (Tue, 29 May 2007)
Log Message:
-----------
Andrew Zhang: First implementation for annotation. Needs more tests about "check".
Modified Paths:
--------------
trunk/punit/src/org/punit/builder/method/TestMethodBuilder.java
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit/src/org/punit/runner/ConcurrentRunner.java
trunk/punit/src/org/punit/runner/SoloRunner.java
trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java
trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java
trunk/punit/src/org/punit/runner/method/MethodRunner.java
trunk/punit/src/org/punit/runner/method/SoloMethodRunner.java
trunk/punit/src/org/punit/watcher/MemoryWatcher.java
trunk/punit/src/org/punit/watcher/TimeWatcher.java
trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/runner/AbstractRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterface1.java
Added Paths:
-----------
trunk/punit/src/org/punit/builder/method/MethodBuilderImpl.java
trunk/punit/src/org/punit/runner/DefaultMethodFilter.java
trunk/punit/src/org/punit/type/MethodFilter.java
trunk/punit.extension/src/org/punit/annotation/
trunk/punit.extension/src/org/punit/annotation/Test.java
trunk/punit.extension/src/org/punit/builder/
trunk/punit.extension/src/org/punit/builder/method/
trunk/punit.extension/src/org/punit/builder/method/AnnotationMethodFilter.java
trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
Removed Paths:
-------------
trunk/punit/src/org/punit/builder/method/AbstractTestMethodBuilder.java
trunk/punit/src/org/punit/builder/method/TestMethodBuilderImpl.java
Deleted: trunk/punit/src/org/punit/builder/method/AbstractTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/method/AbstractTestMethodBuilder.java 2007-05-29 21:10:22 UTC (rev 170)
+++ trunk/punit/src/org/punit/builder/method/AbstractTestMethodBuilder.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -1,80 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.builder.method;
-
-import java.lang.reflect.*;
-import java.util.*;
-
-import org.punit.type.*;
-
-/**
- * This class is the basic implementation for <code>TestMethodBuilder</code>
- * interface.
- *
- */
-public abstract class AbstractTestMethodBuilder implements
- TestMethodBuilder {
-
- protected final HashSet _testMethodNames = new HashSet();
-
- /**
- * Judges whether this method is a test method.
- *
- * @param method
- * @return
- */
- protected abstract boolean isTestMethod(Method method);
-
- /**
- * @see TestMethodBuilder#buildTestMethods(Class)
- */
- public Collection buildTestMethods(Class testClass) {
- Collection testMethods = null;
- if (isAlphabetical(testClass)) {
- testMethods = new TreeSet(
- new AlphabeticalMethodNameComparator());
- } else {
- testMethods = new ArrayList();
- }
- Class clazz = testClass;
- while (clazz != Object.class) {
- Method[] methods = clazz.getDeclaredMethods();
- for (int i = 0; i < methods.length; ++i) {
- Method method = methods[i];
- if (isTestMethod(method)) {
- testMethods.add(method);
- }
- }
- clazz = clazz.getSuperclass();
- }
- return testMethods;
- }
-
- private boolean isAlphabetical(Class testClass) {
- return Alphabetical.class.isAssignableFrom(testClass);
- }
-
- private static class AlphabeticalMethodNameComparator implements Comparator {
- public int compare(Object o1, Object o2) {
- Method m1 = (Method) o1;
- Method m2 = (Method) o2;
- return m1.getName().compareTo(m2.getName());
- }
- }
-
- /**
- * @see TestMethodBuilder#addTestInterfaces(Class[])
- */
- public void addTestInterfaces(Class[] classes) {
- for (int i = 0; i < classes.length; ++i) {
- addTestInterface(classes[i]);
- }
- }
-
- private void addTestInterface(Class testInterface) {
- Method[] methods = testInterface.getDeclaredMethods();
- for (int i = 0; i < methods.length; ++i) {
- _testMethodNames.add(methods[i].getName());
- }
- }
-}
Copied: trunk/punit/src/org/punit/builder/method/MethodBuilderImpl.java (from rev 165, trunk/punit/src/org/punit/builder/method/AbstractTestMethodBuilder.java)
===================================================================
--- trunk/punit/src/org/punit/builder/method/MethodBuilderImpl.java (rev 0)
+++ trunk/punit/src/org/punit/builder/method/MethodBuilderImpl.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -0,0 +1,69 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.builder.method;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+import org.punit.type.*;
+
+/**
+ * This class is the basic implementation for <code>TestMethodBuilder</code>
+ * interface.
+ *
+ */
+public class MethodBuilderImpl implements TestMethodBuilder {
+
+ private MethodFilter _filter;
+
+ public void setMethodFilter(MethodFilter filter) {
+ _filter = filter;
+ }
+
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @param method
+ * @return
+ */
+ protected boolean isTestMethod(Method method) {
+ return _filter.isTestMethod(method);
+ }
+
+ /**
+ * @see TestMethodBuilder#buildTestMethods(Class)
+ */
+ public Collection buildTestMethods(Class testClass) {
+ Collection testMethods = null;
+ if (isAlphabetical(testClass)) {
+ testMethods = new TreeSet(new AlphabeticalMethodNameComparator());
+ } else {
+ testMethods = new ArrayList();
+ }
+ Class clazz = testClass;
+ while (clazz != Object.class) {
+ Method[] methods = clazz.getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ Method method = methods[i];
+ if (isTestMethod(method)) {
+ testMethods.add(method);
+ }
+ }
+ clazz = clazz.getSuperclass();
+ }
+ return testMethods;
+ }
+
+ private boolean isAlphabetical(Class testClass) {
+ return Alphabetical.class.isAssignableFrom(testClass);
+ }
+
+ private static class AlphabeticalMethodNameComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ Method m1 = (Method) o1;
+ Method m2 = (Method) o2;
+ return m1.getName().compareTo(m2.getName());
+ }
+ }
+
+}
Modified: trunk/punit/src/org/punit/builder/method/TestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/method/TestMethodBuilder.java 2007-05-29 21:10:22 UTC (rev 170)
+++ trunk/punit/src/org/punit/builder/method/TestMethodBuilder.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -5,6 +5,8 @@
import java.io.*;
import java.util.*;
+import org.punit.type.*;
+
/**
* Interface for test method builder. The method builder builds a list of
* methods, which will be executed by the method runner.
@@ -21,13 +23,6 @@
*/
public Collection buildTestMethods(Class testClass);
- /**
- * Adds test classes into the builder. TestMethodBuilder may use it to
- * judege whether a method is a test method.
- *
- * @param interfaces -
- * an array of test classes to be added.
- * @see PUnitTestMethodBuilder#isNameValid(java.lang.reflect.Method);
- */
- public void addTestInterfaces(Class[] interfaces);
+
+ public void setMethodFilter(MethodFilter filter);
}
Deleted: trunk/punit/src/org/punit/builder/method/TestMethodBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/builder/method/TestMethodBuilderImpl.java 2007-05-29 21:10:22 UTC (rev 170)
+++ trunk/punit/src/org/punit/builder/method/TestMethodBuilderImpl.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -1,78 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.builder.method;
-
-import java.lang.reflect.*;
-
-import org.punit.type.*;
-import org.punit.util.*;
-
-/**
- * The default test method builder of punit.
- *
- */
-public class TestMethodBuilderImpl extends AbstractTestMethodBuilder {
-
- private static final long serialVersionUID = -6490270178427969475L;
-
- /**
- * Judges whether this method is a test method.
- *
- * @return returns true if the test modifier, name, and parameter conform to
- * the convention of a test method.
- */
- protected boolean isTestMethod(Method method) {
- return isModifierValid(method) && isNameValid(method)
- && isParamValid(method);
- }
-
- /**
- * Judeges whether the modifier of is method conforms to the convention of a
- * test method.
- *
- * @param method
- * to be judged
- * @return returns true if this method is public and non static.
- */
- protected boolean isModifierValid(Method method) {
- return ReflectionUtil.isPublic(method)
- && !ReflectionUtil.isStatic(method);
- }
-
- /**
- * Judeges whether the name of is method conforms to the convention of a
- * test method.
- *
- * @param method
- * to be judged
- * @return returns true if the name of this method starts with "test", or
- * the name is in the list of test interfaces which are added by
- * <code>TestMethodBuilder.addTestInterfaces</code>
- */
- protected boolean isNameValid(Method method) {
- String name = method.getName();
- return name.startsWith("test") || _testMethodNames.contains(name); //$NON-NLS-1$
- }
-
- /**
- * Judges whether the paramaters of this method conforms to the convention
- * of a test method.
- *
- * @param method
- * @return returns true if the parameter length is zero and the test class
- * is not marked as <code>Parameterizable</code>, or the
- * parameter length is 1, and the parameter is assignable from
- * <code>Parameter</code>.
- */
- protected boolean isParamValid(Method method) {
- Class clazz = method.getDeclaringClass();
- Class[] params = method.getParameterTypes();
- if (TypeUtil.isPUnitParameterizableTest((clazz))) {
- return params.length == 1
- && Parameter.class.isAssignableFrom(params[0]);
- } else {
- return params.length == 0;
- }
- }
-
-}
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-05-29 21:10:22 UTC (rev 170)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -40,8 +40,14 @@
_methodRunner.setEventListeners(_eventListeners);
_methodRunner.setRunnerProperties(_properties);
registerLoggerListeners();
+ setMethodFilter(new DefaultMethodFilter());
}
+ public void setMethodFilter(DefaultMethodFilter filter) {
+ _testMethodBuilder.setMethodFilter(filter);
+ _methodRunner.setMethodFilter(filter);
+ }
+
public void run(Class clazz) {
initResultFolder();
onRunnerStart(clazz);
@@ -326,10 +332,6 @@
return _consoleLogger;
}
- public void addTestInterfaces(Class[] interfaces) {
- _testMethodBuilder.addTestInterfaces(interfaces);
- }
-
private boolean isTestSuiteLabel(Object testClass) {
return testClass instanceof TestSuiteLabel;
}
Modified: trunk/punit/src/org/punit/runner/ConcurrentRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/ConcurrentRunner.java 2007-05-29 21:10:22 UTC (rev 170)
+++ trunk/punit/src/org/punit/runner/ConcurrentRunner.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -22,7 +22,7 @@
}
public ConcurrentRunner(int concurrentCount) {
- super(new TestSuiteBuilderImpl(), new TestMethodBuilderImpl(), new ConcurrentMethodRunner(concurrentCount));
+ super(new TestSuiteBuilderImpl(), new MethodBuilderImpl(), new ConcurrentMethodRunner(concurrentCount));
}
public String punitName() {
Added: trunk/punit/src/org/punit/runner/DefaultMethodFilter.java
===================================================================
--- trunk/punit/src/org/punit/runner/DefaultMethodFilter.java (rev 0)
+++ trunk/punit/src/org/punit/runner/DefaultMethodFilter.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -0,0 +1,75 @@
+package org.punit.runner;
+
+import java.lang.reflect.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class DefaultMethodFilter implements MethodFilter {
+
+ public Method getCheckMethod(Method method) {
+ String checkMethodName = "check_" + method.getName(); //$NON-NLS-1$
+ return ReflectionUtil.getMethod(method.getDeclaringClass(),
+ checkMethodName, method.getParameterTypes());
+ }
+
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @return returns true if the test modifier, name, and parameter conform to
+ * the convention of a test method.
+ */
+ public boolean isTestMethod(Method method) {
+ return isModifierValid(method) && isNameValid(method)
+ && isParamValid(method);
+ }
+
+ /**
+ * Judeges whether the modifier of is method conforms to the convention of a
+ * test method.
+ *
+ * @param method
+ * to be judged
+ * @return returns true if this method is public and non static.
+ */
+ protected boolean isModifierValid(Method method) {
+ return ReflectionUtil.isPublic(method)
+ && !ReflectionUtil.isStatic(method);
+ }
+
+ /**
+ * Judeges whether the name of is method conforms to the convention of a
+ * test method.
+ *
+ * @param method
+ * to be judged
+ * @return returns true if the name of this method starts with "test", or
+ * the name is in the list of test interfaces which are added by
+ * <code>TestMethodBuilder.addTestInterfaces</code>
+ */
+ protected boolean isNameValid(Method method) {
+ String name = method.getName();
+ return name.startsWith("test"); //$NON-NLS-1$
+ }
+
+ /**
+ * Judges whether the paramaters of this method conforms to the convention
+ * of a test method.
+ *
+ * @param method
+ * @return returns true if the parameter length is zero and the test class
+ * is not marked as <code>Parameterizable</code>, or the
+ * parameter length is 1, and the parameter is assignable from
+ * <code>Parameter</code>.
+ */
+ protected boolean isParamValid(Method method) {
+ Class clazz = method.getDeclaringClass();
+ Class[] params = method.getParameterTypes();
+ if (TypeUtil.isPUnitParameterizableTest((clazz))) {
+ return params.length == 1
+ && Parameter.class.isAssignableFrom(params[0]);
+ } else {
+ return params.length == 0;
+ }
+ }
+}
Modified: trunk/punit/src/org/punit/runner/SoloRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/SoloRunner.java 2007-05-29 21:10:22 UTC (rev 170)
+++ trunk/punit/src/org/punit/runner/SoloRunner.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -17,9 +17,8 @@
}
public SoloRunner() {
- super(new TestSuiteBuilderImpl(), new TestMethodBuilderImpl(),
+ super(new TestSuiteBuilderImpl(), new MethodBuilderImpl(),
new SoloMethodRunner());
-
}
public String punitName() {
Modified: trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java 2007-05-29 21:10:22 UTC (rev 170)
+++ trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -22,6 +22,8 @@
private RunnerProperties _runnerProperties;
+ private MethodFilter _filter;
+
protected transient Object _testInstance;
protected transient Method _method;
@@ -33,6 +35,8 @@
protected transient Method _tearDownMethod;
protected transient Method _setUpMethod;
+
+ private transient Method _checkMethod;
public AbstractMethodRunner() {
_watchers.add(_timeWatcher);
@@ -68,6 +72,7 @@
startWatchers(testInstance, method, params);
setUpAfterWatchers(params);
runImpl();
+ runCheckMethod(testInstance, params);
} else {
startWatchers(testInstance, method, params);
}
@@ -93,6 +98,12 @@
}
onMethodEnd(method, testInstance, params, throwable);
}
+
+ private void runCheckMethod(Object testInstance, Object[] params) {
+ if(_checkMethod != null) {
+ ReflectionUtil.invokeMethod(_checkMethod, testInstance, params);
+ }
+ }
private void onMethodStart(final Method method, final Object testInstance,
final Object[] params) {
@@ -126,6 +137,7 @@
.getClass(), "setUp", new Class[] {}); //$NON-NLS-1$
_tearDownMethod = ReflectionUtil.getMethodAndSetAccessible(
_testInstance.getClass(), "tearDown", new Class[] {}); //$NON-NLS-1$
+ _checkMethod = _filter.getCheckMethod(method);
}
/**
@@ -285,4 +297,8 @@
throw new ReflectionException(e);
}
}
+
+ public void setMethodFilter(MethodFilter filter) {
+ _filter = filter;
+ }
}
Modified: trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java 2007-05-29 21:10:22 UTC (rev 170)
+++ trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -2,8 +2,6 @@
package org.punit.runner.method;
-import java.lang.reflect.*;
-
import org.punit.exception.*;
import org.punit.type.*;
import org.punit.util.*;
@@ -18,8 +16,6 @@
private transient TestMethodThread[] _threads;
- private transient Method _checkMethod;
-
public ConcurrentMethodRunner(int concurrentCount) {
_concurrentCount = concurrentCount;
}
@@ -30,14 +26,8 @@
if (_concurrentException.size() > 0) {
throw _concurrentException;
}
- runCheckMethod();
}
- private void runCheckMethod() {
- if(_checkMethod != null) {
- ReflectionUtil.invokeMethod(_checkMethod, _testInstance, _params);
- }
- }
protected void runMethod() throws Throwable {
ReflectionUtil.invokeMethod(_method, _testInstance, _params);
@@ -68,9 +58,7 @@
_threads = new TestMethodThread[threadCount];
for (int i = 0; i < _threads.length; ++i) {
_threads[i] = new TestMethodThread(this, "punit concurrent method runner"); //$NON-NLS-1$
- }
- String checkMethodName = getCheckMethodName();
- _checkMethod = ReflectionUtil.getMethodAndSetAccessible(_method.getDeclaringClass(), checkMethodName, _method.getParameterTypes());
+ }
}
protected String getCheckMethodName() {
Modified: trunk/punit/src/org/punit/runner/method/MethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/MethodRunner.java 2007-05-29 21:10:22 UTC (rev 170)
+++ trunk/punit/src/org/punit/runner/method/MethodRunner.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -5,6 +5,7 @@
import java.util.*;
import org.punit.runner.*;
+import org.punit.type.*;
import org.punit.watcher.*;
public interface MethodRunner extends Serializable, Cloneable {
@@ -36,4 +37,6 @@
public void removeWatcher(Watcher watcher);
public Object clone();
+
+ public void setMethodFilter(MethodFilter filter);
}
Modified: trunk/punit/src/org/punit/runner/method/SoloMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/SoloMethodRunner.java 2007-05-29 21:10:22 UTC (rev 170)
+++ trunk/punit/src/org/punit/runner/method/SoloMethodRunner.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -3,12 +3,13 @@
package org.punit.runner.method;
import org.punit.exception.*;
+import org.punit.type.*;
import org.punit.util.*;
-public class SoloMethodRunner extends AbstractMethodRunner {
+public class SoloMethodRunner extends AbstractMethodRunner {
+
+ private static final long serialVersionUID = 3278612571978181393L;
- private static final long serialVersionUID = 3278612571978181393L;
-
protected void runImpl() throws Throwable {
try {
ReflectionUtil.invokeMethod(_method, _testInstance, _params);
Added: trunk/punit/src/org/punit/type/MethodFilter.java
===================================================================
--- trunk/punit/src/org/punit/type/MethodFilter.java (rev 0)
+++ trunk/punit/src/org/punit/type/MethodFilter.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -0,0 +1,23 @@
+package org.punit.type;
+
+import java.io.*;
+import java.lang.reflect.*;
+
+public interface MethodFilter extends Serializable {
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @return returns true if the test modifier, name, and parameter conform to
+ * the convention of a test method.
+ */
+ public boolean isTestMethod(Method method);
+
+ /**
+ * Gets the corresponding check method to this test method
+ *
+ * @param method
+ * the test method
+ * @return
+ */
+ public Method getCheckMethod(Method method);
+}
Modified: trunk/punit/src/org/punit/watcher/MemoryWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-29 21:10:22 UTC (rev 170)
+++ trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -71,4 +71,12 @@
throw new ReflectionException(e);
}
}
+
+ public int hashCode() {
+ return getClass().hashCode();
+ }
+
+ public boolean equals(Object obj) {
+ return getClass() == obj.getClass();
+ }
}
Modified: trunk/punit/src/org/punit/watcher/TimeWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/TimeWatcher.java 2007-05-29 21:10:22 UTC (rev 170)
+++ trunk/punit/src/org/punit/watcher/TimeWatcher.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -44,4 +44,13 @@
throw new ReflectionException(e);
}
}
+
+ public int hashCode() {
+ return getClass().hashCode();
+ }
+
+ public boolean equals(Object obj) {
+ return getClass() == obj.getClass();
+ }
+
}
Added: trunk/punit.extension/src/org/punit/annotation/Test.java
===================================================================
--- trunk/punit.extension/src/org/punit/annotation/Test.java (rev 0)
+++ trunk/punit.extension/src/org/punit/annotation/Test.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -0,0 +1,15 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.annotation;
+
+
+public @interface Test {
+
+ Class<? extends Throwable> expected() default NoException.class;
+
+ String checkMethod() default "";
+
+ static class NoException extends Throwable {
+ private static final long serialVersionUID = 3987745685001380514L;
+ }
+}
Added: trunk/punit.extension/src/org/punit/builder/method/AnnotationMethodFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/builder/method/AnnotationMethodFilter.java (rev 0)
+++ trunk/punit.extension/src/org/punit/builder/method/AnnotationMethodFilter.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -0,0 +1,32 @@
+package org.punit.builder.method;
+
+import java.lang.reflect.*;
+
+import org.punit.annotation.*;
+import org.punit.runner.*;
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class AnnotationMethodFilter implements MethodFilter {
+
+ DefaultMethodFilter _delegate = new DefaultMethodFilter();
+
+ public Method getCheckMethod(Method method) {
+ Test testAnnotation = method.getAnnotation(Test.class);
+ String checkMethodName = null;
+ if (testAnnotation != null) {
+ checkMethodName = testAnnotation.checkMethod();
+ if (checkMethodName != null) {
+ return ReflectionUtil.getMethod(method.getDeclaringClass(),
+ checkMethodName, method.getParameterTypes());
+ }
+ }
+ return _delegate.getCheckMethod(method);
+ }
+
+ public boolean isTestMethod(Method method) {
+ Test testAnnotation = method.getAnnotation(Test.class);
+ return (testAnnotation != null) || _delegate.isTestMethod(method);
+ }
+
+}
Modified: trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2007-05-29 21:10:22 UTC (rev 170)
+++ trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -19,10 +19,8 @@
public abstract class AbstractChartReporter implements PUnitEventListener {
- private Hashtable datasets = new Hashtable(); // <DatasetKey,
+ private Hashtable _datasets = new Hashtable(); // <DatasetKey, DefaultCategoryDataset>
- // DefaultCategoryDataset>
-
private LinkedList _currentSuiteStack = new LinkedList();
protected ChartRender _render;
@@ -153,8 +151,8 @@
return _runnerProperties.isParent;
}
- protected final DefaultCategoryDataset getDatasetOrNew(Object key) {
- DefaultCategoryDataset dataset = (DefaultCategoryDataset) datasets
+ private final DefaultCategoryDataset getDatasetOrNew(Object key) {
+ DefaultCategoryDataset dataset = (DefaultCategoryDataset) _datasets
.get(key);
if (dataset == null) {
dataset = new DefaultCategoryDataset();
@@ -164,11 +162,11 @@
}
protected final void putDataset(Object key, DefaultCategoryDataset dataset) {
- datasets.put(key, dataset);
+ _datasets.put(key, dataset);
}
protected final Hashtable datasets() {
- return datasets;
+ return _datasets;
}
public boolean supportParentRunner() {
@@ -195,7 +193,7 @@
return (PUnitTestSuite) _currentSuiteStack.getLast();
}
- public void onMethodEnd(final Method method, final Object testInstance,
+ public synchronized void onMethodEnd(final Method method, final Object testInstance,
final Object[] params, final Throwable t, List watchers) {
TraverserUtil.traverse(watchers.iterator(), new Traverser() {
public void traverse(Object obj) {
Modified: trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java 2007-05-29 21:10:22 UTC (rev 170)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -5,7 +5,6 @@
import junit.framework.*;
import org.punit.builder.method.*;
-import org.punit.builder.suite.*;
import tests.api.org.punit.testclasses.*;
import tests.util.*;
@@ -15,7 +14,7 @@
private MockTestMethodBuilder _builder = new MockTestMethodBuilder();
public void testAddInterfaces() {
- _builder.addTestInterfaces(new Class[] { TestInterface1.class });
+ _builder.setMethodFilter(new AnnotationMethodFilter());
Object[] methods = _builder.buildTestMethods(TestInterfaceImpl1.class)
.toArray();
String[] names = TestUtil.toMethodNameArray(methods);
@@ -52,7 +51,7 @@
"testb" }); //$NON-NLS-1$
}
- static class MockTestMethodBuilder extends AbstractTestMethodBuilder {
+ static class MockTestMethodBuilder extends MethodBuilderImpl {
protected boolean isTestMethod(Method method) {
return true;
}
Modified: trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java 2007-05-29 21:10:22 UTC (rev 170)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -3,16 +3,17 @@
import junit.framework.*;
import org.punit.builder.method.*;
-import org.punit.builder.suite.*;
+import org.punit.runner.*;
import tests.api.org.punit.testclasses.*;
import tests.util.*;
public class PUnitTestMethodBuilderTest extends TestCase {
- private TestMethodBuilderImpl _builder;
+ private MethodBuilderImpl _builder;
protected void setUp() throws Exception {
- _builder = new TestMethodBuilderImpl();
+ _builder = new MethodBuilderImpl();
+ _builder.setMethodFilter(new DefaultMethodFilter());
}
public void testBuildTestMethods1() {
Modified: trunk/punit.test/src/tests/api/org/punit/runner/AbstractRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/AbstractRunnerTest.java 2007-05-29 21:10:22 UTC (rev 170)
+++ trunk/punit.test/src/tests/api/org/punit/runner/AbstractRunnerTest.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -2,13 +2,13 @@
package tests.api.org.punit.runner;
+import junit.framework.*;
+
import org.punit.builder.method.*;
import org.punit.builder.suite.*;
import org.punit.runner.*;
import org.punit.runner.method.*;
-import junit.framework.*;
-
public class AbstractRunnerTest extends TestCase {
protected MockPUnitEventListener _eventListener = new MockPUnitEventListener();
@@ -24,8 +24,10 @@
static class MockAbstractPUnitRunner extends AbstractRunner {
+ private static final long serialVersionUID = 1L;
+
public MockAbstractPUnitRunner() {
- super(new TestSuiteBuilderImpl(), new TestMethodBuilderImpl(),
+ super(new TestSuiteBuilderImpl(), new MethodBuilderImpl(),
new SoloMethodRunner());
}
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-05-30 06:55:07 UTC (rev 171)
@@ -0,0 +1,49 @@
+package tests.api.org.punit.testclasses;
+
+import junit.framework.*;
+
+import org.punit.annotation.Test;
+
+
+
+public class AnnotationTestClass {
+ public static boolean _test1;
+
+ public static boolean _test2;
+
+ public static boolean _setUp;
+
+ public static boolean _tearDown;
+
+ public static void reset() {
+ _test1 = false;
+ _test2 = false;
+ _setUp = false;
+ _tearDown = false;
+ }
+
+
+ private void setUp() {
+ _setUp = true;
+ }
+
+ priv...
[truncated message content] |
|
From: <zha...@us...> - 2007-05-30 07:27:46
|
Revision: 172
http://p-unit.svn.sourceforge.net/p-unit/?rev=172&view=rev
Author: zhanghuangzhu
Date: 2007-05-30 00:27:47 -0700 (Wed, 30 May 2007)
Log Message:
-----------
Andrew Zhang: Added more tests about annotation and fixed bugs.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit.extension/src/org/punit/annotation/Test.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterface1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterfaceImpl1.java
Added Paths:
-----------
trunk/punit.test/src/tests/api/org/punit/builder/MethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/builder/method/
trunk/punit.test/src/tests/api/org/punit/builder/method/AnnotationMethodFilterTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationConcurrentTestClass.java
Removed Paths:
-------------
trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-05-30 06:55:07 UTC (rev 171)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-05-30 07:27:47 UTC (rev 172)
@@ -43,7 +43,7 @@
setMethodFilter(new DefaultMethodFilter());
}
- public void setMethodFilter(DefaultMethodFilter filter) {
+ public void setMethodFilter(MethodFilter filter) {
_testMethodBuilder.setMethodFilter(filter);
_methodRunner.setMethodFilter(filter);
}
Modified: trunk/punit.extension/src/org/punit/annotation/Test.java
===================================================================
--- trunk/punit.extension/src/org/punit/annotation/Test.java 2007-05-30 06:55:07 UTC (rev 171)
+++ trunk/punit.extension/src/org/punit/annotation/Test.java 2007-05-30 07:27:47 UTC (rev 172)
@@ -2,13 +2,16 @@
package org.punit.annotation;
+import java.lang.annotation.*;
-public @interface Test {
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Test {
Class<? extends Throwable> expected() default NoException.class;
-
- String checkMethod() default "";
-
+
+ String checkMethod() default "";
+
static class NoException extends Throwable {
private static final long serialVersionUID = 3987745685001380514L;
}
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-30 06:55:07 UTC (rev 171)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-30 07:27:47 UTC (rev 172)
@@ -3,6 +3,7 @@
import junit.framework.*;
import tests.api.org.punit.assertion.*;
import tests.api.org.punit.builder.*;
+import tests.api.org.punit.builder.method.*;
import tests.api.org.punit.exception.*;
import tests.api.org.punit.reporter.stream.*;
import tests.api.org.punit.runner.*;
@@ -30,10 +31,11 @@
AbstractRunnerTest.class,
AbstractTestMethodRunnerTest.class,
AssertTest.class,
+ AnnotationMethodFilterTest.class,
ConcurrentExceptionTest.class,
LoggerUtilTest.class,
MemoryWatcherTest.class,
- PUnitAbstractTestMethodBuilderTest.class,
+ MethodBuilderTest.class,
ConcurrentRunnerTest.class,
PUnitStreamListenerTest.class,
ExecutorPoolTest.class,
Copied: trunk/punit.test/src/tests/api/org/punit/builder/MethodBuilderTest.java (from rev 171, trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java)
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/MethodBuilderTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/builder/MethodBuilderTest.java 2007-05-30 07:27:47 UTC (rev 172)
@@ -0,0 +1,60 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.builder;
+
+import junit.framework.*;
+
+import org.punit.builder.method.*;
+import org.punit.runner.*;
+
+import tests.api.org.punit.testclasses.*;
+import tests.util.*;
+
+public class MethodBuilderTest extends TestCase {
+
+ private MethodBuilderImpl _builder;
+
+ public void setUp() {
+ _builder = new MethodBuilderImpl();
+ _builder.setMethodFilter(new DefaultMethodFilter());
+ }
+
+ public void testAddInterfaces() {
+ _builder.setMethodFilter(new AnnotationMethodFilter());
+ Object[] methods = _builder.buildTestMethods(TestInterfaceImpl1.class)
+ .toArray();
+ String[] names = TestUtil.toMethodNameArray(methods);
+ AssertUtil.assertArrayContent(names, new String[] { "method1" }); //$NON-NLS-1$
+ }
+
+ public void testBuildTestMethods1() {
+ Object[] methods = _builder.buildTestMethods(TestClass1.class)
+ .toArray();
+ String[] names = TestUtil.toMethodNameArray(methods);
+ AssertUtil.assertArrayContains(names, new String[] { "test1", "test2", //$NON-NLS-1$ //$NON-NLS-2$
+ "testa", "testb" }); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBuildTestMethods_SubClass() {
+ Object[] methods = _builder.buildTestMethods(SubTestClass.class).toArray();
+ String[] names = TestUtil.toMethodNameArray(methods);
+ AssertUtil.assertArrayContains(names, new String[] { "test1", "test2", //$NON-NLS-1$ //$NON-NLS-2$
+ "testa", "testb" }); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBuildTestMethods2() {
+ Object[] methods = _builder.buildTestMethods(TestClass2.class).toArray();
+ String[] names = TestUtil.toMethodNameArray(methods);
+ AssertUtil.assertArrayContent(names, new String[] { "test1", "test2", //$NON-NLS-1$ //$NON-NLS-2$
+ "testa", "testb" }); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBuildTestMethods3() {
+ Object[] methods = _builder.buildTestMethods(TestClass3.class).toArray();
+ String[] names = TestUtil.toMethodNameArray(methods);
+ AssertUtil.assertArrayContent(names, new String[] {
+ "test1", "test2", "testa", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "testb" }); //$NON-NLS-1$
+ }
+
+}
Deleted: trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java 2007-05-30 06:55:07 UTC (rev 171)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java 2007-05-30 07:27:47 UTC (rev 172)
@@ -1,61 +0,0 @@
-package tests.api.org.punit.builder;
-
-import java.lang.reflect.*;
-
-import junit.framework.*;
-
-import org.punit.builder.method.*;
-
-import tests.api.org.punit.testclasses.*;
-import tests.util.*;
-
-public class PUnitAbstractTestMethodBuilderTest extends TestCase {
-
- private MockTestMethodBuilder _builder = new MockTestMethodBuilder();
-
- public void testAddInterfaces() {
- _builder.setMethodFilter(new AnnotationMethodFilter());
- Object[] methods = _builder.buildTestMethods(TestInterfaceImpl1.class)
- .toArray();
- String[] names = TestUtil.toMethodNameArray(methods);
- AssertUtil.assertArrayContent(names, new String[] { "method1" }); //$NON-NLS-1$
- }
-
- public void testBuildTestMethods1() {
- Object[] methods = _builder.buildTestMethods(TestClass1.class)
- .toArray();
- String[] names = TestUtil.toMethodNameArray(methods);
- AssertUtil.assertArrayContains(names, new String[] { "test1", "test2", //$NON-NLS-1$ //$NON-NLS-2$
- "testa", "testb" }); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBuildTestMethods_SubClass() {
- Object[] methods = _builder.buildTestMethods(SubTestClass.class).toArray();
- String[] names = TestUtil.toMethodNameArray(methods);
- AssertUtil.assertArrayContains(names, new String[] { "test1", "test2", //$NON-NLS-1$ //$NON-NLS-2$
- "testa", "testb" }); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBuildTestMethods2() {
- Object[] methods = _builder.buildTestMethods(TestClass2.class).toArray();
- String[] names = TestUtil.toMethodNameArray(methods);
- AssertUtil.assertArrayContent(names, new String[] { "test1", "test2", //$NON-NLS-1$ //$NON-NLS-2$
- "testa", "testb" }); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testBuildTestMethods3() {
- Object[] methods = _builder.buildTestMethods(TestClass3.class).toArray();
- String[] names = TestUtil.toMethodNameArray(methods);
- AssertUtil.assertArrayContent(names, new String[] {
- "test1", "test2", "testa", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- "testb" }); //$NON-NLS-1$
- }
-
- static class MockTestMethodBuilder extends MethodBuilderImpl {
- protected boolean isTestMethod(Method method) {
- return true;
- }
-
- }
-
-}
Added: trunk/punit.test/src/tests/api/org/punit/builder/method/AnnotationMethodFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/method/AnnotationMethodFilterTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/builder/method/AnnotationMethodFilterTest.java 2007-05-30 07:27:47 UTC (rev 172)
@@ -0,0 +1,50 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.builder.method;
+
+import java.lang.reflect.*;
+
+import junit.framework.*;
+
+import org.punit.annotation.Test;
+import org.punit.builder.method.*;
+import org.punit.util.*;
+
+public class AnnotationMethodFilterTest extends TestCase {
+ AnnotationMethodFilter _filter = new AnnotationMethodFilter();
+
+ public void testIsTestMethod() {
+ Method method;
+ method = ReflectionUtil.getMethod(getClass(), "_test1", new Class[] {}); //$NON-NLS-1$
+ assertFalse(_filter.isTestMethod(method));
+
+ method = ReflectionUtil.getMethod(getClass(), "_test2", new Class[] {}); //$NON-NLS-1$
+ assertTrue(_filter.isTestMethod(method));
+ }
+
+ public void testGetCheckMethod() {
+ Method method, checkMethod;
+ method = ReflectionUtil.getMethod(getClass(), "_test1", new Class[] {}); //$NON-NLS-1$
+ assertFalse(_filter.isTestMethod(method));
+ checkMethod = _filter.getCheckMethod(method);
+ assertNull(checkMethod);
+
+ method = ReflectionUtil.getMethod(getClass(), "_test2", new Class[] {}); //$NON-NLS-1$
+ assertTrue(_filter.isTestMethod(method));
+ checkMethod = _filter.getCheckMethod(method);
+ assertEquals("checkTest2", checkMethod.getName()); //$NON-NLS-1$
+ }
+
+ public void _test1() {
+
+ }
+
+ @Test(checkMethod="checkTest2")
+ public void _test2() {
+
+ }
+
+ public void checkTest2() {
+
+ }
+}
Modified: trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2007-05-30 06:55:07 UTC (rev 171)
+++ trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2007-05-30 07:27:47 UTC (rev 172)
@@ -6,6 +6,7 @@
import junit.framework.*;
+import org.punit.builder.method.*;
import org.punit.runner.*;
import tests.api.org.punit.testclasses.*;
@@ -38,6 +39,13 @@
TestClass.assertTestClassRun();
}
+ public void testRunAnnotationTest() {
+ AnnotationTestClass.reset();
+ _runner.setMethodFilter(new AnnotationMethodFilter());
+ _runner.run(AnnotationTestClass.class);
+ AnnotationTestClass.assertTestClassRun();
+ }
+
public void testRunPUnitTest() {
PUnitTestClass.reset();
_runner.run(PUnitTestClass.class);
Modified: trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2007-05-30 06:55:07 UTC (rev 171)
+++ trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2007-05-30 07:27:47 UTC (rev 172)
@@ -4,6 +4,7 @@
import junit.framework.*;
+import org.punit.builder.method.*;
import org.punit.runner.*;
import tests.api.org.punit.testclasses.*;
@@ -34,6 +35,13 @@
_eventListener.assertAllEventsInvoked();
}
+ public void testRunAnnotationTest() {
+ AnnotationTestClass.reset();
+ _runner.setMethodFilter(new AnnotationMethodFilter());
+ _runner.run(AnnotationTestClass.class);
+ AnnotationTestClass.assertTestClassRun();
+ }
+
public void testRunPUnitTest() {
PUnitTestClass.reset();
_runner.run(PUnitTestClass.class);
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationConcurrentTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationConcurrentTestClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationConcurrentTestClass.java 2007-05-30 07:27:47 UTC (rev 172)
@@ -0,0 +1,41 @@
+package tests.api.org.punit.testclasses;
+
+import org.punit.type.*;
+
+import tests.util.*;
+
+public class AnnotationConcurrentTestClass implements Concurrent {
+
+ public static boolean _assertCheck1;
+
+ public static boolean _assertCheck2;
+
+ public static int value = 0;
+
+ public static void reset() {
+ value = 0;
+ _assertCheck1 = false;
+ _assertCheck1 = false;
+ }
+
+ public synchronized void test1() {
+ ++value;
+ TestUtil.doSomething();
+ }
+
+ public synchronized void test2() {
+ TestUtil.doSomething();
+ }
+
+ public void check_test1() {
+ _assertCheck1 = true;
+ }
+
+ public void check_test2() {
+ _assertCheck2 = true;
+ }
+
+ public int concurrentCount() {
+ return 5;
+ }
+}
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-05-30 06:55:07 UTC (rev 171)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-05-30 07:27:47 UTC (rev 172)
@@ -10,6 +10,12 @@
public static boolean _test1;
public static boolean _test2;
+
+ public static boolean _check1;
+
+ public static boolean _check2;
+
+ public static boolean _check22;
public static boolean _setUp;
@@ -18,6 +24,9 @@
public static void reset() {
_test1 = false;
_test2 = false;
+ _check1 = false;
+ _check2 = false;
+ _check22 = false;
_setUp = false;
_tearDown = false;
}
@@ -31,18 +40,35 @@
_tearDown = true;
}
- public void _test1() {
+ public void test1() {
_test1 = true;
}
- @Test
+ @Test(checkMethod="annotation_check_2")
public void _test2() {
_test2 = true;
}
+
+ public void check_test1() {
+ _check1 = true;
+ }
+ public void annotation_check_2() {
+ _check2 = true;
+ }
+
+ public void check_test2() {
+ _check22 = true;
+ }
+
public static void assertTestClassRun() {
- Assert.assertFalse(_test1);
+ Assert.assertTrue(_test1);
+ Assert.assertTrue(_check1);
+
Assert.assertTrue(_test2);
+ Assert.assertTrue(_check2);
+ Assert.assertFalse(_check22);
+
Assert.assertTrue(_setUp);
Assert.assertTrue(_tearDown);
}
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterface1.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterface1.java 2007-05-30 06:55:07 UTC (rev 171)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterface1.java 2007-05-30 07:27:47 UTC (rev 172)
@@ -1,9 +1,6 @@
+/* (C) Copyright 2007, by Andrew Zhang */
package tests.api.org.punit.testclasses;
-import org.punit.annotation.*;
-
-
public interface TestInterface1 {
- @Test
public void method1();
}
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterfaceImpl1.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterfaceImpl1.java 2007-05-30 06:55:07 UTC (rev 171)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterfaceImpl1.java 2007-05-30 07:27:47 UTC (rev 172)
@@ -1,7 +1,12 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
package tests.api.org.punit.testclasses;
+import org.punit.annotation.*;
+
public class TestInterfaceImpl1 implements TestInterface1 {
+ @Test
public void method1() {
throw new UnsupportedOperationException();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-30 08:05:53
|
Revision: 174
http://p-unit.svn.sourceforge.net/p-unit/?rev=174&view=rev
Author: zhanghuangzhu
Date: 2007-05-30 01:05:52 -0700 (Wed, 30 May 2007)
Log Message:
-----------
Andrew Zhang: First implementation for annotation is done.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/DefaultMethodFilter.java
trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java
trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java
trunk/punit/src/org/punit/runner/method/SoloMethodRunner.java
trunk/punit/src/org/punit/type/MethodFilter.java
trunk/punit.extension/src/org/punit/annotation/Test.java
trunk/punit.extension/src/org/punit/builder/method/AnnotationMethodFilter.java
trunk/punit.test/src/tests/api/org/punit/builder/method/AnnotationMethodFilterTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
Removed Paths:
-------------
trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationConcurrentTestClass.java
Modified: trunk/punit/src/org/punit/runner/DefaultMethodFilter.java
===================================================================
--- trunk/punit/src/org/punit/runner/DefaultMethodFilter.java 2007-05-30 07:35:35 UTC (rev 173)
+++ trunk/punit/src/org/punit/runner/DefaultMethodFilter.java 2007-05-30 08:05:52 UTC (rev 174)
@@ -72,4 +72,8 @@
return params.length == 0;
}
}
+
+ public Class getExpectedException(Method method) {
+ return null;
+ }
}
Modified: trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java 2007-05-30 07:35:35 UTC (rev 173)
+++ trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java 2007-05-30 08:05:52 UTC (rev 174)
@@ -22,7 +22,7 @@
private RunnerProperties _runnerProperties;
- private MethodFilter _filter;
+ protected MethodFilter _filter;
protected transient Object _testInstance;
@@ -37,6 +37,8 @@
protected transient Method _setUpMethod;
private transient Method _checkMethod;
+
+ protected transient Class _expectedException;
public AbstractMethodRunner() {
_watchers.add(_timeWatcher);
@@ -138,6 +140,7 @@
_tearDownMethod = ReflectionUtil.getMethodAndSetAccessible(
_testInstance.getClass(), "tearDown", new Class[] {}); //$NON-NLS-1$
_checkMethod = _filter.getCheckMethod(method);
+ _expectedException = _filter.getExpectedException(method);
}
/**
Modified: trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java 2007-05-30 07:35:35 UTC (rev 173)
+++ trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java 2007-05-30 08:05:52 UTC (rev 174)
@@ -2,6 +2,7 @@
package org.punit.runner.method;
+import org.punit.assertion.*;
import org.punit.exception.*;
import org.punit.type.*;
import org.punit.util.*;
@@ -30,7 +31,11 @@
protected void runMethod() throws Throwable {
- ReflectionUtil.invokeMethod(_method, _testInstance, _params);
+ try {
+ ReflectionUtil.invokeMethod(_method, _testInstance, _params);
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
}
private void startThreads() {
@@ -75,9 +80,15 @@
public void run() {
try {
- _runner.runMethod();
- } catch (ReflectionException e) {
- _concurrentException.add(e.getCause());
+ if(_expectedException == null) {
+ _runner.runMethod();
+ } else {
+ Assert.assertException(_expectedException, new CodeRunner() {
+ public void run() throws Throwable {
+ _runner.runMethod();
+ }
+ });
+ }
} catch (Throwable t) {
_concurrentException.add(t);
}
Modified: trunk/punit/src/org/punit/runner/method/SoloMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/SoloMethodRunner.java 2007-05-30 07:35:35 UTC (rev 173)
+++ trunk/punit/src/org/punit/runner/method/SoloMethodRunner.java 2007-05-30 08:05:52 UTC (rev 174)
@@ -2,15 +2,27 @@
package org.punit.runner.method;
+import org.punit.assertion.*;
import org.punit.exception.*;
-import org.punit.type.*;
import org.punit.util.*;
-public class SoloMethodRunner extends AbstractMethodRunner {
+public class SoloMethodRunner extends AbstractMethodRunner {
private static final long serialVersionUID = 3278612571978181393L;
-
+
protected void runImpl() throws Throwable {
+ if (_expectedException == null) {
+ runMethod();
+ } else {
+ Assert.assertException(_expectedException, new CodeRunner() {
+ public void run() throws Throwable {
+ runMethod();
+ }
+ });
+ }
+ }
+
+ private void runMethod() throws Throwable {
try {
ReflectionUtil.invokeMethod(_method, _testInstance, _params);
} catch (ReflectionException e) {
Modified: trunk/punit/src/org/punit/type/MethodFilter.java
===================================================================
--- trunk/punit/src/org/punit/type/MethodFilter.java 2007-05-30 07:35:35 UTC (rev 173)
+++ trunk/punit/src/org/punit/type/MethodFilter.java 2007-05-30 08:05:52 UTC (rev 174)
@@ -20,4 +20,6 @@
* @return
*/
public Method getCheckMethod(Method method);
+
+ public Class getExpectedException(Method method);
}
Modified: trunk/punit.extension/src/org/punit/annotation/Test.java
===================================================================
--- trunk/punit.extension/src/org/punit/annotation/Test.java 2007-05-30 07:35:35 UTC (rev 173)
+++ trunk/punit.extension/src/org/punit/annotation/Test.java 2007-05-30 08:05:52 UTC (rev 174)
@@ -12,7 +12,7 @@
String checkMethod() default "";
- static class NoException extends Throwable {
+ public class NoException extends Throwable {
private static final long serialVersionUID = 3987745685001380514L;
}
}
Modified: trunk/punit.extension/src/org/punit/builder/method/AnnotationMethodFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/builder/method/AnnotationMethodFilter.java 2007-05-30 07:35:35 UTC (rev 173)
+++ trunk/punit.extension/src/org/punit/builder/method/AnnotationMethodFilter.java 2007-05-30 08:05:52 UTC (rev 174)
@@ -3,6 +3,7 @@
import java.lang.reflect.*;
import org.punit.annotation.*;
+import org.punit.annotation.Test.*;
import org.punit.runner.*;
import org.punit.type.*;
import org.punit.util.*;
@@ -29,4 +30,16 @@
return (testAnnotation != null) || _delegate.isTestMethod(method);
}
+ public Class<? extends Throwable> getExpectedException(Method method) {
+ Test testAnnotation = method.getAnnotation(Test.class);
+ if(testAnnotation == null) {
+ return null;
+ }
+ Class<? extends Throwable> expected = testAnnotation.expected();
+ if(expected == NoException.class) {
+ return null;
+ }
+ return expected;
+ }
+
}
Modified: trunk/punit.test/src/tests/api/org/punit/builder/method/AnnotationMethodFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/method/AnnotationMethodFilterTest.java 2007-05-30 07:35:35 UTC (rev 173)
+++ trunk/punit.test/src/tests/api/org/punit/builder/method/AnnotationMethodFilterTest.java 2007-05-30 08:05:52 UTC (rev 174)
@@ -40,11 +40,28 @@
assertEquals("check__test3", checkMethod.getName()); //$NON-NLS-1$
}
+ public void testGetExpectedException() {
+ Method method, checkMethod;
+ Class exception;
+
+ method = ReflectionUtil.getMethod(getClass(), "_test1", new Class[] {}); //$NON-NLS-1$
+ exception = _filter.getExpectedException(method);
+ assertNull(exception);
+
+ method = ReflectionUtil.getMethod(getClass(), "_test2", new Class[] {}); //$NON-NLS-1$
+ exception = _filter.getExpectedException(method);
+ assertSame(NullPointerException.class, exception);
+
+ method = ReflectionUtil.getMethod(getClass(), "_test3", new Class[] {}); //$NON-NLS-1$
+ exception = _filter.getExpectedException(method);
+ assertNull(exception);
+ }
+
public void _test1() {
}
- @Test(checkMethod="checkTest2")
+ @Test(checkMethod="checkTest2", expected=NullPointerException.class)
public void _test2() {
}
Deleted: trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationConcurrentTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationConcurrentTestClass.java 2007-05-30 07:35:35 UTC (rev 173)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationConcurrentTestClass.java 2007-05-30 08:05:52 UTC (rev 174)
@@ -1,41 +0,0 @@
-package tests.api.org.punit.testclasses;
-
-import org.punit.type.*;
-
-import tests.util.*;
-
-public class AnnotationConcurrentTestClass implements Concurrent {
-
- public static boolean _assertCheck1;
-
- public static boolean _assertCheck2;
-
- public static int value = 0;
-
- public static void reset() {
- value = 0;
- _assertCheck1 = false;
- _assertCheck1 = false;
- }
-
- public synchronized void test1() {
- ++value;
- TestUtil.doSomething();
- }
-
- public synchronized void test2() {
- TestUtil.doSomething();
- }
-
- public void check_test1() {
- _assertCheck1 = true;
- }
-
- public void check_test2() {
- _assertCheck2 = true;
- }
-
- public int concurrentCount() {
- return 5;
- }
-}
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-05-30 07:35:35 UTC (rev 173)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-05-30 08:05:52 UTC (rev 174)
@@ -3,24 +3,31 @@
import junit.framework.*;
import org.punit.annotation.Test;
+import org.punit.builder.method.*;
+import org.punit.runner.*;
-
-
public class AnnotationTestClass {
+
+ public static void main(String[] args) {
+ SoloRunner soloRunner = new SoloRunner();
+ soloRunner.setMethodFilter(new AnnotationMethodFilter());
+ soloRunner.run(AnnotationTestClass.class);
+ }
+
public static boolean _test1;
public static boolean _test2;
-
+
public static boolean _check1;
-
+
public static boolean _check2;
-
+
public static boolean _check22;
public static boolean _setUp;
-
+
public static boolean _tearDown;
-
+
public static void reset() {
_test1 = false;
_test2 = false;
@@ -31,11 +38,10 @@
_tearDown = false;
}
-
private void setUp() {
_setUp = true;
}
-
+
private void tearDown() {
_tearDown = true;
}
@@ -44,7 +50,7 @@
_test1 = true;
}
- @Test(checkMethod="annotation_check_2")
+ @Test(checkMethod = "annotation_check_2")
public void _test2() {
_test2 = true;
}
@@ -52,23 +58,28 @@
public void check_test1() {
_check1 = true;
}
-
+
public void annotation_check_2() {
- _check2 = true;
+ _check2 = true;
}
-
+
public void check_test2() {
- _check22 = true;
+ _check22 = true;
}
-
+
+ @Test(expected = NullPointerException.class)
+ public void _testException() {
+ throw new NullPointerException();
+ }
+
public static void assertTestClassRun() {
Assert.assertTrue(_test1);
Assert.assertTrue(_check1);
-
+
Assert.assertTrue(_test2);
Assert.assertTrue(_check2);
Assert.assertFalse(_check22);
-
+
Assert.assertTrue(_setUp);
Assert.assertTrue(_tearDown);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-31 06:03:32
|
Revision: 175
http://p-unit.svn.sourceforge.net/p-unit/?rev=175&view=rev
Author: zhanghuangzhu
Date: 2007-05-30 23:03:33 -0700 (Wed, 30 May 2007)
Log Message:
-----------
Andrew Zhang: Refactored some code and wrote more test cases.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java
trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java
trunk/punit/src/org/punit/runner/method/SoloMethodRunner.java
trunk/punit.extension/src/org/punit/builder/method/AnnotationMethodFilter.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/builder/MethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
Added Paths:
-----------
trunk/punit/src/org/punit/runner/ByNameMethodFilter.java
trunk/punit.test/src/tests/api/org/punit/builder/method/ByNameMethodFilterTest.java
Removed Paths:
-------------
trunk/punit/src/org/punit/runner/DefaultMethodFilter.java
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-05-30 08:05:52 UTC (rev 174)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-05-31 06:03:33 UTC (rev 175)
@@ -40,7 +40,7 @@
_methodRunner.setEventListeners(_eventListeners);
_methodRunner.setRunnerProperties(_properties);
registerLoggerListeners();
- setMethodFilter(new DefaultMethodFilter());
+ setMethodFilter(new ByNameMethodFilter());
}
public void setMethodFilter(MethodFilter filter) {
Copied: trunk/punit/src/org/punit/runner/ByNameMethodFilter.java (from rev 174, trunk/punit/src/org/punit/runner/DefaultMethodFilter.java)
===================================================================
--- trunk/punit/src/org/punit/runner/ByNameMethodFilter.java (rev 0)
+++ trunk/punit/src/org/punit/runner/ByNameMethodFilter.java 2007-05-31 06:03:33 UTC (rev 175)
@@ -0,0 +1,79 @@
+package org.punit.runner;
+
+import java.lang.reflect.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class ByNameMethodFilter implements MethodFilter {
+
+ public Method getCheckMethod(Method method) {
+ String checkMethodName = "check_" + method.getName(); //$NON-NLS-1$
+ return ReflectionUtil.getMethod(method.getDeclaringClass(),
+ checkMethodName, method.getParameterTypes());
+ }
+
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @return returns true if the test modifier, name, and parameter conform to
+ * the convention of a test method.
+ */
+ public boolean isTestMethod(Method method) {
+ return isModifierValid(method) && isNameValid(method)
+ && isParamValid(method);
+ }
+
+ /**
+ * Judeges whether the modifier of is method conforms to the convention of a
+ * test method.
+ *
+ * @param method
+ * to be judged
+ * @return returns true if this method is public and non static.
+ */
+ protected boolean isModifierValid(Method method) {
+ return ReflectionUtil.isPublic(method)
+ && !ReflectionUtil.isStatic(method);
+ }
+
+ /**
+ * Judeges whether the name of is method conforms to the convention of a
+ * test method.
+ *
+ * @param method
+ * to be judged
+ * @return returns true if the name of this method starts with "test", or
+ * the name is in the list of test interfaces which are added by
+ * <code>TestMethodBuilder.addTestInterfaces</code>
+ */
+ protected boolean isNameValid(Method method) {
+ String name = method.getName();
+ return name.startsWith("test"); //$NON-NLS-1$
+ }
+
+ /**
+ * Judges whether the paramaters of this method conforms to the convention
+ * of a test method.
+ *
+ * @param method
+ * @return returns true if the parameter length is zero and the test class
+ * is not marked as <code>Parameterizable</code>, or the
+ * parameter length is 1, and the parameter is assignable from
+ * <code>Parameter</code>.
+ */
+ protected boolean isParamValid(Method method) {
+ Class clazz = method.getDeclaringClass();
+ Class[] params = method.getParameterTypes();
+ if (TypeUtil.isPUnitParameterizableTest((clazz))) {
+ return params.length == 1
+ && Parameter.class.isAssignableFrom(params[0]);
+ } else {
+ return params.length == 0;
+ }
+ }
+
+ public Class getExpectedException(Method method) {
+ return null;
+ }
+}
Deleted: trunk/punit/src/org/punit/runner/DefaultMethodFilter.java
===================================================================
--- trunk/punit/src/org/punit/runner/DefaultMethodFilter.java 2007-05-30 08:05:52 UTC (rev 174)
+++ trunk/punit/src/org/punit/runner/DefaultMethodFilter.java 2007-05-31 06:03:33 UTC (rev 175)
@@ -1,79 +0,0 @@
-package org.punit.runner;
-
-import java.lang.reflect.*;
-
-import org.punit.type.*;
-import org.punit.util.*;
-
-public class DefaultMethodFilter implements MethodFilter {
-
- public Method getCheckMethod(Method method) {
- String checkMethodName = "check_" + method.getName(); //$NON-NLS-1$
- return ReflectionUtil.getMethod(method.getDeclaringClass(),
- checkMethodName, method.getParameterTypes());
- }
-
- /**
- * Judges whether this method is a test method.
- *
- * @return returns true if the test modifier, name, and parameter conform to
- * the convention of a test method.
- */
- public boolean isTestMethod(Method method) {
- return isModifierValid(method) && isNameValid(method)
- && isParamValid(method);
- }
-
- /**
- * Judeges whether the modifier of is method conforms to the convention of a
- * test method.
- *
- * @param method
- * to be judged
- * @return returns true if this method is public and non static.
- */
- protected boolean isModifierValid(Method method) {
- return ReflectionUtil.isPublic(method)
- && !ReflectionUtil.isStatic(method);
- }
-
- /**
- * Judeges whether the name of is method conforms to the convention of a
- * test method.
- *
- * @param method
- * to be judged
- * @return returns true if the name of this method starts with "test", or
- * the name is in the list of test interfaces which are added by
- * <code>TestMethodBuilder.addTestInterfaces</code>
- */
- protected boolean isNameValid(Method method) {
- String name = method.getName();
- return name.startsWith("test"); //$NON-NLS-1$
- }
-
- /**
- * Judges whether the paramaters of this method conforms to the convention
- * of a test method.
- *
- * @param method
- * @return returns true if the parameter length is zero and the test class
- * is not marked as <code>Parameterizable</code>, or the
- * parameter length is 1, and the parameter is assignable from
- * <code>Parameter</code>.
- */
- protected boolean isParamValid(Method method) {
- Class clazz = method.getDeclaringClass();
- Class[] params = method.getParameterTypes();
- if (TypeUtil.isPUnitParameterizableTest((clazz))) {
- return params.length == 1
- && Parameter.class.isAssignableFrom(params[0]);
- } else {
- return params.length == 0;
- }
- }
-
- public Class getExpectedException(Method method) {
- return null;
- }
-}
Modified: trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java 2007-05-30 08:05:52 UTC (rev 174)
+++ trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java 2007-05-31 06:03:33 UTC (rev 175)
@@ -5,6 +5,7 @@
import java.lang.reflect.*;
import java.util.*;
+import org.punit.assertion.*;
import org.punit.events.*;
import org.punit.exception.*;
import org.punit.runner.*;
@@ -304,4 +305,24 @@
public void setMethodFilter(MethodFilter filter) {
_filter = filter;
}
+
+ protected void runMethod() throws Throwable {
+ if (_expectedException == null) {
+ invokeMethod();
+ } else {
+ Assert.assertException(_expectedException, new CodeRunner() {
+ public void run() throws Throwable {
+ invokeMethod();
+ }
+ });
+ }
+ }
+
+ private void invokeMethod() throws Throwable {
+ try {
+ ReflectionUtil.invokeMethod(_method, _testInstance, _params);
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
}
Modified: trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java 2007-05-30 08:05:52 UTC (rev 174)
+++ trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java 2007-05-31 06:03:33 UTC (rev 175)
@@ -2,10 +2,8 @@
package org.punit.runner.method;
-import org.punit.assertion.*;
import org.punit.exception.*;
import org.punit.type.*;
-import org.punit.util.*;
public class ConcurrentMethodRunner extends AbstractMethodRunner {
@@ -28,15 +26,6 @@
throw _concurrentException;
}
}
-
-
- protected void runMethod() throws Throwable {
- try {
- ReflectionUtil.invokeMethod(_method, _testInstance, _params);
- } catch (ReflectionException e) {
- throw e.getCause();
- }
- }
private void startThreads() {
for (int i = 0; i < _threads.length; ++i) {
@@ -80,15 +69,7 @@
public void run() {
try {
- if(_expectedException == null) {
- _runner.runMethod();
- } else {
- Assert.assertException(_expectedException, new CodeRunner() {
- public void run() throws Throwable {
- _runner.runMethod();
- }
- });
- }
+ _runner.runMethod();
} catch (Throwable t) {
_concurrentException.add(t);
}
Modified: trunk/punit/src/org/punit/runner/method/SoloMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/SoloMethodRunner.java 2007-05-30 08:05:52 UTC (rev 174)
+++ trunk/punit/src/org/punit/runner/method/SoloMethodRunner.java 2007-05-31 06:03:33 UTC (rev 175)
@@ -2,32 +2,13 @@
package org.punit.runner.method;
-import org.punit.assertion.*;
-import org.punit.exception.*;
-import org.punit.util.*;
public class SoloMethodRunner extends AbstractMethodRunner {
private static final long serialVersionUID = 3278612571978181393L;
protected void runImpl() throws Throwable {
- if (_expectedException == null) {
- runMethod();
- } else {
- Assert.assertException(_expectedException, new CodeRunner() {
- public void run() throws Throwable {
- runMethod();
- }
- });
- }
+ runMethod();
}
- private void runMethod() throws Throwable {
- try {
- ReflectionUtil.invokeMethod(_method, _testInstance, _params);
- } catch (ReflectionException e) {
- throw e.getCause();
- }
- }
-
}
Modified: trunk/punit.extension/src/org/punit/builder/method/AnnotationMethodFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/builder/method/AnnotationMethodFilter.java 2007-05-30 08:05:52 UTC (rev 174)
+++ trunk/punit.extension/src/org/punit/builder/method/AnnotationMethodFilter.java 2007-05-31 06:03:33 UTC (rev 175)
@@ -10,7 +10,7 @@
public class AnnotationMethodFilter implements MethodFilter {
- DefaultMethodFilter _delegate = new DefaultMethodFilter();
+ ByNameMethodFilter _delegate = new ByNameMethodFilter();
public Method getCheckMethod(Method method) {
Test testAnnotation = method.getAnnotation(Test.class);
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-30 08:05:52 UTC (rev 174)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-31 06:03:33 UTC (rev 175)
@@ -32,6 +32,7 @@
AbstractTestMethodRunnerTest.class,
AssertTest.class,
AnnotationMethodFilterTest.class,
+ ByNameMethodFilterTest.class,
ConcurrentExceptionTest.class,
LoggerUtilTest.class,
MemoryWatcherTest.class,
Modified: trunk/punit.test/src/tests/api/org/punit/builder/MethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/MethodBuilderTest.java 2007-05-30 08:05:52 UTC (rev 174)
+++ trunk/punit.test/src/tests/api/org/punit/builder/MethodBuilderTest.java 2007-05-31 06:03:33 UTC (rev 175)
@@ -16,7 +16,7 @@
public void setUp() {
_builder = new MethodBuilderImpl();
- _builder.setMethodFilter(new DefaultMethodFilter());
+ _builder.setMethodFilter(new ByNameMethodFilter());
}
public void testAddInterfaces() {
Modified: trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java 2007-05-30 08:05:52 UTC (rev 174)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java 2007-05-31 06:03:33 UTC (rev 175)
@@ -13,7 +13,7 @@
protected void setUp() throws Exception {
_builder = new MethodBuilderImpl();
- _builder.setMethodFilter(new DefaultMethodFilter());
+ _builder.setMethodFilter(new ByNameMethodFilter());
}
public void testBuildTestMethods1() {
Added: trunk/punit.test/src/tests/api/org/punit/builder/method/ByNameMethodFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/method/ByNameMethodFilterTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/builder/method/ByNameMethodFilterTest.java 2007-05-31 06:03:33 UTC (rev 175)
@@ -0,0 +1,55 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.builder.method;
+
+import java.lang.reflect.*;
+
+import junit.framework.*;
+
+import org.punit.builder.method.*;
+import org.punit.util.*;
+
+public class ByNameMethodFilterTest extends TestCase {
+ AnnotationMethodFilter _filter = new AnnotationMethodFilter();
+
+ public void testIsTestMethod() {
+ Method method;
+ method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$
+ assertTrue(_filter.isTestMethod(method));
+
+ method = ReflectionUtil.getMethod(getClass(), "_test2", new Class[] {}); //$NON-NLS-1$
+ assertFalse(_filter.isTestMethod(method));
+ }
+
+ public void testGetCheckMethod() {
+ Method method, checkMethod;
+ method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$
+ checkMethod = _filter.getCheckMethod(method);
+ assertNull(checkMethod);
+
+ method = ReflectionUtil.getMethod(getClass(), "_test2", new Class[] {}); //$NON-NLS-1$
+ checkMethod = _filter.getCheckMethod(method);
+ assertEquals("check__test2", checkMethod.getName()); //$NON-NLS-1$
+ }
+
+
+ public void test1() {
+
+ }
+
+ public void _test2() {
+
+ }
+
+ public void check__test2() {
+
+ }
+
+ public void _test3() {
+
+ }
+
+ public void check__test3() {
+
+ }
+}
Modified: trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java 2007-05-30 08:05:52 UTC (rev 174)
+++ trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java 2007-05-31 06:03:33 UTC (rev 175)
@@ -4,9 +4,13 @@
import junit.framework.*;
+import org.punit.annotation.Test.*;
import org.punit.runner.method.*;
+import org.punit.util.*;
import org.punit.watcher.*;
+import tests.api.org.punit.testclasses.*;
+
public class AbstractTestMethodRunnerTest extends TestCase {
private MockTestMethodRunnerTest _mockRunner = new MockTestMethodRunnerTest();
@@ -23,8 +27,34 @@
assertEquals(1, watchers.size());
}
+ public void testRunMethod() throws Throwable {
+ _mockRunner.testRunMethod1();
+ }
+
static class MockTestMethodRunnerTest extends AbstractMethodRunner {
+ private static final long serialVersionUID = 1L;
+
+ public void testRunMethod1() throws Throwable {
+ AnnotationTestClass.reset();
+ this._method = ReflectionUtil.getMethod(AnnotationTestClass.class,"test1", new Class[]{}); //$NON-NLS-1$
+ this._params = new Object[] {};
+ this._testInstance = new AnnotationTestClass();
+ this._expectedException = null;
+ super.runMethod();
+ Assert.assertTrue(AnnotationTestClass._test1);
+ }
+
+ public void testRunMethod2() throws Throwable {
+ AnnotationTestClass.reset();
+ this._method = ReflectionUtil.getMethod(AnnotationTestClass.class,"_testException", new Class[]{}); //$NON-NLS-1$
+ this._params = new Object[] {};
+ this._testInstance = new AnnotationTestClass();
+ this._expectedException = NoException.class;
+ super.runMethod();
+ Assert.assertTrue(AnnotationTestClass._testException);
+ }
+
protected void runImpl() throws Throwable {
throw new UnsupportedOperationException();
}
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-05-30 08:05:52 UTC (rev 174)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-05-31 06:03:33 UTC (rev 175)
@@ -23,6 +23,8 @@
public static boolean _check2;
public static boolean _check22;
+
+ public static boolean _testException;
public static boolean _setUp;
@@ -34,6 +36,7 @@
_check1 = false;
_check2 = false;
_check22 = false;
+ _testException = false;
_setUp = false;
_tearDown = false;
}
@@ -69,6 +72,7 @@
@Test(expected = NullPointerException.class)
public void _testException() {
+ _testException = true;
throw new NullPointerException();
}
@@ -79,6 +83,8 @@
Assert.assertTrue(_test2);
Assert.assertTrue(_check2);
Assert.assertFalse(_check22);
+
+ Assert.assertTrue(_testException);
Assert.assertTrue(_setUp);
Assert.assertTrue(_tearDown);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-31 06:09:03
|
Revision: 176
http://p-unit.svn.sourceforge.net/p-unit/?rev=176&view=rev
Author: zhanghuangzhu
Date: 2007-05-30 23:09:04 -0700 (Wed, 30 May 2007)
Log Message:
-----------
Andrew Zhang: refactored package name.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit/src/org/punit/runner/ConcurrentRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit/src/org/punit/runner/SoloRunner.java
trunk/punit.extension/src/org/punit/builder/method/AnnotationMethodFilter.java
trunk/punit.test/src/tests/api/org/punit/builder/MethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestSuiteBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/builder/method/AnnotationMethodFilterTest.java
trunk/punit.test/src/tests/api/org/punit/builder/method/ByNameMethodFilterTest.java
trunk/punit.test/src/tests/api/org/punit/runner/AbstractRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
Added Paths:
-----------
trunk/punit/src/org/punit/method/
trunk/punit/src/org/punit/method/ByNameMethodFilter.java
trunk/punit/src/org/punit/method/MethodFilter.java
trunk/punit/src/org/punit/method/builder/
trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
trunk/punit/src/org/punit/method/runner/
trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
trunk/punit/src/org/punit/method/runner/MethodRunner.java
trunk/punit/src/org/punit/method/runner/SoloMethodRunner.java
trunk/punit/src/org/punit/suite/
trunk/punit/src/org/punit/suite/builder/
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
trunk/punit/src/org/punit/suite/builder/TestSuiteLabel.java
trunk/punit/src/org/punit/suite/builder/TestSuiteLabelImpl.java
Removed Paths:
-------------
trunk/punit/src/org/punit/builder/method/
trunk/punit/src/org/punit/builder/suite/
trunk/punit/src/org/punit/method/builder/PUnitAbstractTestMethodBuilder.java
trunk/punit/src/org/punit/method/builder/PUnitTestMethodBuilder.java
trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
trunk/punit/src/org/punit/method/runner/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/method/runner/ConcurrentTestMethodRunner.java
trunk/punit/src/org/punit/method/runner/SoloTestMethodRunner.java
trunk/punit/src/org/punit/method/runner/TestMethodRunner.java
trunk/punit/src/org/punit/runner/ByNameMethodFilter.java
trunk/punit/src/org/punit/runner/method/
trunk/punit/src/org/punit/suite/builder/PUnitTestSuiteBuilder.java
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
trunk/punit/src/org/punit/suite/builder/TestSuiteLabel.java
trunk/punit/src/org/punit/suite/builder/TestSuiteLabelImpl.java
trunk/punit/src/org/punit/type/MethodFilter.java
Copied: trunk/punit/src/org/punit/method/ByNameMethodFilter.java (from rev 175, trunk/punit/src/org/punit/runner/ByNameMethodFilter.java)
===================================================================
--- trunk/punit/src/org/punit/method/ByNameMethodFilter.java (rev 0)
+++ trunk/punit/src/org/punit/method/ByNameMethodFilter.java 2007-05-31 06:09:04 UTC (rev 176)
@@ -0,0 +1,79 @@
+package org.punit.method;
+
+import java.lang.reflect.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class ByNameMethodFilter implements MethodFilter {
+
+ public Method getCheckMethod(Method method) {
+ String checkMethodName = "check_" + method.getName(); //$NON-NLS-1$
+ return ReflectionUtil.getMethod(method.getDeclaringClass(),
+ checkMethodName, method.getParameterTypes());
+ }
+
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @return returns true if the test modifier, name, and parameter conform to
+ * the convention of a test method.
+ */
+ public boolean isTestMethod(Method method) {
+ return isModifierValid(method) && isNameValid(method)
+ && isParamValid(method);
+ }
+
+ /**
+ * Judeges whether the modifier of is method conforms to the convention of a
+ * test method.
+ *
+ * @param method
+ * to be judged
+ * @return returns true if this method is public and non static.
+ */
+ protected boolean isModifierValid(Method method) {
+ return ReflectionUtil.isPublic(method)
+ && !ReflectionUtil.isStatic(method);
+ }
+
+ /**
+ * Judeges whether the name of is method conforms to the convention of a
+ * test method.
+ *
+ * @param method
+ * to be judged
+ * @return returns true if the name of this method starts with "test", or
+ * the name is in the list of test interfaces which are added by
+ * <code>TestMethodBuilder.addTestInterfaces</code>
+ */
+ protected boolean isNameValid(Method method) {
+ String name = method.getName();
+ return name.startsWith("test"); //$NON-NLS-1$
+ }
+
+ /**
+ * Judges whether the paramaters of this method conforms to the convention
+ * of a test method.
+ *
+ * @param method
+ * @return returns true if the parameter length is zero and the test class
+ * is not marked as <code>Parameterizable</code>, or the
+ * parameter length is 1, and the parameter is assignable from
+ * <code>Parameter</code>.
+ */
+ protected boolean isParamValid(Method method) {
+ Class clazz = method.getDeclaringClass();
+ Class[] params = method.getParameterTypes();
+ if (TypeUtil.isPUnitParameterizableTest((clazz))) {
+ return params.length == 1
+ && Parameter.class.isAssignableFrom(params[0]);
+ } else {
+ return params.length == 0;
+ }
+ }
+
+ public Class getExpectedException(Method method) {
+ return null;
+ }
+}
Copied: trunk/punit/src/org/punit/method/MethodFilter.java (from rev 174, trunk/punit/src/org/punit/type/MethodFilter.java)
===================================================================
--- trunk/punit/src/org/punit/method/MethodFilter.java (rev 0)
+++ trunk/punit/src/org/punit/method/MethodFilter.java 2007-05-31 06:09:04 UTC (rev 176)
@@ -0,0 +1,25 @@
+package org.punit.method;
+
+import java.io.*;
+import java.lang.reflect.*;
+
+public interface MethodFilter extends Serializable {
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @return returns true if the test modifier, name, and parameter conform to
+ * the convention of a test method.
+ */
+ public boolean isTestMethod(Method method);
+
+ /**
+ * Gets the corresponding check method to this test method
+ *
+ * @param method
+ * the test method
+ * @return
+ */
+ public Method getCheckMethod(Method method);
+
+ public Class getExpectedException(Method method);
+}
Copied: trunk/punit/src/org/punit/method/builder (from rev 154, trunk/punit/src/org/punit/builder/method)
Copied: trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java (from rev 175, trunk/punit/src/org/punit/builder/method/MethodBuilderImpl.java)
===================================================================
--- trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java (rev 0)
+++ trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-05-31 06:09:04 UTC (rev 176)
@@ -0,0 +1,70 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.method.builder;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+import org.punit.method.*;
+import org.punit.type.*;
+
+/**
+ * This class is the basic implementation for <code>TestMethodBuilder</code>
+ * interface.
+ *
+ */
+public class MethodBuilderImpl implements TestMethodBuilder {
+
+ private MethodFilter _filter;
+
+ public void setMethodFilter(MethodFilter filter) {
+ _filter = filter;
+ }
+
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @param method
+ * @return
+ */
+ protected boolean isTestMethod(Method method) {
+ return _filter.isTestMethod(method);
+ }
+
+ /**
+ * @see TestMethodBuilder#buildTestMethods(Class)
+ */
+ public Collection buildTestMethods(Class testClass) {
+ Collection testMethods = null;
+ if (isAlphabetical(testClass)) {
+ testMethods = new TreeSet(new AlphabeticalMethodNameComparator());
+ } else {
+ testMethods = new ArrayList();
+ }
+ Class clazz = testClass;
+ while (clazz != Object.class) {
+ Method[] methods = clazz.getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ Method method = methods[i];
+ if (isTestMethod(method)) {
+ testMethods.add(method);
+ }
+ }
+ clazz = clazz.getSuperclass();
+ }
+ return testMethods;
+ }
+
+ private boolean isAlphabetical(Class testClass) {
+ return Alphabetical.class.isAssignableFrom(testClass);
+ }
+
+ private static class AlphabeticalMethodNameComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ Method m1 = (Method) o1;
+ Method m2 = (Method) o2;
+ return m1.getName().compareTo(m2.getName());
+ }
+ }
+
+}
Deleted: trunk/punit/src/org/punit/method/builder/PUnitAbstractTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/method/PUnitAbstractTestMethodBuilder.java 2007-05-24 16:29:25 UTC (rev 154)
+++ trunk/punit/src/org/punit/method/builder/PUnitAbstractTestMethodBuilder.java 2007-05-31 06:09:04 UTC (rev 176)
@@ -1,80 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.builder.method;
-
-import java.lang.reflect.*;
-import java.util.*;
-
-import org.punit.type.*;
-
-/**
- * This class is the basic implementation for <code>TestMethodBuilder</code>
- * interface.
- *
- */
-public abstract class PUnitAbstractTestMethodBuilder implements
- TestMethodBuilder {
-
- protected final HashSet _testMethodNames = new HashSet();
-
- /**
- * Judges whether this method is a test method.
- *
- * @param method
- * @return
- */
- protected abstract boolean isTestMethod(Method method);
-
- /**
- * @see TestMethodBuilder#buildTestMethods(Class)
- */
- public Collection buildTestMethods(Class testClass) {
- Collection testMethods = null;
- if (isAlphabetical(testClass)) {
- testMethods = new TreeSet(
- new AlphabeticalMethodNameComparator());
- } else {
- testMethods = new ArrayList();
- }
- Class clazz = testClass;
- while (clazz != Object.class) {
- Method[] methods = clazz.getDeclaredMethods();
- for (int i = 0; i < methods.length; ++i) {
- Method method = methods[i];
- if (isTestMethod(method)) {
- testMethods.add(method);
- }
- }
- clazz = clazz.getSuperclass();
- }
- return testMethods;
- }
-
- private boolean isAlphabetical(Class testClass) {
- return Alphabetical.class.isAssignableFrom(testClass);
- }
-
- private static class AlphabeticalMethodNameComparator implements Comparator {
- public int compare(Object o1, Object o2) {
- Method m1 = (Method) o1;
- Method m2 = (Method) o2;
- return m1.getName().compareTo(m2.getName());
- }
- }
-
- /**
- * @see TestMethodBuilder#addTestInterfaces(Class[])
- */
- public void addTestInterfaces(Class[] classes) {
- for (int i = 0; i < classes.length; ++i) {
- addTestInterface(classes[i]);
- }
- }
-
- private void addTestInterface(Class testInterface) {
- Method[] methods = testInterface.getDeclaredMethods();
- for (int i = 0; i < methods.length; ++i) {
- _testMethodNames.add(methods[i].getName());
- }
- }
-}
Deleted: trunk/punit/src/org/punit/method/builder/PUnitTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/method/PUnitTestMethodBuilder.java 2007-05-24 16:29:25 UTC (rev 154)
+++ trunk/punit/src/org/punit/method/builder/PUnitTestMethodBuilder.java 2007-05-31 06:09:04 UTC (rev 176)
@@ -1,78 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.builder.method;
-
-import java.lang.reflect.*;
-
-import org.punit.type.*;
-import org.punit.util.*;
-
-/**
- * The default test method builder of punit.
- *
- */
-public class PUnitTestMethodBuilder extends PUnitAbstractTestMethodBuilder {
-
- private static final long serialVersionUID = -6490270178427969475L;
-
- /**
- * Judges whether this method is a test method.
- *
- * @return returns true if the test modifier, name, and parameter conform to
- * the convention of a test method.
- */
- protected boolean isTestMethod(Method method) {
- return isModifierValid(method) && isNameValid(method)
- && isParamValid(method);
- }
-
- /**
- * Judeges whether the modifier of is method conforms to the convention of a
- * test method.
- *
- * @param method
- * to be judged
- * @return returns true if this method is public and non static.
- */
- protected boolean isModifierValid(Method method) {
- return ReflectionUtil.isPublic(method)
- && !ReflectionUtil.isStatic(method);
- }
-
- /**
- * Judeges whether the name of is method conforms to the convention of a
- * test method.
- *
- * @param method
- * to be judged
- * @return returns true if the name of this method starts with "test", or
- * the name is in the list of test interfaces which are added by
- * <code>TestMethodBuilder.addTestInterfaces</code>
- */
- protected boolean isNameValid(Method method) {
- String name = method.getName();
- return name.startsWith("test") || _testMethodNames.contains(name); //$NON-NLS-1$
- }
-
- /**
- * Judges whether the paramaters of this method conforms to the convention
- * of a test method.
- *
- * @param method
- * @return returns true if the parameter length is zero and the test class
- * is not marked as <code>Parameterizable</code>, or the
- * parameter length is 1, and the parameter is assignable from
- * <code>Parameter</code>.
- */
- protected boolean isParamValid(Method method) {
- Class clazz = method.getDeclaringClass();
- Class[] params = method.getParameterTypes();
- if (TypeUtil.isPUnitParameterizableTest((clazz))) {
- return params.length == 1
- && Parameter.class.isAssignableFrom(params[0]);
- } else {
- return params.length == 0;
- }
- }
-
-}
Deleted: trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/method/TestMethodBuilder.java 2007-05-24 16:29:25 UTC (rev 154)
+++ trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-05-31 06:09:04 UTC (rev 176)
@@ -1,33 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.builder.method;
-
-import java.io.*;
-import java.util.*;
-
-/**
- * Interface for test method builder. The method builder builds a list of
- * methods, which will be executed by the method runner.
- */
-public interface TestMethodBuilder extends Serializable {
- /**
- * Builds the test methods from the test class. Returns a list of methods.
- * The real return type should be Method[]. It returns Object[] for java 1.4
- * compatibility.
- *
- * @param clazz -
- * the test class to be built
- * @return a <code>Collection</code> of <code>java.lang.reflect.Method</code>.
- */
- public Collection buildTestMethods(Class testClass);
-
- /**
- * Adds test classes into the builder. TestMethodBuilder may use it to
- * judege whether a method is a test method.
- *
- * @param interfaces -
- * an array of test classes to be added.
- * @see PUnitTestMethodBuilder#isNameValid(java.lang.reflect.Method);
- */
- public void addTestInterfaces(Class[] interfaces);
-}
Copied: trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java (from rev 175, trunk/punit/src/org/punit/builder/method/TestMethodBuilder.java)
===================================================================
--- trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java (rev 0)
+++ trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-05-31 06:09:04 UTC (rev 176)
@@ -0,0 +1,29 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.method.builder;
+
+import java.io.*;
+import java.util.*;
+
+import org.punit.method.*;
+import org.punit.type.*;
+
+/**
+ * Interface for test method builder. The method builder builds a list of
+ * methods, which will be executed by the method runner.
+ */
+public interface TestMethodBuilder extends Serializable {
+ /**
+ * Builds the test methods from the test class. Returns a list of methods.
+ * The real return type should be Method[]. It returns Object[] for java 1.4
+ * compatibility.
+ *
+ * @param clazz -
+ * the test class to be built
+ * @return a <code>Collection</code> of <code>java.lang.reflect.Method</code>.
+ */
+ public Collection buildTestMethods(Class testClass);
+
+
+ public void setMethodFilter(MethodFilter filter);
+}
Copied: trunk/punit/src/org/punit/method/runner (from rev 154, trunk/punit/src/org/punit/runner/method)
Copied: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java (from rev 175, trunk/punit/src/org/punit/runner/method/AbstractMethodRunner.java)
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-05-31 06:09:04 UTC (rev 176)
@@ -0,0 +1,329 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.method.runner;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+import org.punit.assertion.*;
+import org.punit.events.*;
+import org.punit.exception.*;
+import org.punit.method.*;
+import org.punit.runner.*;
+import org.punit.type.*;
+import org.punit.util.*;
+import org.punit.watcher.*;
+
+public abstract class AbstractMethodRunner implements MethodRunner {
+
+ protected ArrayList _watchers = new ArrayList(); // <Watcher>
+
+ private TimeWatcher _timeWatcher = new TimeWatcher();
+
+ private List _eventListeners; // List <PUnitEventListener>
+
+ private RunnerProperties _runnerProperties;
+
+ protected MethodFilter _filter;
+
+ protected transient Object _testInstance;
+
+ protected transient Method _method;
+
+ protected transient Object[] _params;
+
+ protected transient Class _class;
+
+ protected transient Method _tearDownMethod;
+
+ protected transient Method _setUpMethod;
+
+ private transient Method _checkMethod;
+
+ protected transient Class _expectedException;
+
+ public AbstractMethodRunner() {
+ _watchers.add(_timeWatcher);
+ }
+
+ public void setEventListeners(List eventListeners) {
+ _eventListeners = eventListeners;
+ }
+
+ public void setRunnerProperties(RunnerProperties props) {
+ _runnerProperties = props;
+ }
+
+ public void addWatcher(Watcher watcher) {
+ _watchers.add(watcher);
+ }
+
+ public void removeWatcher(Watcher watcher) {
+ _watchers.remove(watcher);
+ }
+
+ public void removeTimeWatcher() {
+ _watchers.remove(_timeWatcher);
+ }
+
+ public void run(Object testInstance, Method method, Object[] params) {
+ onMethodStart(method, testInstance, params);
+ Throwable throwable = null;
+ try {
+ if (needsRunMethod()) {
+ init(testInstance, method, params);
+ setUpBeforeWatchers(params);
+ startWatchers(testInstance, method, params);
+ setUpAfterWatchers(params);
+ runImpl();
+ runCheckMethod(testInstance, params);
+ } else {
+ startWatchers(testInstance, method, params);
+ }
+ } catch (Throwable t) {
+ throwable = t;
+ } finally {
+ try {
+ if (needsRunMethod()) {
+ tearDownBeforeWatchers(params);
+ }
+ } catch (Throwable t) {
+ throwable = t;
+ } finally {
+ try {
+ stopWatchers(testInstance, method, params);
+ if (needsRunMethod()) {
+ tearDownAfterWatchers(params);
+ }
+ } catch (Throwable t) {
+ throwable = t;
+ }
+ }
+ }
+ onMethodEnd(method, testInstance, params, throwable);
+ }
+
+ private void runCheckMethod(Object testInstance, Object[] params) {
+ if(_checkMethod != null) {
+ ReflectionUtil.invokeMethod(_checkMethod, testInstance, params);
+ }
+ }
+
+ private void onMethodStart(final Method method, final Object testInstance,
+ final Object[] params) {
+ TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ ((PUnitEventListener) obj).onMethodStart(method, testInstance,
+ params);
+ }
+ });
+ }
+
+ private void onMethodEnd(final Method method, final Object testInstance,
+ 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);
+ }
+ });
+ }
+
+ protected abstract void runImpl() throws Throwable;
+
+ protected final void init(Object testInstance, Method method,
+ Object[] params) {
+ _testInstance = testInstance;
+ _class = testInstance.getClass();
+ _params = params;
+ _method = method;
+ _setUpMethod = ReflectionUtil.getMethodAndSetAccessible(_testInstance
+ .getClass(), "setUp", new Class[] {}); //$NON-NLS-1$
+ _tearDownMethod = ReflectionUtil.getMethodAndSetAccessible(
+ _testInstance.getClass(), "tearDown", new Class[] {}); //$NON-NLS-1$
+ _checkMethod = _filter.getCheckMethod(method);
+ _expectedException = _filter.getExpectedException(method);
+ }
+
+ /**
+ * This method might be overriden by subclass. The runner may do some more
+ * things during this step.
+ *
+ */
+ protected void setUpBeforeWatchers(Object[] params) throws Throwable {
+ if (TypeUtil.isPUnitTest(_class)) {
+ ((PUnitTest) _testInstance).setUpBeforeWatchers();
+ } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
+ ((Parameterizable) _testInstance)
+ .setUpBeforeWatchers((Parameter) params[0]);
+ }
+ }
+
+ private void setUpAfterWatchers(Object[] params) throws Throwable {
+ if (TypeUtil.isPUnitTest(_class)) {
+ ((PUnitTest) _testInstance).setUpAfterWatchers();
+ } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
+ ((Parameterizable) _testInstance)
+ .setUpAfterWatchers((Parameter) params[0]);
+ } else {
+ setUp();
+ }
+ }
+
+ private void tearDownBeforeWatchers(Object[] params) throws Throwable {
+ if (TypeUtil.isPUnitTest(_class)) {
+ ((PUnitTest) _testInstance).tearDownBeforeWatchers();
+ } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
+ ((Parameterizable) _testInstance)
+ .tearDownBeforeWatchers((Parameter) params[0]);
+ } else {
+ tearDown();
+ }
+ }
+
+ private void tearDownAfterWatchers(Object[] params) throws Throwable {
+ if (TypeUtil.isPUnitTest(_class)) {
+ ((PUnitTest) _testInstance).tearDownAfterWatchers();
+ } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
+ ((Parameterizable) _testInstance)
+ .tearDownAfterWatchers((Parameter) params[0]);
+ }
+ }
+
+ private void setUp() throws Throwable {
+ if (_setUpMethod != null) {
+ try {
+ ReflectionUtil.invokeMethod(_setUpMethod, _testInstance,
+ new Object[] {});
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+ }
+
+ private void tearDown() throws Throwable {
+ if (_tearDownMethod != null) {
+ try {
+ ReflectionUtil.invokeMethod(_tearDownMethod, _testInstance,
+ new Object[] {});
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+ }
+
+ protected final void startWatchers(final Object testInstance,
+ final Method method, final Object[] params) {
+ onWatchersStart(testInstance, method, params);
+ TraverserUtil.traverse(_watchers.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ Watcher watcher = (Watcher) obj;
+ onWatcherStart(watcher, testInstance, method, params);
+ watcher.start();
+ }
+ });
+ }
+
+ private void onWatchersStart(final Object testInstance,
+ final Method method, final Object[] params) {
+ TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ ((PUnitEventListener) obj).onWatchersStart(_watchers);
+ }
+ });
+ }
+
+ private void onWatcherStart(final Watcher watcher,
+ final Object testInstance, final Method method,
+ final Object[] params) {
+ TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ ((PUnitEventListener) obj).onWatcherStart(watcher);
+ }
+ });
+ }
+
+ protected final void stopWatchers(final Object testInstance,
+ final Method method, final Object[] params) {
+ TraverserUtil.traverse(_watchers.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ Watcher watcher = (Watcher) obj;
+ watcher.stop();
+ onWatcherEnd(watcher, testInstance, method, params);
+ }
+ });
+ onWatchersEnd(testInstance, method, params);
+ }
+
+ private void onWatcherEnd(final Watcher watcher, final Object testInstance,
+ final Method method, final Object[] params) {
+ TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ ((PUnitEventListener) obj).onWatcherEnd(watcher);
+ }
+ });
+ }
+
+ private void onWatchersEnd(final Object testInstance, final Method method,
+ final Object[] params) {
+ TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ ((PUnitEventListener) obj).onWatchersEnd(_watchers);
+ }
+ });
+ }
+
+ private List eventListeners() {
+ return _eventListeners;
+ }
+
+ public List watchers() {
+ return _watchers;
+ }
+
+ public boolean needsRunMethod() {
+ return !_runnerProperties.isParent;
+ }
+
+ public Object clone() {
+ try {
+ final AbstractMethodRunner methodRunner = (AbstractMethodRunner) super
+ .clone();
+ methodRunner._watchers = (ArrayList) _watchers.clone();
+ methodRunner._watchers.clear();
+ TraverserUtil.traverse(_watchers.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ Watcher watcher = (Watcher) obj;
+ methodRunner.addWatcher(watcher.cloneSelf());
+ }
+ });
+ return methodRunner;
+ } catch (CloneNotSupportedException e) {
+ throw new ReflectionException(e);
+ }
+ }
+
+ public void setMethodFilter(MethodFilter filter) {
+ _filter = filter;
+ }
+
+ protected void runMethod() throws Throwable {
+ if (_expectedException == null) {
+ invokeMethod();
+ } else {
+ Assert.assertException(_expectedException, new CodeRunner() {
+ public void run() throws Throwable {
+ invokeMethod();
+ }
+ });
+ }
+ }
+
+ private void invokeMethod() throws Throwable {
+ try {
+ ReflectionUtil.invokeMethod(_method, _testInstance, _params);
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+}
Deleted: trunk/punit/src/org/punit/method/runner/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-24 16:29:25 UTC (rev 154)
+++ trunk/punit/src/org/punit/method/runner/AbstractTestMethodRunner.java 2007-05-31 06:09:04 UTC (rev 176)
@@ -1,252 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.runner.method;
-
-import java.lang.reflect.*;
-import java.util.*;
-
-import org.punit.events.*;
-import org.punit.exception.*;
-import org.punit.runner.*;
-import org.punit.type.*;
-import org.punit.util.*;
-import org.punit.watcher.*;
-
-public abstract class AbstractTestMethodRunner implements TestMethodRunner {
-
- protected List _watchers = new ArrayList(); // <Watcher>
-
- private Runner _runner;
-
- private MemoryWatcher _memoryWatcher = new MemoryWatcher();
-
- private TimeWatcher _timeWatcher = new TimeWatcher();
-
- protected transient Object _testInstance;
-
- protected transient Method _method;
-
- protected transient Object[] _params;
-
- protected transient Class _class;
-
- protected transient Method _tearDownMethod;
-
- protected transient Method _setUpMethod;
-
- public AbstractTestMethodRunner() {
- _watchers.add(_memoryWatcher);
- _watchers.add(_timeWatcher);
- }
-
- public void addWatcher(Watcher watcher) {
- _watchers.add(watcher);
- }
-
- public void removeWatcher(Watcher watcher) {
- _watchers.remove(watcher);
- }
-
- public void removeTimeWatcher() {
- _watchers.remove(_timeWatcher);
- }
-
- public void removeMemoryWatcher() {
- _watchers.remove(_memoryWatcher);
- }
-
- public void setRunner(Runner runner) {
- _runner = runner;
- }
-
- public void run(Object testInstance, Method method, Object[] params) {
- Throwable throwable = null;
- try {
- onMethodStart(method, testInstance, params);
- init(testInstance, method, params);
- setUpBeforeWatchers(params);
- startWatchers(testInstance, method, params);
- setUpAfterWatchers(params);
- if(isParentRunner()) {
- return;
- }
- runImpl();
- } catch (Throwable t) {
- throwable = t;
- } finally {
- try {
- tearDownBeforeWatchers(params);
- } catch (Throwable t) {
- throwable = t;
- } finally {
- try {
- stopWatchers(testInstance, method, params);
- tearDownAfterWatchers(params);
- } catch (Throwable t) {
- throwable = t;
- }
- }
- onMethodEnd(method, testInstance, params, throwable);
- }
- }
-
- private boolean isParentRunner() {
- return _runner.properties().isParent;
- }
-
- private void onMethodStart(final Method method, final Object testInstance, final Object[] params) {
- TraverserUtil.traverse(runnerEventListeners().iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((PUnitEventListener) obj).onMethodStart(method, testInstance, params);
- }
- });
- }
-
- private void onMethodEnd(final Method method, final Object testInstance, final Object[...
[truncated message content] |
|
From: <zha...@us...> - 2007-05-31 06:20:46
|
Revision: 180
http://p-unit.svn.sourceforge.net/p-unit/?rev=180&view=rev
Author: zhanghuangzhu
Date: 2007-05-30 23:20:45 -0700 (Wed, 30 May 2007)
Log Message:
-----------
Andrew Zhang: removed some warnings.
Modified Paths:
--------------
trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
trunk/punit/src/org/punit/method/runner/MethodRunner.java
trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java
trunk/punit.samples/src/samples/ParamTestClass.java
Modified: trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-05-31 06:19:08 UTC (rev 179)
+++ trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-05-31 06:20:45 UTC (rev 180)
@@ -6,7 +6,6 @@
import java.util.*;
import org.punit.method.*;
-import org.punit.type.*;
/**
* Interface for test method builder. The method builder builds a list of
Modified: trunk/punit/src/org/punit/method/runner/MethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/MethodRunner.java 2007-05-31 06:19:08 UTC (rev 179)
+++ trunk/punit/src/org/punit/method/runner/MethodRunner.java 2007-05-31 06:20:45 UTC (rev 180)
@@ -6,7 +6,6 @@
import org.punit.method.*;
import org.punit.runner.*;
-import org.punit.type.*;
import org.punit.watcher.*;
public interface MethodRunner extends Serializable, Cloneable {
Modified: trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java 2007-05-31 06:19:08 UTC (rev 179)
+++ trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java 2007-05-31 06:20:45 UTC (rev 180)
@@ -4,9 +4,6 @@
import org.punit.annotation.*;
import org.punit.annotation.Test.*;
-import org.punit.method.*;
-import org.punit.runner.*;
-import org.punit.type.*;
import org.punit.util.*;
public class AnnotationMethodFilter implements MethodFilter {
Modified: trunk/punit.samples/src/samples/ParamTestClass.java
===================================================================
--- trunk/punit.samples/src/samples/ParamTestClass.java 2007-05-31 06:19:08 UTC (rev 179)
+++ trunk/punit.samples/src/samples/ParamTestClass.java 2007-05-31 06:20:45 UTC (rev 180)
@@ -14,17 +14,17 @@
}
public void testA(ParameterImpl param) {
- System.out.println("testA count = " + param.count());
+ System.out.println("testA count = " + param.count()); //$NON-NLS-1$
SampleUtil.doSomething();
}
public void testB(ParameterImpl param) {
- System.out.println("testB count = " + param.count());
+ System.out.println("testB count = " + param.count()); //$NON-NLS-1$
SampleUtil.doSomething();
}
public void testC(ParameterImpl param) {
- System.out.println("testB count = " + param.count());
+ System.out.println("testB count = " + param.count()); //$NON-NLS-1$
SampleUtil.doSomething();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-31 11:49:31
|
Revision: 183
http://p-unit.svn.sourceforge.net/p-unit/?rev=183&view=rev
Author: zhanghuangzhu
Date: 2007-05-31 04:49:33 -0700 (Thu, 31 May 2007)
Log Message:
-----------
Andrew Zhang: refactored PUnitTestSuite#suite to testSuite to avoid the conflict with JUnit.
Modified Paths:
--------------
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
trunk/punit/src/org/punit/type/PUnitTestSuite.java
trunk/punit.samples/src/samples/AllTestSuite.java
trunk/punit.samples/src/samples/LongTimeExecutionPUnitTestSuite.java
trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-05-31 07:41:56 UTC (rev 182)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-05-31 11:49:33 UTC (rev 183)
@@ -31,7 +31,7 @@
private void buildTestClassFromTestSuite(List testClasses, Class clazz) {
PUnitTestSuite testSuite = (PUnitTestSuite) ReflectionUtil.newInstance(clazz);
testClasses.add(new TestSuiteLabelImpl(testSuite, true));
- Class[] suite = testSuite.suite();
+ Class[] suite = testSuite.testSuite();
for(int i = 0; i < suite.length; ++i) {
buildTestClasses(testClasses, suite[i]);
}
Modified: trunk/punit/src/org/punit/type/PUnitTestSuite.java
===================================================================
--- trunk/punit/src/org/punit/type/PUnitTestSuite.java 2007-05-31 07:41:56 UTC (rev 182)
+++ trunk/punit/src/org/punit/type/PUnitTestSuite.java 2007-05-31 11:49:33 UTC (rev 183)
@@ -13,5 +13,5 @@
*
* @return
*/
- public Class[] suite();
+ public Class[] testSuite();
}
Modified: trunk/punit.samples/src/samples/AllTestSuite.java
===================================================================
--- trunk/punit.samples/src/samples/AllTestSuite.java 2007-05-31 07:41:56 UTC (rev 182)
+++ trunk/punit.samples/src/samples/AllTestSuite.java 2007-05-31 11:49:33 UTC (rev 183)
@@ -6,7 +6,7 @@
public class AllTestSuite implements PUnitTestSuite {
- public Class[] suite() {
+ public Class[] testSuite() {
return new Class[] {
JUnitTestClass.class,
SimpleTestClass.class,
Modified: trunk/punit.samples/src/samples/LongTimeExecutionPUnitTestSuite.java
===================================================================
--- trunk/punit.samples/src/samples/LongTimeExecutionPUnitTestSuite.java 2007-05-31 07:41:56 UTC (rev 182)
+++ trunk/punit.samples/src/samples/LongTimeExecutionPUnitTestSuite.java 2007-05-31 11:49:33 UTC (rev 183)
@@ -4,7 +4,7 @@
public class LongTimeExecutionPUnitTestSuite implements PUnitTestSuite{
- public Class[] suite() {
+ public Class[] testSuite() {
return LongTimeExecutionJUnitTestSuite.testCases();
}
Modified: trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java 2007-05-31 07:41:56 UTC (rev 182)
+++ trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java 2007-05-31 11:49:33 UTC (rev 183)
@@ -9,7 +9,7 @@
new SoloRunner().run(PUnitAllTests.class);
}
- public Class[] suite() {
+ public Class[] testSuite() {
return AllTests.testCases();
}
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java 2007-05-31 07:41:56 UTC (rev 182)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java 2007-05-31 11:49:33 UTC (rev 183)
@@ -1,6 +1,6 @@
package tests.api.org.punit.testclasses;
public class TestSuite1 implements org.punit.type.PUnitTestSuite {
- public Class[] suite() {
+ public Class[] testSuite() {
return new Class[] { TestClass1.class, TestClass2.class, TestClass3.class,
};
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java 2007-05-31 07:41:56 UTC (rev 182)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java 2007-05-31 11:49:33 UTC (rev 183)
@@ -1,7 +1,7 @@
package tests.api.org.punit.testclasses;
public class TestSuite2 implements org.punit.type.PUnitTestSuite {
- public Class[] suite() {
+ public Class[] testSuite() {
return new Class[] { TestClass4.class, TestSuite1.class,
TestClass5.class,
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java 2007-05-31 07:41:56 UTC (rev 182)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java 2007-05-31 11:49:33 UTC (rev 183)
@@ -4,7 +4,7 @@
public class TestSuiteClass implements PUnitTestSuite {
- public Class[] suite() {
+ public Class[] testSuite() {
return new Class[] {
TestClass.class,
PUnitTestClass.class,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-06-02 21:27:33
|
Revision: 186
http://p-unit.svn.sourceforge.net/p-unit/?rev=186&view=rev
Author: zhanghuangzhu
Date: 2007-06-02 14:27:35 -0700 (Sat, 02 Jun 2007)
Log Message:
-----------
Andrew Zhang: Removed warning and refactored class name.
Modified Paths:
--------------
trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java
trunk/punit.test/src/tests/api/org/punit/method/builder/MethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/method/builder/PUnitTestMethodBuilderTest.java
Added Paths:
-----------
trunk/punit/src/org/punit/method/NameMethodFilter.java
Removed Paths:
-------------
trunk/punit/src/org/punit/method/ByNameMethodFilter.java
Deleted: trunk/punit/src/org/punit/method/ByNameMethodFilter.java
===================================================================
--- trunk/punit/src/org/punit/method/ByNameMethodFilter.java 2007-06-01 13:16:32 UTC (rev 185)
+++ trunk/punit/src/org/punit/method/ByNameMethodFilter.java 2007-06-02 21:27:35 UTC (rev 186)
@@ -1,79 +0,0 @@
-package org.punit.method;
-
-import java.lang.reflect.*;
-
-import org.punit.type.*;
-import org.punit.util.*;
-
-public class ByNameMethodFilter implements MethodFilter {
-
- public Method getCheckMethod(Method method) {
- String checkMethodName = "check_" + method.getName(); //$NON-NLS-1$
- return ReflectionUtil.getMethod(method.getDeclaringClass(),
- checkMethodName, method.getParameterTypes());
- }
-
- /**
- * Judges whether this method is a test method.
- *
- * @return returns true if the test modifier, name, and parameter conform to
- * the convention of a test method.
- */
- public boolean isTestMethod(Method method) {
- return isModifierValid(method) && isNameValid(method)
- && isParamValid(method);
- }
-
- /**
- * Judeges whether the modifier of is method conforms to the convention of a
- * test method.
- *
- * @param method
- * to be judged
- * @return returns true if this method is public and non static.
- */
- protected boolean isModifierValid(Method method) {
- return ReflectionUtil.isPublic(method)
- && !ReflectionUtil.isStatic(method);
- }
-
- /**
- * Judeges whether the name of is method conforms to the convention of a
- * test method.
- *
- * @param method
- * to be judged
- * @return returns true if the name of this method starts with "test", or
- * the name is in the list of test interfaces which are added by
- * <code>TestMethodBuilder.addTestInterfaces</code>
- */
- protected boolean isNameValid(Method method) {
- String name = method.getName();
- return name.startsWith("test"); //$NON-NLS-1$
- }
-
- /**
- * Judges whether the paramaters of this method conforms to the convention
- * of a test method.
- *
- * @param method
- * @return returns true if the parameter length is zero and the test class
- * is not marked as <code>Parameterizable</code>, or the
- * parameter length is 1, and the parameter is assignable from
- * <code>Parameter</code>.
- */
- protected boolean isParamValid(Method method) {
- Class clazz = method.getDeclaringClass();
- Class[] params = method.getParameterTypes();
- if (TypeUtil.isPUnitParameterizableTest((clazz))) {
- return params.length == 1
- && Parameter.class.isAssignableFrom(params[0]);
- } else {
- return params.length == 0;
- }
- }
-
- public Class getExpectedException(Method method) {
- return null;
- }
-}
Copied: trunk/punit/src/org/punit/method/NameMethodFilter.java (from rev 176, trunk/punit/src/org/punit/method/ByNameMethodFilter.java)
===================================================================
--- trunk/punit/src/org/punit/method/NameMethodFilter.java (rev 0)
+++ trunk/punit/src/org/punit/method/NameMethodFilter.java 2007-06-02 21:27:35 UTC (rev 186)
@@ -0,0 +1,81 @@
+package org.punit.method;
+
+import java.lang.reflect.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class NameMethodFilter implements MethodFilter {
+
+ private static final long serialVersionUID = -1252188754463864599L;
+
+ public Method getCheckMethod(Method method) {
+ String checkMethodName = "check_" + method.getName(); //$NON-NLS-1$
+ return ReflectionUtil.getMethod(method.getDeclaringClass(),
+ checkMethodName, method.getParameterTypes());
+ }
+
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @return returns true if the test modifier, name, and parameter conform to
+ * the convention of a test method.
+ */
+ public boolean isTestMethod(Method method) {
+ return isModifierValid(method) && isNameValid(method)
+ && isParamValid(method);
+ }
+
+ /**
+ * Judeges whether the modifier of is method conforms to the convention of a
+ * test method.
+ *
+ * @param method
+ * to be judged
+ * @return returns true if this method is public and non static.
+ */
+ protected boolean isModifierValid(Method method) {
+ return ReflectionUtil.isPublic(method)
+ && !ReflectionUtil.isStatic(method);
+ }
+
+ /**
+ * Judeges whether the name of is method conforms to the convention of a
+ * test method.
+ *
+ * @param method
+ * to be judged
+ * @return returns true if the name of this method starts with "test", or
+ * the name is in the list of test interfaces which are added by
+ * <code>TestMethodBuilder.addTestInterfaces</code>
+ */
+ protected boolean isNameValid(Method method) {
+ String name = method.getName();
+ return name.startsWith("test"); //$NON-NLS-1$
+ }
+
+ /**
+ * Judges whether the paramaters of this method conforms to the convention
+ * of a test method.
+ *
+ * @param method
+ * @return returns true if the parameter length is zero and the test class
+ * is not marked as <code>Parameterizable</code>, or the
+ * parameter length is 1, and the parameter is assignable from
+ * <code>Parameter</code>.
+ */
+ protected boolean isParamValid(Method method) {
+ Class clazz = method.getDeclaringClass();
+ Class[] params = method.getParameterTypes();
+ if (TypeUtil.isPUnitParameterizableTest((clazz))) {
+ return params.length == 1
+ && Parameter.class.isAssignableFrom(params[0]);
+ } else {
+ return params.length == 0;
+ }
+ }
+
+ public Class getExpectedException(Method method) {
+ return null;
+ }
+}
Modified: trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-06-01 13:16:32 UTC (rev 185)
+++ trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-06-02 21:27:35 UTC (rev 186)
@@ -15,6 +15,8 @@
*/
public class MethodBuilderImpl implements TestMethodBuilder {
+ private static final long serialVersionUID = -6593981780599574964L;
+
private MethodFilter _filter;
public void setMethodFilter(MethodFilter filter) {
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-01 13:16:32 UTC (rev 185)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-02 21:27:35 UTC (rev 186)
@@ -41,7 +41,7 @@
_methodRunner.setEventListeners(_eventListeners);
_methodRunner.setRunnerProperties(_properties);
registerLoggerListeners();
- setMethodFilter(new ByNameMethodFilter());
+ setMethodFilter(new NameMethodFilter());
}
public void setMethodFilter(MethodFilter filter) {
Modified: trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java 2007-06-01 13:16:32 UTC (rev 185)
+++ trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java 2007-06-02 21:27:35 UTC (rev 186)
@@ -8,7 +8,9 @@
public class AnnotationMethodFilter implements MethodFilter {
- ByNameMethodFilter _delegate = new ByNameMethodFilter();
+ private static final long serialVersionUID = -2043378593194849589L;
+
+ NameMethodFilter _delegate = new NameMethodFilter();
public Method getCheckMethod(Method method) {
Test testAnnotation = method.getAnnotation(Test.class);
Modified: trunk/punit.test/src/tests/api/org/punit/method/builder/MethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/builder/MethodBuilderTest.java 2007-06-01 13:16:32 UTC (rev 185)
+++ trunk/punit.test/src/tests/api/org/punit/method/builder/MethodBuilderTest.java 2007-06-02 21:27:35 UTC (rev 186)
@@ -15,7 +15,7 @@
public void setUp() {
_builder = new MethodBuilderImpl();
- _builder.setMethodFilter(new ByNameMethodFilter());
+ _builder.setMethodFilter(new NameMethodFilter());
}
public void testAddInterfaces() {
Modified: trunk/punit.test/src/tests/api/org/punit/method/builder/PUnitTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/builder/PUnitTestMethodBuilderTest.java 2007-06-01 13:16:32 UTC (rev 185)
+++ trunk/punit.test/src/tests/api/org/punit/method/builder/PUnitTestMethodBuilderTest.java 2007-06-02 21:27:35 UTC (rev 186)
@@ -12,7 +12,7 @@
protected void setUp() throws Exception {
_builder = new MethodBuilderImpl();
- _builder.setMethodFilter(new ByNameMethodFilter());
+ _builder.setMethodFilter(new NameMethodFilter());
}
public void testBuildTestMethods1() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-06-04 06:31:39
|
Revision: 191
http://p-unit.svn.sourceforge.net/p-unit/?rev=191&view=rev
Author: zhanghuangzhu
Date: 2007-06-03 23:31:40 -0700 (Sun, 03 Jun 2007)
Log Message:
-----------
Andrew Zhang: refactored name.
Modified Paths:
--------------
trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
trunk/punit/src/org/punit/method/runner/MethodRunner.java
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
trunk/punit.test/src/tests/api/org/punit/method/AnnotationMethodFilterTest.java
trunk/punit.test/src/tests/api/org/punit/method/ByNameMethodFilterTest.java
trunk/punit.test/src/tests/api/org/punit/method/builder/MethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/method/builder/PUnitTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
Added Paths:
-----------
trunk/punit/src/org/punit/method/Filter.java
trunk/punit/src/org/punit/method/NameConventionFilter.java
trunk/punit.extension/src/org/punit/method/AnnotationFilter.java
Removed Paths:
-------------
trunk/punit/src/org/punit/method/MethodFilter.java
trunk/punit/src/org/punit/method/NameMethodFilter.java
trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java
Copied: trunk/punit/src/org/punit/method/Filter.java (from rev 190, trunk/punit/src/org/punit/method/MethodFilter.java)
===================================================================
--- trunk/punit/src/org/punit/method/Filter.java (rev 0)
+++ trunk/punit/src/org/punit/method/Filter.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -0,0 +1,34 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.method;
+
+import java.io.*;
+import java.lang.reflect.*;
+
+public interface Filter extends Serializable {
+
+ /**
+ * Judges whether this test class is excluded.
+ *
+ * @return returns true if the test class is excluded.
+ */
+ public boolean isExcluded(Class clazz);
+
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @return returns true if it is a test method.
+ */
+ public boolean isTestMethod(Method method);
+
+ /**
+ * Gets the corresponding check method to this test method
+ *
+ * @param method
+ * the test method
+ * @return
+ */
+ public Method getCheckMethod(Method method);
+
+ public Class getExpectedException(Method method);
+}
Deleted: trunk/punit/src/org/punit/method/MethodFilter.java
===================================================================
--- trunk/punit/src/org/punit/method/MethodFilter.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit/src/org/punit/method/MethodFilter.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -1,34 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.method;
-
-import java.io.*;
-import java.lang.reflect.*;
-
-public interface MethodFilter extends Serializable {
-
- /**
- * Judges whether this test class is excluded.
- *
- * @return returns true if the test class is excluded.
- */
- public boolean isExcluded(Class clazz);
-
- /**
- * Judges whether this method is a test method.
- *
- * @return returns true if it is a test method.
- */
- public boolean isTestMethod(Method method);
-
- /**
- * Gets the corresponding check method to this test method
- *
- * @param method
- * the test method
- * @return
- */
- public Method getCheckMethod(Method method);
-
- public Class getExpectedException(Method method);
-}
Copied: trunk/punit/src/org/punit/method/NameConventionFilter.java (from rev 190, trunk/punit/src/org/punit/method/NameMethodFilter.java)
===================================================================
--- trunk/punit/src/org/punit/method/NameConventionFilter.java (rev 0)
+++ trunk/punit/src/org/punit/method/NameConventionFilter.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -0,0 +1,87 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.method;
+
+import java.lang.reflect.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class NameConventionFilter implements Filter {
+
+ private static final long serialVersionUID = -1252188754463864599L;
+
+ public boolean isExcluded(Class method) {
+ return false;
+ }
+
+ public Method getCheckMethod(Method method) {
+ String checkMethodName = "check_" + method.getName(); //$NON-NLS-1$
+ return ReflectionUtil.getMethod(method.getDeclaringClass(),
+ checkMethodName, method.getParameterTypes());
+ }
+
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @return returns true if the test modifier, name, and parameter conform to
+ * the convention of a test method.
+ */
+ public boolean isTestMethod(Method method) {
+ return isModifierValid(method) && isNameValid(method)
+ && isParamValid(method);
+ }
+
+ /**
+ * Judeges whether the modifier of is method conforms to the convention of a
+ * test method.
+ *
+ * @param method
+ * to be judged
+ * @return returns true if this method is public and non static.
+ */
+ protected boolean isModifierValid(Method method) {
+ return ReflectionUtil.isPublic(method)
+ && !ReflectionUtil.isStatic(method);
+ }
+
+ /**
+ * Judeges whether the name of is method conforms to the convention of a
+ * test method.
+ *
+ * @param method
+ * to be judged
+ * @return returns true if the name of this method starts with "test", or
+ * the name is in the list of test interfaces which are added by
+ * <code>TestMethodBuilder.addTestInterfaces</code>
+ */
+ protected boolean isNameValid(Method method) {
+ String name = method.getName();
+ return name.startsWith("test"); //$NON-NLS-1$
+ }
+
+ /**
+ * Judges whether the paramaters of this method conforms to the convention
+ * of a test method.
+ *
+ * @param method
+ * @return returns true if the parameter length is zero and the test class
+ * is not marked as <code>Parameterizable</code>, or the
+ * parameter length is 1, and the parameter is assignable from
+ * <code>Parameter</code>.
+ */
+ protected boolean isParamValid(Method method) {
+ Class clazz = method.getDeclaringClass();
+ Class[] params = method.getParameterTypes();
+ if (TypeUtil.isPUnitParameterizableTest((clazz))) {
+ return params.length == 1
+ && Parameter.class.isAssignableFrom(params[0]);
+ } else {
+ return params.length == 0;
+ }
+ }
+
+ public Class getExpectedException(Method method) {
+ return null;
+ }
+}
Deleted: trunk/punit/src/org/punit/method/NameMethodFilter.java
===================================================================
--- trunk/punit/src/org/punit/method/NameMethodFilter.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit/src/org/punit/method/NameMethodFilter.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -1,87 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.method;
-
-import java.lang.reflect.*;
-
-import org.punit.type.*;
-import org.punit.util.*;
-
-public class NameMethodFilter implements MethodFilter {
-
- private static final long serialVersionUID = -1252188754463864599L;
-
- public boolean isExcluded(Class method) {
- return false;
- }
-
- public Method getCheckMethod(Method method) {
- String checkMethodName = "check_" + method.getName(); //$NON-NLS-1$
- return ReflectionUtil.getMethod(method.getDeclaringClass(),
- checkMethodName, method.getParameterTypes());
- }
-
- /**
- * Judges whether this method is a test method.
- *
- * @return returns true if the test modifier, name, and parameter conform to
- * the convention of a test method.
- */
- public boolean isTestMethod(Method method) {
- return isModifierValid(method) && isNameValid(method)
- && isParamValid(method);
- }
-
- /**
- * Judeges whether the modifier of is method conforms to the convention of a
- * test method.
- *
- * @param method
- * to be judged
- * @return returns true if this method is public and non static.
- */
- protected boolean isModifierValid(Method method) {
- return ReflectionUtil.isPublic(method)
- && !ReflectionUtil.isStatic(method);
- }
-
- /**
- * Judeges whether the name of is method conforms to the convention of a
- * test method.
- *
- * @param method
- * to be judged
- * @return returns true if the name of this method starts with "test", or
- * the name is in the list of test interfaces which are added by
- * <code>TestMethodBuilder.addTestInterfaces</code>
- */
- protected boolean isNameValid(Method method) {
- String name = method.getName();
- return name.startsWith("test"); //$NON-NLS-1$
- }
-
- /**
- * Judges whether the paramaters of this method conforms to the convention
- * of a test method.
- *
- * @param method
- * @return returns true if the parameter length is zero and the test class
- * is not marked as <code>Parameterizable</code>, or the
- * parameter length is 1, and the parameter is assignable from
- * <code>Parameter</code>.
- */
- protected boolean isParamValid(Method method) {
- Class clazz = method.getDeclaringClass();
- Class[] params = method.getParameterTypes();
- if (TypeUtil.isPUnitParameterizableTest((clazz))) {
- return params.length == 1
- && Parameter.class.isAssignableFrom(params[0]);
- } else {
- return params.length == 0;
- }
- }
-
- public Class getExpectedException(Method method) {
- return null;
- }
-}
Modified: trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -17,9 +17,9 @@
private static final long serialVersionUID = -6593981780599574964L;
- private MethodFilter _filter;
+ private Filter _filter;
- public void setMethodFilter(MethodFilter filter) {
+ public void setMethodFilter(Filter filter) {
_filter = filter;
}
Modified: trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -24,5 +24,5 @@
public Collection buildTestMethods(Class testClass);
- public void setMethodFilter(MethodFilter filter);
+ public void setMethodFilter(Filter filter);
}
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -24,7 +24,7 @@
private RunnerProperties _runnerProperties;
- protected MethodFilter _filter;
+ protected Filter _filter;
protected transient Object _testInstance;
@@ -303,7 +303,7 @@
}
}
- public void setMethodFilter(MethodFilter filter) {
+ public void setMethodFilter(Filter filter) {
_filter = filter;
}
Modified: trunk/punit/src/org/punit/method/runner/MethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/MethodRunner.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit/src/org/punit/method/runner/MethodRunner.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -38,5 +38,5 @@
public Object clone();
- public void setMethodFilter(MethodFilter filter);
+ public void setMethodFilter(Filter filter);
}
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -41,10 +41,10 @@
_methodRunner.setEventListeners(_eventListeners);
_methodRunner.setRunnerProperties(_properties);
registerLoggerListeners();
- setFilter(new NameMethodFilter());
+ setFilter(new NameConventionFilter());
}
- public void setFilter(MethodFilter filter) {
+ public void setFilter(Filter filter) {
_testSuiteBuiler.setFilter(filter);
_testMethodBuilder.setMethodFilter(filter);
_methodRunner.setMethodFilter(filter);
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -20,5 +20,5 @@
*/
public Object[] buildTestClasses(Class testSutie);
- public void setFilter(MethodFilter filter);
+ public void setFilter(Filter filter);
}
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -12,9 +12,9 @@
private static final long serialVersionUID = -4468961881014123138L;
- private MethodFilter _filter;
+ private Filter _filter;
- public void setFilter(MethodFilter filter) {
+ public void setFilter(Filter filter) {
_filter = filter;
}
Copied: trunk/punit.extension/src/org/punit/method/AnnotationFilter.java (from rev 190, trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java)
===================================================================
--- trunk/punit.extension/src/org/punit/method/AnnotationFilter.java (rev 0)
+++ trunk/punit.extension/src/org/punit/method/AnnotationFilter.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -0,0 +1,54 @@
+package org.punit.method;
+
+import java.lang.reflect.*;
+
+import org.punit.annotation.*;
+import org.punit.annotation.Test.*;
+import org.punit.util.*;
+
+public class AnnotationFilter implements Filter {
+
+ private static final long serialVersionUID = -2043378593194849589L;
+
+ NameConventionFilter _delegate = new NameConventionFilter();
+
+ public Method getCheckMethod(Method method) {
+ Test testAnnotation = method.getAnnotation(Test.class);
+ String checkMethodName = null;
+ if (testAnnotation != null) {
+ checkMethodName = testAnnotation.checkMethod();
+ if (checkMethodName != null && checkMethodName.length() > 0) {
+ return ReflectionUtil.getMethod(method.getDeclaringClass(),
+ checkMethodName, method.getParameterTypes());
+ }
+ }
+ return _delegate.getCheckMethod(method);
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean isExcluded(Class clazz) {
+ Test testAnnotation = (Test) clazz.getAnnotation(Test.class);
+ if(testAnnotation == null) {
+ return false;
+ }
+ return testAnnotation.excluded();
+ }
+
+ public boolean isTestMethod(Method method) {
+ Test testAnnotation = method.getAnnotation(Test.class);
+ return (testAnnotation != null) || _delegate.isTestMethod(method);
+ }
+
+ public Class<? extends Throwable> getExpectedException(Method method) {
+ Test testAnnotation = method.getAnnotation(Test.class);
+ if(testAnnotation == null) {
+ return null;
+ }
+ Class<? extends Throwable> expected = testAnnotation.expected();
+ if(expected == NoException.class) {
+ return null;
+ }
+ return expected;
+ }
+
+}
Deleted: trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -1,54 +0,0 @@
-package org.punit.method;
-
-import java.lang.reflect.*;
-
-import org.punit.annotation.*;
-import org.punit.annotation.Test.*;
-import org.punit.util.*;
-
-public class AnnotationMethodFilter implements MethodFilter {
-
- private static final long serialVersionUID = -2043378593194849589L;
-
- NameMethodFilter _delegate = new NameMethodFilter();
-
- public Method getCheckMethod(Method method) {
- Test testAnnotation = method.getAnnotation(Test.class);
- String checkMethodName = null;
- if (testAnnotation != null) {
- checkMethodName = testAnnotation.checkMethod();
- if (checkMethodName != null && checkMethodName.length() > 0) {
- return ReflectionUtil.getMethod(method.getDeclaringClass(),
- checkMethodName, method.getParameterTypes());
- }
- }
- return _delegate.getCheckMethod(method);
- }
-
- @SuppressWarnings("unchecked")
- public boolean isExcluded(Class clazz) {
- Test testAnnotation = (Test) clazz.getAnnotation(Test.class);
- if(testAnnotation == null) {
- return false;
- }
- return testAnnotation.excluded();
- }
-
- public boolean isTestMethod(Method method) {
- Test testAnnotation = method.getAnnotation(Test.class);
- return (testAnnotation != null) || _delegate.isTestMethod(method);
- }
-
- public Class<? extends Throwable> getExpectedException(Method method) {
- Test testAnnotation = method.getAnnotation(Test.class);
- if(testAnnotation == null) {
- return null;
- }
- Class<? extends Throwable> expected = testAnnotation.expected();
- if(expected == NoException.class) {
- return null;
- }
- return expected;
- }
-
-}
Modified: trunk/punit.test/src/tests/api/org/punit/method/AnnotationMethodFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/AnnotationMethodFilterTest.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit.test/src/tests/api/org/punit/method/AnnotationMethodFilterTest.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -11,7 +11,7 @@
import org.punit.util.*;
public class AnnotationMethodFilterTest extends TestCase {
- AnnotationMethodFilter _filter = new AnnotationMethodFilter();
+ AnnotationFilter _filter = new AnnotationFilter();
public void testIsExcluded() {
assertTrue(_filter.isExcluded(ExcludedClass.class));
Modified: trunk/punit.test/src/tests/api/org/punit/method/ByNameMethodFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/ByNameMethodFilterTest.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit.test/src/tests/api/org/punit/method/ByNameMethodFilterTest.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -10,7 +10,7 @@
import org.punit.util.*;
public class ByNameMethodFilterTest extends TestCase {
- AnnotationMethodFilter _filter = new AnnotationMethodFilter();
+ AnnotationFilter _filter = new AnnotationFilter();
public void testIsTestMethod() {
Method method;
Modified: trunk/punit.test/src/tests/api/org/punit/method/builder/MethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/builder/MethodBuilderTest.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit.test/src/tests/api/org/punit/method/builder/MethodBuilderTest.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -15,11 +15,11 @@
public void setUp() {
_builder = new MethodBuilderImpl();
- _builder.setMethodFilter(new NameMethodFilter());
+ _builder.setMethodFilter(new NameConventionFilter());
}
public void testAddInterfaces() {
- _builder.setMethodFilter(new AnnotationMethodFilter());
+ _builder.setMethodFilter(new AnnotationFilter());
Object[] methods = _builder.buildTestMethods(TestInterfaceImpl1.class)
.toArray();
String[] names = TestUtil.toMethodNameArray(methods);
Modified: trunk/punit.test/src/tests/api/org/punit/method/builder/PUnitTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/builder/PUnitTestMethodBuilderTest.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit.test/src/tests/api/org/punit/method/builder/PUnitTestMethodBuilderTest.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -12,7 +12,7 @@
protected void setUp() throws Exception {
_builder = new MethodBuilderImpl();
- _builder.setMethodFilter(new NameMethodFilter());
+ _builder.setMethodFilter(new NameConventionFilter());
}
public void testBuildTestMethods1() {
Modified: trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -41,7 +41,7 @@
public void testRunAnnotationTest() {
AnnotationTestClass.reset();
- _runner.setFilter(new AnnotationMethodFilter());
+ _runner.setFilter(new AnnotationFilter());
_runner.run(AnnotationTestClass.class);
AnnotationTestClass.assertTestClassRun();
}
Modified: trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -37,7 +37,7 @@
public void testRunAnnotationTest() {
AnnotationTestClass.reset();
- _runner.setFilter(new AnnotationMethodFilter());
+ _runner.setFilter(new AnnotationFilter());
_runner.run(AnnotationTestClass.class);
AnnotationTestClass.assertTestClassRun();
}
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-06-04 06:27:22 UTC (rev 190)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-06-04 06:31:40 UTC (rev 191)
@@ -10,7 +10,7 @@
public static void main(String[] args) {
SoloRunner soloRunner = new SoloRunner();
- soloRunner.setFilter(new AnnotationMethodFilter());
+ soloRunner.setFilter(new AnnotationFilter());
soloRunner.run(AnnotationTestClass.class);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-06-04 06:33:46
|
Revision: 192
http://p-unit.svn.sourceforge.net/p-unit/?rev=192&view=rev
Author: zhanghuangzhu
Date: 2007-06-03 23:33:48 -0700 (Sun, 03 Jun 2007)
Log Message:
-----------
Andrew Zhang: refactored name.
Modified Paths:
--------------
trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
trunk/punit.test/src/tests/api/org/punit/method/AnnotationMethodFilterTest.java
trunk/punit.test/src/tests/api/org/punit/method/ByNameMethodFilterTest.java
trunk/punit.test/src/tests/api/org/punit/method/builder/MethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/method/builder/PUnitTestMethodBuilderTest.java
Added Paths:
-----------
trunk/punit/src/org/punit/runner/Filter.java
trunk/punit/src/org/punit/runner/NameConventionFilter.java
trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java
Removed Paths:
-------------
trunk/punit/src/org/punit/method/Filter.java
trunk/punit/src/org/punit/method/NameConventionFilter.java
trunk/punit.extension/src/org/punit/method/AnnotationFilter.java
Deleted: trunk/punit/src/org/punit/method/Filter.java
===================================================================
--- trunk/punit/src/org/punit/method/Filter.java 2007-06-04 06:31:40 UTC (rev 191)
+++ trunk/punit/src/org/punit/method/Filter.java 2007-06-04 06:33:48 UTC (rev 192)
@@ -1,34 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.method;
-
-import java.io.*;
-import java.lang.reflect.*;
-
-public interface Filter extends Serializable {
-
- /**
- * Judges whether this test class is excluded.
- *
- * @return returns true if the test class is excluded.
- */
- public boolean isExcluded(Class clazz);
-
- /**
- * Judges whether this method is a test method.
- *
- * @return returns true if it is a test method.
- */
- public boolean isTestMethod(Method method);
-
- /**
- * Gets the corresponding check method to this test method
- *
- * @param method
- * the test method
- * @return
- */
- public Method getCheckMethod(Method method);
-
- public Class getExpectedException(Method method);
-}
Deleted: trunk/punit/src/org/punit/method/NameConventionFilter.java
===================================================================
--- trunk/punit/src/org/punit/method/NameConventionFilter.java 2007-06-04 06:31:40 UTC (rev 191)
+++ trunk/punit/src/org/punit/method/NameConventionFilter.java 2007-06-04 06:33:48 UTC (rev 192)
@@ -1,87 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.method;
-
-import java.lang.reflect.*;
-
-import org.punit.type.*;
-import org.punit.util.*;
-
-public class NameConventionFilter implements Filter {
-
- private static final long serialVersionUID = -1252188754463864599L;
-
- public boolean isExcluded(Class method) {
- return false;
- }
-
- public Method getCheckMethod(Method method) {
- String checkMethodName = "check_" + method.getName(); //$NON-NLS-1$
- return ReflectionUtil.getMethod(method.getDeclaringClass(),
- checkMethodName, method.getParameterTypes());
- }
-
- /**
- * Judges whether this method is a test method.
- *
- * @return returns true if the test modifier, name, and parameter conform to
- * the convention of a test method.
- */
- public boolean isTestMethod(Method method) {
- return isModifierValid(method) && isNameValid(method)
- && isParamValid(method);
- }
-
- /**
- * Judeges whether the modifier of is method conforms to the convention of a
- * test method.
- *
- * @param method
- * to be judged
- * @return returns true if this method is public and non static.
- */
- protected boolean isModifierValid(Method method) {
- return ReflectionUtil.isPublic(method)
- && !ReflectionUtil.isStatic(method);
- }
-
- /**
- * Judeges whether the name of is method conforms to the convention of a
- * test method.
- *
- * @param method
- * to be judged
- * @return returns true if the name of this method starts with "test", or
- * the name is in the list of test interfaces which are added by
- * <code>TestMethodBuilder.addTestInterfaces</code>
- */
- protected boolean isNameValid(Method method) {
- String name = method.getName();
- return name.startsWith("test"); //$NON-NLS-1$
- }
-
- /**
- * Judges whether the paramaters of this method conforms to the convention
- * of a test method.
- *
- * @param method
- * @return returns true if the parameter length is zero and the test class
- * is not marked as <code>Parameterizable</code>, or the
- * parameter length is 1, and the parameter is assignable from
- * <code>Parameter</code>.
- */
- protected boolean isParamValid(Method method) {
- Class clazz = method.getDeclaringClass();
- Class[] params = method.getParameterTypes();
- if (TypeUtil.isPUnitParameterizableTest((clazz))) {
- return params.length == 1
- && Parameter.class.isAssignableFrom(params[0]);
- } else {
- return params.length == 0;
- }
- }
-
- public Class getExpectedException(Method method) {
- return null;
- }
-}
Modified: trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-06-04 06:31:40 UTC (rev 191)
+++ trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-06-04 06:33:48 UTC (rev 192)
@@ -6,6 +6,7 @@
import java.util.*;
import org.punit.method.*;
+import org.punit.runner.*;
import org.punit.type.*;
/**
Modified: trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-06-04 06:31:40 UTC (rev 191)
+++ trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-06-04 06:33:48 UTC (rev 192)
@@ -6,6 +6,7 @@
import java.util.*;
import org.punit.method.*;
+import org.punit.runner.*;
/**
* Interface for test method builder. The method builder builds a list of
Copied: trunk/punit/src/org/punit/runner/Filter.java (from rev 191, trunk/punit/src/org/punit/method/Filter.java)
===================================================================
--- trunk/punit/src/org/punit/runner/Filter.java (rev 0)
+++ trunk/punit/src/org/punit/runner/Filter.java 2007-06-04 06:33:48 UTC (rev 192)
@@ -0,0 +1,34 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.runner;
+
+import java.io.*;
+import java.lang.reflect.*;
+
+public interface Filter extends Serializable {
+
+ /**
+ * Judges whether this test class is excluded.
+ *
+ * @return returns true if the test class is excluded.
+ */
+ public boolean isExcluded(Class clazz);
+
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @return returns true if it is a test method.
+ */
+ public boolean isTestMethod(Method method);
+
+ /**
+ * Gets the corresponding check method to this test method
+ *
+ * @param method
+ * the test method
+ * @return
+ */
+ public Method getCheckMethod(Method method);
+
+ public Class getExpectedException(Method method);
+}
Copied: trunk/punit/src/org/punit/runner/NameConventionFilter.java (from rev 191, trunk/punit/src/org/punit/method/NameConventionFilter.java)
===================================================================
--- trunk/punit/src/org/punit/runner/NameConventionFilter.java (rev 0)
+++ trunk/punit/src/org/punit/runner/NameConventionFilter.java 2007-06-04 06:33:48 UTC (rev 192)
@@ -0,0 +1,87 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.runner;
+
+import java.lang.reflect.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class NameConventionFilter implements Filter {
+
+ private static final long serialVersionUID = -1252188754463864599L;
+
+ public boolean isExcluded(Class method) {
+ return false;
+ }
+
+ public Method getCheckMethod(Method method) {
+ String checkMethodName = "check_" + method.getName(); //$NON-NLS-1$
+ return ReflectionUtil.getMethod(method.getDeclaringClass(),
+ checkMethodName, method.getParameterTypes());
+ }
+
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @return returns true if the test modifier, name, and parameter conform to
+ * the convention of a test method.
+ */
+ public boolean isTestMethod(Method method) {
+ return isModifierValid(method) && isNameValid(method)
+ && isParamValid(method);
+ }
+
+ /**
+ * Judeges whether the modifier of is method conforms to the convention of a
+ * test method.
+ *
+ * @param method
+ * to be judged
+ * @return returns true if this method is public and non static.
+ */
+ protected boolean isModifierValid(Method method) {
+ return ReflectionUtil.isPublic(method)
+ && !ReflectionUtil.isStatic(method);
+ }
+
+ /**
+ * Judeges whether the name of is method conforms to the convention of a
+ * test method.
+ *
+ * @param method
+ * to be judged
+ * @return returns true if the name of this method starts with "test", or
+ * the name is in the list of test interfaces which are added by
+ * <code>TestMethodBuilder.addTestInterfaces</code>
+ */
+ protected boolean isNameValid(Method method) {
+ String name = method.getName();
+ return name.startsWith("test"); //$NON-NLS-1$
+ }
+
+ /**
+ * Judges whether the paramaters of this method conforms to the convention
+ * of a test method.
+ *
+ * @param method
+ * @return returns true if the parameter length is zero and the test class
+ * is not marked as <code>Parameterizable</code>, or the
+ * parameter length is 1, and the parameter is assignable from
+ * <code>Parameter</code>.
+ */
+ protected boolean isParamValid(Method method) {
+ Class clazz = method.getDeclaringClass();
+ Class[] params = method.getParameterTypes();
+ if (TypeUtil.isPUnitParameterizableTest((clazz))) {
+ return params.length == 1
+ && Parameter.class.isAssignableFrom(params[0]);
+ } else {
+ return params.length == 0;
+ }
+ }
+
+ public Class getExpectedException(Method method) {
+ return null;
+ }
+}
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-04 06:31:40 UTC (rev 191)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-04 06:33:48 UTC (rev 192)
@@ -5,6 +5,7 @@
import java.io.*;
import org.punit.method.*;
+import org.punit.runner.*;
/**
* Interface for test suite builder.
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-04 06:31:40 UTC (rev 191)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-04 06:33:48 UTC (rev 192)
@@ -5,6 +5,7 @@
import java.util.*;
import org.punit.method.*;
+import org.punit.runner.*;
import org.punit.type.*;
import org.punit.util.*;
Deleted: trunk/punit.extension/src/org/punit/method/AnnotationFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/method/AnnotationFilter.java 2007-06-04 06:31:40 UTC (rev 191)
+++ trunk/punit.extension/src/org/punit/method/AnnotationFilter.java 2007-06-04 06:33:48 UTC (rev 192)
@@ -1,54 +0,0 @@
-package org.punit.method;
-
-import java.lang.reflect.*;
-
-import org.punit.annotation.*;
-import org.punit.annotation.Test.*;
-import org.punit.util.*;
-
-public class AnnotationFilter implements Filter {
-
- private static final long serialVersionUID = -2043378593194849589L;
-
- NameConventionFilter _delegate = new NameConventionFilter();
-
- public Method getCheckMethod(Method method) {
- Test testAnnotation = method.getAnnotation(Test.class);
- String checkMethodName = null;
- if (testAnnotation != null) {
- checkMethodName = testAnnotation.checkMethod();
- if (checkMethodName != null && checkMethodName.length() > 0) {
- return ReflectionUtil.getMethod(method.getDeclaringClass(),
- checkMethodName, method.getParameterTypes());
- }
- }
- return _delegate.getCheckMethod(method);
- }
-
- @SuppressWarnings("unchecked")
- public boolean isExcluded(Class clazz) {
- Test testAnnotation = (Test) clazz.getAnnotation(Test.class);
- if(testAnnotation == null) {
- return false;
- }
- return testAnnotation.excluded();
- }
-
- public boolean isTestMethod(Method method) {
- Test testAnnotation = method.getAnnotation(Test.class);
- return (testAnnotation != null) || _delegate.isTestMethod(method);
- }
-
- public Class<? extends Throwable> getExpectedException(Method method) {
- Test testAnnotation = method.getAnnotation(Test.class);
- if(testAnnotation == null) {
- return null;
- }
- Class<? extends Throwable> expected = testAnnotation.expected();
- if(expected == NoException.class) {
- return null;
- }
- return expected;
- }
-
-}
Copied: trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java (from rev 191, trunk/punit.extension/src/org/punit/method/AnnotationFilter.java)
===================================================================
--- trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java (rev 0)
+++ trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java 2007-06-04 06:33:48 UTC (rev 192)
@@ -0,0 +1,55 @@
+package org.punit.runner;
+
+import java.lang.reflect.*;
+
+import org.punit.annotation.*;
+import org.punit.annotation.Test.*;
+import org.punit.runner.*;
+import org.punit.util.*;
+
+public class AnnotationFilter implements Filter {
+
+ private static final long serialVersionUID = -2043378593194849589L;
+
+ NameConventionFilter _delegate = new NameConventionFilter();
+
+ public Method getCheckMethod(Method method) {
+ Test testAnnotation = method.getAnnotation(Test.class);
+ String checkMethodName = null;
+ if (testAnnotation != null) {
+ checkMethodName = testAnnotation.checkMethod();
+ if (checkMethodName != null && checkMethodName.length() > 0) {
+ return ReflectionUtil.getMethod(method.getDeclaringClass(),
+ checkMethodName, method.getParameterTypes());
+ }
+ }
+ return _delegate.getCheckMethod(method);
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean isExcluded(Class clazz) {
+ Test testAnnotation = (Test) clazz.getAnnotation(Test.class);
+ if(testAnnotation == null) {
+ return false;
+ }
+ return testAnnotation.excluded();
+ }
+
+ public boolean isTestMethod(Method method) {
+ Test testAnnotation = method.getAnnotation(Test.class);
+ return (testAnnotation != null) || _delegate.isTestMethod(method);
+ }
+
+ public Class<? extends Throwable> getExpectedException(Method method) {
+ Test testAnnotation = method.getAnnotation(Test.class);
+ if(testAnnotation == null) {
+ return null;
+ }
+ Class<? extends Throwable> expected = testAnnotation.expected();
+ if(expected == NoException.class) {
+ return null;
+ }
+ return expected;
+ }
+
+}
Modified: trunk/punit.test/src/tests/api/org/punit/method/AnnotationMethodFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/AnnotationMethodFilterTest.java 2007-06-04 06:31:40 UTC (rev 191)
+++ trunk/punit.test/src/tests/api/org/punit/method/AnnotationMethodFilterTest.java 2007-06-04 06:33:48 UTC (rev 192)
@@ -8,6 +8,7 @@
import org.punit.annotation.Test;
import org.punit.method.*;
+import org.punit.runner.*;
import org.punit.util.*;
public class AnnotationMethodFilterTest extends TestCase {
Modified: trunk/punit.test/src/tests/api/org/punit/method/ByNameMethodFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/ByNameMethodFilterTest.java 2007-06-04 06:31:40 UTC (rev 191)
+++ trunk/punit.test/src/tests/api/org/punit/method/ByNameMethodFilterTest.java 2007-06-04 06:33:48 UTC (rev 192)
@@ -7,6 +7,7 @@
import junit.framework.*;
import org.punit.method.*;
+import org.punit.runner.*;
import org.punit.util.*;
public class ByNameMethodFilterTest extends TestCase {
Modified: trunk/punit.test/src/tests/api/org/punit/method/builder/MethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/builder/MethodBuilderTest.java 2007-06-04 06:31:40 UTC (rev 191)
+++ trunk/punit.test/src/tests/api/org/punit/method/builder/MethodBuilderTest.java 2007-06-04 06:33:48 UTC (rev 192)
@@ -6,6 +6,8 @@
import org.punit.method.*;
import org.punit.method.builder.*;
+import org.punit.runner.*;
+
import tests.api.org.punit.testclasses.*;
import tests.util.*;
Modified: trunk/punit.test/src/tests/api/org/punit/method/builder/PUnitTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/builder/PUnitTestMethodBuilderTest.java 2007-06-04 06:31:40 UTC (rev 191)
+++ trunk/punit.test/src/tests/api/org/punit/method/builder/PUnitTestMethodBuilderTest.java 2007-06-04 06:33:48 UTC (rev 192)
@@ -4,6 +4,8 @@
import org.punit.method.*;
import org.punit.method.builder.*;
+import org.punit.runner.*;
+
import tests.api.org.punit.testclasses.*;
import tests.util.*;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-06-04 06:37:44
|
Revision: 193
http://p-unit.svn.sourceforge.net/p-unit/?rev=193&view=rev
Author: zhanghuangzhu
Date: 2007-06-03 23:37:45 -0700 (Sun, 03 Jun 2007)
Log Message:
-----------
Andrew Zhang: refactored name.
Modified Paths:
--------------
trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
trunk/punit/src/org/punit/method/runner/MethodRunner.java
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java
trunk/punit.test/src/tests/api/org/punit/method/AnnotationMethodFilterTest.java
trunk/punit.test/src/tests/api/org/punit/method/ByNameMethodFilterTest.java
trunk/punit.test/src/tests/api/org/punit/method/builder/MethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/method/builder/PUnitTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
Modified: trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-06-04 06:33:48 UTC (rev 192)
+++ trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-06-04 06:37:45 UTC (rev 193)
@@ -5,7 +5,6 @@
import java.lang.reflect.*;
import java.util.*;
-import org.punit.method.*;
import org.punit.runner.*;
import org.punit.type.*;
Modified: trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-06-04 06:33:48 UTC (rev 192)
+++ trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-06-04 06:37:45 UTC (rev 193)
@@ -5,7 +5,6 @@
import java.io.*;
import java.util.*;
-import org.punit.method.*;
import org.punit.runner.*;
/**
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-04 06:33:48 UTC (rev 192)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-04 06:37:45 UTC (rev 193)
@@ -8,7 +8,6 @@
import org.punit.assertion.*;
import org.punit.events.*;
import org.punit.exception.*;
-import org.punit.method.*;
import org.punit.runner.*;
import org.punit.type.*;
import org.punit.util.*;
Modified: trunk/punit/src/org/punit/method/runner/MethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/MethodRunner.java 2007-06-04 06:33:48 UTC (rev 192)
+++ trunk/punit/src/org/punit/method/runner/MethodRunner.java 2007-06-04 06:37:45 UTC (rev 193)
@@ -4,7 +4,6 @@
import java.lang.reflect.*;
import java.util.*;
-import org.punit.method.*;
import org.punit.runner.*;
import org.punit.watcher.*;
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-04 06:33:48 UTC (rev 192)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-04 06:37:45 UTC (rev 193)
@@ -8,7 +8,6 @@
import org.punit.events.*;
import org.punit.exception.*;
-import org.punit.method.*;
import org.punit.method.builder.*;
import org.punit.method.runner.*;
import org.punit.reporter.stream.console.*;
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-04 06:33:48 UTC (rev 192)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-04 06:37:45 UTC (rev 193)
@@ -4,7 +4,6 @@
import java.io.*;
-import org.punit.method.*;
import org.punit.runner.*;
/**
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-04 06:33:48 UTC (rev 192)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-04 06:37:45 UTC (rev 193)
@@ -4,7 +4,6 @@
import java.util.*;
-import org.punit.method.*;
import org.punit.runner.*;
import org.punit.type.*;
import org.punit.util.*;
Modified: trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java 2007-06-04 06:33:48 UTC (rev 192)
+++ trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java 2007-06-04 06:37:45 UTC (rev 193)
@@ -4,7 +4,6 @@
import org.punit.annotation.*;
import org.punit.annotation.Test.*;
-import org.punit.runner.*;
import org.punit.util.*;
public class AnnotationFilter implements Filter {
Modified: trunk/punit.test/src/tests/api/org/punit/method/AnnotationMethodFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/AnnotationMethodFilterTest.java 2007-06-04 06:33:48 UTC (rev 192)
+++ trunk/punit.test/src/tests/api/org/punit/method/AnnotationMethodFilterTest.java 2007-06-04 06:37:45 UTC (rev 193)
@@ -7,7 +7,6 @@
import junit.framework.*;
import org.punit.annotation.Test;
-import org.punit.method.*;
import org.punit.runner.*;
import org.punit.util.*;
Modified: trunk/punit.test/src/tests/api/org/punit/method/ByNameMethodFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/ByNameMethodFilterTest.java 2007-06-04 06:33:48 UTC (rev 192)
+++ trunk/punit.test/src/tests/api/org/punit/method/ByNameMethodFilterTest.java 2007-06-04 06:37:45 UTC (rev 193)
@@ -6,7 +6,6 @@
import junit.framework.*;
-import org.punit.method.*;
import org.punit.runner.*;
import org.punit.util.*;
Modified: trunk/punit.test/src/tests/api/org/punit/method/builder/MethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/builder/MethodBuilderTest.java 2007-06-04 06:33:48 UTC (rev 192)
+++ trunk/punit.test/src/tests/api/org/punit/method/builder/MethodBuilderTest.java 2007-06-04 06:37:45 UTC (rev 193)
@@ -4,7 +4,6 @@
import junit.framework.*;
-import org.punit.method.*;
import org.punit.method.builder.*;
import org.punit.runner.*;
Modified: trunk/punit.test/src/tests/api/org/punit/method/builder/PUnitTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/builder/PUnitTestMethodBuilderTest.java 2007-06-04 06:33:48 UTC (rev 192)
+++ trunk/punit.test/src/tests/api/org/punit/method/builder/PUnitTestMethodBuilderTest.java 2007-06-04 06:37:45 UTC (rev 193)
@@ -2,7 +2,6 @@
import junit.framework.*;
-import org.punit.method.*;
import org.punit.method.builder.*;
import org.punit.runner.*;
Modified: trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2007-06-04 06:33:48 UTC (rev 192)
+++ trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2007-06-04 06:37:45 UTC (rev 193)
@@ -6,7 +6,6 @@
import junit.framework.*;
-import org.punit.method.*;
import org.punit.runner.*;
import tests.api.org.punit.testclasses.*;
Modified: trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2007-06-04 06:33:48 UTC (rev 192)
+++ trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2007-06-04 06:37:45 UTC (rev 193)
@@ -4,7 +4,6 @@
import junit.framework.*;
-import org.punit.method.*;
import org.punit.runner.*;
import tests.api.org.punit.testclasses.*;
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-06-04 06:33:48 UTC (rev 192)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-06-04 06:37:45 UTC (rev 193)
@@ -3,7 +3,6 @@
import junit.framework.*;
import org.punit.annotation.Test;
-import org.punit.method.*;
import org.punit.runner.*;
public class AnnotationTestClass {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-06-07 03:40:44
|
Revision: 201
http://p-unit.svn.sourceforge.net/p-unit/?rev=201&view=rev
Author: zhanghuangzhu
Date: 2007-06-06 20:40:32 -0700 (Wed, 06 Jun 2007)
Log Message:
-----------
Andrew Zhang: Refactored name, and added IntParameter default implementation.
Modified Paths:
--------------
trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
trunk/punit/src/org/punit/runner/Filter.java
trunk/punit/src/org/punit/runner/NameConventionFilter.java
trunk/punit/src/org/punit/util/IOUtil.java
trunk/punit/src/org/punit/util/ReflectionUtil.java
trunk/punit/src/org/punit/util/RunnerUtil.java
trunk/punit.extension/src/org/punit/annotation/Test.java
trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java
trunk/punit.samples/src/samples/vms/VMConfig.java
trunk/punit.test/src/tests/api/org/punit/runner/AnnotationFilterTest.java
trunk/punit.test/src/tests/api/org/punit/runner/NameConventionFilterTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
Added Paths:
-----------
trunk/punit/src/org/punit/util/IntParameter.java
Modified: trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2007-06-04 07:15:18 UTC (rev 200)
+++ trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2007-06-07 03:40:32 UTC (rev 201)
@@ -3,7 +3,6 @@
package org.punit.method.runner;
import org.punit.exception.*;
-import org.punit.type.*;
public class ConcurrentMethodRunner extends AbstractMethodRunner {
@@ -45,14 +44,23 @@
protected void setUpBeforeWatchers(Object[] params) throws Throwable {
super.setUpBeforeWatchers(params);
+ initThreads();
+ }
+
+ private void initThreads() {
int threadCount = _concurrentCount;
- if(_testInstance instanceof Concurrent) {
- threadCount = ((Concurrent)_testInstance).concurrentCount();
+ int count = _filter.getConcurrentCount(_testInstance);
+ if(count > 0) {
+ threadCount = count;
}
+ count = _filter.getConcurrentCount(_method);
+ if(count > 0) {
+ threadCount = count;
+ }
_threads = new TestMethodThread[threadCount];
for (int i = 0; i < _threads.length; ++i) {
_threads[i] = new TestMethodThread(this, "punit concurrent method runner"); //$NON-NLS-1$
- }
+ }
}
protected String getCheckMethodName() {
Modified: trunk/punit/src/org/punit/runner/Filter.java
===================================================================
--- trunk/punit/src/org/punit/runner/Filter.java 2007-06-04 07:15:18 UTC (rev 200)
+++ trunk/punit/src/org/punit/runner/Filter.java 2007-06-07 03:40:32 UTC (rev 201)
@@ -31,4 +31,8 @@
public Method getCheckMethod(Method method);
public Class getExpectedException(Method method);
+
+ public int getConcurrentCount(Method method);
+
+ public int getConcurrentCount(Object testInstance);
}
Modified: trunk/punit/src/org/punit/runner/NameConventionFilter.java
===================================================================
--- trunk/punit/src/org/punit/runner/NameConventionFilter.java 2007-06-04 07:15:18 UTC (rev 200)
+++ trunk/punit/src/org/punit/runner/NameConventionFilter.java 2007-06-07 03:40:32 UTC (rev 201)
@@ -84,4 +84,17 @@
public Class getExpectedException(Method method) {
return null;
}
+
+ public int getConcurrentCount(Method method) {
+ return 0;
+ }
+
+ public int getConcurrentCount(Object testInstance) {
+ if(testInstance instanceof Concurrent) {
+ return ((Concurrent)testInstance).concurrentCount();
+ }
+ return 0;
+ }
+
+
}
Modified: trunk/punit/src/org/punit/util/IOUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/IOUtil.java 2007-06-04 07:15:18 UTC (rev 200)
+++ trunk/punit/src/org/punit/util/IOUtil.java 2007-06-07 03:40:32 UTC (rev 201)
@@ -1,3 +1,5 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
package org.punit.util;
import java.io.*;
Added: trunk/punit/src/org/punit/util/IntParameter.java
===================================================================
--- trunk/punit/src/org/punit/util/IntParameter.java (rev 0)
+++ trunk/punit/src/org/punit/util/IntParameter.java 2007-06-07 03:40:32 UTC (rev 201)
@@ -0,0 +1,23 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.util;
+
+import org.punit.type.*;
+
+public class IntParameter implements Parameter {
+
+ private int _intValue;
+
+ public IntParameter(int value) {
+ _intValue = value;
+ }
+
+ public int intValue() {
+ return _intValue;
+ }
+
+ public String toString() {
+ return String.valueOf(_intValue);
+ }
+
+}
Modified: trunk/punit/src/org/punit/util/ReflectionUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-06-04 07:15:18 UTC (rev 200)
+++ trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-06-07 03:40:32 UTC (rev 201)
@@ -1,3 +1,5 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
package org.punit.util;
import java.lang.reflect.*;
Modified: trunk/punit/src/org/punit/util/RunnerUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/RunnerUtil.java 2007-06-04 07:15:18 UTC (rev 200)
+++ trunk/punit/src/org/punit/util/RunnerUtil.java 2007-06-07 03:40:32 UTC (rev 201)
@@ -2,8 +2,6 @@
package org.punit.util;
-import java.io.*;
-
import org.punit.message.*;
import org.punit.runner.*;
@@ -23,12 +21,6 @@
testRunner = (Runner) IOUtil.getSerialiableObject(args[1]);
}
if(length >= 3) {
- try {
- System.out.println(new File(args[2]).getCanonicalPath());
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
properties = (RunnerProperties) IOUtil.getSerialiableObject(args[2]);
}
testRunner.run(testClass, properties);
Modified: trunk/punit.extension/src/org/punit/annotation/Test.java
===================================================================
--- trunk/punit.extension/src/org/punit/annotation/Test.java 2007-06-04 07:15:18 UTC (rev 200)
+++ trunk/punit.extension/src/org/punit/annotation/Test.java 2007-06-07 03:40:32 UTC (rev 201)
@@ -12,6 +12,8 @@
String checkMethod() default "";
boolean excluded() default false;
+
+ int concurrentCount() default 0;
public class NoException extends Throwable {
private static final long serialVersionUID = 3987745685001380514L;
Modified: trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java 2007-06-04 07:15:18 UTC (rev 200)
+++ trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java 2007-06-07 03:40:32 UTC (rev 201)
@@ -13,7 +13,7 @@
NameConventionFilter _delegate = new NameConventionFilter();
public Method getCheckMethod(Method method) {
- Test testAnnotation = method.getAnnotation(Test.class);
+ Test testAnnotation = getTestAnnotation(method);
String checkMethodName = null;
if (testAnnotation != null) {
checkMethodName = testAnnotation.checkMethod();
@@ -24,10 +24,10 @@
}
return _delegate.getCheckMethod(method);
}
-
+
@SuppressWarnings("unchecked")
public boolean isExcluded(Class clazz) {
- Test testAnnotation = (Test) clazz.getAnnotation(Test.class);
+ Test testAnnotation = getTestAnnotation(clazz);
if(testAnnotation == null) {
return false;
}
@@ -35,12 +35,12 @@
}
public boolean isTestMethod(Method method) {
- Test testAnnotation = method.getAnnotation(Test.class);
+ Test testAnnotation = getTestAnnotation(method);
return (testAnnotation != null) || _delegate.isTestMethod(method);
}
public Class<? extends Throwable> getExpectedException(Method method) {
- Test testAnnotation = method.getAnnotation(Test.class);
+ Test testAnnotation = getTestAnnotation(method);
if(testAnnotation == null) {
return null;
}
@@ -51,4 +51,27 @@
return expected;
}
+ public int getConcurrentCount(Method method) {
+ Test testAnnotation = getTestAnnotation(method);
+ if(testAnnotation == null) {
+ return 0;
+ }
+ return testAnnotation.concurrentCount();
+ }
+
+ public int getConcurrentCount(Object testInstnace) {
+ Test testAnnotation = getTestAnnotation(testInstnace.getClass());
+ if(testAnnotation == null) {
+ return _delegate.getConcurrentCount(testInstnace);
+ }
+ return testAnnotation.concurrentCount();
+ }
+
+ private Test getTestAnnotation(Method method) {
+ return method.getAnnotation(Test.class);
+ }
+
+ private Test getTestAnnotation(Class<?> clazz) {
+ return (Test) clazz.getAnnotation(Test.class);
+ }
}
Modified: trunk/punit.samples/src/samples/vms/VMConfig.java
===================================================================
--- trunk/punit.samples/src/samples/vms/VMConfig.java 2007-06-04 07:15:18 UTC (rev 200)
+++ trunk/punit.samples/src/samples/vms/VMConfig.java 2007-06-07 03:40:32 UTC (rev 201)
@@ -4,7 +4,7 @@
public class VMConfig {
- private static String CLASSPATH = " -cp d:\\workspace_3.2\\punit.samples\\bin;d:\\workspace_3.2\\punit\\bin;d:\\workspace_3.2\\punit.extension\\bin;D:\\workspace_3.2\\punit.extension\\lib\\jcommon-1.0.9.jar;D:\\workspace_3.2\\punit.extension\\lib\\jfreechart-1.0.5.jar;"; //$NON-NLS-1$
+ private static String CLASSPATH = " -cp .;d:\\workspace_3.2\\punit.samples\\bin;d:\\workspace_3.2\\punit\\bin;d:\\workspace_3.2\\punit.extension\\bin;D:\\workspace_3.2\\punit.extension\\lib\\jcommon-1.0.9.jar;D:\\workspace_3.2\\punit.extension\\lib\\jfreechart-1.0.5.jar;"; //$NON-NLS-1$
private static String DRLVM_PATH = "D:\\harmony-jre-r530500\\bin\\java" + CLASSPATH; //$NON-NLS-1$
Modified: trunk/punit.test/src/tests/api/org/punit/runner/AnnotationFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/AnnotationFilterTest.java 2007-06-04 07:15:18 UTC (rev 200)
+++ trunk/punit.test/src/tests/api/org/punit/runner/AnnotationFilterTest.java 2007-06-07 03:40:32 UTC (rev 201)
@@ -10,6 +10,8 @@
import org.punit.runner.*;
import org.punit.util.*;
+import tests.api.org.punit.testclasses.*;
+
public class AnnotationFilterTest extends TestCase {
AnnotationFilter _filter = new AnnotationFilter();
@@ -63,6 +65,25 @@
assertNull(exception);
}
+ public void testGetConcurrentCount1() {
+ ConcurrentTestClass test = new ConcurrentTestClass();
+ int count = _filter.getConcurrentCount(test);
+ assertEquals(test.concurrentCount(), count);
+ assertEquals(0, _filter.getConcurrentCount(new TestClass()));
+ }
+
+ public void testGetConcurrentCountClass() {
+ AnnotationTestClass test = new AnnotationTestClass();
+ int count = _filter.getConcurrentCount(test);
+ assertEquals(5, count);
+ }
+
+ public void testGetConcurrentCountMethod() {
+ Method method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
+ int count = _filter.getConcurrentCount(method);
+ assertEquals(6, count);
+ }
+
public void _test1() {
}
Modified: trunk/punit.test/src/tests/api/org/punit/runner/NameConventionFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/NameConventionFilterTest.java 2007-06-04 07:15:18 UTC (rev 200)
+++ trunk/punit.test/src/tests/api/org/punit/runner/NameConventionFilterTest.java 2007-06-07 03:40:32 UTC (rev 201)
@@ -9,9 +9,12 @@
import org.punit.runner.*;
import org.punit.util.*;
+import tests.api.org.punit.testclasses.*;
+
public class NameConventionFilterTest extends TestCase {
- AnnotationFilter _filter = new AnnotationFilter();
+ NameConventionFilter _filter = new NameConventionFilter();
+
public void testIsTestMethod() {
Method method;
method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$
@@ -32,6 +35,12 @@
assertEquals("check__test2", checkMethod.getName()); //$NON-NLS-1$
}
+ public void testGetConcurrentCount() {
+ ConcurrentTestClass test = new ConcurrentTestClass();
+ int count = _filter.getConcurrentCount(test);
+ assertEquals(test.concurrentCount(), count);
+ assertEquals(0, _filter.getConcurrentCount(new TestClass()));
+ }
public void test1() {
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-06-04 07:15:18 UTC (rev 200)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-06-07 03:40:32 UTC (rev 201)
@@ -5,6 +5,7 @@
import org.punit.annotation.Test;
import org.punit.runner.*;
+@Test(concurrentCount=5)
public class AnnotationTestClass {
public static void main(String[] args) {
@@ -52,6 +53,7 @@
_test1 = true;
}
+ @Test(checkMethod="annotation_check_2", concurrentCount=6)
public void _test2() {
_test2 = true;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-06-14 13:17:02
|
Revision: 202
http://p-unit.svn.sourceforge.net/p-unit/?rev=202&view=rev
Author: zhanghuangzhu
Date: 2007-06-14 06:17:01 -0700 (Thu, 14 Jun 2007)
Log Message:
-----------
Andrew Zhang: First implementation for junit annotation support.
Modified Paths:
--------------
trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit/src/org/punit/runner/Filter.java
trunk/punit/src/org/punit/runner/NameConventionFilter.java
trunk/punit.extension/.classpath
trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java
Added Paths:
-----------
trunk/punit.extension/lib/junit-4.3.1.jar
trunk/punit.extension/src/org/punit/annotation/After.java
trunk/punit.extension/src/org/punit/annotation/AfterClass.java
trunk/punit.extension/src/org/punit/annotation/Before.java
trunk/punit.extension/src/org/punit/annotation/BeforeClass.java
trunk/punit.extension/src/org/punit/runner/JUnitAnnotationFilter.java
trunk/punit.extension/src/org/punit/util/
trunk/punit.extension/src/org/punit/util/AnnotationUtil.java
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-07 03:40:32 UTC (rev 201)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-14 13:17:01 UTC (rev 202)
@@ -33,10 +33,10 @@
protected transient Class _class;
- protected transient Method _tearDownMethod;
-
protected transient Method _setUpMethod;
+ protected transient Method _tearDownMethod;
+
private transient Method _checkMethod;
protected transient Class _expectedException;
@@ -136,10 +136,8 @@
_class = testInstance.getClass();
_params = params;
_method = method;
- _setUpMethod = ReflectionUtil.getMethodAndSetAccessible(_testInstance
- .getClass(), "setUp", new Class[] {}); //$NON-NLS-1$
- _tearDownMethod = ReflectionUtil.getMethodAndSetAccessible(
- _testInstance.getClass(), "tearDown", new Class[] {}); //$NON-NLS-1$
+ _setUpMethod = _filter.getSetupMethod(_class);
+ _tearDownMethod = _filter.getTearDownMethod(_class);
_checkMethod = _filter.getCheckMethod(method);
_expectedException = _filter.getExpectedException(method);
}
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-07 03:40:32 UTC (rev 201)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-14 13:17:01 UTC (rev 202)
@@ -32,6 +32,8 @@
private ExecutorPool _executorPool;
+ private Filter _filter;
+
public AbstractRunner(TestSuiteBuilder testSuiteBuiler,
TestMethodBuilder testMethodBuilder, MethodRunner testMethodRunner) {
_testSuiteBuiler = testSuiteBuiler;
@@ -44,6 +46,7 @@
}
public void setFilter(Filter filter) {
+ _filter = filter;
_testSuiteBuiler.setFilter(filter);
_testMethodBuilder.setMethodFilter(filter);
_methodRunner.setMethodFilter(filter);
@@ -235,16 +238,39 @@
private void runTestClassImpl(final Class clazz) {
onClassStart(clazz);
- Collection testMethods = buildTestMethod(clazz);
- TraverserUtil.traverse(testMethods.iterator(), new Traverser() {
- public void traverse(Object obj) {
- Method method = (Method) obj;
- runTestMethod(clazz, method);
+ try {
+ beforeClass(clazz);
+ Collection testMethods = buildTestMethod(clazz);
+ TraverserUtil.traverse(testMethods.iterator(), new Traverser() {
+ public void traverse(Object obj) {
+ Method method = (Method) obj;
+ runTestMethod(clazz, method);
+ }
+ });
+ } finally {
+ try {
+ afterClass(clazz);
+ }catch (Throwable t) {
+ // TODO: will be passed to onClassEnd
}
- });
+ }
onClassEnd(clazz);
}
+ private void beforeClass(Class clazz) {
+ Method beforeClassMethod = _filter.getBeforeClassMethod(clazz);
+ if(beforeClassMethod != null) {
+ ReflectionUtil.invokeMethod(beforeClassMethod, null, new Object[] {});
+ }
+ }
+
+ private void afterClass(Class clazz) {
+ Method afterClassMethod = _filter.getAfterClassMethod(clazz);
+ 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) {
Modified: trunk/punit/src/org/punit/runner/Filter.java
===================================================================
--- trunk/punit/src/org/punit/runner/Filter.java 2007-06-07 03:40:32 UTC (rev 201)
+++ trunk/punit/src/org/punit/runner/Filter.java 2007-06-14 13:17:01 UTC (rev 202)
@@ -35,4 +35,12 @@
public int getConcurrentCount(Method method);
public int getConcurrentCount(Object testInstance);
+
+ public Method getSetupMethod(Class test);
+
+ public Method getTearDownMethod(Class test);
+
+ public Method getBeforeClassMethod(Class test);
+
+ public Method getAfterClassMethod(Class test);
}
Modified: trunk/punit/src/org/punit/runner/NameConventionFilter.java
===================================================================
--- trunk/punit/src/org/punit/runner/NameConventionFilter.java 2007-06-07 03:40:32 UTC (rev 201)
+++ trunk/punit/src/org/punit/runner/NameConventionFilter.java 2007-06-14 13:17:01 UTC (rev 202)
@@ -96,5 +96,21 @@
return 0;
}
+ public Method getAfterClassMethod(Class test) {
+ return ReflectionUtil.getMethodAndSetAccessible(test, "beforeClass", new Class[] {}); //$NON-NLS-1$
+ }
+
+ public Method getBeforeClassMethod(Class test) {
+ return ReflectionUtil.getMethodAndSetAccessible(test, "afterClass", new Class[] {}); //$NON-NLS-1$
+ }
+
+ public Method getSetupMethod(Class test) {
+ return ReflectionUtil.getMethodAndSetAccessible(test, "setUp", new Class[] {}); //$NON-NLS-1$
+ }
+
+ public Method getTearDownMethod(Class test) {
+ return ReflectionUtil.getMethodAndSetAccessible(test, "tearDown", new Class[] {}); //$NON-NLS-1$
+ }
+
}
Modified: trunk/punit.extension/.classpath
===================================================================
--- trunk/punit.extension/.classpath 2007-06-07 03:40:32 UTC (rev 201)
+++ trunk/punit.extension/.classpath 2007-06-14 13:17:01 UTC (rev 202)
@@ -6,5 +6,6 @@
<classpathentry path="lib/jfreechart-1.0.5.jar" exported="true" kind="lib"/>
<classpathentry path="lib/jcommon-1.0.9.jar" exported="true" kind="lib"/>
<classpathentry path="lib/itext-2.0.2.jar" kind="lib"/>
+ <classpathentry path="lib/junit-4.3.1.jar" kind="lib"/>
<classpathentry path="bin" kind="output"/>
</classpath>
Added: trunk/punit.extension/lib/junit-4.3.1.jar
===================================================================
(Binary files differ)
Property changes on: trunk/punit.extension/lib/junit-4.3.1.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/punit.extension/src/org/punit/annotation/After.java
===================================================================
--- trunk/punit.extension/src/org/punit/annotation/After.java (rev 0)
+++ trunk/punit.extension/src/org/punit/annotation/After.java 2007-06-14 13:17:01 UTC (rev 202)
@@ -0,0 +1,11 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+package org.punit.annotation;
+
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+
+public @interface After {
+
+}
Added: trunk/punit.extension/src/org/punit/annotation/AfterClass.java
===================================================================
--- trunk/punit.extension/src/org/punit/annotation/AfterClass.java (rev 0)
+++ trunk/punit.extension/src/org/punit/annotation/AfterClass.java 2007-06-14 13:17:01 UTC (rev 202)
@@ -0,0 +1,11 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+package org.punit.annotation;
+
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+
+public @interface AfterClass {
+
+}
Added: trunk/punit.extension/src/org/punit/annotation/Before.java
===================================================================
--- trunk/punit.extension/src/org/punit/annotation/Before.java (rev 0)
+++ trunk/punit.extension/src/org/punit/annotation/Before.java 2007-06-14 13:17:01 UTC (rev 202)
@@ -0,0 +1,11 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+package org.punit.annotation;
+
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+
+public @interface Before {
+
+}
Added: trunk/punit.extension/src/org/punit/annotation/BeforeClass.java
===================================================================
--- trunk/punit.extension/src/org/punit/annotation/BeforeClass.java (rev 0)
+++ trunk/punit.extension/src/org/punit/annotation/BeforeClass.java 2007-06-14 13:17:01 UTC (rev 202)
@@ -0,0 +1,11 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+package org.punit.annotation;
+
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+
+public @interface BeforeClass {
+
+}
Modified: trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java 2007-06-07 03:40:32 UTC (rev 201)
+++ trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java 2007-06-14 13:17:01 UTC (rev 202)
@@ -1,3 +1,5 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
package org.punit.runner;
import java.lang.reflect.*;
@@ -10,7 +12,7 @@
private static final long serialVersionUID = -2043378593194849589L;
- NameConventionFilter _delegate = new NameConventionFilter();
+ private NameConventionFilter _delegate = new NameConventionFilter();
public Method getCheckMethod(Method method) {
Test testAnnotation = getTestAnnotation(method);
@@ -74,4 +76,36 @@
private Test getTestAnnotation(Class<?> clazz) {
return (Test) clazz.getAnnotation(Test.class);
}
+
+ public Method getAfterClassMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, AfterClass.class);
+ if(method == null) {
+ method = _delegate.getAfterClassMethod(test);
+ }
+ return method;
+ }
+
+ public Method getBeforeClassMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, BeforeClass.class);
+ if(method == null) {
+ method = _delegate.getBeforeClassMethod(test);
+ }
+ return method;
+ }
+
+ public Method getSetupMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, Before.class);
+ if(method == null) {
+ method = _delegate.getSetupMethod(test);
+ }
+ return method;
+ }
+
+ public Method getTearDownMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, After.class);
+ if(method == null) {
+ method = _delegate.getTearDownMethod(test);
+ }
+ return method;
+ }
}
Added: trunk/punit.extension/src/org/punit/runner/JUnitAnnotationFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/runner/JUnitAnnotationFilter.java (rev 0)
+++ trunk/punit.extension/src/org/punit/runner/JUnitAnnotationFilter.java 2007-06-14 13:17:01 UTC (rev 202)
@@ -0,0 +1,85 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.runner;
+
+import java.lang.reflect.*;
+
+import org.junit.*;
+import org.punit.annotation.Test.*;
+import org.punit.util.*;
+
+public class JUnitAnnotationFilter implements Filter {
+
+ private static final long serialVersionUID = 2826000346348614825L;
+
+ private NameConventionFilter _delegate = new NameConventionFilter();
+
+ public Method getCheckMethod(Method method) {
+ return _delegate.getCheckMethod(method);
+ }
+
+ public boolean isExcluded(Class clazz) {
+ return false;
+ }
+
+ public boolean isTestMethod(Method method) {
+ Test testAnnotation = getTestAnnotation(method);
+ return (testAnnotation != null) || _delegate.isTestMethod(method);
+ }
+
+ public Class<? extends Throwable> getExpectedException(Method method) {
+ Test testAnnotation = getTestAnnotation(method);
+ if(testAnnotation == null) {
+ return null;
+ }
+ Class<? extends Throwable> expected = testAnnotation.expected();
+ if(expected == NoException.class) {
+ return null;
+ }
+ return expected;
+ }
+
+ public int getConcurrentCount(Method method) {
+ return 0;
+ }
+
+ public int getConcurrentCount(Object testInstnace) {
+ return _delegate.getConcurrentCount(testInstnace);
+ }
+
+ private Test getTestAnnotation(Method method) {
+ return method.getAnnotation(Test.class);
+ }
+
+ public Method getAfterClassMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, AfterClass.class);
+ if(method == null) {
+ method = _delegate.getAfterClassMethod(test);
+ }
+ return method;
+ }
+
+ public Method getBeforeClassMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, BeforeClass.class);
+ if(method == null) {
+ method = _delegate.getBeforeClassMethod(test);
+ }
+ return method;
+ }
+
+ public Method getSetupMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, Before.class);
+ if(method == null) {
+ method = _delegate.getSetupMethod(test);
+ }
+ return method;
+ }
+
+ public Method getTearDownMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, After.class);
+ if(method == null) {
+ method = _delegate.getTearDownMethod(test);
+ }
+ return method;
+ }
+}
Added: trunk/punit.extension/src/org/punit/util/AnnotationUtil.java
===================================================================
--- trunk/punit.extension/src/org/punit/util/AnnotationUtil.java (rev 0)
+++ trunk/punit.extension/src/org/punit/util/AnnotationUtil.java 2007-06-14 13:17:01 UTC (rev 202)
@@ -0,0 +1,22 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.util;
+
+import java.lang.annotation.*;
+import java.lang.reflect.*;
+
+public class AnnotationUtil {
+
+ public static <T extends Annotation> Method getMethodByAnnotation(Class clazz, Class <T> annotationClass) {
+ Method[] methods = clazz.getDeclaredMethods();
+ for(int i = 0; i < methods.length; ++i) {
+ Method method = methods[i];
+ Annotation annotation = method.getAnnotation(annotationClass);
+ if(annotation != null) {
+ method.setAccessible(true);
+ return method;
+ }
+ }
+ return null;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-06-14 13:53:57
|
Revision: 203
http://p-unit.svn.sourceforge.net/p-unit/?rev=203&view=rev
Author: zhanghuangzhu
Date: 2007-06-14 06:53:58 -0700 (Thu, 14 Jun 2007)
Log Message:
-----------
Andrew Zhang: refactored package name.
Modified Paths:
--------------
trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
trunk/punit/src/org/punit/method/runner/MethodRunner.java
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
trunk/punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/runner/AnnotationFilterTest.java
trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/NameConventionFilterTest.java
trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/suite/builder/TestSuiteBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
Added Paths:
-----------
trunk/punit/src/org/punit/filter/
trunk/punit/src/org/punit/filter/Filter.java
trunk/punit/src/org/punit/filter/NameConventionFilter.java
trunk/punit.extension/src/org/punit/filter/
trunk/punit.extension/src/org/punit/filter/AnnotationFilter.java
trunk/punit.extension/src/org/punit/filter/JUnitAnnotationFilter.java
Removed Paths:
-------------
trunk/punit/src/org/punit/runner/Filter.java
trunk/punit/src/org/punit/runner/NameConventionFilter.java
trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java
trunk/punit.extension/src/org/punit/runner/JUnitAnnotationFilter.java
Copied: trunk/punit/src/org/punit/filter/Filter.java (from rev 202, trunk/punit/src/org/punit/runner/Filter.java)
===================================================================
--- trunk/punit/src/org/punit/filter/Filter.java (rev 0)
+++ trunk/punit/src/org/punit/filter/Filter.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -0,0 +1,46 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.filter;
+
+import java.io.*;
+import java.lang.reflect.*;
+
+public interface Filter extends Serializable {
+
+ /**
+ * Judges whether this test class is excluded.
+ *
+ * @return returns true if the test class is excluded.
+ */
+ public boolean isExcluded(Class clazz);
+
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @return returns true if it is a test method.
+ */
+ public boolean isTestMethod(Method method);
+
+ /**
+ * Gets the corresponding check method to this test method
+ *
+ * @param method
+ * the test method
+ * @return
+ */
+ public Method getCheckMethod(Method method);
+
+ public Class getExpectedException(Method method);
+
+ public int getConcurrentCount(Method method);
+
+ public int getConcurrentCount(Object testInstance);
+
+ public Method getSetupMethod(Class test);
+
+ public Method getTearDownMethod(Class test);
+
+ public Method getBeforeClassMethod(Class test);
+
+ public Method getAfterClassMethod(Class test);
+}
Copied: trunk/punit/src/org/punit/filter/NameConventionFilter.java (from rev 202, trunk/punit/src/org/punit/runner/NameConventionFilter.java)
===================================================================
--- trunk/punit/src/org/punit/filter/NameConventionFilter.java (rev 0)
+++ trunk/punit/src/org/punit/filter/NameConventionFilter.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -0,0 +1,117 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.filter;
+
+import java.lang.reflect.*;
+
+import org.punit.filter.*;
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class NameConventionFilter implements Filter {
+
+ private static final long serialVersionUID = -1252188754463864599L;
+
+ public boolean isExcluded(Class method) {
+ return false;
+ }
+
+ public Method getCheckMethod(Method method) {
+ String checkMethodName = "check_" + method.getName(); //$NON-NLS-1$
+ return ReflectionUtil.getMethod(method.getDeclaringClass(),
+ checkMethodName, method.getParameterTypes());
+ }
+
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @return returns true if the test modifier, name, and parameter conform to
+ * the convention of a test method.
+ */
+ public boolean isTestMethod(Method method) {
+ return isModifierValid(method) && isNameValid(method)
+ && isParamValid(method);
+ }
+
+ /**
+ * Judeges whether the modifier of is method conforms to the convention of a
+ * test method.
+ *
+ * @param method
+ * to be judged
+ * @return returns true if this method is public and non static.
+ */
+ protected boolean isModifierValid(Method method) {
+ return ReflectionUtil.isPublic(method)
+ && !ReflectionUtil.isStatic(method);
+ }
+
+ /**
+ * Judeges whether the name of is method conforms to the convention of a
+ * test method.
+ *
+ * @param method
+ * to be judged
+ * @return returns true if the name of this method starts with "test", or
+ * the name is in the list of test interfaces which are added by
+ * <code>TestMethodBuilder.addTestInterfaces</code>
+ */
+ protected boolean isNameValid(Method method) {
+ String name = method.getName();
+ return name.startsWith("test"); //$NON-NLS-1$
+ }
+
+ /**
+ * Judges whether the paramaters of this method conforms to the convention
+ * of a test method.
+ *
+ * @param method
+ * @return returns true if the parameter length is zero and the test class
+ * is not marked as <code>Parameterizable</code>, or the
+ * parameter length is 1, and the parameter is assignable from
+ * <code>Parameter</code>.
+ */
+ protected boolean isParamValid(Method method) {
+ Class clazz = method.getDeclaringClass();
+ Class[] params = method.getParameterTypes();
+ if (TypeUtil.isPUnitParameterizableTest((clazz))) {
+ return params.length == 1
+ && Parameter.class.isAssignableFrom(params[0]);
+ } else {
+ return params.length == 0;
+ }
+ }
+
+ public Class getExpectedException(Method method) {
+ return null;
+ }
+
+ public int getConcurrentCount(Method method) {
+ return 0;
+ }
+
+ public int getConcurrentCount(Object testInstance) {
+ if(testInstance instanceof Concurrent) {
+ return ((Concurrent)testInstance).concurrentCount();
+ }
+ return 0;
+ }
+
+ public Method getAfterClassMethod(Class test) {
+ return ReflectionUtil.getMethodAndSetAccessible(test, "beforeClass", new Class[] {}); //$NON-NLS-1$
+ }
+
+ public Method getBeforeClassMethod(Class test) {
+ return ReflectionUtil.getMethodAndSetAccessible(test, "afterClass", new Class[] {}); //$NON-NLS-1$
+ }
+
+ public Method getSetupMethod(Class test) {
+ return ReflectionUtil.getMethodAndSetAccessible(test, "setUp", new Class[] {}); //$NON-NLS-1$
+ }
+
+ public Method getTearDownMethod(Class test) {
+ return ReflectionUtil.getMethodAndSetAccessible(test, "tearDown", new Class[] {}); //$NON-NLS-1$
+ }
+
+
+}
Modified: trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-06-14 13:17:01 UTC (rev 202)
+++ trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -5,6 +5,7 @@
import java.lang.reflect.*;
import java.util.*;
+import org.punit.filter.*;
import org.punit.runner.*;
import org.punit.type.*;
Modified: trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-06-14 13:17:01 UTC (rev 202)
+++ trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -5,6 +5,7 @@
import java.io.*;
import java.util.*;
+import org.punit.filter.*;
import org.punit.runner.*;
/**
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-14 13:17:01 UTC (rev 202)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -8,6 +8,7 @@
import org.punit.assertion.*;
import org.punit.events.*;
import org.punit.exception.*;
+import org.punit.filter.*;
import org.punit.runner.*;
import org.punit.type.*;
import org.punit.util.*;
Modified: trunk/punit/src/org/punit/method/runner/MethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/MethodRunner.java 2007-06-14 13:17:01 UTC (rev 202)
+++ trunk/punit/src/org/punit/method/runner/MethodRunner.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -4,6 +4,7 @@
import java.lang.reflect.*;
import java.util.*;
+import org.punit.filter.*;
import org.punit.runner.*;
import org.punit.watcher.*;
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-14 13:17:01 UTC (rev 202)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -8,6 +8,7 @@
import org.punit.events.*;
import org.punit.exception.*;
+import org.punit.filter.*;
import org.punit.method.builder.*;
import org.punit.method.runner.*;
import org.punit.reporter.stream.console.*;
Deleted: trunk/punit/src/org/punit/runner/Filter.java
===================================================================
--- trunk/punit/src/org/punit/runner/Filter.java 2007-06-14 13:17:01 UTC (rev 202)
+++ trunk/punit/src/org/punit/runner/Filter.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -1,46 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.runner;
-
-import java.io.*;
-import java.lang.reflect.*;
-
-public interface Filter extends Serializable {
-
- /**
- * Judges whether this test class is excluded.
- *
- * @return returns true if the test class is excluded.
- */
- public boolean isExcluded(Class clazz);
-
- /**
- * Judges whether this method is a test method.
- *
- * @return returns true if it is a test method.
- */
- public boolean isTestMethod(Method method);
-
- /**
- * Gets the corresponding check method to this test method
- *
- * @param method
- * the test method
- * @return
- */
- public Method getCheckMethod(Method method);
-
- public Class getExpectedException(Method method);
-
- public int getConcurrentCount(Method method);
-
- public int getConcurrentCount(Object testInstance);
-
- public Method getSetupMethod(Class test);
-
- public Method getTearDownMethod(Class test);
-
- public Method getBeforeClassMethod(Class test);
-
- public Method getAfterClassMethod(Class test);
-}
Deleted: trunk/punit/src/org/punit/runner/NameConventionFilter.java
===================================================================
--- trunk/punit/src/org/punit/runner/NameConventionFilter.java 2007-06-14 13:17:01 UTC (rev 202)
+++ trunk/punit/src/org/punit/runner/NameConventionFilter.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -1,116 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.runner;
-
-import java.lang.reflect.*;
-
-import org.punit.type.*;
-import org.punit.util.*;
-
-public class NameConventionFilter implements Filter {
-
- private static final long serialVersionUID = -1252188754463864599L;
-
- public boolean isExcluded(Class method) {
- return false;
- }
-
- public Method getCheckMethod(Method method) {
- String checkMethodName = "check_" + method.getName(); //$NON-NLS-1$
- return ReflectionUtil.getMethod(method.getDeclaringClass(),
- checkMethodName, method.getParameterTypes());
- }
-
- /**
- * Judges whether this method is a test method.
- *
- * @return returns true if the test modifier, name, and parameter conform to
- * the convention of a test method.
- */
- public boolean isTestMethod(Method method) {
- return isModifierValid(method) && isNameValid(method)
- && isParamValid(method);
- }
-
- /**
- * Judeges whether the modifier of is method conforms to the convention of a
- * test method.
- *
- * @param method
- * to be judged
- * @return returns true if this method is public and non static.
- */
- protected boolean isModifierValid(Method method) {
- return ReflectionUtil.isPublic(method)
- && !ReflectionUtil.isStatic(method);
- }
-
- /**
- * Judeges whether the name of is method conforms to the convention of a
- * test method.
- *
- * @param method
- * to be judged
- * @return returns true if the name of this method starts with "test", or
- * the name is in the list of test interfaces which are added by
- * <code>TestMethodBuilder.addTestInterfaces</code>
- */
- protected boolean isNameValid(Method method) {
- String name = method.getName();
- return name.startsWith("test"); //$NON-NLS-1$
- }
-
- /**
- * Judges whether the paramaters of this method conforms to the convention
- * of a test method.
- *
- * @param method
- * @return returns true if the parameter length is zero and the test class
- * is not marked as <code>Parameterizable</code>, or the
- * parameter length is 1, and the parameter is assignable from
- * <code>Parameter</code>.
- */
- protected boolean isParamValid(Method method) {
- Class clazz = method.getDeclaringClass();
- Class[] params = method.getParameterTypes();
- if (TypeUtil.isPUnitParameterizableTest((clazz))) {
- return params.length == 1
- && Parameter.class.isAssignableFrom(params[0]);
- } else {
- return params.length == 0;
- }
- }
-
- public Class getExpectedException(Method method) {
- return null;
- }
-
- public int getConcurrentCount(Method method) {
- return 0;
- }
-
- public int getConcurrentCount(Object testInstance) {
- if(testInstance instanceof Concurrent) {
- return ((Concurrent)testInstance).concurrentCount();
- }
- return 0;
- }
-
- public Method getAfterClassMethod(Class test) {
- return ReflectionUtil.getMethodAndSetAccessible(test, "beforeClass", new Class[] {}); //$NON-NLS-1$
- }
-
- public Method getBeforeClassMethod(Class test) {
- return ReflectionUtil.getMethodAndSetAccessible(test, "afterClass", new Class[] {}); //$NON-NLS-1$
- }
-
- public Method getSetupMethod(Class test) {
- return ReflectionUtil.getMethodAndSetAccessible(test, "setUp", new Class[] {}); //$NON-NLS-1$
- }
-
- public Method getTearDownMethod(Class test) {
- return ReflectionUtil.getMethodAndSetAccessible(test, "tearDown", new Class[] {}); //$NON-NLS-1$
- }
-
-
-}
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-14 13:17:01 UTC (rev 202)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -4,6 +4,7 @@
import java.io.*;
+import org.punit.filter.*;
import org.punit.runner.*;
/**
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-14 13:17:01 UTC (rev 202)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -4,6 +4,7 @@
import java.util.*;
+import org.punit.filter.*;
import org.punit.runner.*;
import org.punit.type.*;
import org.punit.util.*;
Copied: trunk/punit.extension/src/org/punit/filter/AnnotationFilter.java (from rev 202, trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java)
===================================================================
--- trunk/punit.extension/src/org/punit/filter/AnnotationFilter.java (rev 0)
+++ trunk/punit.extension/src/org/punit/filter/AnnotationFilter.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -0,0 +1,112 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.filter;
+
+import java.lang.reflect.*;
+
+import org.punit.annotation.*;
+import org.punit.annotation.Test.*;
+import org.punit.filter.*;
+import org.punit.util.*;
+
+public class AnnotationFilter implements Filter {
+
+ private static final long serialVersionUID = -2043378593194849589L;
+
+ private NameConventionFilter _delegate = new NameConventionFilter();
+
+ public Method getCheckMethod(Method method) {
+ Test testAnnotation = getTestAnnotation(method);
+ String checkMethodName = null;
+ if (testAnnotation != null) {
+ checkMethodName = testAnnotation.checkMethod();
+ if (checkMethodName != null && checkMethodName.length() > 0) {
+ return ReflectionUtil.getMethod(method.getDeclaringClass(),
+ checkMethodName, method.getParameterTypes());
+ }
+ }
+ return _delegate.getCheckMethod(method);
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean isExcluded(Class clazz) {
+ Test testAnnotation = getTestAnnotation(clazz);
+ if(testAnnotation == null) {
+ return false;
+ }
+ return testAnnotation.excluded();
+ }
+
+ public boolean isTestMethod(Method method) {
+ Test testAnnotation = getTestAnnotation(method);
+ return (testAnnotation != null) || _delegate.isTestMethod(method);
+ }
+
+ public Class<? extends Throwable> getExpectedException(Method method) {
+ Test testAnnotation = getTestAnnotation(method);
+ if(testAnnotation == null) {
+ return null;
+ }
+ Class<? extends Throwable> expected = testAnnotation.expected();
+ if(expected == NoException.class) {
+ return null;
+ }
+ return expected;
+ }
+
+ public int getConcurrentCount(Method method) {
+ Test testAnnotation = getTestAnnotation(method);
+ if(testAnnotation == null) {
+ return 0;
+ }
+ return testAnnotation.concurrentCount();
+ }
+
+ public int getConcurrentCount(Object testInstnace) {
+ Test testAnnotation = getTestAnnotation(testInstnace.getClass());
+ if(testAnnotation == null) {
+ return _delegate.getConcurrentCount(testInstnace);
+ }
+ return testAnnotation.concurrentCount();
+ }
+
+ private Test getTestAnnotation(Method method) {
+ return method.getAnnotation(Test.class);
+ }
+
+ private Test getTestAnnotation(Class<?> clazz) {
+ return (Test) clazz.getAnnotation(Test.class);
+ }
+
+ public Method getAfterClassMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, AfterClass.class);
+ if(method == null) {
+ method = _delegate.getAfterClassMethod(test);
+ }
+ return method;
+ }
+
+ public Method getBeforeClassMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, BeforeClass.class);
+ if(method == null) {
+ method = _delegate.getBeforeClassMethod(test);
+ }
+ return method;
+ }
+
+ public Method getSetupMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, Before.class);
+ if(method == null) {
+ method = _delegate.getSetupMethod(test);
+ }
+ return method;
+ }
+
+ public Method getTearDownMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, After.class);
+ if(method == null) {
+ method = _delegate.getTearDownMethod(test);
+ }
+ return method;
+ }
+}
Copied: trunk/punit.extension/src/org/punit/filter/JUnitAnnotationFilter.java (from rev 202, trunk/punit.extension/src/org/punit/runner/JUnitAnnotationFilter.java)
===================================================================
--- trunk/punit.extension/src/org/punit/filter/JUnitAnnotationFilter.java (rev 0)
+++ trunk/punit.extension/src/org/punit/filter/JUnitAnnotationFilter.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -0,0 +1,86 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.filter;
+
+import java.lang.reflect.*;
+
+import org.junit.*;
+import org.punit.annotation.Test.*;
+import org.punit.filter.*;
+import org.punit.util.*;
+
+public class JUnitAnnotationFilter implements Filter {
+
+ private static final long serialVersionUID = 2826000346348614825L;
+
+ private NameConventionFilter _delegate = new NameConventionFilter();
+
+ public Method getCheckMethod(Method method) {
+ return _delegate.getCheckMethod(method);
+ }
+
+ public boolean isExcluded(Class clazz) {
+ return false;
+ }
+
+ public boolean isTestMethod(Method method) {
+ Test testAnnotation = getTestAnnotation(method);
+ return (testAnnotation != null) || _delegate.isTestMethod(method);
+ }
+
+ public Class<? extends Throwable> getExpectedException(Method method) {
+ Test testAnnotation = getTestAnnotation(method);
+ if(testAnnotation == null) {
+ return null;
+ }
+ Class<? extends Throwable> expected = testAnnotation.expected();
+ if(expected == NoException.class) {
+ return null;
+ }
+ return expected;
+ }
+
+ public int getConcurrentCount(Method method) {
+ return 0;
+ }
+
+ public int getConcurrentCount(Object testInstnace) {
+ return _delegate.getConcurrentCount(testInstnace);
+ }
+
+ private Test getTestAnnotation(Method method) {
+ return method.getAnnotation(Test.class);
+ }
+
+ public Method getAfterClassMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, AfterClass.class);
+ if(method == null) {
+ method = _delegate.getAfterClassMethod(test);
+ }
+ return method;
+ }
+
+ public Method getBeforeClassMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, BeforeClass.class);
+ if(method == null) {
+ method = _delegate.getBeforeClassMethod(test);
+ }
+ return method;
+ }
+
+ public Method getSetupMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, Before.class);
+ if(method == null) {
+ method = _delegate.getSetupMethod(test);
+ }
+ return method;
+ }
+
+ public Method getTearDownMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, After.class);
+ if(method == null) {
+ method = _delegate.getTearDownMethod(test);
+ }
+ return method;
+ }
+}
Deleted: trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java 2007-06-14 13:17:01 UTC (rev 202)
+++ trunk/punit.extension/src/org/punit/runner/AnnotationFilter.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -1,111 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.runner;
-
-import java.lang.reflect.*;
-
-import org.punit.annotation.*;
-import org.punit.annotation.Test.*;
-import org.punit.util.*;
-
-public class AnnotationFilter implements Filter {
-
- private static final long serialVersionUID = -2043378593194849589L;
-
- private NameConventionFilter _delegate = new NameConventionFilter();
-
- public Method getCheckMethod(Method method) {
- Test testAnnotation = getTestAnnotation(method);
- String checkMethodName = null;
- if (testAnnotation != null) {
- checkMethodName = testAnnotation.checkMethod();
- if (checkMethodName != null && checkMethodName.length() > 0) {
- return ReflectionUtil.getMethod(method.getDeclaringClass(),
- checkMethodName, method.getParameterTypes());
- }
- }
- return _delegate.getCheckMethod(method);
- }
-
- @SuppressWarnings("unchecked")
- public boolean isExcluded(Class clazz) {
- Test testAnnotation = getTestAnnotation(clazz);
- if(testAnnotation == null) {
- return false;
- }
- return testAnnotation.excluded();
- }
-
- public boolean isTestMethod(Method method) {
- Test testAnnotation = getTestAnnotation(method);
- return (testAnnotation != null) || _delegate.isTestMethod(method);
- }
-
- public Class<? extends Throwable> getExpectedException(Method method) {
- Test testAnnotation = getTestAnnotation(method);
- if(testAnnotation == null) {
- return null;
- }
- Class<? extends Throwable> expected = testAnnotation.expected();
- if(expected == NoException.class) {
- return null;
- }
- return expected;
- }
-
- public int getConcurrentCount(Method method) {
- Test testAnnotation = getTestAnnotation(method);
- if(testAnnotation == null) {
- return 0;
- }
- return testAnnotation.concurrentCount();
- }
-
- public int getConcurrentCount(Object testInstnace) {
- Test testAnnotation = getTestAnnotation(testInstnace.getClass());
- if(testAnnotation == null) {
- return _delegate.getConcurrentCount(testInstnace);
- }
- return testAnnotation.concurrentCount();
- }
-
- private Test getTestAnnotation(Method method) {
- return method.getAnnotation(Test.class);
- }
-
- private Test getTestAnnotation(Class<?> clazz) {
- return (Test) clazz.getAnnotation(Test.class);
- }
-
- public Method getAfterClassMethod(Class test) {
- Method method = AnnotationUtil.getMethodByAnnotation(test, AfterClass.class);
- if(method == null) {
- method = _delegate.getAfterClassMethod(test);
- }
- return method;
- }
-
- public Method getBeforeClassMethod(Class test) {
- Method method = AnnotationUtil.getMethodByAnnotation(test, BeforeClass.class);
- if(method == null) {
- method = _delegate.getBeforeClassMethod(test);
- }
- return method;
- }
-
- public Method getSetupMethod(Class test) {
- Method method = AnnotationUtil.getMethodByAnnotation(test, Before.class);
- if(method == null) {
- method = _delegate.getSetupMethod(test);
- }
- return method;
- }
-
- public Method getTearDownMethod(Class test) {
- Method method = AnnotationUtil.getMethodByAnnotation(test, After.class);
- if(method == null) {
- method = _delegate.getTearDownMethod(test);
- }
- return method;
- }
-}
Deleted: trunk/punit.extension/src/org/punit/runner/JUnitAnnotationFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/runner/JUnitAnnotationFilter.java 2007-06-14 13:17:01 UTC (rev 202)
+++ trunk/punit.extension/src/org/punit/runner/JUnitAnnotationFilter.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -1,85 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.runner;
-
-import java.lang.reflect.*;
-
-import org.junit.*;
-import org.punit.annotation.Test.*;
-import org.punit.util.*;
-
-public class JUnitAnnotationFilter implements Filter {
-
- private static final long serialVersionUID = 2826000346348614825L;
-
- private NameConventionFilter _delegate = new NameConventionFilter();
-
- public Method getCheckMethod(Method method) {
- return _delegate.getCheckMethod(method);
- }
-
- public boolean isExcluded(Class clazz) {
- return false;
- }
-
- public boolean isTestMethod(Method method) {
- Test testAnnotation = getTestAnnotation(method);
- return (testAnnotation != null) || _delegate.isTestMethod(method);
- }
-
- public Class<? extends Throwable> getExpectedException(Method method) {
- Test testAnnotation = getTestAnnotation(method);
- if(testAnnotation == null) {
- return null;
- }
- Class<? extends Throwable> expected = testAnnotation.expected();
- if(expected == NoException.class) {
- return null;
- }
- return expected;
- }
-
- public int getConcurrentCount(Method method) {
- return 0;
- }
-
- public int getConcurrentCount(Object testInstnace) {
- return _delegate.getConcurrentCount(testInstnace);
- }
-
- private Test getTestAnnotation(Method method) {
- return method.getAnnotation(Test.class);
- }
-
- public Method getAfterClassMethod(Class test) {
- Method method = AnnotationUtil.getMethodByAnnotation(test, AfterClass.class);
- if(method == null) {
- method = _delegate.getAfterClassMethod(test);
- }
- return method;
- }
-
- public Method getBeforeClassMethod(Class test) {
- Method method = AnnotationUtil.getMethodByAnnotation(test, BeforeClass.class);
- if(method == null) {
- method = _delegate.getBeforeClassMethod(test);
- }
- return method;
- }
-
- public Method getSetupMethod(Class test) {
- Method method = AnnotationUtil.getMethodByAnnotation(test, Before.class);
- if(method == null) {
- method = _delegate.getSetupMethod(test);
- }
- return method;
- }
-
- public Method getTearDownMethod(Class test) {
- Method method = AnnotationUtil.getMethodByAnnotation(test, After.class);
- if(method == null) {
- method = _delegate.getTearDownMethod(test);
- }
- return method;
- }
-}
Modified: trunk/punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java 2007-06-14 13:17:01 UTC (rev 202)
+++ trunk/punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -2,6 +2,7 @@
import junit.framework.*;
+import org.punit.filter.*;
import org.punit.method.builder.*;
import org.punit.runner.*;
Modified: trunk/punit.test/src/tests/api/org/punit/runner/AnnotationFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/AnnotationFilterTest.java 2007-06-14 13:17:01 UTC (rev 202)
+++ trunk/punit.test/src/tests/api/org/punit/runner/AnnotationFilterTest.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -7,6 +7,7 @@
import junit.framework.*;
import org.punit.annotation.Test;
+import org.punit.filter.*;
import org.punit.runner.*;
import org.punit.util.*;
Modified: trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2007-06-14 13:17:01 UTC (rev 202)
+++ trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2007-06-14 13:53:58 UTC (rev 203)
@@ -6,6 +6,7 @@
import junit.framework.*;
+import org.punit.filter.*;
import org.punit.runner.*;
import tests.api.org.punit.testclasses.*;
Modified: trunk/punit.test/src/tests/api/org/punit/runner/NameConventionFilterTest.ja...
[truncated message content] |
|
From: <zha...@us...> - 2007-06-14 15:12:59
|
Revision: 205
http://p-unit.svn.sourceforge.net/p-unit/?rev=205&view=rev
Author: zhanghuangzhu
Date: 2007-06-14 08:12:59 -0700 (Thu, 14 Jun 2007)
Log Message:
-----------
Andrew Zhang: refined test cases and implementation.
Modified Paths:
--------------
trunk/punit/src/org/punit/filter/NameConventionFilter.java
trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
trunk/punit.extension/.classpath
trunk/punit.extension/src/org/punit/annotation/AfterClass.java
trunk/punit.extension/src/org/punit/annotation/BeforeClass.java
trunk/punit.test/.classpath
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass.java
Added Paths:
-----------
trunk/punit.test/src/tests/api/org/punit/filter/
trunk/punit.test/src/tests/api/org/punit/filter/AnnotationFilterTest.java
trunk/punit.test/src/tests/api/org/punit/filter/JUnitAnnotationConventionTest.java
trunk/punit.test/src/tests/api/org/punit/filter/NameConventionFilterTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/JUnitAnnotationTestClass.java
Removed Paths:
-------------
trunk/punit.test/src/tests/api/org/punit/runner/AnnotationFilterTest.java
trunk/punit.test/src/tests/api/org/punit/runner/NameConventionFilterTest.java
Modified: trunk/punit/src/org/punit/filter/NameConventionFilter.java
===================================================================
--- trunk/punit/src/org/punit/filter/NameConventionFilter.java 2007-06-14 13:58:12 UTC (rev 204)
+++ trunk/punit/src/org/punit/filter/NameConventionFilter.java 2007-06-14 15:12:59 UTC (rev 205)
@@ -4,7 +4,6 @@
import java.lang.reflect.*;
-import org.punit.filter.*;
import org.punit.type.*;
import org.punit.util.*;
@@ -98,11 +97,19 @@
}
public Method getAfterClassMethod(Class test) {
- return ReflectionUtil.getMethodAndSetAccessible(test, "beforeClass", new Class[] {}); //$NON-NLS-1$
+ Method method = ReflectionUtil.getMethodAndSetAccessible(test, "beforeClass", new Class[] {}); //$NON-NLS-1$
+ if(method != null && ReflectionUtil.isStatic(method)) {
+ return method;
+ }
+ return null;
}
public Method getBeforeClassMethod(Class test) {
- return ReflectionUtil.getMethodAndSetAccessible(test, "afterClass", new Class[] {}); //$NON-NLS-1$
+ Method method = ReflectionUtil.getMethodAndSetAccessible(test, "afterClass", new Class[] {}); //$NON-NLS-1$
+ if(method != null && ReflectionUtil.isStatic(method)) {
+ return method;
+ }
+ return null;
}
public Method getSetupMethod(Class test) {
Modified: trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-06-14 13:58:12 UTC (rev 204)
+++ trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-06-14 15:12:59 UTC (rev 205)
@@ -6,7 +6,6 @@
import java.util.*;
import org.punit.filter.*;
-import org.punit.runner.*;
import org.punit.type.*;
/**
Modified: trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-06-14 13:58:12 UTC (rev 204)
+++ trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-06-14 15:12:59 UTC (rev 205)
@@ -6,7 +6,6 @@
import java.util.*;
import org.punit.filter.*;
-import org.punit.runner.*;
/**
* Interface for test method builder. The method builder builds a list of
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-14 13:58:12 UTC (rev 204)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-14 15:12:59 UTC (rev 205)
@@ -5,7 +5,6 @@
import java.io.*;
import org.punit.filter.*;
-import org.punit.runner.*;
/**
* Interface for test suite builder.
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-14 13:58:12 UTC (rev 204)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-14 15:12:59 UTC (rev 205)
@@ -5,7 +5,6 @@
import java.util.*;
import org.punit.filter.*;
-import org.punit.runner.*;
import org.punit.type.*;
import org.punit.util.*;
Modified: trunk/punit.extension/.classpath
===================================================================
--- trunk/punit.extension/.classpath 2007-06-14 13:58:12 UTC (rev 204)
+++ trunk/punit.extension/.classpath 2007-06-14 15:12:59 UTC (rev 205)
@@ -5,7 +5,7 @@
<classpathentry path="/punit" exported="true" combineaccessrules="false" kind="src"/>
<classpathentry path="lib/jfreechart-1.0.5.jar" exported="true" kind="lib"/>
<classpathentry path="lib/jcommon-1.0.9.jar" exported="true" kind="lib"/>
- <classpathentry path="lib/itext-2.0.2.jar" kind="lib"/>
- <classpathentry path="lib/junit-4.3.1.jar" kind="lib"/>
+ <classpathentry path="lib/itext-2.0.2.jar" exported="true" kind="lib"/>
+ <classpathentry path="lib/junit-4.3.1.jar" exported="true" kind="lib"/>
<classpathentry path="bin" kind="output"/>
</classpath>
Modified: trunk/punit.extension/src/org/punit/annotation/AfterClass.java
===================================================================
--- trunk/punit.extension/src/org/punit/annotation/AfterClass.java 2007-06-14 13:58:12 UTC (rev 204)
+++ trunk/punit.extension/src/org/punit/annotation/AfterClass.java 2007-06-14 15:12:59 UTC (rev 205)
@@ -4,7 +4,7 @@
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
+@Target(ElementType.METHOD)
public @interface AfterClass {
Modified: trunk/punit.extension/src/org/punit/annotation/BeforeClass.java
===================================================================
--- trunk/punit.extension/src/org/punit/annotation/BeforeClass.java 2007-06-14 13:58:12 UTC (rev 204)
+++ trunk/punit.extension/src/org/punit/annotation/BeforeClass.java 2007-06-14 15:12:59 UTC (rev 205)
@@ -4,7 +4,7 @@
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
+@Target(ElementType.METHOD)
public @interface BeforeClass {
Modified: trunk/punit.test/.classpath
===================================================================
--- trunk/punit.test/.classpath 2007-06-14 13:58:12 UTC (rev 204)
+++ trunk/punit.test/.classpath 2007-06-14 15:12:59 UTC (rev 205)
@@ -2,7 +2,6 @@
<classpath>
<classpathentry path="src" kind="src"/>
<classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"/>
- <classpathentry path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1" kind="con"/>
<classpathentry path="/punit.extension" combineaccessrules="false" kind="src"/>
<classpathentry path="bin" kind="output"/>
</classpath>
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-06-14 13:58:12 UTC (rev 204)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-06-14 15:12:59 UTC (rev 205)
@@ -3,6 +3,7 @@
import junit.framework.*;
import tests.api.org.punit.assertion.*;
import tests.api.org.punit.exception.*;
+import tests.api.org.punit.filter.*;
import tests.api.org.punit.method.builder.*;
import tests.api.org.punit.method.runner.*;
import tests.api.org.punit.reporter.stream.*;
@@ -33,11 +34,12 @@
AbstractTestMethodRunnerTest.class,
AssertTest.class,
AnnotationFilterTest.class,
- NameConventionFilterTest.class,
ConcurrentExceptionTest.class,
+ ConcurrentRunnerTest.class,
+ JUnitAnnotationConventionTest.class,
LoggerUtilTest.class,
MemoryWatcherTest.class,
- ConcurrentRunnerTest.class,
+ NameConventionFilterTest.class,
StreamLoggerTest.class,
ExecutorPoolTest.class,
SoloRunnerExtensionTest.class,
Copied: trunk/punit.test/src/tests/api/org/punit/filter/AnnotationFilterTest.java (from rev 203, trunk/punit.test/src/tests/api/org/punit/runner/AnnotationFilterTest.java)
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/filter/AnnotationFilterTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/filter/AnnotationFilterTest.java 2007-06-14 15:12:59 UTC (rev 205)
@@ -0,0 +1,115 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.filter;
+
+import java.lang.reflect.*;
+
+import junit.framework.*;
+
+import org.punit.annotation.Test;
+import org.punit.filter.*;
+import org.punit.util.*;
+
+import tests.api.org.punit.testclasses.*;
+
+public class AnnotationFilterTest extends TestCase {
+ AnnotationFilter _filter = new AnnotationFilter();
+
+ public void testIsExcluded() {
+ assertTrue(_filter.isExcluded(ExcludedClass.class));
+ assertFalse(_filter.isExcluded(NonExcludedClass.class));
+ assertFalse(_filter.isExcluded(AnnotationTestClass.class));
+ }
+
+ public void testIsTestMethod() {
+ Method method;
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test1", new Class[] {}); //$NON-NLS-1$
+ assertFalse(_filter.isTestMethod(method));
+
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
+ assertTrue(_filter.isTestMethod(method));
+ }
+
+ public void testGetCheckMethod() {
+ Method method, checkMethod;
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test1", new Class[] {}); //$NON-NLS-1$
+ assertFalse(_filter.isTestMethod(method));
+ checkMethod = _filter.getCheckMethod(method);
+ assertNull(checkMethod);
+
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
+ assertTrue(_filter.isTestMethod(method));
+ checkMethod = _filter.getCheckMethod(method);
+ assertEquals("annotation_check_2", checkMethod.getName()); //$NON-NLS-1$
+
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test3", new Class[] {}); //$NON-NLS-1$
+ assertTrue(_filter.isTestMethod(method));
+ checkMethod = _filter.getCheckMethod(method);
+ assertEquals("check__test3", checkMethod.getName()); //$NON-NLS-1$
+ }
+
+ public void testGetExpectedException() {
+ Method method;
+ Class exception;
+
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test1", new Class[] {}); //$NON-NLS-1$
+ exception = _filter.getExpectedException(method);
+ assertNull(exception);
+
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
+ exception = _filter.getExpectedException(method);
+ assertSame(NullPointerException.class, exception);
+
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test3", new Class[] {}); //$NON-NLS-1$
+ exception = _filter.getExpectedException(method);
+ assertNull(exception);
+ }
+
+ public void testGetConcurrentCount1() {
+ ConcurrentTestClass test = new ConcurrentTestClass();
+ int count = _filter.getConcurrentCount(test);
+ assertEquals(test.concurrentCount(), count);
+ assertEquals(0, _filter.getConcurrentCount(new TestClass()));
+ }
+
+ public void testGetConcurrentCountClass() {
+ AnnotationTestClass test = new AnnotationTestClass();
+ int count = _filter.getConcurrentCount(test);
+ assertEquals(5, count);
+ }
+
+ public void testGetConcurrentCountMethod() {
+ Method method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
+ int count = _filter.getConcurrentCount(method);
+ assertEquals(6, count);
+ }
+
+ public void testGetSetUpMethod() {
+ assertNotNull(_filter.getSetupMethod(AnnotationTestClass.class));
+ }
+
+ public void testGetTearDownMethod() {
+ assertNotNull(_filter.getTearDownMethod(AnnotationTestClass.class));
+ }
+
+ public void testGetBeforeClass() {
+ assertNotNull(_filter.getBeforeClassMethod(AnnotationTestClass.class));
+ assertNull(_filter.getBeforeClassMethod(TestClass1.class));
+ }
+
+ public void testGetAfterClass() {
+ assertNotNull(_filter.getAfterClassMethod(AnnotationTestClass.class));
+ assertNull(_filter.getAfterClassMethod(TestClass1.class));
+ }
+
+
+ @Test(excluded = true)
+ static class ExcludedClass {
+
+ }
+
+ @Test(excluded = false)
+ static class NonExcludedClass {
+
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/filter/JUnitAnnotationConventionTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/filter/JUnitAnnotationConventionTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/filter/JUnitAnnotationConventionTest.java 2007-06-14 15:12:59 UTC (rev 205)
@@ -0,0 +1,110 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.filter;
+
+import java.lang.reflect.*;
+
+import junit.framework.*;
+
+import org.junit.Test;
+import org.punit.filter.*;
+import org.punit.util.*;
+
+import tests.api.org.punit.filter.AnnotationFilterTest.*;
+import tests.api.org.punit.testclasses.*;
+
+public class JUnitAnnotationConventionTest extends TestCase {
+ JUnitAnnotationFilter _filter = new JUnitAnnotationFilter();
+
+ public void testIsExcluded() {
+ assertFalse(_filter.isExcluded(ExcludedClass.class));
+ assertFalse(_filter.isExcluded(NonExcludedClass.class));
+ assertFalse(_filter.isExcluded(getClass()));
+ }
+
+ public void testIsTestMethod() {
+ Method method;
+ method = ReflectionUtil.getMethod(JUnitAnnotationTestClass.class, "_test1", new Class[] {}); //$NON-NLS-1$
+ assertFalse(_filter.isTestMethod(method));
+
+ method = ReflectionUtil.getMethod(JUnitAnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
+ assertTrue(_filter.isTestMethod(method));
+ }
+
+ public void testGetCheckMethod() {
+ Method method, checkMethod;
+ method = ReflectionUtil.getMethod(JUnitAnnotationTestClass.class, "_test1", new Class[] {}); //$NON-NLS-1$
+ assertFalse(_filter.isTestMethod(method));
+ checkMethod = _filter.getCheckMethod(method);
+ assertNull(checkMethod);
+
+ method = ReflectionUtil.getMethod(JUnitAnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
+ assertTrue(_filter.isTestMethod(method));
+ checkMethod = _filter.getCheckMethod(method);
+ assertNull(checkMethod);
+
+ method = ReflectionUtil.getMethod(JUnitAnnotationTestClass.class, "_test3", new Class[] {}); //$NON-NLS-1$
+ assertTrue(_filter.isTestMethod(method));
+ checkMethod = _filter.getCheckMethod(method);
+ assertEquals("check__test3", checkMethod.getName()); //$NON-NLS-1$
+ }
+
+ public void testGetExpectedException() {
+ Method method;
+ Class exception;
+
+ method = ReflectionUtil.getMethod(JUnitAnnotationTestClass.class, "_test1", new Class[] {}); //$NON-NLS-1$
+ exception = _filter.getExpectedException(method);
+ assertNull(exception);
+
+ method = ReflectionUtil.getMethod(JUnitAnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
+ exception = _filter.getExpectedException(method);
+ assertSame(NullPointerException.class, exception);
+
+ method = ReflectionUtil.getMethod(JUnitAnnotationTestClass.class, "_test3", new Class[] {}); //$NON-NLS-1$
+ exception = _filter.getExpectedException(method);
+ assertSame(Test.None.class, exception);
+ }
+
+ public void testGetConcurrentCount1() {
+ ConcurrentTestClass test = new ConcurrentTestClass();
+ int count = _filter.getConcurrentCount(test);
+ assertEquals(test.concurrentCount(), count);
+ assertEquals(0, _filter.getConcurrentCount(new TestClass()));
+ }
+
+ public void testGetConcurrentCountClass() {
+ JUnitAnnotationTestClass test = new JUnitAnnotationTestClass();
+ int count = _filter.getConcurrentCount(test);
+ assertEquals(0, count);
+ }
+
+ public void testGetConcurrentCountMethod() {
+ Method method = ReflectionUtil.getMethod(JUnitAnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
+ int count = _filter.getConcurrentCount(method);
+ assertEquals(0, count);
+ }
+
+ public void testGetSetUpMethod() {
+ assertNotNull(_filter.getSetupMethod(JUnitAnnotationTestClass.class));
+ }
+
+ public void testGetTearDownMethod() {
+ assertNotNull(_filter.getTearDownMethod(JUnitAnnotationTestClass.class));
+ }
+
+ public void testGetBeforeClass() {
+ assertNotNull(_filter.getBeforeClassMethod(JUnitAnnotationTestClass.class));
+ assertNull(_filter.getBeforeClassMethod(TestClass1.class));
+ }
+
+ public void testGetAfterClass() {
+ assertNotNull(_filter.getAfterClassMethod(JUnitAnnotationTestClass.class));
+ assertNull(_filter.getAfterClassMethod(TestClass1.class));
+ }
+
+ public void _test1() {
+
+ }
+
+}
Copied: trunk/punit.test/src/tests/api/org/punit/filter/NameConventionFilterTest.java (from rev 203, trunk/punit.test/src/tests/api/org/punit/runner/NameConventionFilterTest.java)
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/filter/NameConventionFilterTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/filter/NameConventionFilterTest.java 2007-06-14 15:12:59 UTC (rev 205)
@@ -0,0 +1,84 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.filter;
+
+import java.lang.reflect.*;
+
+import junit.framework.*;
+
+import org.punit.filter.*;
+import org.punit.util.*;
+
+import tests.api.org.punit.testclasses.*;
+
+public class NameConventionFilterTest extends TestCase {
+
+ NameConventionFilter _filter = new NameConventionFilter();
+
+ public void testIsTestMethod() {
+ Method method;
+ method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$
+ assertTrue(_filter.isTestMethod(method));
+
+ method = ReflectionUtil.getMethod(getClass(), "_test2", new Class[] {}); //$NON-NLS-1$
+ assertFalse(_filter.isTestMethod(method));
+ }
+
+ public void testGetCheckMethod() {
+ Method method, checkMethod;
+ method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$
+ checkMethod = _filter.getCheckMethod(method);
+ assertNull(checkMethod);
+
+ method = ReflectionUtil.getMethod(getClass(), "_test2", new Class[] {}); //$NON-NLS-1$
+ checkMethod = _filter.getCheckMethod(method);
+ assertEquals("check__test2", checkMethod.getName()); //$NON-NLS-1$
+ }
+
+ public void testGetConcurrentCount() {
+ ConcurrentTestClass test = new ConcurrentTestClass();
+ int count = _filter.getConcurrentCount(test);
+ assertEquals(test.concurrentCount(), count);
+ assertEquals(0, _filter.getConcurrentCount(new TestClass()));
+ }
+
+ public void testGetSetUpMethod() {
+ assertNotNull(_filter.getSetupMethod(TestClass.class));
+ assertNull(_filter.getSetupMethod(TestClass1.class));
+ }
+
+ public void testGetTearDownMethod() {
+ assertNotNull(_filter.getTearDownMethod(TestClass.class));
+ assertNull(_filter.getTearDownMethod(TestClass1.class));
+ }
+
+ public void testGetBeforeClass() {
+ assertNotNull(_filter.getBeforeClassMethod(TestClass.class));
+ assertNull(_filter.getBeforeClassMethod(TestClass1.class));
+ }
+
+ public void testGetAfterClass() {
+ assertNotNull(_filter.getAfterClassMethod(TestClass.class));
+ assertNull(_filter.getAfterClassMethod(TestClass1.class));
+ }
+
+ public void test1() {
+
+ }
+
+ public void _test2() {
+
+ }
+
+ public void check__test2() {
+
+ }
+
+ public void _test3() {
+
+ }
+
+ public void check__test3() {
+
+ }
+}
Deleted: trunk/punit.test/src/tests/api/org/punit/runner/AnnotationFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/AnnotationFilterTest.java 2007-06-14 13:58:12 UTC (rev 204)
+++ trunk/punit.test/src/tests/api/org/punit/runner/AnnotationFilterTest.java 2007-06-14 15:12:59 UTC (rev 205)
@@ -1,119 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package tests.api.org.punit.runner;
-
-import java.lang.reflect.*;
-
-import junit.framework.*;
-
-import org.punit.annotation.Test;
-import org.punit.filter.*;
-import org.punit.runner.*;
-import org.punit.util.*;
-
-import tests.api.org.punit.testclasses.*;
-
-public class AnnotationFilterTest extends TestCase {
- AnnotationFilter _filter = new AnnotationFilter();
-
- public void testIsExcluded() {
- assertTrue(_filter.isExcluded(ExcludedClass.class));
- assertFalse(_filter.isExcluded(NonExcludedClass.class));
- assertFalse(_filter.isExcluded(getClass()));
- }
-
- public void testIsTestMethod() {
- Method method;
- method = ReflectionUtil.getMethod(getClass(), "_test1", new Class[] {}); //$NON-NLS-1$
- assertFalse(_filter.isTestMethod(method));
-
- method = ReflectionUtil.getMethod(getClass(), "_test2", new Class[] {}); //$NON-NLS-1$
- assertTrue(_filter.isTestMethod(method));
- }
-
- public void testGetCheckMethod() {
- Method method, checkMethod;
- method = ReflectionUtil.getMethod(getClass(), "_test1", new Class[] {}); //$NON-NLS-1$
- assertFalse(_filter.isTestMethod(method));
- checkMethod = _filter.getCheckMethod(method);
- assertNull(checkMethod);
-
- method = ReflectionUtil.getMethod(getClass(), "_test2", new Class[] {}); //$NON-NLS-1$
- assertTrue(_filter.isTestMethod(method));
- checkMethod = _filter.getCheckMethod(method);
- assertEquals("checkTest2", checkMethod.getName()); //$NON-NLS-1$
-
- method = ReflectionUtil.getMethod(getClass(), "_test3", new Class[] {}); //$NON-NLS-1$
- assertTrue(_filter.isTestMethod(method));
- checkMethod = _filter.getCheckMethod(method);
- assertEquals("check__test3", checkMethod.getName()); //$NON-NLS-1$
- }
-
- public void testGetExpectedException() {
- Method method;
- Class exception;
-
- method = ReflectionUtil.getMethod(getClass(), "_test1", new Class[] {}); //$NON-NLS-1$
- exception = _filter.getExpectedException(method);
- assertNull(exception);
-
- method = ReflectionUtil.getMethod(getClass(), "_test2", new Class[] {}); //$NON-NLS-1$
- exception = _filter.getExpectedException(method);
- assertSame(NullPointerException.class, exception);
-
- method = ReflectionUtil.getMethod(getClass(), "_test3", new Class[] {}); //$NON-NLS-1$
- exception = _filter.getExpectedException(method);
- assertNull(exception);
- }
-
- public void testGetConcurrentCount1() {
- ConcurrentTestClass test = new ConcurrentTestClass();
- int count = _filter.getConcurrentCount(test);
- assertEquals(test.concurrentCount(), count);
- assertEquals(0, _filter.getConcurrentCount(new TestClass()));
- }
-
- public void testGetConcurrentCountClass() {
- AnnotationTestClass test = new AnnotationTestClass();
- int count = _filter.getConcurrentCount(test);
- assertEquals(5, count);
- }
-
- public void testGetConcurrentCountMethod() {
- Method method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
- int count = _filter.getConcurrentCount(method);
- assertEquals(6, count);
- }
-
- public void _test1() {
-
- }
-
- @Test(checkMethod="checkTest2", expected=NullPointerException.class)
- public void _test2() {
-
- }
-
- public void checkTest2() {
-
- }
-
- @Test
- public void _test3() {
-
- }
-
- public void check__test3() {
-
- }
-
- @Test(excluded = true)
- static class ExcludedClass {
-
- }
-
- @Test(excluded = false)
- static class NonExcludedClass {
-
- }
-}
Deleted: trunk/punit.test/src/tests/api/org/punit/runner/NameConventionFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/NameConventionFilterTest.java 2007-06-14 13:58:12 UTC (rev 204)
+++ trunk/punit.test/src/tests/api/org/punit/runner/NameConventionFilterTest.java 2007-06-14 15:12:59 UTC (rev 205)
@@ -1,65 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package tests.api.org.punit.runner;
-
-import java.lang.reflect.*;
-
-import junit.framework.*;
-
-import org.punit.filter.*;
-import org.punit.runner.*;
-import org.punit.util.*;
-
-import tests.api.org.punit.testclasses.*;
-
-public class NameConventionFilterTest extends TestCase {
-
- NameConventionFilter _filter = new NameConventionFilter();
-
- public void testIsTestMethod() {
- Method method;
- method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$
- assertTrue(_filter.isTestMethod(method));
-
- method = ReflectionUtil.getMethod(getClass(), "_test2", new Class[] {}); //$NON-NLS-1$
- assertFalse(_filter.isTestMethod(method));
- }
-
- public void testGetCheckMethod() {
- Method method, checkMethod;
- method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$
- checkMethod = _filter.getCheckMethod(method);
- assertNull(checkMethod);
-
- method = ReflectionUtil.getMethod(getClass(), "_test2", new Class[] {}); //$NON-NLS-1$
- checkMethod = _filter.getCheckMethod(method);
- assertEquals("check__test2", checkMethod.getName()); //$NON-NLS-1$
- }
-
- public void testGetConcurrentCount() {
- ConcurrentTestClass test = new ConcurrentTestClass();
- int count = _filter.getConcurrentCount(test);
- assertEquals(test.concurrentCount(), count);
- assertEquals(0, _filter.getConcurrentCount(new TestClass()));
- }
-
- public void test1() {
-
- }
-
- public void _test2() {
-
- }
-
- public void check__test2() {
-
- }
-
- public void _test3() {
-
- }
-
- public void check__test3() {
-
- }
-}
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-06-14 13:58:12 UTC (rev 204)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-06-14 15:12:59 UTC (rev 205)
@@ -2,6 +2,7 @@
import junit.framework.*;
+import org.punit.annotation.*;
import org.punit.annotation.Test;
import org.punit.filter.*;
import org.punit.runner.*;
@@ -30,7 +31,11 @@
public static boolean _setUp;
public static boolean _tearDown;
+
+ public static boolean _beforeClass;
+ public static boolean _afterClass;
+
public static void reset() {
_test1 = false;
_test2 = false;
@@ -40,23 +45,42 @@
_testException = false;
_setUp = false;
_tearDown = false;
+ _beforeClass = false;
+ _afterClass = false;
}
- private void setUp() {
+ @BeforeClass
+ private static void beforeClassMethod() {
+ _beforeClass = true;
+ }
+
+ @AfterClass
+ private static void afterClassMethod() {
+ _afterClass = true;
+ }
+
+ @Before
+ private void before() {
_setUp = true;
}
- private void tearDown() {
+ @After
+ private void after() {
_tearDown = true;
}
+ public void _test1() {
+
+ }
+
public void test1() {
_test1 = true;
}
- @Test(checkMethod="annotation_check_2", concurrentCount=6)
+ @Test(checkMethod="annotation_check_2", concurrentCount=6, expected=NullPointerException.class)
public void _test2() {
_test2 = true;
+ throw new NullPointerException();
}
public void check_test1() {
@@ -71,6 +95,15 @@
_check22 = true;
}
+ @Test
+ public void _test3() {
+
+ }
+
+ public void check__test3() {
+
+ }
+
@Test(expected = NullPointerException.class)
public void _testException() {
_testException = true;
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/JUnitAnnotationTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/JUnitAnnotationTestClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/JUnitAnnotationTestClass.java 2007-06-14 15:12:59 UTC (rev 205)
@@ -0,0 +1,122 @@
+package tests.api.org.punit.testclasses;
+
+import org.junit.*;
+import org.punit.filter.*;
+import org.punit.runner.*;
+
+public class JUnitAnnotationTestClass {
+
+ public static void main(String[] args) {
+ SoloRunner soloRunner = new SoloRunner();
+ soloRunner.setFilter(new AnnotationFilter());
+ soloRunner.run(JUnitAnnotationTestClass.class);
+ }
+
+ public static boolean _test1;
+
+ public static boolean _test2;
+
+ public static boolean _check1;
+
+ public static boolean _check2;
+
+ public static boolean _check22;
+
+ public static boolean _testException;
+
+ public static boolean _setUp;
+
+ public static boolean _tearDown;
+
+ public static boolean _beforeClass;
+
+ public static boolean _afterClass;
+
+ public static void reset() {
+ _test1 = false;
+ _test2 = false;
+ _check1 = false;
+ _check2 = false;
+ _check22 = false;
+ _testException = false;
+ _setUp = false;
+ _tearDown = false;
+ _beforeClass = false;
+ _afterClass = false;
+ }
+
+ @BeforeClass
+ private void beforeClassMethod() {
+ _beforeClass = true;
+ }
+
+ @AfterClass
+ private void afterClassMethod() {
+ _afterClass = true;
+ }
+
+ @Before
+ private void before() {
+ _setUp = true;
+ }
+
+ @After
+ private void after() {
+ _tearDown = true;
+ }
+
+ public void _test1() {
+
+ }
+
+ public void test1() {
+ _test1 = true;
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void _test2() {
+ _test2 = true;
+ throw new NullPointerException();
+ }
+
+ public void check_test1() {
+ _check1 = true;
+ }
+
+ public void annotation_check_2() {
+ _check2 = true;
+ }
+
+ public void check_test2() {
+ _check22 = true;
+ }
+
+ @Test
+ public void _test3() {
+
+ }
+
+ public void check__test3() {
+
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void _testException() {
+ _testException = true;
+ throw new NullPointerException();
+ }
+
+ public static void assertTestClassRun() {
+ Assert.assertTrue(_test1);
+ Assert.assertTrue(_check1);
+
+ Assert.assertTrue(_test2);
+ Assert.asser...
[truncated message content] |