diff options
Diffstat (limited to 'tck/org')
-rw-r--r-- | tck/org/atinject/tck/Tck.java | 128 | ||||
-rw-r--r-- | tck/org/atinject/tck/auto/Car.java | 21 | ||||
-rw-r--r-- | tck/org/atinject/tck/auto/Convertible.java | 573 | ||||
-rw-r--r-- | tck/org/atinject/tck/auto/Drivers.java | 25 | ||||
-rw-r--r-- | tck/org/atinject/tck/auto/DriversSeat.java | 29 | ||||
-rw-r--r-- | tck/org/atinject/tck/auto/Engine.java | 68 | ||||
-rw-r--r-- | tck/org/atinject/tck/auto/FuelTank.java | 21 | ||||
-rw-r--r-- | tck/org/atinject/tck/auto/GasEngine.java | 30 | ||||
-rw-r--r-- | tck/org/atinject/tck/auto/Seat.java | 37 | ||||
-rw-r--r-- | tck/org/atinject/tck/auto/Seatbelt.java | 20 | ||||
-rw-r--r-- | tck/org/atinject/tck/auto/Tire.java | 182 | ||||
-rw-r--r-- | tck/org/atinject/tck/auto/V8Engine.java | 61 | ||||
-rw-r--r-- | tck/org/atinject/tck/auto/accessories/Cupholder.java | 34 | ||||
-rw-r--r-- | tck/org/atinject/tck/auto/accessories/RoundThing.java | 40 | ||||
-rw-r--r-- | tck/org/atinject/tck/auto/accessories/SpareTire.java | 122 | ||||
-rw-r--r-- | tck/org/atinject/tck/package-info.java | 8 |
16 files changed, 1399 insertions, 0 deletions
diff --git a/tck/org/atinject/tck/Tck.java b/tck/org/atinject/tck/Tck.java new file mode 100644 index 0000000..76b5465 --- /dev/null +++ b/tck/org/atinject/tck/Tck.java @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2009 The JSR-330 Expert Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.atinject.tck; + +import org.atinject.tck.auto.Car; +import org.atinject.tck.auto.Convertible; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Manufactures the compatibility test suite. This TCK relies on + * <a href="http://junit.org/">JUnit</a>. To integrate the TCK with your + * injector, create a JUnit test suite class that passes an injected + * {@link Car Car} instance to {@link #testsFor testsFor(Car)}: + * + * <pre> + * import junit.framework.Test; + * import org.atinject.tck.Tck; + * import org.atinject.tck.auto.Car; + * + * public class MyTck { + * public static Test suite() { + * Car car = new MyInjector().getInstance(Car.class); + * return Tck.testsFor(car, + * true /* supportsStatic */, + * true /* supportsPrivate */); + * } + * }</pre> + * + * <p>The static {@code suite} method that returns a {@code Test} is a JUnit + * convention. Feel free to run the returned tests in other ways. + * + * <p>Configure the injector as follows: + * + * <ul> + * <li>{@link org.atinject.tck.auto.Car} is implemented by + * {@link org.atinject.tck.auto.Convertible Convertible}. + * <li>{@link org.atinject.tck.auto.Drivers @Drivers} + * {@link org.atinject.tck.auto.Seat Seat} is + * implemented by {@link org.atinject.tck.auto.DriversSeat DriversSeat}. + * <li>{@link org.atinject.tck.auto.Seat Seat} is + * implemented by {@link org.atinject.tck.auto.Seat Seat} itself, and + * {@link org.atinject.tck.auto.Tire Tire} by + * {@link org.atinject.tck.auto.Tire Tire} itself + * (not subclasses). + * <li>{@link org.atinject.tck.auto.Engine Engine} is implemented by + * {@link org.atinject.tck.auto.V8Engine V8Engine}. + * <li>{@link javax.inject.Named @Named("spare")} + * {@link org.atinject.tck.auto.Tire Tire} is implemented by + * {@link org.atinject.tck.auto.accessories.SpareTire SpareTire}. + * <li>The following classes may also be injected directly: + * {@link org.atinject.tck.auto.accessories.Cupholder Cupholder}, + * {@link org.atinject.tck.auto.accessories.SpareTire SpareTire}, and + * {@link org.atinject.tck.auto.FuelTank FuelTank}. + * </ul> + * + * <p>Static and private member injection support is optional, but if your + * injector supports those features, it must pass the respective tests. If + * static member injection is supported, the static members of the following + * types shall also be injected once: + * {@link org.atinject.tck.auto.Convertible Convertible}, + * {@link org.atinject.tck.auto.Tire Tire}, and + * {@link org.atinject.tck.auto.accessories.SpareTire SpareTire}. + * + * <p>Use your favorite JUnit tool to run the tests. For example, you can use + * your IDE or JUnit's command line runner: + * + * <pre> + * java -cp javax.inject-tck.jar:junit.jar:myinjector.jar \ + * junit.textui.TestRunner MyTck</pre> + */ +public class Tck { + + private Tck() {} + + /** + * Constructs a JUnit test suite for the given {@link Car} instance. + * + * @param car to test + * @param supportsStatic true if the injector supports static member + * injection + * @param supportsPrivate true if the injector supports private member + * injection + * + * @throws NullPointerException if car is null + * @throws ClassCastException if car doesn't extend + * {@link Convertible Convertible} + */ + public static Test testsFor(Car car, boolean supportsStatic, + boolean supportsPrivate) { + if (car == null) { + throw new NullPointerException("car"); + } + + if (!(car instanceof Convertible)) { + throw new ClassCastException("car doesn't implement Convertible"); + } + + Convertible.localConvertible.set((Convertible) car); + try { + 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.localConvertible.remove(); + } + } +} diff --git a/tck/org/atinject/tck/auto/Car.java b/tck/org/atinject/tck/auto/Car.java new file mode 100644 index 0000000..d312ee5 --- /dev/null +++ b/tck/org/atinject/tck/auto/Car.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2009 The JSR-330 Expert Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.atinject.tck.auto; + +public interface Car { + +} diff --git a/tck/org/atinject/tck/auto/Convertible.java b/tck/org/atinject/tck/auto/Convertible.java new file mode 100644 index 0000000..b5b7c48 --- /dev/null +++ b/tck/org/atinject/tck/auto/Convertible.java @@ -0,0 +1,573 @@ +/* + * Copyright (C) 2009 The JSR-330 Expert Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.atinject.tck.auto; + +import junit.framework.TestCase; +import org.atinject.tck.auto.accessories.Cupholder; +import org.atinject.tck.auto.accessories.SpareTire; +import org.atinject.tck.auto.accessories.RoundThing; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Provider; + +public class Convertible implements Car { + + @Inject @Drivers Seat driversSeatA; + @Inject @Drivers Seat driversSeatB; + @Inject SpareTire spareTire; + @Inject Cupholder cupholder; + @Inject Provider<Engine> engineProvider; + + private boolean methodWithZeroParamsInjected; + private boolean methodWithMultipleParamsInjected; + private boolean methodWithNonVoidReturnInjected; + + private Seat constructorPlainSeat; + private Seat constructorDriversSeat; + private Tire constructorPlainTire; + private Tire constructorSpareTire; + private Provider<Seat> constructorPlainSeatProvider = nullProvider(); + private Provider<Seat> constructorDriversSeatProvider = nullProvider(); + private Provider<Tire> constructorPlainTireProvider = nullProvider(); + private Provider<Tire> constructorSpareTireProvider = nullProvider(); + + @Inject Seat fieldPlainSeat; + @Inject @Drivers Seat fieldDriversSeat; + @Inject Tire fieldPlainTire; + @Inject @Named("spare") Tire fieldSpareTire; + @Inject Provider<Seat> fieldPlainSeatProvider = nullProvider(); + @Inject @Drivers Provider<Seat> fieldDriversSeatProvider = nullProvider(); + @Inject Provider<Tire> fieldPlainTireProvider = nullProvider(); + @Inject @Named("spare") Provider<Tire> fieldSpareTireProvider = nullProvider(); + + private Seat methodPlainSeat; + private Seat methodDriversSeat; + private Tire methodPlainTire; + private Tire methodSpareTire; + private Provider<Seat> methodPlainSeatProvider = nullProvider(); + private Provider<Seat> methodDriversSeatProvider = nullProvider(); + private Provider<Tire> methodPlainTireProvider = nullProvider(); + private Provider<Tire> methodSpareTireProvider = nullProvider(); + + @Inject static Seat staticFieldPlainSeat; + @Inject @Drivers static Seat staticFieldDriversSeat; + @Inject static Tire staticFieldPlainTire; + @Inject @Named("spare") static Tire staticFieldSpareTire; + @Inject static Provider<Seat> staticFieldPlainSeatProvider = nullProvider(); + @Inject @Drivers static Provider<Seat> staticFieldDriversSeatProvider = nullProvider(); + @Inject static Provider<Tire> staticFieldPlainTireProvider = nullProvider(); + @Inject @Named("spare") static Provider<Tire> staticFieldSpareTireProvider = nullProvider(); + + private static Seat staticMethodPlainSeat; + private static Seat staticMethodDriversSeat; + private static Tire staticMethodPlainTire; + private static Tire staticMethodSpareTire; + private static Provider<Seat> staticMethodPlainSeatProvider = nullProvider(); + private static Provider<Seat> staticMethodDriversSeatProvider = nullProvider(); + private static Provider<Tire> staticMethodPlainTireProvider = nullProvider(); + private static Provider<Tire> staticMethodSpareTireProvider = nullProvider(); + + @Inject Convertible( + Seat plainSeat, + @Drivers Seat driversSeat, + Tire plainTire, + @Named("spare") Tire spareTire, + Provider<Seat> plainSeatProvider, + @Drivers Provider<Seat> driversSeatProvider, + Provider<Tire> plainTireProvider, + @Named("spare") Provider<Tire> spareTireProvider) { + constructorPlainSeat = plainSeat; + constructorDriversSeat = driversSeat; + constructorPlainTire = plainTire; + constructorSpareTire = spareTire; + constructorPlainSeatProvider = plainSeatProvider; + constructorDriversSeatProvider = driversSeatProvider; + constructorPlainTireProvider = plainTireProvider; + constructorSpareTireProvider = spareTireProvider; + } + + Convertible() { + throw new AssertionError("Unexpected call to non-injectable constructor"); + } + + void setSeat(Seat unused) { + throw new AssertionError("Unexpected call to non-injectable method"); + } + + @Inject void injectMethodWithZeroArgs() { + methodWithZeroParamsInjected = true; + } + + @Inject String injectMethodWithNonVoidReturn() { + methodWithNonVoidReturnInjected = true; + return "unused"; + } + + @Inject void injectInstanceMethodWithManyArgs( + Seat plainSeat, + @Drivers Seat driversSeat, + Tire plainTire, + @Named("spare") Tire spareTire, + Provider<Seat> plainSeatProvider, + @Drivers Provider<Seat> driversSeatProvider, + Provider<Tire> plainTireProvider, + @Named("spare") Provider<Tire> spareTireProvider) { + methodWithMultipleParamsInjected = true; + + methodPlainSeat = plainSeat; + methodDriversSeat = driversSeat; + methodPlainTire = plainTire; + methodSpareTire = spareTire; + methodPlainSeatProvider = plainSeatProvider; + methodDriversSeatProvider = driversSeatProvider; + methodPlainTireProvider = plainTireProvider; + methodSpareTireProvider = spareTireProvider; + } + + @Inject static void injectStaticMethodWithManyArgs( + Seat plainSeat, + @Drivers Seat driversSeat, + Tire plainTire, + @Named("spare") Tire spareTire, + Provider<Seat> plainSeatProvider, + @Drivers Provider<Seat> driversSeatProvider, + Provider<Tire> plainTireProvider, + @Named("spare") Provider<Tire> spareTireProvider) { + staticMethodPlainSeat = plainSeat; + staticMethodDriversSeat = driversSeat; + staticMethodPlainTire = plainTire; + staticMethodSpareTire = spareTire; + staticMethodPlainSeatProvider = plainSeatProvider; + staticMethodDriversSeatProvider = driversSeatProvider; + staticMethodPlainTireProvider = plainTireProvider; + staticMethodSpareTireProvider = spareTireProvider; + } + + /** + * Returns a provider that always returns null. This is used as a default + * value to avoid null checks for omitted provider injections. + */ + private static <T> Provider<T> nullProvider() { + return new Provider<T>() { + public T get() { + return null; + } + }; + } + + 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 Tire plainTire = car.fieldPlainTire; + private final Engine engine = car.engineProvider.get(); + + // smoke tests: if these fail all bets are off + + public void testFieldsInjected() { + assertTrue(cupholder != null && spareTire != null); + } + + public void testProviderReturnedValues() { + assertTrue(engine != null); + } + + // injecting different kinds of members + + public void testMethodWithZeroParametersInjected() { + assertTrue(car.methodWithZeroParamsInjected); + } + + public void testMethodWithMultipleParametersInjected() { + assertTrue(car.methodWithMultipleParamsInjected); + } + + public void testNonVoidMethodInjected() { + assertTrue(car.methodWithNonVoidReturnInjected); + } + + public void testPublicNoArgsConstructorInjected() { + assertTrue(engine.publicNoArgsConstructorInjected); + } + + public void testSubtypeFieldsInjected() { + assertTrue(spareTire.hasSpareTireBeenFieldInjected()); + } + + public void testSubtypeMethodsInjected() { + assertTrue(spareTire.hasSpareTireBeenMethodInjected()); + } + + public void testSupertypeFieldsInjected() { + assertTrue(spareTire.hasTireBeenFieldInjected()); + } + + public void testSupertypeMethodsInjected() { + assertTrue(spareTire.hasTireBeenMethodInjected()); + } + + public void testTwiceOverriddenMethodInjectedWhenMiddleLacksAnnotation() { + assertTrue(engine.overriddenTwiceWithOmissionInMiddleInjected); + } + + // injected values + + public void testQualifiersNotInheritedFromOverriddenMethod() { + assertFalse(engine.qualifiersInheritedFromOverriddenMethod); + } + + public void testConstructorInjectionWithValues() { + assertFalse("Expected unqualified value", + car.constructorPlainSeat instanceof DriversSeat); + assertFalse("Expected unqualified value", + car.constructorPlainTire instanceof SpareTire); + assertTrue("Expected qualified value", + car.constructorDriversSeat instanceof DriversSeat); + assertTrue("Expected qualified value", + car.constructorSpareTire instanceof SpareTire); + } + + public void testFieldInjectionWithValues() { + assertFalse("Expected unqualified value", + car.fieldPlainSeat instanceof DriversSeat); + assertFalse("Expected unqualified value", + car.fieldPlainTire instanceof SpareTire); + assertTrue("Expected qualified value", + car.fieldDriversSeat instanceof DriversSeat); + assertTrue("Expected qualified value", + car.fieldSpareTire instanceof SpareTire); + } + + public void testMethodInjectionWithValues() { + assertFalse("Expected unqualified value", + car.methodPlainSeat instanceof DriversSeat); + assertFalse("Expected unqualified value", + car.methodPlainTire instanceof SpareTire); + assertTrue("Expected qualified value", + car.methodDriversSeat instanceof DriversSeat); + assertTrue("Expected qualified value", + car.methodSpareTire instanceof SpareTire); + } + + // injected providers + + public void testConstructorInjectionWithProviders() { + assertFalse("Expected unqualified value", + car.constructorPlainSeatProvider.get() instanceof DriversSeat); + assertFalse("Expected unqualified value", + car.constructorPlainTireProvider.get() instanceof SpareTire); + assertTrue("Expected qualified value", + car.constructorDriversSeatProvider.get() instanceof DriversSeat); + assertTrue("Expected qualified value", + car.constructorSpareTireProvider.get() instanceof SpareTire); + } + + public void testFieldInjectionWithProviders() { + assertFalse("Expected unqualified value", + car.fieldPlainSeatProvider.get() instanceof DriversSeat); + assertFalse("Expected unqualified value", + car.fieldPlainTireProvider.get() instanceof SpareTire); + assertTrue("Expected qualified value", + car.fieldDriversSeatProvider.get() instanceof DriversSeat); + assertTrue("Expected qualified value", + car.fieldSpareTireProvider.get() instanceof SpareTire); + } + + public void testMethodInjectionWithProviders() { + assertFalse("Expected unqualified value", + car.methodPlainSeatProvider.get() instanceof DriversSeat); + assertFalse("Expected unqualified value", + car.methodPlainTireProvider.get() instanceof SpareTire); + assertTrue("Expected qualified value", + car.methodDriversSeatProvider.get() instanceof DriversSeat); + assertTrue("Expected qualified value", + car.methodSpareTireProvider.get() instanceof SpareTire); + } + + + // singletons + + public void testConstructorInjectedProviderYieldsSingleton() { + assertSame("Expected same value", + car.constructorPlainSeatProvider.get(), car.constructorPlainSeatProvider.get()); + } + + public void testFieldInjectedProviderYieldsSingleton() { + assertSame("Expected same value", + car.fieldPlainSeatProvider.get(), car.fieldPlainSeatProvider.get()); + } + + public void testMethodInjectedProviderYieldsSingleton() { + assertSame("Expected same value", + car.methodPlainSeatProvider.get(), car.methodPlainSeatProvider.get()); + } + + public void testCircularlyDependentSingletons() { + // uses provider.get() to get around circular deps + assertSame(cupholder.seatProvider.get().getCupholder(), cupholder); + } + + + // non singletons + + public void testSingletonAnnotationNotInheritedFromSupertype() { + assertNotSame(car.driversSeatA, car.driversSeatB); + } + + public void testConstructorInjectedProviderYieldsDistinctValues() { + assertNotSame("Expected distinct values", + car.constructorDriversSeatProvider.get(), car.constructorDriversSeatProvider.get()); + assertNotSame("Expected distinct values", + car.constructorPlainTireProvider.get(), car.constructorPlainTireProvider.get()); + assertNotSame("Expected distinct values", + car.constructorSpareTireProvider.get(), car.constructorSpareTireProvider.get()); + } + + public void testFieldInjectedProviderYieldsDistinctValues() { + assertNotSame("Expected distinct values", + car.fieldDriversSeatProvider.get(), car.fieldDriversSeatProvider.get()); + assertNotSame("Expected distinct values", + car.fieldPlainTireProvider.get(), car.fieldPlainTireProvider.get()); + assertNotSame("Expected distinct values", + car.fieldSpareTireProvider.get(), car.fieldSpareTireProvider.get()); + } + + public void testMethodInjectedProviderYieldsDistinctValues() { + assertNotSame("Expected distinct values", + car.methodDriversSeatProvider.get(), car.methodDriversSeatProvider.get()); + assertNotSame("Expected distinct values", + car.methodPlainTireProvider.get(), car.methodPlainTireProvider.get()); + assertNotSame("Expected distinct values", + car.methodSpareTireProvider.get(), car.methodSpareTireProvider.get()); + } + + + // mix inheritance + visibility + + public void testPackagePrivateMethodInjectedDifferentPackages() { + assertTrue(spareTire.subPackagePrivateMethodInjected); + assertTrue(spareTire.superPackagePrivateMethodInjected); + } + + public void testOverriddenProtectedMethodInjection() { + assertTrue(spareTire.subProtectedMethodInjected); + assertFalse(spareTire.superProtectedMethodInjected); + } + + public void testOverriddenPublicMethodNotInjected() { + assertTrue(spareTire.subPublicMethodInjected); + assertFalse(spareTire.superPublicMethodInjected); + } + + + // inject in order + + public void testFieldsInjectedBeforeMethods() { + assertFalse(spareTire.methodInjectedBeforeFields); + } + + public void testSupertypeMethodsInjectedBeforeSubtypeFields() { + assertFalse(spareTire.subtypeFieldInjectedBeforeSupertypeMethods); + } + + public void testSupertypeMethodInjectedBeforeSubtypeMethods() { + assertFalse(spareTire.subtypeMethodInjectedBeforeSupertypeMethods); + } + + + // necessary injections occur + + public void testPackagePrivateMethodInjectedEvenWhenSimilarMethodLacksAnnotation() { + assertTrue(spareTire.subPackagePrivateMethodForOverrideInjected); + } + + + // override or similar method without @Inject + + public void testPrivateMethodNotInjectedWhenSupertypeHasAnnotatedSimilarMethod() { + assertFalse(spareTire.superPrivateMethodForOverrideInjected); + } + + public void testPackagePrivateMethodNotInjectedWhenOverrideLacksAnnotation() { + assertFalse(engine.subPackagePrivateMethodForOverrideInjected); + assertFalse(engine.superPackagePrivateMethodForOverrideInjected); + } + + public void testPackagePrivateMethodNotInjectedWhenSupertypeHasAnnotatedSimilarMethod() { + assertFalse(spareTire.superPackagePrivateMethodForOverrideInjected); + } + + public void testProtectedMethodNotInjectedWhenOverrideNotAnnotated() { + assertFalse(spareTire.protectedMethodForOverrideInjected); + } + + public void testPublicMethodNotInjectedWhenOverrideNotAnnotated() { + assertFalse(spareTire.publicMethodForOverrideInjected); + } + + public void testTwiceOverriddenMethodNotInjectedWhenOverrideLacksAnnotation() { + assertFalse(engine.overriddenTwiceWithOmissionInSubclassInjected); + } + + public void testOverriddingMixedWithPackagePrivate2() { + assertTrue(spareTire.packagePrivateMethod2Injected); + assertTrue(((Tire) spareTire).packagePrivateMethod2Injected); + assertFalse(((RoundThing) spareTire).packagePrivateMethod2Injected); + + assertTrue(plainTire.packagePrivateMethod2Injected); + assertTrue(((RoundThing) plainTire).packagePrivateMethod2Injected); + } + + public void testOverriddingMixedWithPackagePrivate3() { + assertFalse(spareTire.packagePrivateMethod3Injected); + assertTrue(((Tire) spareTire).packagePrivateMethod3Injected); + assertFalse(((RoundThing) spareTire).packagePrivateMethod3Injected); + + assertTrue(plainTire.packagePrivateMethod3Injected); + assertTrue(((RoundThing) plainTire).packagePrivateMethod3Injected); + } + + public void testOverriddingMixedWithPackagePrivate4() { + assertFalse(plainTire.packagePrivateMethod4Injected); + assertTrue(((RoundThing) plainTire).packagePrivateMethod4Injected); + } + + // inject only once + + public void testOverriddenPackagePrivateMethodInjectedOnlyOnce() { + assertFalse(engine.overriddenPackagePrivateMethodInjectedTwice); + } + + public void testSimilarPackagePrivateMethodInjectedOnlyOnce() { + assertFalse(spareTire.similarPackagePrivateMethodInjectedTwice); + } + + public void testOverriddenProtectedMethodInjectedOnlyOnce() { + assertFalse(spareTire.overriddenProtectedMethodInjectedTwice); + } + + public void testOverriddenPublicMethodInjectedOnlyOnce() { + assertFalse(spareTire.overriddenPublicMethodInjectedTwice); + } + + } + + 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); + } + } +} diff --git a/tck/org/atinject/tck/auto/Drivers.java b/tck/org/atinject/tck/auto/Drivers.java new file mode 100644 index 0000000..53a2dc0 --- /dev/null +++ b/tck/org/atinject/tck/auto/Drivers.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2009 The JSR-330 Expert Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.atinject.tck.auto; + +import javax.inject.Qualifier; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) @Qualifier +public @interface Drivers { +} diff --git a/tck/org/atinject/tck/auto/DriversSeat.java b/tck/org/atinject/tck/auto/DriversSeat.java new file mode 100644 index 0000000..3ba90d9 --- /dev/null +++ b/tck/org/atinject/tck/auto/DriversSeat.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2009 The JSR-330 Expert Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.atinject.tck.auto; + +import org.atinject.tck.auto.accessories.Cupholder; + +import javax.inject.Inject; + +public class DriversSeat extends Seat { + + @Inject + public DriversSeat(Cupholder cupholder) { + super(cupholder); + } +} diff --git a/tck/org/atinject/tck/auto/Engine.java b/tck/org/atinject/tck/auto/Engine.java new file mode 100644 index 0000000..e4231e5 --- /dev/null +++ b/tck/org/atinject/tck/auto/Engine.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2009 The JSR-330 Expert Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.atinject.tck.auto; + +import org.atinject.tck.auto.accessories.SpareTire; + +import javax.inject.Inject; +import javax.inject.Named; + +public abstract class Engine { + + protected boolean publicNoArgsConstructorInjected; + protected boolean subPackagePrivateMethodInjected; + protected boolean superPackagePrivateMethodInjected; + protected boolean subPackagePrivateMethodForOverrideInjected; + protected boolean superPackagePrivateMethodForOverrideInjected; + + protected boolean overriddenTwiceWithOmissionInMiddleInjected; + protected boolean overriddenTwiceWithOmissionInSubclassInjected; + + protected Seat seatA; + protected Seat seatB; + protected Tire tireA; + protected Tire tireB; + + public boolean overriddenPackagePrivateMethodInjectedTwice; + public boolean qualifiersInheritedFromOverriddenMethod; + + @Inject void injectPackagePrivateMethod() { + superPackagePrivateMethodInjected = true; + } + + @Inject void injectPackagePrivateMethodForOverride() { + superPackagePrivateMethodForOverrideInjected = true; + } + + @Inject public void injectQualifiers(@Drivers Seat seatA, Seat seatB, + @Named("spare") Tire tireA, Tire tireB) { + if (!(seatA instanceof DriversSeat) + || (seatB instanceof DriversSeat) + || !(tireA instanceof SpareTire) + || (tireB instanceof SpareTire)) { + qualifiersInheritedFromOverriddenMethod = true; + } + } + + @Inject public void injectTwiceOverriddenWithOmissionInMiddle() { + overriddenTwiceWithOmissionInMiddleInjected = true; + } + + @Inject public void injectTwiceOverriddenWithOmissionInSubclass() { + overriddenTwiceWithOmissionInSubclassInjected = true; + } +} diff --git a/tck/org/atinject/tck/auto/FuelTank.java b/tck/org/atinject/tck/auto/FuelTank.java new file mode 100644 index 0000000..37d5199 --- /dev/null +++ b/tck/org/atinject/tck/auto/FuelTank.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2009 The JSR-330 Expert Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.atinject.tck.auto; + +public class FuelTank { + +} diff --git a/tck/org/atinject/tck/auto/GasEngine.java b/tck/org/atinject/tck/auto/GasEngine.java new file mode 100644 index 0000000..6f7edf1 --- /dev/null +++ b/tck/org/atinject/tck/auto/GasEngine.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2009 The JSR-330 Expert Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.atinject.tck.auto; + +import javax.inject.Inject; + +public abstract class GasEngine extends Engine { + + public void injectTwiceOverriddenWithOmissionInMiddle() { + overriddenTwiceWithOmissionInMiddleInjected = true; + } + + @Inject public void injectTwiceOverriddenWithOmissionInSubclass() { + overriddenTwiceWithOmissionInSubclassInjected = true; + } +} diff --git a/tck/org/atinject/tck/auto/Seat.java b/tck/org/atinject/tck/auto/Seat.java new file mode 100644 index 0000000..4d41a20 --- /dev/null +++ b/tck/org/atinject/tck/auto/Seat.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2009 The JSR-330 Expert Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.atinject.tck.auto; + +import org.atinject.tck.auto.accessories.Cupholder; + +import javax.inject.Inject; +import javax.inject.Singleton; + +@Singleton +public class Seat { + + private final Cupholder cupholder; + + @Inject + Seat(Cupholder cupholder) { + this.cupholder = cupholder; + } + + public Cupholder getCupholder() { + return cupholder; + } +} diff --git a/tck/org/atinject/tck/auto/Seatbelt.java b/tck/org/atinject/tck/auto/Seatbelt.java new file mode 100644 index 0000000..c6329dd --- /dev/null +++ b/tck/org/atinject/tck/auto/Seatbelt.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2009 The JSR-330 Expert Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.atinject.tck.auto; + +public class Seatbelt { +} diff --git a/tck/org/atinject/tck/auto/Tire.java b/tck/org/atinject/tck/auto/Tire.java new file mode 100644 index 0000000..1a8423f --- /dev/null +++ b/tck/org/atinject/tck/auto/Tire.java @@ -0,0 +1,182 @@ +/* + * Copyright (C) 2009 The JSR-330 Expert Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.atinject.tck.auto; + +import org.atinject.tck.auto.accessories.SpareTire; +import org.atinject.tck.auto.accessories.RoundThing; + +import javax.inject.Inject; +import java.util.LinkedHashSet; +import java.util.Set; + +public class Tire extends RoundThing { + + protected static final FuelTank NEVER_INJECTED = new FuelTank(); + + protected static final Set<String> moreProblems = new LinkedHashSet<String>(); + + FuelTank constructorInjection = NEVER_INJECTED; + @Inject FuelTank fieldInjection = NEVER_INJECTED; + FuelTank methodInjection = NEVER_INJECTED; + @Inject static FuelTank staticFieldInjection = NEVER_INJECTED; + static FuelTank staticMethodInjection = NEVER_INJECTED; + + boolean constructorInjected; + + protected boolean superPrivateMethodInjected; + protected boolean superPackagePrivateMethodInjected; + protected boolean superProtectedMethodInjected; + protected boolean superPublicMethodInjected; + protected boolean subPrivateMethodInjected; + protected boolean subPackagePrivateMethodInjected; + protected boolean subProtectedMethodInjected; + protected boolean subPublicMethodInjected; + + protected boolean superPrivateMethodForOverrideInjected; + protected boolean superPackagePrivateMethodForOverrideInjected; + protected boolean subPrivateMethodForOverrideInjected; + protected boolean subPackagePrivateMethodForOverrideInjected; + protected boolean protectedMethodForOverrideInjected; + protected boolean publicMethodForOverrideInjected; + + public boolean methodInjectedBeforeFields; + public boolean subtypeFieldInjectedBeforeSupertypeMethods; + public boolean subtypeMethodInjectedBeforeSupertypeMethods; + public static boolean staticMethodInjectedBeforeStaticFields; + public static boolean subtypeStaticFieldInjectedBeforeSupertypeStaticMethods; + public static boolean subtypeStaticMethodInjectedBeforeSupertypeStaticMethods; + public boolean similarPrivateMethodInjectedTwice; + public boolean similarPackagePrivateMethodInjectedTwice; + public boolean overriddenProtectedMethodInjectedTwice; + public boolean overriddenPublicMethodInjectedTwice; + + @Inject public Tire(FuelTank constructorInjection) { + this.constructorInjection = constructorInjection; + } + + @Inject void supertypeMethodInjection(FuelTank methodInjection) { + if (!hasTireBeenFieldInjected()) { + methodInjectedBeforeFields = true; + } + if (hasSpareTireBeenFieldInjected()) { + subtypeFieldInjectedBeforeSupertypeMethods = true; + } + if (hasSpareTireBeenMethodInjected()) { + subtypeMethodInjectedBeforeSupertypeMethods = true; + } + this.methodInjection = methodInjection; + } + + @Inject static void supertypeStaticMethodInjection(FuelTank methodInjection) { + if (!Tire.hasBeenStaticFieldInjected()) { + staticMethodInjectedBeforeStaticFields = true; + } + if (SpareTire.hasBeenStaticFieldInjected()) { + subtypeStaticFieldInjectedBeforeSupertypeStaticMethods = true; + } + if (SpareTire.hasBeenStaticMethodInjected()) { + subtypeStaticMethodInjectedBeforeSupertypeStaticMethods = true; + } + staticMethodInjection = methodInjection; + } + + @Inject private void injectPrivateMethod() { + if (superPrivateMethodInjected) { + similarPrivateMethodInjectedTwice = true; + } + superPrivateMethodInjected = true; + } + + @Inject void injectPackagePrivateMethod() { + if (superPackagePrivateMethodInjected) { + similarPackagePrivateMethodInjectedTwice = true; + } + superPackagePrivateMethodInjected = true; + } + + @Inject protected void injectProtectedMethod() { + if (superProtectedMethodInjected) { + overriddenProtectedMethodInjectedTwice = true; + } + superProtectedMethodInjected = true; + } + + @Inject public void injectPublicMethod() { + if (superPublicMethodInjected) { + overriddenPublicMethodInjectedTwice = true; + } + superPublicMethodInjected = true; + } + + @Inject private void injectPrivateMethodForOverride() { + subPrivateMethodForOverrideInjected = true; + } + + @Inject void injectPackagePrivateMethodForOverride() { + subPackagePrivateMethodForOverrideInjected = true; + } + + @Inject protected void injectProtectedMethodForOverride() { + protectedMethodForOverrideInjected = true; + } + + @Inject public void injectPublicMethodForOverride() { + publicMethodForOverrideInjected = true; + } + + protected final boolean hasTireBeenFieldInjected() { + return fieldInjection != NEVER_INJECTED; + } + + protected boolean hasSpareTireBeenFieldInjected() { + return false; + } + + protected final boolean hasTireBeenMethodInjected() { + return methodInjection != NEVER_INJECTED; + } + + protected static boolean hasBeenStaticFieldInjected() { + return staticFieldInjection != NEVER_INJECTED; + } + + protected static boolean hasBeenStaticMethodInjected() { + return staticMethodInjection != NEVER_INJECTED; + } + + protected boolean hasSpareTireBeenMethodInjected() { + return false; + } + + boolean packagePrivateMethod2Injected; + + @Inject void injectPackagePrivateMethod2() { + packagePrivateMethod2Injected = true; + } + + public boolean packagePrivateMethod3Injected; + + @Inject void injectPackagePrivateMethod3() { + packagePrivateMethod3Injected = true; + } + + public boolean packagePrivateMethod4Injected; + + void injectPackagePrivateMethod4() { + packagePrivateMethod4Injected = true; + } +} diff --git a/tck/org/atinject/tck/auto/V8Engine.java b/tck/org/atinject/tck/auto/V8Engine.java new file mode 100644 index 0000000..2dc7473 --- /dev/null +++ b/tck/org/atinject/tck/auto/V8Engine.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2009 The JSR-330 Expert Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.atinject.tck.auto; + +import org.atinject.tck.auto.accessories.SpareTire; + +import javax.inject.Inject; +import javax.inject.Named; + +public class V8Engine extends GasEngine { + + public V8Engine() { + publicNoArgsConstructorInjected = true; + } + + @Inject void injectPackagePrivateMethod() { + if (subPackagePrivateMethodInjected) { + overriddenPackagePrivateMethodInjectedTwice = true; + } + subPackagePrivateMethodInjected = true; + } + + /** + * Qualifiers are swapped from how they appear in the superclass. + */ + public void injectQualifiers(Seat seatA, @Drivers Seat seatB, + Tire tireA, @Named("spare") Tire tireB) { + if ((seatA instanceof DriversSeat) + || !(seatB instanceof DriversSeat) + || (tireA instanceof SpareTire) + || !(tireB instanceof SpareTire)) { + qualifiersInheritedFromOverriddenMethod = true; + } + } + + void injectPackagePrivateMethodForOverride() { + subPackagePrivateMethodForOverrideInjected = true; + } + + @Inject public void injectTwiceOverriddenWithOmissionInMiddle() { + overriddenTwiceWithOmissionInMiddleInjected = true; + } + + public void injectTwiceOverriddenWithOmissionInSubclass() { + overriddenTwiceWithOmissionInSubclassInjected = true; + } +} diff --git a/tck/org/atinject/tck/auto/accessories/Cupholder.java b/tck/org/atinject/tck/auto/accessories/Cupholder.java new file mode 100644 index 0000000..fec70a4 --- /dev/null +++ b/tck/org/atinject/tck/auto/accessories/Cupholder.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2009 The JSR-330 Expert Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.atinject.tck.auto.accessories; + +import org.atinject.tck.auto.Seat; + +import javax.inject.Inject; +import javax.inject.Provider; +import javax.inject.Singleton; + +@Singleton +public class Cupholder { + + public final Provider<Seat> seatProvider; + + @Inject + public Cupholder(Provider<Seat> seatProvider) { + this.seatProvider = seatProvider; + } +} diff --git a/tck/org/atinject/tck/auto/accessories/RoundThing.java b/tck/org/atinject/tck/auto/accessories/RoundThing.java new file mode 100644 index 0000000..582979c --- /dev/null +++ b/tck/org/atinject/tck/auto/accessories/RoundThing.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2009 The JSR-330 Expert Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.atinject.tck.auto.accessories; + +import javax.inject.Inject; + +public class RoundThing { + + public boolean packagePrivateMethod2Injected; + + @Inject void injectPackagePrivateMethod2() { + packagePrivateMethod2Injected = true; + } + + public boolean packagePrivateMethod3Injected; + + @Inject void injectPackagePrivateMethod3() { + packagePrivateMethod3Injected = true; + } + + public boolean packagePrivateMethod4Injected; + + @Inject void injectPackagePrivateMethod4() { + packagePrivateMethod4Injected = true; + } +} diff --git a/tck/org/atinject/tck/auto/accessories/SpareTire.java b/tck/org/atinject/tck/auto/accessories/SpareTire.java new file mode 100644 index 0000000..5dd6211 --- /dev/null +++ b/tck/org/atinject/tck/auto/accessories/SpareTire.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2009 The JSR-330 Expert Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.atinject.tck.auto.accessories; + +import org.atinject.tck.auto.FuelTank; +import org.atinject.tck.auto.Tire; + +import javax.inject.Inject; + +public class SpareTire extends Tire { + + FuelTank constructorInjection = NEVER_INJECTED; + @Inject FuelTank fieldInjection = NEVER_INJECTED; + FuelTank methodInjection = NEVER_INJECTED; + @Inject static FuelTank staticFieldInjection = NEVER_INJECTED; + static FuelTank staticMethodInjection = NEVER_INJECTED; + + @Inject public SpareTire(FuelTank forSupertype, FuelTank forSubtype) { + super(forSupertype); + this.constructorInjection = forSubtype; + } + + @Inject void subtypeMethodInjection(FuelTank methodInjection) { + if (!hasSpareTireBeenFieldInjected()) { + methodInjectedBeforeFields = true; + } + this.methodInjection = methodInjection; + } + + @Inject static void subtypeStaticMethodInjection(FuelTank methodInjection) { + if (!hasBeenStaticFieldInjected()) { + staticMethodInjectedBeforeStaticFields = true; + } + staticMethodInjection = methodInjection; + } + + @Inject private void injectPrivateMethod() { + if (subPrivateMethodInjected) { + similarPrivateMethodInjectedTwice = true; + } + subPrivateMethodInjected = true; + } + + @Inject void injectPackagePrivateMethod() { + if (subPackagePrivateMethodInjected) { + similarPackagePrivateMethodInjectedTwice = true; + } + subPackagePrivateMethodInjected = true; + } + + @Inject protected void injectProtectedMethod() { + if (subProtectedMethodInjected) { + overriddenProtectedMethodInjectedTwice = true; + } + subProtectedMethodInjected = true; + } + + @Inject public void injectPublicMethod() { + if (subPublicMethodInjected) { + overriddenPublicMethodInjectedTwice = true; + } + subPublicMethodInjected = true; + } + + private void injectPrivateMethodForOverride() { + superPrivateMethodForOverrideInjected = true; + } + + void injectPackagePrivateMethodForOverride() { + superPackagePrivateMethodForOverrideInjected = true; + } + + protected void injectProtectedMethodForOverride() { + protectedMethodForOverrideInjected = true; + } + + public void injectPublicMethodForOverride() { + publicMethodForOverrideInjected = true; + } + + public boolean hasSpareTireBeenFieldInjected() { + return fieldInjection != NEVER_INJECTED; + } + + public boolean hasSpareTireBeenMethodInjected() { + return methodInjection != NEVER_INJECTED; + } + + public static boolean hasBeenStaticFieldInjected() { + return staticFieldInjection != NEVER_INJECTED; + } + + public static boolean hasBeenStaticMethodInjected() { + return staticMethodInjection != NEVER_INJECTED; + } + + public boolean packagePrivateMethod2Injected; + + @Inject void injectPackagePrivateMethod2() { + packagePrivateMethod2Injected = true; + } + + public boolean packagePrivateMethod3Injected; + + void injectPackagePrivateMethod3() { + packagePrivateMethod3Injected = true; + } +} diff --git a/tck/org/atinject/tck/package-info.java b/tck/org/atinject/tck/package-info.java new file mode 100644 index 0000000..fa72b16 --- /dev/null +++ b/tck/org/atinject/tck/package-info.java @@ -0,0 +1,8 @@ +/** + * The compatibility test suite for + * <a href="http://code.google.com/p/atinject/">JSR-330: Dependency Injection + * for Java</a>. + * + * @see org.atinject.tck.Tck + */ +package org.atinject.tck; |