From 1f02531c4a4019ff21efd1ccabdbcb2aa5eda6d7 Mon Sep 17 00:00:00 2001 From: Aaron Kromer Date: Tue, 12 Dec 2017 16:59:54 -0500 Subject: [PATCH 1/5] Include running average in Parcel data This fixes a minor issue where the running average is not set after restoring a beacon from a parcel. Looking at the history it seems that the running average was an internal detail until #479 where support was added for running the service in a separate process. Part of the reason this needs to be included is that on Android 8.0 the running average _is_ restored and available for access. The reason the behavior is different across Android versions is in the way a service intent versus local notification handles the data `Bundle` (i.e. which [`Callback`](https://github.com/AltBeacon/android-beacon-library/blob/2.12.3/src/main/java/org/altbeacon/beacon/service/Callback.java#L58-L86) branch runs). Explicitly setting the `BeaconManager` to use scheduled scan jobs, forcing the first conditional code path using local notifications, allows the running average to be available on older versions. --- CHANGELOG.md | 6 +- .../java/org/altbeacon/beacon/Beacon.java | 3 + .../java/org/altbeacon/beacon/BeaconTest.java | 63 +++++++++++++++++++ .../beacon/service/RangingDataTest.java | 13 +++- 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e3cdcf00..200b50e91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ Bug Fixes: Identifier#toHexString(). (#615, David G. Young) - Fix regression with `RunningAverageRssiFilter.setSampleExpirationMilliseconds` being overwritten when committing ranged beacon measurements. (#629, Aaron Kromer) + - Fix missing running average RSSI in callbacks when apps do not use the + scheduled scan job feature. (#630, Aaron Kromer) ### 2.12.3 / 2017-10-14 @@ -13,7 +15,7 @@ Bug Fixes: Bug Fixes: - Fix NullPointerException in ProcessUtils. (#598, David G. Young) - Fix ConcurrentModificationException crashing app on Android 8 when monitored regions are - changed at the same time the app shifts from active scanning to passive scanning. + changed at the same time the app shifts from active scanning to passive scanning. (#578, David G. Young) - Fix ConcurrentModifictionExceptions starting ScanJobs. (#584, #588, David G. Young) - Fix NullPointerException when BluetoothLeScanner cannot be obtained. @@ -50,7 +52,7 @@ Bug Fixes: [Full Changelog](https://github.com/AltBeacon/android-beacon-library/compare/2.11...2.12) Enhancements: - - Add Android O support with ScanJob using JobScheduler to do scans instead of BeaconService, + - Add Android O support with ScanJob using JobScheduler to do scans instead of BeaconService, set as default for Android O. (#484, David G. Young) Bug Fixes: diff --git a/src/main/java/org/altbeacon/beacon/Beacon.java b/src/main/java/org/altbeacon/beacon/Beacon.java index 8e1f183fd..4a3161297 100644 --- a/src/main/java/org/altbeacon/beacon/Beacon.java +++ b/src/main/java/org/altbeacon/beacon/Beacon.java @@ -244,6 +244,8 @@ protected Beacon(Parcel in) { mBluetoothName = in.readString(); mParserIdentifier = in.readString(); mMultiFrameBeacon = in.readByte() != 0; + double tmpAverageRssi = in.readDouble(); + mRunningAverageRssi = tmpAverageRssi < Double.MAX_VALUE ? tmpAverageRssi : null; } /** @@ -584,6 +586,7 @@ public void writeToParcel(Parcel out, int flags) { out.writeString(mBluetoothName); out.writeString(mParserIdentifier); out.writeByte((byte) (mMultiFrameBeacon ? 1: 0)); + out.writeDouble(null == mRunningAverageRssi ? Double.MAX_VALUE : mRunningAverageRssi); } /** diff --git a/src/test/java/org/altbeacon/beacon/BeaconTest.java b/src/test/java/org/altbeacon/beacon/BeaconTest.java index d95fb0e72..4456543c5 100644 --- a/src/test/java/org/altbeacon/beacon/BeaconTest.java +++ b/src/test/java/org/altbeacon/beacon/BeaconTest.java @@ -1,11 +1,18 @@ package org.altbeacon.beacon; +import android.os.Parcel; + import org.altbeacon.beacon.distance.ModelSpecificDistanceCalculator; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasProperty; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -35,11 +42,21 @@ 4. Expand the System.err section */ public class BeaconTest { + private Parcel aParcel = null; @Before public void before() { Beacon.setHardwareEqualityEnforced(false); } + + @After + public void after() { + // Clean up any obtained parcel + if (null != aParcel) { + aParcel.recycle(); + } + } + @Test public void testAccessBeaconIdentifiers() { Beacon beacon = new AltBeacon.Builder().setMfgReserved(7).setId1("1").setId2("2").setId3("3").setRssi(4) @@ -206,6 +223,52 @@ public void testHashCodeWithNullIdentifier() { .build(); assertTrue("hashCode() should not throw exception", beacon.hashCode() >= Integer.MIN_VALUE); } + + @Test + public void parcelingBeaconContainsAllFields() { + final Beacon original = new Beacon.Builder().setBluetoothAddress("aa:bb:cc:dd:ee:ff") + .setBluetoothName("Any Bluetooth") + .setBeaconTypeCode(1) + .setDataFields(Arrays.asList(2L, 3L)) + .setExtraDataFields(Arrays.asList(4L, 5L)) + .setId1("6") + .setId2("7") + .setId3("8") + .setManufacturer(10) + .setMultiFrameBeacon(true) + .setParserIdentifier("Any Parser ID") + .setRssi(-11) + .setRunningAverageRssi(-12.3) + .setServiceUuid(13) + .setTxPower(14) + .build(); + + aParcel = Parcel.obtain(); + original.writeToParcel(aParcel, 0); + aParcel.setDataPosition(0); + final Beacon parceled = Beacon.CREATOR.createFromParcel(aParcel); + assertThat( + parceled, + allOf( + hasProperty("bluetoothAddress", equalTo("aa:bb:cc:dd:ee:ff")), + hasProperty("bluetoothName", equalTo("Any Bluetooth")), + hasProperty("beaconTypeCode", equalTo(1)), + hasProperty("dataFields", equalTo(Arrays.asList(2L, 3L))), + hasProperty("extraDataFields", equalTo(Arrays.asList(4L, 5L))), + hasProperty("id1", equalTo(Identifier.fromInt(6))), + hasProperty("id2", equalTo(Identifier.fromInt(7))), + hasProperty("id3", equalTo(Identifier.fromInt(8))), + hasProperty("manufacturer", equalTo(10)), + hasProperty("multiFrameBeacon", equalTo(true)), + hasProperty("parserIdentifier", equalTo("Any Parser ID")), + hasProperty("rssi", equalTo(-11)), + hasProperty("runningAverageRssi", equalTo(-12.3)), + hasProperty("serviceUuid", equalTo(13)), + hasProperty("txPower", equalTo(14)) + ) + ); + } + // utilty methods for testing serialization private byte[] convertToBytes(Object object) throws IOException { diff --git a/src/test/java/org/altbeacon/beacon/service/RangingDataTest.java b/src/test/java/org/altbeacon/beacon/service/RangingDataTest.java index 403cd9553..7a7264d2c 100644 --- a/src/test/java/org/altbeacon/beacon/service/RangingDataTest.java +++ b/src/test/java/org/altbeacon/beacon/service/RangingDataTest.java @@ -41,7 +41,12 @@ public void testSerialization() throws Exception { identifiers.add(Identifier.parse("2")); Region region = new Region("testRegion", identifiers); ArrayList beacons = new ArrayList(); - Beacon beacon = new Beacon.Builder().setIdentifiers(identifiers).setRssi(-1).setRunningAverageRssi(-2).setTxPower(-50).setBluetoothAddress("01:02:03:04:05:06").build(); + Beacon beacon = new Beacon.Builder().setIdentifiers(identifiers) + .setRssi(-1) + .setRunningAverageRssi(-2) + .setTxPower(-50) + .setBluetoothAddress("01:02:03:04:05:06") + .build(); for (int i=0; i < 10; i++) { beacons.add(beacon); } @@ -49,8 +54,12 @@ public void testSerialization() throws Exception { Bundle bundle = data.toBundle(); RangingData data2 = RangingData.fromBundle(bundle); assertEquals("beacon count shouild be restored", 10, data2.getBeacons().size()); - assertEquals("beacon identifier 1 shouild be restored", "2f234454-cf6d-4a0f-adf2-f4911ba9ffa6", data2.getBeacons().iterator().next().getId1().toString()); assertEquals("region identifier 1 shouild be restored", "2f234454-cf6d-4a0f-adf2-f4911ba9ffa6", data2.getRegion().getId1().toString()); + Beacon restoredBeacon = data2.getBeacons().iterator().next(); + assertEquals("beacon identifier 1 shouild be restored", "2f234454-cf6d-4a0f-adf2-f4911ba9ffa6", restoredBeacon.getId1().toString()); + assertEquals("RSSI is restored", -1, restoredBeacon.getRssi()); + assertEquals("Average RSSI is restored", -2.0, restoredBeacon.getRunningAverageRssi(), 0.0); + assertEquals("TXPower is restored", -50, restoredBeacon.getTxPower()); } @Test From ec07eb4e680e56dde6f6e32fb19e4c34c3640af3 Mon Sep 17 00:00:00 2001 From: Aaron Kromer Date: Tue, 12 Dec 2017 18:04:49 -0500 Subject: [PATCH 2/5] Add omitted fields in copy beacon constructor It's unclear why `mManufacturer` wasn't included with the copy constructor originally. However, as it's an internal field which is also included in the serialization and parceling it probably should be copied here too. The `mMultiFrameBeacon` field was added later to provide better support for beacons with extra data packets (#387). It's likely this was just overlooked as most of the "copying" of beacons occurred through parceling at the time. --- CHANGELOG.md | 1 + .../java/org/altbeacon/beacon/Beacon.java | 2 + .../java/org/altbeacon/beacon/BeaconTest.java | 44 ++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 200b50e91..2cf32eb35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Bug Fixes: being overwritten when committing ranged beacon measurements. (#629, Aaron Kromer) - Fix missing running average RSSI in callbacks when apps do not use the scheduled scan job feature. (#630, Aaron Kromer) + - Fix copying of multi-frame beacon flag in `Beacon(Beacon)` constructor (#630, Aaron Kromer) ### 2.12.3 / 2017-10-14 diff --git a/src/main/java/org/altbeacon/beacon/Beacon.java b/src/main/java/org/altbeacon/beacon/Beacon.java index 4a3161297..eda74a7bc 100644 --- a/src/main/java/org/altbeacon/beacon/Beacon.java +++ b/src/main/java/org/altbeacon/beacon/Beacon.java @@ -266,6 +266,8 @@ protected Beacon(Beacon otherBeacon) { this.mServiceUuid = otherBeacon.getServiceUuid(); this.mBluetoothName = otherBeacon.mBluetoothName; this.mParserIdentifier = otherBeacon.mParserIdentifier; + this.mMultiFrameBeacon = otherBeacon.mMultiFrameBeacon; + this.mManufacturer = otherBeacon.mManufacturer; } /** diff --git a/src/test/java/org/altbeacon/beacon/BeaconTest.java b/src/test/java/org/altbeacon/beacon/BeaconTest.java index 4456543c5..acd041452 100644 --- a/src/test/java/org/altbeacon/beacon/BeaconTest.java +++ b/src/test/java/org/altbeacon/beacon/BeaconTest.java @@ -268,7 +268,49 @@ public void parcelingBeaconContainsAllFields() { ) ); } - + + @Test + public void copyingBeaconContainsAllFields() { + final Beacon original = new Beacon.Builder().setBluetoothAddress("aa:bb:cc:dd:ee:ff") + .setBluetoothName("Any Bluetooth") + .setBeaconTypeCode(1) + .setDataFields(Arrays.asList(2L, 3L)) + .setExtraDataFields(Arrays.asList(4L, 5L)) + .setId1("6") + .setId2("7") + .setId3("8") + .setManufacturer(10) + .setMultiFrameBeacon(true) + .setParserIdentifier("Any Parser ID") + .setRssi(-11) + .setRunningAverageRssi(-12.3) + .setServiceUuid(13) + .setTxPower(14) + .build(); + + final Beacon copied = new Beacon(original); + assertThat( + copied, + allOf( + hasProperty("bluetoothAddress", equalTo("aa:bb:cc:dd:ee:ff")), + hasProperty("bluetoothName", equalTo("Any Bluetooth")), + hasProperty("beaconTypeCode", equalTo(1)), + hasProperty("dataFields", equalTo(Arrays.asList(2L, 3L))), + hasProperty("extraDataFields", equalTo(Arrays.asList(4L, 5L))), + hasProperty("id1", equalTo(Identifier.fromInt(6))), + hasProperty("id2", equalTo(Identifier.fromInt(7))), + hasProperty("id3", equalTo(Identifier.fromInt(8))), + hasProperty("manufacturer", equalTo(10)), + hasProperty("multiFrameBeacon", equalTo(true)), + hasProperty("parserIdentifier", equalTo("Any Parser ID")), + hasProperty("rssi", equalTo(-11)), + hasProperty("runningAverageRssi", equalTo(-12.3)), + hasProperty("serviceUuid", equalTo(13)), + hasProperty("txPower", equalTo(14)) + ) + ); + } + // utilty methods for testing serialization private byte[] convertToBytes(Object object) throws IOException { From 29fd2ac426aa820280f185724f10bea03adb344d Mon Sep 17 00:00:00 2001 From: Aaron Kromer Date: Tue, 12 Dec 2017 17:46:26 -0500 Subject: [PATCH 3/5] Whitespace only update --- .../org/altbeacon/beacon/AltBeaconTest.java | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/test/java/org/altbeacon/beacon/AltBeaconTest.java b/src/test/java/org/altbeacon/beacon/AltBeaconTest.java index 2519ad132..3710e5e47 100644 --- a/src/test/java/org/altbeacon/beacon/AltBeaconTest.java +++ b/src/test/java/org/altbeacon/beacon/AltBeaconTest.java @@ -27,32 +27,31 @@ */ public class AltBeaconTest { - public static byte[] hexStringToByteArray(String s) { - int len = s.length(); - byte[] data = new byte[len / 2]; - for (int i = 0; i < len; i += 2) { - data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) - + Character.digit(s.charAt(i+1), 16)); - } - return data; - } - - @Test - public void testRecognizeBeacon() { - byte[] bytes = hexStringToByteArray("02011a1bff1801beac2f234454cf6d4a0fadf2f4911ba9ffa600010002c509"); - AltBeaconParser parser = new AltBeaconParser(); - Beacon beacon = parser.fromScanData(bytes, -55, null); - assertEquals("manData should be parsed", 9, ((AltBeacon) beacon).getMfgReserved() ); - } + public static byte[] hexStringToByteArray(String s) { + int len = s.length(); + byte[] data = new byte[len / 2]; + for (int i = 0; i < len; i += 2) { + data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + + Character.digit(s.charAt(i+1), 16)); + } + return data; + } + @Test + public void testRecognizeBeacon() { + byte[] bytes = hexStringToByteArray("02011a1bff1801beac2f234454cf6d4a0fadf2f4911ba9ffa600010002c509"); + AltBeaconParser parser = new AltBeaconParser(); + Beacon beacon = parser.fromScanData(bytes, -55, null); + assertEquals("manData should be parsed", 9, ((AltBeacon) beacon).getMfgReserved() ); + } @Test public void testCanSerializeParcelable() { org.robolectric.shadows.ShadowLog.stream = System.err; Parcel parcel = Parcel.obtain(); Beacon beacon = new AltBeacon.Builder().setMfgReserved(7).setId1("1").setId2("2").setId3("3").setRssi(4) - .setBeaconTypeCode(5).setTxPower(6) - .setBluetoothAddress("1:2:3:4:5:6").build(); + .setBeaconTypeCode(5).setTxPower(6) + .setBluetoothAddress("1:2:3:4:5:6").build(); beacon.writeToParcel(parcel, 0); parcel.setDataPosition(0); Beacon beacon2 = new AltBeacon(parcel); From 49df8a757eeb748af76d8e26e6e2d2319bb7aa5c Mon Sep 17 00:00:00 2001 From: Aaron Kromer Date: Tue, 12 Dec 2017 17:33:17 -0500 Subject: [PATCH 4/5] Delegate `AltBeacon` constructors to parent It's unclear from the history why only some of the fields are part of the `AltBeacon` constructor. When initially implemented the constructor omitted copying `mRunningAverageRssi` and `mManufacturer`. Since then several additional data fields were added which are also not in the `AltBeacon` constructor: - `mExtraDataFields` - `mServiceUuid` - `mBluetoothName` - `mParserIdentifier` - `mMultiFrameBeacon` The only real change in this subclass seems to be the additional custom getter `getMfgReserved`. Based on the fact that the parceling logic and the builder all delegate to `Beacon` it seems reasonable that the general intended logic was to wrap the parent class. This fixes the two constructors so that all setup is based on the `Beacon` implementation. This ensures that any changes in `Beacon` are reflected by `AltBeacon` as well. --- CHANGELOG.md | 1 + .../java/org/altbeacon/beacon/AltBeacon.java | 10 +- .../org/altbeacon/beacon/AltBeaconTest.java | 118 +++++++++++++++--- 3 files changed, 107 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cf32eb35..b4952f12d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Bug Fixes: - Fix missing running average RSSI in callbacks when apps do not use the scheduled scan job feature. (#630, Aaron Kromer) - Fix copying of multi-frame beacon flag in `Beacon(Beacon)` constructor (#630, Aaron Kromer) + - Fix the `AltBeaon(Beacon)` copy constructor which omitted some data fields (#630, Aaron Kromer) ### 2.12.3 / 2017-10-14 diff --git a/src/main/java/org/altbeacon/beacon/AltBeacon.java b/src/main/java/org/altbeacon/beacon/AltBeacon.java index 891829e81..ccfd27775 100644 --- a/src/main/java/org/altbeacon/beacon/AltBeacon.java +++ b/src/main/java/org/altbeacon/beacon/AltBeacon.java @@ -64,20 +64,14 @@ public AltBeacon[] newArray(int size) { * @param beacon */ protected AltBeacon(Beacon beacon) { - super(); - this.mBluetoothAddress = beacon.mBluetoothAddress; - this.mIdentifiers = beacon.mIdentifiers; - this.mBeaconTypeCode = beacon.mBeaconTypeCode; - this.mDataFields = beacon.mDataFields; - this.mDistance = beacon.mDistance; - this.mRssi = beacon.mRssi; - this.mTxPower = beacon.mTxPower; + super(beacon); } /** * @see AltBeacon.Builder to make AltBeacon instances */ protected AltBeacon() { + super(); } /** diff --git a/src/test/java/org/altbeacon/beacon/AltBeaconTest.java b/src/test/java/org/altbeacon/beacon/AltBeaconTest.java index 3710e5e47..4f20296a7 100644 --- a/src/test/java/org/altbeacon/beacon/AltBeaconTest.java +++ b/src/test/java/org/altbeacon/beacon/AltBeaconTest.java @@ -2,15 +2,20 @@ import android.os.Parcel; -import static org.junit.Assert.assertEquals; - -import org.altbeacon.beacon.logging.Loggers; -import org.robolectric.RobolectricTestRunner; - -import org.junit.runner.RunWith; +import org.junit.After; import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; +import java.util.Arrays; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasProperty; +import static org.junit.Assert.assertEquals; + @Config(sdk = 18) @RunWith(RobolectricTestRunner.class) @@ -26,6 +31,15 @@ 4. Expand the System.err section */ public class AltBeaconTest { + private Parcel aParcel = null; + + @After + public void after() { + // Clean up any obtained parcel + if (null != aParcel) { + aParcel.recycle(); + } + } public static byte[] hexStringToByteArray(String s) { int len = s.length(); @@ -48,13 +62,89 @@ public void testRecognizeBeacon() { @Test public void testCanSerializeParcelable() { org.robolectric.shadows.ShadowLog.stream = System.err; - Parcel parcel = Parcel.obtain(); - Beacon beacon = new AltBeacon.Builder().setMfgReserved(7).setId1("1").setId2("2").setId3("3").setRssi(4) - .setBeaconTypeCode(5).setTxPower(6) - .setBluetoothAddress("1:2:3:4:5:6").build(); - beacon.writeToParcel(parcel, 0); - parcel.setDataPosition(0); - Beacon beacon2 = new AltBeacon(parcel); - assertEquals("beaconMfgReserved is same after deserialization", ((AltBeacon)beacon).getMfgReserved(), ((AltBeacon)beacon2).getMfgReserved()); + final Beacon original = new AltBeacon.Builder().setMfgReserved(2) + .setBluetoothAddress("aa:bb:cc:dd:ee:ff") + .setBluetoothName("Any Bluetooth") + .setBeaconTypeCode(1) + .setExtraDataFields(Arrays.asList(4L, 5L)) + .setId1("6") + .setId2("7") + .setId3("8") + .setManufacturer(10) + .setMultiFrameBeacon(true) + .setParserIdentifier("Any Parser ID") + .setRssi(-11) + .setRunningAverageRssi(-12.3) + .setServiceUuid(13) + .setTxPower(14) + .build(); + + aParcel = Parcel.obtain(); + original.writeToParcel(aParcel, 0); + aParcel.setDataPosition(0); + final AltBeacon parceled = AltBeacon.CREATOR.createFromParcel(aParcel); + assertThat( + parceled, + allOf( + hasProperty("bluetoothAddress", equalTo("aa:bb:cc:dd:ee:ff")), + hasProperty("bluetoothName", equalTo("Any Bluetooth")), + hasProperty("beaconTypeCode", equalTo(1)), + hasProperty("dataFields", equalTo(Arrays.asList(2L))), + hasProperty("extraDataFields", equalTo(Arrays.asList(4L, 5L))), + hasProperty("id1", equalTo(Identifier.fromInt(6))), + hasProperty("id2", equalTo(Identifier.fromInt(7))), + hasProperty("id3", equalTo(Identifier.fromInt(8))), + hasProperty("manufacturer", equalTo(10)), + hasProperty("multiFrameBeacon", equalTo(true)), + hasProperty("parserIdentifier", equalTo("Any Parser ID")), + hasProperty("rssi", equalTo(-11)), + hasProperty("runningAverageRssi", equalTo(-12.3)), + hasProperty("serviceUuid", equalTo(13)), + hasProperty("txPower", equalTo(14)), + hasProperty("mfgReserved", equalTo(2)) + ) + ); + } + + + @Test + public void copyingBeaconTransfersAllFields() { + final Beacon original = new AltBeacon.Builder().setMfgReserved(2) + .setBluetoothAddress("aa:bb:cc:dd:ee:ff") + .setBluetoothName("Any Bluetooth") + .setBeaconTypeCode(1) + .setExtraDataFields(Arrays.asList(4L, 5L)) + .setId1("6") + .setId2("7") + .setId3("8") + .setManufacturer(10) + .setMultiFrameBeacon(true) + .setParserIdentifier("Any Parser ID") + .setRssi(-11) + .setRunningAverageRssi(-12.3) + .setServiceUuid(13) + .setTxPower(14) + .build(); + final AltBeacon copied = new AltBeacon(original); + assertThat( + copied, + allOf( + hasProperty("bluetoothAddress", equalTo("aa:bb:cc:dd:ee:ff")), + hasProperty("bluetoothName", equalTo("Any Bluetooth")), + hasProperty("beaconTypeCode", equalTo(1)), + hasProperty("dataFields", equalTo(Arrays.asList(2L))), + hasProperty("extraDataFields", equalTo(Arrays.asList(4L, 5L))), + hasProperty("id1", equalTo(Identifier.fromInt(6))), + hasProperty("id2", equalTo(Identifier.fromInt(7))), + hasProperty("id3", equalTo(Identifier.fromInt(8))), + hasProperty("manufacturer", equalTo(10)), + hasProperty("multiFrameBeacon", equalTo(true)), + hasProperty("parserIdentifier", equalTo("Any Parser ID")), + hasProperty("rssi", equalTo(-11)), + hasProperty("runningAverageRssi", equalTo(-12.3)), + hasProperty("serviceUuid", equalTo(13)), + hasProperty("txPower", equalTo(14)) + ) + ); } } From deaa42d4b5386001d6277e214f7e2ecffd98e016 Mon Sep 17 00:00:00 2001 From: Aaron Kromer Date: Fri, 15 Dec 2017 17:57:16 -0500 Subject: [PATCH 5/5] Update tests with new fields These fields were added in #621. --- .../java/org/altbeacon/beacon/AltBeaconTest.java | 12 ++++++++++-- src/test/java/org/altbeacon/beacon/BeaconTest.java | 12 ++++++++++-- .../altbeacon/beacon/service/RangingDataTest.java | 4 ++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/altbeacon/beacon/AltBeaconTest.java b/src/test/java/org/altbeacon/beacon/AltBeaconTest.java index 4f20296a7..2d726781a 100644 --- a/src/test/java/org/altbeacon/beacon/AltBeaconTest.java +++ b/src/test/java/org/altbeacon/beacon/AltBeaconTest.java @@ -78,6 +78,8 @@ public void testCanSerializeParcelable() { .setServiceUuid(13) .setTxPower(14) .build(); + original.setPacketCount(15); + original.setRssiMeasurementCount(16); aParcel = Parcel.obtain(); original.writeToParcel(aParcel, 0); @@ -101,7 +103,9 @@ public void testCanSerializeParcelable() { hasProperty("runningAverageRssi", equalTo(-12.3)), hasProperty("serviceUuid", equalTo(13)), hasProperty("txPower", equalTo(14)), - hasProperty("mfgReserved", equalTo(2)) + hasProperty("mfgReserved", equalTo(2)), + hasProperty("packetCount", equalTo(15)), + hasProperty("measurementCount", equalTo(16)) ) ); } @@ -125,6 +129,8 @@ public void copyingBeaconTransfersAllFields() { .setServiceUuid(13) .setTxPower(14) .build(); + original.setPacketCount(15); + original.setRssiMeasurementCount(16); final AltBeacon copied = new AltBeacon(original); assertThat( copied, @@ -143,7 +149,9 @@ public void copyingBeaconTransfersAllFields() { hasProperty("rssi", equalTo(-11)), hasProperty("runningAverageRssi", equalTo(-12.3)), hasProperty("serviceUuid", equalTo(13)), - hasProperty("txPower", equalTo(14)) + hasProperty("txPower", equalTo(14)), + hasProperty("packetCount", equalTo(15)), + hasProperty("measurementCount", equalTo(16)) ) ); } diff --git a/src/test/java/org/altbeacon/beacon/BeaconTest.java b/src/test/java/org/altbeacon/beacon/BeaconTest.java index acd041452..63d37ea8f 100644 --- a/src/test/java/org/altbeacon/beacon/BeaconTest.java +++ b/src/test/java/org/altbeacon/beacon/BeaconTest.java @@ -242,6 +242,8 @@ public void parcelingBeaconContainsAllFields() { .setServiceUuid(13) .setTxPower(14) .build(); + original.setPacketCount(15); + original.setRssiMeasurementCount(16); aParcel = Parcel.obtain(); original.writeToParcel(aParcel, 0); @@ -264,7 +266,9 @@ public void parcelingBeaconContainsAllFields() { hasProperty("rssi", equalTo(-11)), hasProperty("runningAverageRssi", equalTo(-12.3)), hasProperty("serviceUuid", equalTo(13)), - hasProperty("txPower", equalTo(14)) + hasProperty("txPower", equalTo(14)), + hasProperty("packetCount", equalTo(15)), + hasProperty("measurementCount", equalTo(16)) ) ); } @@ -287,6 +291,8 @@ public void copyingBeaconContainsAllFields() { .setServiceUuid(13) .setTxPower(14) .build(); + original.setPacketCount(15); + original.setRssiMeasurementCount(16); final Beacon copied = new Beacon(original); assertThat( @@ -306,7 +312,9 @@ public void copyingBeaconContainsAllFields() { hasProperty("rssi", equalTo(-11)), hasProperty("runningAverageRssi", equalTo(-12.3)), hasProperty("serviceUuid", equalTo(13)), - hasProperty("txPower", equalTo(14)) + hasProperty("txPower", equalTo(14)), + hasProperty("packetCount", equalTo(15)), + hasProperty("measurementCount", equalTo(16)) ) ); } diff --git a/src/test/java/org/altbeacon/beacon/service/RangingDataTest.java b/src/test/java/org/altbeacon/beacon/service/RangingDataTest.java index 7a7264d2c..90f92dbf1 100644 --- a/src/test/java/org/altbeacon/beacon/service/RangingDataTest.java +++ b/src/test/java/org/altbeacon/beacon/service/RangingDataTest.java @@ -47,6 +47,8 @@ public void testSerialization() throws Exception { .setTxPower(-50) .setBluetoothAddress("01:02:03:04:05:06") .build(); + beacon.setRssiMeasurementCount(1); + beacon.setPacketCount(2); for (int i=0; i < 10; i++) { beacons.add(beacon); } @@ -60,6 +62,8 @@ public void testSerialization() throws Exception { assertEquals("RSSI is restored", -1, restoredBeacon.getRssi()); assertEquals("Average RSSI is restored", -2.0, restoredBeacon.getRunningAverageRssi(), 0.0); assertEquals("TXPower is restored", -50, restoredBeacon.getTxPower()); + assertEquals("Measurement count is restored", 1, restoredBeacon.getMeasurementCount()); + assertEquals("Packet count is restored", 2, restoredBeacon.getPacketCount()); } @Test