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

Commit 6d4a18be authored by William Escande's avatar William Escande
Browse files

Setup Looper for OppServiceTest

Bug: 327696134
Fix: 327696134
Bug: 332042380
Test: atest BluetoothOppServiceTest
Flag: Exempt, test only
Change-Id: Iaf184ba2f534bda77e810b4712f86cfebb47ab53
parent 651d68ee
Loading
Loading
Loading
Loading
+39 −16
Original line number Diff line number Diff line
@@ -29,10 +29,10 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;

import android.bluetooth.BluetoothAdapter;
import android.content.ContentResolver;
import android.content.Context;
import android.database.MatrixCursor;
import android.os.Looper;

import androidx.test.filters.MediumTest;
import androidx.test.platform.app.InstrumentationRegistry;
@@ -57,7 +57,6 @@ import org.mockito.junit.MockitoRule;
@RunWith(AndroidJUnit4.class)
public class BluetoothOppServiceTest {
    private BluetoothOppService mService = null;
    private BluetoothAdapter mAdapter = null;
    private boolean mIsAdapterServiceSet;
    private boolean mIsBluetoothOppServiceStarted;

@@ -69,6 +68,9 @@ public class BluetoothOppServiceTest {

    @Before
    public void setUp() throws Exception {
        if (Looper.myLooper() == null) {
            Looper.prepare();
        }
        Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

        BluetoothMethodProxy.setInstanceForTesting(mBluetoothMethodProxy);
@@ -86,10 +88,6 @@ public class BluetoothOppServiceTest {
        mService.setAvailable(true);
        mIsBluetoothOppServiceStarted = true;

        // Try getting the Bluetooth adapter
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        Assert.assertNotNull(mAdapter);

        // Wait until the initial trimDatabase operation is done.
        verify(mBluetoothMethodProxy, timeout(3_000))
                .contentResolverQuery(
@@ -132,12 +130,38 @@ public class BluetoothOppServiceTest {
        int infoTimestamp = 123456789;
        int infoTimestamp2 = 123489;

        BluetoothOppShareInfo shareInfo = mock(BluetoothOppShareInfo.class);
        shareInfo.mTimestamp = infoTimestamp;
        shareInfo.mDestination = "AA:BB:CC:DD:EE:FF";
        BluetoothOppShareInfo shareInfo2 = mock(BluetoothOppShareInfo.class);
        shareInfo2.mTimestamp = infoTimestamp2;
        shareInfo2.mDestination = "00:11:22:33:44:55";
        BluetoothOppShareInfo shareInfo =
                new BluetoothOppShareInfo(
                        1, // id
                        null, // Uri,
                        "hint",
                        "filename",
                        "mimetype",
                        0, // direction
                        "AA:BB:CC:DD:EE:FF", // destination
                        0, // visibility,
                        0, // confirm
                        0, // status
                        0, // totalBytes
                        0, // currentBytes
                        infoTimestamp,
                        false); // mediaScanned
        BluetoothOppShareInfo shareInfo2 =
                new BluetoothOppShareInfo(
                        1, // id
                        null, // Uri,
                        "hint",
                        "filename",
                        "mimetype",
                        0, // direction
                        "00:11:22:33:44:55", // destination
                        0, // visibility,
                        0, // confirm
                        0, // status
                        0, // totalBytes
                        0, // currentBytes
                        infoTimestamp2,
                        false); // mediaScanned

        mService.mShares.clear();
        mService.mShares.add(shareInfo);
@@ -152,10 +176,9 @@ public class BluetoothOppServiceTest {
        mService.mBatches.add(batch2);

        mService.deleteShare(0);
        assertThat(mService.mShares.size()).isEqualTo(1);
        assertThat(mService.mBatches.size()).isEqualTo(1);
        assertThat(mService.mShares.get(0)).isEqualTo(shareInfo2);
        assertThat(mService.mBatches.get(0)).isEqualTo(batch2);

        assertThat(mService.mShares).containsExactly(shareInfo2);
        assertThat(mService.mBatches).containsExactly(batch2);
    }

    @Test