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 package com.android.externalstorage;
18 
19 import static com.android.externalstorage.ExternalStorageProvider.AUTHORITY;
20 
21 import static org.mockito.Mockito.atLeast;
22 import static org.mockito.Mockito.spy;
23 import static org.mockito.Mockito.verify;
24 
25 import android.content.pm.ProviderInfo;
26 
27 import androidx.test.InstrumentationRegistry;
28 import androidx.test.runner.AndroidJUnit4;
29 
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 
33 @RunWith(AndroidJUnit4.class)
34 public class ExternalStorageProviderTest {
35     @Test
onCreate_shouldUpdateVolumes()36     public void onCreate_shouldUpdateVolumes() throws Exception {
37         ExternalStorageProvider externalStorageProvider = new ExternalStorageProvider();
38         ExternalStorageProvider spyProvider = spy(externalStorageProvider);
39         ProviderInfo providerInfo = new ProviderInfo();
40         providerInfo.authority = AUTHORITY;
41         providerInfo.grantUriPermissions = true;
42         providerInfo.exported = true;
43 
44         InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
45             @Override
46             public void run() {
47                 spyProvider.attachInfoForTesting(
48                         InstrumentationRegistry.getTargetContext(), providerInfo);
49             }
50         });
51 
52         verify(spyProvider, atLeast(1)).updateVolumes();
53     }
54 }
55