summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBob Lee <crazybob@crazybob.org>2009-09-29 08:31:12 +0000
committerBob Lee <crazybob@crazybob.org>2009-09-29 08:31:12 +0000
commit18603c8c4caca659d621efa161112cd2e1fb2b46 (patch)
treeaaf77104b254317480113af0e8c297be4cc83c38
parentb32f8b0274e4b073346a7462ed6afeea62f8d673 (diff)
downloadplatform_external_jsr330-18603c8c4caca659d621efa161112cd2e1fb2b46.tar.gz
platform_external_jsr330-18603c8c4caca659d621efa161112cd2e1fb2b46.tar.bz2
platform_external_jsr330-18603c8c4caca659d621efa161112cd2e1fb2b46.zip
Made static and private member injection optional.
git-svn-id: https://atinject.googlecode.com/svn/trunk@39 3bc8319c-20ab-11de-9edc-3f40a397ab60
-rw-r--r--atinject.ipr4
-rw-r--r--tck/org/atinject/tck/Tck.java25
-rw-r--r--tck/org/atinject/tck/auto/Convertible.java202
3 files changed, 124 insertions, 107 deletions
diff --git a/atinject.ipr b/atinject.ipr
index 21c3e15..5caf3de 100644
--- a/atinject.ipr
+++ b/atinject.ipr
@@ -223,7 +223,7 @@
</component>
<component name="ProjectFileVersion" converted="true" />
<component name="ProjectKey">
- <option name="state" value="project:///Users/crazybob/projects/atinject/atinject.ipr" />
+ <option name="state" value="https://atinject.googlecode.com/svn/trunk/atinject.ipr" />
</component>
<component name="ProjectModuleManager">
<modules>
@@ -253,7 +253,7 @@
<option name="mySupportsUserInfoFilter" value="true" />
</component>
<component name="VcsDirectoryMappings">
- <mapping directory="$PROJECT_DIR$/tck" vcs="svn" />
+ <mapping directory="" vcs="svn" />
</component>
<component name="libraryTable">
<library name="Guice">
diff --git a/tck/org/atinject/tck/Tck.java b/tck/org/atinject/tck/Tck.java
index 23cda5c..cead878 100644
--- a/tck/org/atinject/tck/Tck.java
+++ b/tck/org/atinject/tck/Tck.java
@@ -28,7 +28,7 @@ import junit.framework.TestSuite;
* <pre>
* public class MyTck {
* public static Test suite() {
- * return Tck.testsFor(new MyInjector().getInstance(Car.class));
+ * return Tck.testsFor(new MyInjector().getInstance(Car.class), true, true);
* }
* }
* </pre>
@@ -61,14 +61,20 @@ public class Tck {
* FuelTank}.
* </ul>
*
- * <p>The static members of the following types shall also be injected: {@link org.atinject.tck.auto.Convertible
+ * <p>If static injection is supported, 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}.
*
+ * @param car to test
+ * @param supportsStatic if the injector supports static member injection
+ * @param supportsPrivate if the injector supports private member injection
+ *
* @throws NullPointerException if car is null
* @throws ClassCastException if car doesn't extend Convertible
*/
- public static Test testsFor(Car car) {
+ public static Test testsFor(Car car, boolean supportsStatic,
+ boolean supportsPrivate) {
if (car == null) {
throw new NullPointerException("car");
}
@@ -77,11 +83,18 @@ public class Tck {
throw new ClassCastException("car doesn't implement Convertible");
}
- Convertible.Tests.localConvertible.set((Convertible) car);
+ Convertible.localConvertible.set((Convertible) car);
try {
- return new TestSuite(Convertible.Tests.class);
+ TestSuite suite = new TestSuite(Convertible.Tests.class);
+ if (supportsStatic) {
+ suite.addTestSuite(Convertible.StaticTests.class);
+ }
+ if (supportsPrivate) {
+ suite.addTestSuite(Convertible.PrivateTests.class);
+ }
+ return suite;
} finally {
- Convertible.Tests.localConvertible.remove();
+ Convertible.localConvertible.remove();
}
}
}
diff --git a/tck/org/atinject/tck/auto/Convertible.java b/tck/org/atinject/tck/auto/Convertible.java
index 50c6b3c..ebb784c 100644
--- a/tck/org/atinject/tck/auto/Convertible.java
+++ b/tck/org/atinject/tck/auto/Convertible.java
@@ -169,20 +169,16 @@ public class Convertible implements Car {
};
}
- /**
- * Tests against the Convertible instance.
- */
- public static class Tests extends TestCase {
+ public static ThreadLocal<Convertible> localConvertible
+ = new ThreadLocal<Convertible>();
- public static ThreadLocal<Convertible> localConvertible
- = new ThreadLocal<Convertible>();
+ public static class Tests extends TestCase {
private final Convertible car = localConvertible.get();
private final Cupholder cupholder = car.cupholder;
private final SpareTire spareTire = car.spareTire;
private final Engine engine = car.engineProvider.get();
-
// smoke tests: if these fail all bets are off
public void testFieldsInjected() {
@@ -193,7 +189,6 @@ public class Convertible implements Car {
assertTrue(engine != null);
}
-
// injecting different kinds of members
public void testMethodWithZeroParametersInjected() {
@@ -228,22 +223,6 @@ public class Convertible implements Car {
assertTrue(spareTire.hasTireBeenMethodInjected());
}
- public void testSubtypeStaticFieldsInjected() {
- assertTrue(SpareTire.hasBeenStaticFieldInjected());
- }
-
- public void testSubtypeStaticMethodsInjected() {
- assertTrue(SpareTire.hasBeenStaticMethodInjected());
- }
-
- public void testSupertypeStaticFieldsInjected() {
- assertTrue(Tire.hasBeenStaticFieldInjected());
- }
-
- public void testSupertypeStaticMethodsInjected() {
- assertTrue(Tire.hasBeenStaticMethodInjected());
- }
-
public void testTwiceOverriddenMethodInjectedWhenMiddleLacksAnnotation() {
assertTrue(engine.overriddenTwiceWithOmissionInMiddleInjected);
}
@@ -287,29 +266,6 @@ public class Convertible implements Car {
car.methodSpareTire instanceof SpareTire);
}
- public void testStaticFieldInjectionWithValues() {
- assertFalse("Expected unqualified value",
- staticFieldPlainSeat instanceof DriversSeat);
- assertFalse("Expected unqualified value",
- staticFieldPlainTire instanceof SpareTire);
- assertTrue("Expected qualified value",
- staticFieldDriversSeat instanceof DriversSeat);
- assertTrue("Expected qualified value",
- staticFieldSpareTire instanceof SpareTire);
- }
-
- public void testStaticMethodInjectionWithValues() {
- assertFalse("Expected unqualified value",
- staticMethodPlainSeat instanceof DriversSeat);
- assertFalse("Expected unqualified value",
- staticMethodPlainTire instanceof SpareTire);
- assertTrue("Expected qualified value",
- staticMethodDriversSeat instanceof DriversSeat);
- assertTrue("Expected qualified value",
- staticMethodSpareTire instanceof SpareTire);
- }
-
-
// injected providers
public void testConstructorInjectionWithProviders() {
@@ -345,28 +301,6 @@ public class Convertible implements Car {
car.methodSpareTireProvider.get() instanceof SpareTire);
}
- public void testStaticFieldInjectionWithProviders() {
- assertFalse("Expected unqualified value",
- staticFieldPlainSeatProvider.get() instanceof DriversSeat);
- assertFalse("Expected unqualified value",
- staticFieldPlainTireProvider.get() instanceof SpareTire);
- assertTrue("Expected qualified value",
- staticFieldDriversSeatProvider.get() instanceof DriversSeat);
- assertTrue("Expected qualified value",
- staticFieldSpareTireProvider.get() instanceof SpareTire);
- }
-
- public void testStaticMethodInjectionWithProviders() {
- assertFalse("Expected unqualified value",
- staticMethodPlainSeatProvider.get() instanceof DriversSeat);
- assertFalse("Expected unqualified value",
- staticMethodPlainTireProvider.get() instanceof SpareTire);
- assertTrue("Expected qualified value",
- staticMethodDriversSeatProvider.get() instanceof DriversSeat);
- assertTrue("Expected qualified value",
- staticMethodSpareTireProvider.get() instanceof SpareTire);
- }
-
// singletons
@@ -427,16 +361,6 @@ public class Convertible implements Car {
// mix inheritance + visibility
- public void testSupertypePrivateMethodInjected() {
- assertTrue(spareTire.superPrivateMethodInjected);
- assertTrue(spareTire.subPrivateMethodInjected);
- }
-
- public void testPackagePrivateMethodInjectedSamePackage() {
- assertTrue(engine.subPackagePrivateMethodInjected);
- assertFalse(engine.superPackagePrivateMethodInjected);
- }
-
public void testPackagePrivateMethodInjectedDifferentPackages() {
assertTrue(spareTire.subPackagePrivateMethodInjected);
assertTrue(spareTire.superPackagePrivateMethodInjected);
@@ -459,10 +383,6 @@ public class Convertible implements Car {
assertFalse(spareTire.methodInjectedBeforeFields);
}
- public void testStaticFieldsInjectedBeforeMethods() {
- assertFalse(SpareTire.staticMethodInjectedBeforeStaticFields);
- }
-
public void testSupertypeFieldsInjectedBeforeSubtypeMethods() {
assertFalse(spareTire.subtypeFieldInjectedBeforeSupertypeMethods);
}
@@ -471,21 +391,9 @@ public class Convertible implements Car {
assertFalse(spareTire.subtypeMethodInjectedBeforeSupertypeMethods);
}
- public void testSupertypeStaticMethodsInjectedBeforeSubtypeStaticFields() {
- assertFalse(SpareTire.subtypeStaticFieldInjectedBeforeSupertypeStaticMethods);
- }
-
- public void testSupertypeStaticMethodsInjectedBeforeSubtypeStaticMethods() {
- assertFalse(SpareTire.subtypeStaticMethodInjectedBeforeSupertypeStaticMethods);
- }
-
// necessary injections occur
- public void testPrivateMethodInjectedEvenWhenSimilarMethodLacksAnnotation() {
- assertTrue(spareTire.subPrivateMethodForOverrideInjected);
- }
-
public void testPackagePrivateMethodInjectedEvenWhenSimilarMethodLacksAnnotation() {
assertTrue(spareTire.subPackagePrivateMethodForOverrideInjected);
}
@@ -525,10 +433,6 @@ public class Convertible implements Car {
assertFalse(engine.overriddenPackagePrivateMethodInjectedTwice);
}
- public void testSimilarPrivateMethodInjectedOnlyOnce() {
- assertFalse(spareTire.similarPrivateMethodInjectedTwice);
- }
-
public void testSimilarPackagePrivateMethodInjectedOnlyOnce() {
assertFalse(spareTire.similarPackagePrivateMethodInjectedTwice);
}
@@ -542,4 +446,104 @@ public class Convertible implements Car {
}
}
+
+ public static class StaticTests extends TestCase {
+
+ public void testSubtypeStaticFieldsInjected() {
+ assertTrue(SpareTire.hasBeenStaticFieldInjected());
+ }
+
+ public void testSubtypeStaticMethodsInjected() {
+ assertTrue(SpareTire.hasBeenStaticMethodInjected());
+ }
+
+ public void testSupertypeStaticFieldsInjected() {
+ assertTrue(Tire.hasBeenStaticFieldInjected());
+ }
+
+ public void testSupertypeStaticMethodsInjected() {
+ assertTrue(Tire.hasBeenStaticMethodInjected());
+ }
+
+ public void testStaticFieldInjectionWithValues() {
+ assertFalse("Expected unqualified value",
+ staticFieldPlainSeat instanceof DriversSeat);
+ assertFalse("Expected unqualified value",
+ staticFieldPlainTire instanceof SpareTire);
+ assertTrue("Expected qualified value",
+ staticFieldDriversSeat instanceof DriversSeat);
+ assertTrue("Expected qualified value",
+ staticFieldSpareTire instanceof SpareTire);
+ }
+
+ public void testStaticMethodInjectionWithValues() {
+ assertFalse("Expected unqualified value",
+ staticMethodPlainSeat instanceof DriversSeat);
+ assertFalse("Expected unqualified value",
+ staticMethodPlainTire instanceof SpareTire);
+ assertTrue("Expected qualified value",
+ staticMethodDriversSeat instanceof DriversSeat);
+ assertTrue("Expected qualified value",
+ staticMethodSpareTire instanceof SpareTire);
+ }
+
+ public void testStaticFieldsInjectedBeforeMethods() {
+ assertFalse(SpareTire.staticMethodInjectedBeforeStaticFields);
+ }
+
+ public void testSupertypeStaticMethodsInjectedBeforeSubtypeStaticFields() {
+ assertFalse(SpareTire.subtypeStaticFieldInjectedBeforeSupertypeStaticMethods);
+ }
+
+ public void testSupertypeStaticMethodsInjectedBeforeSubtypeStaticMethods() {
+ assertFalse(SpareTire.subtypeStaticMethodInjectedBeforeSupertypeStaticMethods);
+ }
+
+ public void testStaticFieldInjectionWithProviders() {
+ assertFalse("Expected unqualified value",
+ staticFieldPlainSeatProvider.get() instanceof DriversSeat);
+ assertFalse("Expected unqualified value",
+ staticFieldPlainTireProvider.get() instanceof SpareTire);
+ assertTrue("Expected qualified value",
+ staticFieldDriversSeatProvider.get() instanceof DriversSeat);
+ assertTrue("Expected qualified value",
+ staticFieldSpareTireProvider.get() instanceof SpareTire);
+ }
+
+ public void testStaticMethodInjectionWithProviders() {
+ assertFalse("Expected unqualified value",
+ staticMethodPlainSeatProvider.get() instanceof DriversSeat);
+ assertFalse("Expected unqualified value",
+ staticMethodPlainTireProvider.get() instanceof SpareTire);
+ assertTrue("Expected qualified value",
+ staticMethodDriversSeatProvider.get() instanceof DriversSeat);
+ assertTrue("Expected qualified value",
+ staticMethodSpareTireProvider.get() instanceof SpareTire);
+ }
+ }
+
+ public static class PrivateTests extends TestCase {
+
+ private final Convertible car = localConvertible.get();
+ private final Engine engine = car.engineProvider.get();
+ private final SpareTire spareTire = car.spareTire;
+
+ public void testSupertypePrivateMethodInjected() {
+ assertTrue(spareTire.superPrivateMethodInjected);
+ assertTrue(spareTire.subPrivateMethodInjected);
+ }
+
+ public void testPackagePrivateMethodInjectedSamePackage() {
+ assertTrue(engine.subPackagePrivateMethodInjected);
+ assertFalse(engine.superPackagePrivateMethodInjected);
+ }
+
+ public void testPrivateMethodInjectedEvenWhenSimilarMethodLacksAnnotation() {
+ assertTrue(spareTire.subPrivateMethodForOverrideInjected);
+ }
+
+ public void testSimilarPrivateMethodInjectedOnlyOnce() {
+ assertFalse(spareTire.similarPrivateMethodInjectedTwice);
+ }
+ }
}