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