Thread: [P-unit-devel] SF.net SVN: p-unit: [206] trunk/punit (Page 4)
Status: Beta
Brought to you by:
zhanghuangzhu
|
From: <zha...@us...> - 2007-06-14 15:16:44
|
Revision: 206
http://p-unit.svn.sourceforge.net/p-unit/?rev=206&view=rev
Author: zhanghuangzhu
Date: 2007-06-14 08:16:45 -0700 (Thu, 14 Jun 2007)
Log Message:
-----------
Andrew Zhang: refactored filter to convention.
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/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/method/builder/TestMethodBuilderTest.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/JUnitAnnotationTestClass.java
Added Paths:
-----------
trunk/punit/src/org/punit/filter/Convention.java
trunk/punit/src/org/punit/filter/NameConvention.java
trunk/punit.extension/src/org/punit/filter/AnnotationConvention.java
trunk/punit.extension/src/org/punit/filter/JUnitAnnotationConvention.java
Removed Paths:
-------------
trunk/punit/src/org/punit/filter/Filter.java
trunk/punit/src/org/punit/filter/NameConventionFilter.java
trunk/punit.extension/src/org/punit/filter/AnnotationFilter.java
trunk/punit.extension/src/org/punit/filter/JUnitAnnotationFilter.java
Copied: trunk/punit/src/org/punit/filter/Convention.java (from rev 203, trunk/punit/src/org/punit/filter/Filter.java)
===================================================================
--- trunk/punit/src/org/punit/filter/Convention.java (rev 0)
+++ trunk/punit/src/org/punit/filter/Convention.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -0,0 +1,46 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.filter;
+
+import java.io.*;
+import java.lang.reflect.*;
+
+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);
+
+ /**
+ * 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/filter/Filter.java
===================================================================
--- trunk/punit/src/org/punit/filter/Filter.java 2007-06-14 15:12:59 UTC (rev 205)
+++ trunk/punit/src/org/punit/filter/Filter.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -1,46 +0,0 @@
-/* (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/NameConvention.java (from rev 205, trunk/punit/src/org/punit/filter/NameConventionFilter.java)
===================================================================
--- trunk/punit/src/org/punit/filter/NameConvention.java (rev 0)
+++ trunk/punit/src/org/punit/filter/NameConvention.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -0,0 +1,124 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.filter;
+
+import java.lang.reflect.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class NameConvention implements Convention {
+
+ 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) {
+ 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 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$
+ }
+
+
+}
Deleted: trunk/punit/src/org/punit/filter/NameConventionFilter.java
===================================================================
--- trunk/punit/src/org/punit/filter/NameConventionFilter.java 2007-06-14 15:12:59 UTC (rev 205)
+++ trunk/punit/src/org/punit/filter/NameConventionFilter.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -1,124 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.filter;
-
-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) {
- 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 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 15:12:59 UTC (rev 205)
+++ trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -17,9 +17,9 @@
private static final long serialVersionUID = -6593981780599574964L;
- private Filter _filter;
+ private Convention _filter;
- public void setMethodFilter(Filter filter) {
+ public void setMethodFilter(Convention filter) {
_filter = filter;
}
Modified: trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-06-14 15:12:59 UTC (rev 205)
+++ trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -24,5 +24,5 @@
public Collection buildTestMethods(Class testClass);
- public void setMethodFilter(Filter filter);
+ public void setMethodFilter(Convention filter);
}
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-14 15:12:59 UTC (rev 205)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -24,7 +24,7 @@
private RunnerProperties _runnerProperties;
- protected Filter _filter;
+ protected Convention _filter;
protected transient Object _testInstance;
@@ -301,7 +301,7 @@
}
}
- public void setMethodFilter(Filter filter) {
+ public void setMethodFilter(Convention filter) {
_filter = filter;
}
Modified: trunk/punit/src/org/punit/method/runner/MethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/MethodRunner.java 2007-06-14 15:12:59 UTC (rev 205)
+++ trunk/punit/src/org/punit/method/runner/MethodRunner.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -38,5 +38,5 @@
public Object clone();
- public void setMethodFilter(Filter filter);
+ public void setMethodFilter(Convention filter);
}
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-14 15:12:59 UTC (rev 205)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -33,7 +33,7 @@
private ExecutorPool _executorPool;
- private Filter _filter;
+ private Convention _filter;
public AbstractRunner(TestSuiteBuilder testSuiteBuiler,
TestMethodBuilder testMethodBuilder, MethodRunner testMethodRunner) {
@@ -43,10 +43,10 @@
_methodRunner.setEventListeners(_eventListeners);
_methodRunner.setRunnerProperties(_properties);
registerLoggerListeners();
- setFilter(new NameConventionFilter());
+ setFilter(new NameConvention());
}
- public void setFilter(Filter filter) {
+ public void setFilter(Convention filter) {
_filter = filter;
_testSuiteBuiler.setFilter(filter);
_testMethodBuilder.setMethodFilter(filter);
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-14 15:12:59 UTC (rev 205)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -20,5 +20,5 @@
*/
public Object[] buildTestClasses(Class testSutie);
- public void setFilter(Filter filter);
+ public void setFilter(Convention filter);
}
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-14 15:12:59 UTC (rev 205)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -12,9 +12,9 @@
private static final long serialVersionUID = -4468961881014123138L;
- private Filter _filter;
+ private Convention _filter;
- public void setFilter(Filter filter) {
+ public void setFilter(Convention filter) {
_filter = filter;
}
Copied: trunk/punit.extension/src/org/punit/filter/AnnotationConvention.java (from rev 203, trunk/punit.extension/src/org/punit/filter/AnnotationFilter.java)
===================================================================
--- trunk/punit.extension/src/org/punit/filter/AnnotationConvention.java (rev 0)
+++ trunk/punit.extension/src/org/punit/filter/AnnotationConvention.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -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 AnnotationConvention implements Convention {
+
+ private static final long serialVersionUID = -2043378593194849589L;
+
+ private NameConvention _delegate = new NameConvention();
+
+ 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/filter/AnnotationFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/filter/AnnotationFilter.java 2007-06-14 15:12:59 UTC (rev 205)
+++ trunk/punit.extension/src/org/punit/filter/AnnotationFilter.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -1,112 +0,0 @@
-/* (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/JUnitAnnotationConvention.java (from rev 203, trunk/punit.extension/src/org/punit/filter/JUnitAnnotationFilter.java)
===================================================================
--- trunk/punit.extension/src/org/punit/filter/JUnitAnnotationConvention.java (rev 0)
+++ trunk/punit.extension/src/org/punit/filter/JUnitAnnotationConvention.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -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 JUnitAnnotationConvention implements Convention {
+
+ private static final long serialVersionUID = 2826000346348614825L;
+
+ private NameConvention _delegate = new NameConvention();
+
+ 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/filter/JUnitAnnotationFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/filter/JUnitAnnotationFilter.java 2007-06-14 15:12:59 UTC (rev 205)
+++ trunk/punit.extension/src/org/punit/filter/JUnitAnnotationFilter.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -1,86 +0,0 @@
-/* (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;
- }
-}
Modified: trunk/punit.test/src/tests/api/org/punit/filter/AnnotationFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/...
[truncated message content] |
|
From: <zha...@us...> - 2007-06-15 04:42:06
|
Revision: 210
http://p-unit.svn.sourceforge.net/p-unit/?rev=210&view=rev
Author: zhanghuangzhu
Date: 2007-06-14 21:42:00 -0700 (Thu, 14 Jun 2007)
Log Message:
-----------
Andrew Zhang: refactored setFilter to setConvention.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit.samples/.classpath
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/JUnitAnnotationTestClass.java
Added Paths:
-----------
trunk/punit.samples/src/samples/JUnitAnnotationSample.java
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-15 03:56:43 UTC (rev 209)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-15 04:42:00 UTC (rev 210)
@@ -43,10 +43,10 @@
_methodRunner.setEventListeners(_eventListeners);
_methodRunner.setRunnerProperties(_properties);
registerLoggerListeners();
- setFilter(new NameConvention());
+ setConvention(new NameConvention());
}
- public void setFilter(Convention filter) {
+ public void setConvention(Convention filter) {
_filter = filter;
_testSuiteBuiler.setFilter(filter);
_testMethodBuilder.setMethodFilter(filter);
Modified: trunk/punit.samples/.classpath
===================================================================
--- trunk/punit.samples/.classpath 2007-06-15 03:56:43 UTC (rev 209)
+++ trunk/punit.samples/.classpath 2007-06-15 04:42:00 UTC (rev 210)
@@ -4,6 +4,5 @@
<classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"/>
<classpathentry path="/punit" combineaccessrules="false" kind="src"/>
<classpathentry path="/punit.extension" combineaccessrules="false" kind="src"/>
- <classpathentry path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1" kind="con"/>
<classpathentry path="bin" kind="output"/>
</classpath>
Added: trunk/punit.samples/src/samples/JUnitAnnotationSample.java
===================================================================
--- trunk/punit.samples/src/samples/JUnitAnnotationSample.java (rev 0)
+++ trunk/punit.samples/src/samples/JUnitAnnotationSample.java 2007-06-15 04:42:00 UTC (rev 210)
@@ -0,0 +1,34 @@
+package samples;
+
+import org.junit.*;
+import org.punit.convention.*;
+import org.punit.runner.*;
+
+import junit.framework.*;
+
+public class JUnitAnnotationSample extends TestCase {
+
+ public static void main(String[] args) {
+ SoloRunner runner = new SoloRunner();
+ runner.setConvention(new JUnitAnnotationConvention());
+ runner.run(JUnitAnnotationSample.class);
+ }
+
+ @BeforeClass
+ public static void init() {
+ System.out.println("beforeClass");
+ }
+
+ @AfterClass
+ public static void close() {
+ System.out.println("afterClass");
+ }
+
+ public void test1() {
+ System.out.println("test1");
+ }
+
+ public void test2() {
+ System.out.println("test2");
+ }
+}
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-15 03:56:43 UTC (rev 209)
+++ trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2007-06-15 04:42:00 UTC (rev 210)
@@ -41,7 +41,7 @@
public void testRunAnnotationTest() {
AnnotationTestClass.reset();
- _runner.setFilter(new AnnotationConvention());
+ _runner.setConvention(new AnnotationConvention());
_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-15 03:56:43 UTC (rev 209)
+++ trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2007-06-15 04:42:00 UTC (rev 210)
@@ -37,7 +37,7 @@
public void testRunAnnotationTest() {
AnnotationTestClass.reset();
- _runner.setFilter(new AnnotationConvention());
+ _runner.setConvention(new AnnotationConvention());
_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-15 03:56:43 UTC (rev 209)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-06-15 04:42:00 UTC (rev 210)
@@ -12,7 +12,7 @@
public static void main(String[] args) {
SoloRunner soloRunner = new SoloRunner();
- soloRunner.setFilter(new AnnotationConvention());
+ soloRunner.setConvention(new AnnotationConvention());
soloRunner.run(AnnotationTestClass.class);
}
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/JUnitAnnotationTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/JUnitAnnotationTestClass.java 2007-06-15 03:56:43 UTC (rev 209)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/JUnitAnnotationTestClass.java 2007-06-15 04:42:00 UTC (rev 210)
@@ -8,7 +8,7 @@
public static void main(String[] args) {
SoloRunner soloRunner = new SoloRunner();
- soloRunner.setFilter(new AnnotationConvention());
+ soloRunner.setConvention(new AnnotationConvention());
soloRunner.run(JUnitAnnotationTestClass.class);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-06-23 13:07:45
|
Revision: 221
http://p-unit.svn.sourceforge.net/p-unit/?rev=221&view=rev
Author: zhanghuangzhu
Date: 2007-06-23 06:07:46 -0700 (Sat, 23 Jun 2007)
Log Message:
-----------
Andrew Zhang: combined two getConcurrent methods in the Convention interface.
Modified Paths:
--------------
trunk/punit/src/org/punit/convention/Convention.java
trunk/punit/src/org/punit/convention/NameConvention.java
trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java
trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.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
Added Paths:
-----------
trunk/punit/src/org/punit/type/Loop.java
Modified: trunk/punit/src/org/punit/convention/Convention.java
===================================================================
--- trunk/punit/src/org/punit/convention/Convention.java 2007-06-18 12:58:04 UTC (rev 220)
+++ trunk/punit/src/org/punit/convention/Convention.java 2007-06-23 13:07:46 UTC (rev 221)
@@ -32,10 +32,8 @@
public Class getExpectedException(Method method);
- public int getConcurrentCount(Method method);
+ public int getConcurrentCount(Object testInstance, Method method);
- public int getConcurrentCount(Object testInstance);
-
public Method getSetupMethod(Class test);
public Method getTearDownMethod(Class test);
@@ -43,4 +41,8 @@
public Method getBeforeClassMethod(Class test);
public Method getAfterClassMethod(Class test);
+
+ public int getToStop(Method method);
+
+ public int getToAbort(Method method);
}
Modified: trunk/punit/src/org/punit/convention/NameConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/NameConvention.java 2007-06-18 12:58:04 UTC (rev 220)
+++ trunk/punit/src/org/punit/convention/NameConvention.java 2007-06-23 13:07:46 UTC (rev 221)
@@ -85,11 +85,7 @@
return null;
}
- public int getConcurrentCount(Method method) {
- return 0;
- }
-
- public int getConcurrentCount(Object testInstance) {
+ public int getConcurrentCount(Object testInstance, Method method) {
if(testInstance instanceof Concurrent) {
return ((Concurrent)testInstance).concurrentCount();
}
@@ -120,5 +116,13 @@
return ReflectionUtil.getMethodAndSetAccessible(test, "tearDown", new Class[] {}); //$NON-NLS-1$
}
+ public int getToAbort(Method method) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getToStop(Method method) {
+ throw new UnsupportedOperationException();
+ }
+
}
Modified: trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2007-06-18 12:58:04 UTC (rev 220)
+++ trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2007-06-23 13:07:46 UTC (rev 221)
@@ -48,15 +48,8 @@
}
private void initThreads() {
- int threadCount = _concurrentCount;
- int count = _convention.getConcurrentCount(_testInstance);
- if(count > 0) {
- threadCount = count;
- }
- count = _convention.getConcurrentCount(_method);
- if(count > 0) {
- threadCount = count;
- }
+ int count = _convention.getConcurrentCount(_testInstance, _method);
+ int threadCount = count > 0? count : _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$
Added: trunk/punit/src/org/punit/type/Loop.java
===================================================================
--- trunk/punit/src/org/punit/type/Loop.java (rev 0)
+++ trunk/punit/src/org/punit/type/Loop.java 2007-06-23 13:07:46 UTC (rev 221)
@@ -0,0 +1,19 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.type;
+
+/**
+ * If a test implements this interface, punit concurrent runner will executes
+ * its method concurrently.
+ */
+public interface Loop {
+ /**
+ * @return returns the time to stop the loop
+ */
+ public long toStop();
+
+ /**
+ * @return returns the time to stop the loop
+ */
+ public long toAbort();
+}
Modified: trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java
===================================================================
--- trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java 2007-06-18 12:58:04 UTC (rev 220)
+++ trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java 2007-06-23 13:07:46 UTC (rev 221)
@@ -57,18 +57,13 @@
return expected;
}
- public int getConcurrentCount(Method method) {
+ public int getConcurrentCount(Object testInstance, Method method) {
Test testAnnotation = getTestAnnotation(method);
if(testAnnotation == null) {
- return 0;
+ testAnnotation = getTestAnnotation(testInstance.getClass());
}
- return testAnnotation.concurrentCount();
- }
-
- public int getConcurrentCount(Object testInstnace) {
- Test testAnnotation = getTestAnnotation(testInstnace.getClass());
if(testAnnotation == null) {
- return _delegate.getConcurrentCount(testInstnace);
+ return _delegate.getConcurrentCount(testInstance, method);
}
return testAnnotation.concurrentCount();
}
@@ -112,4 +107,12 @@
}
return method;
}
+
+ public int getToAbort(Method method) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getToStop(Method method) {
+ throw new UnsupportedOperationException();
+ }
}
Modified: trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java
===================================================================
--- trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java 2007-06-18 12:58:04 UTC (rev 220)
+++ trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java 2007-06-23 13:07:46 UTC (rev 221)
@@ -43,13 +43,9 @@
return expected;
}
- public int getConcurrentCount(Method method) {
- return 0;
+ public int getConcurrentCount(Object testInstance, Method method) {
+ return _delegate.getConcurrentCount(testInstance, method);
}
-
- public int getConcurrentCount(Object testInstnace) {
- return _delegate.getConcurrentCount(testInstnace);
- }
private Test getTestAnnotation(Method method) {
return method.getAnnotation(Test.class);
@@ -86,4 +82,12 @@
}
return method;
}
+
+ public int getToAbort(Method method) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getToStop(Method method) {
+ throw new UnsupportedOperationException();
+ }
}
Modified: trunk/punit.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java 2007-06-18 12:58:04 UTC (rev 220)
+++ trunk/punit.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java 2007-06-23 13:07:46 UTC (rev 221)
@@ -7,7 +7,6 @@
import junit.framework.*;
import org.punit.annotation.*;
-import org.punit.annotation.Test;
import org.punit.convention.*;
import org.punit.util.*;
@@ -67,21 +66,25 @@
}
public void testGetConcurrentCount1() {
+ Method method = ReflectionUtil.getMethod(ConcurrentTestClass.class, "test1", new Class[] {}); //$NON-NLS-1$
ConcurrentTestClass test = new ConcurrentTestClass();
- int count = _filter.getConcurrentCount(test);
+ int count = _filter.getConcurrentCount(test, method);
assertEquals(test.concurrentCount(), count);
- assertEquals(0, _filter.getConcurrentCount(new TestClass()));
+
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "test1", new Class[] {}); //$NON-NLS-1$
+ assertEquals(0, _filter.getConcurrentCount(new TestClass(), method));
}
public void testGetConcurrentCountClass() {
+ Method method = ReflectionUtil.getMethod(AnnotationTestClass.class, "test1", new Class[] {}); //$NON-NLS-1$
AnnotationTestClass test = new AnnotationTestClass();
- int count = _filter.getConcurrentCount(test);
+ int count = _filter.getConcurrentCount(test, method);
assertEquals(5, count);
}
public void testGetConcurrentCountMethod() {
Method method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
- int count = _filter.getConcurrentCount(method);
+ int count = _filter.getConcurrentCount(new AnnotationTestClass(), method);
assertEquals(6, count);
}
Modified: trunk/punit.test/src/tests/api/org/punit/convention/JUnitAnnotationConventionTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/convention/JUnitAnnotationConventionTest.java 2007-06-18 12:58:04 UTC (rev 220)
+++ trunk/punit.test/src/tests/api/org/punit/convention/JUnitAnnotationConventionTest.java 2007-06-23 13:07:46 UTC (rev 221)
@@ -72,21 +72,25 @@
}
public void testGetConcurrentCount1() {
+ Method method = ReflectionUtil.getMethod(ConcurrentTestClass.class, "test1", new Class[] {}); //$NON-NLS-1$
ConcurrentTestClass test = new ConcurrentTestClass();
- int count = _filter.getConcurrentCount(test);
+ int count = _filter.getConcurrentCount(test, method);
assertEquals(test.concurrentCount(), count);
- assertEquals(0, _filter.getConcurrentCount(new TestClass()));
+
+ method = ReflectionUtil.getMethod(TestClass.class, "test1", new Class[] {}); //$NON-NLS-1$
+ assertEquals(0, _filter.getConcurrentCount(new TestClass(), method));
}
public void testGetConcurrentCountClass() {
+ Method method = ReflectionUtil.getMethod(JUnitAnnotationTestClass.class, "test1", new Class[] {}); //$NON-NLS-1$
JUnitAnnotationTestClass test = new JUnitAnnotationTestClass();
- int count = _filter.getConcurrentCount(test);
+ int count = _filter.getConcurrentCount(test, method);
assertEquals(0, count);
}
public void testGetConcurrentCountMethod() {
Method method = ReflectionUtil.getMethod(JUnitAnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
- int count = _filter.getConcurrentCount(method);
+ int count = _filter.getConcurrentCount(new JUnitAnnotationTestClass(), method);
assertEquals(0, count);
}
Modified: trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java 2007-06-18 12:58:04 UTC (rev 220)
+++ trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java 2007-06-23 13:07:46 UTC (rev 221)
@@ -36,10 +36,13 @@
}
public void testGetConcurrentCount() {
+ Method method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$
ConcurrentTestClass test = new ConcurrentTestClass();
- int count = _filter.getConcurrentCount(test);
+ int count = _filter.getConcurrentCount(test, method);
assertEquals(test.concurrentCount(), count);
- assertEquals(0, _filter.getConcurrentCount(new TestClass()));
+
+ method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$
+ assertEquals(0, _filter.getConcurrentCount(new TestClass(), method));
}
public void testGetSetUpMethod() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-06-24 05:27:23
|
Revision: 222
http://p-unit.svn.sourceforge.net/p-unit/?rev=222&view=rev
Author: zhanghuangzhu
Date: 2007-06-23 22:27:25 -0700 (Sat, 23 Jun 2007)
Log Message:
-----------
Andrew Zhang:
1. TestResult is added as a default listener
2. return value for runner
Modified Paths:
--------------
trunk/punit/src/org/punit/convention/Convention.java
trunk/punit/src/org/punit/convention/NameConvention.java
trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java
trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java
Added Paths:
-----------
trunk/punit/src/org/punit/reporter/TestResult.java
Removed Paths:
-------------
trunk/punit/src/org/punit/reporter/stream/TestResult.java
Modified: trunk/punit/src/org/punit/convention/Convention.java
===================================================================
--- trunk/punit/src/org/punit/convention/Convention.java 2007-06-23 13:07:46 UTC (rev 221)
+++ trunk/punit/src/org/punit/convention/Convention.java 2007-06-24 05:27:25 UTC (rev 222)
@@ -42,7 +42,7 @@
public Method getAfterClassMethod(Class test);
- public int getToStop(Method method);
+ public int getToStop(Object testInstance);
- public int getToAbort(Method method);
+ public int getToAbort(Object testInstance);
}
Modified: trunk/punit/src/org/punit/convention/NameConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/NameConvention.java 2007-06-23 13:07:46 UTC (rev 221)
+++ trunk/punit/src/org/punit/convention/NameConvention.java 2007-06-24 05:27:25 UTC (rev 222)
@@ -116,12 +116,18 @@
return ReflectionUtil.getMethodAndSetAccessible(test, "tearDown", new Class[] {}); //$NON-NLS-1$
}
- public int getToAbort(Method method) {
- throw new UnsupportedOperationException();
+ public int getToAbort(Object testInstance) {
+ if(testInstance instanceof Loop) {
+ ((Loop) testInstance).toAbort();
+ }
+ return 0;
}
- public int getToStop(Method method) {
- throw new UnsupportedOperationException();
+ public int getToStop(Object testInstance) {
+ if(testInstance instanceof Loop) {
+ ((Loop) testInstance).toStop();
+ }
+ return 0;
}
Added: trunk/punit/src/org/punit/reporter/TestResult.java
===================================================================
--- trunk/punit/src/org/punit/reporter/TestResult.java (rev 0)
+++ trunk/punit/src/org/punit/reporter/TestResult.java 2007-06-24 05:27:25 UTC (rev 222)
@@ -0,0 +1,92 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+package org.punit.reporter;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+import org.punit.events.*;
+import org.punit.runner.*;
+import org.punit.type.*;
+import org.punit.watcher.*;
+
+public class TestResult implements PUnitEventListener {
+
+ private static final long serialVersionUID = -5770657966003459019L;
+
+ private transient int _methodCount;
+
+ private List _failures = new ArrayList();
+
+ public void onMethodEnd(Method method, Object testInstance, Object[] params, Throwable t, List Watchers) {
+ countMethod();
+ if (t != null) {
+ addThrowable(t);
+ }
+ }
+
+ public synchronized void countMethod() {
+ ++_methodCount;
+ }
+
+ public synchronized void addThrowable(Throwable t) {
+ _failures.add(t);
+ }
+
+ public int methodCount() {
+ return _methodCount;
+ }
+
+ public List failures() {
+ return _failures;
+ }
+
+ public void onClassEnd(Class clazz) {
+
+ }
+
+ public void onClassStart(Class clazz) {
+
+ }
+
+
+ public void onMethodStart(Method method, Object testInstance, Object[] params) {
+
+ }
+
+ public void onRunnerEnd(Class clazz, Runner runner) {
+
+ }
+
+ public void onRunnerStart(Class clazz, Runner runner) {
+
+ }
+
+ public void onSuiteEnd(PUnitTestSuite suite) {
+
+ }
+
+ public void onSuiteStart(PUnitTestSuite suite) {
+
+ }
+
+ public void onWatcherEnd(Watcher watcher) {
+
+ }
+
+ public void onWatcherStart(Watcher watcher) {
+
+ }
+
+ public void onWatchersEnd(List watchers) {
+
+ }
+
+ public void onWatchersStart(List watchers) {
+
+ }
+
+ public boolean supportParentRunner() {
+ return false;
+ }
+
+}
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2007-06-23 13:07:46 UTC (rev 221)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2007-06-24 05:27:25 UTC (rev 222)
@@ -9,6 +9,7 @@
import org.punit.events.*;
import org.punit.message.*;
+import org.punit.reporter.*;
import org.punit.runner.*;
import org.punit.type.*;
import org.punit.util.*;
@@ -36,7 +37,7 @@
public void onRunnerStart(Class clazz, Runner runner) {
startTimeWatcher();
- _result = new TestResult();
+ _result = runner.testResult();
StringBuffer sb = new StringBuffer();
sb.append("["); //$NON-NLS-1$
sb.append(runner.punitName());
@@ -108,10 +109,6 @@
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) {
Deleted: trunk/punit/src/org/punit/reporter/stream/TestResult.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/TestResult.java 2007-06-23 13:07:46 UTC (rev 221)
+++ trunk/punit/src/org/punit/reporter/stream/TestResult.java 2007-06-24 05:27:25 UTC (rev 222)
@@ -1,27 +0,0 @@
-/* (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/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-23 13:07:46 UTC (rev 221)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-24 05:27:25 UTC (rev 222)
@@ -11,6 +11,7 @@
import org.punit.exception.*;
import org.punit.method.builder.*;
import org.punit.method.runner.*;
+import org.punit.reporter.*;
import org.punit.reporter.stream.console.*;
import org.punit.suite.builder.*;
import org.punit.type.*;
@@ -27,6 +28,8 @@
// List <PUnitEventListener>
private final List _eventListeners = new ArrayList();
+ private TestResult _testResult = new TestResult();
+
private ConsoleLogger _consoleLogger = new ConsoleLogger();
private RunnerProperties _properties = new RunnerProperties();
@@ -42,7 +45,7 @@
_methodRunner = testMethodRunner;
_methodRunner.setEventListeners(_eventListeners);
_methodRunner.setRunnerProperties(_properties);
- registerLoggerListeners();
+ registerDefaultListeners();
setConvention(new NameConvention());
}
@@ -53,14 +56,20 @@
_methodRunner.setConvention(convention);
}
- public void run(Class clazz) {
+ public int run(Class clazz) {
initResultFolder();
onRunnerStart(clazz);
Object[] testClasses = _testSuiteBuiler.buildTestClasses(clazz);
runTestClasses(testClasses);
onRunnerEnd(clazz);
+ return _testResult.failures().size();
}
+ public int run(Class clazz, RunnerProperties properties) {
+ setRunnerProperties(properties);
+ return run(clazz);
+ }
+
private void runTestClasses(Object[] testClasses) {
startExecutorPool();
for (int i = 0; i < testClasses.length; ++i) {
@@ -90,11 +99,6 @@
}
}
- public void run(Class clazz, RunnerProperties properties) {
- setRunnerProperties(properties);
- run(clazz);
- }
-
private void setRunnerProperties(RunnerProperties properties) {
_properties = properties;
_methodRunner.setRunnerProperties(_properties);
@@ -336,7 +340,8 @@
return _testSuiteBuiler;
}
- private void registerLoggerListeners() {
+ private void registerDefaultListeners() {
+ addEventListener(_testResult);
addEventListener(_consoleLogger);
}
@@ -373,4 +378,8 @@
throw new ReflectionException(e);
}
}
+
+ public TestResult testResult() {
+ return _testResult;
+ }
}
Modified: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java 2007-06-23 13:07:46 UTC (rev 221)
+++ trunk/punit/src/org/punit/runner/Runner.java 2007-06-24 05:27:25 UTC (rev 222)
@@ -7,14 +7,15 @@
import org.punit.events.*;
import org.punit.method.builder.*;
import org.punit.method.runner.*;
+import org.punit.reporter.*;
import org.punit.suite.builder.*;
import org.punit.type.*;
public interface Runner extends PUnitEventRegsitry, PUnitName, Serializable, Cloneable {
- public void run(Class clazz);
+ public int run(Class clazz);
- public void run(Class clazz, RunnerProperties properties);
+ public int run(Class clazz, RunnerProperties properties);
public RunnerProperties properties();
@@ -23,5 +24,7 @@
public MethodRunner methodRunner();
public TestSuiteBuilder suiteBuiler();
+
+ public TestResult testResult();
}
Modified: trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java
===================================================================
--- trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java 2007-06-23 13:07:46 UTC (rev 221)
+++ trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java 2007-06-24 05:27:25 UTC (rev 222)
@@ -108,11 +108,11 @@
return method;
}
- public int getToAbort(Method method) {
+ public int getToAbort(Object testInstance) {
throw new UnsupportedOperationException();
}
- public int getToStop(Method method) {
+ public int getToStop(Object testInstance) {
throw new UnsupportedOperationException();
}
}
Modified: trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java
===================================================================
--- trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java 2007-06-23 13:07:46 UTC (rev 221)
+++ trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java 2007-06-24 05:27:25 UTC (rev 222)
@@ -83,11 +83,11 @@
return method;
}
- public int getToAbort(Method method) {
+ public int getToAbort(Object testInstance) {
throw new UnsupportedOperationException();
}
- public int getToStop(Method method) {
+ public int getToStop(Object testInstance) {
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-06-25 01:24:48
|
Revision: 223
http://p-unit.svn.sourceforge.net/p-unit/?rev=223&view=rev
Author: zhanghuangzhu
Date: 2007-06-24 18:24:49 -0700 (Sun, 24 Jun 2007)
Log Message:
-----------
Andrew Zhang: First implementation for Loop test.
Modified Paths:
--------------
trunk/punit/src/org/punit/convention/Convention.java
trunk/punit/src/org/punit/convention/NameConvention.java
trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java
trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java
Added Paths:
-----------
trunk/punit/src/org/punit/method/runner/ToStopThread.java
Modified: trunk/punit/src/org/punit/convention/Convention.java
===================================================================
--- trunk/punit/src/org/punit/convention/Convention.java 2007-06-24 05:27:25 UTC (rev 222)
+++ trunk/punit/src/org/punit/convention/Convention.java 2007-06-25 01:24:49 UTC (rev 223)
@@ -42,6 +42,8 @@
public Method getAfterClassMethod(Class test);
+ public boolean isLoopTest(Object testInstance);
+
public int getToStop(Object testInstance);
public int getToAbort(Object testInstance);
Modified: trunk/punit/src/org/punit/convention/NameConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/NameConvention.java 2007-06-24 05:27:25 UTC (rev 222)
+++ trunk/punit/src/org/punit/convention/NameConvention.java 2007-06-25 01:24:49 UTC (rev 223)
@@ -116,15 +116,19 @@
return ReflectionUtil.getMethodAndSetAccessible(test, "tearDown", new Class[] {}); //$NON-NLS-1$
}
+ public boolean isLoopTest(Object testInstance) {
+ return testInstance instanceof Loop;
+ }
+
public int getToAbort(Object testInstance) {
- if(testInstance instanceof Loop) {
+ if(isLoopTest(testInstance)) {
((Loop) testInstance).toAbort();
}
return 0;
}
public int getToStop(Object testInstance) {
- if(testInstance instanceof Loop) {
+ if(isLoopTest(testInstance)) {
((Loop) testInstance).toStop();
}
return 0;
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-24 05:27:25 UTC (rev 222)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-25 01:24:49 UTC (rev 223)
@@ -26,6 +26,10 @@
protected Convention _convention;
+ private transient ToStopThread _toStopThread;
+
+ private transient boolean _isLoop;
+
protected transient Object _testInstance;
protected transient Method _method;
@@ -72,10 +76,14 @@
try {
if (needsRunMethod()) {
init(testInstance, method, params);
- setUpBeforeWatchers(params);
- startWatchers(testInstance, method, params);
- setUpAfterWatchers(params);
- runImpl();
+ startToStopThread();
+ do {
+ setUpBeforeWatchers(params);
+ startWatchers(testInstance, method, params);
+ setUpAfterWatchers(params);
+ runImpl();
+ } while (isLoop());
+ stopToStopThread();
runCheckMethod(testInstance, params);
} else {
startWatchers(testInstance, method, params);
@@ -103,6 +111,18 @@
onMethodEnd(method, testInstance, params, throwable);
}
+ private void startToStopThread() {
+ if(_toStopThread != null) {
+ _toStopThread.start();
+ }
+ }
+
+ private void stopToStopThread() {
+ if(_toStopThread != null) {
+ _toStopThread.close();
+ }
+ }
+
private void runCheckMethod(Object testInstance, Object[] params) {
if(_checkMethod != null) {
ReflectionUtil.invokeMethod(_checkMethod, testInstance, params);
@@ -141,8 +161,28 @@
_tearDownMethod = _convention.getTearDownMethod(_class);
_checkMethod = _convention.getCheckMethod(method);
_expectedException = _convention.getExpectedException(method);
+ int toStop = _convention.getToStop(_testInstance);
+ if (toStop > 0) {
+ _toStopThread = new ToStopThread(new Runnable() {
+ public void run() {
+ stop();
+ }
+ }, toStop);
+ _isLoop = true;
+ } else {
+ _isLoop = false;
+ _toStopThread = null;
+ }
}
+ protected synchronized boolean isLoop() {
+ return _isLoop;
+ }
+
+ protected synchronized void stop() {
+ _isLoop = false;
+ }
+
/**
* This method might be overriden by subclass. The runner may do some more
* things during this step.
Added: trunk/punit/src/org/punit/method/runner/ToStopThread.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/ToStopThread.java (rev 0)
+++ trunk/punit/src/org/punit/method/runner/ToStopThread.java 2007-06-25 01:24:49 UTC (rev 223)
@@ -0,0 +1,41 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.method.runner;
+
+public class ToStopThread extends Thread {
+
+ private long _timeout;
+
+ private Object _lock = new Object();
+
+ private boolean _closed;
+
+ private Runnable _runnable;
+
+ public ToStopThread(Runnable runnable, long timeout) {
+ _runnable = runnable;
+ _timeout = timeout;
+ }
+
+ public void run() {
+ synchronized (_lock) {
+ try {
+ _lock.wait(_timeout);
+ } catch (InterruptedException e) {
+
+ }
+ if(_closed) {
+ return;
+ }
+ _runnable.run();
+ }
+ }
+
+ public void close() {
+ _closed = true;
+ synchronized (_lock) {
+ _lock.notifyAll();
+ }
+ }
+
+}
Modified: trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java
===================================================================
--- trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java 2007-06-24 05:27:25 UTC (rev 222)
+++ trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java 2007-06-25 01:24:49 UTC (rev 223)
@@ -109,10 +109,14 @@
}
public int getToAbort(Object testInstance) {
- throw new UnsupportedOperationException();
+ return 0;
}
public int getToStop(Object testInstance) {
- throw new UnsupportedOperationException();
+ return 0;
}
+
+ public boolean isLoopTest(Object testInstance) {
+ return false;
+ }
}
Modified: trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java
===================================================================
--- trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java 2007-06-24 05:27:25 UTC (rev 222)
+++ trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java 2007-06-25 01:24:49 UTC (rev 223)
@@ -84,10 +84,14 @@
}
public int getToAbort(Object testInstance) {
- throw new UnsupportedOperationException();
+ return 0;
}
public int getToStop(Object testInstance) {
- throw new UnsupportedOperationException();
+ return 0;
}
+
+ public boolean isLoopTest(Object testInstance) {
+ return false;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-06-25 10:06:18
|
Revision: 224
http://p-unit.svn.sourceforge.net/p-unit/?rev=224&view=rev
Author: zhanghuangzhu
Date: 2007-06-25 02:09:45 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Andrew Zhang: Some test cases and continue to implement Loop runner.
Modified Paths:
--------------
trunk/punit/src/org/punit/convention/Convention.java
trunk/punit/src/org/punit/convention/NameConvention.java
trunk/punit/src/org/punit/type/Loop.java
trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java
trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java
trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java
trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractTestMethodRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass.java
Added Paths:
-----------
trunk/punit.samples/src/samples/LoopTestSample.java
trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java
Modified: trunk/punit/src/org/punit/convention/Convention.java
===================================================================
--- trunk/punit/src/org/punit/convention/Convention.java 2007-06-25 01:24:49 UTC (rev 223)
+++ trunk/punit/src/org/punit/convention/Convention.java 2007-06-25 09:09:45 UTC (rev 224)
@@ -44,7 +44,7 @@
public boolean isLoopTest(Object testInstance);
- public int getToStop(Object testInstance);
+ public long toStop(Object testInstance);
- public int getToAbort(Object testInstance);
+ public long toAbort(Object testInstance);
}
Modified: trunk/punit/src/org/punit/convention/NameConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/NameConvention.java 2007-06-25 01:24:49 UTC (rev 223)
+++ trunk/punit/src/org/punit/convention/NameConvention.java 2007-06-25 09:09:45 UTC (rev 224)
@@ -120,16 +120,16 @@
return testInstance instanceof Loop;
}
- public int getToAbort(Object testInstance) {
+ public long toAbort(Object testInstance) {
if(isLoopTest(testInstance)) {
- ((Loop) testInstance).toAbort();
+ return ((Loop) testInstance).toAbort();
}
return 0;
}
- public int getToStop(Object testInstance) {
+ public long toStop(Object testInstance) {
if(isLoopTest(testInstance)) {
- ((Loop) testInstance).toStop();
+ return ((Loop) testInstance).toStop();
}
return 0;
}
Modified: trunk/punit/src/org/punit/type/Loop.java
===================================================================
--- trunk/punit/src/org/punit/type/Loop.java 2007-06-25 01:24:49 UTC (rev 223)
+++ trunk/punit/src/org/punit/type/Loop.java 2007-06-25 09:09:45 UTC (rev 224)
@@ -4,7 +4,7 @@
/**
* If a test implements this interface, punit concurrent runner will executes
- * its method concurrently.
+ * its method repeatedly until timeout.
*/
public interface Loop {
/**
Modified: trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java
===================================================================
--- trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java 2007-06-25 01:24:49 UTC (rev 223)
+++ trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java 2007-06-25 09:09:45 UTC (rev 224)
@@ -108,11 +108,11 @@
return method;
}
- public int getToAbort(Object testInstance) {
+ public long toAbort(Object testInstance) {
return 0;
}
- public int getToStop(Object testInstance) {
+ public long toStop(Object testInstance) {
return 0;
}
Modified: trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java
===================================================================
--- trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java 2007-06-25 01:24:49 UTC (rev 223)
+++ trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java 2007-06-25 09:09:45 UTC (rev 224)
@@ -83,11 +83,11 @@
return method;
}
- public int getToAbort(Object testInstance) {
+ public long toAbort(Object testInstance) {
return 0;
}
- public int getToStop(Object testInstance) {
+ public long toStop(Object testInstance) {
return 0;
}
Added: trunk/punit.samples/src/samples/LoopTestSample.java
===================================================================
--- trunk/punit.samples/src/samples/LoopTestSample.java (rev 0)
+++ trunk/punit.samples/src/samples/LoopTestSample.java 2007-06-25 09:09:45 UTC (rev 224)
@@ -0,0 +1,56 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package samples;
+
+import org.punit.runner.*;
+import org.punit.type.*;
+
+import junit.framework.*;
+
+public class LoopTestSample implements Loop {
+
+ public static final long TIMEOUT = 1000;
+
+ public static void main(String[] args) {
+ new SoloRunner().run(LoopTestSample.class);
+ }
+
+ public static int _test1;
+
+ public static int _test2;
+
+ public static int _setUp;
+
+ public static int _tearDown;
+
+ public static void reset() {
+ _test1 = 0;
+ _test2 = 0;
+ _setUp = 0;
+ _tearDown = 0;
+ }
+
+ private void setUp() {
+ _setUp++;
+ }
+
+ private void tearDown() {
+ _tearDown++;
+ }
+
+ public void test1() {
+// System.out.println("test1 = " + _test1++);
+ }
+
+ public void test2() {
+// System.out.println("test2 = " + _test2++);
+ }
+
+ public long toAbort() {
+ return TIMEOUT;
+ }
+
+ public long toStop() {
+ return TIMEOUT;
+ }
+}
Modified: trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java 2007-06-25 01:24:49 UTC (rev 223)
+++ trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java 2007-06-25 09:09:45 UTC (rev 224)
@@ -13,58 +13,68 @@
public class NameConventionFilterTest extends TestCase {
- NameConvention _filter = new NameConvention();
+ NameConvention _convention = new NameConvention();
public void testIsTestMethod() {
Method method;
method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$
- assertTrue(_filter.isTestMethod(method));
+ assertTrue(_convention.isTestMethod(method));
method = ReflectionUtil.getMethod(getClass(), "_test2", new Class[] {}); //$NON-NLS-1$
- assertFalse(_filter.isTestMethod(method));
+ assertFalse(_convention.isTestMethod(method));
}
public void testGetCheckMethod() {
Method method, checkMethod;
method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$
- checkMethod = _filter.getCheckMethod(method);
+ checkMethod = _convention.getCheckMethod(method);
assertNull(checkMethod);
method = ReflectionUtil.getMethod(getClass(), "_test2", new Class[] {}); //$NON-NLS-1$
- checkMethod = _filter.getCheckMethod(method);
+ checkMethod = _convention.getCheckMethod(method);
assertEquals("check__test2", checkMethod.getName()); //$NON-NLS-1$
}
public void testGetConcurrentCount() {
Method method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$
ConcurrentTestClass test = new ConcurrentTestClass();
- int count = _filter.getConcurrentCount(test, method);
+ int count = _convention.getConcurrentCount(test, method);
assertEquals(test.concurrentCount(), count);
method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$
- assertEquals(0, _filter.getConcurrentCount(new TestClass(), method));
+ assertEquals(0, _convention.getConcurrentCount(new TestClass(), method));
}
public void testGetSetUpMethod() {
- assertNotNull(_filter.getSetupMethod(TestClass.class));
- assertNull(_filter.getSetupMethod(TestClass1.class));
+ assertNotNull(_convention.getSetupMethod(TestClass.class));
+ assertNull(_convention.getSetupMethod(TestClass1.class));
}
public void testGetTearDownMethod() {
- assertNotNull(_filter.getTearDownMethod(TestClass.class));
- assertNull(_filter.getTearDownMethod(TestClass1.class));
+ assertNotNull(_convention.getTearDownMethod(TestClass.class));
+ assertNull(_convention.getTearDownMethod(TestClass1.class));
}
public void testGetBeforeClass() {
- assertNotNull(_filter.getBeforeClassMethod(TestClass.class));
- assertNull(_filter.getBeforeClassMethod(TestClass1.class));
+ assertNotNull(_convention.getBeforeClassMethod(TestClass.class));
+ assertNull(_convention.getBeforeClassMethod(TestClass1.class));
}
public void testGetAfterClass() {
- assertNotNull(_filter.getAfterClassMethod(TestClass.class));
- assertNull(_filter.getAfterClassMethod(TestClass1.class));
+ assertNotNull(_convention.getAfterClassMethod(TestClass.class));
+ assertNull(_convention.getAfterClassMethod(TestClass1.class));
}
+ public void testIsLoop() {
+ assertTrue(_convention.isLoopTest(new LoopTestClass()));
+ assertFalse(_convention.isLoopTest(new TestClass()));
+ }
+
+ public void testGetToStop() {
+ assertEquals(LoopTestClass.TIMEOUT, _convention.toStop(new LoopTestClass()));
+ assertEquals(0, _convention.toStop(new TestClass()));
+ }
+
public void test1() {
}
Modified: trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractTestMethodRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractTestMethodRunnerTest.java 2007-06-25 01:24:49 UTC (rev 223)
+++ trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractTestMethodRunnerTest.java 2007-06-25 09:09:45 UTC (rev 224)
@@ -1,3 +1,5 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
package tests.api.org.punit.method.runner;
import java.util.*;
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-25 01:24:49 UTC (rev 223)
+++ trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2007-06-25 09:09:45 UTC (rev 224)
@@ -1,3 +1,5 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
package tests.api.org.punit.runner;
import java.util.*;
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java 2007-06-25 09:09:45 UTC (rev 224)
@@ -0,0 +1,63 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.testclasses;
+
+import org.punit.runner.*;
+import org.punit.type.*;
+
+import junit.framework.*;
+
+public class LoopTestClass implements Loop {
+
+ public static final long TIMEOUT = 100;
+
+ public static void main(String[] args) {
+ new SoloRunner().run(LoopTestClass.class);
+ }
+
+ public static int _test1;
+
+ public static int _test2;
+
+ public static int _setUp;
+
+ public static int _tearDown;
+
+ public static void reset() {
+ _test1 = 0;
+ _test2 = 0;
+ _setUp = 0;
+ _tearDown = 0;
+ }
+
+ private void setUp() {
+ _setUp++;
+ }
+
+ private void tearDown() {
+ _tearDown++;
+ }
+
+ public void test1() {
+ _test1++;
+ }
+
+ public void test2() {
+ _test2++;
+ }
+
+ public static void assertTestClassRun() {
+ Assert.assertTrue(_test1 > 1);
+ Assert.assertTrue(_test2 > 1);
+ Assert.assertTrue(_setUp > 1);
+ Assert.assertTrue(_tearDown > 1);
+ }
+
+ public long toAbort() {
+ return TIMEOUT;
+ }
+
+ public long toStop() {
+ return TIMEOUT;
+ }
+}
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass.java 2007-06-25 01:24:49 UTC (rev 223)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass.java 2007-06-25 09:09:45 UTC (rev 224)
@@ -1,3 +1,5 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
package tests.api.org.punit.testclasses;
import junit.framework.*;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-06-25 11:34:22
|
Revision: 225
http://p-unit.svn.sourceforge.net/p-unit/?rev=225&view=rev
Author: zhanghuangzhu
Date: 2007-06-25 04:34:23 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Andrew Zhang: First implementation for Loop test is done.
Modified Paths:
--------------
trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.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/LoopTestClass.java
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-25 09:09:45 UTC (rev 224)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-25 11:34:23 UTC (rev 225)
@@ -76,11 +76,11 @@
try {
if (needsRunMethod()) {
init(testInstance, method, params);
+ setUpBeforeWatchers(params);
+ startWatchers(testInstance, method, params);
+ setUpAfterWatchers(params);
startToStopThread();
do {
- setUpBeforeWatchers(params);
- startWatchers(testInstance, method, params);
- setUpAfterWatchers(params);
runImpl();
} while (isLoop());
stopToStopThread();
@@ -161,7 +161,7 @@
_tearDownMethod = _convention.getTearDownMethod(_class);
_checkMethod = _convention.getCheckMethod(method);
_expectedException = _convention.getExpectedException(method);
- int toStop = _convention.getToStop(_testInstance);
+ long toStop = _convention.toStop(_testInstance);
if (toStop > 0) {
_toStopThread = new ToStopThread(new Runnable() {
public void run() {
Modified: trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2007-06-25 09:09:45 UTC (rev 224)
+++ trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2007-06-25 11:34:23 UTC (rev 225)
@@ -27,7 +27,13 @@
}
private void startThreads() {
+ int count = _convention.getConcurrentCount(_testInstance, _method);
+ int threadCount = count > 0? count : _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$
+ }
+ for (int i = 0; i < _threads.length; ++i) {
_threads[i].start();
}
}
@@ -41,20 +47,6 @@
}
}
}
-
- protected void setUpBeforeWatchers(Object[] params) throws Throwable {
- super.setUpBeforeWatchers(params);
- initThreads();
- }
-
- private void initThreads() {
- int count = _convention.getConcurrentCount(_testInstance, _method);
- int threadCount = count > 0? count : _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$
- }
- }
protected String getCheckMethodName() {
return "check_" + _method.getName(); //$NON-NLS-1$
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-25 09:09:45 UTC (rev 224)
+++ trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2007-06-25 11:34:23 UTC (rev 225)
@@ -13,12 +13,9 @@
import tests.util.*;
public class ConcurrentRunnerTest extends TestCase {
- private ConcurrentRunner _runner;
+
+ private ConcurrentRunner _runner = new ConcurrentRunner();
- protected void setUp() throws Exception {
- _runner = new ConcurrentRunner();
- }
-
public void testMain() {
ConcurrentRunner.main(new String[] {TestSuiteClass.class.getName()});
}
@@ -27,6 +24,12 @@
_runner.run(TestSuiteClass.class);
}
+ public void testRunLoopTest() {
+ LoopTestClass.reset();
+ _runner.run(LoopTestClass.class);
+ LoopTestClass.assertTestClassRun();
+ }
+
public void testRunConcurrent() {
ConcurrentTestClass.reset();
_runner.run(ConcurrentTestClass.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-06-25 09:09:45 UTC (rev 224)
+++ trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2007-06-25 11:34:23 UTC (rev 225)
@@ -36,6 +36,13 @@
TestClass.assertTestClassRun();
_eventListener.assertAllEventsInvoked();
}
+
+ public void testRunLoopTest() {
+ LoopTestClass.reset();
+ _runner.run(LoopTestClass.class);
+ LoopTestClass.assertTestClassRun();
+ _eventListener.assertAllEventsInvoked();
+ }
public void testRunAnnotationTest() {
AnnotationTestClass.reset();
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java 2007-06-25 09:09:45 UTC (rev 224)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java 2007-06-25 11:34:23 UTC (rev 225)
@@ -47,10 +47,10 @@
}
public static void assertTestClassRun() {
- Assert.assertTrue(_test1 > 1);
- Assert.assertTrue(_test2 > 1);
- Assert.assertTrue(_setUp > 1);
- Assert.assertTrue(_tearDown > 1);
+ Assert.assertTrue(_test1 > 2);
+ Assert.assertTrue(_test2 > 2);
+ Assert.assertEquals(2, _setUp);
+ Assert.assertEquals(2, _tearDown);
}
public long toAbort() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <le...@us...> - 2007-07-20 13:04:21
|
Revision: 230
http://p-unit.svn.sourceforge.net/p-unit/?rev=230&view=rev
Author: leshik
Date: 2007-07-20 06:04:13 -0700 (Fri, 20 Jul 2007)
Log Message:
-----------
* Added a new EventListener which sets public test fields on start up. Added listener package and a test for a new functionality.
* Renamed Parameterizable -> Parameterized. The latter one has fewer letters and my spellchecker doesn't underline it with red.
* Renamed setup -> setUp to be consistent with JUnit.
* Enhanced before/after class events to take a test instance instead a class, fixed TODO comment to supply an exception to an after class listener.
* Fixed a number of misspells and added few lines of javadoc.
* Removed TypeUtil class, moved the checks to the Convention interface. Added org.punit.convention.AbstractConvention minimizing code duplication.
Modified Paths:
--------------
trunk/punit/src/org/punit/convention/Convention.java
trunk/punit/src/org/punit/convention/NameConvention.java
trunk/punit/src/org/punit/events/EventListener.java
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/reporter/TestResult.java
trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit/src/org/punit/suite/builder/TestSuiteLabel.java
trunk/punit/src/org/punit/type/Loop.java
trunk/punit/src/org/punit/type/Parameter.java
trunk/punit/src/org/punit/type/Test.java
trunk/punit/src/org/punit/util/IntParameter.java
trunk/punit/src/org/punit/util/ReflectionUtil.java
trunk/punit.extension/src/org/punit/annotation/After.java
trunk/punit.extension/src/org/punit/annotation/Before.java
trunk/punit.extension/src/org/punit/annotation/Test.java
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/TestClassReporter.java
trunk/punit.extension/src/org/punit/reporter/chart/image/ImageRender.java
trunk/punit.extension/src/org/punit/util/AnnotationUtil.java
trunk/punit.samples/src/samples/LoopTestSample.java
trunk/punit.samples/src/samples/ParamTestClass.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/runner/ConcurrentRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/MockEventListener.java
trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java
trunk/punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass2.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java
Added Paths:
-----------
trunk/punit/src/org/punit/convention/AbstractConvention.java
trunk/punit/src/org/punit/type/Parameterized.java
trunk/punit.extension/src/org/punit/listener/
trunk/punit.extension/src/org/punit/listener/FieldSetter.java
trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizedTestClass.java
trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizedTestClass.java
trunk/punit.test/src/tests/samples/ConcurrentParameterizedTestSample.java
trunk/punit.test/src/tests/samples/ParameterizedTestSample.java
Removed Paths:
-------------
trunk/punit/src/org/punit/type/Parameterizable.java
trunk/punit/src/org/punit/util/TypeUtil.java
trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizableTestClass.java
trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestClass.java
trunk/punit.test/src/tests/samples/ConcurrentParameterizableTestSample.java
trunk/punit.test/src/tests/samples/ParameterizableTestSample.java
Added: trunk/punit/src/org/punit/convention/AbstractConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/AbstractConvention.java (rev 0)
+++ trunk/punit/src/org/punit/convention/AbstractConvention.java 2007-07-20 13:04:13 UTC (rev 230)
@@ -0,0 +1,52 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.convention;
+
+import java.lang.reflect.Method;
+
+import org.punit.type.Concurrent;
+import org.punit.type.Loop;
+import org.punit.type.Parameter;
+import org.punit.type.Parameterized;
+import org.punit.type.Test;
+
+abstract public class AbstractConvention implements Convention {
+
+ public boolean isExcluded(Class method) {
+ return false;
+ }
+
+ 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 boolean isPUnitTest(Class clazz) {
+ return Test.class.isAssignableFrom(clazz);
+ }
+
+ public boolean isParameter(Class clazz) {
+ return Parameter.class.isAssignableFrom(clazz);
+ }
+
+ public boolean isParameterizedTest(Class clazz) {
+ return Parameterized.class.isAssignableFrom(clazz);
+ }
+
+ public boolean isLoopTest(Class clazz) {
+ return Loop.class.isAssignableFrom(clazz);
+ }
+
+ public long toWork(Object testInstance) {
+ if (isLoopTest(testInstance.getClass())) {
+ return ((Loop) testInstance).toWork();
+ }
+ return 0;
+ }
+}
Property changes on: trunk/punit/src/org/punit/convention/AbstractConvention.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: trunk/punit/src/org/punit/convention/Convention.java
===================================================================
--- trunk/punit/src/org/punit/convention/Convention.java 2007-07-12 07:08:43 UTC (rev 229)
+++ trunk/punit/src/org/punit/convention/Convention.java 2007-07-20 13:04:13 UTC (rev 230)
@@ -34,17 +34,21 @@
public int getConcurrentCount(Object testInstance, Method method);
- public Method getSetupMethod(Class test);
+ public Method getSetUpMethod(Class test);
public Method getTearDownMethod(Class test);
public Method getBeforeClassMethod(Class test);
public Method getAfterClassMethod(Class test);
+
+ public boolean isPUnitTest(Class clazz);
- public boolean isLoopTest(Object testInstance);
+ public boolean isParameter(Class clazz);
+
+ public boolean isParameterizedTest(Class clazz);
+
+ public boolean isLoopTest(Class clazz);
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-07-12 07:08:43 UTC (rev 229)
+++ trunk/punit/src/org/punit/convention/NameConvention.java 2007-07-20 13:04:13 UTC (rev 230)
@@ -2,19 +2,14 @@
package org.punit.convention;
-import java.lang.reflect.*;
+import java.lang.reflect.Method;
-import org.punit.type.*;
-import org.punit.util.*;
+import org.punit.util.ReflectionUtil;
-public class NameConvention implements Convention {
+public class NameConvention extends AbstractConvention {
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(),
@@ -33,7 +28,7 @@
}
/**
- * Judeges whether the modifier of is method conforms to the convention of a
+ * Judges whether the modifier of is method conforms to the convention of a
* test method.
*
* @param method
@@ -46,8 +41,8 @@
}
/**
- * Judeges whether the name of is method conforms to the convention of a
- * test method.
+ * Judges whether the name of is method conforms to the convention of a test
+ * method.
*
* @param method
* to be judged
@@ -61,78 +56,50 @@
}
/**
- * Judges whether the paramaters of this method conforms to the convention
- * of a test method.
+ * Judges whether the parameters of this method conform 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>.
+ * @return <code>true</code> if the number of method parameters is zero
+ * and the test class is not marked as <code>Parameterized</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]);
+ if (isParameterizedTest(clazz)) {
+ return params.length == 1 && isParameter(params[0]);
} else {
return params.length == 0;
}
}
- 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 Method getAfterClassMethod(Class test) {
- Method method = ReflectionUtil.getMethodAndSetAccessible(test, "beforeClass", new Class[] {}); //$NON-NLS-1$
- if(method != null && ReflectionUtil.isStatic(method)) {
+ 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)) {
+ 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$
+ return ReflectionUtil.getMethodAndSetAccessible(test,
+ "tearDown", new Class[] {}); //$NON-NLS-1$
}
-
- 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 toWork(Object testInstance) {
- if(isLoopTest(testInstance)) {
- return ((Loop) testInstance).toWork();
- }
- return 0;
- }
-
-
}
Modified: trunk/punit/src/org/punit/events/EventListener.java
===================================================================
--- trunk/punit/src/org/punit/events/EventListener.java 2007-07-12 07:08:43 UTC (rev 229)
+++ trunk/punit/src/org/punit/events/EventListener.java 2007-07-20 13:04:13 UTC (rev 230)
@@ -51,14 +51,23 @@
public void onSuiteEnd(TestSuite suite);
/**
- * Is triggered when the test class is to be executed.
+ * Is triggered when the test class is already instantiated and is ready to
+ * be executed.
+ *
+ * @param testInstance
+ * a test class instance
*/
- public void onClassStart(Class clazz);
+ public void onClassStart(Object testInstance);
/**
* Is triggered after executing the test class.
+ *
+ * @param testInstance
+ * the test class instance
+ * @param t
+ * an error was triggered while tearing the test down
*/
- public void onClassEnd(Class clazz);
+ public void onClassEnd(Object testInstance, Throwable t);
/**
* Is triggered when the method to be executed.
Modified: trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-07-12 07:08:43 UTC (rev 229)
+++ trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-07-20 13:04:13 UTC (rev 230)
@@ -34,9 +34,9 @@
}
/**
- * @see TestMethodBuilder#buildTestMethods(Class)
+ * @see TestMethodBuilder#extractTestMethods(Class)
*/
- public Collection buildTestMethods(Class testClass) {
+ public Collection extractTestMethods(Class testClass) {
Collection testMethods = null;
if (isAlphabetical(testClass)) {
testMethods = new TreeSet(new AlphabeticalMethodNameComparator());
Modified: trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-07-12 07:08:43 UTC (rev 229)
+++ trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-07-20 13:04:13 UTC (rev 230)
@@ -13,16 +13,15 @@
*/
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.
+ * Builds a collection of test methods from the test class. Returns a list
+ * of methods.
*
- * @param clazz -
- * the test class to be built
- * @return a <code>Collection</code> of <code>java.lang.reflect.Method</code>.
+ * @param clazz
+ * the test class to be extract methods from
+ * @return a <code>Collection</code> of
+ * <code>java.lang.reflect.Method</code>.
*/
- public Collection buildTestMethods(Class testClass);
+ public Collection extractTestMethods(Class testClass); // Collection<Method>
-
public void setConvention(Convention convention);
}
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-07-12 07:08:43 UTC (rev 229)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-07-20 13:04:13 UTC (rev 230)
@@ -13,12 +13,11 @@
import org.punit.exception.ReflectionException;
import org.punit.runner.RunnerProperties;
import org.punit.type.Parameter;
-import org.punit.type.Parameterizable;
+import org.punit.type.Parameterized;
import org.punit.type.Test;
import org.punit.util.ReflectionUtil;
import org.punit.util.Traverser;
import org.punit.util.TraverserUtil;
-import org.punit.util.TypeUtil;
import org.punit.watcher.TimeWatcher;
import org.punit.watcher.Watcher;
@@ -165,7 +164,7 @@
_class = testInstance.getClass();
_params = params;
_method = method;
- _setUpMethod = _convention.getSetupMethod(_class);
+ _setUpMethod = _convention.getSetUpMethod(_class);
_tearDownMethod = _convention.getTearDownMethod(_class);
_checkMethod = _convention.getCheckMethod(method);
_expectedException = _convention.getExpectedException(method);
@@ -197,19 +196,19 @@
*
*/
protected void setUpBeforeWatchers(Object[] params) throws Throwable {
- if (TypeUtil.isPUnitTest(_class)) {
+ if (_convention.isPUnitTest(_class)) {
((Test) _testInstance).setUpBeforeWatchers();
- } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
- ((Parameterizable) _testInstance)
+ } else if (_convention.isParameterizedTest(_class)) {
+ ((Parameterized) _testInstance)
.setUpBeforeWatchers((Parameter) params[0]);
}
}
private void setUpAfterWatchers(Object[] params) throws Throwable {
- if (TypeUtil.isPUnitTest(_class)) {
+ if (_convention.isPUnitTest(_class)) {
((Test) _testInstance).setUpAfterWatchers();
- } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
- ((Parameterizable) _testInstance)
+ } else if (_convention.isParameterizedTest(_class)) {
+ ((Parameterized) _testInstance)
.setUpAfterWatchers((Parameter) params[0]);
} else {
setUp();
@@ -217,10 +216,10 @@
}
private void tearDownBeforeWatchers(Object[] params) throws Throwable {
- if (TypeUtil.isPUnitTest(_class)) {
+ if (_convention.isPUnitTest(_class)) {
((Test) _testInstance).tearDownBeforeWatchers();
- } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
- ((Parameterizable) _testInstance)
+ } else if (_convention.isParameterizedTest(_class)) {
+ ((Parameterized) _testInstance)
.tearDownBeforeWatchers((Parameter) params[0]);
} else {
tearDown();
@@ -228,10 +227,10 @@
}
private void tearDownAfterWatchers(Object[] params) throws Throwable {
- if (TypeUtil.isPUnitTest(_class)) {
+ if (_convention.isPUnitTest(_class)) {
((Test) _testInstance).tearDownAfterWatchers();
- } else if (TypeUtil.isPUnitParameterizableTest(_class)) {
- ((Parameterizable) _testInstance)
+ } else if (_convention.isParameterizedTest(_class)) {
+ ((Parameterized) _testInstance)
.tearDownAfterWatchers((Parameter) params[0]);
}
}
Modified: trunk/punit/src/org/punit/reporter/TestResult.java
===================================================================
--- trunk/punit/src/org/punit/reporter/TestResult.java 2007-07-12 07:08:43 UTC (rev 229)
+++ trunk/punit/src/org/punit/reporter/TestResult.java 2007-07-20 13:04:13 UTC (rev 230)
@@ -18,13 +18,14 @@
private List _failures = new ArrayList();
- public void onMethodEnd(Method method, Object testInstance, Object[] params, Throwable t, List Watchers) {
+ public void onMethodEnd(Method method, Object testInstance,
+ Object[] params, Throwable t, List Watchers) {
countMethod();
if (t != null) {
addThrowable(t);
}
}
-
+
public synchronized void countMethod() {
++_methodCount;
}
@@ -41,53 +42,61 @@
return _failures;
}
- public void onClassEnd(Class clazz) {
-
+ /**
+ * A method is required by <code>EventListener</code> interface. It does
+ * nothing when a new test class is instantiated.
+ */
+ public void onClassStart(Object testInstance) {
+
}
- public void onClassStart(Class clazz) {
-
+ /**
+ * A method is required by <code>EventListener</code> interface. It does
+ * nothing when a test class execution is completed.
+ */
+ public void onClassEnd(Object testInstance, Throwable t) {
+
}
+ public void onMethodStart(Method method, Object testInstance,
+ Object[] params) {
- public void onMethodStart(Method method, Object testInstance, Object[] params) {
-
}
public void onRunnerEnd(Class clazz, Runner runner) {
-
+
}
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) {
-
+
}
public void onWatchersEnd(List watchers) {
-
+
}
public void onWatchersStart(List watchers) {
-
+
}
public boolean supportParentRunner() {
return false;
}
-
+
}
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2007-07-12 07:08:43 UTC (rev 229)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2007-07-20 13:04:13 UTC (rev 230)
@@ -105,9 +105,12 @@
log(sb.toString(), Level.INFO);
}
+ public void onClassStart(Object testInstance) {
+ logln(testInstance.getClass().getName(), Level.INFO);
+ }
- public void onClassStart(Class clazz) {
- logln(clazz.getName(), Level.INFO);
+ public void onClassEnd(Object testInstance, Throwable t) {
+ // nothing needs to be done
}
public void onMethodEnd(Method method, Object instance, Object[] params,
@@ -190,30 +193,26 @@
}
public void onWatchersStart(List watchers) {
- // nothing needs to do
+ // nothing needs to be done
}
public void onWatcherStart(Watcher watcher) {
- // nothing needs to do
+ // nothing needs to be done
}
public void onWatchersEnd(List watchers) {
- // nothing needs to do
+ // nothing needs to be done
}
public void onWatcherEnd(Watcher watcher) {
- // nothing needs to do
+ // nothing needs to be done
}
public void onSuiteEnd(TestSuite suite) {
- // nothing needs to do
+ // nothing needs to be done
}
- public void onClassEnd(Class clazz) {
- // nothing needs to do
- }
-
public void onMethodStart(Method method, Object instance, Object[] params) {
- // nothing needs to do
+ // nothing needs to be done
}
}
\ No newline at end of file
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-07-12 07:08:43 UTC (rev 229)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-07-20 13:04:13 UTC (rev 230)
@@ -20,14 +20,13 @@
import org.punit.suite.builder.TestSuiteBuilder;
import org.punit.suite.builder.TestSuiteLabel;
import org.punit.type.Parameter;
-import org.punit.type.Parameterizable;
+import org.punit.type.Parameterized;
import org.punit.type.TestSuite;
import org.punit.type.VM;
import org.punit.util.IOUtil;
import org.punit.util.ReflectionUtil;
import org.punit.util.Traverser;
import org.punit.util.TraverserUtil;
-import org.punit.util.TypeUtil;
public abstract class AbstractRunner implements Runner {
@@ -37,8 +36,7 @@
private MethodRunner _methodRunner;
- // List <EventListener>
- private final List _eventListeners = new ArrayList();
+ private final List _eventListeners = new ArrayList(); // List<EventListener>
private TestResult _testResult = new TestResult();
@@ -253,24 +251,29 @@
}
private void runTestClassImpl(final Class clazz) {
- onClassStart(clazz);
+ Object testInstance = ReflectionUtil.newInstance(clazz);
+ Throwable storedException = null;
+ Collection testMethods = extractTestMethods(clazz);
+
+ onClassStart(testInstance);
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);
}
});
+ } catch (Throwable t) {
+ storedException = t;
} finally {
try {
afterClass(clazz);
} catch (Throwable t) {
- // TODO: will be passed to onClassEnd
+ storedException = t;
}
}
- onClassEnd(clazz);
+ onClassEnd(testInstance, storedException);
}
private void beforeClass(Class clazz) {
@@ -303,44 +306,40 @@
});
}
- private void onClassStart(final Class clazz) {
+ private void onClassStart(final Object testInstance) {
TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
public void traverse(Object obj) {
- ((EventListener) obj).onClassStart(clazz);
+ ((EventListener) obj).onClassStart(testInstance);
}
});
}
- private void onClassEnd(final Class clazz) {
+ private void onClassEnd(final Object testInstance, final Throwable t) {
TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
public void traverse(Object obj) {
- ((EventListener) obj).onClassEnd(clazz);
+ ((EventListener) obj).onClassEnd(testInstance, t);
}
});
}
private void runTestMethod(Class clazz, Method method) {
Object testInstance = ReflectionUtil.newInstance(clazz);
- if (TypeUtil.isPUnitParameterizableTest(clazz)) {
- Parameterizable pInstance = (Parameterizable) testInstance;
+ if (_convention.isParameterizedTest(clazz)) {
+ Parameterized pInstance = (Parameterized) testInstance;
Parameter[] params = pInstance.parameters();
for (int i = 0; i < params.length; ++i) {
- runTestMethod(testInstance, method, new Object[] { params[i] });
+ _methodRunner.run(testInstance, method,
+ new Object[] { params[i] });
}
} else {
- runTestMethod(testInstance, method, new Object[] {});
+ _methodRunner.run(testInstance, method, new Object[] {});
}
}
- private void runTestMethod(Object testInstance, Method method,
- Object[] params) {
- _methodRunner.run(testInstance, method, params);
+ private Collection extractTestMethods(Class testClass) {
+ return _testMethodBuilder.extractTestMethods(testClass);
}
- private Collection buildTestMethod(Class testClass) {
- return _testMethodBuilder.buildTestMethods(testClass);
- }
-
public TestMethodBuilder methodBuilder() {
return _testMethodBuilder;
}
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteLabel.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteLabel.java 2007-07-12 07:08:43 UTC (rev 229)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteLabel.java 2007-07-20 13:04:13 UTC (rev 230)
@@ -2,22 +2,23 @@
package org.punit.suite.builder;
-import org.punit.type.*;
+import org.punit.type.TestSuite;
/**
* Represents a test suite label. TestSuiteBuilder inserts this label in the
* result to indicate the start and the end of a test suite.
+ *
* @see TestSuiteBuilder#buildTestClasses(Class)
*/
public interface TestSuiteLabel {
-
+
/**
* @return the test suite it represents
*/
public TestSuite suite();
/**
- * @return returns true if it represents the start of a test suite.
+ * @return <code>true</code> if it represents the start of a test suite.
*/
public boolean isStart();
}
Modified: trunk/punit/src/org/punit/type/Loop.java
===================================================================
--- trunk/punit/src/org/punit/type/Loop.java 2007-07-12 07:08:43 UTC (rev 229)
+++ trunk/punit/src/org/punit/type/Loop.java 2007-07-20 13:04:13 UTC (rev 230)
@@ -3,17 +3,12 @@
package org.punit.type;
/**
- * If a test implements this interface, punit concurrent runner will executes
- * its method repeatedly until timeout.
+ * If a test implements this interface, PUnit concurrent runner executes
+ * the method repeatedly until timeout.
*/
public interface Loop {
/**
* @return returns the time to loop
*/
public long toWork();
-
- /**
- * @return returns the time to stop the test gracefully
- */
- public long toStop();
}
Modified: trunk/punit/src/org/punit/type/Parameter.java
===================================================================
--- trunk/punit/src/org/punit/type/Parameter.java 2007-07-12 07:08:43 UTC (rev 229)
+++ trunk/punit/src/org/punit/type/Parameter.java 2007-07-20 13:04:13 UTC (rev 230)
@@ -2,13 +2,13 @@
package org.punit.type;
-import org.punit.type.Parameterizable;
+import org.punit.type.Parameterized;
/**
- * If a test implements <code>Parameterizable</code> interface, the test
+ * If a test implements <code>Pa...
[truncated message content] |
|
From: <zha...@us...> - 2007-08-12 14:03:49
|
Revision: 231
http://p-unit.svn.sourceforge.net/p-unit/?rev=231&view=rev
Author: zhanghuangzhu
Date: 2007-08-12 07:03:50 -0700 (Sun, 12 Aug 2007)
Log Message:
-----------
Andrew Zhang: removed some warnings and unused codes.
Modified Paths:
--------------
trunk/punit/src/org/punit/util/RunnerUtil.java
trunk/punit/src/org/punit/watcher/AbstractWatcher.java
trunk/punit.extension/src/org/punit/listener/FieldSetter.java
trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java
trunk/punit.test/src/tests/api/org/punit/watcher/CustomWatcherTest.java
trunk/punit.test/src/tests/util/TestUtil.java
Removed Paths:
-------------
trunk/punit/src/org/punit/exception/OutOfMemoryException.java
Deleted: trunk/punit/src/org/punit/exception/OutOfMemoryException.java
===================================================================
--- trunk/punit/src/org/punit/exception/OutOfMemoryException.java 2007-07-20 13:04:13 UTC (rev 230)
+++ trunk/punit/src/org/punit/exception/OutOfMemoryException.java 2007-08-12 14:03:50 UTC (rev 231)
@@ -1,15 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.exception;
-
-/**
- * The root exception of all PUnit exception.
- */
-public class OutOfMemoryException extends RuntimeException {
-
- private static final long serialVersionUID = -2694385721230707311L;
-
- public OutOfMemoryException(OutOfMemoryError e) {
- super("Framework cannot reclaim its resources", e);
- }
-}
Modified: trunk/punit/src/org/punit/util/RunnerUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/RunnerUtil.java 2007-07-20 13:04:13 UTC (rev 230)
+++ trunk/punit/src/org/punit/util/RunnerUtil.java 2007-08-12 14:03:50 UTC (rev 231)
@@ -2,8 +2,6 @@
package org.punit.util;
-import java.io.File;
-
import org.punit.message.Messages;
import org.punit.runner.Runner;
import org.punit.runner.RunnerProperties;
@@ -31,46 +29,4 @@
testRunner.run(testClass, properties);
}
- private static final String BIN = File.separator + "bin"; //$NON-NLS-1$
- private static final String LIB = File.separator + "lib" + File.separator; //$NON-NLS-1$
-
- public static String getVmLaunchString() {
- return System.getProperty("java.home") + BIN + File.separator
- + "java -cp " + generateClassPath();
- }
-
- private static String generateClassPath() {
- StringBuffer sb = new StringBuffer();
- final String TEST_PATH = IOUtil.getCurrentPath();
-
- // test project
- sb.append(TEST_PATH);
- sb.append(BIN);
- sb.append(File.pathSeparator);
-
- // extension project
- final String EXTENSION_PATH = TEST_PATH.replace(
- "punit.test", "punit.extension"); //$NON-NLS-2$
- sb.append(EXTENSION_PATH);
- sb.append(BIN);
- sb.append(File.pathSeparator);
-
- // core project
- sb.append(TEST_PATH.replaceAll("punit.test", "punit")); //$NON-NLS-2$
- sb.append(BIN);
- sb.append(File.pathSeparator);
-
- // JUnit
- sb.append(EXTENSION_PATH + LIB + "junit-4.3.1.jar"); //$NON-NLS-1$
- sb.append(File.pathSeparator);
-
- // reporting tools
- sb.append(EXTENSION_PATH + LIB + "jcommon-1.0.9.jar"); //$NON-NLS-1$
- sb.append(File.pathSeparator);
- sb.append(EXTENSION_PATH + LIB + "jfreechart-1.0.5.jar"); //$NON-NLS-1$
- sb.append(File.pathSeparator);
- sb.append(EXTENSION_PATH + LIB + "itext-2.0.2.jar"); //$NON-NLS-1$
- return sb.toString();
- }
-
}
Modified: trunk/punit/src/org/punit/watcher/AbstractWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/AbstractWatcher.java 2007-07-20 13:04:13 UTC (rev 230)
+++ trunk/punit/src/org/punit/watcher/AbstractWatcher.java 2007-08-12 14:03:50 UTC (rev 231)
@@ -17,14 +17,12 @@
}
public double value() {
-// System.out.println("_value = " + _value + ", _scale = " + _scale);
-// System.out.println("value() = " + (((double) _value) / _scale));
return ((double) _value) / _scale;
}
public String stringValue() {
if (_scale == 1) {
- return _value + " " + unit();
+ return _value + " " + unit(); //$NON-NLS-1$
} else {
return value() + unit();
}
Modified: trunk/punit.extension/src/org/punit/listener/FieldSetter.java
===================================================================
--- trunk/punit.extension/src/org/punit/listener/FieldSetter.java 2007-07-20 13:04:13 UTC (rev 230)
+++ trunk/punit.extension/src/org/punit/listener/FieldSetter.java 2007-08-12 14:03:50 UTC (rev 231)
@@ -80,7 +80,7 @@
return false;
}
- private final String PACKAGE_SEPARATOR = ".";
+ private final String PACKAGE_SEPARATOR = "."; //$NON-NLS-1$
/**
* Set public class fields from java properties.
Modified: trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2007-07-20 13:04:13 UTC (rev 230)
+++ trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2007-08-12 14:03:50 UTC (rev 231)
@@ -67,8 +67,8 @@
public void testFieldSetter() {
Properties properties = new Properties();
// 12 + 18 = ParameterizedTestClass.SUM
- properties.put("VALUE1", "12");
- properties.put("VALUE2", "18");
+ properties.put("VALUE1", "12"); //$NON-NLS-1$ //$NON-NLS-2$
+ properties.put("VALUE2", "18"); //$NON-NLS-1$ //$NON-NLS-2$
EventListener listener = new FieldSetter(properties);
_runner.addEventListener(listener);
_runner.run(ParameterizedTestClass.class);
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java 2007-07-20 13:04:13 UTC (rev 230)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java 2007-08-12 14:03:50 UTC (rev 231)
@@ -13,9 +13,9 @@
public static final long TIMEOUT = 500;
- public static final String SUPPORTED_THREADS = "Supported Number of Threads";
+ public static final String SUPPORTED_THREADS = "Supported Number of Threads"; //$NON-NLS-1$
- public static final String THREAD_UNITS = "threads";
+ public static final String THREAD_UNITS = "threads"; //$NON-NLS-1$
private boolean _stop;
Modified: trunk/punit.test/src/tests/api/org/punit/watcher/CustomWatcherTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/watcher/CustomWatcherTest.java 2007-07-20 13:04:13 UTC (rev 230)
+++ trunk/punit.test/src/tests/api/org/punit/watcher/CustomWatcherTest.java 2007-08-12 14:03:50 UTC (rev 231)
@@ -27,8 +27,8 @@
protected void setUp() throws Exception {
MethodRunner methodRunner = new SoloMethodRunner();
- _minWatcher = new MinimumWatcher(methodRunner, HEAP_WASTE, "%");
- _maxWatcher = new MaximumWatcher(methodRunner, HEAP_UTILIZATION, "%");
+ _minWatcher = new MinimumWatcher(methodRunner, HEAP_WASTE, "%"); //$NON-NLS-1$
+ _maxWatcher = new MaximumWatcher(methodRunner, HEAP_UTILIZATION, "%"); //$NON-NLS-1$
}
public void test() throws Exception {
@@ -78,9 +78,9 @@
private void setWatcherValue(long allocated) {
long total = MemoryUtil.totalMemory();
- CustomWatcher.setResult(HEAP_WASTE, (total - allocated) * 100, "%",
+ CustomWatcher.setResult(HEAP_WASTE, (total - allocated) * 100, "%", //$NON-NLS-1$
total);
- CustomWatcher.setResult(HEAP_UTILIZATION, allocated * 100, "%", total);
+ CustomWatcher.setResult(HEAP_UTILIZATION, allocated * 100, "%", total); //$NON-NLS-1$
}
public void testSerializable() throws Exception {
Modified: trunk/punit.test/src/tests/util/TestUtil.java
===================================================================
--- trunk/punit.test/src/tests/util/TestUtil.java 2007-07-20 13:04:13 UTC (rev 230)
+++ trunk/punit.test/src/tests/util/TestUtil.java 2007-08-12 14:03:50 UTC (rev 231)
@@ -1,17 +1,13 @@
package tests.util;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.*;
import java.lang.reflect.Method;
import java.util.Random;
import org.punit.events.EventListener;
import org.punit.runner.SoloRunner;
import org.punit.type.VM;
-import org.punit.util.RunnerUtil;
-import org.punit.util.ThreadUtil;
+import org.punit.util.*;
public class TestUtil {
@@ -60,10 +56,53 @@
consumeMemory(Math.abs(_random.nextInt()) % 100000);
}
+ public static String getVmLaunchString() {
+ return System.getProperty("java.home") + BIN + File.separator //$NON-NLS-1$
+ + "java -cp " + generateClassPath(); //$NON-NLS-1$
+ }
+
+ private static final String BIN = File.separator + "bin"; //$NON-NLS-1$
+ private static final String LIB = File.separator + "lib" + File.separator; //$NON-NLS-1$
+
+
+ private static String generateClassPath() {
+ StringBuffer sb = new StringBuffer();
+ final String TEST_PATH = IOUtil.getCurrentPath();
+
+ // test project
+ sb.append(TEST_PATH);
+ sb.append(BIN);
+ sb.append(File.pathSeparator);
+
+ // extension project
+ final String EXTENSION_PATH = TEST_PATH.replace(
+ "punit.test", "punit.extension"); //$NON-NLS-1$//$NON-NLS-2$
+ sb.append(EXTENSION_PATH);
+ sb.append(BIN);
+ sb.append(File.pathSeparator);
+
+ // core project
+ sb.append(TEST_PATH.replaceAll("punit.test", "punit")); //$NON-NLS-1$//$NON-NLS-2$
+ sb.append(BIN);
+ sb.append(File.pathSeparator);
+
+ // JUnit
+ sb.append(EXTENSION_PATH + LIB + "junit-4.3.1.jar"); //$NON-NLS-1$
+ sb.append(File.pathSeparator);
+
+ // reporting tools
+ sb.append(EXTENSION_PATH + LIB + "jcommon-1.0.9.jar"); //$NON-NLS-1$
+ sb.append(File.pathSeparator);
+ sb.append(EXTENSION_PATH + LIB + "jfreechart-1.0.5.jar"); //$NON-NLS-1$
+ sb.append(File.pathSeparator);
+ sb.append(EXTENSION_PATH + LIB + "itext-2.0.2.jar"); //$NON-NLS-1$
+ return sb.toString();
+ }
+
@SuppressWarnings("unchecked")
public static void runVMs(Class clazz, EventListener[] listeners) {
runUnitTest = false;
- final String THIS_VM = RunnerUtil.getVmLaunchString();
+ final String THIS_VM = getVmLaunchString();
final String NO_VERIFY = " -Xverify:none"; //$NON-NLS-1$
VM vm = new VM(THIS_VM, "VM"); //$NON-NLS-1$
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <le...@us...> - 2007-08-19 22:46:40
|
Revision: 232
http://p-unit.svn.sourceforge.net/p-unit/?rev=232&view=rev
Author: leshik
Date: 2007-08-19 15:45:41 -0700 (Sun, 19 Aug 2007)
Log Message:
-----------
* Added junit-style shouldStop() method to detect timeout expiration from inside the test
* Allocate thread objects once for all test iterations.
* Replaced logger.* and assert.* domains with sensible ones.
* Slightly corrected messages in float and double asserts.
* Fixed testInstance allocation: allocate it once for class (as it is done in ng-unit).
* Improved memory deallocation algorithm in MemoryUtil.clear() to free objects with finalizers on RI, added wilderness utilities and maximum total memory calculation. Restored org.punit.exception.OutOfMemoryException. Added related test.
* Fixed Maximum/Minimum watcher value accumulation in case when _scale changes.
* Fixed formatting and tabs.
Modified Paths:
--------------
trunk/punit/src/org/punit/assertion/Assert.java
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/reporter/stream/StreamLogger.java
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit/src/org/punit/util/MemoryUtil.java
trunk/punit/src/org/punit/util/ReflectionUtil.java
trunk/punit/src/org/punit/util/TraverserUtil.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/src/punit.properties
trunk/punit.extension/src/org/punit/listener/FieldSetter.java
trunk/punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java
trunk/punit.test/src/tests/api/org/punit/util/IOUtilTest.java
trunk/punit.test/src/tests/api/org/punit/watcher/CustomWatcherTest.java
Added Paths:
-----------
trunk/punit/src/org/punit/exception/OutOfMemoryException.java
trunk/punit.test/src/tests/api/org/punit/util/MemoryUtilTest.java
Modified: trunk/punit/src/org/punit/assertion/Assert.java
===================================================================
--- trunk/punit/src/org/punit/assertion/Assert.java 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit/src/org/punit/assertion/Assert.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -14,7 +14,7 @@
public static void assertNotSame(Object expected, Object actual) {
if (expected == actual) {
- fail(Messages.getString("Assert.2") + expected); //$NON-NLS-1$
+ fail(Messages.getString("assert.notsame") + expected); //$NON-NLS-1$
}
}
@@ -37,15 +37,19 @@
}
public static void assertEquals(double expected, double actual, double delta) {
- assertTrue(Math.abs(expected - actual) <= delta);
+ if (Math.abs(expected - actual) > delta) {
+ fail(new Double(expected), new Double(actual));
+ }
}
-
+
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);
+ if (Math.abs(expected - actual) > delta) {
+ fail(new Float(expected), new Float(actual));
+ }
}
public static void assertTrue(boolean flag) {
@@ -91,6 +95,6 @@
}
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$
+ fail(Messages.getString("assert.expected") + expected + Messages.getString("assert.got") + actual); //$NON-NLS-2$
}
}
Added: trunk/punit/src/org/punit/exception/OutOfMemoryException.java
===================================================================
--- trunk/punit/src/org/punit/exception/OutOfMemoryException.java (rev 0)
+++ trunk/punit/src/org/punit/exception/OutOfMemoryException.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -0,0 +1,15 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.exception;
+
+/**
+ * Indicates framework memory problem.
+ */
+public class OutOfMemoryException extends PUnitException {
+
+ private static final long serialVersionUID = -2694385721230707311L;
+
+ public OutOfMemoryException(OutOfMemoryError e) {
+ super("Framework didn't release allocated memory", e);
+ }
+}
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -35,7 +35,7 @@
private transient ToStopThread _toStopThread;
- private transient boolean _isLoop;
+ private transient boolean _shouldStop;
protected transient Object _testInstance;
@@ -87,9 +87,7 @@
startWatchers(testInstance, method, params);
setUpAfterWatchers(params);
startToStopThread();
- do {
- runImpl();
- } while (isLoop());
+ runImpl();
stopToStopThread();
runCheckMethod(testInstance, params);
} else {
@@ -175,23 +173,23 @@
stop();
}
}, toWork);
- _isLoop = true;
+ _shouldStop = false;
} else {
- _isLoop = false;
+ _shouldStop = true;
_toStopThread = null;
}
}
- protected synchronized boolean isLoop() {
- return _isLoop;
+ public boolean shouldStop() {
+ return _shouldStop;
}
protected synchronized void stop() {
- _isLoop = false;
+ _shouldStop = true;
}
/**
- * This method might be overriden by subclass. The runner may do some more
+ * This method might be overridden by subclass. The runner may do some more
* things during this step.
*
*/
@@ -354,7 +352,9 @@
protected void runMethod() throws Throwable {
if (_expectedException == null) {
- invokeMethod();
+ do {
+ invokeMethod();
+ } while (!shouldStop());
} else {
Assert.assertException(_expectedException, new CodeRunner() {
public void run() throws Throwable {
Modified: trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -2,70 +2,71 @@
package org.punit.method.runner;
-import org.punit.exception.*;
+import org.punit.exception.ConcurrentException;
public class ConcurrentMethodRunner extends AbstractMethodRunner {
- private static final long serialVersionUID = 6423244395038097893L;
+ private static final long serialVersionUID = 6423244395038097893L;
- private ConcurrentException _concurrentException = new ConcurrentException();
+ private ConcurrentException _concurrentException = new ConcurrentException();
- private int _concurrentCount;
-
- private transient TestMethodThread[] _threads;
-
- public ConcurrentMethodRunner(int concurrentCount) {
- _concurrentCount = concurrentCount;
- }
+ private int _concurrentCount;
- protected void runImpl() throws Throwable {
- startThreads();
- joinThreads();
- if (_concurrentException.size() > 0) {
- throw _concurrentException;
- }
- }
-
- private void startThreads() {
- int count = _convention.getConcurrentCount(_testInstance, _method);
- int threadCount = count > 0? count : _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$
- }
- for (int i = 0; i < _threads.length; ++i) {
- _threads[i].start();
- }
- }
+ private transient TestMethodThread[] _threads;
- private void joinThreads() {
- for (int i = 0; i < _threads.length; ++i) {
- try {
- _threads[i].join();
- } catch (InterruptedException e) {
- _concurrentException.add(e);
- }
- }
- }
-
- protected String getCheckMethodName() {
- return "check_" + _method.getName(); //$NON-NLS-1$
- }
+ public ConcurrentMethodRunner(int concurrentCount) {
+ _concurrentCount = concurrentCount;
+ }
- private class TestMethodThread extends Thread {
- ConcurrentMethodRunner _runner;
+ protected void runImpl() throws Throwable {
+ startThreads();
+ joinThreads();
+ if (_concurrentException.size() > 0) {
+ throw _concurrentException;
+ }
+ }
- public TestMethodThread(ConcurrentMethodRunner runner, String threadName) {
- super(threadName);
- _runner = runner;
- }
+ private void startThreads() {
+ int count = _convention.getConcurrentCount(_testInstance, _method);
+ int threadCount = count > 0 ? count : _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$
+ }
+ for (int i = 0; i < _threads.length; ++i) {
+ _threads[i].start();
+ }
+ }
- public void run() {
- try {
- _runner.runMethod();
- } catch (Throwable t) {
- _concurrentException.add(t);
- }
- }
- }
+ private void joinThreads() {
+ for (int i = 0; i < _threads.length; ++i) {
+ try {
+ _threads[i].join();
+ } catch (InterruptedException e) {
+ _concurrentException.add(e);
+ }
+ }
+ }
+
+ protected String getCheckMethodName() {
+ return "check_" + _method.getName(); //$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 (Throwable t) {
+ _concurrentException.add(t);
+ }
+ }
+ }
}
Modified: trunk/punit/src/org/punit/method/runner/MethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/MethodRunner.java 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit/src/org/punit/method/runner/MethodRunner.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -38,4 +38,6 @@
public Object clone();
public void setConvention(Convention convention);
+
+ public boolean shouldStop();
}
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -65,18 +65,18 @@
public void logResult() {
stopTimeWatcher();
StringBuffer sb = new StringBuffer();
- sb.append(Messages.getString("logger.02")); //$NON-NLS-1$
+ sb.append(Messages.getString("logger.total")); //$NON-NLS-1$
sb.append(_result.methodCount());
sb.append(", "); //$NON-NLS-1$
- sb.append(Messages.getString("logger.03")); //$NON-NLS-1$
+ sb.append(Messages.getString("logger.failures")); //$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$
+ sb.append(Messages.getString("logger.green")); //$NON-NLS-1$
} else {
- sb.append(Messages.getString("logger.05")); //$NON-NLS-1$
+ sb.append(Messages.getString("logger.red")); //$NON-NLS-1$
}
sb.append(") - "); //$NON-NLS-1$
sb.append(_timeWatcher.stringValue());
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -251,7 +251,7 @@
}
private void runTestClassImpl(final Class clazz) {
- Object testInstance = ReflectionUtil.newInstance(clazz);
+ final Object testInstance = ReflectionUtil.newInstance(clazz);
Throwable storedException = null;
Collection testMethods = extractTestMethods(clazz);
@@ -261,7 +261,7 @@
TraverserUtil.traverse(testMethods.iterator(), new Traverser() {
public void traverse(Object obj) {
Method method = (Method) obj;
- runTestMethod(clazz, method);
+ runTestMethod(testInstance, method);
}
});
} catch (Throwable t) {
@@ -322,9 +322,8 @@
});
}
- private void runTestMethod(Class clazz, Method method) {
- Object testInstance = ReflectionUtil.newInstance(clazz);
- if (_convention.isParameterizedTest(clazz)) {
+ private void runTestMethod(Object testInstance, Method method) {
+ if (_convention.isParameterizedTest(testInstance.getClass())) {
Parameterized pInstance = (Parameterized) testInstance;
Parameter[] params = pInstance.parameters();
for (int i = 0; i < params.length; ++i) {
Modified: trunk/punit/src/org/punit/util/MemoryUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/MemoryUtil.java 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit/src/org/punit/util/MemoryUtil.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -1,5 +1,7 @@
package org.punit.util;
+import org.punit.assertion.Assert;
+import org.punit.exception.OutOfMemoryException;
public class MemoryUtil {
@@ -8,18 +10,80 @@
private static long freeMemory() {
return _runtime.freeMemory();
}
-
+
public static long totalMemory() {
return _runtime.totalMemory();
}
-
+
public static long usedMemory() {
+ clear();
return totalMemory() - freeMemory();
}
public static void clear() {
- System.gc();
- System.runFinalization();
+ final int CLEAR_RETRIES = 3;
+
+ long free;
+
+ // continue while amount of free memory grows
+ do {
+ free = freeMemory();
+ for (int i = 0; i < CLEAR_RETRIES; i++) {
+ System.gc();
+ System.runFinalization();
+ // give a finalization thread a chance to do it's job
+ Thread.yield();
+ }
+ } while (free < freeMemory());
+
}
+ /**
+ * Allocates objects till OutOfMemoryError is not thrown.
+ *
+ * @return total memory when virtual pages can be no longer committed
+ */
+ public static long maxTotalMemory() {
+ int size = Integer.MAX_VALUE;
+
+ Object[] list = new Object[1];
+
+ // decrease the chunk size
+ while (size > 0) {
+ try {
+ while (true) {
+ Object[] newElement = new Object[size];
+ newElement[0] = list;
+ list = newElement;
+ }
+ } catch (OutOfMemoryError oome) {
+ }
+ size = size / 2;
+ }
+ return totalMemory();
+ }
+
+ private static final int WILDERNESS_SIZE = 4096;
+
+ private static byte[] _wilderness;
+
+ static {
+ allocateWilderness();
+ }
+
+ public static void allocateWilderness() {
+ Assert.assertNull(_wilderness);
+ try {
+ _wilderness = new byte[WILDERNESS_SIZE];
+ } catch (OutOfMemoryError oome) {
+ System.out.println("failed to allocate wilderness");
+ Thread.dumpStack();
+ throw new OutOfMemoryException(oome);
+ }
+ }
+
+ public static void releaseWilderness() {
+ Assert.assertNotNull(_wilderness);
+ _wilderness = null;
+ }
}
Modified: trunk/punit/src/org/punit/util/ReflectionUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -62,6 +62,7 @@
field.setInt(testInstance, intVal);
} else if (fieldClass.equals(long.class)) {
long longVal = Long.parseLong(value);
+
field.setLong(testInstance, longVal);
} else {
field.set(testInstance, value);
@@ -117,6 +118,5 @@
private static boolean isBitSet(int value, int expectedBit) {
return (value & expectedBit) != 0;
-
}
}
Modified: trunk/punit/src/org/punit/util/TraverserUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/TraverserUtil.java 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit/src/org/punit/util/TraverserUtil.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -7,5 +7,6 @@
while (iter.hasNext()) {
traverser.traverse(iter.next());
}
+
}
}
Modified: trunk/punit/src/org/punit/watcher/AbstractWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/AbstractWatcher.java 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit/src/org/punit/watcher/AbstractWatcher.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -22,7 +22,7 @@
public String stringValue() {
if (_scale == 1) {
- return _value + " " + unit(); //$NON-NLS-1$
+ return _value + unit(); //$NON-NLS-1$
} else {
return value() + unit();
}
Modified: trunk/punit/src/org/punit/watcher/CustomWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/CustomWatcher.java 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit/src/org/punit/watcher/CustomWatcher.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -48,14 +48,12 @@
public static synchronized void setResult(final String name,
final long value, final String unit, final long scale) {
Iterator iter = _methodRunner.watchers().iterator();
-// System.out.println(name + " " + value + " " + unit + " " + scale);
while (iter.hasNext()) {
try {
CustomWatcher watcher = (CustomWatcher) iter.next();
if (watcher.punitName().equals(name)) {
- watcher.setValue(value);
+ watcher.setValue(value, scale);
watcher._unit = unit;
- watcher._scale = scale;
}
} catch (ClassCastException cce) {
}
@@ -73,18 +71,23 @@
try {
CustomWatcher watcher = (CustomWatcher) iter.next();
if (watcher.punitName().equals(name)) {
- watcher.setValue(value);
+ watcher.setValue(value, watcher._scale);
}
} catch (ClassCastException cce) {
}
}
}
+
+ public static boolean shouldStop() {
+ return _methodRunner.shouldStop();
+ }
/**
* Updates the value for this runner.
*/
- void setValue(final long value) {
+ public void setValue(final long value, final long scale) {
_value = value;
+ _scale = scale;
}
public String punitName() {
Modified: trunk/punit/src/org/punit/watcher/MaximumWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/MaximumWatcher.java 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit/src/org/punit/watcher/MaximumWatcher.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -26,9 +26,12 @@
/**
* Updates the value for this runner.
*/
- void setValue(final long value) {
- if (value > _value) {
+ public void setValue(final long value, final long scale) {
+ long dv = value - _value;
+ long ds = scale - _scale;
+ if (dv * _scale > _value * ds) {
_value = value;
+ _scale = scale;
}
}
}
Modified: trunk/punit/src/org/punit/watcher/MinimumWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/MinimumWatcher.java 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit/src/org/punit/watcher/MinimumWatcher.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -26,9 +26,12 @@
/**
* Updates the value for this runner.
*/
- void setValue(final long value) {
- if (value < _value) {
+ public void setValue(final long value, final long scale) {
+ long dv = value - _value;
+ long ds = scale - _scale;
+ if (dv * _scale < _value * ds) {
_value = value;
+ _scale = scale;
}
}
}
Modified: trunk/punit/src/punit.properties
===================================================================
--- trunk/punit/src/punit.properties 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit/src/punit.properties 2007-08-19 22:45:41 UTC (rev 232)
@@ -1,23 +1,23 @@
-builder.01=\ should implement
-logger.01=Started running
-logger.02=total:
-logger.03=failures:
-logger.04=GREEN
-logger.05=RED
-logger.06=TestSuite:
-runner.01=solo
-runner.02=solo.param
-runner.03=concurrent
-runner.04=concurrent.param
-runner.arguments=\ arguments
-watcher.bytes=bytes
-watcher.ms=ms
-watcher.memory=Memory
-watcher.time=Time
-reporter.01=result
-reporter.02=overview
-PDFRender.01=PUnit result\n
-PDFRender.02=the open source performance benchmark framework\n
-Assert.0=Excepted
-Assert.1=, but
-Assert.2=expected not the same:
+builder.01=\ should implement
+logger.01=Started running
+logger.total=total:
+logger.failures=failures:
+logger.green=GREEN
+logger.red=RED
+logger.06=TestSuite:
+runner.01=solo
+runner.02=solo.param
+runner.03=concurrent
+runner.04=concurrent.param
+runner.arguments=\ arguments
+watcher.bytes=bytes
+watcher.ms=ms
+watcher.memory=Memory
+watcher.time=Time
+reporter.01=result
+reporter.02=overview
+PDFRender.01=PUnit result\n
+PDFRender.02=the open source performance benchmark framework\n
+assert.expected=Expected
+assert.got=, but got
+assert.notsame=Expected a different object:
Modified: trunk/punit.extension/src/org/punit/listener/FieldSetter.java
===================================================================
--- trunk/punit.extension/src/org/punit/listener/FieldSetter.java 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit.extension/src/org/punit/listener/FieldSetter.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -18,7 +18,7 @@
public class FieldSetter implements EventListener {
private static final long serialVersionUID = 5194809928409791777L;
-
+
private final Properties _properties;
public FieldSetter(Properties properties) {
@@ -92,11 +92,14 @@
*/
private void setClassFields(Object testInstance, Properties properties) {
for (Field field : testInstance.getClass().getFields()) {
- String fieldName = PACKAGE_SEPARATOR + field.getName();
+ String fieldName = PACKAGE_SEPARATOR
+ + field.getDeclaringClass().getName() + PACKAGE_SEPARATOR
+ + field.getName();
for (Object key : properties.keySet()) {
final String keyName = key.toString();
if (fieldName.indexOf(PACKAGE_SEPARATOR + keyName) >= 0) {
- ReflectionUtil.setField(testInstance, field, properties.getProperty(keyName));
+ ReflectionUtil.setField(testInstance, field, properties
+ .getProperty(keyName));
}
}
}
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -15,7 +15,7 @@
public static final String SUPPORTED_THREADS = "Supported Number of Threads"; //$NON-NLS-1$
- public static final String THREAD_UNITS = "threads"; //$NON-NLS-1$
+ public static final String THREAD_UNITS = " threads"; //$NON-NLS-1$
private boolean _stop;
Modified: trunk/punit.test/src/tests/api/org/punit/util/IOUtilTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/util/IOUtilTest.java 2007-08-12 14:03:50 UTC (rev 231)
+++ trunk/punit.test/src/tests/api/org/punit/util/IOUtilTest.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -14,45 +14,47 @@
public class IOUtilTest extends TestCase {
- public void testSerialize1() throws java.io.IOException {
- File file = File.createTempFile("test", "ser"); //$NON-NLS-1$//$NON-NLS-2$
- file.deleteOnExit();
- IOUtil.serialize(new SerializableClass1(), file.getCanonicalPath());
- }
-
- public void testSerialize2() throws java.io.IOException {
- final File file = File.createTempFile("test", "ser"); //$NON-NLS-1$//$NON-NLS-2$
- file.deleteOnExit();
- AssertUtil.assertException(IOException.class, new CodeRunner() {
- public void run() throws Throwable {
- IOUtil.serialize(new NonSerializableClass1(), file.getCanonicalPath());
- }
- });
- }
-
- public void testgetSerializableObject() throws java.io.IOException {
- File file = File.createTempFile("test", "ser"); //$NON-NLS-1$//$NON-NLS-2$
- file.deleteOnExit();
- String fileName = file.getCanonicalPath();
- SerializableClass1 obj1 = new SerializableClass1();
- IOUtil.serialize(obj1, fileName);
- SerializableClass1 obj2 = (SerializableClass1) IOUtil.getSerialiableObject(fileName);
- assertEquals(3, obj2.i);
- }
+ public void testSerialize1() throws java.io.IOException {
+ File file = File.createTempFile("test", "ser"); //$NON-NLS-2$
+ file.deleteOnExit();
+ IOUtil.serialize(new SerializableClass1(), file.getCanonicalPath());
+ }
- public void testDeleteFile() throws Exception {
- String fileName = "hello.txt"; //$NON-NLS-1$
- new FileOutputStream(fileName).close();
- IOUtil.deleteFile(fileName);
- assertFalse(new File(fileName).exists());
- }
-
- private static class SerializableClass1 implements Serializable {
- private static final long serialVersionUID = -5238909303048584560L;
- public int i = 3;
- }
-
- private static class NonSerializableClass1 {
- public int i = 3;
- }
+ public void testSerialize2() throws java.io.IOException {
+ final File file = File.createTempFile("test", "ser"); //$NON-NLS-2$
+ file.deleteOnExit();
+ AssertUtil.assertException(IOException.class, new CodeRunner() {
+ public void run() throws Throwable {
+ IOUtil.serialize(new NonSerializableClass1(), file
+ .getCanonicalPath());
+ }
+ });
+ }
+
+ public void testgetSerializableObject() throws java.io.IOException {
+ File file = File.createTempFile("test", "ser"); //$NON-NLS-2$
+ file.deleteOnExit();
+ String fileName = file.getCanonicalPath();
+ SerializableClass1 obj1 = new SerializableClass1();
+ IOUtil.serialize(obj1, fileName);
+ SerializableClass1 obj2 = (SerializableClass1) IOUtil
+ .getSerialiableObject(fileName);
+ assertEquals(3, obj2.i);
+ }
+
+ public void testDeleteFile() throws Exception {
+ String fileName = "hello.txt"; //$NON-NLS-1$
+ new FileOutputStream(fileName).close();
+ IOUtil.deleteFile(fileName);
+ assertFalse(new File(fileName).exists());
+ }
+
+ private static class SerializableClass1 implements Serializable {
+ private static final long serialVersionUID = -5238909303048584560L;
+ public int i = 3;
+ }
+
+ private static class NonSerializableClass1 {
+ public int i = 3;
+ }
}
Added: trunk/punit.test/src/tests/api/org/punit/util/MemoryUtilTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/util/MemoryUtilTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/util/MemoryUtilTest.java 2007-08-19 22:45:41 UTC (rev 232)
@@ -0,0 +1,27 @@
+package tests.api.org.punit.util;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.punit.util.MemoryUtil;
+
+public class MemoryUtilTest extends TestCase {
+
+ private static final float TOLERANCE = 0.1f;
+
+ public void testUsedMemory() {
+ long used = MemoryUtil.usedMemory();
+ Assert.assertTrue(used <= MemoryUtil.totalMemory());
+ Assert.assertTrue(used <= MemoryUtil.maxTotalMemory());
+
+ int size = Math.round((1 - TOLERANCE)
+ * (MemoryUtil.totalMemory() - used));
+ Object a = new byte[size];
+ Assert.assertEquals(1, ((float) MemoryUtil.usedMemory() - used) / size, TOLERANCE);
+ }
+
+ public void testTotalMemory() {
+ Assert.assertTrue(MemoryUtil.totalMemory() ...
[truncated message content] |
|
From: <le...@us...> - 2007-09-28 17:30:01
|
Revision: 233
http://p-unit.svn.sourceforge.net/p-unit/?rev=233&view=rev
Author: leshik
Date: 2007-09-28 10:29:13 -0700 (Fri, 28 Sep 2007)
Log Message:
-----------
Simplified memory cleanup utilities, fixed minor formatting issues.
Modified Paths:
--------------
trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
trunk/punit/src/org/punit/util/MemoryUtil.java
trunk/punit/src/org/punit/util/ReflectionUtil.java
trunk/punit/src/org/punit/watcher/CustomWatcher.java
trunk/punit/src/punit.properties
trunk/punit.samples/src/samples/DoSomethingTestClass.java
trunk/punit.test/src/tests/api/org/punit/util/MemoryUtilTest.java
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-08-19 22:45:41 UTC (rev 232)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-09-28 17:29:13 UTC (rev 233)
@@ -55,6 +55,7 @@
public AbstractMethodRunner() {
_watchers.add(_timeWatcher);
+ _shouldStop = true;
}
public void setEventListeners(List eventListeners) {
@@ -174,9 +175,6 @@
}
}, toWork);
_shouldStop = false;
- } else {
- _shouldStop = true;
- _toStopThread = null;
}
}
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2007-08-19 22:45:41 UTC (rev 232)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2007-09-28 17:29:13 UTC (rev 233)
@@ -106,7 +106,7 @@
}
public void onClassStart(Object testInstance) {
- logln(testInstance.getClass().getName(), Level.INFO);
+ // logln(testInstance.getClass().getName(), Level.INFO);
}
public void onClassEnd(Object testInstance, Throwable t) {
Modified: trunk/punit/src/org/punit/util/MemoryUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/MemoryUtil.java 2007-08-19 22:45:41 UTC (rev 232)
+++ trunk/punit/src/org/punit/util/MemoryUtil.java 2007-09-28 17:29:13 UTC (rev 233)
@@ -6,63 +6,20 @@
public class MemoryUtil {
private static Runtime _runtime = Runtime.getRuntime();
-
- private static long freeMemory() {
- return _runtime.freeMemory();
- }
-
+
public static long totalMemory() {
return _runtime.totalMemory();
}
public static long usedMemory() {
- clear();
- return totalMemory() - freeMemory();
+ return totalMemory() - _runtime.freeMemory();
}
public static void clear() {
- final int CLEAR_RETRIES = 3;
-
- long free;
-
- // continue while amount of free memory grows
- do {
- free = freeMemory();
- for (int i = 0; i < CLEAR_RETRIES; i++) {
- System.gc();
- System.runFinalization();
- // give a finalization thread a chance to do it's job
- Thread.yield();
- }
- } while (free < freeMemory());
-
+ System.gc();
+ System.runFinalization();
}
-
- /**
- * Allocates objects till OutOfMemoryError is not thrown.
- *
- * @return total memory when virtual pages can be no longer committed
- */
- public static long maxTotalMemory() {
- int size = Integer.MAX_VALUE;
-
- Object[] list = new Object[1];
-
- // decrease the chunk size
- while (size > 0) {
- try {
- while (true) {
- Object[] newElement = new Object[size];
- newElement[0] = list;
- list = newElement;
- }
- } catch (OutOfMemoryError oome) {
- }
- size = size / 2;
- }
- return totalMemory();
- }
-
+
private static final int WILDERNESS_SIZE = 4096;
private static byte[] _wilderness;
@@ -76,8 +33,6 @@
try {
_wilderness = new byte[WILDERNESS_SIZE];
} catch (OutOfMemoryError oome) {
- System.out.println("failed to allocate wilderness");
- Thread.dumpStack();
throw new OutOfMemoryException(oome);
}
}
Modified: trunk/punit/src/org/punit/util/ReflectionUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-08-19 22:45:41 UTC (rev 232)
+++ trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-09-28 17:29:13 UTC (rev 233)
@@ -51,9 +51,6 @@
* the string value to assign
*/
public static void setField(Object testInstance, Field field, String value) {
- // System.out.println("Field = " + field + ", value = " + value);
- // System.out.println("value = " + Integer.getInteger(value));
-
try {
field.setAccessible(true);
Class fieldClass = field.getType();
Modified: trunk/punit/src/org/punit/watcher/CustomWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/CustomWatcher.java 2007-08-19 22:45:41 UTC (rev 232)
+++ trunk/punit/src/org/punit/watcher/CustomWatcher.java 2007-09-28 17:29:13 UTC (rev 233)
@@ -18,7 +18,7 @@
private String _name;
- private String _unit;
+ private String _unit;
private transient static MethodRunner _methodRunner;
@@ -77,7 +77,7 @@
}
}
}
-
+
public static boolean shouldStop() {
return _methodRunner.shouldStop();
}
Modified: trunk/punit/src/punit.properties
===================================================================
--- trunk/punit/src/punit.properties 2007-08-19 22:45:41 UTC (rev 232)
+++ trunk/punit/src/punit.properties 2007-09-28 17:29:13 UTC (rev 233)
@@ -1,5 +1,5 @@
builder.01=\ should implement
-logger.01=Started running
+logger.01=Starting
logger.total=total:
logger.failures=failures:
logger.green=GREEN
Modified: trunk/punit.samples/src/samples/DoSomethingTestClass.java
===================================================================
--- trunk/punit.samples/src/samples/DoSomethingTestClass.java 2007-08-19 22:45:41 UTC (rev 232)
+++ trunk/punit.samples/src/samples/DoSomethingTestClass.java 2007-09-28 17:29:13 UTC (rev 233)
@@ -5,19 +5,19 @@
public class DoSomethingTestClass implements Test {
public void setUpBeforeWatchers() throws Exception {
- System.out.println("This setup will not be caculated into the execution time"); //$NON-NLS-1$
+ System.out.println("This setup is not included into the execution time"); //$NON-NLS-1$
}
public void setUpAfterWatchers() throws Exception {
- System.out.println("This setup will be caculated into the execution time"); //$NON-NLS-1$
+ System.out.println("This setup is included into the execution time"); //$NON-NLS-1$
}
public void tearDownBeforeWatchers() throws Exception {
- System.out.println("This setup will be caculated into the execution time"); //$NON-NLS-1$
+ System.out.println("This tear down is included into the execution time"); //$NON-NLS-1$
}
public void tearDownAfterWatchers() throws Exception {
- System.out.println("This setup will not be caculated into the execution time"); //$NON-NLS-1$
+ System.out.println("This setup is not included into the execution time"); //$NON-NLS-1$
}
public void testA() {
Modified: trunk/punit.test/src/tests/api/org/punit/util/MemoryUtilTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/util/MemoryUtilTest.java 2007-08-19 22:45:41 UTC (rev 232)
+++ trunk/punit.test/src/tests/api/org/punit/util/MemoryUtilTest.java 2007-09-28 17:29:13 UTC (rev 233)
@@ -12,16 +12,10 @@
public void testUsedMemory() {
long used = MemoryUtil.usedMemory();
Assert.assertTrue(used <= MemoryUtil.totalMemory());
- Assert.assertTrue(used <= MemoryUtil.maxTotalMemory());
int size = Math.round((1 - TOLERANCE)
* (MemoryUtil.totalMemory() - used));
Object a = new byte[size];
Assert.assertEquals(1, ((float) MemoryUtil.usedMemory() - used) / size, TOLERANCE);
}
-
- public void testTotalMemory() {
- Assert.assertTrue(MemoryUtil.totalMemory() <= MemoryUtil
- .maxTotalMemory());
- }
}
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:57:00
|
Revision: 270
http://p-unit.svn.sourceforge.net/p-unit/?rev=270&view=rev
Author: zhanghuangzhu
Date: 2008-01-11 07:57:04 -0800 (Fri, 11 Jan 2008)
Log Message:
-----------
Andrew Zhang: Looking forward, based on java 5 now.
Modified Paths:
--------------
trunk/punit/.settings/org.eclipse.jdt.core.prefs
trunk/punit/src/org/punit/assertion/Assert.java
trunk/punit/src/org/punit/convention/AbstractConvention.java
trunk/punit/src/org/punit/convention/Convention.java
trunk/punit/src/org/punit/convention/NameConvention.java
trunk/punit/src/org/punit/events/EventListener.java
trunk/punit/src/org/punit/events/EventRegistry.java
trunk/punit/src/org/punit/events/VanillaEventListener.java
trunk/punit/src/org/punit/exception/ConcurrentException.java
trunk/punit/src/org/punit/message/Messages.java
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/method/runner/VanillaRunner.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/file/FileLogger.java
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
trunk/punit/src/org/punit/type/TestSuite.java
trunk/punit/src/org/punit/util/ReflectionUtil.java
trunk/punit/src/org/punit/util/ReporterUtil.java
trunk/punit/src/org/punit/util/RunnerUtil.java
trunk/punit/src/org/punit/watcher/CustomWatcher.java
Added Paths:
-----------
trunk/punit/src/org/punit/annotation/
trunk/punit/src/org/punit/annotation/After.java
trunk/punit/src/org/punit/annotation/AfterClass.java
trunk/punit/src/org/punit/annotation/Before.java
trunk/punit/src/org/punit/annotation/BeforeClass.java
trunk/punit/src/org/punit/annotation/Ignore.java
trunk/punit/src/org/punit/annotation/Test.java
trunk/punit/src/org/punit/convention/AnnotationConvention.java
trunk/punit/src/org/punit/runner/ExecutorPoolImpl.java
trunk/punit/src/org/punit/util/AnnotationUtil.java
Removed Paths:
-------------
trunk/punit/.settings/org.eclipse.jdt.ui.prefs
trunk/punit/src/org/punit/util/Traverser.java
trunk/punit/src/org/punit/util/TraverserUtil.java
Modified: trunk/punit/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- trunk/punit/.settings/org.eclipse.jdt.core.prefs 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/.settings/org.eclipse.jdt.core.prefs 2008-01-11 15:57:04 UTC (rev 270)
@@ -1,4 +1,4 @@
-#Sun May 13 18:44:47 CST 2007
+#Fri Jan 11 20:22:14 CST 2008
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
@@ -9,4 +9,4 @@
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.3
+org.eclipse.jdt.core.compiler.source=1.5
Deleted: trunk/punit/.settings/org.eclipse.jdt.ui.prefs
===================================================================
--- trunk/punit/.settings/org.eclipse.jdt.ui.prefs 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/.settings/org.eclipse.jdt.ui.prefs 2008-01-11 15:57:04 UTC (rev 270)
@@ -1,3 +0,0 @@
-#Sun May 13 18:44:44 CST 2007
-eclipse.preferences.version=1
-internal.default.compliance=user
Added: trunk/punit/src/org/punit/annotation/After.java
===================================================================
--- trunk/punit/src/org/punit/annotation/After.java (rev 0)
+++ trunk/punit/src/org/punit/annotation/After.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -0,0 +1,14 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+package org.punit.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+
+public @interface After {
+
+}
Property changes on: trunk/punit/src/org/punit/annotation/After.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit/src/org/punit/annotation/AfterClass.java
===================================================================
--- trunk/punit/src/org/punit/annotation/AfterClass.java (rev 0)
+++ trunk/punit/src/org/punit/annotation/AfterClass.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -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 AfterClass {
+
+}
Property changes on: trunk/punit/src/org/punit/annotation/AfterClass.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit/src/org/punit/annotation/Before.java
===================================================================
--- trunk/punit/src/org/punit/annotation/Before.java (rev 0)
+++ trunk/punit/src/org/punit/annotation/Before.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -0,0 +1,13 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+package org.punit.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Before {
+
+}
Property changes on: trunk/punit/src/org/punit/annotation/Before.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit/src/org/punit/annotation/BeforeClass.java
===================================================================
--- trunk/punit/src/org/punit/annotation/BeforeClass.java (rev 0)
+++ trunk/punit/src/org/punit/annotation/BeforeClass.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -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 BeforeClass {
+
+}
Property changes on: trunk/punit/src/org/punit/annotation/BeforeClass.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit/src/org/punit/annotation/Ignore.java
===================================================================
--- trunk/punit/src/org/punit/annotation/Ignore.java (rev 0)
+++ trunk/punit/src/org/punit/annotation/Ignore.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -0,0 +1,10 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.annotation;
+
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Ignore {
+ String value() default "";
+}
Property changes on: trunk/punit/src/org/punit/annotation/Ignore.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit/src/org/punit/annotation/Test.java
===================================================================
--- trunk/punit/src/org/punit/annotation/Test.java (rev 0)
+++ trunk/punit/src/org/punit/annotation/Test.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -0,0 +1,20 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.annotation;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Test {
+
+ Class<? extends Throwable> expected() default NoException.class;
+
+ String checkMethod() default "";
+
+ int concurrentCount() default 0;
+
+ public class NoException extends Throwable {
+ private static final long serialVersionUID = 3987745685001380514L;
+ }
+}
Property changes on: trunk/punit/src/org/punit/annotation/Test.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/punit/src/org/punit/assertion/Assert.java
===================================================================
--- trunk/punit/src/org/punit/assertion/Assert.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/assertion/Assert.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -76,8 +76,8 @@
}
}
- public static void assertException(Class throwable, CodeRunner code) {
- Class exceptionClass = null;
+ public static void assertException(Class <? extends Throwable> throwable, CodeRunner code) {
+ Class <? extends Throwable> exceptionClass = null;
try {
code.run();
} catch (Throwable e) {
Modified: trunk/punit/src/org/punit/convention/AbstractConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/AbstractConvention.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/convention/AbstractConvention.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -12,11 +12,11 @@
abstract public class AbstractConvention implements Convention {
- public boolean isExcluded(Class method) {
+ public boolean isExcluded(Class <?> method) {
return false;
}
- public Class getExpectedException(Method method) {
+ public Class<? extends Throwable> getExpectedException(Method method) {
return null;
}
@@ -27,19 +27,19 @@
return 0;
}
- public boolean isPUnitTest(Class clazz) {
+ public boolean isPUnitTest(Class<?> clazz) {
return Test.class.isAssignableFrom(clazz);
}
- public boolean isParameter(Class clazz) {
+ public boolean isParameter(Class<?> clazz) {
return Parameter.class.isAssignableFrom(clazz);
}
- public boolean isParameterizedTest(Class clazz) {
+ public boolean isParameterizedTest(Class<?> clazz) {
return Parameterized.class.isAssignableFrom(clazz);
}
- public boolean isLoopTest(Class clazz) {
+ public boolean isLoopTest(Class<?> clazz) {
return Loop.class.isAssignableFrom(clazz);
}
Added: trunk/punit/src/org/punit/convention/AnnotationConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/AnnotationConvention.java (rev 0)
+++ trunk/punit/src/org/punit/convention/AnnotationConvention.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -0,0 +1,134 @@
+/* (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;
+ }
+
+}
Property changes on: trunk/punit/src/org/punit/convention/AnnotationConvention.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/punit/src/org/punit/convention/Convention.java
===================================================================
--- trunk/punit/src/org/punit/convention/Convention.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/convention/Convention.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -12,7 +12,7 @@
*
* @return returns true if the test class is excluded.
*/
- public boolean isExcluded(Class clazz);
+ public boolean isExcluded(Class <?> clazz);
/**
* Judges whether this method is a test method.
@@ -30,25 +30,25 @@
*/
public Method getCheckMethod(Method method);
- public Class getExpectedException(Method method);
+ public Class<? extends Throwable> getExpectedException(Method method);
public int getConcurrentCount(Object testInstance, Method method);
- public Method getSetUpMethod(Class test);
+ public Method getSetUpMethod(Class<?> test);
- public Method getTearDownMethod(Class test);
+ public Method getTearDownMethod(Class<?> test);
- public Method getBeforeClassMethod(Class test);
+ public Method getBeforeClassMethod(Class<?> test);
- public Method getAfterClassMethod(Class test);
+ public Method getAfterClassMethod(Class<?> test);
- public boolean isPUnitTest(Class clazz);
+ public boolean isPUnitTest(Class<?> clazz);
- public boolean isParameter(Class clazz);
+ public boolean isParameter(Class<?> clazz);
- public boolean isParameterizedTest(Class clazz);
+ public boolean isParameterizedTest(Class<?> clazz);
- public boolean isLoopTest(Class clazz);
+ public boolean isLoopTest(Class<?> clazz);
public long toWork(Object testInstance);
}
Modified: trunk/punit/src/org/punit/convention/NameConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/NameConvention.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/convention/NameConvention.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -66,8 +66,8 @@
* from <code>Parameter</code>.
*/
protected boolean isParamValid(Method method) {
- Class clazz = method.getDeclaringClass();
- Class[] params = method.getParameterTypes();
+ Class<?> clazz = method.getDeclaringClass();
+ Class<?>[] params = method.getParameterTypes();
if (isParameterizedTest(clazz)) {
return params.length == 1 && isParameter(params[0]);
} else {
@@ -75,30 +75,30 @@
}
}
- public Method getAfterClassMethod(Class test) {
+ public Method getAfterClassMethod(Class<?> test) {
Method method = ReflectionUtil.getMethodAndSetAccessible(test,
- "beforeClass", new Class[] {}); //$NON-NLS-1$
+ "afterClass", new Class[] {}); //$NON-NLS-1$
if (method != null && ReflectionUtil.isStatic(method)) {
return method;
}
return null;
}
- public Method getBeforeClassMethod(Class test) {
+ public Method getBeforeClassMethod(Class<?> test) {
Method method = ReflectionUtil.getMethodAndSetAccessible(test,
- "afterClass", new Class[] {}); //$NON-NLS-1$
+ "beforeClass", new Class[] {}); //$NON-NLS-1$
if (method != null && ReflectionUtil.isStatic(method)) {
return method;
}
return null;
}
- public Method getSetUpMethod(Class test) {
+ public Method getSetUpMethod(Class<?> test) {
return ReflectionUtil.getMethodAndSetAccessible(test,
"setUp", new Class[] {}); //$NON-NLS-1$
}
- public Method getTearDownMethod(Class test) {
+ public Method getTearDownMethod(Class<?> test) {
return ReflectionUtil.getMethodAndSetAccessible(test,
"tearDown", new Class[] {}); //$NON-NLS-1$
}
Modified: trunk/punit/src/org/punit/events/EventListener.java
===================================================================
--- trunk/punit/src/org/punit/events/EventListener.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/events/EventListener.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -27,7 +27,7 @@
* @param runner
* the runner who runs this class
*/
- public void onRunnerStart(Class clazz, Runner runner);
+ public void onRunnerStart(Class<?> clazz, Runner runner);
/**
* Is triggered after running the class.
@@ -37,7 +37,7 @@
* @param runner
* the runner who runs this class
*/
- public void onRunnerEnd(Class clazz, Runner runner);
+ public void onRunnerEnd(Class<?> clazz, Runner runner);
/**
* Is triggered when the test suite is to be executed.
@@ -79,17 +79,17 @@
* Is triggered after executing the method.
*/
public void onMethodEnd(Method method, Object testInstance,
- Object[] params, Throwable t, List Watchers);
+ Object[] params, Throwable t, List<Watcher> Watchers);
/**
* Is triggered before all watchers start.
*/
- public void onWatchersStart(List watchers);
+ public void onWatchersStart(List<Watcher> watchers);
/**
* Is triggered after all watchers stop.
*/
- public void onWatchersEnd(List watchers);
+ public void onWatchersEnd(List<Watcher> watchers);
/**
* Is triggered before this watcher starts.
Modified: trunk/punit/src/org/punit/events/EventRegistry.java
===================================================================
--- trunk/punit/src/org/punit/events/EventRegistry.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/events/EventRegistry.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -27,5 +27,5 @@
/**
* @return returns the registered event listeners.
*/
- public List eventListeners();
+ public List<EventListener> eventListeners();
}
Modified: trunk/punit/src/org/punit/events/VanillaEventListener.java
===================================================================
--- trunk/punit/src/org/punit/events/VanillaEventListener.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/events/VanillaEventListener.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -12,42 +12,29 @@
private static final long serialVersionUID = -2413131933921801719L;
public VanillaEventListener() {
-
}
public void onClassEnd(Object testInstance, Throwable t) {
-
}
public void onClassStart(Object testInstance) {
-
}
public void onMethodEnd(Method method, Object testInstance,
- Object[] params, Throwable t, List Watchers) {
- // TODO Auto-generated method stub
-
+ Object[] params, Throwable t, List<Watcher> Watchers) {
}
public void onMethodStart(Method method, Object testInstance,
Object[] params) {
- // TODO Auto-generated method stub
-
}
- public void onRunnerEnd(Class clazz, Runner runner) {
- // TODO Auto-generated method stub
-
+ public void onRunnerEnd(Class<?> clazz, Runner runner) {
}
- public void onRunnerStart(Class clazz, Runner runner) {
- // TODO Auto-generated method stub
-
+ public void onRunnerStart(Class<?> clazz, Runner runner) {
}
public void onSuiteEnd(TestSuite suite) {
- // TODO Auto-generated method stub
-
}
public void onSuiteStart(TestSuite suite) {
@@ -62,11 +49,11 @@
}
- public void onWatchersEnd(List watchers) {
+ public void onWatchersEnd(List<Watcher> watchers) {
}
- public void onWatchersStart(List watchers) {
+ public void onWatchersStart(List<Watcher> watchers) {
}
Modified: trunk/punit/src/org/punit/exception/ConcurrentException.java
===================================================================
--- trunk/punit/src/org/punit/exception/ConcurrentException.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/exception/ConcurrentException.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -2,13 +2,10 @@
package org.punit.exception;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.util.Vector;
+import java.io.*;
+import java.util.*;
-import org.punit.util.ReporterUtil;
-import org.punit.util.Traverser;
-import org.punit.util.TraverserUtil;
+import org.punit.util.*;
/**
* Exception for concurrent runner. There might be not only one exception thrown
@@ -19,7 +16,7 @@
private static final long serialVersionUID = 6816596410667344664L;
- private Vector _throwables = new Vector();
+ private Vector<Throwable> _throwables = new Vector<Throwable>();
public void add(Throwable t) {
_throwables.add(t);
@@ -31,43 +28,35 @@
public void printStackTrace() {
System.err.println(ConcurrentException.class.getName() + ":"); //$NON-NLS-1$
- TraverserUtil.traverse(_throwables.iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((Throwable) obj).printStackTrace();
- }
- });
+ Iterator<Throwable> iter = _throwables.iterator();
+ while(iter.hasNext()) {
+ iter.next().printStackTrace();
+ }
}
public void printStackTrace(final PrintStream ps) {
ps.println(ConcurrentException.class.getName() + ":"); //$NON-NLS-1$
- TraverserUtil.traverse(_throwables.iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((Throwable) obj).printStackTrace(ps);
- }
- });
+ Iterator<Throwable> iter = _throwables.iterator();
+ while(iter.hasNext()) {
+ iter.next().printStackTrace(ps);
+ }
}
public void printStackTrace(final PrintWriter pw) {
pw.println(ConcurrentException.class.getName() + ":"); //$NON-NLS-1$
- TraverserUtil.traverse(_throwables.iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((Throwable) obj).printStackTrace(pw);
- }
- });
+ Iterator<Throwable> iter = _throwables.iterator();
+ while(iter.hasNext()) {
+ iter.next().printStackTrace(pw);
+ }
}
public String getMessage() {
- GetMessageVisitor visitor = new GetMessageVisitor();
- TraverserUtil.traverse(_throwables.iterator(), visitor);
- return visitor.sb.toString();
- }
-
- static class GetMessageVisitor implements Traverser {
- final StringBuffer sb = new StringBuffer();
-
- public void traverse(Object obj) {
- sb.append(((Throwable) obj));
+ StringBuffer sb = new StringBuffer();
+ Iterator<Throwable> iter = _throwables.iterator();
+ while(iter.hasNext()) {
+ sb.append(iter.next());
sb.append(ReporterUtil.LINE_SEPERATOR);
}
+ return sb.toString();
}
}
Modified: trunk/punit/src/org/punit/message/Messages.java
===================================================================
--- trunk/punit/src/org/punit/message/Messages.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/message/Messages.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -7,7 +7,7 @@
private static ResourceBundle RESOURCE_BUNDLE = null;
- private static Hashtable MESSAGE_TABLE = null;
+ private static Hashtable<String, String> MESSAGE_TABLE = null;
private static boolean isAndroid;
@@ -26,7 +26,7 @@
}
private static void initMessageTable() {
- MESSAGE_TABLE = new Hashtable();
+ MESSAGE_TABLE = new Hashtable<String, String>();
for (int i = 0; i < MessageStrings.DATA.length; ++i) {
MESSAGE_TABLE.put(MessageStrings.DATA[i][0],
MessageStrings.DATA[i][1]);
Modified: trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -36,14 +36,14 @@
/**
* @see TestMethodBuilder#extractTestMethods(Class)
*/
- public Collection extractTestMethods(Class testClass) {
- Collection testMethods = null;
+ public Collection<Method> extractTestMethods(Class<?> testClass) {
+ Collection<Method> testMethods = null;
if (isAlphabetical(testClass)) {
- testMethods = new TreeSet(new AlphabeticalMethodNameComparator());
+ testMethods = new TreeSet<Method>(new AlphabeticalMethodNameComparator());
} else {
- testMethods = new ArrayList();
+ testMethods = new ArrayList<Method>();
}
- Class clazz = testClass;
+ Class<?> clazz = testClass;
while (clazz != Object.class) {
Method[] methods = clazz.getDeclaredMethods();
for (int i = 0; i < methods.length; ++i) {
@@ -57,14 +57,12 @@
return testMethods;
}
- private boolean isAlphabetical(Class testClass) {
+ 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;
+ private static class AlphabeticalMethodNameComparator implements Comparator<Method> {
+ public int compare(Method m1, Method m2) {
return m1.getName().compareTo(m2.getName());
}
}
Modified: trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -3,6 +3,7 @@
package org.punit.method.builder;
import java.io.Serializable;
+import java.lang.reflect.*;
import java.util.Collection;
import org.punit.convention.Convention;
@@ -21,7 +22,7 @@
* @return a <code>Collection</code> of
* <code>java.lang.reflect.Method</code>.
*/
- public Collection extractTestMethods(Class testClass); // Collection<Method>
+ public Collection<Method> extractTestMethods(Class<?> testClass); // Collection<Method>
public void setConvention(Convention convention);
}
Modified: tru...
[truncated message content] |
|
From: <zha...@us...> - 2008-02-16 15:10:54
|
Revision: 276
http://p-unit.svn.sourceforge.net/p-unit/?rev=276&view=rev
Author: zhanghuangzhu
Date: 2008-02-16 07:10:59 -0800 (Sat, 16 Feb 2008)
Log Message:
-----------
Andrew Zhang: flush writer information after logFailures
Modified Paths:
--------------
trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
Added Paths:
-----------
trunk/punit/core.jardesc
Added: trunk/punit/core.jardesc
===================================================================
--- trunk/punit/core.jardesc (rev 0)
+++ trunk/punit/core.jardesc 2008-02-16 15:10:59 UTC (rev 276)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="GBK" standalone="no"?>
+<jardesc>
+ <jar path="E:/workspace/p-unit/release/p-unit-0.14.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/>
+ <manifest generateManifest="true" manifestLocation="" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
+ <sealing sealJar="false">
+ <packagesToSeal/>
+ <packagesToUnSeal/>
+ </sealing>
+ </manifest>
+ <selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
+ <javaElement handleIdentifier="=punit/src"/>
+ </selectedElements>
+</jardesc>
Property changes on: trunk/punit/core.jardesc
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2008-01-19 11:53:46 UTC (rev 275)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2008-02-16 15:10:59 UTC (rev 276)
@@ -94,9 +94,10 @@
int count = 0;
log(++count + ")", Level.SEVERE); //$NON-NLS-1$
if (shouldLog(Level.SEVERE)) {
- iter.next().printStackTrace(_writer);
+ iter.next().printStackTrace(_writer);
}
}
+ _writer.flush();
}
private void stopTimeWatcher() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-15 09:32:53
|
Revision: 79
http://p-unit.svn.sourceforge.net/p-unit/?rev=79&view=rev
Author: zhanghuangzhu
Date: 2007-05-15 02:32:50 -0700 (Tue, 15 May 2007)
Log Message:
-----------
Andrew Zhang: began to implement vm competitive feature.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit/src/org/punit/util/ArgUtil.java
trunk/punit.test/src/tests/api/org/punit/util/ArgUtilTest.java
Added Paths:
-----------
trunk/punit/src/org/punit/runner/PUnitArgs.java
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-15 08:25:22 UTC (rev 78)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-15 09:32:50 UTC (rev 79)
@@ -1,6 +1,5 @@
package org.punit.runner;
-import java.io.*;
import java.lang.reflect.*;
import java.util.*;
@@ -26,6 +25,8 @@
private ConsoleLoggerListener _consoleLogger = new ConsoleLoggerListener();
private FileLoggerListener _fileLogger = new FileLoggerListener();
+
+ private PUnitArgs _pargs;
public PUnitAbstractRunner(TestSuiteBuilder testSuiteBuiler,
TestMethodBuilder testMethodBuilder,
@@ -37,6 +38,17 @@
}
public void run(Class clazz) {
+ punitArgs(defaultPargs(clazz));
+ runImpl(clazz);
+ }
+
+ public void run(PUnitArgs pargs) {
+ punitArgs(pargs);
+ Class clazz = ReflectionUtil.newClass(pargs.testClassName);
+ runImpl(clazz);
+ }
+
+ private void runImpl(Class clazz) {
onRunnerStart(clazz);
Object[] testClasses = _testSuiteBuiler.buildTestClasses(clazz);
for (int i = 0; i < testClasses.length; ++i) {
@@ -45,15 +57,11 @@
onRunnerEnd(clazz);
}
- public void run(String className, String resultFolder) {
- Class clazz = ReflectionUtil.newClass(className);
- run(clazz);
- }
-
public void runVMs(Class clazz, VM[] vm) {
for (int i = 0; i < vm.length; ++i) {
- String command = generateVMCommand(vm[i], clazz);
+ String command = generateVMCommand(clazz, vm[i]);
IOUtil.exec(command);
+ //TODO: generate report here.
}
}
@@ -61,7 +69,7 @@
* VM command: /path/java -classpath a.jar;path/lib/b.jar
* org.punit.runner.PUnitSoloRunner TestSuite1.class /output/
*/
- private String generateVMCommand(VM vm, Class testClass) {
+ private String generateVMCommand(Class testClass, VM vm) {
StringBuffer sb = new StringBuffer();
sb.append(vm.path());
sb.append(" -classpath "); //$NON-NLS-1$
@@ -71,6 +79,7 @@
sb.append(testClass.getName());
sb.append(" "); //$NON-NLS-1$
sb.append(IOUtil.getCurrentPath());
+ sb.append(" false"); //$NON-NLS-1$
return sb.toString();
}
@@ -224,4 +233,20 @@
public void addTestInterfaces(Class[] interfaces) {
_testMethodBuilder.addTestInterfaces(interfaces);
}
+
+ private PUnitArgs defaultPargs(Class clazz) {
+ String className = clazz.getName();
+ String resultFolder = IOUtil.getCurrentPath();
+ boolean intermediate = false;
+ return new PUnitArgs(className, resultFolder,intermediate);
+ }
+
+ private void punitArgs(PUnitArgs pargs) {
+ _pargs = pargs;
+ }
+
+ public PUnitArgs punitArgs() {
+ return _pargs;
+ }
+
}
Added: trunk/punit/src/org/punit/runner/PUnitArgs.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitArgs.java (rev 0)
+++ trunk/punit/src/org/punit/runner/PUnitArgs.java 2007-05-15 09:32:50 UTC (rev 79)
@@ -0,0 +1,15 @@
+package org.punit.runner;
+
+public class PUnitArgs {
+ public PUnitArgs(String className, String folder, boolean intermediate) {
+ testClassName = className;
+ resultFolder = folder;
+ this.intermediate = intermediate;
+ }
+
+ public final String testClassName;
+
+ public final String resultFolder;
+
+ public final boolean intermediate;
+}
Modified: trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitSoloRunner.java 2007-05-15 08:25:22 UTC (rev 78)
+++ trunk/punit/src/org/punit/runner/PUnitSoloRunner.java 2007-05-15 09:32:50 UTC (rev 79)
@@ -3,6 +3,8 @@
import org.punit.builder.*;
import org.punit.message.*;
import org.punit.runner.method.*;
+import org.punit.util.*;
+import org.punit.util.ArgUtil.*;
public class PUnitSoloRunner extends PUnitAbstractRunner {
@@ -13,12 +15,8 @@
* folder if it is not specified
*/
public static void main(String[] args) {
- if(args.length < 1 || args.length > 2) {
- throw new IllegalArgumentException();
- }
- String className = args[0];
- String resultFolder = args.length == 1 ? null : args[1];
- new PUnitSoloRunner().run(className, resultFolder);
+ PUnitArgs parg = ArgUtil.getPUnitArgs(args);
+ new PUnitSoloRunner().run(parg);
}
public PUnitSoloRunner() {
Modified: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java 2007-05-15 08:25:22 UTC (rev 78)
+++ trunk/punit/src/org/punit/runner/Runner.java 2007-05-15 09:32:50 UTC (rev 79)
@@ -2,13 +2,15 @@
import org.punit.builder.*;
import org.punit.events.*;
-import org.punit.result.*;
import org.punit.runner.method.*;
import org.punit.type.*;
public interface Runner extends RunnerEvent, ClassEvent, PUnitName {
+
public void run(Class clazz);
+ public PUnitArgs punitArgs();
+
public TestMethodBuilder testMethodBuilder();
public TestMethodRunner testMethodRunner();
Modified: trunk/punit/src/org/punit/util/ArgUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ArgUtil.java 2007-05-15 08:25:22 UTC (rev 78)
+++ trunk/punit/src/org/punit/util/ArgUtil.java 2007-05-15 09:32:50 UTC (rev 79)
@@ -1,25 +1,16 @@
package org.punit.util;
import org.punit.message.*;
+import org.punit.runner.*;
public class ArgUtil {
- public static class PUnitArgs {
- public PUnitArgs(String className, String folder) {
- testClassName = className;
- resultFolder = folder;
- }
-
- public String testClassName;
-
- public String resultFolder;
- }
-
public static PUnitArgs getPUnitArgs(String[] args) {
- if (args.length < 1 || args.length > 2) {
+ if (args.length < 1 || args.length > 3) {
throw new IllegalArgumentException(Messages.getString("runner.05")); //$NON-NLS-1$
}
String className = args[0];
- String resultFolder = args.length == 1 ? null : args[1];
- return new PUnitArgs(className, resultFolder);
+ String resultFolder = args.length >= 2 ? args[1] : null;
+ boolean intermediate = args.length == 3 ? Boolean.parseBoolean(args[2]) : false;
+ return new PUnitArgs(className, resultFolder, intermediate);
}
}
Modified: trunk/punit.test/src/tests/api/org/punit/util/ArgUtilTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/util/ArgUtilTest.java 2007-05-15 08:25:22 UTC (rev 78)
+++ trunk/punit.test/src/tests/api/org/punit/util/ArgUtilTest.java 2007-05-15 09:32:50 UTC (rev 79)
@@ -2,8 +2,8 @@
import junit.framework.*;
+import org.punit.runner.*;
import org.punit.util.*;
-import org.punit.util.ArgUtil.*;
import tests.util.*;
@@ -13,27 +13,40 @@
private static String RESULT_FOLDER = "b"; //$NON-NLS-1$
public void testGetPUnitArgs() {
-
PUnitArgs parg = ArgUtil.getPUnitArgs(new String[] { CLASS_NAME });
assertEquals(CLASS_NAME, parg.testClassName);
assertNull(parg.resultFolder);
+ assertFalse(parg.intermediate);
parg = ArgUtil.getPUnitArgs(new String[] { CLASS_NAME, RESULT_FOLDER });
assertEquals(CLASS_NAME, parg.testClassName);
assertEquals(RESULT_FOLDER, parg.resultFolder);
-
+ assertFalse(parg.intermediate);
+
+
+ parg = ArgUtil.getPUnitArgs(new String[] { CLASS_NAME, RESULT_FOLDER, "true" }); //$NON-NLS-1$
+ assertEquals(CLASS_NAME, parg.testClassName);
+ assertEquals(RESULT_FOLDER, parg.resultFolder);
+ assertTrue(parg.intermediate);
+
+ parg = ArgUtil.getPUnitArgs(new String[] { CLASS_NAME, RESULT_FOLDER, "false" }); //$NON-NLS-1$
+ assertEquals(CLASS_NAME, parg.testClassName);
+ assertEquals(RESULT_FOLDER, parg.resultFolder);
+ assertFalse(parg.intermediate);
+
AssertUtil.assertException(IllegalArgumentException.class,
new CodeRunner() {
public void run() throws Throwable {
ArgUtil.getPUnitArgs(new String[] {});
}
});
+
AssertUtil.assertException(IllegalArgumentException.class,
new CodeRunner() {
public void run() throws Throwable {
ArgUtil.getPUnitArgs(new String[] { CLASS_NAME,
- RESULT_FOLDER, null });
+ RESULT_FOLDER, null, null });
}
});
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-18 17:45:12
|
Revision: 119
http://p-unit.svn.sourceforge.net/p-unit/?rev=119&view=rev
Author: zhanghuangzhu
Date: 2007-05-18 10:45:10 -0700 (Fri, 18 May 2007)
Log Message:
-----------
Andrew Zhang: pdf is done.
Modified Paths:
--------------
trunk/punit/src/org/punit/exception/ConcurrentException.java
trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
trunk/punit/src/org/punit/reporter/stream/file/FileLoggerListener.java
trunk/punit/src/punit.properties
trunk/punit.extension/.classpath
trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
trunk/punit.extension/src/org/punit/reporter/chart/pdf/PDFRender.java
trunk/punit.test/src/extension/tests/samples/TestSuiteVMsSample.java
trunk/punit.test/src/tests/api/org/punit/exception/ConcurrentExceptionTest.java
trunk/punit.test/src/tests/api/org/punit/util/LoggerUtilTest.java
Added Paths:
-----------
trunk/punit/src/org/punit/util/ReporterUtil.java
trunk/punit.extension/lib/itext-2.0.2.jar
trunk/punit.extension/src/org/punit/reporter/chart/pdf/PDFConstants.java
Removed Paths:
-------------
trunk/punit/src/org/punit/util/LoggerUtil.java
Modified: trunk/punit/src/org/punit/exception/ConcurrentException.java
===================================================================
--- trunk/punit/src/org/punit/exception/ConcurrentException.java 2007-05-18 16:00:59 UTC (rev 118)
+++ trunk/punit/src/org/punit/exception/ConcurrentException.java 2007-05-18 17:45:10 UTC (rev 119)
@@ -54,7 +54,7 @@
final StringBuffer sb = new StringBuffer();
public void traverse(Object obj) {
sb.append(((Throwable) obj));
- sb.append(LoggerUtil.LINE_SEPERATOR);
+ sb.append(ReporterUtil.LINE_SEPERATOR);
}
}
}
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-18 16:00:59 UTC (rev 118)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-18 17:45:10 UTC (rev 119)
@@ -39,7 +39,7 @@
sb.append(Messages.getString("logger.01")); //$NON-NLS-1$
sb.append(" "); //$NON-NLS-1$
sb.append(clazz.getName());
- sb.append(LoggerUtil.LINE_SEPERATOR);
+ sb.append(ReporterUtil.LINE_SEPERATOR);
log(sb.toString(), Level.INFO);
}
@@ -52,7 +52,7 @@
StringBuffer sb = new StringBuffer();
sb.append(Messages.getString("logger.06")); //$NON-NLS-1$
sb.append(suite.getClass().getName());
- sb.append(LoggerUtil.LINE_SEPERATOR);
+ sb.append(ReporterUtil.LINE_SEPERATOR);
log(sb.toString(), Level.INFO);
}
@@ -61,7 +61,7 @@
}
public void onClassStart(Class clazz) {
- log(clazz.getName() + LoggerUtil.LINE_SEPERATOR, Level.INFO);
+ log(clazz.getName() + ReporterUtil.LINE_SEPERATOR, Level.INFO);
}
public void onClassEnd(Class clazz) {
@@ -69,7 +69,7 @@
}
public void onMethodStart(Method method, Object instance, Object[] params) {
- log(LoggerUtil.simpleMethodName(method, params), Level.INFO);
+ log(ReporterUtil.simpleMethodName(method, params), Level.INFO);
}
public void onMethodEnd(Method method, Object instance, Object[] params, Throwable t) {
@@ -115,11 +115,11 @@
}
public void logln(Level level) {
- log(LoggerUtil.LINE_SEPERATOR, level);
+ log(ReporterUtil.LINE_SEPERATOR, level);
}
public void logln(String message, Level level) {
- log(message + LoggerUtil.LINE_SEPERATOR, level);
+ log(message + ReporterUtil.LINE_SEPERATOR, level);
}
public void log(String message, Level level) {
@@ -170,7 +170,7 @@
}
sb.append(") "); //$NON-NLS-1$
sb.append(_timeWatcher.stringValue());
- sb.append(LoggerUtil.LINE_SEPERATOR);
+ sb.append(ReporterUtil.LINE_SEPERATOR);
logger.log(sb.toString(), Level.INFO);
TraverserUtil.traverse(_throwableList.iterator(), new Traverser() {
int count = 0;
Modified: trunk/punit/src/org/punit/reporter/stream/file/FileLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/file/FileLoggerListener.java 2007-05-18 16:00:59 UTC (rev 118)
+++ trunk/punit/src/org/punit/reporter/stream/file/FileLoggerListener.java 2007-05-18 17:45:10 UTC (rev 119)
@@ -9,7 +9,7 @@
public class FileLoggerListener extends StreamLoggerListener {
public void onRunnerStart(Class clazz, Runner runner) {
- String fileName = generateFileName(clazz, runner);
+ String fileName = ReporterUtil.generateFileName(clazz, runner) + ".txt"; //$NON-NLS-1$
try {
PrintStream ps = new PrintStream(fileName);
setOutputStream(ps);
@@ -24,24 +24,6 @@
_ps.close();
}
- private String generateFileName(Class clazz, Runner runner) {
- RunnerProperties properties = runner.properties();
- StringBuffer sb = new StringBuffer();
- sb.append(IOUtil.getCurrentPath());
- sb.append(File.separator);
- sb.append(RunnerConstants.RESULT_FOLDER);
- sb.append(File.separator);
- sb.append(clazz.getName());
- sb.append("."); //$NON-NLS-1$
- sb.append(runner.punitName());
- if(properties.vmName != null) {
- sb.append("."); //$NON-NLS-1$
- sb.append(properties.vmName);
- }
- sb.append(".txt"); //$NON-NLS-1$
- return sb.toString();
- }
-
public boolean supportParentRunner() {
return false;
}
Deleted: trunk/punit/src/org/punit/util/LoggerUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/LoggerUtil.java 2007-05-18 16:00:59 UTC (rev 118)
+++ trunk/punit/src/org/punit/util/LoggerUtil.java 2007-05-18 17:45:10 UTC (rev 119)
@@ -1,36 +0,0 @@
-package org.punit.util;
-
-import java.lang.reflect.*;
-
-public class LoggerUtil {
- public final static String LINE_SEPERATOR;
-
- static {
- LINE_SEPERATOR = System.getProperty("line.separator"); //$NON-NLS-1$
- }
-
- public static String simpleMethodName(Method method) {
- Class[] params = method.getParameterTypes();
- String[] paramsNames = new String[params.length];
- for(int i = 0; i < params.length; ++i) {
- paramsNames[i] = params[i].getSimpleName();
- }
- return simpleMethodName(method, paramsNames);
- }
-
- public static String simpleMethodName(Method method, Object[] params) {
- StringBuffer sb = new StringBuffer();
- sb.append(method.getName());
- sb.append("("); //$NON-NLS-1$
- for(int i = 0; i < params.length - 1 ; ++i) {
- sb.append(params[i]);
- sb.append(", "); //$NON-NLS-1$
- }
- if(params.length > 0) {
- sb.append(params[params.length - 1]);
- }
- sb.append(")"); //$NON-NLS-1$
- return sb.toString();
- }
-
-}
Copied: trunk/punit/src/org/punit/util/ReporterUtil.java (from rev 101, trunk/punit/src/org/punit/util/LoggerUtil.java)
===================================================================
--- trunk/punit/src/org/punit/util/ReporterUtil.java (rev 0)
+++ trunk/punit/src/org/punit/util/ReporterUtil.java 2007-05-18 17:45:10 UTC (rev 119)
@@ -0,0 +1,56 @@
+package org.punit.util;
+
+import java.io.*;
+import java.lang.reflect.*;
+
+import org.punit.runner.*;
+
+public class ReporterUtil {
+ public final static String LINE_SEPERATOR;
+
+ static {
+ LINE_SEPERATOR = System.getProperty("line.separator"); //$NON-NLS-1$
+ }
+
+ public static String simpleMethodName(Method method) {
+ Class[] params = method.getParameterTypes();
+ String[] paramsNames = new String[params.length];
+ for(int i = 0; i < params.length; ++i) {
+ paramsNames[i] = params[i].getSimpleName();
+ }
+ return simpleMethodName(method, paramsNames);
+ }
+
+ public static String simpleMethodName(Method method, Object[] params) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(method.getName());
+ sb.append("("); //$NON-NLS-1$
+ for(int i = 0; i < params.length - 1 ; ++i) {
+ sb.append(params[i]);
+ sb.append(", "); //$NON-NLS-1$
+ }
+ if(params.length > 0) {
+ sb.append(params[params.length - 1]);
+ }
+ sb.append(")"); //$NON-NLS-1$
+ return sb.toString();
+ }
+
+ public static String generateFileName(Class clazz, Runner runner) {
+ RunnerProperties properties = runner.properties();
+ StringBuffer sb = new StringBuffer();
+ sb.append(IOUtil.getCurrentPath());
+ sb.append(File.separator);
+ sb.append(RunnerConstants.RESULT_FOLDER);
+ sb.append(File.separator);
+ sb.append(clazz.getName());
+ sb.append("."); //$NON-NLS-1$
+ sb.append(runner.punitName());
+ if(properties.vmName != null) {
+ sb.append("."); //$NON-NLS-1$
+ sb.append(properties.vmName);
+ }
+ return sb.toString();
+ }
+
+}
Modified: trunk/punit/src/punit.properties
===================================================================
--- trunk/punit/src/punit.properties 2007-05-18 16:00:59 UTC (rev 118)
+++ trunk/punit/src/punit.properties 2007-05-18 17:45:10 UTC (rev 119)
@@ -15,4 +15,6 @@
watcher.03=memory
watcher.04=time
reporter.01=result
-reporter.02=overview
\ No newline at end of file
+reporter.02=overview
+PDFRender.01=PUnit result\n
+PDFRender.02=the open source performance benchmark framework\n
Modified: trunk/punit.extension/.classpath
===================================================================
--- trunk/punit.extension/.classpath 2007-05-18 16:00:59 UTC (rev 118)
+++ trunk/punit.extension/.classpath 2007-05-18 17:45:10 UTC (rev 119)
@@ -5,5 +5,6 @@
<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="bin" kind="output"/>
</classpath>
Added: trunk/punit.extension/lib/itext-2.0.2.jar
===================================================================
(Binary files differ)
Property changes on: trunk/punit.extension/lib/itext-2.0.2.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2007-05-18 16:00:59 UTC (rev 118)
+++ trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2007-05-18 17:45:10 UTC (rev 119)
@@ -47,12 +47,15 @@
}
double value = watcher.value();
String yname = _currentInstance.getClass().getSimpleName();
- String xname = LoggerUtil.simpleMethodName(_currentMethod, _currentParams);
+ 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()) {
+ _render.onRunnerStart(clazz, runner);
+ }
}
public void onRunnerEnd(final Class clazz, final Runner runner) {
@@ -65,6 +68,9 @@
storeDataset(dataset, fileName, key);
}
});
+ if(!isIntermediate()) {
+ _render.onRunnerEnd(clazz, runner);
+ }
}
private DefaultCategoryDataset getDataset(final Runner runner, DatasetKey key) {
Added: trunk/punit.extension/src/org/punit/reporter/chart/pdf/PDFConstants.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/pdf/PDFConstants.java (rev 0)
+++ trunk/punit.extension/src/org/punit/reporter/chart/pdf/PDFConstants.java 2007-05-18 17:45:10 UTC (rev 119)
@@ -0,0 +1,22 @@
+package org.punit.reporter.chart.pdf;
+
+import com.lowagie.text.*;
+
+public class PDFConstants {
+ public static final Font H1_FONT = FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD);
+
+ public static final Font H2_FONT = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
+
+ public static final Font BIG_FONT = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD);
+
+ public static final Font SMALL_FONT = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.DEFAULTSIZE);
+
+ public static final int DEFAULT_HEIGHT = 500;
+
+ public static final int DEFAULT_WIDTH = 500;
+
+ static final String WEBSITE = "https://sourceforge.net/projects/p-unit/"; //$NON-NLS-1$
+
+ static final String POSTFIX = ".pdf"; //$NON-NLS-1$
+
+}
Modified: trunk/punit.extension/src/org/punit/reporter/chart/pdf/PDFRender.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/pdf/PDFRender.java 2007-05-18 16:00:59 UTC (rev 118)
+++ trunk/punit.extension/src/org/punit/reporter/chart/pdf/PDFRender.java 2007-05-18 17:45:10 UTC (rev 119)
@@ -1,19 +1,95 @@
package org.punit.reporter.chart.pdf;
+import java.awt.*;
+import java.awt.Rectangle;
+import java.io.*;
+
import org.jfree.chart.*;
+import org.punit.exception.*;
+import org.punit.message.*;
import org.punit.reporter.chart.*;
import org.punit.runner.*;
+import org.punit.util.*;
+import com.lowagie.text.*;
+import com.lowagie.text.pdf.*;
+
public class PDFRender implements ChartRender {
+
+ private int _height;
+
+ private int _width;
+
+ private transient Document _document;
+
+ private transient PdfWriter _writer;
+
+ public PDFRender() {
+ this(PDFConstants.DEFAULT_HEIGHT, PDFConstants.DEFAULT_WIDTH);
+ }
+
+ public PDFRender(int height, int width) {
+ _height = height;
+ _width = width;
+ }
+
+ public void onRunnerStart(Class clazz, Runner runner) {
+ String fileName = ReporterUtil.generateFileName(clazz, runner)
+ + PDFConstants.POSTFIX;
+ initPDFDocument(fileName);
+ renderPreface();
+ }
+
+ private void initPDFDocument(String fileName) {
+ _document = new Document();
+ try {
+ _writer = PdfWriter.getInstance(_document, new FileOutputStream(
+ fileName));
+ } catch (Exception e) {
+ throw new PUnitIOException(e);
+ }
+ _document.open();
+ }
+
public void renderChart(JFreeChart chart, String prefixFileName) {
- throw new UnsupportedOperationException();
+ PdfTemplate template = _writer.getDirectContent().createTemplate(_width, _height);
+ Graphics2D graphics = template.createGraphics(_width, _height, new DefaultFontMapper());
+ Rectangle area = new Rectangle(0, 0, _width, _height);
+ chart.draw(graphics, area);
+ graphics.dispose();
+ try {
+ _document.add(new ImgTemplate(template));
+ } catch (BadElementException e) {
+ throw new PUnitIOException(e);
+ } catch (DocumentException e) {
+ throw new PUnitIOException(e);
+ }
+ _document.newPage();
}
public void onRunnerEnd(Class clazz, Runner runner) {
- throw new UnsupportedOperationException();
+ _document.close();
+ _writer.close();
}
- public void onRunnerStart(Class clazz, Runner runner) {
- throw new UnsupportedOperationException();
+ private void renderPreface() {
+ Paragraph paragraph = new Paragraph();
+ paragraph.add(new Chunk(Messages.getString("PDFRender.01"), PDFConstants.H1_FONT)); //$NON-NLS-1$
+ paragraph.add(new Chunk("\n\n\n", PDFConstants.H1_FONT)); //$NON-NLS-1$
+ paragraph.add(new Chunk(Messages.getString("PDFRender.02"), PDFConstants.H1_FONT));//$NON-NLS-1$
+ paragraph.add(new Chunk("\n\n\n", PDFConstants.H1_FONT)); //$NON-NLS-1$
+ paragraph.add(url(PDFConstants.WEBSITE));
+ try {
+ _document.add(paragraph);
+ } catch (DocumentException e) {
+ throw new PUnitIOException(e);
+ }
+ _document.newPage();
}
+
+ private Element url(String url) {
+ Anchor anchor = new Anchor(new Chunk(url));
+ anchor.setReference(url);
+ return anchor;
+ }
}
Modified: trunk/punit.test/src/extension/tests/samples/TestSuiteVMsSample.java
===================================================================
--- trunk/punit.test/src/extension/tests/samples/TestSuiteVMsSample.java 2007-05-18 16:00:59 UTC (rev 118)
+++ trunk/punit.test/src/extension/tests/samples/TestSuiteVMsSample.java 2007-05-18 17:45:10 UTC (rev 119)
@@ -4,6 +4,7 @@
import org.punit.reporter.chart.*;
import org.punit.reporter.chart.image.*;
+import org.punit.reporter.chart.pdf.*;
import org.punit.runner.*;
import org.punit.type.*;
import org.punit.util.*;
@@ -28,7 +29,7 @@
VM harmonyIBMVM = new VM(HARMONY_IBMVME, "HarmonyIBM"); //$NON-NLS-1$
VM sunVM = new VM(SUN, "SUN"); //$NON-NLS-1$
PUnitSoloRunner runner = new PUnitSoloRunner();
- runner.addPUnitEventListener(new TestSuiteReporter(new ImageRender()));
+ runner.addPUnitEventListener(new TestSuiteReporter(new PDFRender()));
runner.runVMs(TestSuite2.class, new VM[] { harmonyVM, sunVM });
}
@@ -56,6 +57,7 @@
sb.append("D:\\tools\\eclipse3.2\\plugins\\org.junit_3.8.1\\junit.jar;"); //$NON-NLS-1$
sb.append("D:\\workspace_3.2\\punit.extension\\lib\\jcommon-1.0.9.jar;"); //$NON-NLS-1$
sb.append("D:\\workspace_3.2\\punit.extension\\lib\\jfreechart-1.0.5.jar;"); //$NON-NLS-1$
+ sb.append("D:\\workspace_3.2\\punit.extension\\lib\\itext-2.0.2.jar;"); //$NON-NLS-1$
return sb.toString();
}
Modified: trunk/punit.test/src/tests/api/org/punit/exception/ConcurrentExceptionTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/exception/ConcurrentExceptionTest.java 2007-05-18 16:00:59 UTC (rev 118)
+++ trunk/punit.test/src/tests/api/org/punit/exception/ConcurrentExceptionTest.java 2007-05-18 17:45:10 UTC (rev 119)
@@ -13,6 +13,6 @@
IllegalArgumentException iae = new IllegalArgumentException("IAE"); //$NON-NLS-1$
concurrentException.add(iae);
String message = concurrentException.getMessage();
- assertEquals(npe + LoggerUtil.LINE_SEPERATOR + iae + LoggerUtil.LINE_SEPERATOR, message);
+ assertEquals(npe + ReporterUtil.LINE_SEPERATOR + iae + ReporterUtil.LINE_SEPERATOR, message);
}
}
Modified: trunk/punit.test/src/tests/api/org/punit/util/LoggerUtilTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/util/LoggerUtilTest.java 2007-05-18 16:00:59 UTC (rev 118)
+++ trunk/punit.test/src/tests/api/org/punit/util/LoggerUtilTest.java 2007-05-18 17:45:10 UTC (rev 119)
@@ -12,22 +12,22 @@
public void testSimpleMethodName() {
Method method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f", //$NON-NLS-1$
new Class[] {});
- String simpleMethodName = LoggerUtil.simpleMethodName(method);
+ String simpleMethodName = ReporterUtil.simpleMethodName(method);
assertEquals("f()", simpleMethodName); //$NON-NLS-1$
method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f", //$NON-NLS-1$
new Class[] { Parameter.class });
- simpleMethodName = LoggerUtil.simpleMethodName(method);
+ simpleMethodName = ReporterUtil.simpleMethodName(method);
assertEquals("f(Parameter)", simpleMethodName); //$NON-NLS-1$
method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f", //$NON-NLS-1$
new Class[] { int.class });
- simpleMethodName = LoggerUtil.simpleMethodName(method);
+ simpleMethodName = ReporterUtil.simpleMethodName(method);
assertEquals("f(int)", simpleMethodName); //$NON-NLS-1$
method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f", //$NON-NLS-1$
new Class[] { int[].class });
- simpleMethodName = LoggerUtil.simpleMethodName(method);
+ simpleMethodName = ReporterUtil.simpleMethodName(method);
assertEquals("f(int[])", simpleMethodName); //$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-19 08:23:03
|
Revision: 125
http://p-unit.svn.sourceforge.net/p-unit/?rev=125&view=rev
Author: zhanghuangzhu
Date: 2007-05-19 01:23:03 -0700 (Sat, 19 May 2007)
Log Message:
-----------
Andrew Zhang: javadoc and refactored watchers.
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/src/org/punit/runner/method/TestMethodRunner.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-19 08:03:15 UTC (rev 124)
+++ trunk/punit/src/org/punit/events/PUnitEventListener.java 2007-05-19 08:23:03 UTC (rev 125)
@@ -4,6 +4,7 @@
import java.io.*;
import java.lang.reflect.*;
+import java.util.*;
import org.punit.runner.*;
import org.punit.type.*;
@@ -74,12 +75,12 @@
/**
* It is triggered before all watchers start.
*/
- public void onWatchersStart(Watcher[] watchers);
+ public void onWatchersStart(List watchers);
/**
* It is triggered after all watchers stop.
*/
- public void onWatchersEnd(Watcher[] watchers);
+ public void onWatchersEnd(List watchers);
/**
* It is triggered before this watcher starts.
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-19 08:03:15 UTC (rev 124)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-19 08:23:03 UTC (rev 125)
@@ -81,14 +81,14 @@
}
}
- public void onWatchersStart(Watcher[] watchers) {
+ public void onWatchersStart(List watchers) {
_watchersStart = true;
}
public void onWatcherStart(Watcher watcher) {
}
- public void onWatchersEnd(Watcher[] watchers) {
+ public void onWatchersEnd(List watchers) {
log("]", Level.FINE); //$NON-NLS-1$
}
Modified: trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-19 08:03:15 UTC (rev 124)
+++ trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-19 08:23:03 UTC (rev 125)
@@ -12,7 +12,7 @@
public abstract class AbstractTestMethodRunner implements TestMethodRunner {
- protected Watcher[] _watchers;
+ protected List _watchers = new ArrayList(); // <Watcher>
protected Object _testInstance;
@@ -27,15 +27,28 @@
protected Method _setUpMethod;
private Runner _runner;
+
+ private MemoryWatcher _memoryWatcher = new MemoryWatcher();
+
+ private TimeWatcher _timeWatcher = new TimeWatcher();
public AbstractTestMethodRunner() {
- _watchers = new Watcher[] { new MemoryWatcher(), new TimeWatcher() };
+ _watchers.add(_memoryWatcher);
+ _watchers.add(_timeWatcher);
}
- public void setWatchers(Watcher[] watchers) {
- _watchers = watchers;
+ public void addWatcher(Watcher watcher) {
+ _watchers.add(watcher);
}
+ public void removeTimeWatcher() {
+ _watchers.remove(_timeWatcher);
+ }
+
+ public void removeMemoryWatcher() {
+ _watchers.remove(_memoryWatcher);
+ }
+
public void setRunner(Runner runner) {
_runner = runner;
}
@@ -170,10 +183,13 @@
protected final void startWatchers(final Object testInstance, final Method method, final Object[] params) {
onWatchersStart(testInstance, method, params);
- for (int i = 0; i < _watchers.length; ++i) {
- onWatcherStart(_watchers[i], testInstance, method, params);
- _watchers[i].start();
- }
+ 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) {
@@ -192,11 +208,14 @@
});
}
- protected final void stopWatchers(Object testInstance, Method method, Object[] params) {
- for (int i = 0; i < _watchers.length; ++i) {
- _watchers[i].stop();
- onWatcherEnd(_watchers[i], testInstance, method, 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;
+ watcher.stop();
+ onWatcherEnd(watcher, testInstance, method, params);
+ }
+ });
onWatchersEnd(testInstance, method, params);
}
@@ -220,7 +239,7 @@
return _runner.eventListeners();
}
- public Watcher[] watchers() {
+ 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-19 08:03:15 UTC (rev 124)
+++ trunk/punit/src/org/punit/runner/method/TestMethodRunner.java 2007-05-19 08:23:03 UTC (rev 125)
@@ -2,9 +2,9 @@
import java.io.*;
import java.lang.reflect.*;
+import java.util.*;
import org.punit.runner.*;
-import org.punit.watcher.*;
public interface TestMethodRunner extends Serializable{
/**
@@ -22,5 +22,5 @@
* returns the watchers associated with this method runner.
* @return
*/
- public Watcher[] watchers();
+ public List watchers();
}
Modified: trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2007-05-19 08:03:15 UTC (rev 124)
+++ trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2007-05-19 08:23:03 UTC (rev 125)
@@ -205,11 +205,11 @@
// nothing needs to do
}
- public void onWatchersStart(Watcher[] watchers) {
+ public void onWatchersStart(List watchers) {
// nothing needs to do
}
- public void onWatchersEnd(Watcher[] watchers) {
+ public void onWatchersEnd(List watchers) {
// nothing needs to do
}
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-19 08:03:15 UTC (rev 124)
+++ trunk/punit.test/src/tests/api/org/punit/runner/MockPUnitEventListener.java 2007-05-19 08:23:03 UTC (rev 125)
@@ -1,6 +1,7 @@
package tests.api.org.punit.runner;
import java.lang.reflect.*;
+import java.util.*;
import junit.framework.*;
@@ -56,11 +57,11 @@
onWatcherStart = true;
}
- public void onWatchersEnd(Watcher[] watchers) {
+ public void onWatchersEnd(List watchers) {
onWatchersEnd = true;
}
- public void onWatchersStart(Watcher[] watchers) {
+ public void onWatchersStart(List watchers) {
onWatchersStart = 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 22:20:20
|
Revision: 158
http://p-unit.svn.sourceforge.net/p-unit/?rev=158&view=rev
Author: zhanghuangzhu
Date: 2007-05-24 15:20:21 -0700 (Thu, 24 May 2007)
Log Message:
-----------
Andrew Zhang: Now it supports to run test case with executor pool!!!
Modified Paths:
--------------
trunk/punit/src/org/punit/exception/PUnitException.java
trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/StreamReaderThread.java
trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
trunk/punit.samples/src/samples/RunnerSamples.java
trunk/punit.samples/src/samples/vms/ListVMTest.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
Added Paths:
-----------
trunk/punit/src/org/punit/runner/ExecutorPool.java
trunk/punit.extension/src/org/punit/runner/
trunk/punit.extension/src/org/punit/runner/PUnitExecutorPool.java
trunk/punit.samples/src/samples/MultiThreadRunnerSample.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitExecutorPoolTest.java
Modified: trunk/punit/src/org/punit/exception/PUnitException.java
===================================================================
--- trunk/punit/src/org/punit/exception/PUnitException.java 2007-05-24 19:59:58 UTC (rev 157)
+++ trunk/punit/src/org/punit/exception/PUnitException.java 2007-05-24 22:20:21 UTC (rev 158)
@@ -1,3 +1,5 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
package org.punit.exception;
/**
Modified: trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java 2007-05-24 19:59:58 UTC (rev 157)
+++ trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java 2007-05-24 22:20:21 UTC (rev 158)
@@ -12,7 +12,8 @@
private void readObject(java.io.ObjectInputStream in) throws IOException,
ClassNotFoundException {
- _outStream = System.err;
+ _outStream = System.out;
+ _errStream = System.err;
}
public ConsoleLogger() {
Added: trunk/punit/src/org/punit/runner/ExecutorPool.java
===================================================================
--- trunk/punit/src/org/punit/runner/ExecutorPool.java (rev 0)
+++ trunk/punit/src/org/punit/runner/ExecutorPool.java 2007-05-24 22:20:21 UTC (rev 158)
@@ -0,0 +1,11 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.runner;
+
+import java.io.*;
+
+public interface ExecutorPool extends Serializable {
+ public void execute(Runnable task);
+ public void start();
+ public void join();
+}
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-24 19:59:58 UTC (rev 157)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-24 22:20:21 UTC (rev 158)
@@ -1,3 +1,5 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
package org.punit.runner;
import java.io.*;
@@ -21,13 +23,14 @@
private TestMethodRunner _testMethodRunner;
- private final List _eventListeners = new ArrayList(); // List
+ // List <PUnitEventListener>
+ private final List _eventListeners = new ArrayList();
- // <PUnitEventListener>
-
private ConsoleLogger _consoleLogger = new ConsoleLogger();
private RunnerProperties _properties = new RunnerProperties();
+
+ private ExecutorPool _executorPool;
public PUnitAbstractRunner(TestSuiteBuilder testSuiteBuiler,
TestMethodBuilder testMethodBuilder,
@@ -49,6 +52,7 @@
}
private void runTestClasses(Object[] testClasses) {
+ startExecutorPool();
for (int i = 0; i < testClasses.length; ++i) {
Object testClass = testClasses[i];
if (isTestSuiteLabel(testClass)) {
@@ -57,8 +61,25 @@
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);
@@ -94,11 +115,11 @@
}
private void readOutputStream(Process p) {
- new StreamReaderThread(p.getInputStream()).start();
+ new StreamReaderThread(p.getInputStream(), false).start();
}
private void readErrorStream(Process p) {
- new StreamReaderThread(p.getErrorStream()).start();
+ new StreamReaderThread(p.getErrorStream(), true).start();
}
private void filterNonParentEventListeners() {
@@ -185,6 +206,27 @@
}
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() {
+ runTestClassImpl(_clazz);
+ }
+
+ }
+
+ private void runTestClassImpl(final Class clazz) {
onClassStart(clazz);
Collection testMethods = buildTestMethod(clazz);
TraverserUtil.traverse(testMethods.iterator(), new Traverser() {
@@ -232,16 +274,17 @@
Parameterizable pInstance = (Parameterizable) testInstance;
Parameter[] params = pInstance.parameters();
for (int i = 0; i < params.length; ++i) {
- runTestMethod(testInstance, method, new Object[] { params[i] });
+ runTestMethod(testInstance, method, new Object[] { params[i] });
}
} else {
runTestMethod(testInstance, method, new Object[] {});
}
}
- private void runTestMethod(Object testInstance, Method method, Object[] params) {
+ private void runTestMethod(Object testInstance, Method method,
+ Object[] params) {
_testMethodRunner.run(testInstance, method, params);
- }
+ }
private Collection buildTestMethod(Class testClass) {
return _testMethodBuilder.buildTestMethods(testClass);
Modified: trunk/punit/src/org/punit/runner/StreamReaderThread.java
===================================================================
--- trunk/punit/src/org/punit/runner/StreamReaderThread.java 2007-05-24 19:59:58 UTC (rev 157)
+++ trunk/punit/src/org/punit/runner/StreamReaderThread.java 2007-05-24 22:20:21 UTC (rev 158)
@@ -4,9 +4,11 @@
class StreamReaderThread extends Thread {
private InputStream _is;
+ private PrintStream _ps;
- public StreamReaderThread(InputStream is) {
+ public StreamReaderThread(InputStream is, boolean errStream) {
_is = is;
+ _ps = errStream ? System.err : System.out;
}
public void run() {
@@ -19,7 +21,7 @@
if(string == null) {
break;
}
- System.err.println(string);
+ _ps.println(string);
}
} catch (IOException e) {
}
Modified: trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2007-05-24 19:59:58 UTC (rev 157)
+++ trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2007-05-24 22:20:21 UTC (rev 158)
@@ -195,6 +195,24 @@
return (PUnitTestSuite) _currentSuiteStack.getLast();
}
+ 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
+ }
+ });
+ }
+
public void onWatcherStart(Watcher watcher) {
// nothing needs to do
}
@@ -216,22 +234,4 @@
// nothing needs to do
}
- 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
- }
- });
- }
-
}
Added: trunk/punit.extension/src/org/punit/runner/PUnitExecutorPool.java
===================================================================
--- trunk/punit.extension/src/org/punit/runner/PUnitExecutorPool.java (rev 0)
+++ trunk/punit.extension/src/org/punit/runner/PUnitExecutorPool.java 2007-05-24 22:20:21 UTC (rev 158)
@@ -0,0 +1,40 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.runner;
+
+import java.util.concurrent.*;
+import org.punit.exception.*;
+
+public class PUnitExecutorPool implements ExecutorPool {
+
+ private static final long serialVersionUID = 642472113631919417L;
+
+ private int _threadCount;
+
+ private transient ExecutorService _pool;
+
+ public PUnitExecutorPool(int count) {
+ if (count < 1) {
+ throw new IllegalArgumentException();
+ }
+ _threadCount = count;
+ }
+
+ public void execute(Runnable task) {
+ _pool.execute(task);
+ }
+
+ public void join() {
+ try {
+ _pool.shutdown();
+ _pool.awaitTermination(Integer.MAX_VALUE, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ throw new PUnitIOException(e);
+ }
+ }
+
+ public void start() {
+ _pool = Executors.newFixedThreadPool(_threadCount);
+ }
+
+}
Added: trunk/punit.samples/src/samples/MultiThreadRunnerSample.java
===================================================================
--- trunk/punit.samples/src/samples/MultiThreadRunnerSample.java (rev 0)
+++ trunk/punit.samples/src/samples/MultiThreadRunnerSample.java 2007-05-24 22:20:21 UTC (rev 158)
@@ -0,0 +1,21 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+package samples;
+
+import org.punit.runner.*;
+
+public class MultiThreadRunnerSample {
+ public static void main(String[] args) {
+ /*
+ * Users can use either PUnitSoloRunner or PUnitConcurrentRunner to run
+ * any test classes and test suites. The reporters can be configured by
+ * runner.addPUnitEventListener, including
+ * Console(default)/File/Image/PDF.
+ *
+ * The result can be found in ./result/ folder.
+ */
+ PUnitSoloRunner runner = new PUnitSoloRunner();
+ // runner = new PUnitConcurrentRunner();
+ runner.setExecutorPool(new PUnitExecutorPool(10));
+ runner.run(AllTestSuite.class);
+ }
+}
Modified: trunk/punit.samples/src/samples/RunnerSamples.java
===================================================================
--- trunk/punit.samples/src/samples/RunnerSamples.java 2007-05-24 19:59:58 UTC (rev 157)
+++ trunk/punit.samples/src/samples/RunnerSamples.java 2007-05-24 22:20:21 UTC (rev 158)
@@ -17,8 +17,9 @@
*
* The result can be found in ./result/ folder.
*/
- Runner runner = new PUnitSoloRunner();
+ PUnitSoloRunner runner = new PUnitSoloRunner();
// runner = new PUnitConcurrentRunner();
+ runner.setExecutorPool(new PUnitExecutorPool(5));
runner.addPUnitEventListener(new FileLogger());
runner.addPUnitEventListener(new OverviewReporter(new ImageRender()));
runner.addPUnitEventListener(new OverviewReporter(new PDFRender()));
Modified: trunk/punit.samples/src/samples/vms/ListVMTest.java
===================================================================
--- trunk/punit.samples/src/samples/vms/ListVMTest.java 2007-05-24 19:59:58 UTC (rev 157)
+++ trunk/punit.samples/src/samples/vms/ListVMTest.java 2007-05-24 22:20:21 UTC (rev 158)
@@ -4,6 +4,7 @@
import org.punit.reporter.chart.*;
import org.punit.reporter.chart.image.*;
+import org.punit.reporter.stream.file.*;
import org.punit.runner.*;
import org.punit.type.*;
@@ -15,6 +16,8 @@
*/
public static void main(String[] args) {
PUnitSoloRunner runner = new PUnitSoloRunner();
+// runner.setExecutorPool(new PUnitExecutorPool(5));
+ runner.addPUnitEventListener(new FileLogger());
runner.addPUnitEventListener(new OverviewReporter(new ImageRender()));
runner.runVMs(ListTestClass.class, new VM[] { VMConfig.IBMVME, VMConfig.SUNVM });
}
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-24 19:59:58 UTC (rev 157)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-24 22:20:21 UTC (rev 158)
@@ -33,7 +33,8 @@
PUnitAbstractTestMethodBuilderTest.class,
PUnitConcurrentRunnerTest.class,
PUnitStreamListenerTest.class,
- extension.tests.api.org.punit.runner.PUnitSoloRunnerTest.class,
+ PUnitExecutorPoolTest.class,
+ extension.tests.api.org.punit.runner.PUnitSoloRunnerTest.class,
PUnitSoloRunnerTest.class,
PUnitTestMethodBuilderTest.class,
PUnitTestSuiteBuilderTest.class,
Added: trunk/punit.test/src/tests/api/org/punit/runner/PUnitExecutorPoolTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitExecutorPoolTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitExecutorPoolTest.java 2007-05-24 22:20:21 UTC (rev 158)
@@ -0,0 +1,50 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.runner;
+
+import org.punit.runner.*;
+
+import tests.util.*;
+
+import junit.framework.*;
+
+public class PUnitExecutorPoolTest extends TestCase {
+
+ private PUnitExecutorPool _pool = new PUnitExecutorPool(5);
+
+ public void testCtor() {
+ AssertUtil.assertException(IllegalArgumentException.class,
+ new CodeRunner() {
+ public void run() throws Throwable {
+ new PUnitExecutorPool(0);
+ }
+ });
+ }
+
+ public void testStartJoin() {
+ _pool.start();
+ _pool.join();
+ }
+
+ public void testExecute() {
+ _pool.start();
+ RunnableTask task = new RunnableTask();
+ _pool.execute(task);
+ _pool.join();
+ task.assertExecuted();
+ }
+
+ static class RunnableTask implements Runnable {
+
+ private boolean _executed;
+
+ public void run() {
+ _executed = true;
+ }
+
+ public void assertExecuted() {
+ assertTrue(_executed);
+ }
+
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-25 13:06:19
|
Revision: 159
http://p-unit.svn.sourceforge.net/p-unit/?rev=159&view=rev
Author: zhanghuangzhu
Date: 2007-05-25 06:06:21 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Andrew Zhang: fixed a test problem.
Modified Paths:
--------------
trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
trunk/punit.test/src/tests/api/org/punit/reporter/stream/PUnitStreamListenerTest.java
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-24 22:20:21 UTC (rev 158)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-25 13:06:21 UTC (rev 159)
@@ -124,9 +124,13 @@
_errStream = err;
}
- public PrintStream printStream() {
+ public PrintStream outPrintStream() {
return _outStream;
}
+
+ public PrintStream errPrintStream() {
+ return _errStream;
+ }
public void logln(Level level) {
log(ReporterUtil.LINE_SEPERATOR, level);
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 22:20:21 UTC (rev 158)
+++ trunk/punit.test/src/tests/api/org/punit/reporter/stream/PUnitStreamListenerTest.java 2007-05-25 13:06:21 UTC (rev 159)
@@ -42,7 +42,8 @@
public void testSerializable() throws Exception {
ConsoleLogger logger = (ConsoleLogger) TestUtil.getSerialiableObject(_logger);
- assertSame(System.err, logger.printStream());
+ assertSame(System.out, logger.outPrintStream());
+ assertSame(System.err, logger.errPrintStream());
}
private void assertPrinted() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-29 06:33:32
|
Revision: 167
http://p-unit.svn.sourceforge.net/p-unit/?rev=167&view=rev
Author: zhanghuangzhu
Date: 2007-05-28 23:33:34 -0700 (Mon, 28 May 2007)
Log Message:
-----------
Andrew Zhang: check method is supported in ConcurrentMethodRunner.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java
trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentTestClass.java
Modified: trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java 2007-05-27 09:30:31 UTC (rev 166)
+++ trunk/punit/src/org/punit/runner/method/ConcurrentMethodRunner.java 2007-05-29 06:33:34 UTC (rev 167)
@@ -2,6 +2,8 @@
package org.punit.runner.method;
+import java.lang.reflect.*;
+
import org.punit.exception.*;
import org.punit.type.*;
import org.punit.util.*;
@@ -10,12 +12,14 @@
private static final long serialVersionUID = 6423244395038097893L;
- private transient TestMethodThread[] _threads;
-
private ConcurrentException _concurrentException = new ConcurrentException();
private int _concurrentCount;
+ private transient TestMethodThread[] _threads;
+
+ private transient Method _checkMethod;
+
public ConcurrentMethodRunner(int concurrentCount) {
_concurrentCount = concurrentCount;
}
@@ -26,8 +30,15 @@
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);
}
@@ -58,7 +69,13 @@
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() {
+ return "check_" + _method.getName(); //$NON-NLS-1$
+ }
private class TestMethodThread extends Thread {
ConcurrentMethodRunner _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-05-27 09:30:31 UTC (rev 166)
+++ trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2007-05-29 06:33:34 UTC (rev 167)
@@ -72,6 +72,8 @@
private void assertConcurrentTestClassRun() {
ConcurrentTestClass test = new ConcurrentTestClass();
assertEquals(test.concurrentCount(), ConcurrentTestClass.value);
+ assertTrue(ConcurrentTestClass._assertCheck1);
+ assertTrue(ConcurrentTestClass._assertCheck2);
}
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentTestClass.java 2007-05-27 09:30:31 UTC (rev 166)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentTestClass.java 2007-05-29 06:33:34 UTC (rev 167)
@@ -6,10 +6,16 @@
public class ConcurrentTestClass 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() {
@@ -21,6 +27,14 @@
TestUtil.doSomething();
}
+ public void check_test1() {
+ _assertCheck1 = true;
+ }
+
+ public void check_test2() {
+ _assertCheck2 = true;
+ }
+
public int concurrentCount() {
return 5;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-29 07:17:24
|
Revision: 168
http://p-unit.svn.sourceforge.net/p-unit/?rev=168&view=rev
Author: zhanghuangzhu
Date: 2007-05-29 00:17:23 -0700 (Tue, 29 May 2007)
Log Message:
-----------
Andrew Zhang: p-unit its own Assert methods.
Modified Paths:
--------------
trunk/punit/src/org/punit/util/TypeUtil.java
trunk/punit/src/punit.properties
trunk/punit.test/src/extension/tests/api/org/punit/reporter/chart/AbstractChartReporterTest.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/runner/ExecutorPoolTest.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/util/AssertUtil.java
Added Paths:
-----------
trunk/punit/src/org/punit/assertion/
trunk/punit/src/org/punit/assertion/Assert.java
trunk/punit/src/org/punit/assertion/CodeRunner.java
trunk/punit.test/src/tests/api/org/punit/assertion/
trunk/punit.test/src/tests/api/org/punit/assertion/AssertTest.java
Removed Paths:
-------------
trunk/punit.test/src/tests/util/CodeRunner.java
Added: trunk/punit/src/org/punit/assertion/Assert.java
===================================================================
--- trunk/punit/src/org/punit/assertion/Assert.java (rev 0)
+++ trunk/punit/src/org/punit/assertion/Assert.java 2007-05-29 07:17:23 UTC (rev 168)
@@ -0,0 +1,53 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.assertion;
+
+import org.punit.message.*;
+
+public class Assert {
+
+ public static void assertSame(Object expected, Object actual) {
+ if (expected != actual) {
+ fail(expected, actual);
+ }
+ }
+
+ public static void assertEquals(Object expected, Object actual) {
+ if (!expected.equals(actual)) {
+ fail(expected, actual);
+ }
+ }
+
+ 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 assertException(Class throwable, CodeRunner code) {
+ try {
+ code.run();
+ fail(throwable, null);
+ } catch (Throwable e) {
+ assertSame(throwable, e.getClass());
+ }
+ }
+
+ 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$
+ }
+}
Added: trunk/punit/src/org/punit/assertion/CodeRunner.java
===================================================================
--- trunk/punit/src/org/punit/assertion/CodeRunner.java (rev 0)
+++ trunk/punit/src/org/punit/assertion/CodeRunner.java 2007-05-29 07:17:23 UTC (rev 168)
@@ -0,0 +1,7 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.assertion;
+
+public interface CodeRunner {
+ public void run() throws Throwable;
+}
\ No newline at end of file
Modified: trunk/punit/src/org/punit/util/TypeUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/TypeUtil.java 2007-05-29 06:33:34 UTC (rev 167)
+++ trunk/punit/src/org/punit/util/TypeUtil.java 2007-05-29 07:17:23 UTC (rev 168)
@@ -1,3 +1,5 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
package org.punit.util;
import org.punit.type.*;
Modified: trunk/punit/src/punit.properties
===================================================================
--- trunk/punit/src/punit.properties 2007-05-29 06:33:34 UTC (rev 167)
+++ trunk/punit/src/punit.properties 2007-05-29 07:17:23 UTC (rev 168)
@@ -18,3 +18,5 @@
reporter.02=overview
PDFRender.01=PUnit result\n
PDFRender.02=the open source performance benchmark framework\n
+Assert.0=Excepted
+Assert.1=, but
Modified: trunk/punit.test/src/extension/tests/api/org/punit/reporter/chart/AbstractChartReporterTest.java
===================================================================
--- trunk/punit.test/src/extension/tests/api/org/punit/reporter/chart/AbstractChartReporterTest.java 2007-05-29 06:33:34 UTC (rev 167)
+++ trunk/punit.test/src/extension/tests/api/org/punit/reporter/chart/AbstractChartReporterTest.java 2007-05-29 07:17:23 UTC (rev 168)
@@ -1,13 +1,11 @@
package extension.tests.api.org.punit.reporter.chart;
-import java.io.*;
import java.util.*;
import junit.framework.*;
-import org.jfree.chart.*;
+import org.punit.assertion.*;
import org.punit.reporter.chart.*;
-import org.punit.reporter.chart.image.*;
import org.punit.type.*;
import org.punit.watcher.*;
@@ -34,6 +32,8 @@
}
static class MockChartReporter extends AbstractChartReporter {
+ private static final long serialVersionUID = 1L;
+
MockChartReporter() {
super(null);
}
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-29 06:33:34 UTC (rev 167)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-29 07:17:23 UTC (rev 168)
@@ -1,6 +1,7 @@
package tests.api.org.punit.all;
import junit.framework.*;
+import tests.api.org.punit.assertion.*;
import tests.api.org.punit.builder.*;
import tests.api.org.punit.exception.*;
import tests.api.org.punit.reporter.stream.*;
@@ -28,6 +29,7 @@
AbstractChartReporterTest.class,
AbstractRunnerTest.class,
AbstractTestMethodRunnerTest.class,
+ AssertTest.class,
ConcurrentExceptionTest.class,
LoggerUtilTest.class,
MemoryWatcherTest.class,
Added: trunk/punit.test/src/tests/api/org/punit/assertion/AssertTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/assertion/AssertTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/assertion/AssertTest.java 2007-05-29 07:17:23 UTC (rev 168)
@@ -0,0 +1,66 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.assertion;
+
+import junit.framework.*;
+
+import org.punit.assertion.*;
+import org.punit.assertion.Assert;
+
+public class AssertTest extends TestCase {
+ public void testAssertSame() {
+ Object o1 = new Object();
+ Assert.assertSame(o1, o1);
+ Object o2 = new Object();
+ try {
+ Assert.assertSame(o1, o2);
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+
+ public void testAssertEqual() {
+ String s1 = new String("1"); //$NON-NLS-1$
+ String s2 = new String("1"); //$NON-NLS-1$
+ String s3 = new String("3"); //$NON-NLS-1$
+ Assert.assertEquals(s1, s2);
+ try {
+ Assert.assertEquals(s1, s3);
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+
+ public void testFail() {
+ try {
+ Assert.fail();
+ } catch (AssertionError e) {
+ // expected
+ }
+
+ try {
+ Assert.fail("fail"); //$NON-NLS-1$
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+
+ public void testAssertException() {
+ Assert.assertException(NullPointerException.class, new CodeRunner() {
+ public void run() throws Throwable {
+ throw new NullPointerException();
+ }
+ });
+
+ try {
+ Assert.assertException(IllegalArgumentException.class,
+ new CodeRunner() {
+ public void run() throws Throwable {
+ throw new NullPointerException();
+ }
+ });
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+}
Modified: trunk/punit.test/src/tests/api/org/punit/runner/ExecutorPoolTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/ExecutorPoolTest.java 2007-05-29 06:33:34 UTC (rev 167)
+++ trunk/punit.test/src/tests/api/org/punit/runner/ExecutorPoolTest.java 2007-05-29 07:17:23 UTC (rev 168)
@@ -2,6 +2,7 @@
package tests.api.org.punit.runner;
+import org.punit.assertion.*;
import org.punit.runner.*;
import tests.util.*;
Modified: trunk/punit.test/src/tests/api/org/punit/util/IOUtilTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/util/IOUtilTest.java 2007-05-29 06:33:34 UTC (rev 167)
+++ trunk/punit.test/src/tests/api/org/punit/util/IOUtilTest.java 2007-05-29 07:17:23 UTC (rev 168)
@@ -2,6 +2,7 @@
import java.io.*;
+import org.punit.assertion.*;
import org.punit.exception.*;
import org.punit.util.*;
Modified: trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java 2007-05-29 06:33:34 UTC (rev 167)
+++ trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java 2007-05-29 07:17:23 UTC (rev 168)
@@ -4,6 +4,7 @@
import junit.framework.*;
+import org.punit.assertion.*;
import org.punit.exception.*;
import org.punit.util.*;
Modified: trunk/punit.test/src/tests/util/AssertUtil.java
===================================================================
--- trunk/punit.test/src/tests/util/AssertUtil.java 2007-05-29 06:33:34 UTC (rev 167)
+++ trunk/punit.test/src/tests/util/AssertUtil.java 2007-05-29 07:17:23 UTC (rev 168)
@@ -2,8 +2,10 @@
import java.util.*;
-import junit.framework.*;
+import org.punit.assertion.*;
+import org.punit.assertion.Assert;
+
public class AssertUtil {
public static void assertArray(Object[] array1, Object[] array2) {
Deleted: trunk/punit.test/src/tests/util/CodeRunner.java
===================================================================
--- trunk/punit.test/src/tests/util/CodeRunner.java 2007-05-29 06:33:34 UTC (rev 167)
+++ trunk/punit.test/src/tests/util/CodeRunner.java 2007-05-29 07:17:23 UTC (rev 168)
@@ -1,5 +0,0 @@
-package tests.util;
-
-public interface CodeRunner {
- public void run() throws Throwable;
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-29 15:09:42
|
Revision: 169
http://p-unit.svn.sourceforge.net/p-unit/?rev=169&view=rev
Author: zhanghuangzhu
Date: 2007-05-29 08:09:43 -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.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 07:17:23 UTC (rev 168)
+++ trunk/punit/src/org/punit/assertion/Assert.java 2007-05-29 15:09:43 UTC (rev 169)
@@ -17,6 +17,30 @@
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) {
@@ -30,6 +54,18 @@
}
}
+ 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) {
try {
code.run();
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 07:17:23 UTC (rev 168)
+++ trunk/punit.test/src/tests/api/org/punit/assertion/AssertTest.java 2007-05-29 15:09:43 UTC (rev 169)
@@ -19,7 +19,7 @@
}
}
- public void testAssertEqual() {
+ public void testAssertEquals() {
String s1 = new String("1"); //$NON-NLS-1$
String s2 = new String("1"); //$NON-NLS-1$
String s3 = new String("3"); //$NON-NLS-1$
@@ -31,6 +31,56 @@
}
}
+ public void testAssertEqualsII() {
+ Assert.assertEquals(1, 1);
+ try {
+ Assert.assertEquals(1, 2);
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+
+ public void testAssertEqualsJJ() {
+ Assert.assertEquals(1l, 1l);
+ try {
+ Assert.assertEquals(1l, 2l);
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+
+ public void testAssertEqualsDD() {
+ Assert.assertEquals(1.0, 1.0);
+ Assert.assertEquals(1.0, 2.0, 1.0);
+ try {
+ Assert.assertEquals(1.0, 2.0);
+ } catch (AssertionError e) {
+ // expected
+ }
+
+ try {
+ Assert.assertEquals(1.0, 2.0, 0.9);
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+
+ public void testAssertEqualsFF() {
+ Assert.assertEquals(1.0f, 1.0f);
+ Assert.assertEquals(1.0f, 2.0f, 1.0f);
+ try {
+ Assert.assertEquals(1.0f, 2.0f);
+ } catch (AssertionError e) {
+ // expected
+ }
+
+ try {
+ Assert.assertEquals(1.0f, 2.0f, 0.9f);
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+
public void testFail() {
try {
Assert.fail();
@@ -63,4 +113,22 @@
// expected
}
}
+
+ public void testAssertNull() {
+ Assert.assertNull(null);
+ try {
+ Assert.assertNull(new Object());
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+
+ public void testAssertNotNull() {
+ Assert.assertNotNull(new Object());
+ try {
+ Assert.assertNotNull(null);
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
}
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:27:21
|
Revision: 190
http://p-unit.svn.sourceforge.net/p-unit/?rev=190&view=rev
Author: zhanghuangzhu
Date: 2007-06-03 23:27:22 -0700 (Sun, 03 Jun 2007)
Log Message:
-----------
Andrew Zhang: Added class exclude annotation
Modified Paths:
--------------
trunk/punit/src/org/punit/method/MethodFilter.java
trunk/punit/src/org/punit/method/NameMethodFilter.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/annotation/Test.java
trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java
trunk/punit.test/src/tests/api/org/punit/method/AnnotationMethodFilterTest.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/MethodFilter.java
===================================================================
--- trunk/punit/src/org/punit/method/MethodFilter.java 2007-06-04 06:04:31 UTC (rev 189)
+++ trunk/punit/src/org/punit/method/MethodFilter.java 2007-06-04 06:27:22 UTC (rev 190)
@@ -1,3 +1,5 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
package org.punit.method;
import java.io.*;
@@ -4,11 +6,18 @@
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 the test modifier, name, and parameter conform to
- * the convention of a test method.
+ * @return returns true if it is a test method.
*/
public boolean isTestMethod(Method method);
Modified: trunk/punit/src/org/punit/method/NameMethodFilter.java
===================================================================
--- trunk/punit/src/org/punit/method/NameMethodFilter.java 2007-06-04 06:04:31 UTC (rev 189)
+++ trunk/punit/src/org/punit/method/NameMethodFilter.java 2007-06-04 06:27:22 UTC (rev 190)
@@ -1,3 +1,5 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
package org.punit.method;
import java.lang.reflect.*;
@@ -9,6 +11,10 @@
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(),
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-04 06:04:31 UTC (rev 189)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-04 06:27:22 UTC (rev 190)
@@ -41,10 +41,11 @@
_methodRunner.setEventListeners(_eventListeners);
_methodRunner.setRunnerProperties(_properties);
registerLoggerListeners();
- setMethodFilter(new NameMethodFilter());
+ setFilter(new NameMethodFilter());
}
- public void setMethodFilter(MethodFilter filter) {
+ public void setFilter(MethodFilter 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:04:31 UTC (rev 189)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-04 06:27:22 UTC (rev 190)
@@ -4,6 +4,8 @@
import java.io.*;
+import org.punit.method.*;
+
/**
* Interface for test suite builder.
* @see TestSuiteLabel
@@ -17,4 +19,6 @@
* @return
*/
public Object[] buildTestClasses(Class testSutie);
+
+ public void setFilter(MethodFilter filter);
}
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-04 06:04:31 UTC (rev 189)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-04 06:27:22 UTC (rev 190)
@@ -4,13 +4,20 @@
import java.util.*;
+import org.punit.method.*;
import org.punit.type.*;
import org.punit.util.*;
public class TestSuiteBuilderImpl implements TestSuiteBuilder {
- private static final long serialVersionUID = 633363267326297920L;
+ private static final long serialVersionUID = -4468961881014123138L;
+
+ private MethodFilter _filter;
+ public void setFilter(MethodFilter filter) {
+ _filter = filter;
+ }
+
/**
* @see TestSuiteBuilder#buildTestClasses(Class)
*/
@@ -29,6 +36,9 @@
}
private void buildTestClassFromTestSuite(List testClasses, Class clazz) {
+ if(_filter.isExcluded(clazz)) {
+ return;
+ }
PUnitTestSuite testSuite = (PUnitTestSuite) ReflectionUtil.newInstance(clazz);
testClasses.add(new TestSuiteLabelImpl(testSuite, true));
Class[] suite = testSuite.testSuite();
@@ -39,6 +49,9 @@
}
private void buildTestClassesFromClass(List testClasses, Class clazz) {
+ if(_filter.isExcluded(clazz)) {
+ return;
+ }
testClasses.add(clazz);
}
Modified: trunk/punit.extension/src/org/punit/annotation/Test.java
===================================================================
--- trunk/punit.extension/src/org/punit/annotation/Test.java 2007-06-04 06:04:31 UTC (rev 189)
+++ trunk/punit.extension/src/org/punit/annotation/Test.java 2007-06-04 06:27:22 UTC (rev 190)
@@ -5,12 +5,13 @@
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
public @interface Test {
Class<? extends Throwable> expected() default NoException.class;
String checkMethod() default "";
+
+ boolean excluded() default false;
public class NoException extends Throwable {
private static final long serialVersionUID = 3987745685001380514L;
Modified: trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java 2007-06-04 06:04:31 UTC (rev 189)
+++ trunk/punit.extension/src/org/punit/method/AnnotationMethodFilter.java 2007-06-04 06:27:22 UTC (rev 190)
@@ -25,6 +25,15 @@
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);
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:04:31 UTC (rev 189)
+++ trunk/punit.test/src/tests/api/org/punit/method/AnnotationMethodFilterTest.java 2007-06-04 06:27:22 UTC (rev 190)
@@ -13,6 +13,12 @@
public class AnnotationMethodFilterTest extends TestCase {
AnnotationMethodFilter _filter = new AnnotationMethodFilter();
+ 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$
@@ -41,7 +47,7 @@
}
public void testGetExpectedException() {
- Method method, checkMethod;
+ Method method;
Class exception;
method = ReflectionUtil.getMethod(getClass(), "_test1", new Class[] {}); //$NON-NLS-1$
@@ -78,4 +84,14 @@
public void check__test3() {
}
+
+ @Test(excluded = true)
+ static class ExcludedClass {
+
+ }
+
+ @Test(excluded = false)
+ static class NonExcludedClass {
+
+ }
}
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:04:31 UTC (rev 189)
+++ trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2007-06-04 06:27:22 UTC (rev 190)
@@ -41,7 +41,7 @@
public void testRunAnnotationTest() {
AnnotationTestClass.reset();
- _runner.setMethodFilter(new AnnotationMethodFilter());
+ _runner.setFilter(new AnnotationMethodFilter());
_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:04:31 UTC (rev 189)
+++ trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2007-06-04 06:27:22 UTC (rev 190)
@@ -37,7 +37,7 @@
public void testRunAnnotationTest() {
AnnotationTestClass.reset();
- _runner.setMethodFilter(new AnnotationMethodFilter());
+ _runner.setFilter(new AnnotationMethodFilter());
_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:04:31 UTC (rev 189)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-06-04 06:27:22 UTC (rev 190)
@@ -10,7 +10,7 @@
public static void main(String[] args) {
SoloRunner soloRunner = new SoloRunner();
- soloRunner.setMethodFilter(new AnnotationMethodFilter());
+ soloRunner.setFilter(new AnnotationMethodFilter());
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-14 15:21:07
|
Revision: 207
http://p-unit.svn.sourceforge.net/p-unit/?rev=207&view=rev
Author: zhanghuangzhu
Date: 2007-06-14 08:21:09 -0700 (Thu, 14 Jun 2007)
Log Message:
-----------
Andrew Zhang: refactored filter to convention.
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/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.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/JUnitAnnotationTestClass.java
Added Paths:
-----------
trunk/punit/src/org/punit/convention/
trunk/punit/src/org/punit/convention/Convention.java
trunk/punit/src/org/punit/convention/NameConvention.java
trunk/punit.extension/src/org/punit/convention/
trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java
trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java
trunk/punit.test/src/tests/api/org/punit/convention/
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
Removed Paths:
-------------
trunk/punit/src/org/punit/convention/Filter.java
trunk/punit/src/org/punit/convention/NameConventionFilter.java
trunk/punit/src/org/punit/filter/
trunk/punit.extension/src/org/punit/convention/AnnotationFilter.java
trunk/punit.extension/src/org/punit/convention/JUnitAnnotationFilter.java
trunk/punit.extension/src/org/punit/filter/
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/filter/
Copied: trunk/punit/src/org/punit/convention (from rev 203, trunk/punit/src/org/punit/filter)
Copied: trunk/punit/src/org/punit/convention/Convention.java (from rev 206, trunk/punit/src/org/punit/filter/Convention.java)
===================================================================
--- trunk/punit/src/org/punit/convention/Convention.java (rev 0)
+++ trunk/punit/src/org/punit/convention/Convention.java 2007-06-14 15:21:09 UTC (rev 207)
@@ -0,0 +1,46 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.convention;
+
+import java.io.*;
+import java.lang.reflect.*;
+
+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);
+
+ /**
+ * 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/convention/Filter.java
===================================================================
--- trunk/punit/src/org/punit/filter/Filter.java 2007-06-14 13:53:58 UTC (rev 203)
+++ trunk/punit/src/org/punit/convention/Filter.java 2007-06-14 15:21:09 UTC (rev 207)
@@ -1,46 +0,0 @@
-/* (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/convention/NameConvention.java (from rev 206, trunk/punit/src/org/punit/filter/NameConvention.java)
===================================================================
--- trunk/punit/src/org/punit/convention/NameConvention.java (rev 0)
+++ trunk/punit/src/org/punit/convention/NameConvention.java 2007-06-14 15:21:09 UTC (rev 207)
@@ -0,0 +1,124 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.convention;
+
+import java.lang.reflect.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class NameConvention implements Convention {
+
+ 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) {
+ 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 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$
+ }
+
+
+}
Deleted: trunk/punit/src/org/punit/convention/NameConventionFilter.java
===================================================================
--- trunk/punit/src/org/punit/filter/NameConventionFilter.java 2007-06-14 13:53:58 UTC (rev 203)
+++ trunk/punit/src/org/punit/convention/NameConventionFilter.java 2007-06-14 15:21:09 UTC (rev 207)
@@ -1,117 +0,0 @@
-/* (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 15:16:45 UTC (rev 206)
+++ trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-06-14 15:21:09 UTC (rev 207)
@@ -5,7 +5,7 @@
import java.lang.reflect.*;
import java.util.*;
-import org.punit.filter.*;
+import org.punit.convention.*;
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 15:16:45 UTC (rev 206)
+++ trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-06-14 15:21:09 UTC (rev 207)
@@ -5,7 +5,7 @@
import java.io.*;
import java.util.*;
-import org.punit.filter.*;
+import org.punit.convention.*;
/**
* Interface for test method builder. The method builder builds a list of
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-14 15:16:45 UTC (rev 206)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-14 15:21:09 UTC (rev 207)
@@ -6,9 +6,9 @@
import java.util.*;
import org.punit.assertion.*;
+import org.punit.convention.*;
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 15:16:45 UTC (rev 206)
+++ trunk/punit/src/org/punit/method/runner/MethodRunner.java 2007-06-14 15:21:09 UTC (rev 207)
@@ -4,7 +4,7 @@
import java.lang.reflect.*;
import java.util.*;
-import org.punit.filter.*;
+import org.punit.convention.*;
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 15:16:45 UTC (rev 206)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-14 15:21:09 UTC (rev 207)
@@ -6,9 +6,9 @@
import java.lang.reflect.*;
import java.util.*;
+import org.punit.convention.*;
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.*;
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-14 15:16:45 UTC (rev 206)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-14 15:21:09 UTC (rev 207)
@@ -4,7 +4,7 @@
import java.io.*;
-import org.punit.filter.*;
+import org.punit.convention.*;
/**
* 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 15:16:45 UTC (rev 206)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-14 15:21:09 UTC (rev 207)
@@ -4,7 +4,7 @@
import java.util.*;
-import org.punit.filter.*;
+import org.punit.convention.*;
import org.punit.type.*;
import org.punit.util.*;
Copied: trunk/punit.extension/src/org/punit/convention (from rev 203, trunk/punit.extension/src/org/punit/filter)
Copied: trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java (from rev 206, trunk/punit.extension/src/org/punit/filter/AnnotationConvention.java)
===================================================================
--- trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java (rev 0)
+++ trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java 2007-06-14 15:21:09 UTC (rev 207)
@@ -0,0 +1,112 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.convention;
+
+import java.lang.reflect.*;
+
+import org.punit.annotation.*;
+import org.punit.annotation.Test.*;
+import org.punit.convention.*;
+import org.punit.util.*;
+
+public class AnnotationConvention implements Convention {
+
+ private static final long serialVersionUID = -2043378593194849589L;
+
+ private NameConvention _delegate = new NameConvention();
+
+ 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/convention/AnnotationFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/filter/AnnotationFilter.java 2007-06-14 13:53:58 UTC (rev 203)
+++ trunk/punit.extension/src/org/punit/convention/AnnotationFilter.java 2007-06-14 15:21:09 UTC (rev 207)
@@ -1,112 +0,0 @@
-/* (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/convention/JUnitAnnotationConvention.java (from rev 206, trunk/punit.extension/src/org/punit/filter/JUnitAnnotationConvention.java)
===================================================================
--- trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java (rev 0)
+++ trunk/punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java 2007-06-14 15:21:09 UTC (rev 207)
@@ -0,0 +1,86 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.convention;
+
+import java.lang.reflect.*;
+
+import org.junit.*;
+import org.punit.annotation.Test.*;
+import org.punit.convention.*;
+import org.punit.util.*;
+
+public class JUnitAnnotationConvention implements Convention {
+
+ private static final long serialVersionUID = 2826000346348614825L;
+
+ private NameConvention _delegate = new NameConvention();
+
+ 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/convention/JUnitAnnotationFilter.java
===================================================================
--- trunk/punit.extension/src/org/punit/filter/JUnitAnnotationFilter.java 2007-06-14 13:53:58 UTC (rev 203)
+++ trunk/punit.extension/src/org/punit/convention/JUnitAnnotationFilter.java 2007-06-14 15:21:09 UTC (rev 207)
@@ -1,86 +0,0 @@
-/* (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;
- }
-}
Modified: trunk/punit.test/sr...
[truncated message content] |
|
From: <zha...@us...> - 2007-06-15 04:48:39
|
Revision: 211
http://p-unit.svn.sourceforge.net/p-unit/?rev=211&view=rev
Author: zhanghuangzhu
Date: 2007-06-14 21:48:40 -0700 (Thu, 14 Jun 2007)
Log Message:
-----------
Andrew Zhang: refactored setFilter to setConvention.
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/ConcurrentMethodRunner.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/suite/builder/TestSuiteBuilderTest.java
Modified: trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-06-15 04:42:00 UTC (rev 210)
+++ trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2007-06-15 04:48:40 UTC (rev 211)
@@ -15,12 +15,12 @@
*/
public class MethodBuilderImpl implements TestMethodBuilder {
- private static final long serialVersionUID = -6593981780599574964L;
+ private static final long serialVersionUID = -7839703149112306751L;
- private Convention _filter;
+ private Convention _convention;
- public void setMethodFilter(Convention filter) {
- _filter = filter;
+ public void setConvention(Convention convention) {
+ _convention = convention;
}
/**
@@ -30,7 +30,7 @@
* @return
*/
protected boolean isTestMethod(Method method) {
- return _filter.isTestMethod(method);
+ return _convention.isTestMethod(method);
}
/**
Modified: trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-06-15 04:42:00 UTC (rev 210)
+++ trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2007-06-15 04:48:40 UTC (rev 211)
@@ -24,5 +24,5 @@
public Collection buildTestMethods(Class testClass);
- public void setMethodFilter(Convention filter);
+ public void setConvention(Convention convention);
}
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-15 04:42:00 UTC (rev 210)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-06-15 04:48:40 UTC (rev 211)
@@ -24,7 +24,7 @@
private RunnerProperties _runnerProperties;
- protected Convention _filter;
+ protected Convention _convention;
protected transient Object _testInstance;
@@ -137,10 +137,10 @@
_class = testInstance.getClass();
_params = params;
_method = method;
- _setUpMethod = _filter.getSetupMethod(_class);
- _tearDownMethod = _filter.getTearDownMethod(_class);
- _checkMethod = _filter.getCheckMethod(method);
- _expectedException = _filter.getExpectedException(method);
+ _setUpMethod = _convention.getSetupMethod(_class);
+ _tearDownMethod = _convention.getTearDownMethod(_class);
+ _checkMethod = _convention.getCheckMethod(method);
+ _expectedException = _convention.getExpectedException(method);
}
/**
@@ -301,8 +301,8 @@
}
}
- public void setMethodFilter(Convention filter) {
- _filter = filter;
+ public void setConvention(Convention convention) {
+ _convention = convention;
}
protected void runMethod() throws Throwable {
Modified: trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2007-06-15 04:42:00 UTC (rev 210)
+++ trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2007-06-15 04:48:40 UTC (rev 211)
@@ -49,11 +49,11 @@
private void initThreads() {
int threadCount = _concurrentCount;
- int count = _filter.getConcurrentCount(_testInstance);
+ int count = _convention.getConcurrentCount(_testInstance);
if(count > 0) {
threadCount = count;
}
- count = _filter.getConcurrentCount(_method);
+ count = _convention.getConcurrentCount(_method);
if(count > 0) {
threadCount = count;
}
Modified: trunk/punit/src/org/punit/method/runner/MethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/MethodRunner.java 2007-06-15 04:42:00 UTC (rev 210)
+++ trunk/punit/src/org/punit/method/runner/MethodRunner.java 2007-06-15 04:48:40 UTC (rev 211)
@@ -38,5 +38,5 @@
public Object clone();
- public void setMethodFilter(Convention filter);
+ public void setConvention(Convention convention);
}
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-15 04:42:00 UTC (rev 210)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2007-06-15 04:48:40 UTC (rev 211)
@@ -33,7 +33,7 @@
private ExecutorPool _executorPool;
- private Convention _filter;
+ private Convention _convention;
public AbstractRunner(TestSuiteBuilder testSuiteBuiler,
TestMethodBuilder testMethodBuilder, MethodRunner testMethodRunner) {
@@ -46,11 +46,11 @@
setConvention(new NameConvention());
}
- public void setConvention(Convention filter) {
- _filter = filter;
- _testSuiteBuiler.setFilter(filter);
- _testMethodBuilder.setMethodFilter(filter);
- _methodRunner.setMethodFilter(filter);
+ public void setConvention(Convention convention) {
+ _convention = convention;
+ _testSuiteBuiler.setConvention(convention);
+ _testMethodBuilder.setConvention(convention);
+ _methodRunner.setConvention(convention);
}
public void run(Class clazz) {
@@ -259,14 +259,14 @@
}
private void beforeClass(Class clazz) {
- Method beforeClassMethod = _filter.getBeforeClassMethod(clazz);
+ Method beforeClassMethod = _convention.getBeforeClassMethod(clazz);
if(beforeClassMethod != null) {
ReflectionUtil.invokeMethod(beforeClassMethod, null, new Object[] {});
}
}
private void afterClass(Class clazz) {
- Method afterClassMethod = _filter.getAfterClassMethod(clazz);
+ Method afterClassMethod = _convention.getAfterClassMethod(clazz);
if(afterClassMethod != null) {
ReflectionUtil.invokeMethod(afterClassMethod, null, new Object[] {});
}
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-15 04:42:00 UTC (rev 210)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2007-06-15 04:48:40 UTC (rev 211)
@@ -20,5 +20,5 @@
*/
public Object[] buildTestClasses(Class testSutie);
- public void setFilter(Convention filter);
+ public void setConvention(Convention convention);
}
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-15 04:42:00 UTC (rev 210)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2007-06-15 04:48:40 UTC (rev 211)
@@ -14,7 +14,7 @@
private Convention _filter;
- public void setFilter(Convention filter) {
+ public void setConvention(Convention filter) {
_filter = filter;
}
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-15 04:42:00 UTC (rev 210)
+++ trunk/punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java 2007-06-15 04:48:40 UTC (rev 211)
@@ -14,7 +14,7 @@
protected void setUp() throws Exception {
_builder = new MethodBuilderImpl();
- _builder.setMethodFilter(new NameConvention());
+ _builder.setConvention(new NameConvention());
}
public void testBuildTestMethods1() {
Modified: trunk/punit.test/src/tests/api/org/punit/suite/builder/TestSuiteBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/suite/builder/TestSuiteBuilderTest.java 2007-06-15 04:42:00 UTC (rev 210)
+++ trunk/punit.test/src/tests/api/org/punit/suite/builder/TestSuiteBuilderTest.java 2007-06-15 04:48:40 UTC (rev 211)
@@ -14,11 +14,11 @@
protected void setUp() throws Exception {
_testSuiteBuidler = new TestSuiteBuilderImpl();
- _testSuiteBuidler.setFilter(new NameConvention());
+ _testSuiteBuidler.setConvention(new NameConvention());
}
public void testBuildExcludedTestClasses1() {
- _testSuiteBuidler.setFilter(new AnnotationConvention());
+ _testSuiteBuidler.setConvention(new AnnotationConvention());
Object[] classes = _testSuiteBuidler.buildTestClasses(ExcludedTestClass1.class);
AssertUtil.assertArray(classes, new Class[] { });
}
@@ -73,7 +73,7 @@
}
public void testBuildTestSuite2ByAnnotationFilter() {
- _testSuiteBuidler.setFilter(new AnnotationConvention());
+ _testSuiteBuidler.setConvention(new AnnotationConvention());
Object[] classes = _testSuiteBuidler.buildTestClasses(TestSuite2.class);
Class[] expectedClasses = new Class[] { TestClass4.class,
TestClass1.class, TestClass2.class, TestClass3.class, TestClass5.class };
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-06-29 02:27:49
|
Revision: 228
http://p-unit.svn.sourceforge.net/p-unit/?rev=228&view=rev
Author: zhanghuangzhu
Date: 2007-06-28 19:27:52 -0700 (Thu, 28 Jun 2007)
Log Message:
-----------
Andrew Zhang: updated the license to Apache License 2.0.
Modified Paths:
--------------
trunk/punit/punit.license.txt
trunk/punit.extension/punit.extension.license.txt
trunk/punit.samples/punit.license.txt
trunk/punit.test/punit.license.txt
Modified: trunk/punit/punit.license.txt
===================================================================
--- trunk/punit/punit.license.txt 2007-06-26 14:09:27 UTC (rev 227)
+++ trunk/punit/punit.license.txt 2007-06-29 02:27:52 UTC (rev 228)
@@ -1,341 +1,203 @@
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
- Preamble
+ 1. Definitions.
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.) You can apply it to
-your programs, too.
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
+ END OF TERMS AND CONDITIONS
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
+ APPENDIX: How to apply the Apache License to your work.
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
+ Copyright [yyyy] [name of copyright owner]
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
+ http://www.apache.org/licenses/LICENSE-2.0
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- <signature of Ty Coon>, 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you...
[truncated message content] |