Commit aa797062 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android] Use ObjectsCompat.equals from support lib

This CL replaces ApiCompatibilityUtils.objectEquals and it's usages with
ObjectsCompat.equals method from Android support library. It also fixes
VisibleNetworksTest that had VisibleWifi objects in static field, as
it doesn't work well with Robolectric (ObjectsCompat.equals was
triggering a crash in that test, because it uses Build.VERSION.SDK_INT).

Bug: 782824
Change-Id: Ifba3325b2dd0102c3097e9dfcf0676d7a2c75fc6
Reviewed-on: https://chromium-review.googlesource.com/964663Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543848}
parent 168f828c
......@@ -699,15 +699,6 @@ public class ApiCompatibilityUtils {
return activity.isInMultiWindowMode();
}
/**
* Null-safe equivalent of {@code a.equals(b)}.
*
* @see Objects#equals(Object, Object)
*/
public static boolean objectEquals(Object a, Object b) {
return (a == null) ? (b == null) : a.equals(b);
}
/**
* Disables the Smart Select {@link TextClassifier} for the given {@link TextView} instance.
* @param textView The {@link TextView} that should have its classifier disabled.
......
......@@ -12,6 +12,7 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.v4.util.ObjectsCompat;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.Gravity;
......@@ -29,7 +30,6 @@ import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.util.MathUtils;
......@@ -226,7 +226,7 @@ public class ItemChooserDialog {
addToDescriptionsMap(oldItem.mDescription);
}
if (!ApiCompatibilityUtils.objectEquals(icon, oldItem.mIcon)) {
if (!ObjectsCompat.equals(icon, oldItem.mIcon)) {
oldItem.mIcon = icon;
oldItem.mIconDescription = iconDescription;
}
......
......@@ -10,8 +10,8 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.util.ObjectsCompat;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
......@@ -134,8 +134,7 @@ public class DelayedInvalidationsController {
PendingInvalidation invalidation =
PendingInvalidation.decodeToPendingInvalidation(encodedInvalidation);
if (invalidation == null) return false;
if (ApiCompatibilityUtils.objectEquals(
invalidation.mObjectId, newInvalidation.mObjectId)
if (ObjectsCompat.equals(invalidation.mObjectId, newInvalidation.mObjectId)
&& invalidation.mObjectSource == newInvalidation.mObjectSource) {
if (invalidation.mVersion >= newInvalidation.mVersion) return true;
iter.remove();
......
......@@ -14,6 +14,7 @@ import android.os.Process;
import android.os.SystemClock;
import android.provider.Settings;
import android.support.annotation.IntDef;
import android.support.v4.util.ObjectsCompat;
import android.util.Base64;
import org.chromium.base.ApiCompatibilityUtils;
......@@ -805,7 +806,7 @@ public class GeolocationHeader {
// Select the extra visible cell.
if (visibleCells != null) {
for (VisibleCell candidateCell : visibleCells) {
if (ApiCompatibilityUtils.objectEquals(connectedCell, candidateCell)) {
if (ObjectsCompat.equals(connectedCell, candidateCell)) {
// Do not include this candidate cell, since its already the connected one.
continue;
}
......@@ -821,7 +822,7 @@ public class GeolocationHeader {
// Do not include this candidate wifi.
continue;
}
if (ApiCompatibilityUtils.objectEquals(connectedWifi, candidateWifi)) {
if (ObjectsCompat.equals(connectedWifi, candidateWifi)) {
// Replace the connected, since the candidate will have level. This is because
// the android APIs exposing connected WIFI do not expose level, while the ones
// exposing visible wifis expose level.
......
......@@ -5,8 +5,7 @@
package org.chromium.chrome.browser.omnibox.geo;
import android.support.annotation.IntDef;
import org.chromium.base.ApiCompatibilityUtils;
import android.support.v4.util.ObjectsCompat;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
......@@ -101,10 +100,10 @@ class VisibleNetworks {
return false;
}
VisibleNetworks that = (VisibleNetworks) object;
return ApiCompatibilityUtils.objectEquals(mConnectedWifi, that.connectedWifi())
&& ApiCompatibilityUtils.objectEquals(mConnectedCell, that.connectedCell())
&& ApiCompatibilityUtils.objectEquals(mAllVisibleWifis, that.allVisibleWifis())
&& ApiCompatibilityUtils.objectEquals(mAllVisibleCells, that.allVisibleCells());
return ObjectsCompat.equals(mConnectedWifi, that.connectedWifi())
&& ObjectsCompat.equals(mConnectedCell, that.connectedCell())
&& ObjectsCompat.equals(mAllVisibleWifis, that.allVisibleWifis())
&& ObjectsCompat.equals(mAllVisibleCells, that.allVisibleCells());
}
private static int objectsHashCode(Object o) {
......@@ -193,8 +192,8 @@ class VisibleNetworks {
}
VisibleWifi that = (VisibleWifi) object;
return ApiCompatibilityUtils.objectEquals(mSsid, that.ssid())
&& ApiCompatibilityUtils.objectEquals(mBssid, that.bssid());
return ObjectsCompat.equals(mSsid, that.ssid())
&& ObjectsCompat.equals(mBssid, that.bssid());
}
@Override
......@@ -367,19 +366,14 @@ class VisibleNetworks {
return false;
}
VisibleCell that = (VisibleCell) object;
return ApiCompatibilityUtils.objectEquals(mRadioType, that.radioType())
&& ApiCompatibilityUtils.objectEquals(mCellId, that.cellId())
&& ApiCompatibilityUtils.objectEquals(
mLocationAreaCode, that.locationAreaCode())
&& ApiCompatibilityUtils.objectEquals(
mMobileCountryCode, that.mobileCountryCode())
&& ApiCompatibilityUtils.objectEquals(
mMobileNetworkCode, that.mobileNetworkCode())
&& ApiCompatibilityUtils.objectEquals(
mPrimaryScramblingCode, that.primaryScramblingCode())
&& ApiCompatibilityUtils.objectEquals(mPhysicalCellId, that.physicalCellId())
&& ApiCompatibilityUtils.objectEquals(
mTrackingAreaCode, that.trackingAreaCode());
return ObjectsCompat.equals(mRadioType, that.radioType())
&& ObjectsCompat.equals(mCellId, that.cellId())
&& ObjectsCompat.equals(mLocationAreaCode, that.locationAreaCode())
&& ObjectsCompat.equals(mMobileCountryCode, that.mobileCountryCode())
&& ObjectsCompat.equals(mMobileNetworkCode, that.mobileNetworkCode())
&& ObjectsCompat.equals(mPrimaryScramblingCode, that.primaryScramblingCode())
&& ObjectsCompat.equals(mPhysicalCellId, that.physicalCellId())
&& ObjectsCompat.equals(mTrackingAreaCode, that.trackingAreaCode());
}
@Override
......
......@@ -8,6 +8,7 @@ import android.app.Dialog;
import android.graphics.drawable.Drawable;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.test.filters.LargeTest;
import android.support.v4.util.ObjectsCompat;
import android.text.SpannableString;
import android.view.View;
import android.widget.Button;
......@@ -21,7 +22,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.RetryOnFailure;
......@@ -65,7 +65,7 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
mTestDrawable2 = getNewTestDrawable();
mTestDrawableDescription2 = "icon2 description";
Assert.assertFalse(ApiCompatibilityUtils.objectEquals(mTestDrawable1, mTestDrawable2));
Assert.assertFalse(ObjectsCompat.equals(mTestDrawable1, mTestDrawable2));
}
// ItemChooserDialog.ItemSelectedCallback:
......
......@@ -42,46 +42,45 @@ public class VisibleNetworksTest {
private static final int[] RADIO_TYPES = {VisibleCell.UNKNOWN_RADIO_TYPE,
VisibleCell.UNKNOWN_MISSING_LOCATION_PERMISSION_RADIO_TYPE, VisibleCell.CDMA_RADIO_TYPE,
VisibleCell.GSM_RADIO_TYPE, VisibleCell.LTE_RADIO_TYPE, VisibleCell.WCDMA_RADIO_TYPE};
private static final VisibleWifi VISIBLE_WIFI1 =
VisibleWifi.create(SSID1, BSSID1, LEVEL1, TIMESTAMP1);
private static final VisibleWifi VISIBLE_WIFI2 =
VisibleWifi.create(SSID2, BSSID2, LEVEL2, TIMESTAMP2);
private static VisibleCell.Builder sVisibleCellCommunBuilder =
private final VisibleWifi mVisibleWifi1 = VisibleWifi.create(SSID1, BSSID1, LEVEL1, TIMESTAMP1);
private final VisibleWifi mVisibleWifi2 = VisibleWifi.create(SSID2, BSSID2, LEVEL2, TIMESTAMP2);
private final VisibleCell.Builder mVisibleCellCommunBuilder =
VisibleCell.builder(VisibleCell.GSM_RADIO_TYPE)
.setCellId(10)
.setLocationAreaCode(11)
.setMobileCountryCode(12)
.setMobileNetworkCode(13);
private static final VisibleCell VISIBLE_CELL1 = sVisibleCellCommunBuilder.setPhysicalCellId(14)
private final VisibleCell mVisibleCell1 = mVisibleCellCommunBuilder.setPhysicalCellId(14)
.setPrimaryScramblingCode(15)
.setTrackingAreaCode(16)
.setTimestamp(10L)
.build();
private static final VisibleCell VISIBLE_CELL1_DIFFERENT_TIMESTAMP =
sVisibleCellCommunBuilder.setTimestamp(20L).build();
private static final VisibleCell VISIBLE_CELL2 = VisibleCell.builder(VisibleCell.GSM_RADIO_TYPE)
private final VisibleCell mVisibleCell1DifferentTimestamp =
mVisibleCellCommunBuilder.setTimestamp(20L).build();
private final VisibleCell mVisibleCell2 = VisibleCell.builder(VisibleCell.GSM_RADIO_TYPE)
.setCellId(30)
.setLocationAreaCode(31)
.setMobileCountryCode(32)
.setMobileNetworkCode(33)
.setTimestamp(30L)
.build();
private static final VisibleCell EMPTY_CELL =
private final VisibleCell mEmptyCell =
VisibleCell.builder(VisibleCell.UNKNOWN_RADIO_TYPE).build();
private static final VisibleWifi EMPTY_WIFI = VisibleWifi.create(null, null, null, null);
private final VisibleWifi mEmptyWifi = VisibleWifi.create(null, null, null, null);
private static Set<VisibleCell> sAllVisibleCells =
new HashSet<VisibleCell>(Arrays.asList(VISIBLE_CELL1, VISIBLE_CELL2));
private static Set<VisibleCell> sAllVisibleCells2 = new HashSet<VisibleCell>(
Arrays.asList(VISIBLE_CELL1, VISIBLE_CELL2, VISIBLE_CELL1_DIFFERENT_TIMESTAMP));
private static Set<VisibleWifi> sAllVisibleWifis =
new HashSet<VisibleWifi>(Arrays.asList(VISIBLE_WIFI1, VISIBLE_WIFI2));
private final Set<VisibleCell> mAllVisibleCells =
new HashSet<>(Arrays.asList(mVisibleCell1, mVisibleCell2));
private final Set<VisibleCell> mAllVisibleCells2 = new HashSet<>(
Arrays.asList(mVisibleCell1, mVisibleCell2, mVisibleCell1DifferentTimestamp));
private final Set<VisibleWifi> mAllVisibleWifis =
new HashSet<>(Arrays.asList(mVisibleWifi1, mVisibleWifi2));
private static final VisibleNetworks VISIBLE_NETWORKS1 = VisibleNetworks.create(
VISIBLE_WIFI1, VISIBLE_CELL1, sAllVisibleWifis, sAllVisibleCells);
private final VisibleNetworks mVisibleNetworks1 = VisibleNetworks.create(
mVisibleWifi1, mVisibleCell1, mAllVisibleWifis, mAllVisibleCells);
private static final VisibleNetworks VISIBLE_NETWORKS2 = VisibleNetworks.create(
VISIBLE_WIFI2, VISIBLE_CELL2, sAllVisibleWifis, sAllVisibleCells2);
private final VisibleNetworks mVisibleNetworks2 = VisibleNetworks.create(
mVisibleWifi2, mVisibleCell2, mAllVisibleWifis, mAllVisibleCells2);
private static final String VISIBLE_CELL1_PROTO_ENCODED =
"CAEQDLoBFhIQCAEQChgLIAwoDTAPOA5AEBgBIAo=";
......@@ -101,48 +100,48 @@ public class VisibleNetworksTest {
@Test
public void testVisibleWifiEquals() {
VisibleWifi copyOfVisibleWifi1 = VisibleWifi.create(VISIBLE_WIFI1.ssid(),
VISIBLE_WIFI1.bssid(), VISIBLE_WIFI1.level(), VISIBLE_WIFI1.timestampMs());
VisibleWifi copyOfVisibleWifi1 = VisibleWifi.create(mVisibleWifi1.ssid(),
mVisibleWifi1.bssid(), mVisibleWifi1.level(), mVisibleWifi1.timestampMs());
assertEquals(VISIBLE_WIFI1, copyOfVisibleWifi1);
assertNotEquals(VISIBLE_WIFI1, VISIBLE_WIFI2);
assertEquals(mVisibleWifi1, copyOfVisibleWifi1);
assertNotEquals(mVisibleWifi1, mVisibleWifi2);
}
@Test
public void testVisibleWifiEqualsDifferentLevelAndTimestamp() {
VisibleWifi visibleWifi3 = VisibleWifi.create(SSID2, BSSID2, LEVEL1, TIMESTAMP1);
// visibleWifi3 has the same ssid and bssid as VISIBLE_WIFI2 but different level and
// visibleWifi3 has the same ssid and bssid as mVisibleWifi2 but different level and
// timestamp. The level and timestamp are excluded from the VisibleWifi equality checks.
assertEquals(visibleWifi3, VISIBLE_WIFI2);
assertEquals(visibleWifi3, mVisibleWifi2);
}
@Test
public void testVisibleWifiHash() {
VisibleWifi copyOfVisibleWifi1 = VisibleWifi.create(VISIBLE_WIFI1.ssid(),
VISIBLE_WIFI1.bssid(), VISIBLE_WIFI1.level(), VISIBLE_WIFI1.timestampMs());
VisibleWifi copyOfVisibleWifi1 = VisibleWifi.create(mVisibleWifi1.ssid(),
mVisibleWifi1.bssid(), mVisibleWifi1.level(), mVisibleWifi1.timestampMs());
assertEquals(VISIBLE_WIFI1.hashCode(), copyOfVisibleWifi1.hashCode());
assertNotEquals(VISIBLE_WIFI1.hashCode(), VISIBLE_WIFI2.hashCode());
assertEquals(mVisibleWifi1.hashCode(), copyOfVisibleWifi1.hashCode());
assertNotEquals(mVisibleWifi1.hashCode(), mVisibleWifi2.hashCode());
}
@Test
public void testVisibleWifiHashDifferentLevelAndTimestamp() {
VisibleWifi visibleWifi3 = VisibleWifi.create(SSID2, BSSID2, LEVEL1, TIMESTAMP1);
// visibleWifi3 has the same ssid and bssid as VISIBLE_WIFI2 but different level and
// visibleWifi3 has the same ssid and bssid as mVisibleWifi2 but different level and
// timestamp. The level and timestamp are excluded from the VisibleWifi hash function.
assertEquals(VISIBLE_WIFI2.hashCode(), visibleWifi3.hashCode());
assertEquals(mVisibleWifi2.hashCode(), visibleWifi3.hashCode());
}
@Test
public void testVisibleWifiToProto() {
boolean connected = true;
PartnerLocationDescriptor.VisibleNetwork visibleNetwork = VISIBLE_WIFI1.toProto(connected);
PartnerLocationDescriptor.VisibleNetwork visibleNetwork = mVisibleWifi1.toProto(connected);
PartnerLocationDescriptor.VisibleNetwork.WiFi wifi = visibleNetwork.getWifi();
assertEquals(VISIBLE_WIFI1.bssid(), wifi.getBssid());
assertEquals(VISIBLE_WIFI1.level().intValue(), wifi.getLevelDbm());
assertEquals(VISIBLE_WIFI1.timestampMs().longValue(), visibleNetwork.getTimestampMs());
assertEquals(mVisibleWifi1.bssid(), wifi.getBssid());
assertEquals(mVisibleWifi1.level().intValue(), wifi.getLevelDbm());
assertEquals(mVisibleWifi1.timestampMs().longValue(), visibleNetwork.getTimestampMs());
assertEquals(connected, visibleNetwork.getConnected());
assertEquals(VISIBLE_WIFI1_PROTO_ENCODED, encodeVisibleNetwork(visibleNetwork));
......@@ -151,7 +150,7 @@ public class VisibleNetworksTest {
@Test
public void testVisibleWifiToProtoEmptyWifi() {
boolean connected = true;
PartnerLocationDescriptor.VisibleNetwork visibleNetwork = EMPTY_WIFI.toProto(connected);
PartnerLocationDescriptor.VisibleNetwork visibleNetwork = mEmptyWifi.toProto(connected);
PartnerLocationDescriptor.VisibleNetwork.WiFi wifi = visibleNetwork.getWifi();
assertFalse(wifi.hasBssid());
......@@ -173,65 +172,65 @@ public class VisibleNetworksTest {
@Test
public void testVisibleCellEquals() {
VisibleCell copyOfVisibleCell1 =
VisibleCell.builder(VISIBLE_CELL1.radioType())
.setCellId(VISIBLE_CELL1.cellId())
.setLocationAreaCode(VISIBLE_CELL1.locationAreaCode())
.setMobileCountryCode(VISIBLE_CELL1.mobileCountryCode())
.setMobileNetworkCode(VISIBLE_CELL1.mobileNetworkCode())
.setPhysicalCellId(VISIBLE_CELL1.physicalCellId())
.setPrimaryScramblingCode(VISIBLE_CELL1.primaryScramblingCode())
.setTrackingAreaCode(VISIBLE_CELL1.trackingAreaCode())
.setTimestamp(VISIBLE_CELL1.timestampMs())
VisibleCell.builder(mVisibleCell1.radioType())
.setCellId(mVisibleCell1.cellId())
.setLocationAreaCode(mVisibleCell1.locationAreaCode())
.setMobileCountryCode(mVisibleCell1.mobileCountryCode())
.setMobileNetworkCode(mVisibleCell1.mobileNetworkCode())
.setPhysicalCellId(mVisibleCell1.physicalCellId())
.setPrimaryScramblingCode(mVisibleCell1.primaryScramblingCode())
.setTrackingAreaCode(mVisibleCell1.trackingAreaCode())
.setTimestamp(mVisibleCell1.timestampMs())
.build();
assertNotEquals(VISIBLE_CELL2, VISIBLE_CELL1);
assertEquals(VISIBLE_CELL1, copyOfVisibleCell1);
assertNotEquals(mVisibleCell2, mVisibleCell1);
assertEquals(mVisibleCell1, copyOfVisibleCell1);
}
@Test
public void testVisibleCellEqualsDifferentTimestamp() {
// The timestamp is not included in the VisibleCell equality checks.
assertEquals(VISIBLE_CELL1, VISIBLE_CELL1_DIFFERENT_TIMESTAMP);
assertEquals(mVisibleCell1, mVisibleCell1DifferentTimestamp);
}
@Test
public void testVisibleCellHash() {
VisibleCell copyOfVisibleCell1 =
VisibleCell.builder(VISIBLE_CELL1.radioType())
.setCellId(VISIBLE_CELL1.cellId())
.setLocationAreaCode(VISIBLE_CELL1.locationAreaCode())
.setMobileCountryCode(VISIBLE_CELL1.mobileCountryCode())
.setMobileNetworkCode(VISIBLE_CELL1.mobileNetworkCode())
.setPhysicalCellId(VISIBLE_CELL1.physicalCellId())
.setPrimaryScramblingCode(VISIBLE_CELL1.primaryScramblingCode())
.setTrackingAreaCode(VISIBLE_CELL1.trackingAreaCode())
.setTimestamp(VISIBLE_CELL1.timestampMs())
VisibleCell.builder(mVisibleCell1.radioType())
.setCellId(mVisibleCell1.cellId())
.setLocationAreaCode(mVisibleCell1.locationAreaCode())
.setMobileCountryCode(mVisibleCell1.mobileCountryCode())
.setMobileNetworkCode(mVisibleCell1.mobileNetworkCode())
.setPhysicalCellId(mVisibleCell1.physicalCellId())
.setPrimaryScramblingCode(mVisibleCell1.primaryScramblingCode())
.setTrackingAreaCode(mVisibleCell1.trackingAreaCode())
.setTimestamp(mVisibleCell1.timestampMs())
.build();
assertEquals(VISIBLE_CELL1.hashCode(), copyOfVisibleCell1.hashCode());
assertNotEquals(VISIBLE_CELL2.hashCode(), VISIBLE_CELL1.hashCode());
assertEquals(mVisibleCell1.hashCode(), copyOfVisibleCell1.hashCode());
assertNotEquals(mVisibleCell2.hashCode(), mVisibleCell1.hashCode());
}
@Test
public void testVisibleCellHashDifferentTimestamp() {
// The timestamp is not included in the VisibleCell hash function.
assertEquals(VISIBLE_CELL1.hashCode(), VISIBLE_CELL1_DIFFERENT_TIMESTAMP.hashCode());
assertEquals(mVisibleCell1.hashCode(), mVisibleCell1DifferentTimestamp.hashCode());
}
@Test
public void testVisibleCellToProto() {
boolean connected = true;
PartnerLocationDescriptor.VisibleNetwork visibleNetwork = VISIBLE_CELL1.toProto(connected);
PartnerLocationDescriptor.VisibleNetwork visibleNetwork = mVisibleCell1.toProto(connected);
PartnerLocationDescriptor.VisibleNetwork.Cell cell = visibleNetwork.getCell();
assertEquals(VISIBLE_CELL1.cellId().intValue(), cell.getCellId());
assertEquals(VISIBLE_CELL1.locationAreaCode().intValue(), cell.getLocationAreaCode());
assertEquals(VISIBLE_CELL1.mobileCountryCode().intValue(), cell.getMobileCountryCode());
assertEquals(VISIBLE_CELL1.mobileNetworkCode().intValue(), cell.getMobileNetworkCode());
assertEquals(mVisibleCell1.cellId().intValue(), cell.getCellId());
assertEquals(mVisibleCell1.locationAreaCode().intValue(), cell.getLocationAreaCode());
assertEquals(mVisibleCell1.mobileCountryCode().intValue(), cell.getMobileCountryCode());
assertEquals(mVisibleCell1.mobileNetworkCode().intValue(), cell.getMobileNetworkCode());
assertEquals(
VISIBLE_CELL1.primaryScramblingCode().intValue(), cell.getPrimaryScramblingCode());
assertEquals(VISIBLE_CELL1.physicalCellId().intValue(), cell.getPhysicalCellId());
assertEquals(VISIBLE_CELL1.trackingAreaCode().intValue(), cell.getTrackingAreaCode());
assertEquals(VISIBLE_CELL1.timestampMs().longValue(), visibleNetwork.getTimestampMs());
mVisibleCell1.primaryScramblingCode().intValue(), cell.getPrimaryScramblingCode());
assertEquals(mVisibleCell1.physicalCellId().intValue(), cell.getPhysicalCellId());
assertEquals(mVisibleCell1.trackingAreaCode().intValue(), cell.getTrackingAreaCode());
assertEquals(mVisibleCell1.timestampMs().longValue(), visibleNetwork.getTimestampMs());
assertEquals(connected, visibleNetwork.getConnected());
assertEquals(PartnerLocationDescriptor.VisibleNetwork.Cell.Type.GSM, cell.getType());
......@@ -241,7 +240,7 @@ public class VisibleNetworksTest {
@Test
public void testVisibleCellToProtoEmptyCell() {
boolean connected = true;
PartnerLocationDescriptor.VisibleNetwork visibleNetwork = EMPTY_CELL.toProto(connected);
PartnerLocationDescriptor.VisibleNetwork visibleNetwork = mEmptyCell.toProto(connected);
PartnerLocationDescriptor.VisibleNetwork.Cell cell = visibleNetwork.getCell();
assertEquals(PartnerLocationDescriptor.VisibleNetwork.Cell.Type.UNKNOWN, cell.getType());
......@@ -261,13 +260,13 @@ public class VisibleNetworksTest {
@Test
public void testVisibleNetworksCreate() {
Set<VisibleCell> expectedVisibleCells =
new HashSet<VisibleCell>(Arrays.asList(VISIBLE_CELL1, VISIBLE_CELL2));
new HashSet<VisibleCell>(Arrays.asList(mVisibleCell1, mVisibleCell2));
Set<VisibleWifi> expectedVisibleWifis =
new HashSet<VisibleWifi>(Arrays.asList(VISIBLE_WIFI1, VISIBLE_WIFI2));
new HashSet<VisibleWifi>(Arrays.asList(mVisibleWifi1, mVisibleWifi2));
VisibleNetworks visibleNetworks = VisibleNetworks.create(
VISIBLE_WIFI1, VISIBLE_CELL1, expectedVisibleWifis, expectedVisibleCells);
assertEquals(VISIBLE_WIFI1, visibleNetworks.connectedWifi());
assertEquals(VISIBLE_CELL1, visibleNetworks.connectedCell());
mVisibleWifi1, mVisibleCell1, expectedVisibleWifis, expectedVisibleCells);
assertEquals(mVisibleWifi1, visibleNetworks.connectedWifi());
assertEquals(mVisibleCell1, visibleNetworks.connectedCell());
assertEquals(expectedVisibleWifis, visibleNetworks.allVisibleWifis());
assertEquals(expectedVisibleCells, visibleNetworks.allVisibleCells());
}
......@@ -275,28 +274,28 @@ public class VisibleNetworksTest {
@Test
public void testVisibleNetworksEquals() {
VisibleNetworks copyOfVisibleNetworks1 = VisibleNetworks.create(
VISIBLE_NETWORKS1.connectedWifi(), VISIBLE_NETWORKS1.connectedCell(),
VISIBLE_NETWORKS1.allVisibleWifis(), VISIBLE_NETWORKS1.allVisibleCells());
mVisibleNetworks1.connectedWifi(), mVisibleNetworks1.connectedCell(),
mVisibleNetworks1.allVisibleWifis(), mVisibleNetworks1.allVisibleCells());
assertEquals(VISIBLE_NETWORKS1, copyOfVisibleNetworks1);
assertNotEquals(VISIBLE_NETWORKS1, VISIBLE_NETWORKS2);
assertEquals(mVisibleNetworks1, copyOfVisibleNetworks1);
assertNotEquals(mVisibleNetworks1, mVisibleNetworks2);
}
@Test
public void testVisibleNetworksHash() {
VisibleNetworks copyOfVisibleNetworks1 = VisibleNetworks.create(
VISIBLE_NETWORKS1.connectedWifi(), VISIBLE_NETWORKS1.connectedCell(),
VISIBLE_NETWORKS1.allVisibleWifis(), VISIBLE_NETWORKS1.allVisibleCells());
mVisibleNetworks1.connectedWifi(), mVisibleNetworks1.connectedCell(),
mVisibleNetworks1.allVisibleWifis(), mVisibleNetworks1.allVisibleCells());
assertEquals(VISIBLE_NETWORKS1.hashCode(), copyOfVisibleNetworks1.hashCode());
assertNotEquals(VISIBLE_NETWORKS1.hashCode(), VISIBLE_NETWORKS2.hashCode());
assertEquals(mVisibleNetworks1.hashCode(), copyOfVisibleNetworks1.hashCode());
assertNotEquals(mVisibleNetworks1.hashCode(), mVisibleNetworks2.hashCode());
}
@Test
public void testVisibleNetworksIsEmpty() {
VisibleNetworks visibleNetworks = VisibleNetworks.create(null, null, null, null);
assertTrue(visibleNetworks.isEmpty());
assertFalse(VISIBLE_NETWORKS1.isEmpty());
assertFalse(mVisibleNetworks1.isEmpty());
}
private static String encodeVisibleNetwork(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment