Thread: [P-unit-devel] SF.net SVN: p-unit: [229] trunk/punit (Page 5)
Status: Beta
Brought to you by:
zhanghuangzhu
|
From: <le...@us...> - 2007-07-12 07:08:53
|
Revision: 229
http://p-unit.svn.sourceforge.net/p-unit/?rev=229&view=rev
Author: leshik
Date: 2007-07-12 00:08:43 -0700 (Thu, 12 Jul 2007)
Log Message:
-----------
Changes:
* Added org.punit.watcher.CustomWatcher infrastructure to make it possible to report results from
* Added three test cases
* Removed PUnit prefixes from class names
* Expanded imports, formatted touched code with Harmony code convention
* Fixed 70 warnings, most of them by means of @SuppressWarnings, some by using generics
Modified Paths:
--------------
trunk/punit/src/org/punit/assertion/Assert.java
trunk/punit/src/org/punit/convention/Convention.java
trunk/punit/src/org/punit/convention/NameConvention.java
trunk/punit/src/org/punit/exception/ConcurrentException.java
trunk/punit/src/org/punit/exception/PUnitException.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/reporter/TestResult.java
trunk/punit/src/org/punit/reporter/stream/StreamLogger.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/ExecutorPool.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit/src/org/punit/runner/RunnerProperties.java
trunk/punit/src/org/punit/runner/StreamReaderThread.java
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
trunk/punit/src/org/punit/type/Loop.java
trunk/punit/src/org/punit/type/Parameterizable.java
trunk/punit/src/org/punit/type/VM.java
trunk/punit/src/org/punit/util/IOUtil.java
trunk/punit/src/org/punit/util/MemoryUtil.java
trunk/punit/src/org/punit/util/ReporterUtil.java
trunk/punit/src/org/punit/util/RunnerUtil.java
trunk/punit/src/org/punit/util/TraverserUtil.java
trunk/punit/src/org/punit/util/TypeUtil.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/src/punit.properties
trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java
trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java
trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
trunk/punit.extension/src/org/punit/reporter/chart/ChartRender.java
trunk/punit.extension/src/org/punit/reporter/chart/ChartUtil.java
trunk/punit.extension/src/org/punit/reporter/chart/DatasetKey.java
trunk/punit.extension/src/org/punit/reporter/chart/TestClassReporter.java
trunk/punit.extension/src/org/punit/reporter/chart/TestSuiteReporter.java
trunk/punit.extension/src/org/punit/reporter/chart/image/ImageRender.java
trunk/punit.extension/src/org/punit/reporter/chart/pdf/PDFRender.java
trunk/punit.extension/src/org/punit/runner/ExecutorPoolImpl.java
trunk/punit.extension/src/org/punit/util/AnnotationUtil.java
trunk/punit.samples/src/samples/AllTestSuite.java
trunk/punit.samples/src/samples/ListTestClass.java
trunk/punit.samples/src/samples/LongTimeExecutionJUnitTestSuite.java
trunk/punit.samples/src/samples/LongTimeExecutionPUnitTestSuite.java
trunk/punit.samples/src/samples/LoopTestSample.java
trunk/punit.samples/src/samples/MultiThreadRunnerSample.java
trunk/punit.samples/src/samples/ParamTestClass.java
trunk/punit.samples/src/samples/RunnerSamples.java
trunk/punit.test/src/extension/tests/api/org/punit/reporter/chart/AbstractChartReporterTest.java
trunk/punit.test/src/extension/tests/api/org/punit/runner/SoloRunnerExtensionTest.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/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/convention/AnnotationFilterTest.java
trunk/punit.test/src/tests/api/org/punit/convention/JUnitAnnotationConventionTest.java
trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java
trunk/punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractTestMethodRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/reporter/stream/StreamLoggerTest.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/suite/builder/TestSuiteBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizableTestClass.java
trunk/punit.test/src/tests/api/org/punit/testclasses/ExcludedTestClass1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java
trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestClass.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass3.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
trunk/punit.test/src/tests/api/org/punit/util/IOUtilTest.java
trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java
trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java
trunk/punit.test/src/tests/samples/PUnitTestCaseSample.java
trunk/punit.test/src/tests/samples/VMsSample.java
trunk/punit.test/src/tests/util/AssertUtil.java
trunk/punit.test/src/tests/util/TestUtil.java
Added Paths:
-----------
trunk/punit/src/org/punit/events/EventListener.java
trunk/punit/src/org/punit/events/EventRegistry.java
trunk/punit/src/org/punit/exception/IOException.java
trunk/punit/src/org/punit/exception/OutOfMemoryException.java
trunk/punit/src/org/punit/type/Name.java
trunk/punit/src/org/punit/type/Parameter.java
trunk/punit/src/org/punit/type/Test.java
trunk/punit/src/org/punit/type/TestSuite.java
trunk/punit/src/org/punit/watcher/AbstractWatcher.java
trunk/punit/src/org/punit/watcher/CustomWatcher.java
trunk/punit/src/org/punit/watcher/MaximumWatcher.java
trunk/punit/src/org/punit/watcher/MinimumWatcher.java
trunk/punit.samples/src/samples/DoSomethingTestClass.java
trunk/punit.test/src/tests/api/org/punit/runner/MockEventListener.java
trunk/punit.test/src/tests/api/org/punit/testclasses/AlphabeticalTestClass.java
trunk/punit.test/src/tests/api/org/punit/testclasses/IntParameter.java
trunk/punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass0.java
trunk/punit.test/src/tests/api/org/punit/watcher/CustomWatcherTest.java
Removed Paths:
-------------
trunk/punit/src/org/punit/events/PUnitEventListener.java
trunk/punit/src/org/punit/events/PUnitEventRegsitry.java
trunk/punit/src/org/punit/exception/PUnitIOException.java
trunk/punit/src/org/punit/type/PUnitName.java
trunk/punit/src/org/punit/type/PUnitTest.java
trunk/punit/src/org/punit/type/PUnitTestSuite.java
trunk/punit/src/org/punit/type/Parameter.java
trunk/punit.samples/src/samples/PUnitTestClass.java
trunk/punit.test/src/tests/api/org/punit/runner/MockPUnitEventListener.java
trunk/punit.test/src/tests/api/org/punit/testclasses/PUnitTestClass.java
trunk/punit.test/src/tests/api/org/punit/testclasses/Parameter1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestParameter.java
Modified: trunk/punit/src/org/punit/assertion/Assert.java
===================================================================
--- trunk/punit/src/org/punit/assertion/Assert.java 2007-06-29 02:27:52 UTC (rev 228)
+++ trunk/punit/src/org/punit/assertion/Assert.java 2007-07-12 07:08:43 UTC (rev 229)
@@ -2,95 +2,95 @@
package org.punit.assertion;
-import org.punit.message.*;
+import org.punit.message.Messages;
public class Assert {
-
- public static void assertSame(Object expected, Object actual) {
- if (expected != actual) {
- fail(expected, actual);
- }
- }
-
- 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);
- }
- }
-
- public static void assertEquals(int expected, int actual) {
- assertEquals(new Integer(expected), new Integer(actual));
- }
-
- public static void assertEquals(long expected, long actual) {
- assertEquals(new Long(expected), new Long(actual));
- }
-
- public static void assertEquals(double expected, double actual) {
- assertEquals(new Double(expected), new Double(actual));
- }
-
- public static void assertEquals(double expected, double actual, double delta) {
- assertTrue(Math.abs(expected - actual) <= delta);
- }
-
- public static void assertEquals(float expected, float actual) {
- assertEquals(new Float(expected), new Float(actual));
- }
-
- public static void assertEquals(float expected, float actual, float delta) {
- assertTrue(Math.abs(expected - actual) <= delta);
- }
+
+ public static void assertSame(Object expected, Object actual) {
+ if (expected != actual) {
+ fail(expected, actual);
+ }
+ }
+
+ 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);
+ }
+ }
+
+ public static void assertEquals(int expected, int actual) {
+ assertEquals(new Integer(expected), new Integer(actual));
+ }
+
+ public static void assertEquals(long expected, long actual) {
+ assertEquals(new Long(expected), new Long(actual));
+ }
+
+ public static void assertEquals(double expected, double actual) {
+ assertEquals(new Double(expected), new Double(actual));
+ }
+
+ public static void assertEquals(double expected, double actual, double delta) {
+ assertTrue(Math.abs(expected - actual) <= delta);
+ }
+
+ public static void assertEquals(float expected, float actual) {
+ assertEquals(new Float(expected), new Float(actual));
+ }
+
+ public static void assertEquals(float expected, float actual, float delta) {
+ assertTrue(Math.abs(expected - actual) <= delta);
+ }
- public static void assertTrue(boolean flag) {
- if(!flag) {
- fail(Boolean.TRUE, Boolean.FALSE);
- }
- }
-
- public static void assertFalse(boolean flag) {
- if(flag) {
- fail(Boolean.FALSE, Boolean.TRUE);
- }
- }
-
- public static void assertNull(Object obj) {
- if(obj != null) {
- fail(null, obj);
- }
- }
-
- public static void assertNotNull(Object obj) {
- if(obj == null) {
- fail(obj, null);
- }
- }
-
- public static void assertException(Class throwable, CodeRunner code) {
- Class exceptionClass = null;
- try {
- code.run();
- } catch (Throwable e) {
- exceptionClass = e.getClass();
- }
- assertSame(throwable, exceptionClass);
- }
-
- public static void fail() {
- throw new AssertionError(null);
- }
-
- public static void fail(String string) {
- throw new AssertionError(string);
- }
-
- private static void fail(Object expected, Object actual) {
- fail(Messages.getString("Assert.0") + expected + Messages.getString("Assert.1") + actual); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ public static void assertTrue(boolean flag) {
+ if(!flag) {
+ fail(Boolean.TRUE, Boolean.FALSE);
+ }
+ }
+
+ public static void assertFalse(boolean flag) {
+ if(flag) {
+ fail(Boolean.FALSE, Boolean.TRUE);
+ }
+ }
+
+ public static void assertNull(Object obj) {
+ if(obj != null) {
+ fail(null, obj);
+ }
+ }
+
+ public static void assertNotNull(Object obj) {
+ if(obj == null) {
+ fail(obj, null);
+ }
+ }
+
+ public static void assertException(Class throwable, CodeRunner code) {
+ Class exceptionClass = null;
+ try {
+ code.run();
+ } catch (Throwable e) {
+ exceptionClass = e.getClass();
+ }
+ assertSame(throwable, exceptionClass);
+ }
+
+ public static void fail() {
+ throw new AssertionError(null);
+ }
+
+ public static void fail(String string) {
+ throw new AssertionError(string);
+ }
+
+ private static void fail(Object expected, Object actual) {
+ fail(Messages.getString("Assert.0") + expected + Messages.getString("Assert.1") + actual); //$NON-NLS-1$ //$NON-NLS-2$
+ }
}
Modified: trunk/punit/src/org/punit/convention/Convention.java
===================================================================
--- trunk/punit/src/org/punit/convention/Convention.java 2007-06-29 02:27:52 UTC (rev 228)
+++ trunk/punit/src/org/punit/convention/Convention.java 2007-07-12 07:08:43 UTC (rev 229)
@@ -2,49 +2,49 @@
package org.punit.convention;
-import java.io.*;
-import java.lang.reflect.*;
+import java.io.Serializable;
+import java.lang.reflect.Method;
public interface Convention extends Serializable {
-
- /**
- * 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);
+
+ /**
+ * 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);
+ /**
+ * 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(Object testInstance, Method method);
-
- public Method getSetupMethod(Class test);
-
- public Method getTearDownMethod(Class test);
-
- public Method getBeforeClassMethod(Class test);
-
- public Method getAfterClassMethod(Class test);
-
- public boolean isLoopTest(Object testInstance);
-
- public long toStop(Object testInstance);
-
- public long toAbort(Object testInstance);
+ public int getConcurrentCount(Object testInstance, Method method);
+
+ public Method getSetupMethod(Class test);
+
+ public Method getTearDownMethod(Class test);
+
+ public Method getBeforeClassMethod(Class test);
+
+ public Method getAfterClassMethod(Class test);
+
+ public boolean isLoopTest(Object testInstance);
+
+ public long toWork(Object testInstance);
+
+ public long toStop(Object testInstance);
}
Modified: trunk/punit/src/org/punit/convention/NameConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/NameConvention.java 2007-06-29 02:27:52 UTC (rev 228)
+++ trunk/punit/src/org/punit/convention/NameConvention.java 2007-07-12 07:08:43 UTC (rev 229)
@@ -9,130 +9,130 @@
public class NameConvention implements Convention {
- private static final long serialVersionUID = -1252188754463864599L;
+ 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());
- }
+ 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);
- }
+ /**
+ * 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 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$
- }
+ /**
+ * 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;
- }
- }
+ /**
+ * 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 Class getExpectedException(Method method) {
+ return null;
+ }
- public int getConcurrentCount(Object testInstance, Method method) {
- if(testInstance instanceof Concurrent) {
- return ((Concurrent)testInstance).concurrentCount();
- }
- return 0;
- }
+ public int getConcurrentCount(Object testInstance, Method method) {
+ if(testInstance instanceof Concurrent) {
+ return ((Concurrent)testInstance).concurrentCount();
+ }
+ return 0;
+ }
- public Method getAfterClassMethod(Class test) {
- Method method = ReflectionUtil.getMethodAndSetAccessible(test, "beforeClass", new Class[] {}); //$NON-NLS-1$
- if(method != null && ReflectionUtil.isStatic(method)) {
- return method;
- }
- return null;
- }
+ public Method getAfterClassMethod(Class test) {
+ 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) {
- Method method = ReflectionUtil.getMethodAndSetAccessible(test, "afterClass", new Class[] {}); //$NON-NLS-1$
- if(method != null && ReflectionUtil.isStatic(method)) {
- return method;
- }
- return null;
- }
+ public Method getBeforeClassMethod(Class test) {
+ 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) {
- return ReflectionUtil.getMethodAndSetAccessible(test, "setUp", 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$
- }
+ public Method getTearDownMethod(Class test) {
+ return ReflectionUtil.getMethodAndSetAccessible(test, "tearDown", new Class[] {}); //$NON-NLS-1$
+ }
- public boolean isLoopTest(Object testInstance) {
- return testInstance instanceof Loop;
- }
-
- public long toAbort(Object testInstance) {
- if(isLoopTest(testInstance)) {
- return ((Loop) testInstance).toAbort();
- }
- return 0;
- }
+ public boolean isLoopTest(Object testInstance) {
+ return testInstance instanceof Loop;
+ }
+
+ public long toStop(Object testInstance) {
+ if(isLoopTest(testInstance)) {
+ return ((Loop) testInstance).toStop();
+ }
+ return 0;
+ }
- public long toStop(Object testInstance) {
- if(isLoopTest(testInstance)) {
- return ((Loop) testInstance).toStop();
- }
- return 0;
- }
+ public long toWork(Object testInstance) {
+ if(isLoopTest(testInstance)) {
+ return ((Loop) testInstance).toWork();
+ }
+ return 0;
+ }
-
+
}
Added: trunk/punit/src/org/punit/events/EventListener.java
===================================================================
--- trunk/punit/src/org/punit/events/EventListener.java (rev 0)
+++ trunk/punit/src/org/punit/events/EventListener.java 2007-07-12 07:08:43 UTC (rev 229)
@@ -0,0 +1,107 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.events;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.punit.runner.Runner;
+import org.punit.type.TestSuite;
+import org.punit.watcher.Watcher;
+
+/**
+ * Event system for PUnit. The event listener can be installed by
+ * {@link EventRegistry#addEventListener(EventListener)}.
+ *
+ * All PUnit runners implement {@link EventRegistry}.
+ *
+ */
+public interface EventListener extends Serializable {
+
+ /**
+ * Is triggered before running the class.
+ *
+ * @param clazz
+ * the class to be run
+ * @param runner
+ * the runner who runs this class
+ */
+ public void onRunnerStart(Class clazz, Runner runner);
+
+ /**
+ * Is triggered after running the class.
+ *
+ * @param clazz
+ * the class to be run
+ * @param runner
+ * the runner who runs this class
+ */
+ public void onRunnerEnd(Class clazz, Runner runner);
+
+ /**
+ * Is triggered when the test suite is to be executed.
+ *
+ */
+ public void onSuiteStart(TestSuite suite);
+
+ /**
+ * Is triggered after executing the test suite.
+ */
+ public void onSuiteEnd(TestSuite suite);
+
+ /**
+ * Is triggered when the test class is to be executed.
+ */
+ public void onClassStart(Class clazz);
+
+ /**
+ * Is triggered after executing the test class.
+ */
+ public void onClassEnd(Class clazz);
+
+ /**
+ * Is triggered when the method to be executed.
+ */
+ public void onMethodStart(Method method, Object testInstance,
+ Object[] params);
+
+ /**
+ * Is triggered after executing the method.
+ */
+ public void onMethodEnd(Method method, Object testInstance,
+ Object[] params, Throwable t, List Watchers);
+
+ /**
+ * Is triggered before all watchers start.
+ */
+ public void onWatchersStart(List watchers);
+
+ /**
+ * Is triggered after all watchers stop.
+ */
+ public void onWatchersEnd(List watchers);
+
+ /**
+ * Is triggered before this watcher starts.
+ */
+ public void onWatcherStart(Watcher watcher);
+
+ /**
+ * Is triggered after this watcher stops.
+ */
+ public void onWatcherEnd(Watcher watcher);
+
+ /**
+ * PUnit may execute test suites against different virtual machines. The
+ * runner who forks child virtual machine is called parent runner. Parent
+ * runner only notifies the events to the event listener who support parent
+ * runner. It is useful for logging and reporting system. For example, file
+ * logging does not care about it since the children virtual machine has
+ * given the output.
+ *
+ * @return <code>true</code> if this listener supports parent runner
+ */
+ public boolean supportParentRunner();
+
+}
Added: trunk/punit/src/org/punit/events/EventRegistry.java
===================================================================
--- trunk/punit/src/org/punit/events/EventRegistry.java (rev 0)
+++ trunk/punit/src/org/punit/events/EventRegistry.java 2007-07-12 07:08:43 UTC (rev 229)
@@ -0,0 +1,31 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.events;
+
+import java.util.List;
+
+/**
+ * Interface for PUnit event registry. It can accept/remove a event
+ * listener.
+ */
+public interface EventRegistry {
+
+ /**
+ * Adds a new event listener.
+ *
+ * @param listener
+ */
+ public void addEventListener(EventListener listener);
+
+ /**
+ * Removes an event listener.
+ *
+ * @param listener
+ */
+ public void removeEventListener(EventListener listener);
+
+ /**
+ * @return returns the registered event listeners.
+ */
+ public List eventListeners();
+}
Deleted: trunk/punit/src/org/punit/events/PUnitEventListener.java
===================================================================
--- trunk/punit/src/org/punit/events/PUnitEventListener.java 2007-06-29 02:27:52 UTC (rev 228)
+++ trunk/punit/src/org/punit/events/PUnitEventListener.java 2007-07-12 07:08:43 UTC (rev 229)
@@ -1,107 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.events;
-
-import java.io.*;
-import java.lang.reflect.*;
-import java.util.*;
-
-import org.punit.runner.*;
-import org.punit.type.*;
-import org.punit.watcher.*;
-
-/**
- * Event system for punit. The event listener can be installed by
- * {@link PUnitEventRegsitry#addEventListener(PUnitEventListener)}.
- *
- * All punit runners implement {@link PUnitEventRegsitry}.
- *
- */
-public interface PUnitEventListener extends Serializable {
-...
[truncated message content] |
|
From: <zha...@us...> - 2008-02-26 05:51:36
|
Revision: 279
http://p-unit.svn.sourceforge.net/p-unit/?rev=279&view=rev
Author: zhanghuangzhu
Date: 2008-02-25 21:51:41 -0800 (Mon, 25 Feb 2008)
Log Message:
-----------
Andrew Zhang: find setUp method from the superclass too.
Modified Paths:
--------------
trunk/punit/core.jardesc
trunk/punit/src/org/punit/convention/NameConvention.java
trunk/punit/src/org/punit/util/ReflectionUtil.java
Modified: trunk/punit/core.jardesc
===================================================================
--- trunk/punit/core.jardesc 2008-02-20 12:18:41 UTC (rev 278)
+++ trunk/punit/core.jardesc 2008-02-26 05:51:41 UTC (rev 279)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="GBK" standalone="no"?>
<jardesc>
- <jar path="E:/workspace/p-unit/release/p-unit-0.14.jar"/>
+ <jar path="E:/workspace/p-unit/release/p-unit-0.14.257.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/punit/core.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/>
Modified: trunk/punit/src/org/punit/convention/NameConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/NameConvention.java 2008-02-20 12:18:41 UTC (rev 278)
+++ trunk/punit/src/org/punit/convention/NameConvention.java 2008-02-26 05:51:41 UTC (rev 279)
@@ -76,7 +76,7 @@
}
public Method getAfterClassMethod(Class<?> test) {
- Method method = ReflectionUtil.getMethodAndSetAccessible(test,
+ Method method = ReflectionUtil.getMethodAndSetAccessibleWithAncestor(test,
"afterClass", new Class[] {}); //$NON-NLS-1$
if (method != null && ReflectionUtil.isStatic(method)) {
return method;
@@ -85,7 +85,7 @@
}
public Method getBeforeClassMethod(Class<?> test) {
- Method method = ReflectionUtil.getMethodAndSetAccessible(test,
+ Method method = ReflectionUtil.getMethodAndSetAccessibleWithAncestor(test,
"beforeClass", new Class[] {}); //$NON-NLS-1$
if (method != null && ReflectionUtil.isStatic(method)) {
return method;
@@ -94,12 +94,12 @@
}
public Method getSetUpMethod(Class<?> test) {
- return ReflectionUtil.getMethodAndSetAccessible(test,
+ return ReflectionUtil.getMethodAndSetAccessibleWithAncestor(test,
"setUp", new Class[] {}); //$NON-NLS-1$
}
public Method getTearDownMethod(Class<?> test) {
- return ReflectionUtil.getMethodAndSetAccessible(test,
+ return ReflectionUtil.getMethodAndSetAccessibleWithAncestor(test,
"tearDown", new Class[] {}); //$NON-NLS-1$
}
}
Modified: trunk/punit/src/org/punit/util/ReflectionUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ReflectionUtil.java 2008-02-20 12:18:41 UTC (rev 278)
+++ trunk/punit/src/org/punit/util/ReflectionUtil.java 2008-02-26 05:51:41 UTC (rev 279)
@@ -12,108 +12,130 @@
public class ReflectionUtil {
- public static Object newInstance(Class<?> clazz) {
- try {
- Constructor<?> constructor = clazz
- .getDeclaredConstructor(new Class[] {});
- constructor.setAccessible(true);
- return constructor.newInstance(new Object[] {});
- } catch (Exception e) {
- throw new ReflectionException(e);
- }
- }
+ public static Object newInstance(Class<?> clazz) {
+ try {
+ Constructor<?> constructor = clazz
+ .getDeclaredConstructor(new Class[] {});
+ constructor.setAccessible(true);
+ return constructor.newInstance(new Object[] {});
+ } catch (Exception e) {
+ throw new ReflectionException(e);
+ }
+ }
- public static Class<?> newClass(String className) {
- try {
- return Class.forName(className);
- } catch (Exception e) {
- throw new ReflectionException(e);
- }
- }
+ public static Class<?> newClass(String className) {
+ try {
+ return Class.forName(className);
+ } catch (Exception e) {
+ throw new ReflectionException(e);
+ }
+ }
- public static Method getMethod(Class<?> clazz, String methodName,
- Class<?>[] params) {
- try {
- Method method = clazz.getDeclaredMethod(methodName, params);
- return method;
- } catch (Exception e) {
- return null;
- }
- }
+ public static Method getMethod(Class<?> clazz, String methodName,
+ Class<?>[] params) {
+ try {
+ Method method = clazz.getDeclaredMethod(methodName, params);
+ return method;
+ } catch (Exception e) {
+ return null;
+ }
+ }
- /**
- * Sets a field with a given value after converting the value to the field
- * type.
- *
- * @param field
- * the field to assign
- * @param value
- * the string value to assign
- */
- public static void setField(Object testInstance, Field field, String value) {
- try {
- field.setAccessible(true);
- Class<?> fieldClass = field.getType();
- if (fieldClass.equals(int.class)) {
- int intVal = Integer.parseInt(value);
- field.setInt(testInstance, intVal);
- } else if (fieldClass.equals(long.class)) {
- long longVal = Long.parseLong(value);
+ /**
+ * Sets a field with a given value after converting the value to the field
+ * type.
+ *
+ * @param field
+ * the field to assign
+ * @param value
+ * the string value to assign
+ */
+ public static void setField(Object testInstance, Field field, String value) {
+ try {
+ field.setAccessible(true);
+ Class<?> fieldClass = field.getType();
+ if (fieldClass.equals(int.class)) {
+ int intVal = Integer.parseInt(value);
+ field.setInt(testInstance, intVal);
+ } else if (fieldClass.equals(long.class)) {
+ long longVal = Long.parseLong(value);
- field.setLong(testInstance, longVal);
- } else {
- field.set(testInstance, value);
- }
- } catch (NumberFormatException nfe) {
- throw new IllegalArgumentException(nfe);
- } catch (Exception e) {
- throw new ReflectionException(e);
- }
- }
+ field.setLong(testInstance, longVal);
+ } else {
+ field.set(testInstance, value);
+ }
+ } catch (NumberFormatException nfe) {
+ throw new IllegalArgumentException(nfe);
+ } catch (Exception e) {
+ throw new ReflectionException(e);
+ }
+ }
- /**
- * Gets the method and sets the accessible to true
- *
- * @param clazz
- * @param methodName
- * @param params
- * @return
- */
- public static Method getMethodAndSetAccessible(Class<?> clazz,
- String methodName, Class<?>[] params) {
- try {
- Method method = clazz.getDeclaredMethod(methodName, params);
- method.setAccessible(true);
- return method;
- } catch (Exception e) {
- return null;
- }
- }
+ /**
+ * Gets the method and sets the accessible to true
+ *
+ * @param clazz
+ * @param methodName
+ * @param params
+ * @return
+ */
+ public static Method getMethodAndSetAccessible(Class<?> clazz,
+ String methodName, Class<?>[] params) {
+ try {
+ Method method = clazz.getDeclaredMethod(methodName, params);
+ method.setAccessible(true);
+ return method;
+ } catch (Exception e) {
+ return null;
+ }
+ }
- public static Object invokeMethod(Method method, Object instance,
- Object[] params) throws ReflectionException {
- try {
- return method.invoke(instance, params);
- } catch (IllegalArgumentException e) {
- throw new ReflectionException(e);
- } catch (IllegalAccessException e) {
- throw new ReflectionException(e);
- } catch (InvocationTargetException e) {
- throw new ReflectionException(e.getTargetException());
- }
- }
+ /**
+ * Gets the method from this class or its superclass. Sets the accessible
+ * of this method to true.
+ *
+ * @param clazz
+ * @param methodName
+ * @param params
+ * @return
+ */
+ public static Method getMethodAndSetAccessibleWithAncestor(Class<?> clazz,
+ String methodName, Class<?>[] params) {
+ Class<?> currentClass = clazz;
+ while (currentClass != null) {
+ Method method = getMethodAndSetAccessible(currentClass, methodName, params);
+ if(method != null) {
+ return method;
+ }
+ currentClass = currentClass.getSuperclass();
+ }
+ return null;
+ }
- public static boolean isPublic(Method method) {
- int modifier = method.getModifiers();
- return isBitSet(modifier, Modifier.PUBLIC);
- }
+ public static Object invokeMethod(Method method, Object instance,
+ Object[] params) throws ReflectionException {
+ try {
+ return method.invoke(instance, params);
+ } catch (IllegalArgumentException e) {
+ throw new ReflectionException(e);
+ } catch (IllegalAccessException e) {
+ throw new ReflectionException(e);
+ } catch (InvocationTargetException e) {
+ throw new ReflectionException(e.getTargetException());
+ }
+ }
- public static boolean isStatic(Method method) {
- int modifier = method.getModifiers();
- return isBitSet(modifier, Modifier.STATIC);
- }
+ public static boolean isPublic(Method method) {
+ int modifier = method.getModifiers();
+ return isBitSet(modifier, Modifier.PUBLIC);
+ }
- private static boolean isBitSet(int value, int expectedBit) {
- return (value & expectedBit) != 0;
- }
+ public static boolean isStatic(Method method) {
+ int modifier = method.getModifiers();
+ return isBitSet(modifier, Modifier.STATIC);
+ }
+
+ private static boolean isBitSet(int value, int expectedBit) {
+ return (value & expectedBit) != 0;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|