p-unit-devel Mailing List for p-unit (Page 3)
Status: Beta
Brought to you by:
zhanghuangzhu
You can subscribe to this list here.
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(182) |
Jun
(46) |
Jul
(3) |
Aug
(2) |
Sep
(1) |
Oct
(7) |
Nov
(18) |
Dec
(8) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2008 |
Jan
(9) |
Feb
(5) |
Mar
(10) |
Apr
(17) |
May
(16) |
Jun
(16) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <zha...@us...> - 2008-03-20 15:22:12
|
Revision: 290
http://p-unit.svn.sourceforge.net/p-unit/?rev=290&view=rev
Author: zhanghuangzhu
Date: 2008-03-20 08:22:14 -0700 (Thu, 20 Mar 2008)
Log Message:
-----------
az: return the first throwable to users from setUp/test/tearDown
Modified Paths:
--------------
trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java
Modified: trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java 2008-03-20 15:21:41 UTC (rev 289)
+++ trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java 2008-03-20 15:22:14 UTC (rev 290)
@@ -54,13 +54,21 @@
}
public void testRun() throws Exception {
- _methodRunner.run(new Test(), getMethod("test1"), new Object[] {});
+ resetRunFlag();
+ _methodRunner.run(new Test(), getMethod(Test.class, "test1"), new Object[] {});
assertRunResult(null);
resetRunFlag();
- _methodRunner.run(new Test(), getMethod("test2"), new Object[] {});
+ _methodRunner.run(new Test(), getMethod(Test.class, "test2"), new Object[] {});
assertRunResult(UnsupportedOperationException.class);
+
}
+
+ public void testRun_MultipleExceptions() {
+ resetRunFlag();
+ _methodRunner.run(new TestMultiException(), getMethod(TestMultiException.class, "test"), new Object[] {});
+ Assert.assertEquals(NullPointerException.class, _mockEvenListener.throwable);
+ }
private void resetRunFlag() {
_methodRunner.isInvoked = false;
@@ -72,9 +80,8 @@
Assert.assertEquals(t, _mockEvenListener.throwable);
}
- private Method getMethod(String methodName) {
- return ReflectionUtil.getMethod(Test.class, methodName,
- new Class<?>[] {});
+ private Method getMethod(Class <?> clazz, String methodName) {
+ return ReflectionUtil.getMethod(clazz, methodName, new Class<?>[] {});
}
public static class Test {
@@ -85,6 +92,18 @@
throw new UnsupportedOperationException();
}
}
+
+ public static class TestMultiException {
+ public void setUp() {
+ throw new NullPointerException();
+ }
+ public void test() {
+ throw new IllegalArgumentException();
+ }
+ public void tearDown() {
+ throw new IllegalStateException();
+ }
+ }
@SuppressWarnings("serial")
private static class MockMethodRunner extends AbstractMethodRunner {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-03-20 15:21:37
|
Revision: 289
http://p-unit.svn.sourceforge.net/p-unit/?rev=289&view=rev
Author: zhanghuangzhu
Date: 2008-03-20 08:21:41 -0700 (Thu, 20 Mar 2008)
Log Message:
-----------
az: return the first throwable to users from setUp/test/tearDown
Modified Paths:
--------------
trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2008-03-18 12:45:49 UTC (rev 288)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2008-03-20 15:21:41 UTC (rev 289)
@@ -93,7 +93,9 @@
tearDownBeforeWatchers(params);
}
} catch (Throwable t) {
- throwable = t;
+ if(throwable == null) {
+ throwable = t;
+ }
} finally {
try {
stopWatchers(testInstance, method, params);
@@ -101,7 +103,9 @@
tearDownAfterWatchers(params);
}
} catch (Throwable t) {
- throwable = t;
+ if(throwable == null) {
+ throwable = t;
+ }
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-03-18 12:45:48
|
Revision: 288
http://p-unit.svn.sourceforge.net/p-unit/?rev=288&view=rev
Author: zhanghuangzhu
Date: 2008-03-18 05:45:49 -0700 (Tue, 18 Mar 2008)
Log Message:
-----------
Andrew Zhang: make jardesc svn:ignore
Added Paths:
-----------
trunk/punit.extension/extension.jardesc
Added: trunk/punit.extension/extension.jardesc
===================================================================
--- trunk/punit.extension/extension.jardesc (rev 0)
+++ trunk/punit.extension/extension.jardesc 2008-03-18 12:45:49 UTC (rev 288)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="GBK" standalone="no"?>
+<jardesc>
+ <jar path="E:/workspace/p-unit/release/p-unit-0.14.257-extension.jar"/>
+ <options buildIfNeeded="true" compress="true" descriptionLocation="/punit.extension/extension.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
+ <storedRefactorings deprecationInfo="true" structuralOnly="false"/>
+ <selectedProjects/>
+ <manifest generateManifest="true" manifestLocation="" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
+ <sealing sealJar="false">
+ <packagesToSeal/>
+ <packagesToUnSeal/>
+ </sealing>
+ </manifest>
+ <selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
+ <javaElement handleIdentifier="=punit.extension/src"/>
+ </selectedElements>
+</jardesc>
Property changes on: trunk/punit.extension/extension.jardesc
___________________________________________________________________
Name: svn:mime-type
+ text/plain
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-03-18 12:37:59
|
Revision: 287
http://p-unit.svn.sourceforge.net/p-unit/?rev=287&view=rev
Author: zhanghuangzhu
Date: 2008-03-18 05:38:03 -0700 (Tue, 18 Mar 2008)
Log Message:
-----------
Andrew Zhang: use the latest android.jar, and remove android.jar from lib folder
Modified Paths:
--------------
trunk/punit.android/.classpath
trunk/punit.android/src/org/punit/runner/AndroidRunner.java
Removed Paths:
-------------
trunk/punit.android/lib/android.jar
Modified: trunk/punit.android/.classpath
===================================================================
--- trunk/punit.android/.classpath 2008-03-18 10:22:26 UTC (rev 286)
+++ trunk/punit.android/.classpath 2008-03-18 12:38:03 UTC (rev 287)
@@ -3,6 +3,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/punit"/>
- <classpathentry kind="lib" path="lib/android.jar"/>
+ <classpathentry kind="lib" path="E:/tools/android-sdk_m5-rc14_windows/android.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Deleted: trunk/punit.android/lib/android.jar
===================================================================
(Binary files differ)
Modified: trunk/punit.android/src/org/punit/runner/AndroidRunner.java
===================================================================
--- trunk/punit.android/src/org/punit/runner/AndroidRunner.java 2008-03-18 10:22:26 UTC (rev 286)
+++ trunk/punit.android/src/org/punit/runner/AndroidRunner.java 2008-03-18 12:38:03 UTC (rev 287)
@@ -1,6 +1,5 @@
package org.punit.runner;
-import org.punit.method.runner.*;
public class AndroidRunner extends VanillaRunner {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-03-18 10:22:26
|
Revision: 286
http://p-unit.svn.sourceforge.net/p-unit/?rev=286&view=rev
Author: zhanghuangzhu
Date: 2008-03-18 03:22:26 -0700 (Tue, 18 Mar 2008)
Log Message:
-----------
Andrew Zhang: cleanup code.
Modified Paths:
--------------
trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java
trunk/punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/suite/builder/TestSuiteBuilderTest.java
trunk/punit.test/src/tests/util/AssertUtil.java
trunk/punit.test/src/tests/util/TestUtil.java
Modified: trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java 2008-03-18 10:21:37 UTC (rev 285)
+++ trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java 2008-03-18 10:22:26 UTC (rev 286)
@@ -6,7 +6,7 @@
import junit.framework.TestCase;
-import org.punit.convention.NameConvention;
+import org.punit.convention.ByNameConvention;
import org.punit.util.ReflectionUtil;
import tests.api.org.punit.testclasses.ConcurrentTestClass;
@@ -16,7 +16,7 @@
public class NameConventionFilterTest extends TestCase {
- NameConvention _convention = new NameConvention();
+ ByNameConvention _convention = new ByNameConvention();
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 2008-03-18 10:21:37 UTC (rev 285)
+++ trunk/punit.test/src/tests/api/org/punit/method/builder/TestMethodBuilderTest.java 2008-03-18 10:22:26 UTC (rev 286)
@@ -1,8 +1,10 @@
package tests.api.org.punit.method.builder;
+import java.lang.reflect.*;
+
import junit.framework.TestCase;
-import org.punit.convention.NameConvention;
+import org.punit.convention.ByNameConvention;
import org.punit.method.builder.MethodBuilderImpl;
import tests.api.org.punit.testclasses.AlphabeticalTestClass;
@@ -17,36 +19,34 @@
protected void setUp() throws Exception {
_builder = new MethodBuilderImpl();
- _builder.setConvention(new NameConvention());
+ _builder.setConvention(new ByNameConvention());
}
public void testBuildTestMethods1() {
- Object[] methods = _builder.extractTestMethods(TestClass1.class)
- .toArray();
+ Method[] methods = _builder.extractTestMethods(TestClass1.class)
+ .toArray(new Method[0]);
String[] names = TestUtil.toMethodNameArray(methods);
AssertUtil.assertArrayContent(new String[] { "test1", "test2", //$NON-NLS-1$ //$NON-NLS-2$
"testa", "testb" }, names); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testBuildTestMethods_SubClass() {
- Object[] methods = _builder.extractTestMethods(SubTestClass.class)
- .toArray();
+ Method[] methods = _builder.extractTestMethods(SubTestClass.class)
+ .toArray(new Method[0]);
String[] names = TestUtil.toMethodNameArray(methods);
AssertUtil.assertArrayContent(new String[] { "test1", "test2", //$NON-NLS-1$ //$NON-NLS-2$
"testa", "testb" }, names); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testBuildTestMethods2() {
- Object[] methods = _builder.extractTestMethods(TestClass2.class)
- .toArray();
+ Method[] methods = _builder.extractTestMethods(TestClass2.class).toArray(new Method[0]);
String[] names = TestUtil.toMethodNameArray(methods);
AssertUtil.assertArrayContent(names, new String[] { "test1", "test2", //$NON-NLS-1$ //$NON-NLS-2$
"testa", "testb" }); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testBuildTestMethods3() {
- Object[] methods = _builder.extractTestMethods(AlphabeticalTestClass.class)
- .toArray();
+ Method[] methods = _builder.extractTestMethods(AlphabeticalTestClass.class).toArray(new Method[0]);
String[] names = TestUtil.toMethodNameArray(methods);
AssertUtil.assertArray(names, new String[] { "test1", "test2", "testa", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"testb" }); //$NON-NLS-1$
Modified: trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java 2008-03-18 10:21:37 UTC (rev 285)
+++ trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java 2008-03-18 10:22:26 UTC (rev 286)
@@ -2,90 +2,108 @@
package tests.api.org.punit.method.runner;
+import java.lang.reflect.*;
import java.util.*;
import junit.framework.*;
-import junit.framework.Assert;
-import org.punit.assertion.*;
+import org.punit.convention.*;
+import org.punit.events.*;
import org.punit.method.runner.*;
+import org.punit.runner.*;
import org.punit.util.*;
import org.punit.watcher.*;
-import tests.api.org.punit.testclasses.*;
+import tests.util.*;
public class AbstractMethodRunnerTest extends TestCase {
- private MockTestMethodRunnerTest _mockRunner = new MockTestMethodRunnerTest();
- public void testWatchers() {
- List<Watcher >watchers = _mockRunner.watchers();
- assertEquals(1, watchers.size()); // time, and memory watchers
+ private MockMethodRunner _methodRunner;
+ private MockEvenListener _mockEvenListener;
- _mockRunner.removeTimeWatcher();
- watchers = _mockRunner.watchers();
- assertEquals(0, watchers.size());
+ public void setUp() throws Exception {
+ _methodRunner = new MockMethodRunner();
+ SoloRunner soloRunner = new SoloRunner();
+ _mockEvenListener = new MockEvenListener();
+ soloRunner.addEventListener(_mockEvenListener);
+ _methodRunner.setRunner(soloRunner);
+ _methodRunner.setRunnerProperties(new RunnerProperties());
+ _methodRunner.setConvention(new ByNameConvention());
+ }
- _mockRunner.addWatcher(new TimeWatcher());
- watchers = _mockRunner.watchers();
- assertEquals(1, watchers.size());
- }
+ public void testWatchers() throws Exception {
+ assertWatchers(new Watcher[] { new TimeWatcher() });
+ }
- public void testRunMethod1() throws Throwable {
- _mockRunner.testRunMethod1();
- }
+ public void testAddWatchers() throws Exception {
+ _methodRunner.addWatcher(new MemoryWatcher());
+ assertWatchers(new Watcher[] { new TimeWatcher(), new MemoryWatcher() });
+ }
- public void testRunMethod2() throws Throwable {
- _mockRunner.testRunMethod2();
- }
+ public void testRemoveWatchers() throws Exception {
+ _methodRunner.addWatcher(new MemoryWatcher());
+ _methodRunner.removeWatcher(new TimeWatcher());
+ assertWatchers(new Watcher[] { new MemoryWatcher() });
+ _methodRunner.removeWatcher(new MemoryWatcher());
+ assertWatchers(new Watcher[] {});
+ }
- public void testRunMethod3() throws Throwable {
- _mockRunner.testRunMethod3();
- }
+ private void assertWatchers(Watcher[] expected) {
+ List<Watcher> watchers = _methodRunner.watchers();
+ AssertUtil.assertArray(expected, watchers.toArray(new Watcher[0]));
+ }
- static class MockTestMethodRunnerTest extends AbstractMethodRunner {
+ public void testRun() throws Exception {
+ _methodRunner.run(new Test(), getMethod("test1"), new Object[] {});
+ assertRunResult(null);
- private static final long serialVersionUID = 1L;
+ resetRunFlag();
+ _methodRunner.run(new Test(), getMethod("test2"), new Object[] {});
+ assertRunResult(UnsupportedOperationException.class);
+ }
- public void testRunMethod1() throws Throwable {
- AnnotationTestClass.reset();
- this._method = ReflectionUtil.getMethod(AnnotationTestClass.class,
- "test1", new Class[] {}); //$NON-NLS-1$
- this._params = new Object[] {};
- this._testInstance = new AnnotationTestClass();
- this._expectedException = null;
- super.runMethod();
- Assert.assertTrue(AnnotationTestClass._test1);
- }
+ private void resetRunFlag() {
+ _methodRunner.isInvoked = false;
+ _mockEvenListener.throwable = null;
+ }
- public void testRunMethod2() throws Throwable {
- AnnotationTestClass.reset();
- this._method = ReflectionUtil.getMethod(AnnotationTestClass.class,
- "_testException", new Class[] {}); //$NON-NLS-1$
- this._params = new Object[] {};
- this._testInstance = new AnnotationTestClass();
- this._expectedException = null;
- org.punit.assertion.Assert.assertException(NullPointerException.class, new CodeRunner(){
- public void run() throws Throwable {
- runMethod();
- }
- });
- Assert.assertTrue(AnnotationTestClass._testException);
- }
+ private void assertRunResult(Class <? extends Throwable> t) {
+ Assert.assertTrue(_methodRunner.isInvoked);
+ Assert.assertEquals(t, _mockEvenListener.throwable);
+ }
- public void testRunMethod3() throws Throwable {
- AnnotationTestClass.reset();
- this._method = ReflectionUtil.getMethod(AnnotationTestClass.class,
- "_testException", new Class[] {}); //$NON-NLS-1$
- this._params = new Object[] {};
- this._testInstance = new AnnotationTestClass();
- this._expectedException = NullPointerException.class;
- super.runMethod();
- Assert.assertTrue(AnnotationTestClass._testException);
- }
+ private Method getMethod(String methodName) {
+ return ReflectionUtil.getMethod(Test.class, methodName,
+ new Class<?>[] {});
+ }
- protected void runImpl() throws Throwable {
- throw new UnsupportedOperationException();
- }
+ public static class Test {
+ public void test1() {
+ }
- }
+ public void test2() {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @SuppressWarnings("serial")
+ private static class MockMethodRunner extends AbstractMethodRunner {
+ public boolean isInvoked;
+
+ protected void runImpl() throws Throwable {
+ isInvoked = true;
+ super.runMethod();
+ }
+ }
+
+ @SuppressWarnings("serial")
+ private static class MockEvenListener extends VanillaEventListener {
+ public Class<? extends Throwable> throwable;
+
+ @Override
+ public void onMethodEnd(Method method, Object testInstance,
+ Object[] params, Throwable t, List<Watcher> Watchers) {
+ throwable = t == null ? null : t.getClass();
+ }
+ }
}
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 2008-03-18 10:21:37 UTC (rev 285)
+++ trunk/punit.test/src/tests/api/org/punit/suite/builder/TestSuiteBuilderTest.java 2008-03-18 10:22:26 UTC (rev 286)
@@ -13,7 +13,7 @@
protected void setUp() throws Exception {
_testSuiteBuidler = new TestSuiteBuilderImpl();
- _testSuiteBuidler.setConvention(new NameConvention());
+ _testSuiteBuidler.setConvention(new ByNameConvention());
}
public void testBuildExcludedTestClasses1() {
@@ -43,7 +43,7 @@
public void testBuildTestSuite2() {
Convention [] conventions = new Convention[] {
- new NameConvention(),
+ new ByNameConvention(),
new AnnotationConvention(),
};
Modified: trunk/punit.test/src/tests/util/AssertUtil.java
===================================================================
--- trunk/punit.test/src/tests/util/AssertUtil.java 2008-03-18 10:21:37 UTC (rev 285)
+++ trunk/punit.test/src/tests/util/AssertUtil.java 2008-03-18 10:22:26 UTC (rev 286)
@@ -1,14 +1,14 @@
package tests.util;
-import java.util.Arrays;
+import org.punit.assertion.*;
-import org.punit.assertion.Assert;
-import org.punit.assertion.CodeRunner;
-
public class AssertUtil {
public static void assertArray(Object[] array1, Object[] array2) {
- Assert.assertTrue(Arrays.equals(array1, array2));
+ Assert.assertEquals(array1.length, array2.length);
+ for(int i = 0; i < array1.length; ++i) {
+ Assert.assertEquals(array1[i], array2[i]);
+ }
}
/**
Modified: trunk/punit.test/src/tests/util/TestUtil.java
===================================================================
--- trunk/punit.test/src/tests/util/TestUtil.java 2008-03-18 10:21:37 UTC (rev 285)
+++ trunk/punit.test/src/tests/util/TestUtil.java 2008-03-18 10:22:26 UTC (rev 286)
@@ -29,10 +29,10 @@
return fis.readObject();
}
- public static String[] toMethodNameArray(Object[] methods) {
+ public static String[] toMethodNameArray(Method[] methods) {
String[] names = new String[methods.length];
for (int i = 0; i < methods.length; ++i) {
- names[i] = ((Method) methods[i]).getName();
+ names[i] = methods[i].getName();
}
return names;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-03-18 10:21:32
|
Revision: 285
http://p-unit.svn.sourceforge.net/p-unit/?rev=285&view=rev
Author: zhanghuangzhu
Date: 2008-03-18 03:21:37 -0700 (Tue, 18 Mar 2008)
Log Message:
-----------
Andrew Zhang: cleanup code.
Modified Paths:
--------------
trunk/punit/src/org/punit/convention/AnnotationConvention.java
trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
trunk/punit/src/org/punit/method/runner/MethodRunner.java
trunk/punit/src/org/punit/method/runner/SoloMethodRunner.java
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit/src/org/punit/util/ReflectionUtil.java
Added Paths:
-----------
trunk/punit/src/org/punit/convention/ByNameConvention.java
trunk/punit/src/org/punit/runner/Notifier.java
trunk/punit/src/org/punit/runner/VanillaRunner.java
Removed Paths:
-------------
trunk/punit/src/org/punit/convention/NameConvention.java
trunk/punit/src/org/punit/method/runner/VanillaRunner.java
Modified: trunk/punit/src/org/punit/convention/AnnotationConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/AnnotationConvention.java 2008-03-16 18:47:12 UTC (rev 284)
+++ trunk/punit/src/org/punit/convention/AnnotationConvention.java 2008-03-18 10:21:37 UTC (rev 285)
@@ -16,7 +16,7 @@
private static final long serialVersionUID = -6800242731470821241L;
- protected NameConvention _delegate = new NameConvention();
+ protected ByNameConvention _delegate = new ByNameConvention();
private Class<? extends Annotation> _after;
private Class<? extends Annotation> _afterClass;
Copied: trunk/punit/src/org/punit/convention/ByNameConvention.java (from rev 279, trunk/punit/src/org/punit/convention/NameConvention.java)
===================================================================
--- trunk/punit/src/org/punit/convention/ByNameConvention.java (rev 0)
+++ trunk/punit/src/org/punit/convention/ByNameConvention.java 2008-03-18 10:21:37 UTC (rev 285)
@@ -0,0 +1,105 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.convention;
+
+import java.lang.reflect.Method;
+
+import org.punit.util.ReflectionUtil;
+
+public class ByNameConvention extends AbstractConvention {
+
+ private static final long serialVersionUID = -1252188754463864599L;
+
+ public Method getCheckMethod(Method method) {
+ String checkMethodName = "check_" + method.getName(); //$NON-NLS-1$
+ return ReflectionUtil.getMethod(method.getDeclaringClass(),
+ checkMethodName, method.getParameterTypes());
+ }
+
+ /**
+ * Judges whether this method is a test method.
+ *
+ * @return returns true if the test modifier, name, and parameter conform to
+ * the convention of a test method.
+ */
+ public boolean isTestMethod(Method method) {
+ return isModifierValid(method) && isNameValid(method)
+ && isParamValid(method);
+ }
+
+ /**
+ * Judges whether 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);
+ }
+
+ /**
+ * Judges 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 parameters of this method conform to the convention of
+ * a test method.
+ *
+ * @param method
+ * @return <code>true</code> if the number of method parameters is zero
+ * and the test class is not marked as <code>Parameterized</code>,
+ * or the parameter length is 1, and the parameter is assignable
+ * from <code>Parameter</code>.
+ */
+ protected boolean isParamValid(Method method) {
+ Class<?> clazz = method.getDeclaringClass();
+ Class<?>[] params = method.getParameterTypes();
+ if (isParameterizedTest(clazz)) {
+ return params.length == 1 && isParameter(params[0]);
+ } else {
+ return params.length == 0;
+ }
+ }
+
+ public Method getAfterClassMethod(Class<?> test) {
+ Method method = ReflectionUtil.getMethodAndSetAccessibleWithAncestor(test,
+ "afterClass", new Class[] {}); //$NON-NLS-1$
+ if (method != null && ReflectionUtil.isStatic(method)) {
+ return method;
+ }
+ return null;
+ }
+
+ public Method getBeforeClassMethod(Class<?> test) {
+ Method method = ReflectionUtil.getMethodAndSetAccessibleWithAncestor(test,
+ "beforeClass", new Class[] {}); //$NON-NLS-1$
+ if (method != null && ReflectionUtil.isStatic(method)) {
+ return method;
+ }
+ return null;
+ }
+
+ public Method getSetUpMethod(Class<?> test) {
+ return ReflectionUtil.getMethodAndSetAccessibleWithAncestor(test,
+ "setUp", new Class[] {}); //$NON-NLS-1$
+ }
+
+ public Method getTearDownMethod(Class<?> test) {
+ return ReflectionUtil.getMethodAndSetAccessibleWithAncestor(test,
+ "tearDown", new Class[] {}); //$NON-NLS-1$
+ }
+}
Deleted: trunk/punit/src/org/punit/convention/NameConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/NameConvention.java 2008-03-16 18:47:12 UTC (rev 284)
+++ trunk/punit/src/org/punit/convention/NameConvention.java 2008-03-18 10:21:37 UTC (rev 285)
@@ -1,105 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.convention;
-
-import java.lang.reflect.Method;
-
-import org.punit.util.ReflectionUtil;
-
-public class NameConvention extends AbstractConvention {
-
- private static final long serialVersionUID = -1252188754463864599L;
-
- public Method getCheckMethod(Method method) {
- String checkMethodName = "check_" + method.getName(); //$NON-NLS-1$
- return ReflectionUtil.getMethod(method.getDeclaringClass(),
- checkMethodName, method.getParameterTypes());
- }
-
- /**
- * Judges whether this method is a test method.
- *
- * @return returns true if the test modifier, name, and parameter conform to
- * the convention of a test method.
- */
- public boolean isTestMethod(Method method) {
- return isModifierValid(method) && isNameValid(method)
- && isParamValid(method);
- }
-
- /**
- * Judges whether 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);
- }
-
- /**
- * Judges 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 parameters of this method conform to the convention of
- * a test method.
- *
- * @param method
- * @return <code>true</code> if the number of method parameters is zero
- * and the test class is not marked as <code>Parameterized</code>,
- * or the parameter length is 1, and the parameter is assignable
- * from <code>Parameter</code>.
- */
- protected boolean isParamValid(Method method) {
- Class<?> clazz = method.getDeclaringClass();
- Class<?>[] params = method.getParameterTypes();
- if (isParameterizedTest(clazz)) {
- return params.length == 1 && isParameter(params[0]);
- } else {
- return params.length == 0;
- }
- }
-
- public Method getAfterClassMethod(Class<?> test) {
- Method method = ReflectionUtil.getMethodAndSetAccessibleWithAncestor(test,
- "afterClass", new Class[] {}); //$NON-NLS-1$
- if (method != null && ReflectionUtil.isStatic(method)) {
- return method;
- }
- return null;
- }
-
- public Method getBeforeClassMethod(Class<?> test) {
- Method method = ReflectionUtil.getMethodAndSetAccessibleWithAncestor(test,
- "beforeClass", new Class[] {}); //$NON-NLS-1$
- if (method != null && ReflectionUtil.isStatic(method)) {
- return method;
- }
- return null;
- }
-
- public Method getSetUpMethod(Class<?> test) {
- return ReflectionUtil.getMethodAndSetAccessibleWithAncestor(test,
- "setUp", new Class[] {}); //$NON-NLS-1$
- }
-
- public Method getTearDownMethod(Class<?> test) {
- return ReflectionUtil.getMethodAndSetAccessibleWithAncestor(test,
- "tearDown", new Class[] {}); //$NON-NLS-1$
- }
-}
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2008-03-16 18:47:12 UTC (rev 284)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2008-03-18 10:21:37 UTC (rev 285)
@@ -20,7 +20,7 @@
private TimeWatcher _timeWatcher = new TimeWatcher();
- private List<EventListener> _eventListeners;
+ private AbstractRunner _runner;
private RunnerProperties _runnerProperties;
@@ -46,13 +46,15 @@
protected transient Class<? extends Throwable> _expectedException;
+ protected abstract void runImpl() throws Throwable;
+
public AbstractMethodRunner() {
_watchers.add(_timeWatcher);
_shouldStop = true;
}
- public void setEventListeners(List<EventListener> eventListeners) {
- _eventListeners = eventListeners;
+ public void setRunner(AbstractRunner runner) {
+ _runner = runner;
}
public void setRunnerProperties(RunnerProperties props) {
@@ -67,10 +69,6 @@
_watchers.remove(watcher);
}
- public void removeTimeWatcher() {
- _watchers.remove(_timeWatcher);
- }
-
public void run(Object testInstance, Method method, Object[] params) {
onMethodStart(method, testInstance, params);
Throwable throwable = null;
@@ -129,26 +127,6 @@
}
}
- private void onMethodStart(final Method method, final Object testInstance,
- final Object[] params) {
- Iterator<EventListener> iter = _eventListeners.iterator();
- while(iter.hasNext()) {
- EventListener listener = iter.next();
- listener.onMethodStart(method, testInstance, params);
- }
- }
-
- private void onMethodEnd(final Method method, final Object testInstance,
- final Object[] params, final Throwable t) {
- Iterator<EventListener> iter = _eventListeners.iterator();
- while (iter.hasNext()) {
- EventListener listener = iter.next();
- listener.onMethodEnd(method, testInstance, params, t, _watchers);
- }
- }
-
- protected abstract void runImpl() throws Throwable;
-
protected final void init(Object testInstance, Method method,
Object[] params) {
_testInstance = testInstance;
@@ -255,25 +233,6 @@
}
}
- private void onWatchersStart(final Object testInstance,
- final Method method, final Object[] params) {
- Iterator<EventListener> iter = _eventListeners.iterator();
- while(iter.hasNext()) {
- EventListener listener = iter.next();
- listener.onWatchersStart(_watchers);
- }
- }
-
- private void onWatcherStart(final Watcher watcher,
- final Object testInstance, final Method method,
- final Object[] params) {
- Iterator<EventListener> iter = _eventListeners.iterator();
- while (iter.hasNext()) {
- EventListener listener = iter.next();
- listener.onWatcherStart(watcher);
- }
- }
-
protected final void stopWatchers(final Object testInstance,
final Method method, final Object[] params) {
Iterator<Watcher> iter = _watchers.iterator();
@@ -285,24 +244,6 @@
onWatchersEnd(testInstance, method, params);
}
- private void onWatcherEnd(final Watcher watcher, final Object testInstance,
- final Method method, final Object[] params) {
- Iterator<EventListener> iter = _eventListeners.iterator();
- while (iter.hasNext()) {
- EventListener listener = iter.next();
- listener.onWatcherEnd(watcher);
- }
- }
-
- private void onWatchersEnd(final Object testInstance, final Method method,
- final Object[] params) {
- Iterator<EventListener> iter = _eventListeners.iterator();
- while (iter.hasNext()) {
- EventListener listener = iter.next();
- listener.onWatchersEnd(_watchers);
- }
- }
-
public List<Watcher> watchers() {
return _watchers;
}
@@ -334,24 +275,77 @@
}
protected void runMethod() throws Throwable {
- if (_expectedException == null) {
- do {
- invokeMethod();
- } while (!shouldStop());
- } else {
- Assert.assertException(_expectedException, new CodeRunner() {
- public void run() throws Throwable {
- invokeMethod();
- }
- });
- }
+ if (_expectedException == null) {
+ runMethodWithStopLoop();
+ } else {
+ Assert.assertException(_expectedException, new CodeRunner() {
+ public void run() throws Throwable {
+ runMethodWithStopLoop();
+ }
+ });
+ }
+ }
+
+ private void runMethodWithStopLoop() throws Throwable {
+ do {
+ ReflectionUtil.invokeMethodWithException(_method,
+ _testInstance, _params);
+ } while (!shouldStop());
+ }
+
+ private void onMethodStart(final Method method, final Object testInstance,
+ final Object[] params) {
+ _runner.notifyListeners(new Notifier(){
+ public void run(EventListener listener) {
+ listener.onMethodStart(method, testInstance, params);
+ }
+ });
}
- private void invokeMethod() throws Throwable {
- try {
- ReflectionUtil.invokeMethod(_method, _testInstance, _params);
- } catch (ReflectionException e) {
- throw e.getCause();
- }
+ private void onMethodEnd(final Method method, final Object testInstance,
+ final Object[] params, final Throwable t) {
+ _runner.notifyListeners(new Notifier(){
+ public void run(EventListener listener) {
+ listener.onMethodEnd(method, testInstance, params, t, _watchers);
+ }
+ });
}
+
+ private void onWatchersStart(final Object testInstance,
+ final Method method, final Object[] params) {
+ _runner.notifyListeners(new Notifier(){
+ public void run(EventListener listener) {
+ listener.onWatchersStart(_watchers);
+ }
+ });
+ }
+
+ private void onWatcherStart(final Watcher watcher,
+ final Object testInstance, final Method method,
+ final Object[] params) {
+ _runner.notifyListeners(new Notifier(){
+ public void run(EventListener listener) {
+ listener.onWatcherStart(watcher);
+ }
+ });
+ }
+
+ private void onWatcherEnd(final Watcher watcher, final Object testInstance,
+ final Method method, final Object[] params) {
+ _runner.notifyListeners(new Notifier() {
+ public void run(EventListener listener) {
+ listener.onWatcherEnd(watcher);
+ }
+ });
+ }
+
+ private void onWatchersEnd(final Object testInstance, final Method method,
+ final Object[] params) {
+ _runner.notifyListeners(new Notifier() {
+ public void run(EventListener listener) {
+ listener.onWatchersEnd(_watchers);
+ }
+ });
+ }
+
}
Modified: trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2008-03-16 18:47:12 UTC (rev 284)
+++ trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2008-03-18 10:21:37 UTC (rev 285)
@@ -4,7 +4,7 @@
import java.util.concurrent.*;
-import org.punit.exception.ConcurrentException;
+import org.punit.exception.*;
public class ConcurrentMethodRunner extends AbstractMethodRunner {
@@ -22,22 +22,21 @@
_concurrentCount = concurrentCount;
}
- protected void runImpl() throws Throwable {
+ protected void runImpl() throws Throwable {
startThreads();
joinThreads();
if (_concurrentException.size() > 0) {
throw _concurrentException;
}
}
-
+
private void startThreads() {
int count = _convention.getConcurrentCount(_testInstance, _method);
int threadCount = count > 0 ? count : _concurrentCount;
_threads = new TestMethodThread[threadCount];
_barrier = new CyclicBarrier(threadCount);
for (int i = 0; i < _threads.length; ++i) {
- _threads[i] = new TestMethodThread(this,
- "punit concurrent method runner"); //$NON-NLS-1$
+ _threads[i] = new TestMethodThread("punit concurrent method runner"); //$NON-NLS-1$
}
for (int i = 0; i < _threads.length; ++i) {
_threads[i].start();
@@ -59,17 +58,15 @@
}
private class TestMethodThread extends Thread {
- ConcurrentMethodRunner _runner;
-
- public TestMethodThread(ConcurrentMethodRunner runner, String threadName) {
+
+ public TestMethodThread(String threadName) {
super(threadName);
- _runner = runner;
}
public void run() {
try {
_barrier.await();
- _runner.runMethod();
+ ConcurrentMethodRunner.this.runMethod();
} catch (Throwable t) {
_concurrentException.add(t);
}
Modified: trunk/punit/src/org/punit/method/runner/MethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/MethodRunner.java 2008-03-16 18:47:12 UTC (rev 284)
+++ trunk/punit/src/org/punit/method/runner/MethodRunner.java 2008-03-18 10:21:37 UTC (rev 285)
@@ -1,13 +1,12 @@
package org.punit.method.runner;
-import java.io.Serializable;
-import java.lang.reflect.Method;
-import java.util.List;
+import java.io.*;
+import java.lang.reflect.*;
+import java.util.*;
-import org.punit.convention.Convention;
-import org.punit.events.*;
-import org.punit.runner.RunnerProperties;
-import org.punit.watcher.Watcher;
+import org.punit.convention.*;
+import org.punit.runner.*;
+import org.punit.watcher.*;
public interface MethodRunner extends Serializable, Cloneable {
/**
@@ -19,11 +18,7 @@
*/
public void run(Object testInstance, Method method, Object[] params);
- /**
- *
- * @param eventListeners List <EventListener>
- */
- public void setEventListeners(List<EventListener> eventListeners);
+ public void setRunner(AbstractRunner runner);
public void setRunnerProperties(RunnerProperties props);
Modified: trunk/punit/src/org/punit/method/runner/SoloMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/SoloMethodRunner.java 2008-03-16 18:47:12 UTC (rev 284)
+++ trunk/punit/src/org/punit/method/runner/SoloMethodRunner.java 2008-03-18 10:21:37 UTC (rev 285)
@@ -3,6 +3,7 @@
package org.punit.method.runner;
+
public class SoloMethodRunner extends AbstractMethodRunner {
private static final long serialVersionUID = 3278612571978181393L;
@@ -10,5 +11,4 @@
protected void runImpl() throws Throwable {
runMethod();
}
-
}
Deleted: trunk/punit/src/org/punit/method/runner/VanillaRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/VanillaRunner.java 2008-03-16 18:47:12 UTC (rev 284)
+++ trunk/punit/src/org/punit/method/runner/VanillaRunner.java 2008-03-18 10:21:37 UTC (rev 285)
@@ -1,73 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-package org.punit.method.runner;
-
-import java.util.*;
-
-import org.punit.events.EventListener;
-import org.punit.method.builder.*;
-import org.punit.reporter.*;
-import org.punit.runner.*;
-import org.punit.suite.builder.*;
-
-public class VanillaRunner implements Runner {
-
- private static final long serialVersionUID = -3536655499041726649L;
-
- private Runner _runner;
-
- public VanillaRunner(Runner runner) {
- _runner = runner;
- }
-
- public TestMethodBuilder methodBuilder() {
- return _runner.methodBuilder();
- }
-
- public MethodRunner methodRunner() {
- return _runner.methodRunner();
- }
-
- public RunnerProperties properties() {
- return _runner.properties();
- }
-
- public void resultFolder(String folder) {
- _runner.resultFolder(folder);
- }
-
- public String resultFolder() {
- return _runner.resultFolder();
- }
-
- public int run(Class<?> clazz) {
- return _runner.run(clazz);
- }
-
- public int run(Class<?> clazz, RunnerProperties properties) {
- return _runner.run(clazz, properties);
- }
-
- public TestSuiteBuilder suiteBuilder() {
- return _runner.suiteBuilder();
- }
-
- public TestResult testResult() {
- return _runner.testResult();
- }
-
- public void addEventListener(EventListener listener) {
- _runner.addEventListener(listener);
- }
-
- public List<EventListener> eventListeners() {
- return _runner.eventListeners();
- }
-
- public void removeEventListener(EventListener listener) {
- _runner.removeEventListener(listener);
- }
-
- public String punitName() {
- return _runner.punitName();
- }
-}
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2008-03-16 18:47:12 UTC (rev 284)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2008-03-18 10:21:37 UTC (rev 285)
@@ -28,6 +28,8 @@
private MethodRunner _methodRunner;
private final List<EventListener> _eventListeners = new ArrayList<EventListener>();
+
+ private final List<EventListener> _internalEventListeners = new ArrayList<EventListener>();
private TestResult _testResult = new TestResult();
@@ -46,10 +48,10 @@
_testSuiteBuiler = testSuiteBuiler;
_testMethodBuilder = testMethodBuilder;
_methodRunner = testMethodRunner;
- _methodRunner.setEventListeners(_eventListeners);
+ _methodRunner.setRunner(this);
_methodRunner.setRunnerProperties(_properties);
registerDefaultListeners();
- setConvention(new NameConvention());
+ setConvention(new ByNameConvention());
}
public void setConvention(Convention convention) {
@@ -196,24 +198,7 @@
sb.append(runnerPropertiesFileName(vm));
return sb.toString();
}
-
- private void onRunnerStart(final Class<?> clazz) {
- Iterator <EventListener> iter = _eventListeners.iterator();
- while(iter.hasNext()) {
- EventListener listener = iter.next();
- listener.onRunnerStart(clazz, AbstractRunner.this);
- }
-
- }
-
- private void onRunnerEnd(final Class<?> clazz) {
- Iterator <EventListener> iter = _eventListeners.iterator();
- while(iter.hasNext()) {
- EventListener listener = iter.next();
- listener.onRunnerEnd(clazz, AbstractRunner.this);
- }
- }
-
+
private void runTestClass(final Class<?> clazz) {
if (_executorPool == null) {
runTestClassImpl(clazz);
@@ -249,7 +234,7 @@
}
private void runTestClassImpl(final Class<?> clazz) {
- final Object testInstance = ReflectionUtil.newInstance(clazz);
+ final Object testInstance = ReflectionUtil.newInstance(clazz);
Throwable exception = null;
Collection<Method> testMethods = extractTestMethods(clazz);
onClassStart(testInstance);
@@ -290,49 +275,82 @@
}
}
+ private void onRunnerStart(final Class<?> clazz) {
+ notifyListeners(new Notifier() {
+ public void run(EventListener listener) {
+ listener.onRunnerStart(clazz, AbstractRunner.this);
+ }
+ });
+ }
+
+ private void onRunnerEnd(final Class<?> clazz) {
+ notifyListeners(new Notifier() {
+ public void run(EventListener listener) {
+ listener.onRunnerEnd(clazz, AbstractRunner.this);
+ }
+ });
+ }
+
private void onSuite(final TestSuiteLabel suiteLabel) {
- Iterator<EventListener> iter = _eventListeners.iterator();
- while (iter.hasNext()) {
- EventListener listener = iter.next();
- TestSuite suite = suiteLabel.suite();
- if (suiteLabel.isStart()) {
- listener.onSuiteStart(suite);
- } else {
- listener.onSuiteEnd(suite);
+ notifyListeners(new Notifier() {
+ public void run(EventListener listener) {
+ TestSuite suite = suiteLabel.suite();
+ if (suiteLabel.isStart()) {
+ listener.onSuiteStart(suite);
+ } else {
+ listener.onSuiteEnd(suite);
+ }
}
- }
+ });
}
private void onClassStart(final Object testInstance) {
- Iterator<EventListener> iter = _eventListeners.iterator();
- while (iter.hasNext()) {
- EventListener listener = iter.next();
- listener.onClassStart(testInstance);
- }
+ notifyListeners(new Notifier() {
+ public void run(EventListener listener) {
+ listener.onClassStart(testInstance);
+ }
+ });
}
private void onClassEnd(final Object testInstance, final Throwable t) {
- Iterator<EventListener> iter = _eventListeners.iterator();
- while (iter.hasNext()) {
+ notifyListeners(new Notifier() {
+ public void run(EventListener listener) {
+ listener.onClassEnd(testInstance, t);
+ }
+ });
+ }
+
+ public void notifyListeners(Notifier notifier) {
+ notifyListeners(_internalEventListeners, notifier);
+ notifyListeners(_eventListeners, notifier);
+ }
+
+ private void notifyListeners(List<EventListener> listeners,
+ Notifier notifier) {
+ Iterator<EventListener> iter = listeners.iterator();
+ while (iter.hasNext()) {
EventListener listener = iter.next();
- listener.onClassEnd(testInstance, t);
+ notifier.run(listener);
}
}
-
+
private void runTestMethod(Object testInstance, Method method) {
if (_convention.isParameterizedTest(testInstance.getClass())) {
Parameterized pInstance = (Parameterized) testInstance;
Parameter[] params = pInstance.parameters();
for (int i = 0; i < params.length; ++i) {
- _methodRunner.run(testInstance, method,
- new Object[] { params[i] });
+ runTestMethod(testInstance, method, new Object[] { params[i] });
}
} else {
- _methodRunner.run(testInstance, method, new Object[] {});
+ runTestMethod(testInstance, method, new Object[] {});
}
}
+
+ private void runTestMethod(Object testInstance, Method method, Object[] params) {
+ _methodRunner.run(testInstance, method, params);
+ }
- private Collection<Method> extractTestMethods(Class<?> testClass) {
+ private Collection<Method> extractTestMethods(Class<?> testClass) {
return _testMethodBuilder.extractTestMethods(testClass);
}
@@ -349,7 +367,7 @@
}
private void registerDefaultListeners() {
- addEventListener(_testResult);
+ addInternalEventListener(_testResult);
addEventListener(_consoleLogger);
}
@@ -360,6 +378,10 @@
public void addEventListener(EventListener listener) {
_eventListeners.add(listener);
}
+
+ private void addInternalEventListener(EventListener listener) {
+ _internalEventListeners.add(listener);
+ }
public void removeEventListener(EventListener listener) {
_eventListeners.remove(listener);
Added: trunk/punit/src/org/punit/runner/Notifier.java
===================================================================
--- trunk/punit/src/org/punit/runner/Notifier.java (rev 0)
+++ trunk/punit/src/org/punit/runner/Notifier.java 2008-03-18 10:21:37 UTC (rev 285)
@@ -0,0 +1,7 @@
+package org.punit.runner;
+
+import org.punit.events.*;
+
+public interface Notifier {
+ public void run(EventListener listener);
+}
Property changes on: trunk/punit/src/org/punit/runner/Notifier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: trunk/punit/src/org/punit/runner/VanillaRunner.java (from rev 270, trunk/punit/src/org/punit/method/runner/VanillaRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/VanillaRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/VanillaRunner.java 2008-03-18 10:21:37 UTC (rev 285)
@@ -0,0 +1,73 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+package org.punit.runner;
+
+import java.util.*;
+
+import org.punit.events.EventListener;
+import org.punit.method.builder.*;
+import org.punit.method.runner.*;
+import org.punit.reporter.*;
+import org.punit.suite.builder.*;
+
+public class VanillaRunner implements Runner {
+
+ private static final long serialVersionUID = -3536655499041726649L;
+
+ private Runner _runner;
+
+ public VanillaRunner(Runner runner) {
+ _runner = runner;
+ }
+
+ public TestMethodBuilder methodBuilder() {
+ return _runner.methodBuilder();
+ }
+
+ public MethodRunner methodRunner() {
+ return _runner.methodRunner();
+ }
+
+ public RunnerProperties properties() {
+ return _runner.properties();
+ }
+
+ public void resultFolder(String folder) {
+ _runner.resultFolder(folder);
+ }
+
+ public String resultFolder() {
+ return _runner.resultFolder();
+ }
+
+ public int run(Class<?> clazz) {
+ return _runner.run(clazz);
+ }
+
+ public int run(Class<?> clazz, RunnerProperties properties) {
+ return _runner.run(clazz, properties);
+ }
+
+ public TestSuiteBuilder suiteBuilder() {
+ return _runner.suiteBuilder();
+ }
+
+ public TestResult testResult() {
+ return _runner.testResult();
+ }
+
+ public void addEventListener(EventListener listener) {
+ _runner.addEventListener(listener);
+ }
+
+ public List<EventListener> eventListeners() {
+ return _runner.eventListeners();
+ }
+
+ public void removeEventListener(EventListener listener) {
+ _runner.removeEventListener(listener);
+ }
+
+ public String punitName() {
+ return _runner.punitName();
+ }
+}
Modified: trunk/punit/src/org/punit/util/ReflectionUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ReflectionUtil.java 2008-03-16 18:47:12 UTC (rev 284)
+++ trunk/punit/src/org/punit/util/ReflectionUtil.java 2008-03-18 10:21:37 UTC (rev 285)
@@ -124,6 +124,15 @@
throw new ReflectionException(e.getTargetException());
}
}
+
+ public static Object invokeMethodWithException(Method method, Object instance,
+ Object[] params) throws Throwable {
+ try {
+ return method.invoke(instance, params);
+ } catch (InvocationTargetException e) {
+ throw e.getTargetException();
+ }
+ }
public static boolean isPublic(Method method) {
int modifier = method.getModifiers();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-03-16 18:47:06
|
Revision: 284
http://p-unit.svn.sourceforge.net/p-unit/?rev=284&view=rev
Author: zhanghuangzhu
Date: 2008-03-16 11:47:12 -0700 (Sun, 16 Mar 2008)
Log Message:
-----------
Andrew Zhang: refactored test.
Modified Paths:
--------------
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/suite/builder/TestSuiteBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java
trunk/punit.test/src/tests/util/AssertUtil.java
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2008-03-16 18:47:02 UTC (rev 283)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2008-03-16 18:47:12 UTC (rev 284)
@@ -1,21 +1,16 @@
package tests.api.org.punit.all;
-import org.punit.method.runner.*;
-
import junit.framework.*;
-import tests.api.org.punit.assertion.AssertTest;
+import tests.api.org.punit.assertion.*;
import tests.api.org.punit.convention.*;
-import tests.api.org.punit.exception.ConcurrentExceptionTest;
-import tests.api.org.punit.method.builder.TestMethodBuilderTest;
+import tests.api.org.punit.exception.*;
+import tests.api.org.punit.method.builder.*;
import tests.api.org.punit.method.runner.*;
-import tests.api.org.punit.reporter.stream.StreamLoggerTest;
+import tests.api.org.punit.reporter.stream.*;
import tests.api.org.punit.runner.*;
import tests.api.org.punit.suite.builder.*;
-import tests.api.org.punit.util.LoggerUtilTest;
-import tests.api.org.punit.util.ReflectionUtilTest;
-import tests.api.org.punit.watcher.CustomWatcherTest;
-import tests.api.org.punit.watcher.MemoryWatcherTest;
-import tests.api.org.punit.watcher.TimeWatcherTest;
+import tests.api.org.punit.util.*;
+import tests.api.org.punit.watcher.*;
public class AllTests {
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 2008-03-16 18:47:02 UTC (rev 283)
+++ trunk/punit.test/src/tests/api/org/punit/suite/builder/TestSuiteBuilderTest.java 2008-03-16 18:47:12 UTC (rev 284)
@@ -9,99 +9,65 @@
import tests.util.*;
public class TestSuiteBuilderTest extends TestCase {
- private TestSuiteBuilderImpl _testSuiteBuidler;
+ private TestSuiteBuilderImpl _testSuiteBuidler;
- protected void setUp() throws Exception {
- _testSuiteBuidler = new TestSuiteBuilderImpl();
- _testSuiteBuidler.setConvention(new NameConvention());
- }
+ protected void setUp() throws Exception {
+ _testSuiteBuidler = new TestSuiteBuilderImpl();
+ _testSuiteBuidler.setConvention(new NameConvention());
+ }
- public void testBuildExcludedTestClasses1() {
- _testSuiteBuidler.setConvention(new AnnotationConvention());
- Object[] classes = _testSuiteBuidler.buildTestClasses(ExcludedTestClass1.class);
- AssertUtil.assertArray(classes, new Class[] { });
- }
-
- public void testBuildTestClasses1() {
- Object[] classes = _testSuiteBuidler.buildTestClasses(TestClass1.class);
- AssertUtil.assertArray(classes, new Class[] { TestClass1.class });
- }
+ public void testBuildExcludedTestClasses1() {
+ _testSuiteBuidler.setConvention(new AnnotationConvention());
+ Object[] classes = _testSuiteBuidler
+ .buildTestClasses(ExcludedTestClass1.class);
+ AssertUtil.assertArray(new Class[] {}, classes);
+ }
- public void testBuildTestSuite1() {
- Object[] classes = _testSuiteBuidler.buildTestClasses(TestSuite1.class);
- Class<?>[] expectedClasses = new Class[] { TestClass1.class,
- TestClass2.class, AlphabeticalTestClass.class };
-
- assertEquals(expectedClasses.length + 2, classes.length); // suite labels
-
- TestSuiteLabel label = (TestSuiteLabel) classes[0];
- assertSame(TestSuite1.class, label.suite().getClass());
- assertTrue(label.isStart());
-
- label = (TestSuiteLabel) classes[classes.length - 1];
- assertSame(TestSuite1.class, label.suite().getClass());
- assertFalse(label.isStart());
-
- AssertUtil.assertArrayContains(classes, expectedClasses);
- }
+ public void testBuildTestClasses1() {
+ Object[] classes = _testSuiteBuidler.buildTestClasses(TestClass1.class);
+ AssertUtil.assertArray(new Class[] { TestClass1.class }, classes);
+ }
- public void testBuildTestSuite2() {
- Object[] classes = _testSuiteBuidler.buildTestClasses(TestSuite2.class);
- Class<?>[] expectedClasses = new Class[] {
- TestClass4.class,
- TestClass1.class,
- TestClass2.class,
- AlphabeticalTestClass.class,
- TestClass5.class
- };
-
- assertEquals(expectedClasses.length + 4, classes.length); // suite labels
-
- TestSuiteLabel label = (TestSuiteLabel) classes[0];
- assertSame(TestSuite2.class, label.suite().getClass());
- assertTrue(label.isStart());
-
- label = (TestSuiteLabel) classes[classes.length - 1];
- assertSame(TestSuite2.class, label.suite().getClass());
- assertFalse(label.isStart());
-
- label = (TestSuiteLabel) classes[2];
- assertSame(TestSuite1.class, label.suite().getClass());
- assertTrue(label.isStart());
-
- label = (TestSuiteLabel) classes[6];
- assertSame(TestSuite1.class, label.suite().getClass());
- assertFalse(label.isStart());
-
- AssertUtil.assertArrayContains(classes, expectedClasses);
- }
-
- public void testBuildTestSuite2ByAnnotationFilter() {
- _testSuiteBuidler.setConvention(new AnnotationConvention());
- Object[] classes = _testSuiteBuidler.buildTestClasses(TestSuite2.class);
- Class<?>[] expectedClasses = new Class[] { TestClass4.class,
- TestClass1.class, TestClass2.class, AlphabeticalTestClass.class, TestClass5.class };
-
- assertEquals(expectedClasses.length + 4, classes.length); // suite labels
-
- TestSuiteLabel label = (TestSuiteLabel) classes[0];
- assertSame(TestSuite2.class, label.suite().getClass());
- assertTrue(label.isStart());
-
- label = (TestSuiteLabel) classes[classes.length - 1];
- assertSame(TestSuite2.class, label.suite().getClass());
- assertFalse(label.isStart());
-
- label = (TestSuiteLabel) classes[2];
- assertSame(TestSuite1.class, label.suite().getClass());
- assertTrue(label.isStart());
-
- label = (TestSuiteLabel) classes[6];
- assertSame(TestSuite1.class, label.suite().getClass());
- assertFalse(label.isStart());
-
- AssertUtil.assertArrayContains(classes, expectedClasses);
- }
+ public void testBuildTestSuite1() {
+ Object[] classes = _testSuiteBuidler.buildTestClasses(TestSuite1.class);
+ Object[] expectedClasses = new Object[] {
+ new TestSuiteLabelImpl(new TestSuite1(), true),
+ TestClass1.class,
+ TestClass2.class,
+ AlphabeticalTestClass.class,
+ new TestSuiteLabelImpl(new TestSuite1(), false),
+ };
+ AssertUtil.assertArray(expectedClasses, classes);
+ }
+ public void testBuildTestSuite2() {
+ Convention [] conventions = new Convention[] {
+ new NameConvention(),
+ new AnnotationConvention(),
+ };
+
+ for(Convention convention : conventions) {
+ _testSuiteBuidler.setConvention(convention);
+ assertTestSuite2();
+ }
+ }
+
+ private void assertTestSuite2() {
+ Object[] classes = _testSuiteBuidler.buildTestClasses(TestSuite2.class);
+ Object[] expectedClasses = new Object[] {
+ new TestSuiteLabelImpl(new TestSuite2(), true),
+ TestClass4.class,
+ new TestSuiteLabelImpl(new TestSuite1(), true),
+ TestClass1.class,
+ TestClass2.class,
+ AlphabeticalTestClass.class,
+ new TestSuiteLabelImpl(new TestSuite1(), false),
+ TestClass5.class,
+ new TestSuiteLabelImpl(new TestSuite2(), false),
+ };
+
+ AssertUtil.assertArray(expectedClasses, classes);
+ }
+
}
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java 2008-03-16 18:47:02 UTC (rev 283)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java 2008-03-16 18:47:12 UTC (rev 284)
@@ -1,7 +1,7 @@
package tests.api.org.punit.testclasses;
public class TestSuite1 implements org.punit.type.TestSuite {
- public Class[] testSuite() {
+ public Class<?>[] testSuite() {
return new Class[] {
TestClass1.class,
TestClass2.class,
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java 2008-03-16 18:47:02 UTC (rev 283)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java 2008-03-16 18:47:12 UTC (rev 284)
@@ -1,7 +1,7 @@
package tests.api.org.punit.testclasses;
public class TestSuite2 implements org.punit.type.TestSuite {
- public Class[] testSuite() {
+ public Class<?>[] testSuite() {
return new Class[] {
TestClass4.class,
TestSuite1.class,
Modified: trunk/punit.test/src/tests/util/AssertUtil.java
===================================================================
--- trunk/punit.test/src/tests/util/AssertUtil.java 2008-03-16 18:47:02 UTC (rev 283)
+++ trunk/punit.test/src/tests/util/AssertUtil.java 2008-03-16 18:47:12 UTC (rev 284)
@@ -41,7 +41,7 @@
Assert.assertTrue(isInArray(o, array));
}
- public static void assertException(Class throwable, CodeRunner code) {
+ public static void assertException(Class<? extends Throwable> throwable, CodeRunner code) {
try {
code.run();
Assert.fail(throwable + " expected!"); //$NON-NLS-1$
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-03-16 18:46:58
|
Revision: 283
http://p-unit.svn.sourceforge.net/p-unit/?rev=283&view=rev
Author: zhanghuangzhu
Date: 2008-03-16 11:47:02 -0700 (Sun, 16 Mar 2008)
Log Message:
-----------
Andrew Zhang: refactored test.
Modified Paths:
--------------
trunk/punit/src/org/punit/suite/builder/TestSuiteLabelImpl.java
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteLabelImpl.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteLabelImpl.java 2008-03-16 16:21:05 UTC (rev 282)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteLabelImpl.java 2008-03-16 18:47:02 UTC (rev 283)
@@ -25,4 +25,14 @@
public boolean isStart() {
return _isStart;
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof TestSuiteLabel)) {
+ return false;
+ }
+ TestSuiteLabel label = (TestSuiteLabel) obj;
+ return label.isStart() == _isStart
+ && label.suite().getClass() == _suite.getClass();
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-03-16 16:21:00
|
Revision: 282
http://p-unit.svn.sourceforge.net/p-unit/?rev=282&view=rev
Author: zhanghuangzhu
Date: 2008-03-16 09:21:05 -0700 (Sun, 16 Mar 2008)
Log Message:
-----------
Andrew Zhang: cleanup code.
Modified Paths:
--------------
trunk/punit.extension.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.extension.test/src/tests/api/org/punit/all/PUnitAllTests.java
Removed Paths:
-------------
trunk/punit.extension.test/src/tests/api/org/punit/method/
trunk/punit.extension.test/src/tests/api/org/punit/suite/
Modified: trunk/punit.extension.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.extension.test/src/tests/api/org/punit/all/AllTests.java 2008-03-15 00:09:28 UTC (rev 281)
+++ trunk/punit.extension.test/src/tests/api/org/punit/all/AllTests.java 2008-03-16 16:21:05 UTC (rev 282)
@@ -2,10 +2,8 @@
import junit.framework.*;
import tests.api.org.punit.convention.*;
-import tests.api.org.punit.method.runner.*;
import tests.api.org.punit.reporter.chart.*;
import tests.api.org.punit.runner.*;
-import tests.api.org.punit.suite.builder.*;
public class AllTests {
Modified: trunk/punit.extension.test/src/tests/api/org/punit/all/PUnitAllTests.java
===================================================================
--- trunk/punit.extension.test/src/tests/api/org/punit/all/PUnitAllTests.java 2008-03-15 00:09:28 UTC (rev 281)
+++ trunk/punit.extension.test/src/tests/api/org/punit/all/PUnitAllTests.java 2008-03-16 16:21:05 UTC (rev 282)
@@ -9,7 +9,7 @@
new SoloRunner().run(PUnitAllTests.class);
}
- public Class[] testSuite() {
+ public Class<?> [] testSuite() {
return AllTests.testSuite();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-03-15 00:09:25
|
Revision: 281
http://p-unit.svn.sourceforge.net/p-unit/?rev=281&view=rev
Author: zhanghuangzhu
Date: 2008-03-14 17:09:28 -0700 (Fri, 14 Mar 2008)
Log Message:
-----------
remove unused code
Modified Paths:
--------------
trunk/punit/src/org/punit/util/MemoryUtil.java
Modified: trunk/punit/src/org/punit/util/MemoryUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/MemoryUtil.java 2008-02-26 05:52:34 UTC (rev 280)
+++ trunk/punit/src/org/punit/util/MemoryUtil.java 2008-03-15 00:09:28 UTC (rev 281)
@@ -1,7 +1,5 @@
package org.punit.util;
-import org.punit.assertion.Assert;
-import org.punit.exception.OutOfMemoryException;
public class MemoryUtil {
@@ -24,26 +22,4 @@
}
ThreadUtil.sleepIgnoreInterruption(100);
}
-
- private static final int WILDERNESS_SIZE = 4096;
-
- private static byte[] _wilderness;
-
- static {
- allocateWilderness();
- }
-
- public static void allocateWilderness() {
- Assert.assertNull(_wilderness);
- try {
- _wilderness = new byte[WILDERNESS_SIZE];
- } catch (OutOfMemoryError oome) {
- throw new OutOfMemoryException(oome);
- }
- }
-
- public static void releaseWilderness() {
- Assert.assertNotNull(_wilderness);
- _wilderness = null;
- }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-02-26 05:52:29
|
Revision: 280
http://p-unit.svn.sourceforge.net/p-unit/?rev=280&view=rev
Author: zhanghuangzhu
Date: 2008-02-25 21:52:34 -0800 (Mon, 25 Feb 2008)
Log Message:
-----------
Andrew Zhang: find setUp method from the superclass too.
Modified Paths:
--------------
trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java
Modified: trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java 2008-02-26 05:51:41 UTC (rev 279)
+++ trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java 2008-02-26 05:52:34 UTC (rev 280)
@@ -52,11 +52,13 @@
public void testGetSetUpMethod() {
assertNotNull(_convention.getSetUpMethod(TestClass0.class));
+ assertNotNull(_convention.getSetUpMethod(TestSubClass.class));
assertNull(_convention.getSetUpMethod(TestClass1.class));
}
public void testGetTearDownMethod() {
assertNotNull(_convention.getTearDownMethod(TestClass0.class));
+ assertNotNull(_convention.getTearDownMethod(TestSubClass.class));
assertNull(_convention.getTearDownMethod(TestClass1.class));
}
@@ -100,4 +102,18 @@
public void check__test3() {
}
+
+ private static class TestBase {
+ public void setUp() {
+
+ }
+ public void tearDown() {
+
+ }
+ }
+
+ private static class TestSubClass extends TestBase {
+
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-02-26 05:51:36
|
Revision: 279
http://p-unit.svn.sourceforge.net/p-unit/?rev=279&view=rev
Author: zhanghuangzhu
Date: 2008-02-25 21:51:41 -0800 (Mon, 25 Feb 2008)
Log Message:
-----------
Andrew Zhang: find setUp method from the superclass too.
Modified Paths:
--------------
trunk/punit/core.jardesc
trunk/punit/src/org/punit/convention/NameConvention.java
trunk/punit/src/org/punit/util/ReflectionUtil.java
Modified: trunk/punit/core.jardesc
===================================================================
--- trunk/punit/core.jardesc 2008-02-20 12:18:41 UTC (rev 278)
+++ trunk/punit/core.jardesc 2008-02-26 05:51:41 UTC (rev 279)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="GBK" standalone="no"?>
<jardesc>
- <jar path="E:/workspace/p-unit/release/p-unit-0.14.jar"/>
+ <jar path="E:/workspace/p-unit/release/p-unit-0.14.257.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/punit/core.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/>
Modified: trunk/punit/src/org/punit/convention/NameConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/NameConvention.java 2008-02-20 12:18:41 UTC (rev 278)
+++ trunk/punit/src/org/punit/convention/NameConvention.java 2008-02-26 05:51:41 UTC (rev 279)
@@ -76,7 +76,7 @@
}
public Method getAfterClassMethod(Class<?> test) {
- Method method = ReflectionUtil.getMethodAndSetAccessible(test,
+ Method method = ReflectionUtil.getMethodAndSetAccessibleWithAncestor(test,
"afterClass", new Class[] {}); //$NON-NLS-1$
if (method != null && ReflectionUtil.isStatic(method)) {
return method;
@@ -85,7 +85,7 @@
}
public Method getBeforeClassMethod(Class<?> test) {
- Method method = ReflectionUtil.getMethodAndSetAccessible(test,
+ Method method = ReflectionUtil.getMethodAndSetAccessibleWithAncestor(test,
"beforeClass", new Class[] {}); //$NON-NLS-1$
if (method != null && ReflectionUtil.isStatic(method)) {
return method;
@@ -94,12 +94,12 @@
}
public Method getSetUpMethod(Class<?> test) {
- return ReflectionUtil.getMethodAndSetAccessible(test,
+ return ReflectionUtil.getMethodAndSetAccessibleWithAncestor(test,
"setUp", new Class[] {}); //$NON-NLS-1$
}
public Method getTearDownMethod(Class<?> test) {
- return ReflectionUtil.getMethodAndSetAccessible(test,
+ return ReflectionUtil.getMethodAndSetAccessibleWithAncestor(test,
"tearDown", new Class[] {}); //$NON-NLS-1$
}
}
Modified: trunk/punit/src/org/punit/util/ReflectionUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ReflectionUtil.java 2008-02-20 12:18:41 UTC (rev 278)
+++ trunk/punit/src/org/punit/util/ReflectionUtil.java 2008-02-26 05:51:41 UTC (rev 279)
@@ -12,108 +12,130 @@
public class ReflectionUtil {
- public static Object newInstance(Class<?> clazz) {
- try {
- Constructor<?> constructor = clazz
- .getDeclaredConstructor(new Class[] {});
- constructor.setAccessible(true);
- return constructor.newInstance(new Object[] {});
- } catch (Exception e) {
- throw new ReflectionException(e);
- }
- }
+ public static Object newInstance(Class<?> clazz) {
+ try {
+ Constructor<?> constructor = clazz
+ .getDeclaredConstructor(new Class[] {});
+ constructor.setAccessible(true);
+ return constructor.newInstance(new Object[] {});
+ } catch (Exception e) {
+ throw new ReflectionException(e);
+ }
+ }
- public static Class<?> newClass(String className) {
- try {
- return Class.forName(className);
- } catch (Exception e) {
- throw new ReflectionException(e);
- }
- }
+ public static Class<?> newClass(String className) {
+ try {
+ return Class.forName(className);
+ } catch (Exception e) {
+ throw new ReflectionException(e);
+ }
+ }
- public static Method getMethod(Class<?> clazz, String methodName,
- Class<?>[] params) {
- try {
- Method method = clazz.getDeclaredMethod(methodName, params);
- return method;
- } catch (Exception e) {
- return null;
- }
- }
+ public static Method getMethod(Class<?> clazz, String methodName,
+ Class<?>[] params) {
+ try {
+ Method method = clazz.getDeclaredMethod(methodName, params);
+ return method;
+ } catch (Exception e) {
+ return null;
+ }
+ }
- /**
- * Sets a field with a given value after converting the value to the field
- * type.
- *
- * @param field
- * the field to assign
- * @param value
- * the string value to assign
- */
- public static void setField(Object testInstance, Field field, String value) {
- try {
- field.setAccessible(true);
- Class<?> fieldClass = field.getType();
- if (fieldClass.equals(int.class)) {
- int intVal = Integer.parseInt(value);
- field.setInt(testInstance, intVal);
- } else if (fieldClass.equals(long.class)) {
- long longVal = Long.parseLong(value);
+ /**
+ * Sets a field with a given value after converting the value to the field
+ * type.
+ *
+ * @param field
+ * the field to assign
+ * @param value
+ * the string value to assign
+ */
+ public static void setField(Object testInstance, Field field, String value) {
+ try {
+ field.setAccessible(true);
+ Class<?> fieldClass = field.getType();
+ if (fieldClass.equals(int.class)) {
+ int intVal = Integer.parseInt(value);
+ field.setInt(testInstance, intVal);
+ } else if (fieldClass.equals(long.class)) {
+ long longVal = Long.parseLong(value);
- field.setLong(testInstance, longVal);
- } else {
- field.set(testInstance, value);
- }
- } catch (NumberFormatException nfe) {
- throw new IllegalArgumentException(nfe);
- } catch (Exception e) {
- throw new ReflectionException(e);
- }
- }
+ field.setLong(testInstance, longVal);
+ } else {
+ field.set(testInstance, value);
+ }
+ } catch (NumberFormatException nfe) {
+ throw new IllegalArgumentException(nfe);
+ } catch (Exception e) {
+ throw new ReflectionException(e);
+ }
+ }
- /**
- * Gets the method and sets the accessible to true
- *
- * @param clazz
- * @param methodName
- * @param params
- * @return
- */
- public static Method getMethodAndSetAccessible(Class<?> clazz,
- String methodName, Class<?>[] params) {
- try {
- Method method = clazz.getDeclaredMethod(methodName, params);
- method.setAccessible(true);
- return method;
- } catch (Exception e) {
- return null;
- }
- }
+ /**
+ * Gets the method and sets the accessible to true
+ *
+ * @param clazz
+ * @param methodName
+ * @param params
+ * @return
+ */
+ public static Method getMethodAndSetAccessible(Class<?> clazz,
+ String methodName, Class<?>[] params) {
+ try {
+ Method method = clazz.getDeclaredMethod(methodName, params);
+ method.setAccessible(true);
+ return method;
+ } catch (Exception e) {
+ return null;
+ }
+ }
- public static Object invokeMethod(Method method, Object instance,
- Object[] params) throws ReflectionException {
- try {
- return method.invoke(instance, params);
- } catch (IllegalArgumentException e) {
- throw new ReflectionException(e);
- } catch (IllegalAccessException e) {
- throw new ReflectionException(e);
- } catch (InvocationTargetException e) {
- throw new ReflectionException(e.getTargetException());
- }
- }
+ /**
+ * Gets the method from this class or its superclass. Sets the accessible
+ * of this method to true.
+ *
+ * @param clazz
+ * @param methodName
+ * @param params
+ * @return
+ */
+ public static Method getMethodAndSetAccessibleWithAncestor(Class<?> clazz,
+ String methodName, Class<?>[] params) {
+ Class<?> currentClass = clazz;
+ while (currentClass != null) {
+ Method method = getMethodAndSetAccessible(currentClass, methodName, params);
+ if(method != null) {
+ return method;
+ }
+ currentClass = currentClass.getSuperclass();
+ }
+ return null;
+ }
- public static boolean isPublic(Method method) {
- int modifier = method.getModifiers();
- return isBitSet(modifier, Modifier.PUBLIC);
- }
+ public static Object invokeMethod(Method method, Object instance,
+ Object[] params) throws ReflectionException {
+ try {
+ return method.invoke(instance, params);
+ } catch (IllegalArgumentException e) {
+ throw new ReflectionException(e);
+ } catch (IllegalAccessException e) {
+ throw new ReflectionException(e);
+ } catch (InvocationTargetException e) {
+ throw new ReflectionException(e.getTargetException());
+ }
+ }
- public static boolean isStatic(Method method) {
- int modifier = method.getModifiers();
- return isBitSet(modifier, Modifier.STATIC);
- }
+ public static boolean isPublic(Method method) {
+ int modifier = method.getModifiers();
+ return isBitSet(modifier, Modifier.PUBLIC);
+ }
- private static boolean isBitSet(int value, int expectedBit) {
- return (value & expectedBit) != 0;
- }
+ public static boolean isStatic(Method method) {
+ int modifier = method.getModifiers();
+ return isBitSet(modifier, Modifier.STATIC);
+ }
+
+ private static boolean isBitSet(int value, int expectedBit) {
+ return (value & expectedBit) != 0;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-02-20 12:18:40
|
Revision: 278
http://p-unit.svn.sourceforge.net/p-unit/?rev=278&view=rev
Author: zhanghuangzhu
Date: 2008-02-20 04:18:41 -0800 (Wed, 20 Feb 2008)
Log Message:
-----------
more friendly error message
Modified Paths:
--------------
trunk/punit/src/org/punit/assertion/Assert.java
trunk/punit/src/org/punit/message/MessageStrings.java
Modified: trunk/punit/src/org/punit/assertion/Assert.java
===================================================================
--- trunk/punit/src/org/punit/assertion/Assert.java 2008-02-20 11:50:32 UTC (rev 277)
+++ trunk/punit/src/org/punit/assertion/Assert.java 2008-02-20 12:18:41 UTC (rev 278)
@@ -95,6 +95,6 @@
}
private static void fail(Object expected, Object actual) {
- fail(Messages.getString("assert.expected") + " " + expected + Messages.getString("assert.got") + " " + actual); //$NON-NLS-2$
+ fail(Messages.getString("assert.expected") + "\"" + expected + "\"" + Messages.getString("assert.got") + "\"" + actual + "\""); //$NON-NLS-2$
}
}
Modified: trunk/punit/src/org/punit/message/MessageStrings.java
===================================================================
--- trunk/punit/src/org/punit/message/MessageStrings.java 2008-02-20 11:50:32 UTC (rev 277)
+++ trunk/punit/src/org/punit/message/MessageStrings.java 2008-02-20 12:18:41 UTC (rev 278)
@@ -22,8 +22,8 @@
{"reporter.02", "overview"},
{"PDFRender.01", "PUnit result\n"},
{"PDFRender.02", "the open source performance benchmark framework\n"},
- {"assert.expected", "Expected"},
- {"assert.got", ", but got"},
+ {"assert.expected", "Expected "},
+ {"assert.got", ", but got "},
{"assert.notsame", "Expected a different object:"},
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-02-20 11:50:29
|
Revision: 277
http://p-unit.svn.sourceforge.net/p-unit/?rev=277&view=rev
Author: zhanghuangzhu
Date: 2008-02-20 03:50:32 -0800 (Wed, 20 Feb 2008)
Log Message:
-----------
Andrew Zhang: fixed display bugs
Modified Paths:
--------------
trunk/punit/src/org/punit/assertion/Assert.java
trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
Modified: trunk/punit/src/org/punit/assertion/Assert.java
===================================================================
--- trunk/punit/src/org/punit/assertion/Assert.java 2008-02-16 15:10:59 UTC (rev 276)
+++ trunk/punit/src/org/punit/assertion/Assert.java 2008-02-20 11:50:32 UTC (rev 277)
@@ -95,6 +95,6 @@
}
private static void fail(Object expected, Object actual) {
- fail(Messages.getString("assert.expected") + expected + Messages.getString("assert.got") + actual); //$NON-NLS-2$
+ fail(Messages.getString("assert.expected") + " " + expected + Messages.getString("assert.got") + " " + actual); //$NON-NLS-2$
}
}
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2008-02-16 15:10:59 UTC (rev 276)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2008-02-20 11:50:32 UTC (rev 277)
@@ -90,8 +90,8 @@
private void logFailures() {
List<Throwable> failures = _result.failures();
Iterator<Throwable> iter = failures.iterator();
+ int count = 0;
while (iter.hasNext()) {
- int count = 0;
log(++count + ")", Level.SEVERE); //$NON-NLS-1$
if (shouldLog(Level.SEVERE)) {
iter.next().printStackTrace(_writer);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-02-16 15:10:54
|
Revision: 276
http://p-unit.svn.sourceforge.net/p-unit/?rev=276&view=rev
Author: zhanghuangzhu
Date: 2008-02-16 07:10:59 -0800 (Sat, 16 Feb 2008)
Log Message:
-----------
Andrew Zhang: flush writer information after logFailures
Modified Paths:
--------------
trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
Added Paths:
-----------
trunk/punit/core.jardesc
Added: trunk/punit/core.jardesc
===================================================================
--- trunk/punit/core.jardesc (rev 0)
+++ trunk/punit/core.jardesc 2008-02-16 15:10:59 UTC (rev 276)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="GBK" standalone="no"?>
+<jardesc>
+ <jar path="E:/workspace/p-unit/release/p-unit-0.14.jar"/>
+ <options buildIfNeeded="true" compress="true" descriptionLocation="/punit/core.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
+ <storedRefactorings deprecationInfo="true" structuralOnly="false"/>
+ <selectedProjects/>
+ <manifest generateManifest="true" manifestLocation="" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
+ <sealing sealJar="false">
+ <packagesToSeal/>
+ <packagesToUnSeal/>
+ </sealing>
+ </manifest>
+ <selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
+ <javaElement handleIdentifier="=punit/src"/>
+ </selectedElements>
+</jardesc>
Property changes on: trunk/punit/core.jardesc
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2008-01-19 11:53:46 UTC (rev 275)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2008-02-16 15:10:59 UTC (rev 276)
@@ -94,9 +94,10 @@
int count = 0;
log(++count + ")", Level.SEVERE); //$NON-NLS-1$
if (shouldLog(Level.SEVERE)) {
- iter.next().printStackTrace(_writer);
+ iter.next().printStackTrace(_writer);
}
}
+ _writer.flush();
}
private void stopTimeWatcher() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-01-19 11:53:51
|
Revision: 275
http://p-unit.svn.sourceforge.net/p-unit/?rev=275&view=rev
Author: zhanghuangzhu
Date: 2008-01-19 03:53:46 -0800 (Sat, 19 Jan 2008)
Log Message:
-----------
Andrew Zhang: cleaned some unused code.
Modified Paths:
--------------
trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java
Modified: trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java 2008-01-19 11:53:14 UTC (rev 274)
+++ trunk/punit/src/org/punit/reporter/stream/console/ConsoleLogger.java 2008-01-19 11:53:46 UTC (rev 275)
@@ -18,10 +18,6 @@
public ConsoleLogger() {
super(new PrintWriter(System.err));
}
-
- public boolean supportParentRunner() {
- return false;
- }
protected void closeStream() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-01-19 11:53:16
|
Revision: 274
http://p-unit.svn.sourceforge.net/p-unit/?rev=274&view=rev
Author: zhanghuangzhu
Date: 2008-01-19 03:53:14 -0800 (Sat, 19 Jan 2008)
Log Message:
-----------
Andrew Zhang: cleaned some unused code.
Modified Paths:
--------------
trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java
Modified: trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java 2008-01-19 11:14:57 UTC (rev 273)
+++ trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java 2008-01-19 11:53:14 UTC (rev 274)
@@ -38,7 +38,4 @@
super.onRunnerStart(clazz, runner);
}
- public boolean supportParentRunner() {
- return false;
- }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-01-19 11:14:58
|
Revision: 273
http://p-unit.svn.sourceforge.net/p-unit/?rev=273&view=rev
Author: zhanghuangzhu
Date: 2008-01-19 03:14:57 -0800 (Sat, 19 Jan 2008)
Log Message:
-----------
Andrew Zhang: cleaned some unused code.
Modified Paths:
--------------
trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java
Modified: trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java 2008-01-11 16:03:50 UTC (rev 272)
+++ trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java 2008-01-19 11:14:57 UTC (rev 273)
@@ -1,4 +1,4 @@
-/* (C) Copyright 2007, by Andrew Zhang */
+ /* (C) Copyright 2007, by Andrew Zhang */
package org.punit.reporter.stream.file;
@@ -38,13 +38,6 @@
super.onRunnerStart(clazz, runner);
}
- public void onRunnerEnd(Class<?> clazz, Runner runner) {
- super.onRunnerEnd(clazz, runner);
- }
-
- public void close() {
- _writer.close();
- }
public boolean supportParentRunner() {
return false;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-01-11 16:03:45
|
Revision: 272
http://p-unit.svn.sourceforge.net/p-unit/?rev=272&view=rev
Author: zhanghuangzhu
Date: 2008-01-11 08:03:50 -0800 (Fri, 11 Jan 2008)
Log Message:
-----------
Andrew Zhang: more accurate assertion.
Modified Paths:
--------------
trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java
Modified: trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java 2008-01-11 15:57:50 UTC (rev 271)
+++ trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java 2008-01-11 16:03:50 UTC (rev 272)
@@ -61,12 +61,12 @@
}
public void testGetBeforeClass() {
- assertNotNull(_convention.getBeforeClassMethod(TestClass0.class));
+ assertEquals("beforeClass", _convention.getBeforeClassMethod(TestClass0.class).getName());
assertNull(_convention.getBeforeClassMethod(TestClass1.class));
}
public void testGetAfterClass() {
- assertNotNull(_convention.getAfterClassMethod(TestClass0.class));
+ assertEquals("afterClass", _convention.getAfterClassMethod(TestClass0.class).getName());
assertNull(_convention.getAfterClassMethod(TestClass1.class));
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-01-11 15:57:55
|
Revision: 271
http://p-unit.svn.sourceforge.net/p-unit/?rev=271&view=rev
Author: zhanghuangzhu
Date: 2008-01-11 07:57:50 -0800 (Fri, 11 Jan 2008)
Log Message:
-----------
Andrew Zhang: Looking forward, based on java 5 now.
Modified Paths:
--------------
trunk/punit.test/.settings/org.eclipse.jdt.core.prefs
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java
trunk/punit.test/src/tests/api/org/punit/runner/MockEventListener.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass0.java
Added Paths:
-----------
trunk/punit.test/src/tests/api/org/punit/convention/
trunk/punit.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java
trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java
trunk/punit.test/src/tests/api/org/punit/method/runner/
trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/ExecutorPoolTest.java
trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/suite/
trunk/punit.test/src/tests/api/org/punit/suite/builder/
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/ExcludedTestClass1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java
Modified: trunk/punit.test/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- trunk/punit.test/.settings/org.eclipse.jdt.core.prefs 2008-01-11 15:57:04 UTC (rev 270)
+++ trunk/punit.test/.settings/org.eclipse.jdt.core.prefs 2008-01-11 15:57:50 UTC (rev 271)
@@ -1,12 +1,12 @@
-#Mon Nov 19 00:43:30 CST 2007
+#Fri Jan 11 23:20:41 CST 2008
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
-org.eclipse.jdt.core.compiler.source=1.3
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2008-01-11 15:57:04 UTC (rev 270)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2008-01-11 15:57:50 UTC (rev 271)
@@ -1,12 +1,16 @@
package tests.api.org.punit.all;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import org.punit.method.runner.*;
+
+import junit.framework.*;
import tests.api.org.punit.assertion.AssertTest;
+import tests.api.org.punit.convention.*;
import tests.api.org.punit.exception.ConcurrentExceptionTest;
import tests.api.org.punit.method.builder.TestMethodBuilderTest;
+import tests.api.org.punit.method.runner.*;
import tests.api.org.punit.reporter.stream.StreamLoggerTest;
-import tests.api.org.punit.runner.AbstractRunnerTest;
+import tests.api.org.punit.runner.*;
+import tests.api.org.punit.suite.builder.*;
import tests.api.org.punit.util.LoggerUtilTest;
import tests.api.org.punit.util.ReflectionUtilTest;
import tests.api.org.punit.watcher.CustomWatcherTest;
@@ -15,10 +19,11 @@
public class AllTests {
+ @SuppressWarnings("unchecked")
public static Test suite() {
TestSuite suite = new TestSuite("Test for tests.api.org.punit"); //$NON-NLS-1$
// $JUnit-BEGIN$
- Class[] tests = testSuite();
+ Class<? extends TestCase>[] tests = (Class<? extends TestCase>[]) testSuite();
for (int i = 0; i < tests.length; ++i) {
suite.addTestSuite(tests[i]);
}
@@ -26,18 +31,25 @@
return suite;
}
- public static final Class[] testSuite() {
- return new Class[] {
+ public static final Class<?> [] testSuite() {
+ return new Class [] {
+ AbstractMethodRunnerTest.class,
AbstractRunnerTest.class,
+ AnnotationFilterTest.class,
+ NameConventionFilterTest.class,
AssertTest.class,
ConcurrentExceptionTest.class,
+ ConcurrentRunnerTest.class,
+ ExecutorPoolTest.class,
LoggerUtilTest.class,
MemoryWatcherTest.class,
CustomWatcherTest.class,
ReflectionUtilTest.class,
+ SoloRunnerTest.class,
StreamLoggerTest.class,
- TestMethodBuilderTest.class,
- TimeWatcherTest.class
+ TestMethodBuilderTest.class,
+ TestSuiteBuilderTest.class,
+ TimeWatcherTest.class
};
}
}
Modified: trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java 2008-01-11 15:57:04 UTC (rev 270)
+++ trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java 2008-01-11 15:57:50 UTC (rev 271)
@@ -10,7 +10,7 @@
soloRunner.run(PUnitAllTests.class);
}
- public Class[] testSuite() {
+ public Class<?> [] testSuite() {
return AllTests.testSuite();
}
Added: trunk/punit.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java 2008-01-11 15:57:50 UTC (rev 271)
@@ -0,0 +1,120 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.convention;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.punit.annotation.Ignore;
+import org.punit.convention.AnnotationConvention;
+import org.punit.util.ReflectionUtil;
+
+import tests.api.org.punit.testclasses.AnnotationTestClass;
+import tests.api.org.punit.testclasses.ConcurrentTestClass;
+import tests.api.org.punit.testclasses.TestClass0;
+import tests.api.org.punit.testclasses.TestClass1;
+
+public class AnnotationFilterTest extends TestCase {
+ AnnotationConvention _filter = new AnnotationConvention();
+
+ public void testIsExcluded() {
+ assertTrue(_filter.isExcluded(ExcludedClass.class));
+ assertFalse(_filter.isExcluded(NonExcludedClass.class));
+ assertFalse(_filter.isExcluded(AnnotationTestClass.class));
+ }
+
+ public void testIsTestMethod() {
+ Method method;
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test1", new Class[] {}); //$NON-NLS-1$
+ assertFalse(_filter.isTestMethod(method));
+
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
+ assertTrue(_filter.isTestMethod(method));
+ }
+
+ public void testGetCheckMethod() {
+ Method method, checkMethod;
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test1", new Class[] {}); //$NON-NLS-1$
+ assertFalse(_filter.isTestMethod(method));
+ checkMethod = _filter.getCheckMethod(method);
+ assertNull(checkMethod);
+
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
+ assertTrue(_filter.isTestMethod(method));
+ checkMethod = _filter.getCheckMethod(method);
+ assertEquals("annotation_check_2", checkMethod.getName()); //$NON-NLS-1$
+
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test3", new Class[] {}); //$NON-NLS-1$
+ assertTrue(_filter.isTestMethod(method));
+ checkMethod = _filter.getCheckMethod(method);
+ assertEquals("check__test3", checkMethod.getName()); //$NON-NLS-1$
+ }
+
+ public void testGetExpectedException() {
+ Method method;
+ Class<? extends Throwable> exception;
+
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test1", new Class[] {}); //$NON-NLS-1$
+ exception = _filter.getExpectedException(method);
+ assertNull(exception);
+
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
+ exception = _filter.getExpectedException(method);
+ assertSame(NullPointerException.class, exception);
+
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test3", new Class[] {}); //$NON-NLS-1$
+ exception = _filter.getExpectedException(method);
+ assertNull(exception);
+ }
+
+ public void testGetConcurrentCount1() {
+ Method method = ReflectionUtil.getMethod(ConcurrentTestClass.class, "test1", new Class[] {}); //$NON-NLS-1$
+ ConcurrentTestClass test = new ConcurrentTestClass();
+ int count = _filter.getConcurrentCount(test, method);
+ assertEquals(test.concurrentCount(), count);
+
+ method = ReflectionUtil.getMethod(AnnotationTestClass.class, "test1", new Class[] {}); //$NON-NLS-1$
+ assertEquals(0, _filter.getConcurrentCount(new TestClass0(), method));
+ }
+
+ public void testGetConcurrentCountClass() {
+ Method method = ReflectionUtil.getMethod(AnnotationTestClass.class, "test1", new Class[] {}); //$NON-NLS-1$
+ AnnotationTestClass test = new AnnotationTestClass();
+ int count = _filter.getConcurrentCount(test, method);
+ assertEquals(5, count);
+ }
+
+ public void testGetConcurrentCountMethod() {
+ Method method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
+ int count = _filter.getConcurrentCount(new AnnotationTestClass(), method);
+ assertEquals(6, count);
+ }
+
+ public void testGetSetUpMethod() {
+ assertNotNull(_filter.getSetUpMethod(AnnotationTestClass.class));
+ }
+
+ public void testGetTearDownMethod() {
+ assertNotNull(_filter.getTearDownMethod(AnnotationTestClass.class));
+ }
+
+ public void testGetBeforeClass() {
+ assertNotNull(_filter.getBeforeClassMethod(AnnotationTestClass.class));
+ assertNull(_filter.getBeforeClassMethod(TestClass1.class));
+ }
+
+ public void testGetAfterClass() {
+ assertNotNull(_filter.getAfterClassMethod(AnnotationTestClass.class));
+ assertNull(_filter.getAfterClassMethod(TestClass1.class));
+ }
+
+ @Ignore
+ static class ExcludedClass {
+
+ }
+
+ static class NonExcludedClass {
+
+ }
+}
Property changes on: trunk/punit.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java 2008-01-11 15:57:50 UTC (rev 271)
@@ -0,0 +1,103 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.convention;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.punit.convention.NameConvention;
+import org.punit.util.ReflectionUtil;
+
+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));
+ }
+
+ 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$
+ 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));
+ }
+
+ public void testGetSetUpMethod() {
+ 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(LoopTestClass.class));
+ assertFalse(_convention.isLoopTest(TestClass0.class));
+ }
+
+ public void testGetToWork() {
+ 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() {
+
+ }
+}
Property changes on: trunk/punit.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java 2008-01-11 15:57:50 UTC (rev 271)
@@ -0,0 +1,91 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.method.runner;
+
+import java.util.*;
+
+import junit.framework.*;
+import junit.framework.Assert;
+
+import org.punit.assertion.*;
+import org.punit.method.runner.*;
+import org.punit.util.*;
+import org.punit.watcher.*;
+
+import tests.api.org.punit.testclasses.*;
+
+public class AbstractMethodRunnerTest extends TestCase {
+ private MockTestMethodRunnerTest _mockRunner = new MockTestMethodRunnerTest();
+
+ public void testWatchers() {
+ List<Watcher >watchers = _mockRunner.watchers();
+ assertEquals(1, watchers.size()); // time, and memory watchers
+
+ _mockRunner.removeTimeWatcher();
+ watchers = _mockRunner.watchers();
+ assertEquals(0, watchers.size());
+
+ _mockRunner.addWatcher(new TimeWatcher());
+ watchers = _mockRunner.watchers();
+ assertEquals(1, watchers.size());
+ }
+
+ public void testRunMethod1() throws Throwable {
+ _mockRunner.testRunMethod1();
+ }
+
+ public void testRunMethod2() throws Throwable {
+ _mockRunner.testRunMethod2();
+ }
+
+ public void testRunMethod3() throws Throwable {
+ _mockRunner.testRunMethod3();
+ }
+
+ static class MockTestMethodRunnerTest extends AbstractMethodRunner {
+
+ private static final long serialVersionUID = 1L;
+
+ public void testRunMethod1() throws Throwable {
+ AnnotationTestClass.reset();
+ this._method = ReflectionUtil.getMethod(AnnotationTestClass.class,
+ "test1", new Class[] {}); //$NON-NLS-1$
+ this._params = new Object[] {};
+ this._testInstance = new AnnotationTestClass();
+ this._expectedException = null;
+ super.runMethod();
+ Assert.assertTrue(AnnotationTestClass._test1);
+ }
+
+ public void testRunMethod2() throws Throwable {
+ AnnotationTestClass.reset();
+ this._method = ReflectionUtil.getMethod(AnnotationTestClass.class,
+ "_testException", new Class[] {}); //$NON-NLS-1$
+ this._params = new Object[] {};
+ this._testInstance = new AnnotationTestClass();
+ this._expectedException = null;
+ org.punit.assertion.Assert.assertException(NullPointerException.class, new CodeRunner(){
+ public void run() throws Throwable {
+ runMethod();
+ }
+ });
+ Assert.assertTrue(AnnotationTestClass._testException);
+ }
+
+ public void testRunMethod3() throws Throwable {
+ AnnotationTestClass.reset();
+ this._method = ReflectionUtil.getMethod(AnnotationTestClass.class,
+ "_testException", new Class[] {}); //$NON-NLS-1$
+ this._params = new Object[] {};
+ this._testInstance = new AnnotationTestClass();
+ this._expectedException = NullPointerException.class;
+ super.runMethod();
+ Assert.assertTrue(AnnotationTestClass._testException);
+ }
+
+ protected void runImpl() throws Throwable {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+}
Property changes on: trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2008-01-11 15:57:50 UTC (rev 271)
@@ -0,0 +1,102 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.runner;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.punit.convention.AnnotationConvention;
+import org.punit.events.*;
+import org.punit.runner.ConcurrentRunner;
+import org.punit.runner.SoloRunner;
+
+import tests.api.org.punit.testclasses.AnnotationTestClass;
+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;
+import tests.api.org.punit.testclasses.TestClass3;
+import tests.api.org.punit.testclasses.TestSuiteClass;
+import tests.util.TestUtil;
+
+public class ConcurrentRunnerTest extends TestCase {
+
+ private ConcurrentRunner _runner = new ConcurrentRunner();
+
+ public static void main(String[] args) {
+ new SoloRunner().run(ConcurrentRunnerTest.class);
+ }
+
+ public void testMain() {
+ ConcurrentRunner.main(new String[] { TestSuiteClass.class.getName() });
+ }
+
+ public void testRun() {
+ _runner.run(TestSuiteClass.class);
+ }
+
+ public void testRunLoopTest() {
+ LoopTestClass.reset();
+ _runner.run(LoopTestClass.class);
+ LoopTestClass.assertTestClassRun();
+ }
+
+ public void testRunConcurrent() {
+ ConcurrentTestClass.reset();
+ _runner.run(ConcurrentTestClass.class);
+ assertConcurrentTestClassRun();
+ }
+
+ public void testRunTest() {
+ TestClass0.reset();
+ _runner.run(TestClass0.class);
+ TestClass0.assertTestClassRun();
+ }
+
+ public void testRunAnnotationTest() {
+ AnnotationTestClass.reset();
+ _runner.setConvention(new AnnotationConvention());
+ _runner.run(AnnotationTestClass.class);
+ AnnotationTestClass.assertTestClassRun();
+ }
+
+ public void testRunPUnitTest() {
+ TestClass3.reset();
+ _runner.run(TestClass3.class);
+ TestClass3.assertTestClassRun();
+ }
+
+ public void testRunParameterized() throws Exception {
+ ConcurrentParameterizedTestClass.reset();
+ _runner.run(ConcurrentParameterizedTestClass.class);
+ ConcurrentParameterizedTestClass.assertTestClassRun();
+ }
+
+ public void testRunTestSuite() {
+ ConcurrentTestClass.reset();
+ TestClass0.reset();
+ TestClass3.reset();
+ _runner.run(TestSuiteClass.class);
+ assertConcurrentTestClassRun();
+ TestClass0.assertTestClassRun();
+ TestClass3.assertTestClassRun();
+ }
+
+ public void testSerializable() throws Exception {
+ _runner.addEventListener(new MockEventListener());
+ List<EventListener> expectedListeners = _runner.eventListeners();
+ ConcurrentRunner runner = (ConcurrentRunner) TestUtil
+ .getSerialiableObject(_runner);
+ List<EventListener> eventListeners = runner.eventListeners();
+ assertEquals(expectedListeners.size(), eventListeners.size());
+ }
+
+ private void assertConcurrentTestClassRun() {
+ ConcurrentTestClass test = new ConcurrentTestClass();
+ assertEquals(test.concurrentCount(), ConcurrentTestClass.value);
+ assertTrue(ConcurrentTestClass._assertCheck1);
+ assertTrue(ConcurrentTestClass._assertCheck2);
+ }
+
+}
Property changes on: trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit.test/src/tests/api/org/punit/runner/ExecutorPoolTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/ExecutorPoolTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/ExecutorPoolTest.java 2008-01-11 15:57:50 UTC (rev 271)
@@ -0,0 +1,51 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.runner;
+
+import org.punit.assertion.*;
+import org.punit.runner.*;
+
+import tests.util.*;
+
+import junit.framework.*;
+
+public class ExecutorPoolTest extends TestCase {
+
+ private ExecutorPoolImpl _pool = new ExecutorPoolImpl(5);
+
+ public void testCtor() {
+ AssertUtil.assertException(IllegalArgumentException.class,
+ new CodeRunner() {
+ public void run() throws Throwable {
+ new ExecutorPoolImpl(0);
+ }
+ });
+ }
+
+ public void testStartJoin() {
+ _pool.start();
+ _pool.join();
+ }
+
+ public void testExecute() {
+ _pool.start();
+ RunnableTask task = new RunnableTask();
+ _pool.execute(task);
+ _pool.join();
+ task.assertExecuted();
+ }
+
+ static class RunnableTask implements Runnable {
+
+ private boolean _executed;
+
+ public void run() {
+ _executed = true;
+ }
+
+ public void assertExecuted() {
+ assertTrue(_executed);
+ }
+
+ }
+}
Property changes on: trunk/punit.test/src/tests/api/org/punit/runner/ExecutorPoolTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/punit.test/src/tests/api/org/punit/runner/MockEventListener.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/MockEventListener.java 2008-01-11 15:57:04 UTC (rev 270)
+++ trunk/punit.test/src/tests/api/org/punit/runner/MockEventListener.java 2008-01-11 15:57:50 UTC (rev 271)
@@ -27,11 +27,11 @@
public boolean _onSuiteEnd;
public boolean _onSuiteStart;
- public void onRunnerEnd(Class clazz, Runner runner) {
+ public void onRunnerEnd(Class<?> clazz, Runner runner) {
_onRunnerEnd = true;
}
- public void onRunnerStart(Class clazz, Runner runner) {
+ public void onRunnerStart(Class<?> clazz, Runner runner) {
_onRunnerStart = true;
}
@@ -43,7 +43,7 @@
_onClassEnd = true;
}
- 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<Watcher> watchers) {
_onMethodEnd = true;
}
@@ -59,11 +59,11 @@
_onWatcherStart = true;
}
- public void onWatchersEnd(List watchers) {
+ public void onWatchersEnd(List<Watcher> watchers) {
_onWatchersEnd = true;
}
- public void onWatchersStart(List watchers) {
+ public void onWatchersStart(List<Watcher> watchers) {
_onWatchersStart = true;
}
Added: trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2008-01-11 15:57:50 UTC (rev 271)
@@ -0,0 +1,99 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.runner;
+
+import junit.framework.*;
+
+import org.punit.convention.*;
+import org.punit.runner.*;
+
+import tests.api.org.punit.testclasses.*;
+import tests.util.*;
+
+public class SoloRunnerTest extends AbstractRunnerTest {
+
+ private SoloRunner _runner;
+
+ protected void setUp() throws Exception {
+ _runner = new SoloRunner();
+ _eventListener = new MockEventListener();
+ _runner.addEventListener(_eventListener);
+ }
+
+ public void testMain() {
+ SoloRunner.main(new String[] { TestSuiteClass.class.getName() });
+ }
+
+ public void testRun() {
+ _runner.run(TestSuiteClass.class);
+ }
+
+ public void testRunTest() {
+ TestClass0.reset();
+ _runner.run(TestClass0.class);
+ TestClass0.assertTestClassRun();
+ _eventListener.assertAllEventsInvoked();
+ }
+
+ public void testRunLoopTest() {
+ LoopTestClass.reset();
+ _runner.run(LoopTestClass.class);
+ LoopTestClass.assertTestClassRun();
+ _eventListener.assertAllEventsInvoked();
+ }
+
+ public void testRunAnnotationTest() {
+ AnnotationTestClass.reset();
+ _runner.setConvention(new AnnotationConvention());
+ _runner.run(AnnotationTestClass.class);
+ AnnotationTestClass.assertTestClassRun();
+ }
+
+ public void testRunPUnitTest() {
+ TestClass3.reset();
+ _runner.run(TestClass3.class);
+ TestClass3.assertTestClassRun();
+ _eventListener.assertAllEventsInvoked();
+ }
+
+ public void testRunConcurrent() {
+ ConcurrentTestClass.reset();
+ _runner.run(ConcurrentTestClass.class);
+ assertConcurrentTestClassRun();
+ _eventListener.assertAllEventsInvoked();
+ }
+
+ public void testRunParameterized() throws Exception {
+ ParameterizedTestClass.reset();
+ _runner.run(ParameterizedTestClass.class);
+ ParameterizedTestClass.assertTestClassRun();
+ }
+
+ public void testRunTestSuite() {
+ TestClass0.reset();
+ TestClass3.reset();
+ _runner.run(TestSuiteClass.class);
+ TestClass0.assertTestClassRun();
+
+ TestClass3.reset();
+ _runner.run(TestClass3.class);
+ TestClass3.assertTestClassRun();
+
+ _eventListener.assertAllEventsInvoked();
+ Assert.assertTrue(_eventListener._onSuiteEnd);
+ Assert.assertTrue(_eventListener._onSuiteStart);
+ }
+
+ public void testSerializable() throws Exception {
+ _runner.addEventListener(new MockEventListener());
+ int expectedListenersSize = _runner.eventListeners().size();
+ SoloRunner runner = (SoloRunner) TestUtil.getSerialiableObject(_runner);
+ int eventListenersSize = runner.eventListeners().size();
+ assertEquals(expectedListenersSize, eventListenersSize);
+ }
+
+ private void assertConcurrentTestClassRun() {
+ assertEquals(1, ConcurrentTestClass.value);
+ }
+
+}
Property changes on: trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit.test/src/tests/api/org/punit/suite/builder/TestSuiteBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/suite/builder/TestSuiteBuilderTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/suite/builder/TestSuiteBuilderTest.java 2008-01-11 15:57:50 UTC (rev 271)
@@ -0,0 +1,107 @@
+package tests.api.org.punit.suite.builder;
+
+import junit.framework.*;
+
+import org.punit.convention.*;
+import org.punit.suite.builder.*;
+
+import tests.api.org.punit.testclasses.*;
+import tests.util.*;
+
+public class TestSuiteBuilderTest extends TestCase {
+ private TestSuiteBuilderImpl _testSuiteBuidler;
+
+ protected void setUp() throws Exception {
+ _testSuiteBuidler = new TestSuiteBuilderImpl();
+ _testSuiteBuidler.setConvention(new NameConvention());
+ }
+
+ public void testBuildExcludedTestClasses1() {
+ _testSuiteBuidler.setConvention(new AnnotationConvention());
+ Object[] classes = _testSuiteBuidler.buildTestClasses(ExcludedTestClass1.class);
+ AssertUtil.assertArray(classes, new Class[] { });
+ }
+
+ public void testBuildTestClasses1() {
+ Object[] classes = _testSuiteBuidler.buildTestClasses(TestClass1.class);
+ AssertUtil.assertArray(classes, new Class[] { TestClass1.class });
+ }
+
+ public void testBuildTestSuite1() {
+ Object[] classes = _testSuiteBuidler.buildTestClasses(TestSuite1.class);
+ Class<?>[] expectedClasses = new Class[] { TestClass1.class,
+ TestClass2.class, AlphabeticalTestClass.class };
+
+ assertEquals(expectedClasses.length + 2, classes.length); // suite labels
+
+ TestSuiteLabel label = (TestSuiteLabel) classes[0];
+ assertSame(TestSuite1.class, label.suite().getClass());
+ assertTrue(label.isStart());
+
+ label = (TestSuiteLabel) classes[classes.length - 1];
+ assertSame(TestSuite1.class, label.suite().getClass());
+ assertFalse(label.isStart());
+
+ AssertUtil.assertArrayContains(classes, expectedClasses);
+ }
+
+ public void testBuildTestSuite2() {
+ Object[] classes = _testSuiteBuidler.buildTestClasses(TestSuite2.class);
+ Class<?>[] expectedClasses = new Class[] {
+ TestClass4.class,
+ TestClass1.class,
+ TestClass2.class,
+ AlphabeticalTestClass.class,
+ TestClass5.class
+ };
+
+ assertEquals(expectedClasses.length + 4, classes.length); // suite labels
+
+ TestSuiteLabel label = (TestSuiteLabel) classes[0];
+ assertSame(TestSuite2.class, label.suite().getClass());
+ assertTrue(label.isStart());
+
+ label = (TestSuiteLabel) classes[classes.length - 1];
+ assertSame(TestSuite2.class, label.suite().getClass());
+ assertFalse(label.isStart());
+
+ label = (TestSuiteLabel) classes[2];
+ assertSame(TestSuite1.class, label.suite().getClass());
+ assertTrue(label.isStart());
+
+ label = (TestSuiteLabel) classes[6];
+ assertSame(TestSuite1.class, label.suite().getClass());
+ assertFalse(label.isStart());
+
+ AssertUtil.assertArrayContains(classes, expectedClasses);
+ }
+
+ public void testBuildTestSuite2ByAnnotationFilter() {
+ _testSuiteBuidler.setConvention(new AnnotationConvention());
+ Object[] classes = _testSuiteBuidler.buildTestClasses(TestSuite2.class);
+ Class<?>[] expectedClasses = new Class[] { TestClass4.class,
+ TestClass1.class, TestClass2.class, AlphabeticalTestClass.class, TestClass5.class };
+
+ assertEquals(expectedClasses.length + 4, classes.length); // suite labels
+
+ TestSuiteLabel label = (TestSuiteLabel) classes[0];
+ assertSame(TestSuite2.class, label.suite().getClass());
+ assertTrue(label.isStart());
+
+ label = (TestSuiteLabel) classes[classes.length - 1];
+ assertSame(TestSuite2.class, label.suite().getClass());
+ assertFalse(label.isStart());
+
+ label = (TestSuiteLabel) classes[2];
+ assertSame(TestSuite1.class, label.suite().getClass());
+ assertTrue(label.isStart());
+
+ label = (TestSuiteLabel) classes[6];
+ assertSame(TestSuite1.class, label.suite().getClass());
+ assertFalse(label.isStart());
+
+ AssertUtil.assertArrayContains(classes, expectedClasses);
+ }
+
+
+}
Property changes on: trunk/punit.test/src/tests/api/org/punit/suite/builder/TestSuiteBuilderTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java 2008-01-11 15:57:50 UTC (rev 271)
@@ -0,0 +1,130 @@
+package tests.api.org.punit.testclasses;
+
+import junit.framework.*;
+
+import org.punit.annotation.*;
+import org.punit.annotation.Test;
+import org.punit.convention.*;
+import org.punit.runner.*;
+
+@Test(concurrentCount=5)
+public class AnnotationTestClass {
+
+ public static void main(String[] args) {
+ SoloRunner soloRunner = new SoloRunner();
+ soloRunner.setConvention(new AnnotationConvention());
+ soloRunner.run(AnnotationTestClass.class);
+ }
+
+ public static boolean _test1;
+
+ public static boolean _test2;
+
+ public static boolean _check1;
+
+ public static boolean _check2;
+
+ public static boolean _check22;
+
+ public static boolean _testException;
+
+ public static boolean _setUp;
+
+ public static boolean _tearDown;
+
+ public static boolean _beforeClass;
+
+ public static boolean _afterClass;
+
+ public static void reset() {
+ _test1 = false;
+ _test2 = false;
+ _check1 = false;
+ _check2 = false;
+ _check22 = false;
+ _testException = false;
+ _setUp = false;
+ _tearDown = false;
+ _beforeClass = false;
+ _afterClass = false;
+ }
+
+ @SuppressWarnings("unused")
+ @BeforeClass
+ private static void beforeClassMethod() {
+ _beforeClass = true;
+ }
+
+ @SuppressWarnings("unused")
+ @AfterClass
+ private static void afterClassMethod() {
+ _afterClass = true;
+ }
+
+ @SuppressWarnings("unused")
+ @Before
+ private void before() {
+ _setUp = true;
+ }
+
+ @SuppressWarnings("unused")
+ @After
+ private void after() {
+ _tearDown = true;
+ }
+
+ public void _test1() {
+
+ }
+
+ public void test1() {
+ _test1 = true;
+ }
+
+ @Test(checkMethod="annotation_check_2", concurrentCount=6, expected=NullPointerException.class)
+ public void _test2() {
+ _test2 = true;
+ throw new NullPointerException();
+ }
+
+ public void check_test1() {
+ _check1 = true;
+ }
+
+ public void annotation_check_2() {
+ _check2 = true;
+ }
+
+ public void check_test2() {
+ _check22 = true;
+ }
+
+ @Test
+ public void _test3() {
+
+ }
+
+ public void check__test3() {
+
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void _testException() {
+ _testException = true;
+ throw new NullPointerException();
+ }
+
+ public static void assertTestClassRun() {
+ Assert.assertTrue(_test1);
+ Assert.assertTrue(_check1);
+
+ Assert.assertTrue(_test2);
+ Assert.assertTrue(_check2);
+ Assert.assertFalse(_check22);
+
+ Assert.assertTrue(_testException);
+
+ Assert.assertTrue(_setUp);
+ Assert.assertTrue(_tearDown);
+ }
+}
Property changes on: trunk/punit.test/src/tests/api/org/punit/testclasses/AnnotationTestClass.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/ExcludedTestClass1.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/ExcludedTestClass1.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/ExcludedTestClass1.java 2008-01-11 15:57:50 UTC (rev 271)
@@ -0,0 +1,54 @@
+package tests.api.org.punit.testclasses;
+
+import org.punit.annotation.Ignore;
+import org.punit.type.Parameter;
+
+import tests.util.TestUtil;
+
+@Ignore
+public class ExcludedTestClass1 {
+ public void test1() {
+ TestUtil.doSomething();
+ }
+
+ public void test1i(int i) {
+ TestUtil.doSomething();
+ }
+
+ public void test2() {
+ TestUtil.doSomething();
+ }
+
+ public void testa() {
+ TestUtil.doSomething();
+ }
+
+ public void testb() {
+ TestUtil.doSomething();
+ }
+
+ public void _testc() {
+ TestUtil.doSomething();
+ }
+
+ void testd() {
+ TestUtil.doSomething();
+ }
+
+ @SuppressWarnings("unused")
+ private void teste() {
+ TestUtil.doSomething();
+ }
+
+ public static void testf() {
+ TestUtil.doSomething();
+ }
+
+ public void testParam(Parameter p) {
+ TestUtil.doSomething();
+ }
+
+ public void testParamI(Parameter p, int i) {
+ TestUtil.doSomething();
+ }
+}
\ No newline at end of file
Property changes on: trunk/punit.test/src/tests/api/org/punit/testclasses/ExcludedTestClass1.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java 2008-01-11 15:57:50 UTC (rev 271)
@@ -0,0 +1,61 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.testclasses;
+
+import junit.framework.Assert;
+
+import org.punit.runner.SoloRunner;
+import org.punit.type.Loop;
+
+public class LoopTestClass implements Loop {
+
+ public static final long TIMEOUT = 100;
+
+ public static void main(String[] args) {
+ new SoloRunner().run(LoopTestClass.class);
+ }
+
+ public static int _test1;
+
+ public static int _test2;
+
+ public static int _setUp;
+
+ public static int _tearDown;
+
+ public static void reset() {
+ _test1 = 0;
+ _test2 = 0;
+ _setUp = 0;
+ _tearDown = 0;
+ }
+
+ @SuppressWarnings("unused")
+ private void setUp() {
+ _setUp++;
+ }
+
+ @SuppressWarnings("unused")
+ private void tearDown() {
+ _tearDown++;
+ }
+
+ public void test1() {
+ _test1++;
+ }
+
+ public void test2() {
+ _test2++;
+ }
+
+ public static void assertTestClassRun() {
+ Assert.assertTrue(_test1 > 2);
+ Assert.assertTrue(_test2 > 2);
+ Assert.assertEquals(2, _setUp);
+ Assert.assertEquals(2, _tearDown);
+ }
+
+ public long toWork() {
+ return TIMEOUT;
+ }
+}
Property changes on: trunk/punit.test/src/tests/api/org/punit/testclasses/LoopTestClass.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass0.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass0.java 2008-01-11 15:57:04 UTC (rev 270)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass0.java 2008-01-11 15:57:50 UTC (rev 271)
@@ -13,25 +13,27 @@
public static boolean _tearDown;
- private static boolean _beforeClass;
+ private static int _beforeClass;
- private static boolean _afterClass;
+ private static int _afterClass;
+
+ private static int count = 0;
public static void reset() {
_test1 = false;
_test2 = false;
_setUp = false;
_tearDown = false;
- _beforeClass = false;
- _afterClass = false;
+ _beforeClass = 0;
+ _afterClass = 0;
}
private static void beforeClass() {
- _beforeClass = true;
+ _beforeClass = ++count;
}
private static void afterClass() {
- _afterClass = true;
+ _afterClass = ++count;
}
private void setUp() {
@@ -55,7 +57,7 @@
Assert.assertTrue(_test2);
Assert.assertTrue(_setUp);
Assert.assertTrue(_tearDown);
- Assert.assertTrue(_beforeClass);
- Assert.assertTrue(_afterClass);
+ Assert.assertTrue(_afterClass > _beforeClass);
+ Assert.assertTrue(_beforeClass > 0);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-01-11 15:57:00
|
Revision: 270
http://p-unit.svn.sourceforge.net/p-unit/?rev=270&view=rev
Author: zhanghuangzhu
Date: 2008-01-11 07:57:04 -0800 (Fri, 11 Jan 2008)
Log Message:
-----------
Andrew Zhang: Looking forward, based on java 5 now.
Modified Paths:
--------------
trunk/punit/.settings/org.eclipse.jdt.core.prefs
trunk/punit/src/org/punit/assertion/Assert.java
trunk/punit/src/org/punit/convention/AbstractConvention.java
trunk/punit/src/org/punit/convention/Convention.java
trunk/punit/src/org/punit/convention/NameConvention.java
trunk/punit/src/org/punit/events/EventListener.java
trunk/punit/src/org/punit/events/EventRegistry.java
trunk/punit/src/org/punit/events/VanillaEventListener.java
trunk/punit/src/org/punit/exception/ConcurrentException.java
trunk/punit/src/org/punit/message/Messages.java
trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
trunk/punit/src/org/punit/method/runner/MethodRunner.java
trunk/punit/src/org/punit/method/runner/VanillaRunner.java
trunk/punit/src/org/punit/reporter/TestResult.java
trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
trunk/punit/src/org/punit/type/TestSuite.java
trunk/punit/src/org/punit/util/ReflectionUtil.java
trunk/punit/src/org/punit/util/ReporterUtil.java
trunk/punit/src/org/punit/util/RunnerUtil.java
trunk/punit/src/org/punit/watcher/CustomWatcher.java
Added Paths:
-----------
trunk/punit/src/org/punit/annotation/
trunk/punit/src/org/punit/annotation/After.java
trunk/punit/src/org/punit/annotation/AfterClass.java
trunk/punit/src/org/punit/annotation/Before.java
trunk/punit/src/org/punit/annotation/BeforeClass.java
trunk/punit/src/org/punit/annotation/Ignore.java
trunk/punit/src/org/punit/annotation/Test.java
trunk/punit/src/org/punit/convention/AnnotationConvention.java
trunk/punit/src/org/punit/runner/ExecutorPoolImpl.java
trunk/punit/src/org/punit/util/AnnotationUtil.java
Removed Paths:
-------------
trunk/punit/.settings/org.eclipse.jdt.ui.prefs
trunk/punit/src/org/punit/util/Traverser.java
trunk/punit/src/org/punit/util/TraverserUtil.java
Modified: trunk/punit/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- trunk/punit/.settings/org.eclipse.jdt.core.prefs 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/.settings/org.eclipse.jdt.core.prefs 2008-01-11 15:57:04 UTC (rev 270)
@@ -1,4 +1,4 @@
-#Sun May 13 18:44:47 CST 2007
+#Fri Jan 11 20:22:14 CST 2008
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
@@ -9,4 +9,4 @@
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.3
+org.eclipse.jdt.core.compiler.source=1.5
Deleted: trunk/punit/.settings/org.eclipse.jdt.ui.prefs
===================================================================
--- trunk/punit/.settings/org.eclipse.jdt.ui.prefs 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/.settings/org.eclipse.jdt.ui.prefs 2008-01-11 15:57:04 UTC (rev 270)
@@ -1,3 +0,0 @@
-#Sun May 13 18:44:44 CST 2007
-eclipse.preferences.version=1
-internal.default.compliance=user
Added: trunk/punit/src/org/punit/annotation/After.java
===================================================================
--- trunk/punit/src/org/punit/annotation/After.java (rev 0)
+++ trunk/punit/src/org/punit/annotation/After.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -0,0 +1,14 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+package org.punit.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+
+public @interface After {
+
+}
Property changes on: trunk/punit/src/org/punit/annotation/After.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit/src/org/punit/annotation/AfterClass.java
===================================================================
--- trunk/punit/src/org/punit/annotation/AfterClass.java (rev 0)
+++ trunk/punit/src/org/punit/annotation/AfterClass.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -0,0 +1,11 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+package org.punit.annotation;
+
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+
+public @interface AfterClass {
+
+}
Property changes on: trunk/punit/src/org/punit/annotation/AfterClass.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit/src/org/punit/annotation/Before.java
===================================================================
--- trunk/punit/src/org/punit/annotation/Before.java (rev 0)
+++ trunk/punit/src/org/punit/annotation/Before.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -0,0 +1,13 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+package org.punit.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Before {
+
+}
Property changes on: trunk/punit/src/org/punit/annotation/Before.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit/src/org/punit/annotation/BeforeClass.java
===================================================================
--- trunk/punit/src/org/punit/annotation/BeforeClass.java (rev 0)
+++ trunk/punit/src/org/punit/annotation/BeforeClass.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -0,0 +1,11 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+package org.punit.annotation;
+
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+
+public @interface BeforeClass {
+
+}
Property changes on: trunk/punit/src/org/punit/annotation/BeforeClass.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit/src/org/punit/annotation/Ignore.java
===================================================================
--- trunk/punit/src/org/punit/annotation/Ignore.java (rev 0)
+++ trunk/punit/src/org/punit/annotation/Ignore.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -0,0 +1,10 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.annotation;
+
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Ignore {
+ String value() default "";
+}
Property changes on: trunk/punit/src/org/punit/annotation/Ignore.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/punit/src/org/punit/annotation/Test.java
===================================================================
--- trunk/punit/src/org/punit/annotation/Test.java (rev 0)
+++ trunk/punit/src/org/punit/annotation/Test.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -0,0 +1,20 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.annotation;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Test {
+
+ Class<? extends Throwable> expected() default NoException.class;
+
+ String checkMethod() default "";
+
+ int concurrentCount() default 0;
+
+ public class NoException extends Throwable {
+ private static final long serialVersionUID = 3987745685001380514L;
+ }
+}
Property changes on: trunk/punit/src/org/punit/annotation/Test.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/punit/src/org/punit/assertion/Assert.java
===================================================================
--- trunk/punit/src/org/punit/assertion/Assert.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/assertion/Assert.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -76,8 +76,8 @@
}
}
- public static void assertException(Class throwable, CodeRunner code) {
- Class exceptionClass = null;
+ public static void assertException(Class <? extends Throwable> throwable, CodeRunner code) {
+ Class <? extends Throwable> exceptionClass = null;
try {
code.run();
} catch (Throwable e) {
Modified: trunk/punit/src/org/punit/convention/AbstractConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/AbstractConvention.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/convention/AbstractConvention.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -12,11 +12,11 @@
abstract public class AbstractConvention implements Convention {
- public boolean isExcluded(Class method) {
+ public boolean isExcluded(Class <?> method) {
return false;
}
- public Class getExpectedException(Method method) {
+ public Class<? extends Throwable> getExpectedException(Method method) {
return null;
}
@@ -27,19 +27,19 @@
return 0;
}
- public boolean isPUnitTest(Class clazz) {
+ public boolean isPUnitTest(Class<?> clazz) {
return Test.class.isAssignableFrom(clazz);
}
- public boolean isParameter(Class clazz) {
+ public boolean isParameter(Class<?> clazz) {
return Parameter.class.isAssignableFrom(clazz);
}
- public boolean isParameterizedTest(Class clazz) {
+ public boolean isParameterizedTest(Class<?> clazz) {
return Parameterized.class.isAssignableFrom(clazz);
}
- public boolean isLoopTest(Class clazz) {
+ public boolean isLoopTest(Class<?> clazz) {
return Loop.class.isAssignableFrom(clazz);
}
Added: trunk/punit/src/org/punit/convention/AnnotationConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/AnnotationConvention.java (rev 0)
+++ trunk/punit/src/org/punit/convention/AnnotationConvention.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -0,0 +1,134 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.convention;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import org.punit.annotation.Test;
+import org.punit.util.AnnotationUtil;
+import org.punit.util.ReflectionUtil;
+
+/**
+ * The class merges annotation and name conventions with annotations taking
+ * preference.
+ */
+public class AnnotationConvention extends AbstractConvention {
+
+ private static final long serialVersionUID = -6800242731470821241L;
+
+ protected NameConvention _delegate = new NameConvention();
+
+ private Class<? extends Annotation> _after;
+ private Class<? extends Annotation> _afterClass;
+ private Class<? extends Annotation> _before;
+ private Class<? extends Annotation> _beforeClass;
+ private Class<? extends Annotation> _ignore;
+ protected Class<? extends Annotation> _test;
+
+ public AnnotationConvention() {
+ this(org.punit.annotation.After.class,
+ org.punit.annotation.AfterClass.class,
+ org.punit.annotation.Before.class,
+ org.punit.annotation.BeforeClass.class,
+ org.punit.annotation.Ignore.class, Test.class);
+ }
+
+ public AnnotationConvention(Class<? extends Annotation> after,
+ Class<? extends Annotation> afterClass,
+ Class<? extends Annotation> before,
+ Class<? extends Annotation> beforeClass,
+ Class<? extends Annotation> ignore, Class<? extends Annotation> test) {
+ _after = after;
+ _afterClass = afterClass;
+ _before = before;
+ _beforeClass = beforeClass;
+ _ignore = ignore;
+ _test = test;
+ }
+
+ public Method getCheckMethod(Method method) {
+ Test testAnnotation = (Test) method.getAnnotation(_test);
+ String checkMethodName = null;
+ if (testAnnotation != null) {
+ checkMethodName = testAnnotation.checkMethod();
+ if (checkMethodName != null && checkMethodName.length() > 0) {
+ return ReflectionUtil.getMethod(method.getDeclaringClass(),
+ checkMethodName, method.getParameterTypes());
+ }
+ }
+ return _delegate.getCheckMethod(method);
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean isExcluded(Class clazz) {
+ return clazz.isAnnotationPresent(_ignore);
+ }
+
+ public boolean isTestMethod(Method method) {
+ if (method.isAnnotationPresent(_ignore)) {
+ return false;
+ }
+ return method.isAnnotationPresent(_test) || _delegate.isTestMethod(method);
+ }
+
+ public Class<? extends Throwable> getExpectedException(Method method) {
+ Test testAnnotation = (Test) method.getAnnotation(_test);
+ if (testAnnotation == null) {
+ return null;
+ }
+ Class<? extends Throwable> expected = testAnnotation.expected();
+ if (expected == Test.NoException.class) {
+ return null;
+ }
+ return expected;
+ }
+
+ public int getConcurrentCount(Object testInstance, Method method) {
+ Test testAnnotation = (Test) method.getAnnotation(_test);
+ if (testAnnotation == null) {
+ testAnnotation = (Test) testInstance.getClass().getAnnotation(_test);
+ }
+ if (testAnnotation == null) {
+ return _delegate.getConcurrentCount(testInstance, method);
+ }
+ return testAnnotation.concurrentCount();
+ }
+
+ @SuppressWarnings("unchecked")
+ public Method getAfterClassMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, _afterClass);
+ if (method == null) {
+ method = _delegate.getAfterClassMethod(test);
+ }
+ return method;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Method getBeforeClassMethod(Class test) {
+ Method method = AnnotationUtil
+ .getMethodByAnnotation(test, _beforeClass);
+ if (method == null) {
+ method = _delegate.getBeforeClassMethod(test);
+ }
+ return method;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Method getSetUpMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, _before);
+ if (method == null) {
+ method = _delegate.getSetUpMethod(test);
+ }
+ return method;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Method getTearDownMethod(Class test) {
+ Method method = AnnotationUtil.getMethodByAnnotation(test, _after);
+ if (method == null) {
+ method = _delegate.getTearDownMethod(test);
+ }
+ return method;
+ }
+
+}
Property changes on: trunk/punit/src/org/punit/convention/AnnotationConvention.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/punit/src/org/punit/convention/Convention.java
===================================================================
--- trunk/punit/src/org/punit/convention/Convention.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/convention/Convention.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -12,7 +12,7 @@
*
* @return returns true if the test class is excluded.
*/
- public boolean isExcluded(Class clazz);
+ public boolean isExcluded(Class <?> clazz);
/**
* Judges whether this method is a test method.
@@ -30,25 +30,25 @@
*/
public Method getCheckMethod(Method method);
- public Class getExpectedException(Method method);
+ public Class<? extends Throwable> getExpectedException(Method method);
public int getConcurrentCount(Object testInstance, Method method);
- public Method getSetUpMethod(Class test);
+ public Method getSetUpMethod(Class<?> test);
- public Method getTearDownMethod(Class test);
+ public Method getTearDownMethod(Class<?> test);
- public Method getBeforeClassMethod(Class test);
+ public Method getBeforeClassMethod(Class<?> test);
- public Method getAfterClassMethod(Class test);
+ public Method getAfterClassMethod(Class<?> test);
- public boolean isPUnitTest(Class clazz);
+ public boolean isPUnitTest(Class<?> clazz);
- public boolean isParameter(Class clazz);
+ public boolean isParameter(Class<?> clazz);
- public boolean isParameterizedTest(Class clazz);
+ public boolean isParameterizedTest(Class<?> clazz);
- public boolean isLoopTest(Class clazz);
+ public boolean isLoopTest(Class<?> clazz);
public long toWork(Object testInstance);
}
Modified: trunk/punit/src/org/punit/convention/NameConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/NameConvention.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/convention/NameConvention.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -66,8 +66,8 @@
* from <code>Parameter</code>.
*/
protected boolean isParamValid(Method method) {
- Class clazz = method.getDeclaringClass();
- Class[] params = method.getParameterTypes();
+ Class<?> clazz = method.getDeclaringClass();
+ Class<?>[] params = method.getParameterTypes();
if (isParameterizedTest(clazz)) {
return params.length == 1 && isParameter(params[0]);
} else {
@@ -75,30 +75,30 @@
}
}
- public Method getAfterClassMethod(Class test) {
+ public Method getAfterClassMethod(Class<?> test) {
Method method = ReflectionUtil.getMethodAndSetAccessible(test,
- "beforeClass", new Class[] {}); //$NON-NLS-1$
+ "afterClass", new Class[] {}); //$NON-NLS-1$
if (method != null && ReflectionUtil.isStatic(method)) {
return method;
}
return null;
}
- public Method getBeforeClassMethod(Class test) {
+ public Method getBeforeClassMethod(Class<?> test) {
Method method = ReflectionUtil.getMethodAndSetAccessible(test,
- "afterClass", new Class[] {}); //$NON-NLS-1$
+ "beforeClass", new Class[] {}); //$NON-NLS-1$
if (method != null && ReflectionUtil.isStatic(method)) {
return method;
}
return null;
}
- public Method getSetUpMethod(Class test) {
+ public Method getSetUpMethod(Class<?> test) {
return ReflectionUtil.getMethodAndSetAccessible(test,
"setUp", new Class[] {}); //$NON-NLS-1$
}
- public Method getTearDownMethod(Class test) {
+ public Method getTearDownMethod(Class<?> test) {
return ReflectionUtil.getMethodAndSetAccessible(test,
"tearDown", new Class[] {}); //$NON-NLS-1$
}
Modified: trunk/punit/src/org/punit/events/EventListener.java
===================================================================
--- trunk/punit/src/org/punit/events/EventListener.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/events/EventListener.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -27,7 +27,7 @@
* @param runner
* the runner who runs this class
*/
- public void onRunnerStart(Class clazz, Runner runner);
+ public void onRunnerStart(Class<?> clazz, Runner runner);
/**
* Is triggered after running the class.
@@ -37,7 +37,7 @@
* @param runner
* the runner who runs this class
*/
- public void onRunnerEnd(Class clazz, Runner runner);
+ public void onRunnerEnd(Class<?> clazz, Runner runner);
/**
* Is triggered when the test suite is to be executed.
@@ -79,17 +79,17 @@
* Is triggered after executing the method.
*/
public void onMethodEnd(Method method, Object testInstance,
- Object[] params, Throwable t, List Watchers);
+ Object[] params, Throwable t, List<Watcher> Watchers);
/**
* Is triggered before all watchers start.
*/
- public void onWatchersStart(List watchers);
+ public void onWatchersStart(List<Watcher> watchers);
/**
* Is triggered after all watchers stop.
*/
- public void onWatchersEnd(List watchers);
+ public void onWatchersEnd(List<Watcher> watchers);
/**
* Is triggered before this watcher starts.
Modified: trunk/punit/src/org/punit/events/EventRegistry.java
===================================================================
--- trunk/punit/src/org/punit/events/EventRegistry.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/events/EventRegistry.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -27,5 +27,5 @@
/**
* @return returns the registered event listeners.
*/
- public List eventListeners();
+ public List<EventListener> eventListeners();
}
Modified: trunk/punit/src/org/punit/events/VanillaEventListener.java
===================================================================
--- trunk/punit/src/org/punit/events/VanillaEventListener.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/events/VanillaEventListener.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -12,42 +12,29 @@
private static final long serialVersionUID = -2413131933921801719L;
public VanillaEventListener() {
-
}
public void onClassEnd(Object testInstance, Throwable t) {
-
}
public void onClassStart(Object testInstance) {
-
}
public void onMethodEnd(Method method, Object testInstance,
- Object[] params, Throwable t, List Watchers) {
- // TODO Auto-generated method stub
-
+ Object[] params, Throwable t, List<Watcher> Watchers) {
}
public void onMethodStart(Method method, Object testInstance,
Object[] params) {
- // TODO Auto-generated method stub
-
}
- public void onRunnerEnd(Class clazz, Runner runner) {
- // TODO Auto-generated method stub
-
+ public void onRunnerEnd(Class<?> clazz, Runner runner) {
}
- public void onRunnerStart(Class clazz, Runner runner) {
- // TODO Auto-generated method stub
-
+ public void onRunnerStart(Class<?> clazz, Runner runner) {
}
public void onSuiteEnd(TestSuite suite) {
- // TODO Auto-generated method stub
-
}
public void onSuiteStart(TestSuite suite) {
@@ -62,11 +49,11 @@
}
- public void onWatchersEnd(List watchers) {
+ public void onWatchersEnd(List<Watcher> watchers) {
}
- public void onWatchersStart(List watchers) {
+ public void onWatchersStart(List<Watcher> watchers) {
}
Modified: trunk/punit/src/org/punit/exception/ConcurrentException.java
===================================================================
--- trunk/punit/src/org/punit/exception/ConcurrentException.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/exception/ConcurrentException.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -2,13 +2,10 @@
package org.punit.exception;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.util.Vector;
+import java.io.*;
+import java.util.*;
-import org.punit.util.ReporterUtil;
-import org.punit.util.Traverser;
-import org.punit.util.TraverserUtil;
+import org.punit.util.*;
/**
* Exception for concurrent runner. There might be not only one exception thrown
@@ -19,7 +16,7 @@
private static final long serialVersionUID = 6816596410667344664L;
- private Vector _throwables = new Vector();
+ private Vector<Throwable> _throwables = new Vector<Throwable>();
public void add(Throwable t) {
_throwables.add(t);
@@ -31,43 +28,35 @@
public void printStackTrace() {
System.err.println(ConcurrentException.class.getName() + ":"); //$NON-NLS-1$
- TraverserUtil.traverse(_throwables.iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((Throwable) obj).printStackTrace();
- }
- });
+ Iterator<Throwable> iter = _throwables.iterator();
+ while(iter.hasNext()) {
+ iter.next().printStackTrace();
+ }
}
public void printStackTrace(final PrintStream ps) {
ps.println(ConcurrentException.class.getName() + ":"); //$NON-NLS-1$
- TraverserUtil.traverse(_throwables.iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((Throwable) obj).printStackTrace(ps);
- }
- });
+ Iterator<Throwable> iter = _throwables.iterator();
+ while(iter.hasNext()) {
+ iter.next().printStackTrace(ps);
+ }
}
public void printStackTrace(final PrintWriter pw) {
pw.println(ConcurrentException.class.getName() + ":"); //$NON-NLS-1$
- TraverserUtil.traverse(_throwables.iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((Throwable) obj).printStackTrace(pw);
- }
- });
+ Iterator<Throwable> iter = _throwables.iterator();
+ while(iter.hasNext()) {
+ iter.next().printStackTrace(pw);
+ }
}
public String getMessage() {
- GetMessageVisitor visitor = new GetMessageVisitor();
- TraverserUtil.traverse(_throwables.iterator(), visitor);
- return visitor.sb.toString();
- }
-
- static class GetMessageVisitor implements Traverser {
- final StringBuffer sb = new StringBuffer();
-
- public void traverse(Object obj) {
- sb.append(((Throwable) obj));
+ StringBuffer sb = new StringBuffer();
+ Iterator<Throwable> iter = _throwables.iterator();
+ while(iter.hasNext()) {
+ sb.append(iter.next());
sb.append(ReporterUtil.LINE_SEPERATOR);
}
+ return sb.toString();
}
}
Modified: trunk/punit/src/org/punit/message/Messages.java
===================================================================
--- trunk/punit/src/org/punit/message/Messages.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/message/Messages.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -7,7 +7,7 @@
private static ResourceBundle RESOURCE_BUNDLE = null;
- private static Hashtable MESSAGE_TABLE = null;
+ private static Hashtable<String, String> MESSAGE_TABLE = null;
private static boolean isAndroid;
@@ -26,7 +26,7 @@
}
private static void initMessageTable() {
- MESSAGE_TABLE = new Hashtable();
+ MESSAGE_TABLE = new Hashtable<String, String>();
for (int i = 0; i < MessageStrings.DATA.length; ++i) {
MESSAGE_TABLE.put(MessageStrings.DATA[i][0],
MessageStrings.DATA[i][1]);
Modified: trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/method/builder/MethodBuilderImpl.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -36,14 +36,14 @@
/**
* @see TestMethodBuilder#extractTestMethods(Class)
*/
- public Collection extractTestMethods(Class testClass) {
- Collection testMethods = null;
+ public Collection<Method> extractTestMethods(Class<?> testClass) {
+ Collection<Method> testMethods = null;
if (isAlphabetical(testClass)) {
- testMethods = new TreeSet(new AlphabeticalMethodNameComparator());
+ testMethods = new TreeSet<Method>(new AlphabeticalMethodNameComparator());
} else {
- testMethods = new ArrayList();
+ testMethods = new ArrayList<Method>();
}
- Class clazz = testClass;
+ Class<?> clazz = testClass;
while (clazz != Object.class) {
Method[] methods = clazz.getDeclaredMethods();
for (int i = 0; i < methods.length; ++i) {
@@ -57,14 +57,12 @@
return testMethods;
}
- private boolean isAlphabetical(Class testClass) {
+ private boolean isAlphabetical(Class<?> testClass) {
return Alphabetical.class.isAssignableFrom(testClass);
}
- private static class AlphabeticalMethodNameComparator implements Comparator {
- public int compare(Object o1, Object o2) {
- Method m1 = (Method) o1;
- Method m2 = (Method) o2;
+ private static class AlphabeticalMethodNameComparator implements Comparator<Method> {
+ public int compare(Method m1, Method m2) {
return m1.getName().compareTo(m2.getName());
}
}
Modified: trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/method/builder/TestMethodBuilder.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -3,6 +3,7 @@
package org.punit.method.builder;
import java.io.Serializable;
+import java.lang.reflect.*;
import java.util.Collection;
import org.punit.convention.Convention;
@@ -21,7 +22,7 @@
* @return a <code>Collection</code> of
* <code>java.lang.reflect.Method</code>.
*/
- public Collection extractTestMethods(Class testClass); // Collection<Method>
+ public Collection<Method> extractTestMethods(Class<?> testClass); // Collection<Method>
public void setConvention(Convention convention);
}
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -2,32 +2,25 @@
package org.punit.method.runner;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
+import java.lang.reflect.*;
+import java.util.*;
-import org.punit.assertion.Assert;
-import org.punit.assertion.CodeRunner;
-import org.punit.convention.Convention;
+import org.punit.assertion.*;
+import org.punit.convention.*;
import org.punit.events.EventListener;
-import org.punit.exception.ReflectionException;
-import org.punit.runner.RunnerProperties;
-import org.punit.type.Parameter;
-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.watcher.TimeWatcher;
-import org.punit.watcher.Watcher;
+import org.punit.exception.*;
+import org.punit.runner.*;
+import org.punit.type.*;
+import org.punit.util.*;
+import org.punit.watcher.*;
public abstract class AbstractMethodRunner implements MethodRunner {
- protected ArrayList _watchers = new ArrayList(); // <Watcher>
+ protected ArrayList<Watcher> _watchers = new ArrayList<Watcher>();
private TimeWatcher _timeWatcher = new TimeWatcher();
- private List _eventListeners; // List <PUnitEventListener>
+ private List<EventListener> _eventListeners;
private RunnerProperties _runnerProperties;
@@ -43,7 +36,7 @@
protected transient Object[] _params;
- protected transient Class _class;
+ protected transient Class<?> _class;
protected transient Method _setUpMethod;
@@ -51,14 +44,14 @@
private transient Method _checkMethod;
- protected transient Class _expectedException;
+ protected transient Class<? extends Throwable> _expectedException;
public AbstractMethodRunner() {
_watchers.add(_timeWatcher);
_shouldStop = true;
}
- public void setEventListeners(List eventListeners) {
+ public void setEventListeners(List<EventListener> eventListeners) {
_eventListeners = eventListeners;
}
@@ -138,22 +131,20 @@
private void onMethodStart(final Method method, final Object testInstance,
final Object[] params) {
- TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((EventListener) obj).onMethodStart(method, testInstance,
- params);
- }
- });
+ Iterator<EventListener> iter = _eventListeners.iterator();
+ while(iter.hasNext()) {
+ EventListener listener = iter.next();
+ listener.onMethodStart(method, testInstance, params);
+ }
}
private void onMethodEnd(final Method method, final Object testInstance,
final Object[] params, final Throwable t) {
- TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((EventListener) obj).onMethodEnd(method, testInstance, params,
- t, _watchers);
- }
- });
+ Iterator<EventListener> iter = _eventListeners.iterator();
+ while (iter.hasNext()) {
+ EventListener listener = iter.next();
+ listener.onMethodEnd(method, testInstance, params, t, _watchers);
+ }
}
protected abstract void runImpl() throws Throwable;
@@ -266,58 +257,53 @@
private void onWatchersStart(final Object testInstance,
final Method method, final Object[] params) {
- TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((EventListener) obj).onWatchersStart(_watchers);
- }
- });
+ Iterator<EventListener> iter = _eventListeners.iterator();
+ while(iter.hasNext()) {
+ EventListener listener = iter.next();
+ listener.onWatchersStart(_watchers);
+ }
}
private void onWatcherStart(final Watcher watcher,
final Object testInstance, final Method method,
final Object[] params) {
- TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((EventListener) obj).onWatcherStart(watcher);
- }
- });
- }
+ Iterator<EventListener> iter = _eventListeners.iterator();
+ while (iter.hasNext()) {
+ EventListener listener = iter.next();
+ listener.onWatcherStart(watcher);
+ }
+ }
protected final void stopWatchers(final Object testInstance,
- final Method method, final Object[] params) {
- TraverserUtil.traverse(_watchers.iterator(), new Traverser() {
- public void traverse(Object obj) {
- Watcher watcher = (Watcher) obj;
- watcher.stop();
- onWatcherEnd(watcher, testInstance, method, params);
- }
- });
- onWatchersEnd(testInstance, method, params);
- }
+ final Method method, final Object[] params) {
+ Iterator<Watcher> iter = _watchers.iterator();
+ while (iter.hasNext()) {
+ Watcher watcher = iter.next();
+ watcher.stop();
+ onWatcherEnd(watcher, testInstance, method, params);
+ }
+ onWatchersEnd(testInstance, method, params);
+ }
private void onWatcherEnd(final Watcher watcher, final Object testInstance,
- final Method method, final Object[] params) {
- TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((EventListener) obj).onWatcherEnd(watcher);
- }
- });
- }
+ final Method method, final Object[] params) {
+ Iterator<EventListener> iter = _eventListeners.iterator();
+ while (iter.hasNext()) {
+ EventListener listener = iter.next();
+ listener.onWatcherEnd(watcher);
+ }
+ }
private void onWatchersEnd(final Object testInstance, final Method method,
- final Object[] params) {
- TraverserUtil.traverse(eventListeners().iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((EventListener) obj).onWatchersEnd(_watchers);
- }
- });
- }
+ final Object[] params) {
+ Iterator<EventListener> iter = _eventListeners.iterator();
+ while (iter.hasNext()) {
+ EventListener listener = iter.next();
+ listener.onWatchersEnd(_watchers);
+ }
+ }
- private List eventListeners() {
- return _eventListeners;
- }
-
- public List watchers() {
+ public List<Watcher> watchers() {
return _watchers;
}
@@ -325,22 +311,22 @@
return !_runnerProperties.isParent;
}
- public Object clone() {
+ @SuppressWarnings("unchecked")
+ public Object clone() {
try {
- final AbstractMethodRunner methodRunner = (AbstractMethodRunner) super
- .clone();
- methodRunner._watchers = (ArrayList) _watchers.clone();
- methodRunner._watchers.clear();
- TraverserUtil.traverse(_watchers.iterator(), new Traverser() {
- public void traverse(Object obj) {
- Watcher watcher = (Watcher) obj;
- methodRunner.addWatcher(watcher.cloneSelf());
- }
- });
- return methodRunner;
- } catch (CloneNotSupportedException e) {
- throw new ReflectionException(e);
- }
+ final AbstractMethodRunner methodRunner = (AbstractMethodRunner) super
+ .clone();
+ methodRunner._watchers = (ArrayList<Watcher>) _watchers.clone();
+ methodRunner._watchers.clear();
+ Iterator<Watcher> iter = _watchers.iterator();
+ while (iter.hasNext()) {
+ Watcher watcher = iter.next();
+ methodRunner.addWatcher(watcher.cloneSelf());
+ }
+ return methodRunner;
+ } catch (CloneNotSupportedException e) {
+ throw new ReflectionException(e);
+ }
}
public void setConvention(Convention convention) {
Modified: trunk/punit/src/org/punit/method/runner/MethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/MethodRunner.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/method/runner/MethodRunner.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -5,6 +5,7 @@
import java.util.List;
import org.punit.convention.Convention;
+import org.punit.events.*;
import org.punit.runner.RunnerProperties;
import org.punit.watcher.Watcher;
@@ -22,14 +23,14 @@
*
* @param eventListeners List <EventListener>
*/
- public void setEventListeners(List eventListeners);
+ public void setEventListeners(List<EventListener> eventListeners);
public void setRunnerProperties(RunnerProperties props);
/**
* @return watchers associated with this method runner
*/
- public List watchers();
+ public List<Watcher> watchers();
public void addWatcher(Watcher watcher);
Modified: trunk/punit/src/org/punit/method/runner/VanillaRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/VanillaRunner.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/method/runner/VanillaRunner.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -39,11 +39,11 @@
return _runner.resultFolder();
}
- public int run(Class clazz) {
+ public int run(Class<?> clazz) {
return _runner.run(clazz);
}
- public int run(Class clazz, RunnerProperties properties) {
+ public int run(Class<?> clazz, RunnerProperties properties) {
return _runner.run(clazz, properties);
}
@@ -59,7 +59,7 @@
_runner.addEventListener(listener);
}
- public List eventListeners() {
+ public List<EventListener> eventListeners() {
return _runner.eventListeners();
}
Modified: trunk/punit/src/org/punit/reporter/TestResult.java
===================================================================
--- trunk/punit/src/org/punit/reporter/TestResult.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/reporter/TestResult.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -5,6 +5,7 @@
import java.util.*;
import org.punit.events.*;
+import org.punit.watcher.*;
public class TestResult extends VanillaEventListener {
@@ -12,10 +13,10 @@
private transient int _methodCount;
- private List _failures = new ArrayList();
+ private List<Throwable> _failures = new ArrayList<Throwable>();
public void onMethodEnd(Method method, Object testInstance,
- Object[] params, Throwable t, List Watchers) {
+ Object[] params, Throwable t, List<Watcher> Watchers) {
countMethod();
if (t != null) {
addThrowable(t);
@@ -34,7 +35,7 @@
return _methodCount;
}
- public List failures() {
+ public List<Throwable> failures() {
return _failures;
}
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -32,7 +32,7 @@
_writer = writer;
}
- public void onRunnerStart(Class clazz, Runner runner) {
+ public void onRunnerStart(Class<?> clazz, Runner runner) {
startTimeWatcher();
_result = runner.testResult();
StringBuffer sb = new StringBuffer();
@@ -51,7 +51,7 @@
_timeWatcher.start();
}
- public void onRunnerEnd(Class clazz, Runner runner) {
+ public void onRunnerEnd(Class<?> clazz, Runner runner) {
logResult();
closeStream();
}
@@ -62,12 +62,17 @@
public void logResult() {
stopTimeWatcher();
- StringBuffer sb = new StringBuffer();
+ logResultSummary();
+ logFailures();
+ }
+
+ private void logResultSummary() {
+ StringBuffer sb = new StringBuffer();
sb.append(Messages.getString("logger.total")); //$NON-NLS-1$
sb.append(_result.methodCount());
sb.append(", "); //$NON-NLS-1$
sb.append(Messages.getString("logger.failures")); //$NON-NLS-1$
- List failures = _result.failures();
+ List<Throwable> failures = _result.failures();
int failuresCount = failures.size();
sb.append(failuresCount);
sb.append(" ("); //$NON-NLS-1$
@@ -80,17 +85,20 @@
sb.append(_timeWatcher.stringValue());
sb.append(ReporterUtil.LINE_SEPERATOR);
log(sb.toString(), Level.SEVERE);
- TraverserUtil.traverse(failures.iterator(), new Traverser() {
- int count = 0;
- public void traverse(Object obj) {
- log(++count + ")", Level.SEVERE); //$NON-NLS-1$
- if(shouldLog(Level.SEVERE)) {
- ((Throwable) obj).printStackTrace(_writer);
- }
- }
- });
- }
+ }
+ private void logFailures() {
+ List<Throwable> failures = _result.failures();
+ Iterator<Throwable> iter = failures.iterator();
+ while (iter.hasNext()) {
+ int count = 0;
+ log(++count + ")", Level.SEVERE); //$NON-NLS-1$
+ if (shouldLog(Level.SEVERE)) {
+ iter.next().printStackTrace(_writer);
+ }
+ }
+ }
+
private void stopTimeWatcher() {
_timeWatcher.stop();
}
@@ -108,27 +116,25 @@
}
public void onMethodEnd(Method method, Object instance, Object[] params,
- Throwable t, List watchers) {
+ Throwable t, List<Watcher> watchers) {
logTestMethodResult(method, params, watchers, t);
}
- private void logTestMethodResult(Method method, Object[] params, List watchers, Throwable t) {
+ private void logTestMethodResult(Method method, Object[] params, List<Watcher> watchers, Throwable t) {
final StringBuffer sb = new StringBuffer();
String simpleMethodName = ReporterUtil.simpleMethodName(method, params);
sb.append(simpleMethodName);
if (watchers.size() > 0) {
- final Iterator iter = watchers.iterator();
- Watcher watcher = (Watcher) iter.next();
- sb.append(" - ["); //$NON-NLS-1$
- sb.append(watcher.stringValue());
- TraverserUtil.traverse(iter, new Traverser() {
- public void traverse(Object obj) {
- Watcher watcher = (Watcher) obj;
- sb.append(","); //$NON-NLS-1$
- sb.append(watcher.stringValue());
- }
- });
- sb.append("]"); //$NON-NLS-1$
+ final Iterator<Watcher> iter = watchers.iterator();
+ Watcher watcher = iter.next();
+ sb.append(" - ["); //$NON-NLS-1$
+ sb.append(watcher.stringValue());
+ while (iter.hasNext()) {
+ watcher = iter.next();
+ sb.append(","); //$NON-NLS-1$
+ sb.append(watcher.stringValue());
+ }
+ sb.append("]"); //$NON-NLS-1$
}
sb.append(ReporterUtil.LINE_SEPERATOR);
Modified: trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/reporter/stream/file/FileLogger.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -22,7 +22,7 @@
_fileName = fileName;
}
- public void onRunnerStart(Class clazz, Runner runner) {
+ public void onRunnerStart(Class<?> clazz, Runner runner) {
if(_fileName == null) {
ReporterUtil.initResultFolder(runner);
_fileName = ReporterUtil.defaultFileName(clazz, runner) + ".txt"; //$NON-NLS-1$
@@ -38,7 +38,7 @@
super.onRunnerStart(clazz, runner);
}
- public void onRunnerEnd(Class clazz, Runner runner) {
+ public void onRunnerEnd(Class<?> clazz, Runner runner) {
super.onRunnerEnd(clazz, runner);
}
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -2,32 +2,22 @@
package org.punit.runner;
-import java.io.File;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
+import java.io.*;
+import java.lang.reflect.*;
+import java.util.*;
-import org.punit.convention.Convention;
-import org.punit.convention.NameConvention;
+import org.punit.convention.*;
import org.punit.events.EventListener;
+import org.punit.exception.*;
import org.punit.exception.IOException;
-import org.punit.exception.ReflectionException;
-import org.punit.message.Messages;
-import org.punit.method.builder.TestMethodBuilder;
-import org.punit.method.runner.MethodRunner;
-import org.punit.reporter.TestResult;
-import org.punit.reporter.stream.console.ConsoleLogger;
-import org.punit.suite.builder.TestSuiteBuilder;
-import org.punit.suite.builder.TestSuiteLabel;
-import org.punit.type.Parameter;
-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.message.*;
+import org.punit.method.builder.*;
+import org.punit.method.runner.*;
+import org.punit.reporter.*;
+import org.punit.reporter.stream.console.*;
+import org.punit.suite.builder.*;
+import org.punit.type.*;
+import org.punit.util.*;
public abstract class AbstractRunner implements Runner {
@@ -37,7 +27,7 @@
private MethodRunner _methodRunner;
- private final List _eventListeners = new ArrayList(); // List<EventListener>
+ private final List<EventListener> _eventListeners = new ArrayList<EventListener>();
private TestResult _testResult = new TestResult();
@@ -69,7 +59,7 @@
_methodRunner.setConvention(convention);
}
- public int run(Class clazz) {
+ public int run(Class<?> clazz) {
onRunnerStart(clazz);
Object[] testClasses = _testSuiteBuiler.buildTestClasses(clazz);
runTestClasses(testClasses);
@@ -77,7 +67,7 @@
return _testResult.failures().size();
}
- public int run(Class clazz, RunnerProperties properties) {
+ public int run(Class<?> clazz, RunnerProperties properties) {
setRunnerProperties(properties);
return run(clazz);
}
@@ -89,7 +79,7 @@
if (isTestSuiteLabel(testClass)) {
onSuite(((TestSuiteLabel) testClass));
} else {
- runTestClass((Class) testClass);
+ runTestClass((Class<?>) testClass);
}
}
waitExecutorPoolTermination();
@@ -116,7 +106,7 @@
_methodRunner.setRunnerProperties(_properties);
}
- public void runVMs(Class clazz, VM[] vms) {
+ public void runVMs(Class<?> clazz, VM[] vms) {
_properties.isParent = true;
_properties.vms = vms;
for (int i = 0; i < vms.length; ++i) {
@@ -148,15 +138,14 @@
}
private void filterNonParentEventListeners() {
- final List newEventListener = new ArrayList();
- TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
- public void traverse(Object obj) {
- EventListener listener = ((EventListener) obj);
- if (listener.supportParentRunner()) {
- newEventListener.add(listener);
- }
- }
- });
+ final List<EventListener> newEventListener = new ArrayList<EventListener>();
+ Iterator<EventListener> iter = _eventListeners.iterator();
+ while (iter.hasNext()) {
+ EventListener listener = iter.next();
+ if (listener.supportParentRunner()) {
+ newEventListener.add(listener);
+ }
+ }
_eventListeners.clear();
_eventListeners.addAll(newEventListener);
}
@@ -194,7 +183,7 @@
return _properties;
}
- private String generateVMCommand(Class clazz, VM vm) {
+ private String generateVMCommand(Class<?> clazz, VM vm) {
final StringBuffer sb = new StringBuffer();
sb.append(vm.path());
sb.append(" "); //$NON-NLS-1$
@@ -208,23 +197,24 @@
return sb.toString();
}
- private void onRunnerStart(final Class clazz) {
- TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((EventListener) obj).onRunnerStart(clazz, AbstractRunner.this);
- }
- });
+ private void onRunnerStart(final Class<?> clazz) {
+ Iterator <EventListener> iter = _eventListeners.iterator();
+ while(iter.hasNext()) {
+ EventListener listener = iter.next();
+ listener.onRunnerStart(clazz, AbstractRunner.this);
+ }
+
}
- private void onRunnerEnd(final Class clazz) {
- TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((EventListener) obj).onRunnerEnd(clazz, AbstractRunner.this);
- }
- });
+ private void onRunnerEnd(final Class<?> clazz) {
+ Iterator <EventListener> iter = _eventListeners.iterator();
+ while(iter.hasNext()) {
+ EventListener listener = iter.next();
+ listener.onRunnerEnd(clazz, AbstractRunner.this);
+ }
}
- private void runTestClass(final Class clazz) {
+ private void runTestClass(final Class<?> clazz) {
if (_executorPool == null) {
runTestClassImpl(clazz);
} else {
@@ -244,9 +234,9 @@
}
private class RunTestClassTask implements Runnable {
- private Class _clazz;
+ private Class<?> _clazz;
- public RunTestClassTask(Class clazz) {
+ public RunTestClassTask(Class<?> clazz) {
_clazz = clazz;
}
@@ -258,33 +248,33 @@
}
- private void runTestClassImpl(final Class clazz) {
+ private void runTestClassImpl(final Class<?> clazz) {
final Object testInstance = ReflectionUtil.newInstance(clazz);
- Throwable storedException = null;
- Collection testMethods = extractTestMethods(clazz);
-
+ Throwable exception = null;
+ Collection<Method> testMethods = extractTestMethods(clazz);
onClassStart(testInstance);
try {
- beforeClass(clazz);
- TraverserUtil.traverse(testMethods.iterator(), new Traverser() {
- public void traverse(Object obj) {
- Method method = (Method) obj;
- runTestMethod(testInstance, method);
- }
- });
- } catch (Throwable t) {
- storedException = t;
+ beforeClass(clazz);
+ Iterator<Method> iter = testMethods.iterator();
+ while (iter.hasNext()) {
+ Method method = iter.next();
+ runTestMethod(testInstance, method);
+ }
+ } catch (Throwable t) {
+ exception = t;
} finally {
try {
afterClass(clazz);
} catch (Throwable t) {
- storedException = t;
+ if(exception == null) {
+ exception = t;
+ }
}
}
- onClassEnd(testInstance, storedException);
+ onClassEnd(testInstance, exception);
}
- private void beforeClass(Class clazz) {
+ private void beforeClass(Class<?> clazz) {
Method beforeClassMethod = _convention.getBeforeClassMethod(clazz);
if (beforeClassMethod != null) {
ReflectionUtil.invokeMethod(beforeClassMethod, null,
@@ -292,7 +282,7 @@
}
}
- private void afterClass(Class clazz) {
+ private void afterClass(Class<?> clazz) {
Method afterClassMethod = _convention.getAfterClassMethod(clazz);
if (afterClassMethod != null) {
ReflectionUtil
@@ -301,34 +291,33 @@
}
private void onSuite(final TestSuiteLabel suiteLabel) {
- TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
- public void traverse(Object obj) {
- EventListener listener = ((EventListener) obj);
- TestSuite suite = suiteLabel.suite();
- if (suiteLabel.isStart()) {
- listener.onSuiteStart(suite);
- } else {
- listener.onSuiteEnd(suite);
- }
- }
- });
- }
+ Iterator<EventListener> iter = _eventListeners.iterator();
+ while (iter.hasNext()) {
+ EventListener listener = iter.next();
+ TestSuite suite = suiteLabel.suite();
+ if (suiteLabel.isStart()) {
+ listener.onSuiteStart(suite);
+ } else {
+ listener.onSuiteEnd(suite);
+ }
+ }
+ }
private void onClassStart(final Object testInstance) {
- TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((EventListener) obj).onClassStart(testInstance);
- }
- });
- }
+ Iterator<EventListener> iter = _eventListeners.iterator();
+ while (iter.hasNext()) {
+ EventListener listener = iter.next();
+ listener.onClassStart(testInstance);
+ }
+ }
private void onClassEnd(final Object testInstance, final Throwable t) {
- TraverserUtil.traverse(_eventListeners.iterator(), new Traverser() {
- public void traverse(Object obj) {
- ((EventListener) obj).onClassEnd(testInstance, t);
- }
- });
- }
+ Iterator<EventListener> iter = _eventListeners.iterator();
+ while (iter.hasNext()) {
+ EventListener listener = iter.next();
+ listener.onClassEnd(testInstance, t);
+ }
+ }
private void runTestMethod(Object testInstance, Method method) {
if (_convention.isParameterizedTest(testInstance.getClass())) {
@@ -343,7 +332,7 @@
}
}
- private Collection extractTestMethods(Class testClass) {
+ private Collection<Method> extractTestMethods(Class<?> testClass) {
return _testMethodBuilder.extractTestMethods(testClass);
}
@@ -364,7 +353,7 @@
addEventListener(_consoleLogger);
}
- public List eventListeners() {
+ public List<EventListener> eventListeners() {
return _eventListeners;
}
Added: trunk/punit/src/org/punit/runner/ExecutorPoolImpl.java
===================================================================
--- trunk/punit/src/org/punit/runner/ExecutorPoolImpl.java (rev 0)
+++ trunk/punit/src/org/punit/runner/ExecutorPoolImpl.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -0,0 +1,40 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package org.punit.runner;
+
+import java.util.concurrent.*;
+import org.punit.exception.*;
+
+public class ExecutorPoolImpl implements ExecutorPool {
+
+ private static final long serialVersionUID = 642472113631919417L;
+
+ private int _threadCount;
+
+ private transient ExecutorService _pool;
+
+ public ExecutorPoolImpl(int count) {
+ if (count < 1) {
+ throw new IllegalArgumentException();
+ }
+ _threadCount = count;
+ }
+
+ public void execute(Runnable task) {
+ _pool.execute(task);
+ }
+
+ public void join() {
+ try {
+ _pool.shutdown();
+ _pool.awaitTermination(Integer.MAX_VALUE, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ throw new IOException(e);
+ }
+ }
+
+ public void start() {
+ _pool = Executors.newFixedThreadPool(_threadCount);
+ }
+
+}
Property changes on: trunk/punit/src/org/punit/runner/ExecutorPoolImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/runner/Runner.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -13,9 +13,9 @@
public interface Runner extends EventRegistry, Name, Serializable, Cloneable {
- public int run(Class clazz);
+ public int run(Class<?> clazz);
- public int run(Class clazz, RunnerProperties properties);
+ public int run(Class<?> clazz, RunnerProperties properties);
public RunnerProperties properties();
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilder.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -18,7 +18,7 @@
* @param clazz
* @return
*/
- public Object[] buildTestClasses(Class testSutie);
+ public Object[] buildTestClasses(Class<?> testSutie);
public void setConvention(Convention convention);
}
Modified: trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java
===================================================================
--- trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2008-01-11 15:55:28 UTC (rev 269)
+++ trunk/punit/src/org/punit/suite/builder/TestSuiteBuilderImpl.java 2008-01-11 15:57:04 UTC (rev 270)
@@ -21,13 +21,13 @@
/**
* @see TestSuiteBuilder#buildTestClasses(Class)
*/
- public Object[] buildTestClasses(Class clazz) {
- List testClasses = new ArrayList();
+ public Object[] buildTestClasses(Class<?> clazz) {
+ List<Object> test...
[truncated message content] |
|
From: <zha...@us...> - 2008-01-11 15:55:26
|
Revision: 269
http://p-unit.svn.sourceforge.net/p-unit/?rev=269&view=rev
Author: zhanghuangzhu
Date: 2008-01-11 07:55:28 -0800 (Fri, 11 Jan 2008)
Log Message:
-----------
Andrew Zhang: Looking forward, based on java 5 now.
Modified Paths:
--------------
trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
Removed Paths:
-------------
trunk/punit.extension/src/org/punit/annotation/
trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java
trunk/punit.extension/src/org/punit/runner/
trunk/punit.extension/src/org/punit/util/
Deleted: trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java
===================================================================
--- trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java 2008-01-11 15:55:11 UTC (rev 268)
+++ trunk/punit.extension/src/org/punit/convention/AnnotationConvention.java 2008-01-11 15:55:28 UTC (rev 269)
@@ -1,134 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.convention;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import org.punit.annotation.Test;
-import org.punit.util.AnnotationUtil;
-import org.punit.util.ReflectionUtil;
-
-/**
- * The class merges annotation and name conventions with annotations taking
- * preference.
- */
-public class AnnotationConvention extends AbstractConvention {
-
- private static final long serialVersionUID = -6800242731470821241L;
-
- protected NameConvention _delegate = new NameConvention();
-
- private Class<? extends Annotation> _after;
- private Class<? extends Annotation> _afterClass;
- private Class<? extends Annotation> _before;
- private Class<? extends Annotation> _beforeClass;
- private Class<? extends Annotation> _ignore;
- protected Class<? extends Annotation> _test;
-
- public AnnotationConvention() {
- this(org.punit.annotation.After.class,
- org.punit.annotation.AfterClass.class,
- org.punit.annotation.Before.class,
- org.punit.annotation.BeforeClass.class,
- org.punit.annotation.Ignore.class, Test.class);
- }
-
- public AnnotationConvention(Class<? extends Annotation> after,
- Class<? extends Annotation> afterClass,
- Class<? extends Annotation> before,
- Class<? extends Annotation> beforeClass,
- Class<? extends Annotation> ignore, Class<? extends Annotation> test) {
- _after = after;
- _afterClass = afterClass;
- _before = before;
- _beforeClass = beforeClass;
- _ignore = ignore;
- _test = test;
- }
-
- public Method getCheckMethod(Method method) {
- Test testAnnotation = (Test) method.getAnnotation(_test);
- String checkMethodName = null;
- if (testAnnotation != null) {
- checkMethodName = testAnnotation.checkMethod();
- if (checkMethodName != null && checkMethodName.length() > 0) {
- return ReflectionUtil.getMethod(method.getDeclaringClass(),
- checkMethodName, method.getParameterTypes());
- }
- }
- return _delegate.getCheckMethod(method);
- }
-
- @SuppressWarnings("unchecked")
- public boolean isExcluded(Class clazz) {
- return clazz.isAnnotationPresent(_ignore);
- }
-
- public boolean isTestMethod(Method method) {
- if (method.isAnnotationPresent(_ignore)) {
- return false;
- }
- return method.isAnnotationPresent(_test) || _delegate.isTestMethod(method);
- }
-
- public Class<? extends Throwable> getExpectedException(Method method) {
- Test testAnnotation = (Test) method.getAnnotation(_test);
- if (testAnnotation == null) {
- return null;
- }
- Class<? extends Throwable> expected = testAnnotation.expected();
- if (expected == Test.NoException.class) {
- return null;
- }
- return expected;
- }
-
- public int getConcurrentCount(Object testInstance, Method method) {
- Test testAnnotation = (Test) method.getAnnotation(_test);
- if (testAnnotation == null) {
- testAnnotation = (Test) testInstance.getClass().getAnnotation(_test);
- }
- if (testAnnotation == null) {
- return _delegate.getConcurrentCount(testInstance, method);
- }
- return testAnnotation.concurrentCount();
- }
-
- @SuppressWarnings("unchecked")
- public Method getAfterClassMethod(Class test) {
- Method method = AnnotationUtil.getMethodByAnnotation(test, _afterClass);
- if (method == null) {
- method = _delegate.getAfterClassMethod(test);
- }
- return method;
- }
-
- @SuppressWarnings("unchecked")
- public Method getBeforeClassMethod(Class test) {
- Method method = AnnotationUtil
- .getMethodByAnnotation(test, _beforeClass);
- if (method == null) {
- method = _delegate.getBeforeClassMethod(test);
- }
- return method;
- }
-
- @SuppressWarnings("unchecked")
- public Method getSetUpMethod(Class test) {
- Method method = AnnotationUtil.getMethodByAnnotation(test, _before);
- if (method == null) {
- method = _delegate.getSetUpMethod(test);
- }
- return method;
- }
-
- @SuppressWarnings("unchecked")
- public Method getTearDownMethod(Class test) {
- Method method = AnnotationUtil.getMethodByAnnotation(test, _after);
- if (method == null) {
- method = _delegate.getTearDownMethod(test);
- }
- return method;
- }
-
-}
Modified: trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2008-01-11 15:55:11 UTC (rev 268)
+++ trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2008-01-11 15:55:28 UTC (rev 269)
@@ -2,29 +2,20 @@
package org.punit.reporter.chart;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.ObjectInputStream;
-import java.lang.reflect.Method;
-import java.util.Hashtable;
-import java.util.LinkedList;
-import java.util.List;
+import java.io.*;
+import java.lang.reflect.*;
+import java.util.*;
-import org.jfree.chart.JFreeChart;
-import org.jfree.data.category.DefaultCategoryDataset;
+import org.jfree.chart.*;
+import org.jfree.data.category.*;
import org.punit.events.*;
import org.punit.exception.IOException;
-import org.punit.message.Messages;
-import org.punit.reporter.chart.image.ImageConstants;
-import org.punit.runner.Runner;
-import org.punit.runner.RunnerProperties;
-import org.punit.type.TestSuite;
-import org.punit.type.VM;
-import org.punit.util.IOUtil;
-import org.punit.util.ReporterUtil;
-import org.punit.util.Traverser;
-import org.punit.util.TraverserUtil;
-import org.punit.watcher.Watcher;
+import org.punit.message.*;
+import org.punit.reporter.chart.image.*;
+import org.punit.runner.*;
+import org.punit.type.*;
+import org.punit.util.*;
+import org.punit.watcher.*;
public abstract class AbstractChartReporter extends VanillaEventListener {
@@ -201,24 +192,22 @@
return _currentSuiteStack.getLast();
}
- @SuppressWarnings("unchecked")
public synchronized void onMethodEnd(final Method method,
- final Object testInstance, final Object[] params,
- final Throwable t, List watchers) {
- TraverserUtil.traverse(watchers.iterator(), new Traverser() {
- public void traverse(Object obj) {
- Watcher watcher = (Watcher) obj;
- DatasetKey key = getKey(watcher);
- DefaultCategoryDataset dataset = getDatasetOrNew(key);
- if (isParentRunner()) {
- return;
- }
- double value = watcher.value();
- String yname = testInstance.getClass().getSimpleName();
- String xname = ReporterUtil.simpleMethodName(method, params);
- dataset.addValue(value, yname, xname); // value, y, x
- }
- });
- }
+ final Object testInstance, final Object[] params,
+ final Throwable t, List<Watcher> watchers) {
+ Iterator<Watcher> iter = watchers.iterator();
+ while (iter.hasNext()) {
+ Watcher watcher = iter.next();
+ DatasetKey key = getKey(watcher);
+ DefaultCategoryDataset dataset = getDatasetOrNew(key);
+ if (isParentRunner()) {
+ return;
+ }
+ double value = watcher.value();
+ String yname = testInstance.getClass().getSimpleName();
+ String xname = ReporterUtil.simpleMethodName(method, params);
+ dataset.addValue(value, yname, xname); // value, y, x
+ }
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-01-11 15:55:11
|
Revision: 268
http://p-unit.svn.sourceforge.net/p-unit/?rev=268&view=rev
Author: zhanghuangzhu
Date: 2008-01-11 07:55:11 -0800 (Fri, 11 Jan 2008)
Log Message:
-----------
Andrew Zhang: Looking forward, based on java 5 now.
Modified Paths:
--------------
trunk/punit.extension.test/src/tests/api/org/punit/all/AllTests.java
Added Paths:
-----------
trunk/punit.extension.test/src/tests/api/org/punit/runner/FieldSetterTest.java
Removed Paths:
-------------
trunk/punit.extension.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java
trunk/punit.extension.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java
trunk/punit.extension.test/src/tests/api/org/punit/method/runner/
trunk/punit.extension.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
trunk/punit.extension.test/src/tests/api/org/punit/runner/ExecutorPoolTest.java
trunk/punit.extension.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
trunk/punit.extension.test/src/tests/api/org/punit/suite/builder/
Modified: trunk/punit.extension.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.extension.test/src/tests/api/org/punit/all/AllTests.java 2008-01-10 08:29:38 UTC (rev 267)
+++ trunk/punit.extension.test/src/tests/api/org/punit/all/AllTests.java 2008-01-11 15:55:11 UTC (rev 268)
@@ -1,25 +1,19 @@
package tests.api.org.punit.all;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import tests.api.org.punit.convention.AnnotationFilterTest;
-import tests.api.org.punit.convention.JUnitAnnotationConventionTest;
-import tests.api.org.punit.convention.NameConventionFilterTest;
-import tests.api.org.punit.method.runner.AbstractTestMethodRunnerTest;
-import tests.api.org.punit.reporter.chart.AbstractChartReporterTest;
-import tests.api.org.punit.runner.ConcurrentRunnerTest;
-import tests.api.org.punit.runner.ExecutorPoolTest;
-import tests.api.org.punit.runner.SoloRunnerExtensionTest;
-import tests.api.org.punit.runner.SoloRunnerTest;
-import tests.api.org.punit.suite.builder.TestSuiteBuilderTest;
+import junit.framework.*;
+import tests.api.org.punit.convention.*;
+import tests.api.org.punit.method.runner.*;
+import tests.api.org.punit.reporter.chart.*;
+import tests.api.org.punit.runner.*;
+import tests.api.org.punit.suite.builder.*;
public class AllTests {
+ @SuppressWarnings("unchecked")
public static Test suite() {
TestSuite suite = new TestSuite("Test for tests.api.org.punit"); //$NON-NLS-1$
// $JUnit-BEGIN$
- Class<? extends TestCase>[] tests = testSuite();
+ Class<? extends TestCase>[] tests = (Class<? extends TestCase>[]) testSuite();
for (int i = 0; i < tests.length; ++i) {
suite.addTestSuite(tests[i]);
}
@@ -27,18 +21,12 @@
return suite;
}
- public static final Class<? extends TestCase>[] testSuite() {
- return new Class[] {
+ public static final Class<?>[] testSuite() {
+ return new Class <?> [] {
AbstractChartReporterTest.class,
- AbstractTestMethodRunnerTest.class,
- AnnotationFilterTest.class,
- ConcurrentRunnerTest.class,
- ExecutorPoolTest.class,
JUnitAnnotationConventionTest.class,
- NameConventionFilterTest.class,
SoloRunnerExtensionTest.class,
- SoloRunnerTest.class,
- TestSuiteBuilderTest.class,
+ FieldSetterTest.class,
};
}
}
Deleted: trunk/punit.extension.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java
===================================================================
--- trunk/punit.extension.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java 2008-01-10 08:29:38 UTC (rev 267)
+++ trunk/punit.extension.test/src/tests/api/org/punit/convention/AnnotationFilterTest.java 2008-01-11 15:55:11 UTC (rev 268)
@@ -1,120 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package tests.api.org.punit.convention;
-
-import java.lang.reflect.Method;
-
-import junit.framework.TestCase;
-
-import org.punit.annotation.Ignore;
-import org.punit.convention.AnnotationConvention;
-import org.punit.util.ReflectionUtil;
-
-import tests.api.org.punit.testclasses.AnnotationTestClass;
-import tests.api.org.punit.testclasses.ConcurrentTestClass;
-import tests.api.org.punit.testclasses.TestClass0;
-import tests.api.org.punit.testclasses.TestClass1;
-
-public class AnnotationFilterTest extends TestCase {
- AnnotationConvention _filter = new AnnotationConvention();
-
- public void testIsExcluded() {
- assertTrue(_filter.isExcluded(ExcludedClass.class));
- assertFalse(_filter.isExcluded(NonExcludedClass.class));
- assertFalse(_filter.isExcluded(AnnotationTestClass.class));
- }
-
- public void testIsTestMethod() {
- Method method;
- method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test1", new Class[] {}); //$NON-NLS-1$
- assertFalse(_filter.isTestMethod(method));
-
- method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
- assertTrue(_filter.isTestMethod(method));
- }
-
- public void testGetCheckMethod() {
- Method method, checkMethod;
- method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test1", new Class[] {}); //$NON-NLS-1$
- assertFalse(_filter.isTestMethod(method));
- checkMethod = _filter.getCheckMethod(method);
- assertNull(checkMethod);
-
- method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
- assertTrue(_filter.isTestMethod(method));
- checkMethod = _filter.getCheckMethod(method);
- assertEquals("annotation_check_2", checkMethod.getName()); //$NON-NLS-1$
-
- method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test3", new Class[] {}); //$NON-NLS-1$
- assertTrue(_filter.isTestMethod(method));
- checkMethod = _filter.getCheckMethod(method);
- assertEquals("check__test3", checkMethod.getName()); //$NON-NLS-1$
- }
-
- public void testGetExpectedException() {
- Method method;
- Class exception;
-
- method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test1", new Class[] {}); //$NON-NLS-1$
- exception = _filter.getExpectedException(method);
- assertNull(exception);
-
- method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
- exception = _filter.getExpectedException(method);
- assertSame(NullPointerException.class, exception);
-
- method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test3", new Class[] {}); //$NON-NLS-1$
- exception = _filter.getExpectedException(method);
- assertNull(exception);
- }
-
- public void testGetConcurrentCount1() {
- Method method = ReflectionUtil.getMethod(ConcurrentTestClass.class, "test1", new Class[] {}); //$NON-NLS-1$
- ConcurrentTestClass test = new ConcurrentTestClass();
- int count = _filter.getConcurrentCount(test, method);
- assertEquals(test.concurrentCount(), count);
-
- method = ReflectionUtil.getMethod(AnnotationTestClass.class, "test1", new Class[] {}); //$NON-NLS-1$
- assertEquals(0, _filter.getConcurrentCount(new TestClass0(), method));
- }
-
- public void testGetConcurrentCountClass() {
- Method method = ReflectionUtil.getMethod(AnnotationTestClass.class, "test1", new Class[] {}); //$NON-NLS-1$
- AnnotationTestClass test = new AnnotationTestClass();
- int count = _filter.getConcurrentCount(test, method);
- assertEquals(5, count);
- }
-
- public void testGetConcurrentCountMethod() {
- Method method = ReflectionUtil.getMethod(AnnotationTestClass.class, "_test2", new Class[] {}); //$NON-NLS-1$
- int count = _filter.getConcurrentCount(new AnnotationTestClass(), method);
- assertEquals(6, count);
- }
-
- public void testGetSetUpMethod() {
- assertNotNull(_filter.getSetUpMethod(AnnotationTestClass.class));
- }
-
- public void testGetTearDownMethod() {
- assertNotNull(_filter.getTearDownMethod(AnnotationTestClass.class));
- }
-
- public void testGetBeforeClass() {
- assertNotNull(_filter.getBeforeClassMethod(AnnotationTestClass.class));
- assertNull(_filter.getBeforeClassMethod(TestClass1.class));
- }
-
- public void testGetAfterClass() {
- assertNotNull(_filter.getAfterClassMethod(AnnotationTestClass.class));
- assertNull(_filter.getAfterClassMethod(TestClass1.class));
- }
-
- @Ignore
- static class ExcludedClass {
-
- }
-
- static class NonExcludedClass {
-
- }
-}
Deleted: trunk/punit.extension.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java
===================================================================
--- trunk/punit.extension.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java 2008-01-10 08:29:38 UTC (rev 267)
+++ trunk/punit.extension.test/src/tests/api/org/punit/convention/NameConventionFilterTest.java 2008-01-11 15:55:11 UTC (rev 268)
@@ -1,103 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package tests.api.org.punit.convention;
-
-import java.lang.reflect.Method;
-
-import junit.framework.TestCase;
-
-import org.punit.convention.NameConvention;
-import org.punit.util.ReflectionUtil;
-
-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));
- }
-
- 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$
- 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));
- }
-
- public void testGetSetUpMethod() {
- 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(LoopTestClass.class));
- assertFalse(_convention.isLoopTest(TestClass0.class));
- }
-
- public void testGetToWork() {
- 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() {
-
- }
-}
Deleted: trunk/punit.extension.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
===================================================================
--- trunk/punit.extension.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2008-01-10 08:29:38 UTC (rev 267)
+++ trunk/punit.extension.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2008-01-11 15:55:11 UTC (rev 268)
@@ -1,101 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package tests.api.org.punit.runner;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.punit.convention.AnnotationConvention;
-import org.punit.runner.ConcurrentRunner;
-import org.punit.runner.SoloRunner;
-
-import tests.api.org.punit.testclasses.AnnotationTestClass;
-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;
-import tests.api.org.punit.testclasses.TestClass3;
-import tests.api.org.punit.testclasses.TestSuiteClass;
-import tests.util.TestUtil;
-
-public class ConcurrentRunnerTest extends TestCase {
-
- private ConcurrentRunner _runner = new ConcurrentRunner();
-
- public static void main(String[] args) {
- new SoloRunner().run(ConcurrentRunnerTest.class);
- }
-
- public void testMain() {
- ConcurrentRunner.main(new String[] { TestSuiteClass.class.getName() });
- }
-
- public void testRun() {
- _runner.run(TestSuiteClass.class);
- }
-
- public void testRunLoopTest() {
- LoopTestClass.reset();
- _runner.run(LoopTestClass.class);
- LoopTestClass.assertTestClassRun();
- }
-
- public void testRunConcurrent() {
- ConcurrentTestClass.reset();
- _runner.run(ConcurrentTestClass.class);
- assertConcurrentTestClassRun();
- }
-
- public void testRunTest() {
- TestClass0.reset();
- _runner.run(TestClass0.class);
- TestClass0.assertTestClassRun();
- }
-
- public void testRunAnnotationTest() {
- AnnotationTestClass.reset();
- _runner.setConvention(new AnnotationConvention());
- _runner.run(AnnotationTestClass.class);
- AnnotationTestClass.assertTestClassRun();
- }
-
- public void testRunPUnitTest() {
- TestClass3.reset();
- _runner.run(TestClass3.class);
- TestClass3.assertTestClassRun();
- }
-
- public void testRunParameterized() throws Exception {
- ConcurrentParameterizedTestClass.reset();
- _runner.run(ConcurrentParameterizedTestClass.class);
- ConcurrentParameterizedTestClass.assertTestClassRun();
- }
-
- public void testRunTestSuite() {
- ConcurrentTestClass.reset();
- TestClass0.reset();
- TestClass3.reset();
- _runner.run(TestSuiteClass.class);
- assertConcurrentTestClassRun();
- TestClass0.assertTestClassRun();
- TestClass3.assertTestClassRun();
- }
-
- public void testSerializable() throws Exception {
- _runner.addEventListener(new MockEventListener());
- List expectedListeners = _runner.eventListeners();
- ConcurrentRunner runner = (ConcurrentRunner) TestUtil
- .getSerialiableObject(_runner);
- List eventListeners = runner.eventListeners();
- assertEquals(expectedListeners.size(), eventListeners.size());
- }
-
- private void assertConcurrentTestClassRun() {
- ConcurrentTestClass test = new ConcurrentTestClass();
- assertEquals(test.concurrentCount(), ConcurrentTestClass.value);
- assertTrue(ConcurrentTestClass._assertCheck1);
- assertTrue(ConcurrentTestClass._assertCheck2);
- }
-
-}
Deleted: trunk/punit.extension.test/src/tests/api/org/punit/runner/ExecutorPoolTest.java
===================================================================
--- trunk/punit.extension.test/src/tests/api/org/punit/runner/ExecutorPoolTest.java 2008-01-10 08:29:38 UTC (rev 267)
+++ trunk/punit.extension.test/src/tests/api/org/punit/runner/ExecutorPoolTest.java 2008-01-11 15:55:11 UTC (rev 268)
@@ -1,51 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package tests.api.org.punit.runner;
-
-import org.punit.assertion.*;
-import org.punit.runner.*;
-
-import tests.util.*;
-
-import junit.framework.*;
-
-public class ExecutorPoolTest extends TestCase {
-
- private ExecutorPoolImpl _pool = new ExecutorPoolImpl(5);
-
- public void testCtor() {
- AssertUtil.assertException(IllegalArgumentException.class,
- new CodeRunner() {
- public void run() throws Throwable {
- new ExecutorPoolImpl(0);
- }
- });
- }
-
- public void testStartJoin() {
- _pool.start();
- _pool.join();
- }
-
- public void testExecute() {
- _pool.start();
- RunnableTask task = new RunnableTask();
- _pool.execute(task);
- _pool.join();
- task.assertExecuted();
- }
-
- static class RunnableTask implements Runnable {
-
- private boolean _executed;
-
- public void run() {
- _executed = true;
- }
-
- public void assertExecuted() {
- assertTrue(_executed);
- }
-
- }
-}
Copied: trunk/punit.extension.test/src/tests/api/org/punit/runner/FieldSetterTest.java (from rev 242, trunk/punit.extension.test/src/tests/api/org/punit/runner/SoloRunnerTest.java)
===================================================================
--- trunk/punit.extension.test/src/tests/api/org/punit/runner/FieldSetterTest.java (rev 0)
+++ trunk/punit.extension.test/src/tests/api/org/punit/runner/FieldSetterTest.java 2008-01-11 15:55:11 UTC (rev 268)
@@ -0,0 +1,45 @@
+/* (C) Copyright 2007, by Andrew Zhang */
+
+package tests.api.org.punit.runner;
+
+import java.util.*;
+
+import org.punit.events.EventListener;
+import org.punit.listener.*;
+import org.punit.method.runner.*;
+import org.punit.runner.*;
+import org.punit.watcher.*;
+
+import tests.api.org.punit.testclasses.*;
+
+public class FieldSetterTest extends AbstractRunnerTest {
+
+ private SoloRunner _runner;
+
+ protected void setUp() throws Exception {
+ _runner = new SoloRunner();
+ _eventListener = new MockEventListener();
+ _runner.addEventListener(_eventListener);
+ }
+
+ public void testRunSetResultTest() {
+ MethodRunner methodRunner = _runner.methodRunner();
+ CustomWatcher watcher = new CustomWatcher(methodRunner,
+ SetResultTestClass.SUPPORTED_THREADS,
+ SetResultTestClass.THREAD_UNITS);
+ _runner.run(SetResultTestClass.class);
+ methodRunner.removeWatcher(watcher);
+ }
+
+ public void testFieldSetter() {
+ Properties properties = new Properties();
+ // 12 + 18 = ParameterizedTestClass.SUM
+ properties.put("VALUE1", "12"); //$NON-NLS-1$ //$NON-NLS-2$
+ properties.put("VALUE2", "18"); //$NON-NLS-1$ //$NON-NLS-2$
+ EventListener listener = new FieldSetter(properties);
+ _runner.addEventListener(listener);
+ _runner.run(ParameterizedTestClass.class);
+ _runner.removeEventListener(listener);
+ }
+
+}
Deleted: trunk/punit.extension.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
===================================================================
--- trunk/punit.extension.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2008-01-10 08:29:38 UTC (rev 267)
+++ trunk/punit.extension.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2008-01-11 15:55:11 UTC (rev 268)
@@ -1,132 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-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;
-
-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.ParameterizedTestClass;
-import tests.api.org.punit.testclasses.SetResultTestClass;
-import tests.api.org.punit.testclasses.TestClass0;
-import tests.api.org.punit.testclasses.TestClass3;
-import tests.api.org.punit.testclasses.TestSuiteClass;
-import tests.util.TestUtil;
-
-public class SoloRunnerTest extends AbstractRunnerTest {
-
- private SoloRunner _runner;
-
- protected void setUp() throws Exception {
- _runner = new SoloRunner();
- _eventListener = new MockEventListener();
- _runner.addEventListener(_eventListener);
- }
-
- public void testMain() {
- SoloRunner.main(new String[] { TestSuiteClass.class.getName() });
- }
-
- public void testRun() {
- _runner.run(TestSuiteClass.class);
- }
-
- public void testRunTest() {
- TestClass0.reset();
- _runner.run(TestClass0.class);
- TestClass0.assertTestClassRun();
- _eventListener.assertAllEventsInvoked();
- }
-
- public void testRunLoopTest() {
- LoopTestClass.reset();
- _runner.run(LoopTestClass.class);
- LoopTestClass.assertTestClassRun();
- _eventListener.assertAllEventsInvoked();
- }
-
- public void testRunSetResultTest() {
- MethodRunner methodRunner = _runner.methodRunner();
- CustomWatcher watcher = new CustomWatcher(methodRunner,
- SetResultTestClass.SUPPORTED_THREADS,
- SetResultTestClass.THREAD_UNITS);
- _runner.run(SetResultTestClass.class);
- methodRunner.removeWatcher(watcher);
- }
-
- public void testFieldSetter() {
- Properties properties = new Properties();
- // 12 + 18 = ParameterizedTestClass.SUM
- properties.put("VALUE1", "12"); //$NON-NLS-1$ //$NON-NLS-2$
- properties.put("VALUE2", "18"); //$NON-NLS-1$ //$NON-NLS-2$
- EventListener listener = new FieldSetter(properties);
- _runner.addEventListener(listener);
- _runner.run(ParameterizedTestClass.class);
- _runner.removeEventListener(listener);
- }
-
- public void testRunAnnotationTest() {
- AnnotationTestClass.reset();
- _runner.setConvention(new AnnotationConvention());
- _runner.run(AnnotationTestClass.class);
- AnnotationTestClass.assertTestClassRun();
- }
-
- public void testRunPUnitTest() {
- TestClass3.reset();
- _runner.run(TestClass3.class);
- TestClass3.assertTestClassRun();
- _eventListener.assertAllEventsInvoked();
- }
-
- public void testRunConcurrent() {
- ConcurrentTestClass.reset();
- _runner.run(ConcurrentTestClass.class);
- assertConcurrentTestClassRun();
- _eventListener.assertAllEventsInvoked();
- }
-
- public void testRunParameterized() throws Exception {
- ParameterizedTestClass.reset();
- _runner.run(ParameterizedTestClass.class);
- ParameterizedTestClass.assertTestClassRun();
- }
-
- public void testRunTestSuite() {
- TestClass0.reset();
- TestClass3.reset();
- _runner.run(TestSuiteClass.class);
- TestClass0.assertTestClassRun();
-
- TestClass3.reset();
- _runner.run(TestClass3.class);
- TestClass3.assertTestClassRun();
-
- _eventListener.assertAllEventsInvoked();
- Assert.assertTrue(_eventListener._onSuiteEnd);
- Assert.assertTrue(_eventListener._onSuiteStart);
- }
-
- public void testSerializable() throws Exception {
- _runner.addEventListener(new MockEventListener());
- int expectedListenersSize = _runner.eventListeners().size();
- SoloRunner runner = (SoloRunner) TestUtil.getSerialiableObject(_runner);
- int eventListenersSize = runner.eventListeners().size();
- assertEquals(expectedListenersSize, eventListenersSize);
- }
-
- private void assertConcurrentTestClassRun() {
- assertEquals(1, ConcurrentTestClass.value);
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-01-10 08:29:36
|
Revision: 267
http://p-unit.svn.sourceforge.net/p-unit/?rev=267&view=rev
Author: zhanghuangzhu
Date: 2008-01-10 00:29:38 -0800 (Thu, 10 Jan 2008)
Log Message:
-----------
Andrew Zhang: Added CyclicBarrier for concurrent runner.
Modified Paths:
--------------
trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
Modified: trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2007-12-25 15:15:16 UTC (rev 266)
+++ trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2008-01-10 08:29:38 UTC (rev 267)
@@ -2,6 +2,8 @@
package org.punit.method.runner;
+import java.util.concurrent.*;
+
import org.punit.exception.ConcurrentException;
public class ConcurrentMethodRunner extends AbstractMethodRunner {
@@ -13,6 +15,8 @@
private int _concurrentCount;
private transient TestMethodThread[] _threads;
+
+ private transient CyclicBarrier _barrier;
public ConcurrentMethodRunner(int concurrentCount) {
_concurrentCount = concurrentCount;
@@ -30,6 +34,7 @@
int count = _convention.getConcurrentCount(_testInstance, _method);
int threadCount = count > 0 ? count : _concurrentCount;
_threads = new TestMethodThread[threadCount];
+ _barrier = new CyclicBarrier(threadCount);
for (int i = 0; i < _threads.length; ++i) {
_threads[i] = new TestMethodThread(this,
"punit concurrent method runner"); //$NON-NLS-1$
@@ -63,6 +68,7 @@
public void run() {
try {
+ _barrier.await();
_runner.runMethod();
} catch (Throwable t) {
_concurrentException.add(t);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-12-25 15:15:11
|
Revision: 266
http://p-unit.svn.sourceforge.net/p-unit/?rev=266&view=rev
Author: zhanghuangzhu
Date: 2007-12-25 07:15:16 -0800 (Tue, 25 Dec 2007)
Log Message:
-----------
Andrew Zhang: move android.jar to lib folder.
Modified Paths:
--------------
trunk/punit.android/.classpath
Added Paths:
-----------
trunk/punit.android/lib/android.jar
Removed Paths:
-------------
trunk/punit.android/android.jar
Modified: trunk/punit.android/.classpath
===================================================================
--- trunk/punit.android/.classpath 2007-12-25 14:02:40 UTC (rev 265)
+++ trunk/punit.android/.classpath 2007-12-25 15:15:16 UTC (rev 266)
@@ -3,6 +3,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/punit"/>
- <classpathentry kind="lib" path="android.jar"/>
+ <classpathentry kind="lib" path="lib/android.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Deleted: trunk/punit.android/android.jar
===================================================================
(Binary files differ)
Copied: trunk/punit.android/lib/android.jar (from rev 258, trunk/punit.android/android.jar)
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|