001    /**
002     Licensed to the Apache Software Foundation (ASF) under one or more
003     contributor license agreements.  See the NOTICE file distributed with
004     this work for additional information regarding copyright ownership.
005     The ASF licenses this file to You under the Apache License, Version 2.0
006     (the "License"); you may not use this file except in compliance with
007     the License.  You may obtain a copy of the License at
008    
009          http://www.apache.org/licenses/LICENSE-2.0
010    
011     Unless required by applicable law or agreed to in writing, software
012     distributed under the License is distributed on an "AS IS" BASIS,
013     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     See the License for the specific language governing permissions and
015     limitations under the License.
016    */
017    package org.apache.commons.inject.impl;
018    
019    import org.apache.commons.inject.api.CommonsInject;
020    import org.apache.commons.inject.api.IInjector;
021    import org.apache.commons.inject.api.bind.IBinder;
022    import org.apache.commons.inject.api.bind.IModule;
023    import org.apache.commons.inject.api.bind.Scopes;
024    import org.atinject.tck.Tck;
025    import org.atinject.tck.auto.Car;
026    import org.atinject.tck.auto.Convertible;
027    import org.atinject.tck.auto.Drivers;
028    import org.atinject.tck.auto.DriversSeat;
029    import org.atinject.tck.auto.Engine;
030    import org.atinject.tck.auto.FuelTank;
031    import org.atinject.tck.auto.Seat;
032    import org.atinject.tck.auto.Tire;
033    import org.atinject.tck.auto.V8Engine;
034    import org.atinject.tck.auto.accessories.Cupholder;
035    import org.atinject.tck.auto.accessories.SpareTire;
036    import org.junit.Test;
037    
038    public class TckTest {
039            @Test
040            public void testTckWithStaticInjection() throws Exception {
041                    final IInjector injector = newInjector(true);
042                    final Car car = injector.requireInstance(Car.class);
043                    Tck.testsFor(car, true, true);
044            }
045    
046            @Test
047            public void testTckWithoutStaticInjection() throws Exception {
048                    final IInjector injector = newInjector(false);
049                    final Car car = injector.requireInstance(Car.class);
050                    Tck.testsFor(car, false, true);
051            }
052    
053            private IInjector newInjector(boolean pWithStaticInjection) {
054                    final IModule module = new IModule(){
055                            @Override
056                            public void configure(IBinder pBinder) {
057                                    pBinder.bind(Car.class).to(Convertible.class).scope(Scopes.PER_CALL);;
058                                    pBinder.bind(Seat.class).annotatedWith(Drivers.class).to(DriversSeat.class).scope(Scopes.PER_CALL);
059                                    pBinder.bind(Engine.class).to(V8Engine.class).scope(Scopes.PER_CALL);
060                                    pBinder.bind(Tire.class, "spare").to(SpareTire.class).scope(Scopes.PER_CALL);
061                                    pBinder.bind(SpareTire.class).scope(Scopes.PER_CALL);
062                                    pBinder.bind(Cupholder.class).scope(Scopes.PER_CALL);
063                                    pBinder.bind(Tire.class).scope(Scopes.PER_CALL);
064                                    pBinder.bind(FuelTank.class).scope(Scopes.PER_CALL);
065                            }
066                    };
067                    return CommonsInject.build(module);
068            }
069    
070    }