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

Commit c02eb6e6 authored by Andrew Cheng's avatar Andrew Cheng
Browse files

MapClientStateMachineTest: use FlagsParameterization and @EnableFlags

Update MapClientStateMachineTest to current best practices with Flags,
specifically:

1. Use FlagsParameterization to test combinations of different flags, on
   tests that do not have a big behavior change and need to test both
   "On" and "Off" states of flags.

2. Use @EnableFlags annotation on tests that have a behavior change.
   (Note: there's no corresponding @DisableFlags tests because there's
   no change in behavior when the flag is "Off", and no applicable new
   tests to add for the "Off" case).

Bug: 352101390
Bug: 322023693
Bug: 317400386
Test: atest MapClientStateMachineTest
Flag: com.android.bluetooth.flags.handle_delivery_sending_failure_events
Change-Id: I5bb415c658d5149e7e624d417b0214c42ac2ddeb
parent 1a7bcca7
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.FlagsParameterization;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Telephony.Sms;
import android.telephony.SmsManager;
@@ -51,7 +53,6 @@ import android.util.Log;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.MediumTest;
import androidx.test.rule.ServiceTestRule;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.TestUtils;
import com.android.bluetooth.btservice.AdapterService;
@@ -76,6 +77,9 @@ import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import platform.test.runner.parameterized.ParameterizedAndroidJunit4;
import platform.test.runner.parameterized.Parameters;

import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
@@ -85,12 +89,12 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

@MediumTest
@RunWith(AndroidJUnit4.class)
@RunWith(ParameterizedAndroidJunit4.class)
public class MapClientStateMachineTest {

    private static final String TAG = "MapStateMachineTest";

    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
    @Rule public final SetFlagsRule mSetFlagsRule;

    private static final int ASYNC_CALL_TIMEOUT_MILLIS = 100;
    private static final int DISCONNECT_TIMEOUT = 3000;
@@ -186,6 +190,16 @@ public class MapClientStateMachineTest {
        }
    }

    @Parameters(name = "{0}")
    public static List<FlagsParameterization> getParams() {
        return FlagsParameterization.progressionOf(
                Flags.FLAG_HANDLE_DELIVERY_SENDING_FAILURE_EVENTS);
    }

    public MapClientStateMachineTest(FlagsParameterization flags) {
        mSetFlagsRule = new SetFlagsRule(flags);
    }

    @Before
    public void setUp() throws Exception {
        mTargetContext = InstrumentationRegistry.getTargetContext();
@@ -1060,7 +1074,6 @@ public class MapClientStateMachineTest {
     */
    @Test
    public void testSendMapMessageSentPendingIntent_notifyStatusSuccess() {
        mSetFlagsRule.enableFlags(Flags.FLAG_HANDLE_DELIVERY_SENDING_FAILURE_EVENTS);
        testSendMapMessagePendingIntents_base(
                ACTION_MESSAGE_SENT, EventReport.Type.SENDING_SUCCESS);

@@ -1078,7 +1091,6 @@ public class MapClientStateMachineTest {
     */
    @Test
    public void testSendMapMessageDeliveryPendingIntent_notifyStatusSuccess() {
        mSetFlagsRule.enableFlags(Flags.FLAG_HANDLE_DELIVERY_SENDING_FAILURE_EVENTS);
        testSendMapMessagePendingIntents_base(
                ACTION_MESSAGE_DELIVERED, EventReport.Type.DELIVERY_SUCCESS);

@@ -1097,7 +1109,6 @@ public class MapClientStateMachineTest {
     */
    @Test
    public void testSendMapMessageNullPendingIntent_noNotifyStatus() {
        mSetFlagsRule.enableFlags(Flags.FLAG_HANDLE_DELIVERY_SENDING_FAILURE_EVENTS);
        testSendMapMessagePendingIntents_base(null, EventReport.Type.SENDING_SUCCESS);

        assertThat(mSentDeliveryReceiver.isActionReceived(PENDING_INTENT_TIMEOUT_MS)).isFalse();
@@ -1112,8 +1123,8 @@ public class MapClientStateMachineTest {
     * <p>Outcome: - SENT_STATUS Intent was broadcast with 'Failure' result code.
     */
    @Test
    @EnableFlags(Flags.FLAG_HANDLE_DELIVERY_SENDING_FAILURE_EVENTS)
    public void testSendMapMessageSentPendingIntent_notifyStatusFailure() {
        mSetFlagsRule.enableFlags(Flags.FLAG_HANDLE_DELIVERY_SENDING_FAILURE_EVENTS);
        testSendMapMessagePendingIntents_base(
                ACTION_MESSAGE_SENT, EventReport.Type.SENDING_FAILURE);

@@ -1131,8 +1142,8 @@ public class MapClientStateMachineTest {
     * <p>Outcome: - DELIVERY_STATUS Intent was broadcast with 'Failure' result code.
     */
    @Test
    @EnableFlags(Flags.FLAG_HANDLE_DELIVERY_SENDING_FAILURE_EVENTS)
    public void testSendMapMessageDeliveryPendingIntent_notifyStatusFailure() {
        mSetFlagsRule.enableFlags(Flags.FLAG_HANDLE_DELIVERY_SENDING_FAILURE_EVENTS);
        testSendMapMessagePendingIntents_base(
                ACTION_MESSAGE_DELIVERED, EventReport.Type.DELIVERY_FAILURE);