• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 app
18 
19 import org.junit.runner.RunWith
20 import org.junit.runners.JUnit4
21 import org.junit.Before
22 import com.google.common.truth.Truth.assertThat
23 import library1.*
24 import org.junit.Test
25 
26 @RunWith(JUnit4::class)
27 class MyComponentTest {
28     private lateinit var component: MyComponent
29 
30     @Before
setupnull31     fun setup() {
32         component = DaggerMyComponent.factory()
33             .create(MyComponentModule(Dep()), MyComponentDependency())
34     }
35 
36     @Test
testFooIsScopednull37     fun testFooIsScoped() {
38         assertThat(component.foo()).isEqualTo(component.foo())
39     }
40 
41     @Test
testAssistedFoonull42     fun testAssistedFoo() {
43         assertThat(component.assistedFooFactory().create(5)).isNotNull()
44     }
45 
46     @Test
testScopedQualifiedBindsTypeIsScopednull47     fun testScopedQualifiedBindsTypeIsScoped() {
48         assertThat(component.scopedQualifiedBindsType())
49             .isEqualTo(component.scopedQualifiedBindsType())
50     }
51 
52     @Test
testScopedUnqualifiedBindsTypeIsScopednull53     fun testScopedUnqualifiedBindsTypeIsScoped() {
54         assertThat(component.scopedUnqualifiedBindsType())
55             .isEqualTo(component.scopedUnqualifiedBindsType())
56     }
57 
58     @Test
testUnscopedQualifiedBindsTypeIsNotScopednull59     fun testUnscopedQualifiedBindsTypeIsNotScoped() {
60         assertThat(component.unscopedQualifiedBindsType())
61             .isNotEqualTo(component.unscopedQualifiedBindsType())
62     }
63 
64     @Test
testUnscopedUnqualifiedBindsTypeIsNotScopednull65     fun testUnscopedUnqualifiedBindsTypeIsNotScoped() {
66         assertThat(component.unscopedUnqualifiedBindsType())
67             .isNotEqualTo(component.unscopedUnqualifiedBindsType())
68     }
69 
70     @Test
testScopedQualifiedProvidesTypeIsScopednull71     fun testScopedQualifiedProvidesTypeIsScoped() {
72         assertThat(component.scopedQualifiedProvidesType())
73             .isEqualTo(component.scopedQualifiedProvidesType())
74     }
75 
76     @Test
testScopedUnqualifiedProvidesTypeIsScopednull77     fun testScopedUnqualifiedProvidesTypeIsScoped() {
78         assertThat(component.scopedUnqualifiedProvidesType())
79             .isEqualTo(component.scopedUnqualifiedProvidesType())
80     }
81 
82     @Test
testUnscopedQualifiedProvidesTypeIsNotScopednull83     fun testUnscopedQualifiedProvidesTypeIsNotScoped() {
84         assertThat(component.unscopedQualifiedProvidesType())
85             .isNotEqualTo(component.unscopedQualifiedProvidesType())
86     }
87 
88     @Test
testUnscopedUnqualifiedProvidesTypeIsNotScopednull89     fun testUnscopedUnqualifiedProvidesTypeIsNotScoped() {
90         assertThat(component.unscopedUnqualifiedProvidesType())
91             .isNotEqualTo(component.unscopedUnqualifiedProvidesType())
92     }
93 
94     @Test
testMyComponentDependencyBindingnull95     fun testMyComponentDependencyBinding() {
96         assertThat(component.qualifiedMyComponentDependencyBinding())
97             .isNotEqualTo(component.unqualifiedMyComponentDependencyBinding())
98     }
99 }