Merge "Fix a bug in InlinePresentationStyleUtils#bundleEquals" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
bc000662c3
@@ -52,10 +52,10 @@ public final class InlinePresentationStyleUtils {
|
|||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
Object value1 = bundle1.get(key);
|
Object value1 = bundle1.get(key);
|
||||||
Object value2 = bundle2.get(key);
|
Object value2 = bundle2.get(key);
|
||||||
if (value1 instanceof Bundle && value2 instanceof Bundle
|
final boolean equal = value1 instanceof Bundle && value2 instanceof Bundle
|
||||||
&& !bundleEquals((Bundle) value1, (Bundle) value2)) {
|
? bundleEquals((Bundle) value1, (Bundle) value2)
|
||||||
return false;
|
: Objects.equals(value1, value2);
|
||||||
} else if (!Objects.equals(value1, value2)) {
|
if (!equal) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user