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

Commit dd61b6bb authored by Fan Wu's avatar Fan Wu Committed by Android (Google) Code Review
Browse files

Merge "Fix BluetoothUpdateWorkerTest." into main

parents 4df98df7 e6d648aa
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import android.os.SystemClock;
import android.util.ArrayMap;
import android.util.Log;

import androidx.annotation.VisibleForTesting;

import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
@@ -172,7 +174,8 @@ public abstract class SliceBackgroundWorker<E> implements Closeable {
    /**
     * Notify that data was updated and attempt to sync changes to the Slice.
     */
    protected final void notifySliceChange() {
    @VisibleForTesting
    public final void notifySliceChange() {
        NotifySliceChangeHandler.getInstance().updateSlice(this);
    }

+7 −15
Original line number Diff line number Diff line
@@ -16,12 +16,9 @@

package com.android.settings.homepage.contextualcards.slices;

import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;

@@ -29,7 +26,6 @@ import com.android.settings.slices.ShadowSliceBackgroundWorker;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@@ -43,50 +39,46 @@ public class BluetoothUpdateWorkerTest {
    private static final Uri URI = Uri.parse("content://com.android.settings.slices/test");

    private BluetoothUpdateWorker mBluetoothUpdateWorker;
    private ContentResolver mResolver;
    private Context mContext;

    @Before
    public void setUp() {
        mContext = spy(RuntimeEnvironment.application);
        mBluetoothUpdateWorker = new BluetoothUpdateWorker(mContext, URI);
        mResolver = mock(ContentResolver.class);
        doReturn(mResolver).when(mContext).getContentResolver();
        mContext = RuntimeEnvironment.getApplication();
        mBluetoothUpdateWorker = spy(new BluetoothUpdateWorker(mContext, URI));
    }

    @Test
    public void onAclConnectionStateChanged_shouldNotifyChange() {
        mBluetoothUpdateWorker.onAclConnectionStateChanged(null, 0);

        verify(mResolver).notifyChange(URI, null);
        verify(mBluetoothUpdateWorker).notifySliceChange();
    }

    @Ignore("b/315399487")
    @Test
    public void onActiveDeviceChanged_shouldNotifyChange() {
        mBluetoothUpdateWorker.onActiveDeviceChanged(null, 0);

        verify(mResolver).notifyChange(URI, null);
        verify(mBluetoothUpdateWorker).notifySliceChange();
    }

    @Test
    public void onBluetoothStateChanged_shouldNotifyChange() {
        mBluetoothUpdateWorker.onBluetoothStateChanged(0);

        verify(mResolver).notifyChange(URI, null);
        verify(mBluetoothUpdateWorker).notifySliceChange();
    }

    @Test
    public void onConnectionStateChanged_shouldNotifyChange() {
        mBluetoothUpdateWorker.onConnectionStateChanged(null, 0);

        verify(mResolver).notifyChange(URI, null);
        verify(mBluetoothUpdateWorker).notifySliceChange();
    }

    @Test
    public void onProfileConnectionStateChanged_shouldNotifyChange() {
        mBluetoothUpdateWorker.onProfileConnectionStateChanged(null, 0, 0);

        verify(mResolver).notifyChange(URI, null);
        verify(mBluetoothUpdateWorker).notifySliceChange();
    }
}
 No newline at end of file