• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.factory;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import dagger.BindsInstance;
22 import dagger.Component;
23 import java.util.Random;
24 import javax.inject.Provider;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.JUnit4;
28 
29 /** Tests for component factories with multiple parameters. */
30 @RunWith(JUnit4.class)
31 public final class FactoryMixedParametersTest {
32 
33   @Component(
34       modules = {
35         AbstractModule.class,
36         UninstantiableConcreteModule.class,
37         InstantiableConcreteModule.class
38       },
39       dependencies = Dependency.class)
40   interface MixedArgComponent {
string()41     String string();
getInt()42     int getInt();
getLong()43     long getLong();
object()44     Object object();
getDouble()45     double getDouble();
randomProvider()46     Provider<Random> randomProvider();
47 
48     @Component.Factory
49     interface Factory {
create( @indsInstance double d, Dependency dependency, UninstantiableConcreteModule module, @BindsInstance Random random)50       MixedArgComponent create(
51           @BindsInstance double d,
52           Dependency dependency,
53           UninstantiableConcreteModule module,
54           @BindsInstance Random random);
55     }
56   }
57 
58   @Test
mixedArgComponent()59   public void mixedArgComponent() {
60     Random random = new Random();
61     MixedArgComponent component =
62         DaggerFactoryMixedParametersTest_MixedArgComponent.factory()
63             .create(3.0, new Dependency(), new UninstantiableConcreteModule(2L), random);
64     assertThat(component.string()).isEqualTo("foo");
65     assertThat(component.getInt()).isEqualTo(42);
66     assertThat(component.getDouble()).isEqualTo(3.0);
67     assertThat(component.object()).isEqualTo("bar");
68     assertThat(component.getLong()).isEqualTo(2L);
69     assertThat(component.randomProvider().get()).isSameInstanceAs(random);
70     assertThat(component.randomProvider().get()).isSameInstanceAs(random);
71   }
72 }
73