diff options
author | Bob Lee <crazybob@crazybob.org> | 2009-09-28 19:54:21 +0000 |
---|---|---|
committer | Bob Lee <crazybob@crazybob.org> | 2009-09-28 19:54:21 +0000 |
commit | 70a11775e3d9e102aaed58c6bd1f73782560246e (patch) | |
tree | b39642ad888598a3a8b1613a1e4b58dc0f07f3ae | |
parent | 38d5c62e329d696d118a06f47d64c4da79309543 (diff) | |
download | platform_external_jsr330-70a11775e3d9e102aaed58c6bd1f73782560246e.tar.gz platform_external_jsr330-70a11775e3d9e102aaed58c6bd1f73782560246e.tar.bz2 platform_external_jsr330-70a11775e3d9e102aaed58c6bd1f73782560246e.zip |
Added tests for the TCK itself.
git-svn-id: https://atinject.googlecode.com/svn/trunk@34 3bc8319c-20ab-11de-9edc-3f40a397ab60
-rw-r--r-- | tck/com/googlecode/atinject/Tck.java | 22 | ||||
-rw-r--r-- | tck/com/googlecode/atinject/meta/BrokenGetCar.java | 41 |
2 files changed, 53 insertions, 10 deletions
diff --git a/tck/com/googlecode/atinject/Tck.java b/tck/com/googlecode/atinject/Tck.java index 1bbb31e..6aa86ac 100644 --- a/tck/com/googlecode/atinject/Tck.java +++ b/tck/com/googlecode/atinject/Tck.java @@ -22,6 +22,7 @@ import com.googlecode.atinject.auto.Convertible; import junit.framework.Test; import junit.framework.TestResult; import junit.framework.TestSuite; +import junit.framework.TestCase; /** * Extend this class, implement {@link #getCar()}, and declare a static @@ -66,7 +67,7 @@ public abstract class Tck implements Test { if (!(car instanceof Convertible)) { delegate = new Failure( "getCar() did not return an instance of Convertible", - new ClassCastException("Expected: Convertible, got: " + new ClassCastException("Expected Convertible, got " + car.getClass().getName())); return; } @@ -107,23 +108,24 @@ public abstract class Tck implements Test { */ protected abstract Car getCar(); - static class Failure implements Test { - final String message; + static class Failure extends TestCase { + /* + * We have to extend TestCase instead of implementing Test so we + * can set the name. + */ + final Throwable t; - Failure(String message, Throwable t) { - this.message = message; + Failure(String name, Throwable t) { + setName(name); this.t = t; } - public int countTestCases() { + @Override public int countTestCases() { return 1; } - public void run(TestResult result) { + @Override public void run(TestResult result) { result.startTest(this); result.addError(this, t); result.endTest(this); } - @Override public String toString() { - return message; - } } } diff --git a/tck/com/googlecode/atinject/meta/BrokenGetCar.java b/tck/com/googlecode/atinject/meta/BrokenGetCar.java new file mode 100644 index 0000000..689bc95 --- /dev/null +++ b/tck/com/googlecode/atinject/meta/BrokenGetCar.java @@ -0,0 +1,41 @@ +package com.googlecode.atinject.meta; + +import com.googlecode.atinject.Tck; +import com.googlecode.atinject.Tester; +import com.googlecode.atinject.auto.Car; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class BrokenGetCar { + + static class ThrowsException extends Tck { + protected Car getCar() { + throw new UnsupportedOperationException(); + } + } + + static class ReturnsNull extends Tck { + protected Car getCar() { + return null; + } + } + + static class WrongType extends Tck { + protected Car getCar() { + return new Car() { + public void check(Tester tester) { + throw new UnsupportedOperationException(); + } + }; + } + } + + public static Test suite() { + TestSuite suite = new TestSuite(); + suite.addTest(new ThrowsException()); + suite.addTest(new ReturnsNull()); + suite.addTest(new WrongType()); + return suite; + } +} |