Loading android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivityTest.java +26 −14 Original line number Original line Diff line number Diff line Loading @@ -51,6 +51,7 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations; import org.mockito.Spy; import org.mockito.Spy; import java.util.concurrent.atomic.AtomicBoolean; @RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class) public class BluetoothOppBtEnablingActivityTest { public class BluetoothOppBtEnablingActivityTest { Loading Loading @@ -117,14 +118,20 @@ public class BluetoothOppBtEnablingActivityTest { ActivityScenario<BluetoothOppBtEnablingActivity> activityScenario = ActivityScenario.launch( ActivityScenario<BluetoothOppBtEnablingActivity> activityScenario = ActivityScenario.launch( mIntent); mIntent); activityScenario.onActivity(activity -> { AtomicBoolean finishCalled = new AtomicBoolean(false); activity.onKeyDown(KeyEvent.KEYCODE_BACK, activityScenario.onActivity( activity -> { activity.onKeyDown( KeyEvent.KEYCODE_BACK, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)); new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)); // Should be cancelled immediately // Should be cancelled immediately BluetoothOppManager mOppManager = BluetoothOppManager.getInstance(activity); BluetoothOppManager mOppManager = BluetoothOppManager.getInstance(activity); assertThat(mOppManager.mSendingFlag).isEqualTo(false); assertThat(mOppManager.mSendingFlag).isEqualTo(false); finishCalled.set(activity.isFinishing()); }); }); assertActivityState(activityScenario, DESTROYED); assertThat(finishCalled.get()).isTrue(); } } @Test @Test Loading @@ -140,12 +147,17 @@ public class BluetoothOppBtEnablingActivityTest { doReturn(false).when(mBluetoothMethodProxy).bluetoothAdapterIsEnabled(any()); doReturn(false).when(mBluetoothMethodProxy).bluetoothAdapterIsEnabled(any()); ActivityScenario<BluetoothOppBtEnablingActivity> activityScenario = ActivityScenario.launch( ActivityScenario<BluetoothOppBtEnablingActivity> activityScenario = ActivityScenario.launch( mIntent); mIntent); activityScenario.onActivity(activity -> { AtomicBoolean finishCalled = new AtomicBoolean(false); activityScenario.onActivity( activity -> { Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED); Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED); intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_ON); intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_ON); activity.mBluetoothReceiver.onReceive(mTargetContext, intent); activity.mBluetoothReceiver.onReceive(mTargetContext, intent); finishCalled.set(activity.isFinishing()); }); }); assertActivityState(activityScenario, DESTROYED); assertThat(finishCalled.get()).isTrue(); } } private void assertActivityState(ActivityScenario activityScenario, Lifecycle.State state) private void assertActivityState(ActivityScenario activityScenario, Lifecycle.State state) Loading Loading
android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivityTest.java +26 −14 Original line number Original line Diff line number Diff line Loading @@ -51,6 +51,7 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations; import org.mockito.Spy; import org.mockito.Spy; import java.util.concurrent.atomic.AtomicBoolean; @RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class) public class BluetoothOppBtEnablingActivityTest { public class BluetoothOppBtEnablingActivityTest { Loading Loading @@ -117,14 +118,20 @@ public class BluetoothOppBtEnablingActivityTest { ActivityScenario<BluetoothOppBtEnablingActivity> activityScenario = ActivityScenario.launch( ActivityScenario<BluetoothOppBtEnablingActivity> activityScenario = ActivityScenario.launch( mIntent); mIntent); activityScenario.onActivity(activity -> { AtomicBoolean finishCalled = new AtomicBoolean(false); activity.onKeyDown(KeyEvent.KEYCODE_BACK, activityScenario.onActivity( activity -> { activity.onKeyDown( KeyEvent.KEYCODE_BACK, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)); new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)); // Should be cancelled immediately // Should be cancelled immediately BluetoothOppManager mOppManager = BluetoothOppManager.getInstance(activity); BluetoothOppManager mOppManager = BluetoothOppManager.getInstance(activity); assertThat(mOppManager.mSendingFlag).isEqualTo(false); assertThat(mOppManager.mSendingFlag).isEqualTo(false); finishCalled.set(activity.isFinishing()); }); }); assertActivityState(activityScenario, DESTROYED); assertThat(finishCalled.get()).isTrue(); } } @Test @Test Loading @@ -140,12 +147,17 @@ public class BluetoothOppBtEnablingActivityTest { doReturn(false).when(mBluetoothMethodProxy).bluetoothAdapterIsEnabled(any()); doReturn(false).when(mBluetoothMethodProxy).bluetoothAdapterIsEnabled(any()); ActivityScenario<BluetoothOppBtEnablingActivity> activityScenario = ActivityScenario.launch( ActivityScenario<BluetoothOppBtEnablingActivity> activityScenario = ActivityScenario.launch( mIntent); mIntent); activityScenario.onActivity(activity -> { AtomicBoolean finishCalled = new AtomicBoolean(false); activityScenario.onActivity( activity -> { Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED); Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED); intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_ON); intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_ON); activity.mBluetoothReceiver.onReceive(mTargetContext, intent); activity.mBluetoothReceiver.onReceive(mTargetContext, intent); finishCalled.set(activity.isFinishing()); }); }); assertActivityState(activityScenario, DESTROYED); assertThat(finishCalled.get()).isTrue(); } } private void assertActivityState(ActivityScenario activityScenario, Lifecycle.State state) private void assertActivityState(ActivityScenario activityScenario, Lifecycle.State state) Loading