1 /* 2 * Copyright (C) 2021 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.assisted; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import dagger.BindsInstance; 22 import dagger.Component; 23 import dagger.assisted.Assisted; 24 import dagger.assisted.AssistedFactory; 25 import dagger.assisted.AssistedInject; 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 import org.junit.runners.JUnit4; 29 30 @RunWith(JUnit4.class) 31 public final class AssistedFactoryDuplicatedParamNamesTest { 32 static final class Foo { 33 private final String arg; 34 private final Bar bar; 35 36 @AssistedInject Foo(@ssisted String arg, Bar bar)37 Foo(@Assisted String arg, Bar bar) { 38 this.arg = arg; 39 this.bar = bar; 40 } 41 getBar()42 Bar getBar() { 43 return bar; 44 } 45 getArg()46 String getArg() { 47 return arg; 48 } 49 } 50 51 static final class Bar {} 52 53 @AssistedFactory 54 interface FooFactory { create(String arg)55 Foo create(String arg); 56 } 57 58 @Component 59 interface TestComponent { 60 @Component.Factory 61 interface Factory { create(@indsInstance Bar arg)62 TestComponent create(@BindsInstance Bar arg); 63 } 64 fooFactory()65 FooFactory fooFactory(); 66 } 67 68 @Test duplicatedParameterNames_doesNotConflict()69 public void duplicatedParameterNames_doesNotConflict() { 70 String str = "test"; 71 Bar bar = new Bar(); 72 73 Foo foo = 74 DaggerAssistedFactoryDuplicatedParamNamesTest_TestComponent.factory() 75 .create(bar) 76 .fooFactory() 77 .create(str); 78 79 assertThat(foo.getArg()).isEqualTo(str); 80 assertThat(foo.getBar()).isEqualTo(bar); 81 } 82 } 83