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 dagger.functional.kotlinsrc.assisted.kotlin
18 
19 import com.google.common.truth.Truth.assertThat
20 import dagger.Component
21 import org.junit.Test
22 import org.junit.runner.RunWith
23 import org.junit.runners.JUnit4
24 
25 // This is a regression test for https://github.com/google/dagger/issues/2299
26 @RunWith(JUnit4::class)
27 class KotlinAssistedInjectionTest {
28   @Component
29   internal interface TestComponent {
fooFactorynull30     fun fooFactory(): FooFactory
31     fun fooDataFactory(): FooDataFactory
32     fun barManagerFactory(): BarManager.Factory
33   }
34 
35   @Test
36   fun testFooFactory() {
37     val fooFactory = DaggerKotlinAssistedInjectionTest_TestComponent.create().fooFactory()
38     val assistedDep = AssistedDep()
39     val foo = fooFactory.create(assistedDep)
40     assertThat(foo.assistedDep).isEqualTo(assistedDep)
41   }
42 
43   @Test
testFooDataFactorynull44   fun testFooDataFactory() {
45     val fooDataFactory = DaggerKotlinAssistedInjectionTest_TestComponent.create().fooDataFactory()
46     val assistedDep = AssistedDep()
47     val fooData = fooDataFactory.create(assistedDep)
48     assertThat(fooData.assistedDep).isEqualTo(assistedDep)
49   }
50 
51   @Test
testBarManagernull52   fun testBarManager() {
53     val barManagerFactory =
54       DaggerKotlinAssistedInjectionTest_TestComponent.create().barManagerFactory()
55     val bar = Bar()
56     val name = "someName"
57     val barManager = barManagerFactory.run { bar(name) }
58     assertThat(barManager.bar).isEqualTo(bar)
59     assertThat(barManager.name).isEqualTo(name)
60   }
61 }
62