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

Commit 0749da8c authored by Kazuki Takise's avatar Kazuki Takise
Browse files

Refactor ScreenDecorWindowTests

To override expected values of assertions, we separate some code
into functions.

Basically, ARC team wants to override expected values as follows.

private void assertTopInsetEquals(Activity activity, int expected) throws Exception {
    expected = otherValue;
    waitFor(() -> getInsets(activity).getSystemWindowInsetTop() == expected);
    ...
}

However, without this CL, the labmda function generates the
following error.

error: local variables referenced from a lambda expression must be final or effectively final

This CL resolves the error by separating the wairFor part into another
function.

Bug: 110906754
Test: ScreenDecorWindowTests
Change-Id: Id46557afdbc5cde4683d8ba33a84e5ec951cc27a
parent 9c19e34d
Loading
Loading
Loading
Loading
+17 −9
Original line number Diff line number Diff line
@@ -255,16 +255,32 @@ public class ScreenDecorWindowTests {
     * Asserts the top inset of {@param activity} is equal to {@param expected} waiting as needed.
     */
    private void assertTopInsetEquals(Activity activity, int expected) throws Exception {
        waitFor(() -> getInsets(activity).getSystemWindowInsetTop() == expected);
        waitForTopInsetEqual(activity, expected);
        assertEquals(expected, getInsets(activity).getSystemWindowInsetTop());
    }

    private void waitForTopInsetEqual(Activity activity, int expected) {
        waitFor(() -> getInsets(activity).getSystemWindowInsetTop() == expected);
    }

    /**
     * Asserts the inset at {@param side} of {@param activity} is equal to {@param expected}
     * waiting as needed.
     */
    private void assertInsetGreaterOrEqual(Activity activity, int side, int expected)
            throws Exception {
        waitForInsetGreaterOrEqual(activity, side, expected);

        final WindowInsets insets = getInsets(activity);
        switch (side) {
            case TOP: assertGreaterOrEqual(insets.getSystemWindowInsetTop(), expected); break;
            case BOTTOM: assertGreaterOrEqual(insets.getSystemWindowInsetBottom(), expected); break;
            case LEFT: assertGreaterOrEqual(insets.getSystemWindowInsetLeft(), expected); break;
            case RIGHT: assertGreaterOrEqual(insets.getSystemWindowInsetRight(), expected); break;
        }
    }

    private void waitForInsetGreaterOrEqual(Activity activity, int side, int expected) {
        waitFor(() -> {
            final WindowInsets insets = getInsets(activity);
            switch (side) {
@@ -275,14 +291,6 @@ public class ScreenDecorWindowTests {
                default: return true;
            }
        });

        final WindowInsets insets = getInsets(activity);
        switch (side) {
            case TOP: assertGreaterOrEqual(insets.getSystemWindowInsetTop(), expected); break;
            case BOTTOM: assertGreaterOrEqual(insets.getSystemWindowInsetBottom(), expected); break;
            case LEFT: assertGreaterOrEqual(insets.getSystemWindowInsetLeft(), expected); break;
            case RIGHT: assertGreaterOrEqual(insets.getSystemWindowInsetRight(), expected); break;
        }
    }

    /** Asserts that the first entry is greater than or equal to the second entry. */