|
| 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