Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a0b7c122 authored by Hieu Dang's avatar Hieu Dang Committed by Automerger Merge Worker
Browse files

Merge "Fix BluetoothOppUtilityTest" am: 243af1b3

parents e615d022 243af1b3
Loading
Loading
Loading
Loading
+39 −0
Original line number Original line Diff line number Diff line
@@ -16,15 +16,22 @@


package com.android.bluetooth.opp;
package com.android.bluetooth.opp;


import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
import static android.content.pm.PackageManager.DONT_KILL_APP;

import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doReturn;


import android.content.ComponentName;
import android.content.Context;
import android.database.Cursor;
import android.database.Cursor;


import org.mockito.internal.util.MockUtil;
import org.mockito.internal.util.MockUtil;


import java.util.Arrays;
import java.util.List;
import java.util.List;
import java.util.Objects;
import java.util.Objects;


@@ -106,5 +113,37 @@ public class BluetoothOppTestUtils {
        doReturn(true).when(cursor).moveToPrevious();
        doReturn(true).when(cursor).moveToPrevious();
        doReturn(true).when(cursor).moveToPosition(anyInt());
        doReturn(true).when(cursor).moveToPosition(anyInt());
    }
    }

    /**
     * Enable/Disable all activities in Opp for testing
     *
     * @param enable true to enable, false to disable
     * @param mTargetContext target context
     */
    public static void enableOppActivities(boolean enable, Context mTargetContext) {
        int enabledState = enable ? COMPONENT_ENABLED_STATE_ENABLED
                : COMPONENT_ENABLED_STATE_DEFAULT;

        mTargetContext.getPackageManager().setApplicationEnabledSetting(
                mTargetContext.getPackageName(), enabledState, DONT_KILL_APP);

        // All activities to be test
        Class[] activities = {
                BluetoothOppTransferActivity.class,
                BluetoothOppBtEnableActivity.class,
                BluetoothOppBtEnablingActivity.class,
                BluetoothOppBtErrorActivity.class,
                BluetoothOppIncomingFileConfirmActivity.class,
                BluetoothOppTransferHistory.class,
                BluetoothOppLauncherActivity.class,
        };

        Arrays.stream(activities).forEach(activityClass -> {
            ComponentName activityName = new ComponentName(mTargetContext, activityClass);
            mTargetContext.getPackageManager().setComponentEnabledSetting(
                    activityName, enabledState, DONT_KILL_APP);
        });

    }
}
}
+4 −0
Original line number Original line Diff line number Diff line
@@ -75,10 +75,12 @@ public class BluetoothOppUtilityTest {
        MockitoAnnotations.initMocks(this);
        MockitoAnnotations.initMocks(this);
        mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        BluetoothMethodProxy.setInstanceForTesting(mCallProxy);
        BluetoothMethodProxy.setInstanceForTesting(mCallProxy);
        BluetoothOppTestUtils.enableOppActivities(true, mContext);
    }
    }


    @After
    @After
    public void tearDown() {
    public void tearDown() {
        BluetoothOppTestUtils.enableOppActivities(false, mContext);
        BluetoothMethodProxy.setInstanceForTesting(null);
        BluetoothMethodProxy.setInstanceForTesting(null);
    }
    }


@@ -136,11 +138,13 @@ public class BluetoothOppUtilityTest {


    @Test
    @Test
    public void openReceivedFile_fileNotExist() {
    public void openReceivedFile_fileNotExist() {

        Uri contentResolverUri = Uri.parse("content://com.android.bluetooth.opp/btopp/0123");
        Uri contentResolverUri = Uri.parse("content://com.android.bluetooth.opp/btopp/0123");
        Uri fileUri = Uri.parse("content:///tmp/randomFileName.txt");
        Uri fileUri = Uri.parse("content:///tmp/randomFileName.txt");


        Context spiedContext = spy(new ContextWrapper(mContext));
        Context spiedContext = spy(new ContextWrapper(mContext));


        doReturn(0).when(mCallProxy).contentResolverDelete(any(), any(), any(), any());
        doReturn(mCursor).when(mCallProxy).contentResolverQuery(any(),
        doReturn(mCursor).when(mCallProxy).contentResolverQuery(any(),
                eq(contentResolverUri), any(), eq(null),
                eq(contentResolverUri), any(), eq(null),
                eq(null), eq(null));
                eq(null), eq(null));