blob: c5a1243683d4e7e1db0051696e42bdf1c8142428 [file] [log] [blame]
fionaxua21a87b2016-12-13 17:15:11 -08001/*
2 * Copyright (C) 2016 Google Inc.
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.carrierdefaultapp;
18
19import android.app.Activity;
20import android.content.ComponentName;
21import android.content.Context;
22import android.content.ContextWrapper;
23import android.content.Intent;
24import android.test.ActivityUnitTestCase;
25import android.util.Log;
26
27import org.mockito.MockitoAnnotations;
28
29import java.util.HashMap;
30
31public class CarrierDefaultActivityTestCase<T extends Activity> extends ActivityUnitTestCase<T> {
32
33 protected TestContext mContext;
34
35 private T mActivity;
36
37 CarrierDefaultActivityTestCase(Class<T> activityClass) {
38 super(activityClass);
39 }
40
41 @Override
42 protected void setUp() throws Exception {
43 super.setUp();
44 MockitoAnnotations.initMocks(this);
45 mContext = new TestContext(getInstrumentation().getTargetContext());
46 setActivityContext(mContext);
47 }
48
49 @Override
50 protected void tearDown() throws Exception {
51 super.tearDown();
52 }
53
54 protected T startActivity() throws Throwable {
55 runTestOnUiThread(new Runnable() {
56 @Override
57 public void run() {
58 mActivity = startActivity(createActivityIntent(), null, null);
59 }
60 });
61 return mActivity;
62 }
63
64 protected void stopActivity() throws Exception {
65 getInstrumentation().callActivityOnStop(mActivity);
66 }
67
68 protected Intent createActivityIntent() {
69 Intent intent = new Intent();
70 return intent;
71 }
72
73 protected <S> void injectSystemService(Class<S> cls, S service) {
74 mContext.injectSystemService(cls, service);
75 }
76}