1 /* 2 * Copyright (C) 2016 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.dashboard; 18 19 import android.app.Activity; 20 import com.android.settings.SettingsRobolectricTestRunner; 21 import com.android.settings.TestConfig; 22 import com.android.settingslib.drawer.DashboardCategory; 23 import com.android.settingslib.drawer.Tile; 24 import org.junit.Before; 25 import org.junit.Test; 26 import org.junit.runner.RunWith; 27 import org.robolectric.Robolectric; 28 import org.robolectric.annotation.Config; 29 30 import java.util.ArrayList; 31 import java.util.List; 32 33 import static com.google.common.truth.Truth.assertThat; 34 35 @RunWith(SettingsRobolectricTestRunner.class) 36 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) 37 public class SummaryLoaderTest { 38 private static final String SUMMARY_1 = "summary1"; 39 private static final String SUMMARY_2 = "summary2"; 40 private SummaryLoader mSummaryLoader; 41 private boolean mCallbackInvoked; 42 private Tile mTile; 43 44 @Before SetUp()45 public void SetUp() { 46 mTile = new Tile(); 47 mTile.summary = SUMMARY_1; 48 mCallbackInvoked = false; 49 50 final Activity activity = Robolectric.buildActivity(Activity.class).get(); 51 final List<DashboardCategory> categories = new ArrayList<>(); 52 mSummaryLoader = new SummaryLoader(activity, categories); 53 mSummaryLoader.setSummaryConsumer(new SummaryLoader.SummaryConsumer() { 54 @Override 55 public void notifySummaryChanged(Tile tile) { 56 mCallbackInvoked = true; 57 } 58 }); 59 } 60 61 @Test testUpdateSummaryIfNeeded_SummaryIdentical_NoCallback()62 public void testUpdateSummaryIfNeeded_SummaryIdentical_NoCallback() { 63 mSummaryLoader.updateSummaryIfNeeded(mTile, SUMMARY_1); 64 65 assertThat(mCallbackInvoked).isFalse(); 66 } 67 68 @Test testUpdateSummaryIfNeeded_SummaryChanged_HasCallback()69 public void testUpdateSummaryIfNeeded_SummaryChanged_HasCallback() { 70 mSummaryLoader.updateSummaryIfNeeded(mTile, SUMMARY_2); 71 72 assertThat(mCallbackInvoked).isTrue(); 73 } 74 } 75