Merge "Fix BluetoothUpdateWorkerTest." into main
This commit is contained in:
@@ -29,6 +29,8 @@ import android.os.SystemClock;
|
|||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
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.
|
* 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);
|
NotifySliceChangeHandler.getInstance().updateSlice(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,12 +16,9 @@
|
|||||||
|
|
||||||
package com.android.settings.homepage.contextualcards.slices;
|
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.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
@@ -29,7 +26,6 @@ import com.android.settings.slices.ShadowSliceBackgroundWorker;
|
|||||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
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 static final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||||
|
|
||||||
private BluetoothUpdateWorker mBluetoothUpdateWorker;
|
private BluetoothUpdateWorker mBluetoothUpdateWorker;
|
||||||
private ContentResolver mResolver;
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = RuntimeEnvironment.getApplication();
|
||||||
mBluetoothUpdateWorker = new BluetoothUpdateWorker(mContext, URI);
|
mBluetoothUpdateWorker = spy(new BluetoothUpdateWorker(mContext, URI));
|
||||||
mResolver = mock(ContentResolver.class);
|
|
||||||
doReturn(mResolver).when(mContext).getContentResolver();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onAclConnectionStateChanged_shouldNotifyChange() {
|
public void onAclConnectionStateChanged_shouldNotifyChange() {
|
||||||
mBluetoothUpdateWorker.onAclConnectionStateChanged(null, 0);
|
mBluetoothUpdateWorker.onAclConnectionStateChanged(null, 0);
|
||||||
|
|
||||||
verify(mResolver).notifyChange(URI, null);
|
verify(mBluetoothUpdateWorker).notifySliceChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("b/315399487")
|
|
||||||
@Test
|
@Test
|
||||||
public void onActiveDeviceChanged_shouldNotifyChange() {
|
public void onActiveDeviceChanged_shouldNotifyChange() {
|
||||||
mBluetoothUpdateWorker.onActiveDeviceChanged(null, 0);
|
mBluetoothUpdateWorker.onActiveDeviceChanged(null, 0);
|
||||||
|
|
||||||
verify(mResolver).notifyChange(URI, null);
|
verify(mBluetoothUpdateWorker).notifySliceChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onBluetoothStateChanged_shouldNotifyChange() {
|
public void onBluetoothStateChanged_shouldNotifyChange() {
|
||||||
mBluetoothUpdateWorker.onBluetoothStateChanged(0);
|
mBluetoothUpdateWorker.onBluetoothStateChanged(0);
|
||||||
|
|
||||||
verify(mResolver).notifyChange(URI, null);
|
verify(mBluetoothUpdateWorker).notifySliceChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onConnectionStateChanged_shouldNotifyChange() {
|
public void onConnectionStateChanged_shouldNotifyChange() {
|
||||||
mBluetoothUpdateWorker.onConnectionStateChanged(null, 0);
|
mBluetoothUpdateWorker.onConnectionStateChanged(null, 0);
|
||||||
|
|
||||||
verify(mResolver).notifyChange(URI, null);
|
verify(mBluetoothUpdateWorker).notifySliceChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_shouldNotifyChange() {
|
public void onProfileConnectionStateChanged_shouldNotifyChange() {
|
||||||
mBluetoothUpdateWorker.onProfileConnectionStateChanged(null, 0, 0);
|
mBluetoothUpdateWorker.onProfileConnectionStateChanged(null, 0, 0);
|
||||||
|
|
||||||
verify(mResolver).notifyChange(URI, null);
|
verify(mBluetoothUpdateWorker).notifySliceChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user