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.multibindings;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import dagger.Component;
22 import dagger.Module;
23 import dagger.Provides;
24 import dagger.multibindings.ClassKey;
25 import dagger.multibindings.IntoMap;
26 import java.util.Map;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.junit.runners.JUnit4;
30 
31 // This is a regression test for https://github.com/google/dagger/issues/4055.
32 @RunWith(JUnit4.class)
33 public final class ClassKeyWithGenericsTest {
34   @Component(modules = TestModule.class)
35   interface TestComponent {
map()36     Map<Class<?>, String> map();
37   }
38 
39   @Module
40   interface TestModule {
41     @Provides
42     @IntoMap
43     @ClassKey(Thing.class)
provideThingValue()44     static String provideThingValue() {
45       return "Thing";
46     }
47 
48     @Provides
49     @IntoMap
50     @ClassKey(GenericThing.class)
provideGenericThingValue()51     static String provideGenericThingValue() {
52       return "GenericThing";
53     }
54   }
55 
56   class Thing {}
57 
58   class GenericThing<T> {}
59 
60   @Test
test()61   public void test() {
62     Map<Class<?>, String> map = DaggerClassKeyWithGenericsTest_TestComponent.create().map();
63     assertThat(map)
64         .containsExactly(
65             Thing.class, "Thing",
66             GenericThing.class, "GenericThing");
67   }
68 }
69