View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.onami.factoryannotation;
20  
21  import static org.junit.Assert.assertEquals;
22  
23  import org.apache.onami.factoryannotation.annotations.SecondLayer;
24  import org.apache.onami.factoryannotation.impl.SecondLayerEntity;
25  import org.apache.onami.factoryannotation.impl.SecondLayerIdentityProvider;
26  import org.junit.Test;
27  
28  import com.google.inject.Guice;
29  import com.google.inject.Injector;
30  
31  public class InterfaceTestCase
32  {
33  
34      @Test
35      public void testInterfaceValueProvider()
36      {
37          final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
38          {
39              @Override
40              protected void configure()
41              {
42                  bindType( SecondLayerEntity.class ).annotatedWith( SecondLayer.class ).toAnnotationFactory( new SecondLayerIdentityProvider() );
43              }
44          } );
45  
46          final SecondLayerInjectable injectable = new SecondLayerInjectable();
47          injector.injectMembers( injectable );
48  
49          assertEquals( "SecondLayerEntity1", injectable.layerEntity1.getValue() );
50          assertEquals( 1, injectable.layerEntity1.getId() );
51          assertEquals( "SecondLayerEntity2", injectable.layerEntity2.getValue() );
52          assertEquals( 2, injectable.layerEntity2.getId() );
53      }
54  
55      public class SecondLayerInjectable
56      {
57          @SecondLayer( byId = 1 )
58          private SecondLayerEntity layerEntity1;
59  
60          @SecondLayer( byId = 2 )
61          private SecondLayerEntity layerEntity2;
62      }
63  
64  }