@Test public void equalsHashCode() { /* Empty objects. */ DeviceExtension a = new DeviceExtension(); DeviceExtension b = new DeviceExtension(); checkEquals(a, b); /* Local ID. */ a.setLocalId("a1"); checkNotEquals(a, b); b.setLocalId("b1"); checkNotEquals(a, b); b.setLocalId("a1"); checkEquals(a, b); } }
@Override public void write(JSONStringer writer) throws JSONException { JSONUtils.write(writer, LOCAL_ID, getLocalId()); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Extensions that = (Extensions) o; if (metadata != null ? !metadata.equals(that.metadata) : that.metadata != null) return false; if (protocol != null ? !protocol.equals(that.protocol) : that.protocol != null) return false; if (user != null ? !user.equals(that.user) : that.user != null) return false; if (device != null ? !device.equals(that.device) : that.device != null) return false; if (os != null ? !os.equals(that.os) : that.os != null) return false; if (app != null ? !app.equals(that.app) : that.app != null) return false; if (net != null ? !net.equals(that.net) : that.net != null) return false; if (sdk != null ? !sdk.equals(that.sdk) : that.sdk != null) return false; return loc != null ? loc.equals(that.loc) : that.loc == null; }
@Test public void collectDeviceId() { CommonSchemaLog log = new CommonSchemaEventLog(); log.setExt(new Extensions()); log.getExt().setDevice(new DeviceExtension()); /* Mock context. */ mockStatic(Secure.class); when(Secure.getString(any(ContentResolver.class), anyString())).thenReturn("mockDeviceId"); /* Get property configurator and collect device ID. */ PropertyConfigurator pc = Analytics.getTransmissionTarget("test").getPropertyConfigurator(); pc.collectDeviceId(); /* Simulate what the pipeline does to convert from App Center to Common Schema. */ log.addTransmissionTarget("test"); log.setTag(Analytics.getTransmissionTarget("test")); pc.onPreparingLog(log, "groupName"); /* Assert device ID is collected. */ assertEquals("a:mockDeviceId", log.getExt().getDevice().getLocalId()); }
DeviceExtension device = new DeviceExtension(); device.read(object.getJSONObject(DEVICE)); setDevice(device);
@Test public void compareDifferentType() { TestUtils.compareSelfNullClass(new DeviceExtension()); }
@Override public void read(JSONObject object) { setLocalId(object.optString(LOCAL_ID, null)); }
@Override public int hashCode() { int result = metadata != null ? metadata.hashCode() : 0; result = 31 * result + (protocol != null ? protocol.hashCode() : 0); result = 31 * result + (user != null ? user.hashCode() : 0); result = 31 * result + (device != null ? device.hashCode() : 0); result = 31 * result + (os != null ? os.hashCode() : 0); result = 31 * result + (app != null ? app.hashCode() : 0); result = 31 * result + (net != null ? net.hashCode() : 0); result = 31 * result + (sdk != null ? sdk.hashCode() : 0); result = 31 * result + (loc != null ? loc.hashCode() : 0); return result; } }
getDevice().write(writer); writer.endObject();
@Test public void collectDeviceIdSavedWhenDisabled() { CommonSchemaLog log = new CommonSchemaEventLog(); log.setExt(new Extensions()); log.getExt().setDevice(new DeviceExtension()); /* Mock context. */ mockStatic(Secure.class); when(Secure.getString(any(ContentResolver.class), anyString())).thenReturn("mockDeviceId"); /* Disable Analytics. */ Analytics.setEnabled(false).get(); /* Get property configurator and collect device ID. */ PropertyConfigurator pc = Analytics.getTransmissionTarget("test").getPropertyConfigurator(); pc.collectDeviceId(); /* Simulate what the pipeline does to convert from App Center to Common Schema. */ log.addTransmissionTarget("test"); log.setTag(Analytics.getTransmissionTarget("test")); /* Enable and simulate log preparing. */ Analytics.setEnabled(true).get(); pc.onPreparingLog(log, "groupName"); /* Assert device ID is collected. */ assertEquals("a:mockDeviceId", log.getExt().getDevice().getLocalId()); }
dest.getExt().setDevice(new DeviceExtension());
device.setLocalId(ANDROID_DEVICE_ID_PREFIX + androidId);
DeviceExtension device = new DeviceExtension(); device.setLocalId("123"); a.setDevice(device); checkNotEquals(a, b); b.setDevice(new DeviceExtension()); checkNotEquals(a, b); b.setDevice(a.getDevice());
logBeforeSetProperty.getExt().setApp(new AppExtension()); logBeforeSetProperty.getExt().setUser(new UserExtension()); logBeforeSetProperty.getExt().setDevice(new DeviceExtension()); logAfterSetProperty.getExt().setApp(new AppExtension()); logAfterSetProperty.getExt().setUser(new UserExtension()); logAfterSetProperty.getExt().setDevice(new DeviceExtension()); assertNull(logBeforeSetProperty.getExt().getApp().getName()); assertNull(logBeforeSetProperty.getExt().getUser().getLocalId()); assertNull(logBeforeSetProperty.getExt().getDevice().getLocalId()); assertEquals("appName", logAfterSetProperty.getExt().getApp().getName()); assertEquals("c:alice", logAfterSetProperty.getExt().getUser().getLocalId()); assertEquals("a:mockDeviceId", logAfterSetProperty.getExt().getDevice().getLocalId());
log.getExt().setDevice(new DeviceExtension()); checkSerialization(serializer, log); log.getExt().getDevice().setLocalId("5DE1C5B8433DF3EE"); checkSerialization(serializer, log);