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.settings.accessibility; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.content.ComponentName; 22 23 import androidx.test.ext.junit.runners.AndroidJUnit4; 24 25 import org.junit.Test; 26 import org.junit.runner.RunWith; 27 28 /** Tests for {@link PreferredShortcut} */ 29 @RunWith(AndroidJUnit4.class) 30 public class PreferredShortcutTest { 31 32 private static final String STUB_COMPONENT_NAME = new ComponentName("com.example", 33 "com.example.testActivity").flattenToString(); 34 private static final int STUB_TYPE = 3; 35 36 @Test fromString_matchMemberObject()37 public void fromString_matchMemberObject() { 38 final String preferredShortcutString = STUB_COMPONENT_NAME + ":" + STUB_TYPE; 39 40 final PreferredShortcut shortcut = PreferredShortcut.fromString(preferredShortcutString); 41 42 assertThat(shortcut.getComponentName()).isEqualTo(STUB_COMPONENT_NAME); 43 assertThat(shortcut.getType()).isEqualTo(STUB_TYPE); 44 } 45 46 @Test toString_matchString()47 public void toString_matchString() { 48 final PreferredShortcut shortcut = new PreferredShortcut(STUB_COMPONENT_NAME, STUB_TYPE); 49 50 final String preferredShortcutString = shortcut.toString(); 51 52 assertThat(preferredShortcutString).isEqualTo(STUB_COMPONENT_NAME + ":" + STUB_TYPE); 53 } 54 55 @Test assertSameObject()56 public void assertSameObject() { 57 final String preferredShortcutString = STUB_COMPONENT_NAME + ":" + STUB_TYPE; 58 final PreferredShortcut targetShortcut = PreferredShortcut.fromString( 59 preferredShortcutString); 60 61 assertThat(targetShortcut).isEqualTo(new PreferredShortcut(STUB_COMPONENT_NAME, STUB_TYPE)); 62 } 63 } 64