[P-unit-devel] SF.net SVN: p-unit: [206] trunk/punit
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/org/punit/filter/AnnotationFilterTest.java 2007-06-14 15:12:59 UTC (rev 205)
+++ trunk/punit.test/src/tests/api/org/punit/filter/AnnotationFilterTest.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -13,7 +13,7 @@
import tests.api.org.punit.testclasses.*;
public class AnnotationFilterTest extends TestCase {
- AnnotationFilter _filter = new AnnotationFilter();
+ AnnotationConvention _filter = new AnnotationConvention();
public void testIsExcluded() {
assertTrue(_filter.isExcluded(ExcludedClass.class));
Modified: trunk/punit.test/src/tests/api/org/punit/filter/JUnitAnnotationConventionTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/filter/JUnitAnnotationConventionTest.java 2007-06-14 15:12:59 UTC (rev 205)
+++ trunk/punit.test/src/tests/api/org/punit/filter/JUnitAnnotationConventionTest.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -14,7 +14,7 @@
import tests.api.org.punit.testclasses.*;
public class JUnitAnnotationConventionTest extends TestCase {
- JUnitAnnotationFilter _filter = new JUnitAnnotationFilter();
+ JUnitAnnotationConvention _filter = new JUnitAnnotationConvention();
public void testIsExcluded() {
assertFalse(_filter.isExcluded(ExcludedClass.class));
Modified: trunk/punit.test/src/tests/api/org/punit/filter/NameConventionFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/filter/NameConventionFilterTest.java 2007-06-14 15:12:59 UTC (rev 205)
+++ trunk/punit.test/src/tests/api/org/punit/filter/NameConventionFilterTest.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -13,7 +13,7 @@
public class NameConventionFilterTest extends TestCase {
- NameConventionFilter _filter = new NameConventionFilter();
+ NameConvention _filter = new NameConvention();
public void testIsTestMethod() {
Method method;
Modified: trunk/punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java 2007-06-14 15:12:59 UTC (rev 205)
+++ trunk/punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -14,7 +14,7 @@
protected void setUp() throws Exception {
_builder = new MethodBuilderImpl();
- _builder.setMethodFilter(new NameConventionFilter());
+ _builder.setMethodFilter(new NameConvention());
}
public void testBuildTestMethods1() {
Modified: trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2007-06-14 15:12:59 UTC (rev 205)
+++ trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -41,7 +41,7 @@
public void testRunAnnotationTest() {
AnnotationTestClass.reset();
- _runner.setFilter(new AnnotationFilter());
+ _runner.setFilter(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-14 15:12:59 UTC (rev 205)
+++ trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -37,7 +37,7 @@
public void testRunAnnotationTest() {
AnnotationTestClass.reset();
- _runner.setFilter(new AnnotationFilter());
+ _runner.setFilter(new AnnotationConvention());
_runner.run(AnnotationTestClass.class);
AnnotationTestClass.assertTestClassRun();
}
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-14 15:12:59 UTC (rev 205)
+++ trunk/punit.test/src/tests/api/org/punit/suite/builder/TestSuiteBuilderTest.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -14,11 +14,11 @@
protected void setUp() throws Exception {
_testSuiteBuidler = new TestSuiteBuilderImpl();
- _testSuiteBuidler.setFilter(new NameConventionFilter());
+ _testSuiteBuidler.setFilter(new NameConvention());
}
public void testBuildExcludedTestClasses1() {
- _testSuiteBuidler.setFilter(new AnnotationFilter());
+ _testSuiteBuidler.setFilter(new AnnotationConvention());
Object[] classes = _testSuiteBuidler.buildTestClasses(ExcludedTestClass1.class);
AssertUtil.assertArray(classes, new Class[] { });
}
@@ -73,7 +73,7 @@
}
public void testBuildTestSuite2ByAnnotationFilter() {
- _testSuiteBuidler.setFilter(new AnnotationFilter());
+ _testSuiteBuidler.setFilter(new AnnotationConvention());
Object[] classes = _testSuiteBuidler.buildTestClasses(TestSuite2.class);
Class[] expectedClasses = new Class[] { TestClass4.class,
TestClass1.class, TestClass2.class, TestClass3.class, TestClass5.class };
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-06-14 15:12:59 UTC (rev 205)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -12,7 +12,7 @@
public static void main(String[] args) {
SoloRunner soloRunner = new SoloRunner();
- soloRunner.setFilter(new AnnotationFilter());
+ soloRunner.setFilter(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-14 15:12:59 UTC (rev 205)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/JUnitAnnotationTestClass.java 2007-06-14 15:16:45 UTC (rev 206)
@@ -8,7 +8,7 @@
public static void main(String[] args) {
SoloRunner soloRunner = new SoloRunner();
- soloRunner.setFilter(new AnnotationFilter());
+ soloRunner.setFilter(new AnnotationConvention());
soloRunner.run(JUnitAnnotationTestClass.class);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|