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.binds;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.junit.runners.JUnit4;
25 
26 @RunWith(JUnit4.class)
27 public class BindsTest {
28 
29   private TestComponent component;
30 
31   @Before
setUp()32   public void setUp() {
33     component = DaggerTestComponent.create();
34   }
35 
36   @Test
bindDelegates()37   public void bindDelegates() {
38     assertThat(component.object()).isInstanceOf(FooOfStrings.class);
39     assertThat(component.fooOfStrings()).isInstanceOf(FooOfStrings.class);
40     assertThat(component.fooOfObjects()).isInstanceOf(FooOfObjects.class);
41     assertThat(component.fooOfIntegers()).isNotNull();
42   }
43 
44   @Test
bindWithScope()45   public void bindWithScope() {
46     assertThat(component.qualifiedFooOfStrings())
47         .isSameInstanceAs(component.qualifiedFooOfStrings());
48   }
49 
50   @Test
multibindings()51   public void multibindings() {
52     assertThat(component.foosOfNumbers()).hasSize(2);
53     assertThat(component.objects()).hasSize(3);
54     assertThat(component.charSequences()).hasSize(5);
55 
56     assertThat(component.integerObjectMap())
57         .containsExactly(123, "123-string", 456, "456-string", 789, "789-string");
58     assertThat(component.integerProviderOfObjectMap()).hasSize(3);
59     assertThat(component.integerProviderOfObjectMap().get(123).get()).isEqualTo("123-string");
60     assertThat(component.integerProviderOfObjectMap().get(456).get()).isEqualTo("456-string");
61     assertThat(component.integerProviderOfObjectMap().get(789).get()).isEqualTo("789-string");
62 
63     assertThat(component.qualifiedIntegerObjectMap()).hasSize(1);
64 
65     assertThat(component.primitiveSet()).containsExactly(100);
66     assertThat(component.primitiveValueMap()).containsExactly(10, 100);
67   }
68 }
69