• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
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 package com.google.android.libraries.mobiledatadownload.populator;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 
20 import com.google.mobiledatadownload.DownloadConfigProto.ManifestConfig;
21 import java.util.Locale;
22 import java.util.concurrent.ExecutionException;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.robolectric.RobolectricTestRunner;
27 
28 /** Tests for {@link MigrationProxyLocaleOverrider}. */
29 @RunWith(RobolectricTestRunner.class)
30 public class MigrationProxyLocaleOverriderTest {
31 
32   private LocaleOverrider localeOverrider;
33   private ManifestConfig manifestConfig;
34 
35   @Before
setUp()36   public void setUp() {
37     manifestConfig =
38         ManifestConfig.newBuilder()
39             .addEntry(
40                 ManifestConfig.Entry.newBuilder()
41                     .setModifier(
42                         ManifestConfig.Entry.Modifier.newBuilder().addLocale("en-US").build())
43                     .build())
44             .build();
45     localeOverrider =
46         LocaleOverrider.builder().setLocaleSupplier(() -> Locale.forLanguageTag("en-US")).build();
47   }
48 
49   @Test
override_whenFlagReturnsFalse_returnsNothing()50   public void override_whenFlagReturnsFalse_returnsNothing()
51       throws InterruptedException, ExecutionException {
52     MigrationProxyLocaleOverrider migrationProxyLocaleOverrider =
53         new MigrationProxyLocaleOverrider(localeOverrider, () -> false);
54     assertThat(migrationProxyLocaleOverrider.override(manifestConfig).get()).isEmpty();
55   }
56 
57   @Test
override_whenFlagReturnsTrue_usesLocaleOverrider()58   public void override_whenFlagReturnsTrue_usesLocaleOverrider()
59       throws InterruptedException, ExecutionException {
60     MigrationProxyLocaleOverrider migrationProxyLocaleOverrider =
61         new MigrationProxyLocaleOverrider(localeOverrider, () -> true);
62     assertThat(migrationProxyLocaleOverrider.override(manifestConfig).get()).hasSize(1);
63   }
64 }
65