Thread: [P-unit-devel] SF.net SVN: p-unit: [262] trunk/punit.extension/src/org/punit
Status: Beta
Brought to you by:
zhanghuangzhu
|
From: <zha...@us...> - 2007-12-25 12:35:12
|
Revision: 262
http://p-unit.svn.sourceforge.net/p-unit/?rev=262&view=rev
Author: zhanghuangzhu
Date: 2007-12-25 04:35:17 -0800 (Tue, 25 Dec 2007)
Log Message:
-----------
Andrew Zhang: introduced VanillaEventListener
Modified Paths:
--------------
trunk/punit.extension/src/org/punit/listener/FieldSetter.java
trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
Modified: trunk/punit.extension/src/org/punit/listener/FieldSetter.java
===================================================================
--- trunk/punit.extension/src/org/punit/listener/FieldSetter.java 2007-12-25 12:35:05 UTC (rev 261)
+++ trunk/punit.extension/src/org/punit/listener/FieldSetter.java 2007-12-25 12:35:17 UTC (rev 262)
@@ -1,21 +1,16 @@
/* (C) Copyright 2007, by Andrew Zhang */
package org.punit.listener;
-import java.lang.reflect.Method;
-import java.util.List;
-import java.util.Properties;
-
-import org.punit.events.EventListener;
-import org.punit.runner.Runner;
-import org.punit.type.TestSuite;
-import org.punit.watcher.Watcher;
import java.lang.reflect.*;
+import java.util.*;
+
+import org.punit.events.*;
import org.punit.util.*;
/**
* The listener sets class public fields using properties.
*/
-public class FieldSetter implements EventListener {
+public class FieldSetter extends VanillaEventListener {
private static final long serialVersionUID = 5194809928409791777L;
@@ -25,61 +20,10 @@
_properties = properties;
}
- @SuppressWarnings("unchecked")
- public void onMethodEnd(Method method, Object testInstance,
- Object[] params, Throwable t, List Watchers) {
- }
-
- public void onClassEnd(Object testInstance, Throwable t) {
- }
-
public void onClassStart(Object testInstance) {
setClassFields(testInstance, _properties);
}
- public void onMethodStart(Method method, Object testInstance,
- Object[] params) {
-
- }
-
- @SuppressWarnings("unchecked")
- public void onRunnerEnd(Class clazz, Runner runner) {
- }
-
- @SuppressWarnings("unchecked")
- public void onRunnerStart(Class clazz, Runner runner) {
- }
-
- public void onSuiteEnd(TestSuite suite) {
-
- }
-
- public void onSuiteStart(TestSuite suite) {
-
- }
-
- public void onWatcherEnd(Watcher watcher) {
-
- }
-
- public void onWatcherStart(Watcher watcher) {
-
- }
-
- @SuppressWarnings("unchecked")
- public void onWatchersEnd(List watchers) {
-
- }
-
- @SuppressWarnings("unchecked")
- public void onWatchersStart(List watchers) {
-
- }
-
- public boolean supportParentRunner() {
- return false;
- }
-
private final String PACKAGE_SEPARATOR = "."; //$NON-NLS-1$
/**
Modified: trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2007-12-25 12:35:05 UTC (rev 261)
+++ trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2007-12-25 12:35:17 UTC (rev 262)
@@ -12,7 +12,7 @@
import org.jfree.chart.JFreeChart;
import org.jfree.data.category.DefaultCategoryDataset;
-import org.punit.events.EventListener;
+import org.punit.events.*;
import org.punit.exception.IOException;
import org.punit.message.Messages;
import org.punit.reporter.chart.image.ImageConstants;
@@ -26,7 +26,7 @@
import org.punit.util.TraverserUtil;
import org.punit.watcher.Watcher;
-public abstract class AbstractChartReporter implements EventListener {
+public abstract class AbstractChartReporter extends VanillaEventListener {
private Hashtable<DatasetKey, DefaultCategoryDataset> _datasets = new Hashtable<DatasetKey, DefaultCategoryDataset>();
@@ -221,27 +221,4 @@
});
}
- public void onWatcherStart(Watcher watcher) {
- // nothing needs to be done
- }
-
- public void onWatcherEnd(Watcher watcher) {
- // nothing needs to be done
- }
-
- @SuppressWarnings("unchecked")
- public void onWatchersStart(List watchers) {
- // nothing needs to be done
- }
-
- @SuppressWarnings("unchecked")
- public void onWatchersEnd(List watchers) {
- // nothing needs to be done
- }
-
- public void onMethodStart(Method method, Object testInstance,
- Object[] params) {
- // nothing needs to be done
- }
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-01-11 15:55:26
|
Revision: 269
http://p-unit.svn.sourceforge.net/p-unit/?rev=269&view=rev
Author: zhanghuangzhu
Date: 2008-01-11 07:55:28 -0800 (Fri, 11 Jan 2008)
Log Message:
-----------
Andrew Zhang: Looking forward, based on java 5 now.
Modified Paths:
--------------
trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
Removed Paths:
-------------
trunk/punit.extension/src/org/punit/annotation/
trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java
trunk/punit.extension/src/org/punit/runner/
trunk/punit.extension/src/org/punit/util/
Deleted: trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java
===================================================================
--- trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java 2008-01-11 15:55:11 UTC (rev 268)
+++ trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java 2008-01-11 15:55:28 UTC (rev 269)
@@ -1,134 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.convention;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import org.punit.annotation.Test;
-import org.punit.util.AnnotationUtil;
-import org.punit.util.ReflectionUtil;
-
-/**
- * The class merges annotation and name conventions with annotations taking
- * preference.
- */
-public class AnnotationConvention extends AbstractConvention {
-
- private static final long serialVersionUID = -6800242731470821241L;
-
- protected NameConvention _delegate = new NameConvention();
-
- private Class<? extends Annotation> _after;
- private Class<? extends Annotation> _afterClass;
- private Class<? extends Annotation> _before;
- private Class<? extends Annotation> _beforeClass;
- private Class<? extends Annotation> _ignore;
- protected Class<? extends Annotation> _test;
-
- public AnnotationConvention() {
- this(org.punit.annotation.After.class,
- org.punit.annotation.AfterClass.class,
- org.punit.annotation.Before.class,
- org.punit.annotation.BeforeClass.class,
- org.punit.annotation.Ignore.class, Test.class);
- }
-
- public AnnotationConvention(Class<? extends Annotation> after,
- Class<? extends Annotation> afterClass,
- Class<? extends Annotation> before,
- Class<? extends Annotation> beforeClass,
- Class<? extends Annotation> ignore, Class<? extends Annotation> test) {
- _after = after;
- _afterClass = afterClass;
- _before = before;
- _beforeClass = beforeClass;
- _ignore = ignore;
- _test = test;
- }
-
- public Method getCheckMethod(Method method) {
- Test testAnnotation = (Test) method.getAnnotation(_test);
- 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) {
- return clazz.isAnnotationPresent(_ignore);
- }
-
- public boolean isTestMethod(Method method) {
- if (method.isAnnotationPresent(_ignore)) {
- return false;
- }
- return method.isAnnotationPresent(_test) || _delegate.isTestMethod(method);
- }
-
- public Class<? extends Throwable> getExpectedException(Method method) {
- Test testAnnotation = (Test) method.getAnnotation(_test);
- if (testAnnotation == null) {
- return null;
- }
- Class<? extends Throwable> expected = testAnnotation.expected();
- if (expected == Test.NoException.class) {
- return null;
- }
- return expected;
- }
-
- public int getConcurrentCount(Object testInstance, Method method) {
- Test testAnnotation = (Test) method.getAnnotation(_test);
- if (testAnnotation == null) {
- testAnnotation = (Test) testInstance.getClass().getAnnotation(_test);
- }
- if (testAnnotation == null) {
- return _delegate.getConcurrentCount(testInstance, method);
- }
- return testAnnotation.concurrentCount();
- }
-
- @SuppressWarnings("unchecked")
- public Method getAfterClassMethod(Class test) {
- Method method = AnnotationUtil.getMethodByAnnotation(test, _afterClass);
- if (method == null) {
- method = _delegate.getAfterClassMethod(test);
- }
- return method;
- }
-
- @SuppressWarnings("unchecked")
- public Method getBeforeClassMethod(Class test) {
- Method method = AnnotationUtil
- .getMethodByAnnotation(test, _beforeClass);
- if (method == null) {
- method = _delegate.getBeforeClassMethod(test);
- }
- return method;
- }
-
- @SuppressWarnings("unchecked")
- public Method getSetUpMethod(Class test) {
- Method method = AnnotationUtil.getMethodByAnnotation(test, _before);
- if (method == null) {
- method = _delegate.getSetUpMethod(test);
- }
- return method;
- }
-
- @SuppressWarnings("unchecked")
- public Method getTearDownMethod(Class test) {
- Method method = AnnotationUtil.getMethodByAnnotation(test, _after);
- if (method == null) {
- method = _delegate.getTearDownMethod(test);
- }
- return method;
- }
-
-}
Modified: trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2008-01-11 15:55:11 UTC (rev 268)
+++ trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2008-01-11 15:55:28 UTC (rev 269)
@@ -2,29 +2,20 @@
package org.punit.reporter.chart;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.ObjectInputStream;
-import java.lang.reflect.Method;
-import java.util.Hashtable;
-import java.util.LinkedList;
-import java.util.List;
+import java.io.*;
+import java.lang.reflect.*;
+import java.util.*;
-import org.jfree.chart.JFreeChart;
-import org.jfree.data.category.DefaultCategoryDataset;
+import org.jfree.chart.*;
+import org.jfree.data.category.*;
import org.punit.events.*;
import org.punit.exception.IOException;
-import org.punit.message.Messages;
-import org.punit.reporter.chart.image.ImageConstants;
-import org.punit.runner.Runner;
-import org.punit.runner.RunnerProperties;
-import org.punit.type.TestSuite;
-import org.punit.type.VM;
-import org.punit.util.IOUtil;
-import org.punit.util.ReporterUtil;
-import org.punit.util.Traverser;
-import org.punit.util.TraverserUtil;
-import org.punit.watcher.Watcher;
+import org.punit.message.*;
+import org.punit.reporter.chart.image.*;
+import org.punit.runner.*;
+import org.punit.type.*;
+import org.punit.util.*;
+import org.punit.watcher.*;
public abstract class AbstractChartReporter extends VanillaEventListener {
@@ -201,24 +192,22 @@
return _currentSuiteStack.getLast();
}
- @SuppressWarnings("unchecked")
public synchronized void onMethodEnd(final Method method,
- final Object testInstance, final Object[] params,
- final Throwable t, List watchers) {
- TraverserUtil.traverse(watchers.iterator(), new Traverser() {
- 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
- }
- });
- }
+ final Object testInstance, final Object[] params,
+ final Throwable t, List<Watcher> watchers) {
+ Iterator<Watcher> iter = watchers.iterator();
+ while (iter.hasNext()) {
+ Watcher watcher = iter.next();
+ 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
+ }
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|