• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Dagger Authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package dagger.functional.producers.binds;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import dagger.producers.Produced;
22 import dagger.producers.Producer;
23 import java.util.Map;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.JUnit4;
28 
29 @RunWith(JUnit4.class)
30 public class BindsProducersTest {
31 
32   private SimpleBindsProductionComponent component;
33 
34   @Before
setUp()35   public void setUp() {
36     component = DaggerSimpleBindsProductionComponent.create();
37   }
38 
39   @Test
bindDelegates()40   public void bindDelegates() throws Exception {
41     assertThat(component.object().get()).isInstanceOf(FooOfStrings.class);
42     assertThat(component.fooOfStrings().get()).isInstanceOf(FooOfStrings.class);
43     assertThat(component.fooOfIntegers().get()).isNotNull();
44   }
45 
46   @Test
bindWithScope()47   public void bindWithScope() throws Exception {
48     assertThat(component.qualifiedFooOfStrings().get())
49         .isSameInstanceAs(component.qualifiedFooOfStrings().get());
50   }
51 
52   @Test
multibindings()53   public void multibindings() throws Exception {
54     assertThat(component.foosOfNumbers().get()).hasSize(2);
55     assertThat(component.objects().get()).hasSize(3);
56     assertThat(component.charSequences().get()).hasSize(5);
57 
58     assertThat(component.integerObjectMap().get())
59         .containsExactly(
60             123, "123-string", 456, "456-string", 789, "789-string", -1, "provision-string");
61 
62     Map<Integer, Producer<Object>> integerProducerOfObjectMap =
63         component.integerProducerOfObjectMap().get();
64     assertThat(integerProducerOfObjectMap).hasSize(4);
65     assertThat(integerProducerOfObjectMap.get(123).get().get()).isEqualTo("123-string");
66     assertThat(integerProducerOfObjectMap.get(456).get().get()).isEqualTo("456-string");
67     assertThat(integerProducerOfObjectMap.get(789).get().get()).isEqualTo("789-string");
68     assertThat(integerProducerOfObjectMap.get(-1).get().get()).isEqualTo("provision-string");
69 
70     assertThat(component.integerProducedOfObjectMap().get())
71         .containsExactly(
72             123, Produced.successful("123-string"),
73             456, Produced.successful("456-string"),
74             789, Produced.successful("789-string"),
75             -1, Produced.successful("provision-string"));
76 
77     assertThat(component.qualifiedIntegerObjectMap().get()).hasSize(1);
78   }
79 }
80