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

Commit d4a273aa authored by Hyundo Moon's avatar Hyundo Moon Committed by Gerrit Code Review
Browse files

Merge "Fix flaky BluetoothOppBtEnablingActivityTest#onKeyDown_cancelProgress" into main

parents 576b2a85 aa1d58f4
Loading
Loading
Loading
Loading
+26 −14
Original line number Original line Diff line number Diff line
@@ -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 {
@@ -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
@@ -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)