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 android.service.settings.suggestions; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.content.Intent; 22 import android.os.IBinder; 23 import android.os.RemoteException; 24 import android.support.test.InstrumentationRegistry; 25 import android.support.test.filters.SmallTest; 26 import android.support.test.rule.ServiceTestRule; 27 import android.support.test.runner.AndroidJUnit4; 28 29 import org.junit.After; 30 import org.junit.Before; 31 import org.junit.Rule; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 35 import java.util.concurrent.TimeoutException; 36 37 @RunWith(AndroidJUnit4.class) 38 @SmallTest 39 public class SuggestionServiceTest { 40 41 @Rule 42 public ServiceTestRule mServiceTestRule; 43 private Intent mMockServiceIntent; 44 45 @Before 46 public void setUp() { 47 mServiceTestRule = new ServiceTestRule(); 48 mMockServiceIntent = new Intent( 49 InstrumentationRegistry.getTargetContext(), 50 MockSuggestionService.class); 51 } 52 53 @After 54 public void tearUp() { 55 MockSuggestionService.reset(); 56 } 57 58 @Test 59 public void canStartService() throws TimeoutException { 60 mServiceTestRule.startService(mMockServiceIntent); 61 // Do nothing after starting service. 62 } 63 64 @Test 65 public void dismissSuggestion_shouldCallImplementation() 66 throws TimeoutException, RemoteException { 67 MockSuggestionService service = new MockSuggestionService(); 68 IBinder binder = mServiceTestRule.bindService(mMockServiceIntent); 69 ISuggestionService serviceBinder = ISuggestionService.Stub.asInterface(binder); 70 serviceBinder.dismissSuggestion(null); 71 72 assertThat(service.sOnSuggestionDismissedCalled).isTrue(); 73 } 74 75 @Test 76 public void launchSuggestion_shouldCallImplementation() 77 throws TimeoutException, RemoteException { 78 MockSuggestionService service = new MockSuggestionService(); 79 IBinder binder = mServiceTestRule.bindService(mMockServiceIntent); 80 ISuggestionService serviceBinder = ISuggestionService.Stub.asInterface(binder); 81 serviceBinder.launchSuggestion(null); 82 83 assertThat(service.sOnSuggestionLaunchedCalled).isTrue(); 84 } 85 } 86