Index: punit/src/org/punit/method/builder/TestMethodBuilder.java =================================================================== --- punit/src/org/punit/method/builder/TestMethodBuilder.java (revision 229) +++ punit/src/org/punit/method/builder/TestMethodBuilder.java (working copy) @@ -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 Collection of java.lang.reflect.Method. + * @param clazz + * the test class to be extract methods from + * @return a Collection of + * java.lang.reflect.Method. */ - public Collection buildTestMethods(Class testClass); + public Collection extractTestMethods(Class testClass); // Collection - public void setConvention(Convention convention); } Index: punit/src/org/punit/method/builder/MethodBuilderImpl.java =================================================================== --- punit/src/org/punit/method/builder/MethodBuilderImpl.java (revision 228) +++ punit/src/org/punit/method/builder/MethodBuilderImpl.java (working copy) @@ -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()); Index: punit/src/org/punit/method/runner/AbstractMethodRunner.java =================================================================== --- punit/src/org/punit/method/runner/AbstractMethodRunner.java (revision 229) +++ punit/src/org/punit/method/runner/AbstractMethodRunner.java (working copy) @@ -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]); } } Index: punit/src/org/punit/type/Test.java =================================================================== --- punit/src/org/punit/type/Test.java (revision 229) +++ punit/src/org/punit/type/Test.java (working copy) @@ -3,7 +3,7 @@ package org.punit.type; /** - * Marks this test as a punit test. It has more setUp/tearDown control than + * Marks this test as a PUnit test. It has more setUp/tearDown control than * normal test class. * */ Index: punit/src/org/punit/type/Parameter.java =================================================================== --- punit/src/org/punit/type/Parameter.java (revision 229) +++ punit/src/org/punit/type/Parameter.java (working copy) @@ -2,13 +2,13 @@ package org.punit.type; -import org.punit.type.Parameterizable; +import org.punit.type.Parameterized; /** - * If a test implements Parameterizable interface, the test + * If a test implements Parameterized interface, the test * method with this interface will be executed. * - * @see Parameterizable + * @see Parameterized * */ public interface Parameter { Index: punit/src/org/punit/type/Parameterizable.java =================================================================== --- punit/src/org/punit/type/Parameterizable.java (revision 228) +++ punit/src/org/punit/type/Parameterizable.java (working copy) @@ -1,52 +0,0 @@ -/* (C) Copyright 2007, by Andrew Zhang */ - -package org.punit.type; - -import org.punit.type.Parameter; - -/** - * If a test implements Parameterizable interface, the test - * method with only a Parameter argument (i.e. - * testFoo(Parameter p)) will be executed. - */ -public interface Parameterizable { - - /** - * This method will be invoked before all watchers start. - * - * @param param - * @throws Exception - */ - public void setUpBeforeWatchers(Parameter param) throws Exception; - - /** - * This method will be invoked after all watchers start. - * - * @param param - * @throws Exception - */ - public void setUpAfterWatchers(Parameter param) throws Exception; - - /** - * This method will be invoked before all watchers stop. - * - * @param param - * @throws Exception - */ - public void tearDownBeforeWatchers(Parameter param) throws Exception; - - /** - * This method will be invoked after all watchers stop. - * - * @param param - * @throws Exception - */ - public void tearDownAfterWatchers(Parameter param) throws Exception; - - /** - * Returns a parameter array for the test. - * - * @return - */ - Parameter[] parameters(); -} Index: punit/src/org/punit/type/Loop.java =================================================================== --- punit/src/org/punit/type/Loop.java (revision 229) +++ punit/src/org/punit/type/Loop.java (working copy) @@ -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(); } Index: punit/src/org/punit/type/Parameterized.java =================================================================== --- punit/src/org/punit/type/Parameterized.java (revision 0) +++ punit/src/org/punit/type/Parameterized.java (revision 0) @@ -0,0 +1,48 @@ +/* (C) Copyright 2007, by Andrew Zhang */ + +package org.punit.type; + +/** + * If a test implements Parameterized interface, the test method + * with only a Parameter argument (i.e. + * testFoo(Parameter p)) will be executed. + */ +public interface Parameterized { + + /** + * Is invoked before all watchers start. + * + * @param param + * @throws Exception + */ + public void setUpBeforeWatchers(Parameter param) throws Exception; + + /** + * Is invoked after all watchers start. + * + * @param param + * @throws Exception + */ + public void setUpAfterWatchers(Parameter param) throws Exception; + + /** + * Is invoked before all watchers stop. + * + * @param param + * @throws Exception + */ + public void tearDownBeforeWatchers(Parameter param) throws Exception; + + /** + * Is invoked after all watchers stop. + * + * @param param + * @throws Exception + */ + public void tearDownAfterWatchers(Parameter param) throws Exception; + + /** + * @return a parameter array for the test + */ + Parameter[] parameters(); +} Index: punit/src/org/punit/convention/Convention.java =================================================================== --- punit/src/org/punit/convention/Convention.java (revision 229) +++ punit/src/org/punit/convention/Convention.java (working copy) @@ -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); } Index: punit/src/org/punit/convention/NameConvention.java =================================================================== --- punit/src/org/punit/convention/NameConvention.java (revision 229) +++ punit/src/org/punit/convention/NameConvention.java (working copy) @@ -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 Parameterizable, or the - * parameter length is 1, and the parameter is assignable from - * Parameter. + * @return true if the number of method parameters is zero + * and the test class is not marked as Parameterized, + * or the parameter length is 1, and the parameter is assignable + * from Parameter. */ 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; - } - - } Index: punit/src/org/punit/convention/AbstractConvention.java =================================================================== --- punit/src/org/punit/convention/AbstractConvention.java (revision 0) +++ punit/src/org/punit/convention/AbstractConvention.java (revision 0) @@ -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: punit/src/org/punit/convention/AbstractConvention.java ___________________________________________________________________ Name: svn:executable + * Index: punit/src/org/punit/reporter/stream/StreamLogger.java =================================================================== --- punit/src/org/punit/reporter/stream/StreamLogger.java (revision 229) +++ punit/src/org/punit/reporter/stream/StreamLogger.java (working copy) @@ -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 Index: punit/src/org/punit/reporter/TestResult.java =================================================================== --- punit/src/org/punit/reporter/TestResult.java (revision 229) +++ punit/src/org/punit/reporter/TestResult.java (working copy) @@ -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 EventListener 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 EventListener 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; } - + } Index: punit/src/org/punit/events/EventListener.java =================================================================== --- punit/src/org/punit/events/EventListener.java (revision 229) +++ punit/src/org/punit/events/EventListener.java (working copy) @@ -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. Index: punit/src/org/punit/runner/AbstractRunner.java =================================================================== --- punit/src/org/punit/runner/AbstractRunner.java (revision 229) +++ punit/src/org/punit/runner/AbstractRunner.java (working copy) @@ -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 - private final List _eventListeners = new ArrayList(); + private final List _eventListeners = new ArrayList(); // List 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; } Index: punit/src/org/punit/suite/builder/TestSuiteLabel.java =================================================================== --- punit/src/org/punit/suite/builder/TestSuiteLabel.java (revision 229) +++ punit/src/org/punit/suite/builder/TestSuiteLabel.java (working copy) @@ -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 true if it represents the start of a test suite. */ public boolean isStart(); } Index: punit/src/org/punit/util/TypeUtil.java =================================================================== --- punit/src/org/punit/util/TypeUtil.java (revision 228) +++ punit/src/org/punit/util/TypeUtil.java (working copy) @@ -1,16 +0,0 @@ -/* (C) Copyright 2007, by Andrew Zhang */ - -package org.punit.util; - -import org.punit.type.*; - -public class TypeUtil { - - public static boolean isPUnitTest(Class clazz) { - return Test.class.isAssignableFrom(clazz); - } - - public static boolean isPUnitParameterizableTest(Class clazz) { - return Parameterizable.class.isAssignableFrom(clazz); - } -} Index: punit/src/org/punit/util/ReflectionUtil.java =================================================================== --- punit/src/org/punit/util/ReflectionUtil.java (revision 228) +++ punit/src/org/punit/util/ReflectionUtil.java (working copy) @@ -2,80 +2,121 @@ package org.punit.util; -import java.lang.reflect.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; -import org.punit.exception.*; +import org.punit.exception.ReflectionException; public class ReflectionUtil { - - public static Object newInstance(Class clazz) { - try { - Constructor constructor = clazz.getDeclaredConstructor(new Class[] {}); - constructor.setAccessible(true); - return constructor.newInstance(new Object [] {}); - } catch (Exception e) { - throw new ReflectionException(e); - } - } - - public static Class newClass(String className) { - try { - return Class.forName(className); - } catch (Exception e) { - throw new ReflectionException(e); - } - } - - public static Method getMethod(Class clazz, String methodName, Class[] params) { - try { - Method method = clazz.getDeclaredMethod(methodName, params); - return method; - } catch (Exception e) { - return null; - } - } - - /** - * Gets the method and sets the accessible to true - * @param clazz - * @param methodName - * @param params - * @return - */ - public static Method getMethodAndSetAccessible(Class clazz, String methodName, Class[] params) { - try { - Method method = clazz.getDeclaredMethod(methodName, params); - method.setAccessible(true); - return method; - } catch (Exception e) { - return null; - } - } - - public static Object invokeMethod(Method method, Object instance, Object[] params) throws ReflectionException { - try { - return method.invoke(instance, params); - } catch (IllegalArgumentException e) { - throw new ReflectionException(e); - } catch (IllegalAccessException e) { - throw new ReflectionException(e); - } catch (InvocationTargetException e) { - throw new ReflectionException(e.getTargetException()); - } - } - - public static boolean isPublic(Method method) { - int modifier = method.getModifiers(); - return isBitSet(modifier, Modifier.PUBLIC); - } - - public static boolean isStatic(Method method) { - int modifier = method.getModifiers(); - return isBitSet(modifier, Modifier.STATIC); - } - - private static boolean isBitSet(int value, int expectedBit) { - return (value & expectedBit) != 0; - - } + + public static Object newInstance(Class clazz) { + try { + Constructor constructor = clazz + .getDeclaredConstructor(new Class[] {}); + constructor.setAccessible(true); + return constructor.newInstance(new Object[] {}); + } catch (Exception e) { + throw new ReflectionException(e); + } + } + + public static Class newClass(String className) { + try { + return Class.forName(className); + } catch (Exception e) { + throw new ReflectionException(e); + } + } + + public static Method getMethod(Class clazz, String methodName, + Class[] params) { + try { + Method method = clazz.getDeclaredMethod(methodName, params); + return method; + } catch (Exception e) { + return null; + } + } + + /** + * Sets a field with a given value after converting the value to the field + * type. + * + * @param field + * the field to assign + * @param value + * the string value to assign + */ + public static void setField(Object testInstance, Field field, String value) { + // System.out.println("Field = " + field + ", value = " + value); + // System.out.println("value = " + Integer.getInteger(value)); + + try { + field.setAccessible(true); + Class fieldClass = field.getType(); + if (fieldClass.equals(int.class)) { + int intVal = Integer.parseInt(value); + field.setInt(testInstance, intVal); + } else if (fieldClass.equals(long.class)) { + long longVal = Long.parseLong(value); + field.setLong(testInstance, longVal); + } else { + field.set(testInstance, value); + } + } catch (NumberFormatException nfe) { + throw new IllegalArgumentException(nfe); + } catch (Exception e) { + throw new ReflectionException(e); + } + } + + /** + * Gets the method and sets the accessible to true + * + * @param clazz + * @param methodName + * @param params + * @return + */ + public static Method getMethodAndSetAccessible(Class clazz, + String methodName, Class[] params) { + try { + Method method = clazz.getDeclaredMethod(methodName, params); + method.setAccessible(true); + return method; + } catch (Exception e) { + return null; + } + } + + public static Object invokeMethod(Method method, Object instance, + Object[] params) throws ReflectionException { + try { + return method.invoke(instance, params); + } catch (IllegalArgumentException e) { + throw new ReflectionException(e); + } catch (IllegalAccessException e) { + throw new ReflectionException(e); + } catch (InvocationTargetException e) { + throw new ReflectionException(e.getTargetException()); + } + } + + public static boolean isPublic(Method method) { + int modifier = method.getModifiers(); + return isBitSet(modifier, Modifier.PUBLIC); + } + + public static boolean isStatic(Method method) { + int modifier = method.getModifiers(); + return isBitSet(modifier, Modifier.STATIC); + } + + private static boolean isBitSet(int value, int expectedBit) { + return (value & expectedBit) != 0; + + } } Index: punit/src/org/punit/util/IntParameter.java =================================================================== --- punit/src/org/punit/util/IntParameter.java (revision 228) +++ punit/src/org/punit/util/IntParameter.java (working copy) @@ -2,22 +2,22 @@ package org.punit.util; -import org.punit.type.*; +import org.punit.type.Parameter; public class IntParameter implements Parameter { - - private int _intValue; - public IntParameter(int value) { - _intValue = value; - } - - public int intValue() { - return _intValue; - } - - public String toString() { - return String.valueOf(_intValue); - } + private int _intValue; + public IntParameter(int value) { + _intValue = value; + } + + public int intValue() { + return _intValue; + } + + public String toString() { + return String.valueOf(_intValue); + } + } Index: punit.samples/src/samples/LoopTestSample.java =================================================================== --- punit.samples/src/samples/LoopTestSample.java (revision 229) +++ punit.samples/src/samples/LoopTestSample.java (working copy) @@ -26,10 +26,6 @@ public void test2() { } - - public long toStop() { - return TIMEOUT; - } public long toWork() { return TIMEOUT; Index: punit.samples/src/samples/ParamTestClass.java =================================================================== --- punit.samples/src/samples/ParamTestClass.java (revision 229) +++ punit.samples/src/samples/ParamTestClass.java (working copy) @@ -4,7 +4,7 @@ import org.punit.type.*; import org.punit.type.Parameter; -public class ParamTestClass implements Parameterizable { +public class ParamTestClass implements Parameterized { public static void main(String[] args) { new SoloRunner().run(ParamTestClass.class); Index: punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java =================================================================== --- punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java (revision 229) +++ punit.extension/src/org/punit/convention/JUnitAnnotationConvention.java (working copy) @@ -2,101 +2,38 @@ package org.punit.convention; -import java.lang.reflect.*; +import java.lang.reflect.Method; -import org.junit.*; -import org.junit.Test.*; -import org.punit.util.*; +import org.junit.Test; -public class JUnitAnnotationConvention implements Convention { - - private static final long serialVersionUID = 2826000346348614825L; - - private NameConvention _delegate = new NameConvention(); +public class JUnitAnnotationConvention extends AnnotationConvention { - public Method getCheckMethod(Method method) { - return _delegate.getCheckMethod(method); + private static final long serialVersionUID = 5775534409608907458L; + + public JUnitAnnotationConvention() { + super(org.junit.After.class, org.junit.AfterClass.class, + org.junit.Before.class, org.junit.BeforeClass.class, + org.junit.Ignore.class, Test.class); } - - @SuppressWarnings("unchecked") - public boolean isExcluded(Class clazz) { - return false; - } - - public boolean isTestMethod(Method method) { - Ignore ignore = (Ignore) method.getAnnotation(Ignore.class); - if(ignore != null) { - return false; - } - Test testAnnotation = getTestAnnotation(method); - return (testAnnotation != null) || _delegate.isTestMethod(method); - } public Class getExpectedException(Method method) { - Test testAnnotation = getTestAnnotation(method); - if(testAnnotation == null) { + Test testAnnotation = (Test) method.getAnnotation(_test); + if (testAnnotation == null) { return null; } Class expected = testAnnotation.expected(); - if(expected == None.class) { + if (expected == Test.None.class) { return null; } return expected; } + public Method getCheckMethod(Method method) { + return _delegate.getCheckMethod(method); + } + public int getConcurrentCount(Object testInstance, Method method) { return _delegate.getConcurrentCount(testInstance, method); } - - private Test getTestAnnotation(Method method) { - return method.getAnnotation(Test.class); - } - @SuppressWarnings("unchecked") - public Method getAfterClassMethod(Class test) { - Method method = AnnotationUtil.getMethodByAnnotation(test, AfterClass.class); - if(method == null) { - method = _delegate.getAfterClassMethod(test); - } - return method; - } - - @SuppressWarnings("unchecked") - public Method getBeforeClassMethod(Class test) { - Method method = AnnotationUtil.getMethodByAnnotation(test, BeforeClass.class); - if(method == null) { - method = _delegate.getBeforeClassMethod(test); - } - return method; - } - - @SuppressWarnings("unchecked") - public Method getSetupMethod(Class test) { - Method method = AnnotationUtil.getMethodByAnnotation(test, Before.class); - if(method == null) { - method = _delegate.getSetupMethod(test); - } - return method; - } - - @SuppressWarnings("unchecked") - public Method getTearDownMethod(Class test) { - Method method = AnnotationUtil.getMethodByAnnotation(test, After.class); - if(method == null) { - method = _delegate.getTearDownMethod(test); - } - return method; - } - - public long toStop(Object testInstance) { - return 0; - } - - public long toWork(Object testInstance) { - return 0; - } - - public boolean isLoopTest(Object testInstance) { - return false; - } } Index: punit.extension/src/org/punit/convention/AnnotationConvention.java =================================================================== --- punit.extension/src/org/punit/convention/AnnotationConvention.java (revision 229) +++ punit.extension/src/org/punit/convention/AnnotationConvention.java (working copy) @@ -2,26 +2,52 @@ package org.punit.convention; +import java.lang.annotation.Annotation; import java.lang.reflect.Method; - -import org.punit.annotation.After; -import org.punit.annotation.AfterClass; -import org.punit.annotation.Before; -import org.punit.annotation.BeforeClass; -import org.punit.annotation.Ignore; import org.punit.annotation.Test; -import org.punit.annotation.Test.NoException; import org.punit.util.AnnotationUtil; import org.punit.util.ReflectionUtil; -public class AnnotationConvention implements Convention { +/** + * The class merges annotation and name conventions with annotations taking + * preference. + */ +public class AnnotationConvention extends AbstractConvention { - private static final long serialVersionUID = -2043378593194849589L; - - private NameConvention _delegate = new NameConvention(); + private static final long serialVersionUID = -6800242731470821241L; + protected NameConvention _delegate = new NameConvention(); + + private Class _after; + private Class _afterClass; + private Class _before; + private Class _beforeClass; + private Class _ignore; + protected Class _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 after, + Class afterClass, + Class before, + Class beforeClass, + Class ignore, Class test) { + _after = after; + _afterClass = afterClass; + _before = before; + _beforeClass = beforeClass; + _ignore = ignore; + _test = test; + } + public Method getCheckMethod(Method method) { - Test testAnnotation = getTestAnnotation(method); + Test testAnnotation = (Test) method.getAnnotation(_test); String checkMethodName = null; if (testAnnotation != null) { checkMethodName = testAnnotation.checkMethod(); @@ -32,60 +58,46 @@ } return _delegate.getCheckMethod(method); } - + @SuppressWarnings("unchecked") public boolean isExcluded(Class clazz) { - Ignore ignore = (Ignore) clazz.getAnnotation(Ignore.class); - if(ignore == null) { - return false; - } - return true; + return clazz.isAnnotationPresent(_ignore); } - + public boolean isTestMethod(Method method) { - Ignore ignore = (Ignore) method.getAnnotation(Ignore.class); - if(ignore != null) { + if (method.isAnnotationPresent(_ignore)) { return false; } - Test testAnnotation = getTestAnnotation(method); - return (testAnnotation != null) || _delegate.isTestMethod(method); + return method.isAnnotationPresent(_test) || _delegate.isTestMethod(method); } public Class getExpectedException(Method method) { - Test testAnnotation = getTestAnnotation(method); - if(testAnnotation == null) { + Test testAnnotation = (Test) method.getAnnotation(_test); + if (testAnnotation == null) { return null; } Class expected = testAnnotation.expected(); - if(expected == NoException.class) { + if (expected == Test.NoException.class) { return null; } return expected; } public int getConcurrentCount(Object testInstance, Method method) { - Test testAnnotation = getTestAnnotation(method); - if(testAnnotation == null) { - testAnnotation = getTestAnnotation(testInstance.getClass()); + Test testAnnotation = (Test) method.getAnnotation(_test); + if (testAnnotation == null) { + testAnnotation = (Test) testInstance.getClass().getAnnotation(_test); } - if(testAnnotation == null) { + if (testAnnotation == null) { return _delegate.getConcurrentCount(testInstance, method); } return testAnnotation.concurrentCount(); } - - private Test getTestAnnotation(Method method) { - return method.getAnnotation(Test.class); - } - - private Test getTestAnnotation(Class clazz) { - return (Test) clazz.getAnnotation(Test.class); - } @SuppressWarnings("unchecked") public Method getAfterClassMethod(Class test) { - Method method = AnnotationUtil.getMethodByAnnotation(test, AfterClass.class); - if(method == null) { + Method method = AnnotationUtil.getMethodByAnnotation(test, _afterClass); + if (method == null) { method = _delegate.getAfterClassMethod(test); } return method; @@ -93,40 +105,30 @@ @SuppressWarnings("unchecked") public Method getBeforeClassMethod(Class test) { - Method method = AnnotationUtil.getMethodByAnnotation(test, BeforeClass.class); - if(method == null) { + 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.class); - if(method == null) { - method = _delegate.getSetupMethod(test); + 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.class); - if(method == null) { + Method method = AnnotationUtil.getMethodByAnnotation(test, _after); + if (method == null) { method = _delegate.getTearDownMethod(test); } return method; } - public long toStop(Object testInstance) { - return 0; - } - - public long toWork(Object testInstance) { - return 0; - } - - public boolean isLoopTest(Object testInstance) { - return false; - } } Index: punit.extension/src/org/punit/reporter/chart/image/ImageRender.java =================================================================== --- punit.extension/src/org/punit/reporter/chart/image/ImageRender.java (revision 229) +++ punit.extension/src/org/punit/reporter/chart/image/ImageRender.java (working copy) @@ -66,11 +66,11 @@ } public void onRunnerStart(Class clazz, Runner runner) { - // nothing needs to do + // nothing needs to be done } public void onRunnerEnd(Class clazz, Runner runner) { - // nothing needs to do + // nothing needs to be done } } Index: punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java =================================================================== --- punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java (revision 229) +++ punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java (working copy) @@ -36,7 +36,7 @@ protected transient RunnerProperties _runnerProperties; - protected transient Class _currentClass; + protected transient Object _testInstance; public AbstractChartReporter(ChartRender render) { _render = render; @@ -180,14 +180,12 @@ return true; } - @SuppressWarnings("unchecked") - public void onClassStart(Class clazz) { - _currentClass = clazz; + public void onClassStart(Object testInstance) { + _testInstance = testInstance; } - @SuppressWarnings("unchecked") - public void onClassEnd(Class clazz) { - _currentClass = null; + public void onClassEnd(Object testInstance, Throwable t) { + _testInstance = null; } public void onSuiteStart(TestSuite suite) { @@ -223,26 +221,26 @@ } public void onWatcherStart(Watcher watcher) { - // nothing needs to do + // nothing needs to be done } public void onWatcherEnd(Watcher watcher) { - // nothing needs to do + // nothing needs to be done } @SuppressWarnings("unchecked") public void onWatchersStart(List watchers) { - // nothing needs to do + // nothing needs to be done } @SuppressWarnings("unchecked") public void onWatchersEnd(List watchers) { - // nothing needs to do + // nothing needs to be done } public void onMethodStart(Method method, Object testInstance, Object[] params) { - // nothing needs to do + // nothing needs to be done } } Index: punit.extension/src/org/punit/reporter/chart/TestClassReporter.java =================================================================== --- punit.extension/src/org/punit/reporter/chart/TestClassReporter.java (revision 229) +++ punit.extension/src/org/punit/reporter/chart/TestClassReporter.java (working copy) @@ -13,7 +13,7 @@ } protected DatasetKey getKey(Watcher watcher) { - return new DatasetKeyImpl(watcher, _currentClass); + return new DatasetKeyImpl(watcher, _testInstance.getClass()); } public static class DatasetKeyImpl implements DatasetKey { Index: punit.extension/src/org/punit/listener/FieldSetter.java =================================================================== --- punit.extension/src/org/punit/listener/FieldSetter.java (revision 0) +++ punit.extension/src/org/punit/listener/FieldSetter.java (revision 0) @@ -0,0 +1,104 @@ +/* (C) Copyright 2007, by Andrew Zhang */ +package org.punit.listener; + +import java.lang.reflect.Method; +import java.util.List; +import java.util.Properties; + +import org.punit.events.EventListener; +import org.punit.runner.Runner; +import org.punit.type.TestSuite; +import org.punit.watcher.Watcher; +import java.lang.reflect.*; +import org.punit.util.*; + +/** + * The listener sets class public fields using properties. + */ +public class FieldSetter implements EventListener { + + private static final long serialVersionUID = 5194809928409791777L; + + private final Properties _properties; + + public FieldSetter(Properties properties) { + _properties = properties; + } + + @SuppressWarnings("unchecked") + public void onMethodEnd(Method method, Object testInstance, + Object[] params, Throwable t, List Watchers) { + } + + public void onClassEnd(Object testInstance, Throwable t) { + } + + public void onClassStart(Object testInstance) { + setClassFields(testInstance, _properties); + } + + public void onMethodStart(Method method, Object testInstance, + Object[] params) { + + } + + @SuppressWarnings("unchecked") + public void onRunnerEnd(Class clazz, Runner runner) { + } + + @SuppressWarnings("unchecked") + public void onRunnerStart(Class clazz, Runner runner) { + } + + public void onSuiteEnd(TestSuite suite) { + + } + + public void onSuiteStart(TestSuite suite) { + + } + + public void onWatcherEnd(Watcher watcher) { + + } + + public void onWatcherStart(Watcher watcher) { + + } + + @SuppressWarnings("unchecked") + public void onWatchersEnd(List watchers) { + + } + + @SuppressWarnings("unchecked") + public void onWatchersStart(List watchers) { + + } + + public boolean supportParentRunner() { + return false; + } + + private final String PACKAGE_SEPARATOR = "."; + + /** + * Set public class fields from java properties. + * + * @param clazz + * a class to set fields + * @param properites + * a set of properties + */ + private void setClassFields(Object testInstance, Properties properties) { + for (Field field : testInstance.getClass().getFields()) { + String fieldName = 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)); + } + } + } + } +} Property changes on: punit.extension/src/org/punit/listener/FieldSetter.java ___________________________________________________________________ Name: svn:executable + * Index: punit.extension/src/org/punit/annotation/Test.java =================================================================== --- punit.extension/src/org/punit/annotation/Test.java (revision 228) +++ punit.extension/src/org/punit/annotation/Test.java (working copy) @@ -2,18 +2,19 @@ package org.punit.annotation; -import java.lang.annotation.*; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.RUNTIME) public @interface Test { - Class expected() default NoException.class; + Class expected() default NoException.class; - String checkMethod() default ""; - - int concurrentCount() default 0; + String checkMethod() default ""; - public class NoException extends Throwable { - private static final long serialVersionUID = 3987745685001380514L; - } + int concurrentCount() default 0; + + public class NoException extends Throwable { + private static final long serialVersionUID = 3987745685001380514L; + } } Index: punit.extension/src/org/punit/annotation/After.java =================================================================== --- punit.extension/src/org/punit/annotation/After.java (revision 228) +++ punit.extension/src/org/punit/annotation/After.java (working copy) @@ -1,7 +1,10 @@ /* (C) Copyright 2007, by Andrew Zhang */ package org.punit.annotation; -import java.lang.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) Index: punit.extension/src/org/punit/annotation/Before.java =================================================================== --- punit.extension/src/org/punit/annotation/Before.java (revision 228) +++ punit.extension/src/org/punit/annotation/Before.java (working copy) @@ -1,11 +1,13 @@ /* (C) Copyright 2007, by Andrew Zhang */ package org.punit.annotation; -import java.lang.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 { -public @interface Before { - } Index: punit.extension/src/org/punit/util/AnnotationUtil.java =================================================================== --- punit.extension/src/org/punit/util/AnnotationUtil.java (revision 229) +++ punit.extension/src/org/punit/util/AnnotationUtil.java (working copy) @@ -2,17 +2,18 @@ package org.punit.util; -import java.lang.annotation.*; -import java.lang.reflect.*; +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; public class AnnotationUtil { - - public static Method getMethodByAnnotation(Class clazz, Class annotationClass) { + + public static Method getMethodByAnnotation( + Class clazz, Class annotationClass) { Method[] methods = clazz.getDeclaredMethods(); - for(int i = 0; i < methods.length; ++i) { + for (int i = 0; i < methods.length; ++i) { Method method = methods[i]; Annotation annotation = method.getAnnotation(annotationClass); - if(annotation != null) { + if (annotation != null) { method.setAccessible(true); return method; } Index: punit.test/src/tests/samples/ConcurrentParameterizedTestSample.java =================================================================== --- punit.test/src/tests/samples/ConcurrentParameterizedTestSample.java (revision 0) +++ punit.test/src/tests/samples/ConcurrentParameterizedTestSample.java (revision 0) @@ -0,0 +1,13 @@ +package tests.samples; + +import org.punit.runner.*; + +import tests.api.org.punit.testclasses.*; + +public class ConcurrentParameterizedTestSample { + + public static void main(String[] args) { + new SoloRunner().run(ConcurrentParameterizedTestClass.class); + new ConcurrentRunner().run(ConcurrentParameterizedTestClass.class); + } +} Index: punit.test/src/tests/samples/ParameterizableTestSample.java =================================================================== --- punit.test/src/tests/samples/ParameterizableTestSample.java (revision 228) +++ punit.test/src/tests/samples/ParameterizableTestSample.java (working copy) @@ -1,12 +0,0 @@ -package tests.samples; - -import org.punit.runner.*; - -import tests.api.org.punit.testclasses.*; - -public class ParameterizableTestSample { - - public static void main(String[] args) { - new SoloRunner().run(ParameterizableTestClass.class); - } -} Index: punit.test/src/tests/samples/ConcurrentParameterizableTestSample.java =================================================================== --- punit.test/src/tests/samples/ConcurrentParameterizableTestSample.java (revision 228) +++ punit.test/src/tests/samples/ConcurrentParameterizableTestSample.java (working copy) @@ -1,13 +0,0 @@ -package tests.samples; - -import org.punit.runner.*; - -import tests.api.org.punit.testclasses.*; - -public class ConcurrentParameterizableTestSample { - - public static void main(String[] args) { - new SoloRunner().run(ConcurrentParameterizableTestClass.class); - new ConcurrentRunner().run(ConcurrentParameterizableTestClass.class); - } -} Index: punit.test/src/tests/samples/ParameterizedTestSample.java =================================================================== --- punit.test/src/tests/samples/ParameterizedTestSample.java (revision 0) +++ punit.test/src/tests/samples/ParameterizedTestSample.java (revision 0) @@ -0,0 +1,12 @@ +package tests.samples; + +import org.punit.runner.*; + +import tests.api.org.punit.testclasses.*; + +public class ParameterizedTestSample { + + public static void main(String[] args) { + new SoloRunner().run(ParameterizedTestClass.class); + } +} Index: punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java =================================================================== --- punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java (revision 229) +++ punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java (working copy) @@ -21,7 +21,7 @@ } public void testBuildTestMethods1() { - Object[] methods = _builder.buildTestMethods(TestClass1.class) + Object[] methods = _builder.extractTestMethods(TestClass1.class) .toArray(); String[] names = TestUtil.toMethodNameArray(methods); AssertUtil.assertArrayContent(new String[] { "test1", "test2", //$NON-NLS-1$ //$NON-NLS-2$ @@ -29,7 +29,7 @@ } public void testBuildTestMethods_SubClass() { - Object[] methods = _builder.buildTestMethods(SubTestClass.class) + Object[] methods = _builder.extractTestMethods(SubTestClass.class) .toArray(); String[] names = TestUtil.toMethodNameArray(methods); AssertUtil.assertArrayContent(new String[] { "test1", "test2", //$NON-NLS-1$ //$NON-NLS-2$ @@ -37,7 +37,7 @@ } public void testBuildTestMethods2() { - Object[] methods = _builder.buildTestMethods(TestClass2.class) + Object[] methods = _builder.extractTestMethods(TestClass2.class) .toArray(); String[] names = TestUtil.toMethodNameArray(methods); AssertUtil.assertArrayContent(names, new String[] { "test1", "test2", //$NON-NLS-1$ //$NON-NLS-2$ @@ -45,7 +45,7 @@ } public void testBuildTestMethods3() { - Object[] methods = _builder.buildTestMethods(AlphabeticalTestClass.class) + Object[] methods = _builder.extractTestMethods(AlphabeticalTestClass.class) .toArray(); String[] names = TestUtil.toMethodNameArray(methods); AssertUtil.assertArray(names, new String[] { "test1", "test2", "testa", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ Index: punit.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java =================================================================== --- punit.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java (revision 229) +++ punit.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java (working copy) @@ -89,7 +89,7 @@ } public void testGetSetUpMethod() { - assertNotNull(_filter.getSetupMethod(AnnotationTestClass.class)); + assertNotNull(_filter.getSetUpMethod(AnnotationTestClass.class)); } public void testGetTearDownMethod() { Index: punit.test/src/tests/api/org/punit/convention/JUnitAnnotationConventionTest.java =================================================================== --- punit.test/src/tests/api/org/punit/convention/JUnitAnnotationConventionTest.java (revision 229) +++ punit.test/src/tests/api/org/punit/convention/JUnitAnnotationConventionTest.java (working copy) @@ -95,7 +95,7 @@ } public void testGetSetUpMethod() { - assertNotNull(_filter.getSetupMethod(JUnitAnnotationTestClass.class)); + assertNotNull(_filter.getSetUpMethod(JUnitAnnotationTestClass.class)); } public void testGetTearDownMethod() { Index: punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java =================================================================== --- punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java (revision 229) +++ punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java (working copy) @@ -2,96 +2,102 @@ package tests.api.org.punit.convention; -import java.lang.reflect.*; +import java.lang.reflect.Method; -import junit.framework.*; +import junit.framework.TestCase; -import org.punit.convention.*; -import org.punit.util.*; +import org.punit.convention.NameConvention; +import org.punit.util.ReflectionUtil; -import tests.api.org.punit.testclasses.*; +import tests.api.org.punit.testclasses.ConcurrentTestClass; +import tests.api.org.punit.testclasses.LoopTestClass; +import tests.api.org.punit.testclasses.TestClass0; +import tests.api.org.punit.testclasses.TestClass1; public class NameConventionFilterTest extends TestCase { - + NameConvention _convention = new NameConvention(); - + public void testIsTestMethod() { Method method; method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$ assertTrue(_convention.isTestMethod(method)); - + method = ReflectionUtil.getMethod(getClass(), "_test2", new Class[] {}); //$NON-NLS-1$ - assertFalse(_convention.isTestMethod(method)); + assertFalse(_convention.isTestMethod(method)); } - + public void testGetCheckMethod() { Method method, checkMethod; method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$ checkMethod = _convention.getCheckMethod(method); assertNull(checkMethod); - + method = ReflectionUtil.getMethod(getClass(), "_test2", new Class[] {}); //$NON-NLS-1$ 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$ + Method method = ReflectionUtil.getMethod(getClass(), + "test1", new Class[] {}); //$NON-NLS-1$ ConcurrentTestClass test = new ConcurrentTestClass(); int count = _convention.getConcurrentCount(test, method); assertEquals(test.concurrentCount(), count); - + method = ReflectionUtil.getMethod(getClass(), "test1", new Class[] {}); //$NON-NLS-1$ - assertEquals(0, _convention.getConcurrentCount(new TestClass0(), method)); + assertEquals(0, _convention + .getConcurrentCount(new TestClass0(), method)); } - + public void testGetSetUpMethod() { - assertNotNull(_convention.getSetupMethod(TestClass0.class)); - assertNull(_convention.getSetupMethod(TestClass1.class)); + assertNotNull(_convention.getSetUpMethod(TestClass0.class)); + assertNull(_convention.getSetUpMethod(TestClass1.class)); } - + public void testGetTearDownMethod() { assertNotNull(_convention.getTearDownMethod(TestClass0.class)); assertNull(_convention.getTearDownMethod(TestClass1.class)); } - + public void testGetBeforeClass() { assertNotNull(_convention.getBeforeClassMethod(TestClass0.class)); assertNull(_convention.getBeforeClassMethod(TestClass1.class)); } - + public void testGetAfterClass() { assertNotNull(_convention.getAfterClassMethod(TestClass0.class)); assertNull(_convention.getAfterClassMethod(TestClass1.class)); } - + public void testIsLoop() { - assertTrue(_convention.isLoopTest(new LoopTestClass())); - assertFalse(_convention.isLoopTest(new TestClass0())); + assertTrue(_convention.isLoopTest(LoopTestClass.class)); + assertFalse(_convention.isLoopTest(TestClass0.class)); } - + public void testGetToWork() { - assertEquals(LoopTestClass.TIMEOUT, _convention.toWork(new LoopTestClass())); + assertEquals(LoopTestClass.TIMEOUT, _convention + .toWork(new LoopTestClass())); assertEquals(0, _convention.toWork(new TestClass0())); } - + public void test1() { - + } - + public void _test2() { - + } - + public void check__test2() { - + } - + public void _test3() { - + } - + public void check__test3() { - + } } Index: punit.test/src/tests/api/org/punit/runner/MockEventListener.java =================================================================== --- punit.test/src/tests/api/org/punit/runner/MockEventListener.java (revision 229) +++ punit.test/src/tests/api/org/punit/runner/MockEventListener.java (working copy) @@ -37,14 +37,12 @@ _onRunnerStart = true; } - @SuppressWarnings("unchecked") - public void onClassEnd(Class clazz) { - _onClassEnd = true; + public void onClassStart(Object testInstance) { + _onClassStart = true; } - @SuppressWarnings("unchecked") - public void onClassStart(Class clazz) { - _onClassStart = true; + public void onClassEnd(Object testInstance, Throwable t) { + _onClassEnd = true; } @SuppressWarnings("unchecked") Index: punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java =================================================================== --- punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java (revision 229) +++ punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java (working copy) @@ -2,9 +2,13 @@ package tests.api.org.punit.runner; +import java.util.Properties; + import junit.framework.Assert; import org.punit.convention.AnnotationConvention; +import org.punit.events.EventListener; +import org.punit.listener.FieldSetter; import org.punit.method.runner.MethodRunner; import org.punit.runner.SoloRunner; import org.punit.watcher.CustomWatcher; @@ -12,7 +16,7 @@ import tests.api.org.punit.testclasses.AnnotationTestClass; import tests.api.org.punit.testclasses.ConcurrentTestClass; import tests.api.org.punit.testclasses.LoopTestClass; -import tests.api.org.punit.testclasses.ParameterizableTestClass; +import tests.api.org.punit.testclasses.ParameterizedTestClass; import tests.api.org.punit.testclasses.SetResultTestClass; import tests.api.org.punit.testclasses.TestClass0; import tests.api.org.punit.testclasses.TestClass3; @@ -60,6 +64,17 @@ methodRunner.removeWatcher(watcher); } + public void testFieldSetter() { + Properties properties = new Properties(); + // 12 + 18 = ParameterizedTestClass.SUM + properties.put("VALUE1", "12"); + properties.put("VALUE2", "18"); + EventListener listener = new FieldSetter(properties); + _runner.addEventListener(listener); + _runner.run(ParameterizedTestClass.class); + _runner.removeEventListener(listener); + } + public void testRunAnnotationTest() { AnnotationTestClass.reset(); _runner.setConvention(new AnnotationConvention()); @@ -81,10 +96,10 @@ _eventListener.assertAllEventsInvoked(); } - public void testRunParameterizable() throws Exception { - ParameterizableTestClass.reset(); - _runner.run(ParameterizableTestClass.class); - ParameterizableTestClass.assertTestClassRun(); + public void testRunParameterized() throws Exception { + ParameterizedTestClass.reset(); + _runner.run(ParameterizedTestClass.class); + ParameterizedTestClass.assertTestClassRun(); } public void testRunTestSuite() { Index: punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java =================================================================== --- punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java (revision 229) +++ punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java (working copy) @@ -10,7 +10,7 @@ import org.punit.runner.ConcurrentRunner; import tests.api.org.punit.testclasses.AnnotationTestClass; -import tests.api.org.punit.testclasses.ConcurrentParameterizableTestClass; +import tests.api.org.punit.testclasses.ConcurrentParameterizedTestClass; import tests.api.org.punit.testclasses.ConcurrentTestClass; import tests.api.org.punit.testclasses.LoopTestClass; import tests.api.org.punit.testclasses.TestClass0; @@ -61,10 +61,10 @@ TestClass3.assertTestClassRun(); } - public void testRunParameterizable() throws Exception { - ConcurrentParameterizableTestClass.reset(); - _runner.run(ConcurrentParameterizableTestClass.class); - ConcurrentParameterizableTestClass.assertTestClassRun(); + public void testRunParameterized() throws Exception { + ConcurrentParameterizedTestClass.reset(); + _runner.run(ConcurrentParameterizedTestClass.class); + ConcurrentParameterizedTestClass.assertTestClassRun(); } public void testRunTestSuite() { Index: punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java =================================================================== --- punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java (revision 229) +++ punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java (working copy) @@ -55,10 +55,6 @@ Assert.assertEquals(2, _tearDown); } - public long toStop() { - return TIMEOUT; - } - public long toWork() { return TIMEOUT; } Index: punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizableTestClass.java =================================================================== --- punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizableTestClass.java (revision 228) +++ punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizableTestClass.java (working copy) @@ -1,96 +0,0 @@ -package tests.api.org.punit.testclasses; - -import junit.framework.Assert; - -import org.punit.type.Concurrent; -import org.punit.type.Parameter; -import org.punit.type.Parameterizable; - -import tests.util.TestUtil; - -public class ConcurrentParameterizableTestClass implements Parameterizable, Concurrent { - - private static final int VALUE1 = 10; - - private static final int VALUE2 = 20; - - public static final int SUM = 30; - - public static final int COCURRENT_COUNT = 5; - - public static int _test1; - - public static boolean _test2; - - public static boolean _setUpBefore; - - public static boolean _setUpAfter; - - public static boolean _tearDownBefore; - - public static boolean _tearDownAfter; - - public static void reset() { - _test1 = 0; - _test2 = false; - _setUpBefore = false; - _setUpAfter = false; - _tearDownBefore = false; - _tearDownAfter = false; - } - - public void setUpAfterWatchers(Parameter param) throws Exception { - _setUpAfter = true; - } - - public void setUpBeforeWatchers(Parameter param) throws Exception { - _setUpBefore = true; - } - - public void tearDownAfterWatchers(Parameter param) throws Exception { - _tearDownAfter = true; - } - - public void tearDownBeforeWatchers(Parameter param) throws Exception { - _tearDownBefore = true; - } - - public synchronized void test1(IntParameter p) { - _test1 += p.value; - TestUtil.doSomething(); - } - - public synchronized void test1() { - TestUtil.doSomething(); - } - - public void test2() { - _test2 = true; - TestUtil.doSomething(); - } - - public void test3(Parameter p) { - TestUtil.doSomething(); - } - - public void test3(int i) { - TestUtil.doSomething(); - } - - public Parameter[] parameters() { - return new Parameter[] { new IntParameter(VALUE1), new IntParameter(VALUE2), }; - } - - public int concurrentCount() { - return COCURRENT_COUNT; - } - - public static void assertTestClassRun() { - Assert.assertEquals(SUM * COCURRENT_COUNT, _test1); - Assert.assertFalse(_test2); - Assert.assertTrue(_setUpBefore); - Assert.assertTrue(_setUpAfter); - Assert.assertTrue(_tearDownBefore); - Assert.assertTrue(_tearDownAfter); - } -} Index: punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java =================================================================== --- punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java (revision 229) +++ punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java (working copy) @@ -7,8 +7,8 @@ public Class[] testSuite() { return new Class[] { TestClass0.class, TestClass3.class, ConcurrentTestClass.class, - ConcurrentParameterizableTestClass.class, JUnitTestClass.class, - ParameterizableTestClass.class, TestClass3.class, + ConcurrentParameterizedTestClass.class, JUnitTestClass.class, + ParameterizedTestClass.class, TestClass3.class, TestClass1.class, }; } } Index: punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java =================================================================== --- punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java (revision 229) +++ punit.test/src/tests/api/org/punit/testclasses/SetResultTestClass.java (working copy) @@ -11,7 +11,7 @@ public class SetResultTestClass implements Runnable, Loop { - public static final long TIMEOUT = 1000; + public static final long TIMEOUT = 500; public static final String SUPPORTED_THREADS = "Supported Number of Threads"; @@ -66,10 +66,6 @@ } } - public long toStop() { - return TIMEOUT; - } - public long toWork() { return TIMEOUT; } Index: punit.test/src/tests/api/org/punit/testclasses/ParameterizedTestClass.java =================================================================== --- punit.test/src/tests/api/org/punit/testclasses/ParameterizedTestClass.java (revision 0) +++ punit.test/src/tests/api/org/punit/testclasses/ParameterizedTestClass.java (revision 0) @@ -0,0 +1,88 @@ +package tests.api.org.punit.testclasses; + +import junit.framework.Assert; + +import org.punit.type.Parameter; +import org.punit.type.Parameterized; + +import tests.util.TestUtil; + +public class ParameterizedTestClass implements Parameterized { + + public final int VALUE1 = 10; + + public final int VALUE2 = 20; + + public static final int SUM = 30; + + public static int _test1; + + public static boolean _test2; + + public static boolean _setUpBefore; + + public static boolean _setUpAfter; + + public static boolean _tearDownBefore; + + public static boolean _tearDownAfter; + + + public static void reset() { + _test1 = 0; + _test2 = false; + _setUpBefore = false; + _setUpAfter = false; + _tearDownBefore = false; + _tearDownAfter = false; + } + + public void setUpAfterWatchers(Parameter param) throws Exception { + _setUpAfter = true; + } + + public void setUpBeforeWatchers(Parameter param) throws Exception { + _setUpBefore = true; + } + + public void tearDownAfterWatchers(Parameter param) throws Exception { + _tearDownAfter = true; + } + + public void tearDownBeforeWatchers(Parameter param) throws Exception { + _tearDownBefore = true; + } + + + public void test1(IntParameter p) { + _test1 += p.value; + TestUtil.doSomething(); + } + + public void test2() { + _test2 = true; + TestUtil.doSomething(); + } + + public void test3(Parameter p) { + TestUtil.doSomething(); + } + + public void test3(int i) { + TestUtil.doSomething(); + } + + public Parameter[] parameters() { + return new Parameter[] { new IntParameter(VALUE1), new IntParameter(VALUE2) }; + } + + public static void assertTestClassRun() { + Assert.assertEquals(SUM, _test1); + Assert.assertFalse(_test2); + Assert.assertTrue(_setUpBefore); + Assert.assertTrue(_setUpAfter); + Assert.assertTrue(_tearDownBefore); + Assert.assertTrue(_tearDownAfter); + } + +} Index: punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizedTestClass.java =================================================================== --- punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizedTestClass.java (revision 0) +++ punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizedTestClass.java (revision 0) @@ -0,0 +1,96 @@ +package tests.api.org.punit.testclasses; + +import junit.framework.Assert; + +import org.punit.type.Concurrent; +import org.punit.type.Parameter; +import org.punit.type.Parameterized; + +import tests.util.TestUtil; + +public class ConcurrentParameterizedTestClass implements Parameterized, Concurrent { + + private static final int VALUE1 = 10; + + private static final int VALUE2 = 20; + + public static final int SUM = 30; + + public static final int COCURRENT_COUNT = 5; + + public static int _test1; + + public static boolean _test2; + + public static boolean _setUpBefore; + + public static boolean _setUpAfter; + + public static boolean _tearDownBefore; + + public static boolean _tearDownAfter; + + public static void reset() { + _test1 = 0; + _test2 = false; + _setUpBefore = false; + _setUpAfter = false; + _tearDownBefore = false; + _tearDownAfter = false; + } + + public void setUpAfterWatchers(Parameter param) throws Exception { + _setUpAfter = true; + } + + public void setUpBeforeWatchers(Parameter param) throws Exception { + _setUpBefore = true; + } + + public void tearDownAfterWatchers(Parameter param) throws Exception { + _tearDownAfter = true; + } + + public void tearDownBeforeWatchers(Parameter param) throws Exception { + _tearDownBefore = true; + } + + public synchronized void test1(IntParameter p) { + _test1 += p.value; + TestUtil.doSomething(); + } + + public synchronized void test1() { + TestUtil.doSomething(); + } + + public void test2() { + _test2 = true; + TestUtil.doSomething(); + } + + public void test3(Parameter p) { + TestUtil.doSomething(); + } + + public void test3(int i) { + TestUtil.doSomething(); + } + + public Parameter[] parameters() { + return new Parameter[] { new IntParameter(VALUE1), new IntParameter(VALUE2), }; + } + + public int concurrentCount() { + return COCURRENT_COUNT; + } + + public static void assertTestClassRun() { + Assert.assertEquals(SUM * COCURRENT_COUNT, _test1); + Assert.assertFalse(_test2); + Assert.assertTrue(_setUpBefore); + Assert.assertTrue(_setUpAfter); + Assert.assertTrue(_tearDownBefore); + Assert.assertTrue(_tearDownAfter); + } +} Index: punit.test/src/tests/api/org/punit/testclasses/TestClass2.java =================================================================== --- punit.test/src/tests/api/org/punit/testclasses/TestClass2.java (revision 228) +++ punit.test/src/tests/api/org/punit/testclasses/TestClass2.java (working copy) @@ -1,21 +1,21 @@ package tests.api.org.punit.testclasses; -import tests.util.*; +import tests.util.TestUtil; public class TestClass2 { - public void test2() { - TestUtil.doSomething(); - } + public void test2() { + TestUtil.doSomething(); + } - public void test1() { - TestUtil.doSomething(); - } + public void test1() { + TestUtil.doSomething(); + } - public void testb() { - TestUtil.doSomething(); - } + public void testb() { + TestUtil.doSomething(); + } - public void testa() { - TestUtil.doSomething(); - } + public void testa() { + TestUtil.doSomething(); + } } Index: punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestClass.java =================================================================== --- punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestClass.java (revision 228) +++ punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestClass.java (working copy) @@ -1,88 +0,0 @@ -package tests.api.org.punit.testclasses; - -import junit.framework.Assert; - -import org.punit.type.Parameter; -import org.punit.type.Parameterizable; - -import tests.util.TestUtil; - -public class ParameterizableTestClass implements Parameterizable { - - private static final int VALUE1 = 10; - - private static final int VALUE2 = 20; - - public static final int SUM = 30; - - public static int _test1; - - public static boolean _test2; - - public static boolean _setUpBefore; - - public static boolean _setUpAfter; - - public static boolean _tearDownBefore; - - public static boolean _tearDownAfter; - - - public static void reset() { - _test1 = 0; - _test2 = false; - _setUpBefore = false; - _setUpAfter = false; - _tearDownBefore = false; - _tearDownAfter = false; - } - - public void setUpAfterWatchers(Parameter param) throws Exception { - _setUpAfter = true; - } - - public void setUpBeforeWatchers(Parameter param) throws Exception { - _setUpBefore = true; - } - - public void tearDownAfterWatchers(Parameter param) throws Exception { - _tearDownAfter = true; - } - - public void tearDownBeforeWatchers(Parameter param) throws Exception { - _tearDownBefore = true; - } - - - public void test1(IntParameter p) { - _test1 += p.value; - TestUtil.doSomething(); - } - - public void test2() { - _test2 = true; - TestUtil.doSomething(); - } - - public void test3(Parameter p) { - TestUtil.doSomething(); - } - - public void test3(int i) { - TestUtil.doSomething(); - } - - public Parameter[] parameters() { - return new Parameter[] { new IntParameter(VALUE1), new IntParameter(VALUE2), }; - } - - public static void assertTestClassRun() { - Assert.assertEquals(SUM, _test1); - Assert.assertFalse(_test2); - Assert.assertTrue(_setUpBefore); - Assert.assertTrue(_setUpAfter); - Assert.assertTrue(_tearDownBefore); - Assert.assertTrue(_tearDownAfter); - } - -}