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
|
||||
*/
|
||||
@NonNull
|
||||
public static String getWithoutRowId() {
|
||||
if (GBApplication.isRunningLollipopOrLater()) {
|
||||
return " WITHOUT ROWID;";
|
||||
|
@ -183,6 +184,7 @@ public class DBHelper {
|
|||
* @param session
|
||||
* @return the User entity
|
||||
*/
|
||||
@NonNull
|
||||
public static User getUser(DaoSession session) {
|
||||
ActivityUser prefsUser = new ActivityUser();
|
||||
UserDao userDao = session.getUserDao();
|
||||
|
@ -199,6 +201,16 @@ public class DBHelper {
|
|||
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) {
|
||||
User user = new User();
|
||||
ensureUserUpToDate(user, prefsUser, session);
|
||||
|
@ -363,6 +375,15 @@ public class DBHelper {
|
|||
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) {
|
||||
if (!isDeviceUpToDate(device, gbDevice)) {
|
||||
device.setIdentifier(gbDevice.getAddress());
|
||||
|
|
|
@ -214,6 +214,7 @@ public class EntitiesTest {
|
|||
List<DeviceAttributes> attrListOld = deviceOld.getDeviceAttributesList();
|
||||
assertEquals(1, attrListOld.size());
|
||||
assertEquals("1.0", attrListOld.get(0).getFirmwareVersion1());
|
||||
assertEquals("1.0", DBHelper.getDeviceAttributes(deviceOld).getFirmwareVersion1());
|
||||
|
||||
// some time passes, firmware update occurs
|
||||
Thread.sleep(2 * 1000);
|
||||
|
@ -225,5 +226,7 @@ public class EntitiesTest {
|
|||
assertEquals(2, attrListNew.size());
|
||||
assertEquals("2.0", attrListNew.get(0).getFirmwareVersion1());
|
||||
assertEquals("1.0", attrListNew.get(1).getFirmwareVersion1());
|
||||
|
||||
assertEquals("2.0", DBHelper.getDeviceAttributes(deviceNew).getFirmwareVersion1());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue