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.factory 18 19 import com.google.common.truth.Truth.assertThat 20 import dagger.BindsInstance 21 import dagger.Component 22 import java.util.Random 23 import javax.inject.Provider 24 import org.junit.Test 25 import org.junit.runner.RunWith 26 import org.junit.runners.JUnit4 27 28 /** Tests for component factories with multiple parameters. */ 29 @RunWith(JUnit4::class) 30 class FactoryMixedParametersTest { 31 @Component( 32 modules = 33 [ 34 AbstractModule::class, 35 UninstantiableConcreteModule::class, 36 InstantiableConcreteModule::class 37 ], 38 dependencies = [Dependency::class] 39 ) 40 internal interface MixedArgComponent { getStringnull41 fun getString(): String 42 val getInt: Int 43 val getLong: Long 44 fun getSomeObject(): Any 45 val getDouble: Double 46 fun getRandomProvider(): Provider<Random> 47 48 @Component.Factory 49 interface Factory { 50 fun create( 51 @BindsInstance d: Double, 52 dependency: Dependency, 53 module: UninstantiableConcreteModule, 54 @BindsInstance random: Random 55 ): MixedArgComponent 56 } 57 } 58 59 @Test mixedArgComponentnull60 fun mixedArgComponent() { 61 val random = Random() 62 val component = 63 DaggerFactoryMixedParametersTest_MixedArgComponent.factory() 64 .create(3.0, Dependency(), UninstantiableConcreteModule(2L), random) 65 assertThat(component.getString()).isEqualTo("foo") 66 assertThat(component.getInt).isEqualTo(42) 67 assertThat(component.getDouble).isEqualTo(3.0) 68 assertThat(component.getSomeObject()).isEqualTo("bar") 69 assertThat(component.getLong).isEqualTo(2L) 70 assertThat(component.getRandomProvider().get()).isSameInstanceAs(random) 71 assertThat(component.getRandomProvider().get()).isSameInstanceAs(random) 72 } 73 } 74