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

Commit 3cc40f4e authored by My Name's avatar My Name Committed by Hyundo Moon
Browse files

Fix BluetoothOppManagerTest

The URI that is used for test is only valid in the local test device.
Therefore the test passed locally even without mocking contentResolverInsert(). However, it should fail since there is no content for the URI in other devices.

This CL fixes the bug by making the contentResolverInsert() do nothing.

Bug: 260183711
Tag: #refactor
Test: atest BluetoothOppManagerTest
Change-Id: I0ba90c1236cd846db4fbf2abb233a9b679274657
parent e0f9ad4e
Loading
Loading
Loading
Loading
+8 −3
Original line number Original line Diff line number Diff line
@@ -20,7 +20,9 @@ import static com.android.bluetooth.opp.BluetoothOppManager.OPP_PREFERENCE_FILE;


import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertThat;


import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.nullable;
import static org.mockito.Mockito.nullable;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.timeout;
@@ -43,7 +45,6 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
@@ -51,8 +52,8 @@ import java.util.List;
@RunWith(AndroidJUnit4.class)
@RunWith(AndroidJUnit4.class)
public class BluetoothOppManagerTest {
public class BluetoothOppManagerTest {
    Context mContext;
    Context mContext;
    @Spy

    BluetoothMethodProxy mCallProxy = BluetoothMethodProxy.getInstance();
    BluetoothMethodProxy mCallProxy;


    @Before
    @Before
    public void setUp() {
    public void setUp() {
@@ -60,7 +61,11 @@ public class BluetoothOppManagerTest {
        mContext = spy(new ContextWrapper(
        mContext = spy(new ContextWrapper(
                InstrumentationRegistry.getInstrumentation().getTargetContext()));
                InstrumentationRegistry.getInstrumentation().getTargetContext()));


        mCallProxy = spy(BluetoothMethodProxy.getInstance());
        BluetoothMethodProxy.setInstanceForTesting(mCallProxy);
        BluetoothMethodProxy.setInstanceForTesting(mCallProxy);

        doReturn(null).when(mCallProxy).contentResolverInsert(
                any(), eq(BluetoothShare.CONTENT_URI), any());
    }
    }


    @After
    @After