1 /* 2 * Copyright (C) 2018 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 18 package com.android.settings.slices; 19 20 import static org.mockito.ArgumentMatchers.any; 21 import static org.mockito.ArgumentMatchers.eq; 22 import static org.mockito.Mockito.doReturn; 23 import static org.mockito.Mockito.spy; 24 import static org.mockito.Mockito.verify; 25 26 import android.content.ContentResolver; 27 import android.content.Context; 28 29 import android.content.Intent; 30 import android.net.Uri; 31 import android.provider.SettingsSlicesContract; 32 import com.android.settings.testutils.SettingsRobolectricTestRunner; 33 import com.android.settingslib.SliceBroadcastRelay; 34 import org.junit.Before; 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 import org.robolectric.RuntimeEnvironment; 38 39 @RunWith(SettingsRobolectricTestRunner.class) 40 public class SliceRelayReceiverTest { 41 42 private Context mContext; 43 private SliceRelayReceiver mSliceRelayReceiver; 44 45 @Before setUp()46 public void setUp() { 47 mContext = spy(RuntimeEnvironment.application); 48 mSliceRelayReceiver = new SliceRelayReceiver(); 49 } 50 51 52 @Test onReceive_extraUri_notifiesChangeOnUri()53 public void onReceive_extraUri_notifiesChangeOnUri() { 54 // Monitor the ContentResolver 55 final ContentResolver resolver = spy(mContext.getContentResolver()); 56 doReturn(resolver).when(mContext).getContentResolver(); 57 58 final Uri uri = new Uri.Builder() 59 .scheme(ContentResolver.SCHEME_CONTENT) 60 .authority(SettingsSlicesContract.AUTHORITY) 61 .appendPath("path") 62 .build(); 63 64 final Intent intent = new Intent(); 65 intent.putExtra(SliceBroadcastRelay.EXTRA_URI, uri.toString()); 66 67 mSliceRelayReceiver.onReceive(mContext, intent); 68 69 verify(resolver).notifyChange(eq(uri), any()); 70 71 } 72 } 73