16
16
17
17
import static org .junit .Assert .assertEquals ;
18
18
import static org .junit .Assert .assertFalse ;
19
+ import static org .junit .Assert .assertTrue ;
20
+ import static org .junit .Assert .fail ;
19
21
20
22
import androidx .annotation .NonNull ;
21
23
import androidx .test .platform .app .InstrumentationRegistry ;
@@ -69,7 +71,7 @@ FirebaseFirestore.EMULATOR, new EmulatedServiceSettings("10.0.2.2", 8080))
69
71
assertFalse (settings .isPersistenceEnabled ());
70
72
}
71
73
72
- @ Test ( expected = IllegalStateException . class )
74
+ @ Test
73
75
public void getInstance_withEmulator_mergeSettingsFailure () {
74
76
FirebaseApp app = getApp ("getInstance_withEmulator_mergeSettingsFailure" );
75
77
app .enableEmulators (
@@ -78,9 +80,64 @@ public void getInstance_withEmulator_mergeSettingsFailure() {
78
80
FirebaseFirestore .EMULATOR , new EmulatedServiceSettings ("10.0.2.2" , 8080 ))
79
81
.build ());
80
82
83
+ try {
84
+ FirebaseFirestore firestore = FirebaseFirestore .getInstance (app );
85
+ firestore .setFirestoreSettings (
86
+ new FirebaseFirestoreSettings .Builder ().setHost ("myhost.com" ).build ());
87
+ fail ("Exception should be thrown" );
88
+ } catch (Exception e ) {
89
+ assertTrue (e instanceof IllegalStateException );
90
+ assertEquals (
91
+ e .getMessage (),
92
+ "Cannot specify the host in FirebaseFirestoreSettings when EmulatedServiceSettings is provided." );
93
+ }
94
+ }
95
+
96
+ @ Test
97
+ public void setSettings_repeatedSuccess () {
98
+ FirebaseApp app = getApp ("setSettings_repeatedSuccess" );
81
99
FirebaseFirestore firestore = FirebaseFirestore .getInstance (app );
82
- firestore .setFirestoreSettings (
83
- new FirebaseFirestoreSettings .Builder ().setHost ("myhost.com" ).build ());
100
+
101
+ FirebaseFirestoreSettings settings =
102
+ new FirebaseFirestoreSettings .Builder ().setHost ("myhost.com" ).setSslEnabled (false ).build ();
103
+ firestore .setFirestoreSettings (settings );
104
+
105
+ // This should 'start' Firestore
106
+ DocumentReference reference = firestore .document ("foo/bar" );
107
+
108
+ // Second settings set should pass because the settings are equal
109
+ firestore .setFirestoreSettings (settings );
110
+ }
111
+
112
+ @ Test
113
+ public void setSettings_repeatedFailure () {
114
+ FirebaseApp app = getApp ("setSettings_repeatedFailure" );
115
+ FirebaseFirestore firestore = FirebaseFirestore .getInstance (app );
116
+
117
+ FirebaseFirestoreSettings settings =
118
+ new FirebaseFirestoreSettings .Builder ().setHost ("myhost.com" ).setSslEnabled (false ).build ();
119
+
120
+ FirebaseFirestoreSettings otherSettings =
121
+ new FirebaseFirestoreSettings .Builder ()
122
+ .setHost ("otherhost.com" )
123
+ .setSslEnabled (false )
124
+ .build ();
125
+
126
+ firestore .setFirestoreSettings (settings );
127
+
128
+ // This should 'start' Firestore
129
+ DocumentReference reference = firestore .document ("foo/bar" );
130
+
131
+ try {
132
+ firestore .setFirestoreSettings (otherSettings );
133
+ fail ("Exception should be thrown" );
134
+ } catch (Exception e ) {
135
+ assertTrue (e instanceof IllegalStateException );
136
+ assertTrue (
137
+ e .getMessage ()
138
+ .startsWith (
139
+ "FirebaseFirestore has already been started and its settings can no longer be changed." ));
140
+ }
84
141
}
85
142
86
143
@ NonNull
0 commit comments