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