import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
-import androidx.slice.SliceItem;
import androidx.slice.SliceMetadata;
import androidx.slice.SliceProvider;
import androidx.slice.core.SliceAction;
import androidx.slice.widget.SliceLiveData;
import com.android.settings.R;
-import com.android.settings.testutils.SliceTester;
import org.junit.Before;
import org.junit.Test;
@Test
public void getBluetoothSlice_correctSliceContent() {
final Slice BluetoothSlice = BluetoothSliceBuilder.getSlice(mContext);
+
final SliceMetadata metadata = SliceMetadata.from(mContext, BluetoothSlice);
+ assertThat(metadata.getTitle()).isEqualTo(
+ mContext.getString(R.string.bluetooth_settings_title));
final List<SliceAction> toggles = metadata.getToggles();
assertThat(toggles).hasSize(1);
final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext,
R.drawable.ic_settings_bluetooth);
assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedToggleIcon.toString());
-
- final List<SliceItem> sliceItems = BluetoothSlice.getItems();
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.bluetooth_settings_title));
}
@Test
import android.provider.Settings;
import androidx.slice.Slice;
-import androidx.slice.SliceItem;
import androidx.slice.SliceMetadata;
import androidx.slice.SliceProvider;
import androidx.slice.core.SliceAction;
import androidx.slice.widget.SliceLiveData;
import com.android.settings.R;
-import com.android.settings.testutils.SliceTester;
import org.junit.Before;
import org.junit.Test;
public void getFlashlightSlice_correctData() {
Settings.Secure.putInt(
mContext.getContentResolver(), Settings.Secure.FLASHLIGHT_AVAILABLE, 1);
+
final Slice slice = new FlashlightSlice(mContext).getSlice();
+
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
+ assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.power_flashlight));
final List<SliceAction> toggles = metadata.getToggles();
assertThat(toggles).hasSize(1);
-
- final List<SliceItem> sliceItems = slice.getItems();
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.power_flashlight));
}
}
import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
-import androidx.slice.SliceItem;
import androidx.slice.SliceMetadata;
import androidx.slice.SliceProvider;
import androidx.slice.core.SliceAction;
import androidx.slice.widget.SliceLiveData;
import com.android.settings.R;
-import com.android.settings.testutils.SliceTester;
import org.junit.Before;
import org.junit.Test;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
-import java.util.List;
-
@RunWith(RobolectricTestRunner.class)
public class BatterySliceTest {
doNothing().when(mBatterySlice).loadBatteryInfo();
doReturn("10%").when(mBatterySlice).getBatteryPercentString();
doReturn("test").when(mBatterySlice).getSummary();
+
final Slice slice = mBatterySlice.getSlice();
+
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
+ assertThat(metadata.getTitle()).isEqualTo(
+ mContext.getString(R.string.power_usage_summary_title));
+
final SliceAction primaryAction = metadata.getPrimaryAction();
final IconCompat expectedIcon = IconCompat.createWithResource(mContext,
R.drawable.ic_settings_battery);
assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedIcon.toString());
-
- final List<SliceItem> sliceItems = slice.getItems();
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.power_usage_summary_title));
}
}
ShadowDataUsageUtils.HAS_SIM = true;
doReturn(DATA_USAGE_TITLE).when(mDataUsageSlice).getDataUsageText(any());
doReturn(DATA_USAGE_SUMMARY).when(mDataUsageSlice).getCycleTime(any());
+
final Slice slice = mDataUsageSlice.getSlice();
+
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
+ assertThat(metadata.getTitle()).isEqualTo(
+ mContext.getString(R.string.data_usage_summary_title));
+
final SliceAction primaryAction = metadata.getPrimaryAction();
final IconCompat expectedIcon = IconCompat.createWithResource(mContext,
R.drawable.ic_settings_data_usage);
assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedIcon.toString());
-
- final List<SliceItem> sliceItems = slice.getItems();
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.data_usage_summary_title));
}
@Test
public void getSlice_hasNoSim_shouldShowNoSimCard() {
ShadowDataUsageUtils.HAS_SIM = false;
+
final Slice slice = mDataUsageSlice.getSlice();
- final List<SliceItem> sliceItems = slice.getItems();
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.data_usage_summary_title));
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.no_sim_card));
+ final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
+ assertThat(metadata.getTitle()).isEqualTo(
+ mContext.getString(R.string.data_usage_summary_title));
+
+ final List<SliceItem> sliceItems = slice.getItems();
+ SliceTester.assertAnySliceItemContainsTitle(sliceItems,
+ mContext.getString(R.string.no_sim_card));
}
}
final String phoneNumber = "1111111111";
doReturn(mSubscriptionInfo).when(mDeviceInfoSlice).getFirstSubscriptionInfo();
doReturn(phoneNumber).when(mDeviceInfoSlice).getPhoneNumber();
+
final Slice slice = mDeviceInfoSlice.getSlice();
+
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
+ assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.device_info_label));
+
final SliceAction primaryAction = metadata.getPrimaryAction();
final IconCompat expectedIcon = IconCompat.createWithResource(mContext,
R.drawable.ic_info_outline_24dp);
assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedIcon.toString());
final List<SliceItem> sliceItems = slice.getItems();
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.device_info_label));
- SliceTester.assertTitle(sliceItems, phoneNumber);
+ SliceTester.assertAnySliceItemContainsTitle(sliceItems, phoneNumber);
}
@Test
public void getSlice_hasNoSubscriptionInfo_shouldShowUnknown() {
final Slice slice = mDeviceInfoSlice.getSlice();
- final List<SliceItem> sliceItems = slice.getItems();
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.device_info_label));
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.device_info_default));
+ final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
+ assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.device_info_label));
+
+ final List<SliceItem> sliceItems = slice.getItems();
+ SliceTester.assertAnySliceItemContainsTitle(sliceItems,
+ mContext.getString(R.string.device_info_default));
}
}
import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
-import androidx.slice.SliceItem;
import androidx.slice.SliceMetadata;
import androidx.slice.SliceProvider;
import androidx.slice.core.SliceAction;
import androidx.slice.widget.SliceLiveData;
import com.android.settings.R;
-import com.android.settings.testutils.SliceTester;
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
import org.junit.Before;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
-import java.util.List;
-
@RunWith(RobolectricTestRunner.class)
public class StorageSliceTest {
private static final String USED_BYTES_TEXT = "test used bytes";
doReturn(info).when(mStorageSlice).getPrivateStorageInfo();
doReturn(USED_BYTES_TEXT).when(mStorageSlice).getStorageUsedText(any());
doReturn(SUMMARY_TEXT).when(mStorageSlice).getStorageSummaryText(any());
+
final Slice slice = mStorageSlice.getSlice();
+
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
+ assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.storage_label));
+
final SliceAction primaryAction = metadata.getPrimaryAction();
final IconCompat expectedIcon = IconCompat.createWithResource(mContext,
R.drawable.ic_homepage_storage);
assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedIcon.toString());
-
- final List<SliceItem> sliceItems = slice.getItems();
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.storage_label));
}
}
final Slice slice = mBluetoothDevicesSlice.getSlice();
- final List<SliceItem> sliceItems = slice.getItems();
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.bluetooth_devices));
+ final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
+ assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.bluetooth_devices));
}
@Test
final Slice slice = mBluetoothDevicesSlice.getSlice();
final List<SliceItem> sliceItems = slice.getItems();
- SliceTester.assertTitle(sliceItems, BLUETOOTH_MOCK_TITLE);
+ SliceTester.assertAnySliceItemContainsTitle(sliceItems, BLUETOOTH_MOCK_TITLE);
}
@Test
final Slice slice = mBluetoothDevicesSlice.getSlice();
final List<SliceItem> sliceItems = slice.getItems();
- SliceTester.assertTitle(sliceItems,
+ SliceTester.assertAnySliceItemContainsTitle(sliceItems,
mContext.getString(R.string.bluetooth_pairing_pref_title));
}
final Slice slice = mBluetoothDevicesSlice.getSlice();
- final List<SliceItem> sliceItems = slice.getItems();
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.no_bluetooth_devices));
+ final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
+ assertThat(metadata.getTitle()).isEqualTo(
+ mContext.getString(R.string.no_bluetooth_devices));
}
@Test
import android.content.Context;
import androidx.slice.Slice;
-import androidx.slice.SliceItem;
+import androidx.slice.SliceMetadata;
import androidx.slice.SliceProvider;
import androidx.slice.widget.SliceLiveData;
import com.android.settings.R;
-import com.android.settings.testutils.SliceTester;
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
-import java.util.List;
-
@RunWith(RobolectricTestRunner.class)
public class LowStorageSliceTest {
final Slice slice = mLowStorageSlice.getSlice();
- final List<SliceItem> sliceItems = slice.getItems();
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.storage_menu_free));
+ final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
+ assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.storage_menu_free));
}
@Test
final Slice slice = mLowStorageSlice.getSlice();
- final List<SliceItem> sliceItems = slice.getItems();
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.storage_settings));
+ final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
+ assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.storage_settings));
}
@Test
import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
-import androidx.slice.SliceItem;
import androidx.slice.SliceMetadata;
import androidx.slice.SliceProvider;
import androidx.slice.core.SliceAction;
import androidx.slice.widget.SliceLiveData;
import com.android.settings.R;
-import com.android.settings.testutils.SliceTester;
import org.junit.Before;
import org.junit.Test;
@Test
public void getLocationSlice_correctSliceContent() {
final Slice LocationSlice = new LocationSlice(mContext).getSlice();
+
final SliceMetadata metadata = SliceMetadata.from(mContext, LocationSlice);
+ assertThat(metadata.getTitle()).isEqualTo(
+ mContext.getString(R.string.location_settings_title));
final List<SliceAction> toggles = metadata.getToggles();
assertThat(toggles).isEmpty();
final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext,
R.drawable.ic_signal_location);
assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedToggleIcon.toString());
-
- final List<SliceItem> sliceItems = LocationSlice.getItems();
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.location_settings_title));
}
}
import android.provider.Settings;
import androidx.slice.Slice;
-import androidx.slice.SliceItem;
import androidx.slice.SliceMetadata;
import androidx.slice.SliceProvider;
import androidx.slice.core.SliceAction;
import androidx.slice.widget.SliceLiveData;
import com.android.settings.R;
-import com.android.settings.testutils.SliceTester;
import com.android.settings.testutils.shadow.ShadowNotificationManager;
import org.junit.Before;
@Test
public void getZenModeSlice_correctSliceContent() {
final Slice dndSlice = ZenModeSliceBuilder.getSlice(mContext);
+
final SliceMetadata metadata = SliceMetadata.from(mContext, dndSlice);
+ assertThat(metadata.getTitle()).isEqualTo(
+ mContext.getString(R.string.zen_mode_settings_title));
final List<SliceAction> toggles = metadata.getToggles();
assertThat(toggles).hasSize(1);
final SliceAction primaryAction = metadata.getPrimaryAction();
assertThat(primaryAction.getIcon()).isNull();
-
- final List<SliceItem> sliceItems = dndSlice.getItems();
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.zen_mode_settings_title));
}
@Test
assertThat(primaryPendingIntent).isEqualTo(
SliceBuilderUtils.getContentPendingIntent(context, sliceData));
- final List<SliceItem> sliceItems = slice.getItems();
- assertTitle(sliceItems, sliceData.getTitle());
+ assertThat(metadata.getTitle()).isEqualTo(sliceData.getTitle());
assertKeywords(metadata, sliceData);
}
assertThat(primaryPendingIntent).isEqualTo(
SliceBuilderUtils.getContentPendingIntent(context, sliceData));
- final List<SliceItem> sliceItems = slice.getItems();
- assertTitle(sliceItems, sliceData.getTitle());
+ assertThat(metadata.getTitle()).isEqualTo(sliceData.getTitle());
assertKeywords(metadata, sliceData);
}
assertThat(primaryPendingIntent).isEqualTo(
SliceBuilderUtils.getContentPendingIntent(context, sliceData));
- final List<SliceItem> sliceItems = slice.getItems();
- assertTitle(sliceItems, sliceData.getTitle());
+ assertThat(metadata.getTitle()).isEqualTo(sliceData.getTitle());
assertKeywords(metadata, sliceData);
}
assertThat(primaryPendingIntent).isEqualTo(
SliceBuilderUtils.getContentPendingIntent(context, sliceData));
- final List<SliceItem> sliceItems = slice.getItems();
- assertTitle(sliceItems, sliceData.getTitle());
+ assertThat(metadata.getTitle()).isEqualTo(sliceData.getTitle());
assertKeywords(metadata, sliceData);
}
assertThat(primaryPendingIntent).isEqualTo(SliceBuilderUtils.getContentPendingIntent(
context, sliceData));
- final List<SliceItem> sliceItems = slice.getItems();
- assertTitle(sliceItems, sliceData.getTitle());
+ assertThat(metadata.getTitle()).isEqualTo(sliceData.getTitle());
assertKeywords(metadata, sliceData);
}
- // TODO(b/120592507): Clean up method of SliceTester
- public static void assertTitle(List<SliceItem> sliceItems, String title) {
+ /**
+ * Assert any slice item contains title.
+ *
+ * @param sliceItems All slice items of a Slice.
+ * @param title Title for asserting.
+ */
+ public static void assertAnySliceItemContainsTitle(List<SliceItem> sliceItems, String title) {
boolean hasTitle = false;
for (SliceItem item : sliceItems) {
List<SliceItem> titleItems = SliceQuery.findAll(item, FORMAT_TEXT, HINT_TITLE,
assertThat(hasTitle).isTrue();
}
- // TODO(b/120592507): Clean up method of SliceTester
private static void assertKeywords(SliceMetadata metadata, SliceData data) {
final List<String> keywords = metadata.getSliceKeywords();
final Set<String> expectedKeywords = Arrays.stream(data.getKeywords().split(","))
expectedKeywords.add(data.getScreenTitle().toString());
assertThat(keywords).containsExactlyElementsIn(expectedKeywords);
}
-}
+}
\ No newline at end of file
import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
-import androidx.slice.SliceItem;
import androidx.slice.SliceMetadata;
import androidx.slice.SliceProvider;
import androidx.slice.core.SliceAction;
import androidx.slice.widget.SliceLiveData;
import com.android.settings.R;
-import com.android.settings.testutils.SliceTester;
import org.junit.Before;
import org.junit.Test;
mWifiManager.connect(config, null /* listener */);
final Slice wifiSlice = mWifiSlice.getSlice();
+
final SliceMetadata metadata = SliceMetadata.from(mContext, wifiSlice);
+ assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.wifi_settings));
final List<SliceAction> toggles = metadata.getToggles();
assertThat(toggles).hasSize(1);
final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext,
R.drawable.ic_settings_wireless);
assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedToggleIcon.toString());
-
- final List<SliceItem> sliceItems = wifiSlice.getItems();
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.wifi_settings));
}
}
@Test
public void getWifiSlice_shouldHaveTitleAndToggle() {
final Slice wifiSlice = mWifiSlice.getSlice();
+
final SliceMetadata metadata = SliceMetadata.from(mContext, wifiSlice);
+ assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.wifi_settings));
final List<SliceAction> toggles = metadata.getToggles();
assertThat(toggles).hasSize(1);
final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext,
R.drawable.ic_settings_wireless);
assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedToggleIcon.toString());
-
- final List<SliceItem> sliceItems = wifiSlice.getItems();
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.wifi_settings));
}
@Test
// All AP rows + title row
assertThat(rows).isEqualTo(DEFAULT_EXPANDED_ROW_COUNT + 1);
// Has scanning text
- SliceTester.assertTitle(sliceItems, mContext.getString(R.string.wifi_empty_list_wifi_on));
+ SliceTester.assertAnySliceItemContainsTitle(sliceItems,
+ mContext.getString(R.string.wifi_empty_list_wifi_on));
}
@Test