1 /** 2 * Copyright (C) 2016 The Android Open Source Project 3 * <p> 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 * <p> 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * <p> 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.cellbroadcastreceiver; 18 19 import android.app.Service; 20 import android.content.ComponentName; 21 import android.content.Context; 22 import android.content.ContextWrapper; 23 import android.content.Intent; 24 import android.test.ServiceTestCase; 25 26 import org.junit.Before; 27 import org.mockito.MockitoAnnotations; 28 29 public abstract class CellBroadcastServiceTestCase<T extends Service> extends ServiceTestCase<T> { 30 31 Intent mServiceIntentToVerify; 32 33 Intent mActivityIntentToVerify; 34 35 CellBroadcastServiceTestCase(Class<T> serviceClass) { 36 super(serviceClass); 37 } 38 39 protected static void waitForMs(long ms) { 40 try { 41 Thread.sleep(ms); 42 } catch (InterruptedException e) { 43 } 44 } 45 46 private class TestContextWrapper extends ContextWrapper { 47 public TestContextWrapper(Context base) { 48 super(base); 49 } 50 51 @Override 52 public ComponentName startService(Intent service) { 53 mServiceIntentToVerify = service; 54 return null; 55 } 56 57 @Override 58 public void startActivity(Intent intent) { 59 mActivityIntentToVerify = intent; 60 } 61 } 62 63 @Before 64 public void setUp() throws Exception { 65 MockitoAnnotations.initMocks(this); 66 mContext = new TestContextWrapper(getContext()); 67 setContext(mContext); 68 } 69 } 70 71