1 /* 2 * Copyright (C) 2018 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.basic 18 19 import dagger.Component 20 import javax.inject.Inject 21 import javax.inject.Provider 22 import org.junit.Test 23 import org.junit.runner.RunWith 24 import org.junit.runners.JUnit4 25 26 /** 27 * This is a regression test that makes sure component method order does not affect initialization 28 * order. 29 */ 30 @RunWith(JUnit4::class) 31 class ComponentMethodTest { 32 internal class Dep1 @Inject constructor(@Suppress("UNUSED_PARAMETER") dep2: Dep2) 33 internal class Dep2 @Inject constructor(@Suppress("UNUSED_PARAMETER") dep3: Dep3) 34 internal class Dep3 @Inject constructor() 35 36 @Component 37 internal interface NonTopologicalOrderComponent { dep1Providernull38 fun dep1Provider(): Provider<Dep1> 39 fun dep2Provider(): Provider<Dep2> 40 } 41 42 @Component 43 internal interface TopologicalOrderComponent { 44 fun dep2Provider(): Provider<Dep2> 45 fun dep1Provider(): Provider<Dep1> 46 } 47 48 @Test testNonTopologicalOrderComponentnull49 fun testNonTopologicalOrderComponent() { 50 val component = DaggerComponentMethodTest_NonTopologicalOrderComponent.create() 51 component.dep1Provider().get() 52 component.dep2Provider().get() 53 } 54 55 @Test testTopologicalOrderComponentnull56 fun testTopologicalOrderComponent() { 57 val component = DaggerComponentMethodTest_TopologicalOrderComponent.create() 58 component.dep1Provider().get() 59 component.dep2Provider().get() 60 } 61 } 62