1 /* 2 * Copyright (C) 2017 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.settings.datausage; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.content.Context; 22 import android.support.v7.preference.Preference; 23 import android.support.v7.preference.PreferenceViewHolder; 24 import android.view.LayoutInflater; 25 import android.view.View; 26 import android.widget.LinearLayout; 27 import android.widget.TextView; 28 import com.android.settings.R; 29 import com.android.settings.TestConfig; 30 import com.android.settings.testutils.SettingsRobolectricTestRunner; 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 import org.robolectric.RuntimeEnvironment; 35 import org.robolectric.annotation.Config; 36 37 @RunWith(SettingsRobolectricTestRunner.class) 38 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) 39 public final class DataPlansSyncTimePreferenceTest { 40 private static final String SYNC_TIME = "Today 12:24pm"; 41 42 private Preference mPreference; 43 private PreferenceViewHolder mHolder; 44 45 @Before setUp()46 public void setUp() { 47 Context context = RuntimeEnvironment.application; 48 mPreference = new Preference(context); 49 mPreference.setLayoutResource(R.layout.data_plans_sync_time_preference); 50 51 LayoutInflater inflater = LayoutInflater.from(context); 52 View view = inflater.inflate(mPreference.getLayoutResource(), 53 new LinearLayout(context), false); 54 mHolder = PreferenceViewHolder.createInstanceForTests(view); 55 } 56 57 @Test shouldRender_withData()58 public void shouldRender_withData() { 59 mPreference.setTitle(SYNC_TIME); 60 61 mPreference.onBindViewHolder(mHolder); 62 63 TextView syncTimeTextView = (TextView) mHolder.findViewById(android.R.id.title); 64 assertThat(syncTimeTextView.getText()).isEqualTo(SYNC_TIME); 65 } 66 } 67