Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java +7 −9 Original line number Diff line number Diff line Loading @@ -22,12 +22,11 @@ import static com.android.settingslib.Utils.STORAGE_MANAGER_SHOW_OPT_IN_PROPERTY import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Matchers.eq; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.robolectric.Shadows.shadowOf; import android.app.ActivityManager; import android.content.ContentResolver; Loading @@ -54,7 +53,6 @@ import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; import org.robolectric.shadows.ShadowAudioManager; import org.robolectric.shadows.ShadowSettings; import java.util.HashMap; Loading @@ -72,7 +70,7 @@ public class UtilsTest { private static final String PERCENTAGE_50 = "50%"; private static final String PERCENTAGE_100 = "100%"; private ShadowAudioManager mShadowAudioManager; private AudioManager mAudioManager; private Context mContext; @Mock private LocationManager mLocationManager; Loading @@ -85,7 +83,7 @@ public class UtilsTest { mContext = spy(RuntimeEnvironment.application); when(mContext.getSystemService(Context.LOCATION_SERVICE)).thenReturn(mLocationManager); ShadowSecure.reset(); mShadowAudioManager = shadowOf(mContext.getSystemService(AudioManager.class)); mAudioManager = mContext.getSystemService(AudioManager.class); } @Test Loading Loading @@ -205,28 +203,28 @@ public class UtilsTest { @Test public void isAudioModeOngoingCall_modeInCommunication_returnTrue() { mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); assertThat(Utils.isAudioModeOngoingCall(mContext)).isTrue(); } @Test public void isAudioModeOngoingCall_modeInCall_returnTrue() { mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL); assertThat(Utils.isAudioModeOngoingCall(mContext)).isTrue(); } @Test public void isAudioModeOngoingCall_modeRingtone_returnTrue() { mShadowAudioManager.setMode(AudioManager.MODE_RINGTONE); mAudioManager.setMode(AudioManager.MODE_RINGTONE); assertThat(Utils.isAudioModeOngoingCall(mContext)).isTrue(); } @Test public void isAudioModeOngoingCall_modeNormal_returnFalse() { mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL); assertThat(Utils.isAudioModeOngoingCall(mContext)).isFalse(); } Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +10 −13 Original line number Diff line number Diff line Loading @@ -17,15 +17,14 @@ package com.android.settingslib.bluetooth; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.robolectric.Shadows.shadowOf; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; Loading @@ -40,7 +39,6 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; import org.robolectric.shadows.ShadowAudioManager; @RunWith(SettingsLibRobolectricTestRunner.class) public class CachedBluetoothDeviceTest { Loading @@ -67,7 +65,7 @@ public class CachedBluetoothDeviceTest { @Mock private BluetoothDevice mSubDevice; private CachedBluetoothDevice mCachedDevice; private ShadowAudioManager mShadowAudioManager; private AudioManager mAudioManager; private Context mContext; private int mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN; Loading @@ -75,7 +73,7 @@ public class CachedBluetoothDeviceTest { public void setUp() { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; mShadowAudioManager = shadowOf(mContext.getSystemService(AudioManager.class)); mAudioManager = mContext.getSystemService(AudioManager.class); when(mDevice.getAddress()).thenReturn(DEVICE_ADDRESS); when(mHfpProfile.isProfileReady()).thenReturn(true); when(mA2dpProfile.isProfileReady()).thenReturn(true); Loading Loading @@ -212,7 +210,7 @@ public class CachedBluetoothDeviceTest { // 2. Audio Manager: In Call updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.A2DP); mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL); // Act & Assert: // Get null result without Battery Level. Loading @@ -228,7 +226,7 @@ public class CachedBluetoothDeviceTest { updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.A2DP); mBatteryLevel = 10; mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL); // Act & Assert: // Get "10% battery" result with Battery Level 10. Loading @@ -244,14 +242,13 @@ public class CachedBluetoothDeviceTest { // Set device as Active for HFP and test connection state summary mCachedDevice.onAudioModeChanged(); mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL); mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEADSET); assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Active"); // Test with battery level mBatteryLevel = 10; assertThat(mCachedDevice.getConnectionSummary()).isEqualTo( "Active, 10% battery"); assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Active, 10% battery"); // Set HFP profile to be disconnected and test connection state summary updateProfileStatus(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED); Loading Loading @@ -363,7 +360,7 @@ public class CachedBluetoothDeviceTest { // 2. Audio Manager: In Call updateProfileStatus(mHearingAidProfile, BluetoothProfile.STATE_CONNECTED); mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEARING_AID); mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL); // Act & Assert: // Get "Active" result without Battery Level. Loading @@ -378,8 +375,8 @@ public class CachedBluetoothDeviceTest { // 3. Audio Manager: In Call updateProfileStatus(mHearingAidProfile, BluetoothProfile.STATE_CONNECTED); mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEARING_AID); mAudioManager.setMode(AudioManager.MODE_IN_CALL); mBatteryLevel = 10; mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); // Act & Assert: // Get "Active, 10% battery" result with Battery Level 10. Loading services/robotests/src/com/android/server/backup/BackupManagerServiceTest.java +4 −3 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.ContextWrapper; import android.content.Intent; import android.os.Binder; import android.os.HandlerThread; import android.os.PowerManager; import android.os.PowerSaveState; Loading Loading @@ -139,7 +140,7 @@ public class BackupManagerServiceTest { * specifically to prevent overloading the logs in production. */ @Test public void testMoreDebug_isFalse() throws Exception { public void testMoreDebug_isFalse() { boolean moreDebug = BackupManagerService.MORE_DEBUG; assertThat(moreDebug).isFalse(); Loading Loading @@ -943,7 +944,7 @@ public class BackupManagerServiceTest { backupManagerService.backupNow(); assertThat(ShadowKeyValueBackupJob.getCallingUid()).isEqualTo(ShadowBinder.LOCAL_UID); assertThat(ShadowBinder.getCallingUid()).isEqualTo(1); assertThat(Binder.getCallingUid()).isEqualTo(1); } /** Loading @@ -961,7 +962,7 @@ public class BackupManagerServiceTest { expectThrows(IllegalArgumentException.class, backupManagerService::backupNow); assertThat(ShadowKeyValueBackupJobException.getCallingUid()) .isEqualTo(ShadowBinder.LOCAL_UID); assertThat(ShadowBinder.getCallingUid()).isEqualTo(1); assertThat(Binder.getCallingUid()).isEqualTo(1); } private BackupManagerService createBackupManagerServiceForRequestBackup() { Loading services/robotests/src/com/android/server/backup/testing/BackupManagerServiceTestUtils.java +2 −7 Original line number Diff line number Diff line Loading @@ -18,9 +18,7 @@ package com.android.server.backup.testing; import static com.android.server.backup.testing.TestUtils.runToEndOfTasks; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; Loading @@ -36,18 +34,16 @@ import android.os.HandlerThread; import android.os.Looper; import android.os.PowerManager; import android.os.Process; import android.util.SparseArray; import android.util.Log; import com.android.server.backup.BackupAgentTimeoutParameters; import com.android.server.backup.BackupManagerService; import com.android.server.backup.Trampoline; import com.android.server.backup.TransportManager; import com.android.server.backup.internal.Operation; import org.mockito.stubbing.Answer; import org.robolectric.shadows.ShadowApplication; import org.robolectric.shadows.ShadowBinder; import org.robolectric.shadows.ShadowLog; import java.io.File; import java.lang.Thread.UncaughtExceptionHandler; Loading Loading @@ -192,8 +188,7 @@ public class BackupManagerServiceTestUtils { public static HandlerThread startSilentBackupThread(String tag) { return startBackupThread( (thread, e) -> ShadowLog.e( tag, "Uncaught exception in test thread " + thread.getName(), e)); Log.e(tag, "Uncaught exception in test thread " + thread.getName(), e)); } private BackupManagerServiceTestUtils() {} Loading services/robotests/src/com/android/server/backup/testing/TestUtils.java +2 −2 Original line number Diff line number Diff line Loading @@ -25,12 +25,12 @@ import static java.util.stream.Collectors.toSet; import android.os.Looper; import android.os.Message; import android.os.MessageQueue; import android.os.SystemClock; import com.android.server.testing.shadows.ShadowEventLog; import org.robolectric.shadows.ShadowLog; import org.robolectric.shadows.ShadowLooper; import org.robolectric.shadows.ShadowSystemClock; import java.util.Arrays; import java.util.concurrent.Callable; Loading Loading @@ -87,7 +87,7 @@ public class TestUtils { // specific time to the looper the time of those messages will be before the looper's time. // To fix this we advance SystemClock as well since that is from where the handlers read // time. ShadowSystemClock.setCurrentTimeMillis(shadowLooper.getScheduler().getCurrentTime()); SystemClock.setCurrentTimeMillis(shadowLooper.getScheduler().getCurrentTime()); } /** Loading Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java +7 −9 Original line number Diff line number Diff line Loading @@ -22,12 +22,11 @@ import static com.android.settingslib.Utils.STORAGE_MANAGER_SHOW_OPT_IN_PROPERTY import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Matchers.eq; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.robolectric.Shadows.shadowOf; import android.app.ActivityManager; import android.content.ContentResolver; Loading @@ -54,7 +53,6 @@ import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; import org.robolectric.shadows.ShadowAudioManager; import org.robolectric.shadows.ShadowSettings; import java.util.HashMap; Loading @@ -72,7 +70,7 @@ public class UtilsTest { private static final String PERCENTAGE_50 = "50%"; private static final String PERCENTAGE_100 = "100%"; private ShadowAudioManager mShadowAudioManager; private AudioManager mAudioManager; private Context mContext; @Mock private LocationManager mLocationManager; Loading @@ -85,7 +83,7 @@ public class UtilsTest { mContext = spy(RuntimeEnvironment.application); when(mContext.getSystemService(Context.LOCATION_SERVICE)).thenReturn(mLocationManager); ShadowSecure.reset(); mShadowAudioManager = shadowOf(mContext.getSystemService(AudioManager.class)); mAudioManager = mContext.getSystemService(AudioManager.class); } @Test Loading Loading @@ -205,28 +203,28 @@ public class UtilsTest { @Test public void isAudioModeOngoingCall_modeInCommunication_returnTrue() { mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); assertThat(Utils.isAudioModeOngoingCall(mContext)).isTrue(); } @Test public void isAudioModeOngoingCall_modeInCall_returnTrue() { mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL); assertThat(Utils.isAudioModeOngoingCall(mContext)).isTrue(); } @Test public void isAudioModeOngoingCall_modeRingtone_returnTrue() { mShadowAudioManager.setMode(AudioManager.MODE_RINGTONE); mAudioManager.setMode(AudioManager.MODE_RINGTONE); assertThat(Utils.isAudioModeOngoingCall(mContext)).isTrue(); } @Test public void isAudioModeOngoingCall_modeNormal_returnFalse() { mShadowAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL); assertThat(Utils.isAudioModeOngoingCall(mContext)).isFalse(); } Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +10 −13 Original line number Diff line number Diff line Loading @@ -17,15 +17,14 @@ package com.android.settingslib.bluetooth; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.robolectric.Shadows.shadowOf; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; Loading @@ -40,7 +39,6 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; import org.robolectric.shadows.ShadowAudioManager; @RunWith(SettingsLibRobolectricTestRunner.class) public class CachedBluetoothDeviceTest { Loading @@ -67,7 +65,7 @@ public class CachedBluetoothDeviceTest { @Mock private BluetoothDevice mSubDevice; private CachedBluetoothDevice mCachedDevice; private ShadowAudioManager mShadowAudioManager; private AudioManager mAudioManager; private Context mContext; private int mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN; Loading @@ -75,7 +73,7 @@ public class CachedBluetoothDeviceTest { public void setUp() { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; mShadowAudioManager = shadowOf(mContext.getSystemService(AudioManager.class)); mAudioManager = mContext.getSystemService(AudioManager.class); when(mDevice.getAddress()).thenReturn(DEVICE_ADDRESS); when(mHfpProfile.isProfileReady()).thenReturn(true); when(mA2dpProfile.isProfileReady()).thenReturn(true); Loading Loading @@ -212,7 +210,7 @@ public class CachedBluetoothDeviceTest { // 2. Audio Manager: In Call updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.A2DP); mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL); // Act & Assert: // Get null result without Battery Level. Loading @@ -228,7 +226,7 @@ public class CachedBluetoothDeviceTest { updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.A2DP); mBatteryLevel = 10; mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL); // Act & Assert: // Get "10% battery" result with Battery Level 10. Loading @@ -244,14 +242,13 @@ public class CachedBluetoothDeviceTest { // Set device as Active for HFP and test connection state summary mCachedDevice.onAudioModeChanged(); mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL); mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEADSET); assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Active"); // Test with battery level mBatteryLevel = 10; assertThat(mCachedDevice.getConnectionSummary()).isEqualTo( "Active, 10% battery"); assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Active, 10% battery"); // Set HFP profile to be disconnected and test connection state summary updateProfileStatus(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED); Loading Loading @@ -363,7 +360,7 @@ public class CachedBluetoothDeviceTest { // 2. Audio Manager: In Call updateProfileStatus(mHearingAidProfile, BluetoothProfile.STATE_CONNECTED); mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEARING_AID); mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL); // Act & Assert: // Get "Active" result without Battery Level. Loading @@ -378,8 +375,8 @@ public class CachedBluetoothDeviceTest { // 3. Audio Manager: In Call updateProfileStatus(mHearingAidProfile, BluetoothProfile.STATE_CONNECTED); mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEARING_AID); mAudioManager.setMode(AudioManager.MODE_IN_CALL); mBatteryLevel = 10; mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL); // Act & Assert: // Get "Active, 10% battery" result with Battery Level 10. Loading
services/robotests/src/com/android/server/backup/BackupManagerServiceTest.java +4 −3 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.ContextWrapper; import android.content.Intent; import android.os.Binder; import android.os.HandlerThread; import android.os.PowerManager; import android.os.PowerSaveState; Loading Loading @@ -139,7 +140,7 @@ public class BackupManagerServiceTest { * specifically to prevent overloading the logs in production. */ @Test public void testMoreDebug_isFalse() throws Exception { public void testMoreDebug_isFalse() { boolean moreDebug = BackupManagerService.MORE_DEBUG; assertThat(moreDebug).isFalse(); Loading Loading @@ -943,7 +944,7 @@ public class BackupManagerServiceTest { backupManagerService.backupNow(); assertThat(ShadowKeyValueBackupJob.getCallingUid()).isEqualTo(ShadowBinder.LOCAL_UID); assertThat(ShadowBinder.getCallingUid()).isEqualTo(1); assertThat(Binder.getCallingUid()).isEqualTo(1); } /** Loading @@ -961,7 +962,7 @@ public class BackupManagerServiceTest { expectThrows(IllegalArgumentException.class, backupManagerService::backupNow); assertThat(ShadowKeyValueBackupJobException.getCallingUid()) .isEqualTo(ShadowBinder.LOCAL_UID); assertThat(ShadowBinder.getCallingUid()).isEqualTo(1); assertThat(Binder.getCallingUid()).isEqualTo(1); } private BackupManagerService createBackupManagerServiceForRequestBackup() { Loading
services/robotests/src/com/android/server/backup/testing/BackupManagerServiceTestUtils.java +2 −7 Original line number Diff line number Diff line Loading @@ -18,9 +18,7 @@ package com.android.server.backup.testing; import static com.android.server.backup.testing.TestUtils.runToEndOfTasks; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; Loading @@ -36,18 +34,16 @@ import android.os.HandlerThread; import android.os.Looper; import android.os.PowerManager; import android.os.Process; import android.util.SparseArray; import android.util.Log; import com.android.server.backup.BackupAgentTimeoutParameters; import com.android.server.backup.BackupManagerService; import com.android.server.backup.Trampoline; import com.android.server.backup.TransportManager; import com.android.server.backup.internal.Operation; import org.mockito.stubbing.Answer; import org.robolectric.shadows.ShadowApplication; import org.robolectric.shadows.ShadowBinder; import org.robolectric.shadows.ShadowLog; import java.io.File; import java.lang.Thread.UncaughtExceptionHandler; Loading Loading @@ -192,8 +188,7 @@ public class BackupManagerServiceTestUtils { public static HandlerThread startSilentBackupThread(String tag) { return startBackupThread( (thread, e) -> ShadowLog.e( tag, "Uncaught exception in test thread " + thread.getName(), e)); Log.e(tag, "Uncaught exception in test thread " + thread.getName(), e)); } private BackupManagerServiceTestUtils() {} Loading
services/robotests/src/com/android/server/backup/testing/TestUtils.java +2 −2 Original line number Diff line number Diff line Loading @@ -25,12 +25,12 @@ import static java.util.stream.Collectors.toSet; import android.os.Looper; import android.os.Message; import android.os.MessageQueue; import android.os.SystemClock; import com.android.server.testing.shadows.ShadowEventLog; import org.robolectric.shadows.ShadowLog; import org.robolectric.shadows.ShadowLooper; import org.robolectric.shadows.ShadowSystemClock; import java.util.Arrays; import java.util.concurrent.Callable; Loading Loading @@ -87,7 +87,7 @@ public class TestUtils { // specific time to the looper the time of those messages will be before the looper's time. // To fix this we advance SystemClock as well since that is from where the handlers read // time. ShadowSystemClock.setCurrentTimeMillis(shadowLooper.getScheduler().getCurrentTime()); SystemClock.setCurrentTimeMillis(shadowLooper.getScheduler().getCurrentTime()); } /** Loading