am 6c2e8fb4: Merge "Fix LinkProperties\'s equals() method." into jb-mr2-dev
* commit '6c2e8fb4d530c5fb1352e8667449591b39d89c5a': Fix LinkProperties's equals() method.
This commit is contained in:
@@ -378,7 +378,7 @@ public class LinkProperties implements Parcelable {
|
|||||||
* @return {@code true} if both are identical, {@code false} otherwise.
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean isIdenticalStackedLinks(LinkProperties target) {
|
public boolean isIdenticalStackedLinks(LinkProperties target) {
|
||||||
if (!mStackedLinks.keys().equals(target.mStackedLinks.keys())) {
|
if (!mStackedLinks.keySet().equals(target.mStackedLinks.keySet())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (LinkProperties stacked : mStackedLinks.values()) {
|
for (LinkProperties stacked : mStackedLinks.values()) {
|
||||||
|
|||||||
@@ -33,14 +33,41 @@ public class LinkPropertiesTest extends TestCase {
|
|||||||
private static String GATEWAY2 = "69.78.8.1";
|
private static String GATEWAY2 = "69.78.8.1";
|
||||||
private static String NAME = "qmi0";
|
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
|
@SmallTest
|
||||||
public void testEqualsNull() {
|
public void testEqualsNull() {
|
||||||
LinkProperties source = new LinkProperties();
|
LinkProperties source = new LinkProperties();
|
||||||
LinkProperties target = new LinkProperties();
|
LinkProperties target = new LinkProperties();
|
||||||
|
|
||||||
assertFalse(source == target);
|
assertFalse(source == target);
|
||||||
assertTrue(source.equals(target));
|
assertLinkPropertiesEqual(source, target);
|
||||||
assertTrue(source.hashCode() == target.hashCode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
@@ -73,8 +100,7 @@ public class LinkPropertiesTest extends TestCase {
|
|||||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
||||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
||||||
|
|
||||||
assertTrue(source.equals(target));
|
assertLinkPropertiesEqual(source, target);
|
||||||
assertTrue(source.hashCode() == target.hashCode());
|
|
||||||
|
|
||||||
target.clear();
|
target.clear();
|
||||||
// change Interface Name
|
// 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(GATEWAY2)));
|
||||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
||||||
|
|
||||||
assertTrue(source.equals(target));
|
assertLinkPropertiesEqual(source, target);
|
||||||
assertTrue(source.hashCode() == target.hashCode());
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
@@ -191,8 +216,7 @@ public class LinkPropertiesTest extends TestCase {
|
|||||||
target.addLinkAddress(new LinkAddress(
|
target.addLinkAddress(new LinkAddress(
|
||||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
||||||
|
|
||||||
assertTrue(source.equals(target));
|
assertLinkPropertiesEqual(source, target);
|
||||||
assertTrue(source.hashCode() == target.hashCode());
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user