mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 04:46:51 +01:00
Unit-Test and fix *Attributes sort order
When adding e.g. new DeviceAttributes, we cannot simply add them to the attributes list, because that list is supposed to be ordered. We could insert it at the beginning, but that would be brittle to changes in the GBDaoGenerator, so we simply re-fetch them from the db after adding new attributes.
This commit is contained in:
parent
507338d034
commit
6f02f9e350
@ -251,7 +251,9 @@ public class DBHelper {
|
||||
attributes.setUserId(user.getId());
|
||||
session.getUserAttributesDao().insert(attributes);
|
||||
|
||||
userAttributes.add(attributes);
|
||||
// sort order is important, so we re-fetch from the db
|
||||
// userAttributes.add(attributes);
|
||||
user.resetUserAttributesList();
|
||||
}
|
||||
|
||||
private static void invalidateUserAttributes(UserAttributes userAttributes, Calendar now, DaoSession session) {
|
||||
@ -423,7 +425,9 @@ public class DBHelper {
|
||||
DeviceAttributesDao attributesDao = session.getDeviceAttributesDao();
|
||||
attributesDao.insert(attributes);
|
||||
|
||||
deviceAttributes.add(attributes);
|
||||
// sort order is important, so we re-fetch from the db
|
||||
// deviceAttributes.add(attributes);
|
||||
device.resetDeviceAttributesList();
|
||||
}
|
||||
|
||||
private static void invalidateDeviceAttributes(DeviceAttributes deviceAttributes, Calendar now, DaoSession session) {
|
||||
|
@ -104,10 +104,10 @@ public class EntitiesTest {
|
||||
|
||||
@Test
|
||||
public void testDBHelper() {
|
||||
GBDevice dummyGBDevice = createDummyGDevice();
|
||||
GBDevice dummyGBDevice = createDummyGDevice("00:00:00:00:01");
|
||||
Device device = DBHelper.getDevice(dummyGBDevice, daoSession);
|
||||
assertNotNull(device);
|
||||
assertEquals("00:00:00:00:00", device.getIdentifier());
|
||||
assertEquals("00:00:00:00:01", device.getIdentifier());
|
||||
assertEquals("Testie", device.getName());
|
||||
assertEquals("4.0", device.getModel());
|
||||
assertEquals(DeviceType.TEST.getKey(), device.getType());
|
||||
@ -116,8 +116,8 @@ public class EntitiesTest {
|
||||
assertEquals("1.2.3", attributes.getFirmwareVersion1());
|
||||
}
|
||||
|
||||
private GBDevice createDummyGDevice() {
|
||||
GBDevice dummyGBDevice = new GBDevice("00:00:00:00:00", "Testie", DeviceType.TEST);
|
||||
private GBDevice createDummyGDevice(String macAddress) {
|
||||
GBDevice dummyGBDevice = new GBDevice(macAddress, "Testie", DeviceType.TEST);
|
||||
dummyGBDevice.setFirmwareVersion("1.2.3");
|
||||
dummyGBDevice.setModel("4.0");
|
||||
return dummyGBDevice;
|
||||
@ -204,4 +204,26 @@ public class EntitiesTest {
|
||||
assertEquals(2, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeviceAttributes() throws Exception {
|
||||
GBDevice dummyGBDevice = createDummyGDevice("00:00:00:00:02");
|
||||
dummyGBDevice.setFirmwareVersion("1.0");
|
||||
Device deviceOld = DBHelper.getDevice(dummyGBDevice, daoSession);
|
||||
assertNotNull(deviceOld);
|
||||
|
||||
List<DeviceAttributes> attrListOld = deviceOld.getDeviceAttributesList();
|
||||
assertEquals(1, attrListOld.size());
|
||||
assertEquals("1.0", attrListOld.get(0).getFirmwareVersion1());
|
||||
|
||||
// some time passes, firmware update occurs
|
||||
Thread.sleep(2 * 1000);
|
||||
dummyGBDevice.setFirmwareVersion("2.0");
|
||||
|
||||
Device deviceNew = DBHelper.getDevice(dummyGBDevice, daoSession);
|
||||
assertNotNull(deviceNew);
|
||||
List<DeviceAttributes> attrListNew = deviceNew.getDeviceAttributesList();
|
||||
assertEquals(2, attrListNew.size());
|
||||
assertEquals("2.0", attrListNew.get(0).getFirmwareVersion1());
|
||||
assertEquals("1.0", attrListNew.get(1).getFirmwareVersion1());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user