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

Commit 213f98b6 authored by Lorenzo Colitti's avatar Lorenzo Colitti
Browse files

Fix LinkProperties's equals() method.

LinkProperties's equals() method was broken by the addition of
stacked interfaces. The reason was that equals() was checking
the equality of mStackedInterfaces.keys(), which is just an
enumeration, instead of mStackedInterfaces.keySet(), which
actually contains the keys. The test was failing, but I didn't
notice.

Fix the bug and make the test check the objects more in depth
so it can give more detailed error messages when equals() fails.

Bug: 8276725
Change-Id: Ie990bd75f641c28e63e54d953dcd0f4de13f7c9f
parent 2fb669e6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -378,7 +378,7 @@ public class LinkProperties implements Parcelable {
     * @return {@code true} if both are identical, {@code false} otherwise.
     */
    public boolean isIdenticalStackedLinks(LinkProperties target) {
        if (!mStackedLinks.keys().equals(target.mStackedLinks.keys())) {
        if (!mStackedLinks.keySet().equals(target.mStackedLinks.keySet())) {
            return false;
        }
        for (LinkProperties stacked : mStackedLinks.values()) {
+32 −8
Original line number Diff line number Diff line
@@ -33,14 +33,41 @@ public class LinkPropertiesTest extends TestCase {
    private static String GATEWAY2 = "69.78.8.1";
    private static String NAME = "qmi0";

    public void assertLinkPropertiesEqual(LinkProperties source, LinkProperties target) {
        // Check implementation of equals(), element by element.
        assertTrue(source.isIdenticalInterfaceName(target));
        assertTrue(target.isIdenticalInterfaceName(source));

        assertTrue(source.isIdenticalAddresses(target));
        assertTrue(target.isIdenticalAddresses(source));

        assertTrue(source.isIdenticalDnses(target));
        assertTrue(target.isIdenticalDnses(source));

        assertTrue(source.isIdenticalRoutes(target));
        assertTrue(target.isIdenticalRoutes(source));

        assertTrue(source.isIdenticalHttpProxy(target));
        assertTrue(target.isIdenticalHttpProxy(source));

        assertTrue(source.isIdenticalStackedLinks(target));
        assertTrue(target.isIdenticalStackedLinks(source));

        // Check result of equals().
        assertTrue(source.equals(target));
        assertTrue(target.equals(source));

        // Check hashCode.
        assertEquals(source.hashCode(), target.hashCode());
    }

    @SmallTest
    public void testEqualsNull() {
        LinkProperties source = new LinkProperties();
        LinkProperties target = new LinkProperties();

        assertFalse(source == target);
        assertTrue(source.equals(target));
        assertTrue(source.hashCode() == target.hashCode());
        assertLinkPropertiesEqual(source, target);
    }

    @SmallTest
@@ -73,8 +100,7 @@ public class LinkPropertiesTest extends TestCase {
            target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
            target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));

            assertTrue(source.equals(target));
            assertTrue(source.hashCode() == target.hashCode());
            assertLinkPropertiesEqual(source, target);

            target.clear();
            // change Interface Name
@@ -163,8 +189,7 @@ public class LinkPropertiesTest extends TestCase {
            target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
            target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));

            assertTrue(source.equals(target));
            assertTrue(source.hashCode() == target.hashCode());
            assertLinkPropertiesEqual(source, target);
        } catch (Exception e) {
            fail();
        }
@@ -191,8 +216,7 @@ public class LinkPropertiesTest extends TestCase {
            target.addLinkAddress(new LinkAddress(
                    NetworkUtils.numericToInetAddress(ADDRV6), 128));

            assertTrue(source.equals(target));
            assertTrue(source.hashCode() == target.hashCode());
            assertLinkPropertiesEqual(source, target);
        } catch (Exception e) {
            fail();
        }