1 /* 2 * Copyright (C) 2010 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.example.android.newalarm; 18 19 import android.content.Intent; 20 import android.test.ServiceTestCase; 21 import com.example.android.newalarm.AlarmService; 22 23 /** 24 * Test class for the Alarm sample test package. This test class tests the AlarmService 25 * service component. 26 */ 27 public class AlarmServiceTest extends ServiceTestCase<AlarmService> { 28 // Contains an Intent used to start the service 29 Intent mStartServiceIntent; 30 31 // Contains a handle to the system alarm service 32 AlarmService mService; 33 34 /** 35 * Constructor for the test class. Test classes that are run by InstrumentationTestRunner 36 * must provide a constructor with no arguments that calls the base class constructor as its 37 * first statement. 38 */ 39 public AlarmServiceTest() { 40 super(AlarmService.class); 41 } 42 43 /* 44 * Sets up the test fixture. This method is called before each test 45 */ 46 @Override 47 protected void setUp() throws Exception { 48 49 super.setUp(); 50 51 // Sets up an intent to start the service under test 52 mStartServiceIntent = new Intent(this.getSystemContext(),AlarmService.class); 53 } 54 55 /** 56 * Cleans up the test fixture 57 * Called after each test method. If you override the method, call super.tearDown() as the 58 * last statement in your override. 59 */ 60 @Override 61 protected void tearDown() throws Exception { 62 // Always call the super constructor when overriding tearDown() 63 super.tearDown(); 64 } 65 66 /** 67 * Tests the service's onCreate() method. Starts the service using startService(Intent) 68 */ 69 public void testServiceCreate() { 70 // Starts the service under test 71 this.startService(mStartServiceIntent); 72 73 // Gets a handle to the service under test. 74 mService = this.getService(); 75 76 // Asserts that the Notification Manager was created in the service under test. 77 assertNotNull(mService.mNotificationManager); 78 79 // Asserts that the PendingIntent for the expanded status window was created 80 assertNotNull(mService.mContentIntent); 81 82 // Asserts that the notification was created 83 assertNotNull(mService.mNotification); 84 } 85 86 } 87