1 /*
2  * Copyright (C) 2023 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.kotlinsrc.multibindings
18 
19 import com.google.common.truth.Truth.assertThat
20 import dagger.Component
21 import dagger.Module
22 import dagger.Provides
23 import dagger.multibindings.ClassKey
24 import dagger.multibindings.IntoMap
25 import org.junit.Test
26 import org.junit.runner.RunWith
27 import org.junit.runners.JUnit4
28 
29 @RunWith(JUnit4::class)
30 class ClassKeyWithGenericsTest {
31   @Component(modules = [TestModule::class])
32   interface TestComponent {
33     val map: Map<Class<*>, String>
34   }
35 
36   @Module
37   internal object TestModule {
38     @Provides
39     @IntoMap
40     @ClassKey(Thing::class)
provideThingValuenull41     fun provideThingValue(): String = "Thing"
42 
43     @Provides
44     @IntoMap
45     @ClassKey(GenericThing::class)
46     fun provideAbstractThingValue(): String = "GenericThing"
47   }
48 
49   class Thing
50 
51   class GenericThing<T>
52 
53   @Test
54   fun test() {
55     val map = DaggerClassKeyWithGenericsTest_TestComponent.create().map
56     assertThat(map)
57         .containsExactly(
58             Thing::class.java, "Thing",
59             GenericThing::class.java, "GenericThing");
60   }
61 }
62