1 /*
2  * Copyright (C) 2020 The Android Open Source Project
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 com.android.deskclock.uidata;
18 
19 import android.content.Context;
20 import android.preference.PreferenceManager;
21 
22 import androidx.test.core.app.ApplicationProvider;
23 import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner;
24 
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 
28 import java.util.Locale;
29 
30 import static com.android.deskclock.uidata.UiDataModel.Tab.ALARMS;
31 import static com.android.deskclock.uidata.UiDataModel.Tab.CLOCKS;
32 import static com.android.deskclock.uidata.UiDataModel.Tab.STOPWATCH;
33 import static com.android.deskclock.uidata.UiDataModel.Tab.TIMERS;
34 
35 import static org.junit.Assert.assertSame;
36 
37 @RunWith(AndroidJUnit4ClassRunner.class)
38 public class TabModelTest {
39 
40     private Locale defaultLocale;
41     private TabModel tabModel;
42 
43     @Test
ltrTabLayoutIndex()44     public void ltrTabLayoutIndex() {
45         setUpTabModel(new Locale("en", "US"));
46         assertSame(ALARMS, tabModel.getTabAt(0));
47         assertSame(CLOCKS, tabModel.getTabAt(1));
48         assertSame(TIMERS, tabModel.getTabAt(2));
49         assertSame(STOPWATCH, tabModel.getTabAt(3));
50         Locale.setDefault(defaultLocale);
51     }
52 
53     @Test
rtlTabLayoutIndex()54     public void rtlTabLayoutIndex() {
55         setUpTabModel(new Locale("ar", "EG"));
56         assertSame(STOPWATCH, tabModel.getTabAt(0));
57         assertSame(TIMERS, tabModel.getTabAt(1));
58         assertSame(CLOCKS, tabModel.getTabAt(2));
59         assertSame(ALARMS, tabModel.getTabAt(3));
60         Locale.setDefault(defaultLocale);
61     }
62 
setUpTabModel(Locale testLocale)63     private void setUpTabModel(Locale testLocale) {
64         defaultLocale = Locale.getDefault();
65         Locale.setDefault(testLocale);
66         final Context context = ApplicationProvider.getApplicationContext();
67         tabModel = new TabModel(PreferenceManager.getDefaultSharedPreferences(context));
68     }
69 }
70