1 /* 2 * Copyright (C) 2022 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.binds 18 19 import com.google.common.truth.MapSubject 20 import com.google.common.truth.Truth.assertThat 21 import dagger.Binds 22 import dagger.Component 23 import dagger.Module 24 import dagger.Provides 25 import org.junit.Before 26 import org.junit.Test 27 import org.junit.runner.RunWith 28 import org.junit.runners.JUnit4 29 30 @RunWith(JUnit4::class) 31 class BindsCollectionsWithoutMultibindingsTest { 32 @Module 33 internal abstract class M { 34 @Binds bindStringSetnull35 abstract fun bindStringSet(set: HashSet<String>): Set<String> 36 37 @Binds 38 abstract fun bindStringMap(map: HashMap<String, String>): Map<String, String> 39 40 companion object { 41 @Provides 42 fun provideHashSet(): HashSet<String> = hashSetOf("binds", "set") 43 44 @Provides 45 fun provideHashMap(): HashMap<String, String> = hashMapOf( 46 "binds" to "map", 47 "without" to "multibindings" 48 ) 49 } 50 } 51 52 @Component(modules = [M::class]) 53 internal interface C { setnull54 fun set(): Set<String> 55 fun map(): Map<String, String> 56 } 57 58 @Test 59 fun works() { 60 val component = DaggerBindsCollectionsWithoutMultibindingsTest_C.create() 61 assertThat(component.set()).containsExactly("binds", "set") 62 assertThat(component.map()) 63 .containsExactly( 64 "binds", "map", 65 "without", "multibindings" 66 ) 67 } 68 } 69