Skip to content

Commit 67f91ad

Browse files
authored
Fix bug where cacheSizeBytes was sometimes not initialized correctly in FirebaseFirestoreSettings (#2965)
1 parent 8122d55 commit 67f91ad

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

firebase-firestore/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 23.0.4
2+
- [fixed] Fixed an issue where some fields were missed when copying in the
3+
`FirebaseFirestoreSettings.Builder` copy constructor.
4+
15
# 23.0.3
26
- [fixed] Fixed an issue when loading a data bundle with
37
multi-byte Unicode characters leads to failures.

firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestoreSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public Builder(@NonNull FirebaseFirestoreSettings settings) {
5757
host = settings.host;
5858
sslEnabled = settings.sslEnabled;
5959
persistenceEnabled = settings.persistenceEnabled;
60+
cacheSizeBytes = settings.cacheSizeBytes;
6061
}
6162

6263
/**
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.firestore;
16+
17+
import static org.junit.Assert.assertEquals;
18+
19+
import org.junit.Test;
20+
import org.junit.runner.RunWith;
21+
import org.robolectric.RobolectricTestRunner;
22+
import org.robolectric.annotation.Config;
23+
24+
@RunWith(RobolectricTestRunner.class)
25+
@Config(manifest = Config.NONE)
26+
public class FirebaseFirestoreSettingsTest {
27+
28+
@Test
29+
public void builderWithNoModificationsShouldProduceDefaultSettings() {
30+
FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder().build();
31+
assertEquals(settings.getHost(), "firestore.googleapis.com");
32+
assertEquals(settings.isSslEnabled(), true);
33+
assertEquals(settings.isPersistenceEnabled(), true);
34+
assertEquals(settings.getCacheSizeBytes(), 104857600L);
35+
}
36+
37+
@Test
38+
public void builderWithAllValuesCustomizedShouldProduceSettingsWithThoseCustomValues() {
39+
FirebaseFirestoreSettings settings =
40+
new FirebaseFirestoreSettings.Builder()
41+
.setHost("a.b.c")
42+
.setSslEnabled(false)
43+
.setPersistenceEnabled(false)
44+
.setCacheSizeBytes(2000000L)
45+
.build();
46+
assertEquals(settings.getHost(), "a.b.c");
47+
assertEquals(settings.isSslEnabled(), false);
48+
assertEquals(settings.isPersistenceEnabled(), false);
49+
assertEquals(settings.getCacheSizeBytes(), 2000000L);
50+
}
51+
52+
@Test
53+
public void builderConstructorShouldCopyAllValuesFromTheGivenSettings() {
54+
FirebaseFirestoreSettings settings1 =
55+
new FirebaseFirestoreSettings.Builder()
56+
.setHost("a.b.c")
57+
.setSslEnabled(false)
58+
.setPersistenceEnabled(false)
59+
.setCacheSizeBytes(2000000L)
60+
.build();
61+
FirebaseFirestoreSettings settings2 = new FirebaseFirestoreSettings.Builder(settings1).build();
62+
assertEquals(settings2.getHost(), "a.b.c");
63+
assertEquals(settings2.isSslEnabled(), false);
64+
assertEquals(settings2.isPersistenceEnabled(), false);
65+
assertEquals(settings2.getCacheSizeBytes(), 2000000L);
66+
}
67+
}

0 commit comments

Comments
 (0)