xref: /aosp_15_r20/external/dagger2/javatests/dagger/functional/kotlinsrc/binds/BindsTest.kt (revision f585d8a307d0621d6060bd7e80091fdcbf94fe27)
1 /*
2  * Copyright (C) 2022 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.kotlinsrc.binds
18 
19 import com.google.common.truth.Truth.assertThat
20 import org.junit.Before
21 import org.junit.Test
22 import org.junit.runner.RunWith
23 import org.junit.runners.JUnit4
24 
25 @RunWith(JUnit4::class)
26 class BindsTest {
27   private lateinit var component: TestComponent
28 
29   @Before
setUpnull30   fun setUp() {
31     component = DaggerTestComponent.create()
32   }
33 
34   @Test
bindDelegatesnull35   fun bindDelegates() {
36     assertThat(component.someObject()).isInstanceOf(FooOfStrings::class.java)
37     assertThat(component.fooOfStrings()).isInstanceOf(FooOfStrings::class.java)
38     assertThat(component.fooOfObjects()).isInstanceOf(FooOfObjects::class.java)
39     assertThat(component.fooOfIntegers()).isNotNull()
40   }
41 
42   @Test
bindWithScopenull43   fun bindWithScope() {
44     assertThat(component.qualifiedFooOfStrings())
45       .isSameInstanceAs(component.qualifiedFooOfStrings())
46   }
47 
48   @Test
multibindingsnull49   fun multibindings() {
50     assertThat(component.foosOfNumbers()).hasSize(2)
51     assertThat(component.someObjects()).hasSize(3)
52     assertThat(component.charSequences()).hasSize(5)
53     assertThat(component.notExposedString()).isEqualTo("not exposed")
54     assertThat(component.integerObjectMap())
55       .containsExactly(
56         123, "123-string",
57         456, "456-string",
58         789, "789-string"
59       )
60     assertThat(component.integerProviderOfObjectMap()).hasSize(3)
61     assertThat(component.integerProviderOfObjectMap()[123]!!.get()).isEqualTo("123-string")
62     assertThat(component.integerProviderOfObjectMap()[456]!!.get()).isEqualTo("456-string")
63     assertThat(component.integerProviderOfObjectMap()[789]!!.get()).isEqualTo("789-string")
64     assertThat(component.qualifiedIntegerObjectMap()).hasSize(1)
65     assertThat(component.primitiveSet()).containsExactly(100)
66     assertThat(component.primitiveValueMap()).containsExactly(10, 100)
67   }
68 }
69