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 17package com.android.settings; 18 19 20import android.content.Intent; 21 22import com.android.settings.testutils.SettingsRobolectricTestRunner; 23import com.android.settings.testutils.shadow.ShadowHelpUtils; 24 25import org.junit.After; 26import org.junit.Test; 27import org.junit.runner.RunWith; 28import org.robolectric.Robolectric; 29import org.robolectric.RuntimeEnvironment; 30import org.robolectric.annotation.Config; 31import org.robolectric.shadows.ShadowActivity; 32 33import static com.google.common.truth.Truth.assertThat; 34import static org.robolectric.Shadows.shadowOf; 35 36@RunWith(SettingsRobolectricTestRunner.class) 37@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, 38 shadows = { 39 ShadowHelpUtils.class 40 }) 41public class HelpTrampolineTest { 42 43 @After 44 public void tearDown() { 45 ShadowHelpUtils.reset(); 46 } 47 48 @Test 49 public void launchHelp_noExtra_shouldDoNothing() { 50 final Intent intent = new Intent().setClassName( 51 RuntimeEnvironment.application.getPackageName(), HelpTrampoline.class.getName()); 52 53 Robolectric.buildActivity(HelpTrampoline.class).withIntent(intent).create().get(); 54 55 assertThat(ShadowHelpUtils.isGetHelpIntentCalled()).isFalse(); 56 } 57 58 @Test 59 public void launchHelp_hasExtra_shouldLaunchHelp() { 60 final Intent intent = new Intent().setClassName( 61 RuntimeEnvironment.application.getPackageName(), HelpTrampoline.class.getName()) 62 .putExtra(Intent.EXTRA_TEXT, "help_url_upgrading"); 63 final ShadowActivity shadow = shadowOf(Robolectric.buildActivity(HelpTrampoline.class) 64 .withIntent(intent).create().get()); 65 final Intent launchedIntent = shadow.getNextStartedActivity(); 66 67 assertThat(ShadowHelpUtils.isGetHelpIntentCalled()).isTrue(); 68 assertThat(launchedIntent).isNotNull(); 69 } 70} 71