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