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.Component;
22 import dagger.assisted.Assisted;
23 import dagger.assisted.AssistedFactory;
24 import dagger.assisted.AssistedInject;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.JUnit4;
28 
29 // This is a regression test for https://github.com/google/dagger/issues/2278
30 @RunWith(JUnit4.class)
31 public final class AssistedFactoryWithAssistedInjectParamTest {
32   @Component
33   interface ParentComponent {
fooFactory()34     FooFactory fooFactory();
35 
barFactory()36     BarFactory barFactory();
37   }
38 
39   static class Foo {
40     private final Bar bar;
41 
42     @AssistedInject
Foo(@ssisted Bar bar)43     Foo(@Assisted Bar bar) {
44       this.bar = bar;
45     }
46   }
47 
48   static class Bar {
49     @AssistedInject
Bar()50     Bar() {}
51   }
52 
53   @AssistedFactory
54   interface FooFactory {
create(Bar bar)55     Foo create(Bar bar);
56   }
57 
58   @AssistedFactory
59   interface BarFactory {
create()60     Bar create();
61   }
62 
63   @Test
testFooFactory()64   public void testFooFactory() {
65     ParentComponent component =
66         DaggerAssistedFactoryWithAssistedInjectParamTest_ParentComponent.create();
67     FooFactory fooFactory = component.fooFactory();
68     BarFactory barFactory = component.barFactory();
69 
70     Bar bar = barFactory.create();
71     Foo foo = fooFactory.create(bar);
72     assertThat(foo.bar).isEqualTo(bar);
73   }
74 }
75