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; 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 public final class ComponentMethodTest { 32 33 static final class Dep1 { 34 35 @Inject Dep1(Dep2 dep2)36 Dep1(Dep2 dep2) {} 37 } 38 39 static final class Dep2 { 40 41 @Inject Dep2(Dep3 dep3)42 Dep2(Dep3 dep3) {} 43 } 44 45 static final class Dep3 { 46 47 @Inject Dep3()48 Dep3() {} 49 } 50 51 @Component 52 interface NonTopologicalOrderComponent { 53 dep1Provider()54 Provider<Dep1> dep1Provider(); 55 dep2Provider()56 Provider<Dep2> dep2Provider(); 57 } 58 59 @Component 60 interface TopologicalOrderComponent { 61 dep2Provider()62 Provider<Dep2> dep2Provider(); 63 dep1Provider()64 Provider<Dep1> dep1Provider(); 65 } 66 67 @Test testNonTopologicalOrderComponent()68 public void testNonTopologicalOrderComponent() throws Exception { 69 NonTopologicalOrderComponent component = 70 DaggerComponentMethodTest_NonTopologicalOrderComponent.create(); 71 component.dep1Provider().get(); 72 component.dep2Provider().get(); 73 } 74 75 @Test testTopologicalOrderComponent()76 public void testTopologicalOrderComponent() throws Exception { 77 TopologicalOrderComponent component = 78 DaggerComponentMethodTest_TopologicalOrderComponent.create(); 79 component.dep1Provider().get(); 80 component.dep2Provider().get(); 81 } 82 } 83