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 18 19 import com.google.common.truth.Truth.assertThat 20 import dagger.Component 21 import dagger.assisted.AssistedFactory 22 import dagger.functional.kotlinsrc.assisted.subpackage.AccessibleFoo 23 import dagger.functional.kotlinsrc.assisted.subpackage.AssistedDep 24 import dagger.functional.kotlinsrc.assisted.subpackage.InaccessibleFooFactory 25 import org.junit.Test 26 import org.junit.runner.RunWith 27 import org.junit.runners.JUnit4 28 29 @RunWith(JUnit4::class) 30 internal class AssistedFactoryInaccessibleTest { 31 @Component 32 interface ParentComponent { 33 // Factory for an accessible type from another package accessibleFooFactorynull34 fun accessibleFooFactory(): AccessibleFooFactory 35 36 // Factory for an inaccessible type from another package 37 fun inaccessibleFooFactory(): InaccessibleFooFactory 38 } 39 40 @AssistedFactory 41 interface AccessibleFooFactory { 42 // Use different parameter names than Foo to make sure we're not assuming they're the same. 43 fun create(factoryAssistedDep: AssistedDep): AccessibleFoo 44 } 45 46 @Test testAccessibleFooFactorynull47 fun testAccessibleFooFactory() { 48 val assistedDep = AssistedDep() 49 val accessibleFoo = 50 DaggerAssistedFactoryInaccessibleTest_ParentComponent.create() 51 .accessibleFooFactory() 52 .create(assistedDep) 53 assertThat(accessibleFoo).isNotNull() 54 assertThat(accessibleFoo.dep).isNotNull() 55 assertThat(accessibleFoo.assistedDep).isEqualTo(assistedDep) 56 } 57 58 @Test testInaccessibleFooFactorynull59 fun testInaccessibleFooFactory() { 60 val assistedDep = AssistedDep() 61 // We can't access InaccessibleFoo directly, so just use Object instead. 62 val inaccessibleFoo = 63 DaggerAssistedFactoryInaccessibleTest_ParentComponent.create() 64 .inaccessibleFooFactory() 65 .create(assistedDep) 66 assertThat(inaccessibleFoo).isNotNull() 67 } 68 } 69