• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.hilt.android.testing;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import androidx.test.ext.junit.runners.AndroidJUnit4;
22 import dagger.hilt.EntryPoint;
23 import dagger.hilt.InstallIn;
24 import dagger.hilt.components.SingletonComponent;
25 import java.util.Set;
26 import javax.inject.Inject;
27 import javax.inject.Provider;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.robolectric.annotation.Config;
32 
33 @HiltAndroidTest
34 @RunWith(AndroidJUnit4.class)
35 @Config(application = HiltTestApplication.class)
36 public final class BindValueIntoSetTest {
37   private static final String SET_STRING_1 = "SetString1";
38   private static final String SET_STRING_2 = "SetString2";
39   private static final String SET_STRING_3 = "SetString3";
40 
41   @EntryPoint
42   @InstallIn(SingletonComponent.class)
43   public interface BindValueIntoSetEntryPoint {
getStringSet()44     Set<String> getStringSet();
45   }
46 
47   @Rule public final HiltAndroidRule rule = new HiltAndroidRule(this);
48 
49   @BindValueIntoSet String bindValueSetString1 = SET_STRING_1;
50   @BindValueIntoSet String bindValueSetString2 = SET_STRING_2;
51 
52   @Inject Set<String> stringSet;
53   @Inject Provider<Set<String>> providedStringSet;
54 
55   @Test
testMutated()56   public void testMutated() throws Exception {
57     rule.inject();
58     // basic check that initial/default values are properly injected
59     assertThat(providedStringSet.get()).containsExactly(SET_STRING_1, SET_STRING_2);
60     bindValueSetString1 = SET_STRING_3;
61     // change the value for bindValueSetString1 from 1 to 3
62     assertThat(providedStringSet.get()).containsExactly(SET_STRING_2, SET_STRING_3);
63   }
64 
65 
66 }
67