• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.binds;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import dagger.Binds;
22 import dagger.Component;
23 import dagger.Module;
24 import dagger.Provides;
25 import java.util.HashMap;
26 import java.util.HashSet;
27 import java.util.Map;
28 import java.util.Set;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.junit.runners.JUnit4;
32 
33 @RunWith(JUnit4.class)
34 public class BindsCollectionsWithoutMultibindingsTest {
35   @Module
36   abstract static class M {
37     @Provides
provideHashSet()38     static HashSet<String> provideHashSet() {
39       HashSet<String> set = new HashSet<>();
40       set.add("binds");
41       set.add("set");
42       return set;
43     }
44 
45     @Binds
bindStringSet(HashSet<String> set)46     abstract Set<String> bindStringSet(HashSet<String> set);
47 
48     @Provides
provideHashMap()49     static HashMap<String, String> provideHashMap() {
50       HashMap<String, String> map = new HashMap<>();
51       map.put("binds", "map");
52       map.put("without", "multibindings");
53       return map;
54     }
55 
56     @Binds
bindStringMap(HashMap<String, String> map)57     abstract Map<String, String> bindStringMap(HashMap<String, String> map);
58   }
59 
60   @Component(modules = M.class)
61   interface C {
set()62     Set<String> set();
63 
map()64     Map<String, String> map();
65   }
66 
67   @Test
works()68   public void works() {
69     C component = DaggerBindsCollectionsWithoutMultibindingsTest_C.create();
70 
71     assertThat(component.set()).containsExactly("binds", "set");
72     assertThat(component.map())
73         .containsExactly(
74             "binds", "map",
75             "without", "multibindings");
76   }
77 }
78