mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-23 16:17:32 +01:00
slightly more testing of Device/Attributes
This commit is contained in:
parent
044c9ed101
commit
8e154ca67d
@ -167,6 +167,7 @@ public class DBHelper {
|
|||||||
*
|
*
|
||||||
* @return the "WITHOUT ROWID" string or an empty string for pre-Lollipop devices
|
* @return the "WITHOUT ROWID" string or an empty string for pre-Lollipop devices
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public static String getWithoutRowId() {
|
public static String getWithoutRowId() {
|
||||||
if (GBApplication.isRunningLollipopOrLater()) {
|
if (GBApplication.isRunningLollipopOrLater()) {
|
||||||
return " WITHOUT ROWID;";
|
return " WITHOUT ROWID;";
|
||||||
@ -183,6 +184,7 @@ public class DBHelper {
|
|||||||
* @param session
|
* @param session
|
||||||
* @return the User entity
|
* @return the User entity
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public static User getUser(DaoSession session) {
|
public static User getUser(DaoSession session) {
|
||||||
ActivityUser prefsUser = new ActivityUser();
|
ActivityUser prefsUser = new ActivityUser();
|
||||||
UserDao userDao = session.getUserDao();
|
UserDao userDao = session.getUserDao();
|
||||||
@ -199,6 +201,16 @@ public class DBHelper {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public static UserAttributes getUserAttributes(User user) {
|
||||||
|
List<UserAttributes> list = user.getUserAttributesList();
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
throw new IllegalStateException("user has no attributes");
|
||||||
|
}
|
||||||
|
return list.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private static User createUser(ActivityUser prefsUser, DaoSession session) {
|
private static User createUser(ActivityUser prefsUser, DaoSession session) {
|
||||||
User user = new User();
|
User user = new User();
|
||||||
ensureUserUpToDate(user, prefsUser, session);
|
ensureUserUpToDate(user, prefsUser, session);
|
||||||
@ -363,6 +375,15 @@ public class DBHelper {
|
|||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public static DeviceAttributes getDeviceAttributes(Device device) {
|
||||||
|
List<DeviceAttributes> list = device.getDeviceAttributesList();
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
throw new IllegalStateException("device has no attributes");
|
||||||
|
}
|
||||||
|
return list.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
private static void ensureDeviceUpToDate(Device device, GBDevice gbDevice, DaoSession session) {
|
private static void ensureDeviceUpToDate(Device device, GBDevice gbDevice, DaoSession session) {
|
||||||
if (!isDeviceUpToDate(device, gbDevice)) {
|
if (!isDeviceUpToDate(device, gbDevice)) {
|
||||||
device.setIdentifier(gbDevice.getAddress());
|
device.setIdentifier(gbDevice.getAddress());
|
||||||
|
@ -214,6 +214,7 @@ public class EntitiesTest {
|
|||||||
List<DeviceAttributes> attrListOld = deviceOld.getDeviceAttributesList();
|
List<DeviceAttributes> attrListOld = deviceOld.getDeviceAttributesList();
|
||||||
assertEquals(1, attrListOld.size());
|
assertEquals(1, attrListOld.size());
|
||||||
assertEquals("1.0", attrListOld.get(0).getFirmwareVersion1());
|
assertEquals("1.0", attrListOld.get(0).getFirmwareVersion1());
|
||||||
|
assertEquals("1.0", DBHelper.getDeviceAttributes(deviceOld).getFirmwareVersion1());
|
||||||
|
|
||||||
// some time passes, firmware update occurs
|
// some time passes, firmware update occurs
|
||||||
Thread.sleep(2 * 1000);
|
Thread.sleep(2 * 1000);
|
||||||
@ -225,5 +226,7 @@ public class EntitiesTest {
|
|||||||
assertEquals(2, attrListNew.size());
|
assertEquals(2, attrListNew.size());
|
||||||
assertEquals("2.0", attrListNew.get(0).getFirmwareVersion1());
|
assertEquals("2.0", attrListNew.get(0).getFirmwareVersion1());
|
||||||
assertEquals("1.0", attrListNew.get(1).getFirmwareVersion1());
|
assertEquals("1.0", attrListNew.get(1).getFirmwareVersion1());
|
||||||
|
|
||||||
|
assertEquals("2.0", DBHelper.getDeviceAttributes(deviceNew).getFirmwareVersion1());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user