Simplified TCK setup.

git-svn-id: https://atinject.googlecode.com/svn/trunk@36 3bc8319c-20ab-11de-9edc-3f40a397ab60
diff --git a/tck/org/atinject/tck/CarWontStart.java b/tck/org/atinject/tck/CarWontStart.java
deleted file mode 100644
index 0f2eac8..0000000
--- a/tck/org/atinject/tck/CarWontStart.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.atinject.tck;
-
-import junit.framework.TestCase;
-import junit.framework.TestResult;
-
-/**
- * Used when we can't even get a Car to test against.
- */
-class CarWontStart extends TestCase {
-    /*
-     * We have to extend TestCase instead of implementing Test so we
-     * can set the name. JUnit sucks (or at least the tools do).
-     */
-
-    final Throwable t;
-
-    CarWontStart(String name, Throwable t) {
-        setName(name);
-        this.t = t;
-    }
-
-    @Override public int countTestCases() {
-        return 1;
-    }
-
-    @Override public void run(TestResult result) {
-        result.startTest(this);
-        result.addError(this, t);
-        result.endTest(this);
-    }
-}
diff --git a/tck/org/atinject/tck/Tck.java b/tck/org/atinject/tck/Tck.java
index 89dd13a..1642a7a 100644
--- a/tck/org/atinject/tck/Tck.java
+++ b/tck/org/atinject/tck/Tck.java
@@ -20,20 +20,15 @@
 import org.atinject.tck.auto.Convertible;
 
 import junit.framework.Test;
-import junit.framework.TestResult;
 import junit.framework.TestSuite;
 
 /**
- * Extend this class, implement {@link #getCar()}, and declare a static
- * {@code suite} method (a JUnit convention):
+ * Call {@link #testsFor} from a JUnit {@code suite} method:
  *
  * <pre>
- * public class MyTck extends Tck {
- *   protected Car getCar() {
- *      return new MyInjector().getInstance(Car.class);
- *   }
+ * public class MyTck {
  *   public static Test suite() {
- *     return new MyTck();
+ *     return Tck.testsFor(new MyInjector().getInstance(Car.class));
  *   }
  * }
  * </pre>
@@ -43,49 +38,16 @@
  * <pre>
  * java junit.textui.TestRunner MyTck
  * </pre>
+ *
+ * @deprecated
  */
-public abstract class Tck implements Test {
+public class Tck {
 
-    private final Test delegate;
-
-    protected Tck() {
-        Car car;
-        try {
-            car = getCar();
-        } catch (Throwable t) {
-            delegate = new CarWontStart("getCar() threw an exception", t);
-            return;
-        }
-
-        if (car == null) {
-            delegate = new CarWontStart("getCar() returned null",
-                    new NullPointerException("getCar() returned null"));
-            return;
-        }
-
-        if (!(car instanceof Convertible)) {
-            delegate = new CarWontStart(
-                    "getCar() did not return an instance of Convertible",
-                    new ClassCastException("Expected Convertible, got "
-                            + car.getClass().getName()));
-            return;
-        }
-
-        Convertible.Test.car = (Convertible) car;
-        delegate = new TestSuite(Convertible.Test.class);
-    }
-
-    public int countTestCases() {
-        return delegate.countTestCases();
-    }
-
-    public void run(TestResult result) {
-        delegate.run(result);
-    }
+    private Tck() {}
 
     /**
-     * Returns a {@link org.atinject.tck.auto.Car} constructed by an
-     * injector with the following configuration:
+     * Constructs a test suite for the given {@link Car} instance. Create the
+     * {@code Car} instance using an injector with the following configuration:
      *
      * <ul>
      *   <li>{@link org.atinject.tck.auto.Car} is implemented by
@@ -104,6 +66,23 @@
      * <p>The static members of the following types shall also be injected: {@link org.atinject.tck.auto.Convertible
      * Convertible}, {@link org.atinject.tck.auto.Tire Tire}, and {@link
      * org.atinject.tck.auto.accessories.SpareTire SpareTire}.
+     *
+     * <p><b>Note:</b> Due to limitations of JUnit, you must create and run
+     * only one test instance at a time.
+     *
+     * @throws NullPointerException if car is null
+     * @throws ClassCastException if car doesn't extend Convertible
      */
-    protected abstract Car getCar();
+    public static Test testsFor(Car car) {
+        if (car == null) {
+            throw new NullPointerException("car");
+        }
+
+        if (!(car instanceof Convertible)) {
+            throw new ClassCastException("car doesn't implement Convertible");
+        }
+
+        Convertible.Tests.car = (Convertible) car;
+        return new TestSuite(Convertible.Tests.class);
+    }
 }
diff --git a/tck/org/atinject/tck/auto/Convertible.java b/tck/org/atinject/tck/auto/Convertible.java
index aad4eb1..79f5777 100644
--- a/tck/org/atinject/tck/auto/Convertible.java
+++ b/tck/org/atinject/tck/auto/Convertible.java
@@ -263,10 +263,8 @@
 
     /**
      * Tests against the Convertible instance.
-     *
-     * @see #car
      */
-    public static class Test extends TestCase {
+    public static class Tests extends TestCase {
 
         /**
          * The instance to test. Making it static isn't ideal, but it saves
diff --git a/tck/org/atinject/tck/meta/BrokenGetCar.java b/tck/org/atinject/tck/meta/BrokenGetCar.java
deleted file mode 100644
index c6b2ce9..0000000
--- a/tck/org/atinject/tck/meta/BrokenGetCar.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package org.atinject.tck.meta;
-
-import org.atinject.tck.Tck;
-import org.atinject.tck.Tester;
-import org.atinject.tck.auto.Car;
-
-import junit.framework.Test;
-import junit.framework.TestResult;
-
-/**
- * We expect these tests to fail.
- */
-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() {
-        return new Test() {
-            public int countTestCases() {
-                return 3;
-            }
-            public void run(TestResult result) {
-                new ThrowsException().run(result);
-                new ReturnsNull().run(result);
-                new WrongType().run(result);
-            }
-        };
-    }
-}