• 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 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 
32     fun fooDataFactory(): FooDataFactory
33 
34     fun barManagerFactory(): BarManager.Factory
35 
36   }
37 
38   @Test
39   fun testFooFactory() {
40     val fooFactory = DaggerKotlinAssistedInjectionTest_TestComponent.create().fooFactory()
41     val assistedDep = AssistedDep()
42     val foo = fooFactory.create(assistedDep)
43     assertThat(foo.assistedDep).isEqualTo(assistedDep)
44   }
45 
46   @Test
testFooDataFactorynull47   fun testFooDataFactory() {
48     val fooDataFactory = DaggerKotlinAssistedInjectionTest_TestComponent.create().fooDataFactory()
49     val assistedDep = AssistedDep()
50     val fooData = fooDataFactory.create(assistedDep)
51     assertThat(fooData.assistedDep).isEqualTo(assistedDep)
52   }
53 
54   @Test
testBarManagernull55   fun testBarManager() {
56     val barManagerFactory =
57       DaggerKotlinAssistedInjectionTest_TestComponent.create().barManagerFactory()
58     val bar = Bar()
59     val name = "someName"
60     val barManager = barManagerFactory.run { bar(name) }
61     assertThat(barManager.bar).isEqualTo(bar)
62     assertThat(barManager.name).isEqualTo(name)
63   }
64 }
65