Merge "Fix BluetoothUpdateWorkerTest." into main

This commit is contained in:
Fan Wu
2023-12-12 01:16:22 +00:00
committed by Android (Google) Code Review
2 changed files with 11 additions and 16 deletions

View File

@@ -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);
}

View File

@@ -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();
}
}