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

Commit cb95c883 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix a bug in InlinePresentationStyleUtils#bundleEquals" into rvc-dev am: bc000662

Change-Id: Ief40a2292f73d0e24a52afb98497298a938a31f3
parents ad2d8350 bc000662
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -52,10 +52,10 @@ public final class InlinePresentationStyleUtils {
        for (String key : keys) {
            Object value1 = bundle1.get(key);
            Object value2 = bundle2.get(key);
            if (value1 instanceof Bundle && value2 instanceof Bundle
                    && !bundleEquals((Bundle) value1, (Bundle) value2)) {
                return false;
            } else if (!Objects.equals(value1, value2)) {
            final boolean equal = value1 instanceof Bundle && value2 instanceof Bundle
                    ? bundleEquals((Bundle) value1, (Bundle) value2)
                    : Objects.equals(value1, value2);
            if (!equal) {
                return false;
            }
        }
+113 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.util;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import android.os.Bundle;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.internal.widget.InlinePresentationStyleUtils;

import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
@SmallTest
public class InlinePresentationStyleUtilsTest {
    @Test
    public void testBundleEquals_empty() {
        Bundle bundle1 = new Bundle();
        Bundle bundle2 = new Bundle();

        assertTrue(InlinePresentationStyleUtils.bundleEquals(bundle1, bundle2));

        bundle1 = Bundle.EMPTY;
        assertTrue(InlinePresentationStyleUtils.bundleEquals(bundle1, bundle2));

        bundle2 = Bundle.EMPTY;
        assertTrue(InlinePresentationStyleUtils.bundleEquals(bundle1, bundle2));
    }

    @Test
    public void testBundleEquals_oneIsEmpty() {
        Bundle bundle1 = Bundle.EMPTY;
        Bundle bundle2 = new Bundle();
        bundle2.putString("KEY", "value");
        assertFalse(InlinePresentationStyleUtils.bundleEquals(bundle1, bundle2));
    }

    @Test
    public void testBundleEquals_nestedBundle_equal() {
        Bundle bundle1 = new Bundle();
        Bundle bundle11 = new Bundle();
        bundle11.putString("KEY", "VALUE");
        bundle1.putBundle("KEY_B", bundle11);

        Bundle bundle2 = new Bundle();
        Bundle bundle21 = new Bundle();
        bundle21.putString("KEY", "VALUE");
        bundle2.putBundle("KEY_B", bundle21);

        assertTrue(InlinePresentationStyleUtils.bundleEquals(bundle1, bundle2));
    }

    @Test
    public void testBundleEquals_nestedBundle_unequal() {
        Bundle bundle1 = new Bundle();
        Bundle bundle11 = new Bundle();
        bundle11.putString("KEY", "VALUE");
        bundle1.putBundle("KEY_B", bundle11);

        Bundle bundle2 = new Bundle();
        bundle2.putBundle("KEY_B", new Bundle());

        assertFalse(InlinePresentationStyleUtils.bundleEquals(bundle1, bundle2));
    }

    @Test
    public void testBundleEquals_sameKeyDifferentType() {
        Bundle bundle1 = new Bundle();
        bundle1.putBundle("KEY_B", new Bundle());

        Bundle bundle2 = new Bundle();
        bundle2.putInt("KEY_B", 12);

        assertFalse(InlinePresentationStyleUtils.bundleEquals(bundle1, bundle2));
    }

    @Test
    public void testBundleEquals_primitiveValue_equal() {
        Bundle bundle1 = new Bundle();
        bundle1.putInt("KEY", 11);
        Bundle bundle2 = new Bundle();
        bundle2.putInt("KEY", 11);
        assertTrue(InlinePresentationStyleUtils.bundleEquals(bundle1, bundle2));
    }

    @Test
    public void testBundleEquals_primitiveValue_unequal() {
        Bundle bundle1 = new Bundle();
        bundle1.putInt("KEY", 11);
        Bundle bundle2 = new Bundle();
        bundle2.putInt("KEY", 22);
        assertFalse(InlinePresentationStyleUtils.bundleEquals(bundle1, bundle2));
    }
}