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

Commit c353915d authored by Marcelo Arteiro's avatar Marcelo Arteiro
Browse files

Fix Flaky UiModeManagerServiceTest

Ensure execution order by replacing Map for LinkedHashMap.

Change-Id: Ice300de201509f968b416cf9f79933ecad235957
Test: UiModeManagerServiceTest
Bug: 382042877
Flag: EXEMPT test fix
parent 57f1b334
Loading
Loading
Loading
Loading
+16 −13
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ import org.mockito.Spy;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
@@ -232,7 +233,8 @@ public class UiModeManagerServiceTest extends UiServiceTestCase {
                any(AlarmManager.OnAlarmListener.class), any(Handler.class));

        doAnswer(inv -> {
            mCustomListener = () -> {};
            mCustomListener = () -> {
            };
            return null;
        }).when(mAlarmManager).cancel(eq(mCustomListener));
        when(mContext.getSystemService(eq(Context.POWER_SERVICE)))
@@ -1473,12 +1475,13 @@ public class UiModeManagerServiceTest extends UiServiceTestCase {
            assertFalse(mUiManagerService.getConfiguration().isNightModeActive());
        }

        // attention modes with expected night modes
        Map<Integer, Boolean> modes = Map.of(
                MODE_ATTENTION_THEME_OVERLAY_OFF, initialNightMode,
                MODE_ATTENTION_THEME_OVERLAY_DAY, false,
                MODE_ATTENTION_THEME_OVERLAY_NIGHT, true
        );
        // Attention modes with expected night modes.
        // Important to keep modes.put(MODE_ATTENTION_THEME_OVERLAY_OFF, initialNightMode) in the
        // first position, hence LinkedHashMap.
        Map<Integer, Boolean> modes = new LinkedHashMap<>();
        modes.put(MODE_ATTENTION_THEME_OVERLAY_OFF, initialNightMode);
        modes.put(MODE_ATTENTION_THEME_OVERLAY_DAY, false);
        modes.put(MODE_ATTENTION_THEME_OVERLAY_NIGHT, true);

        // test
        for (int attentionMode : modes.keySet()) {