mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-12 10:55:49 +01:00
More robolectric stuff
- guard against multiple GBApplication.onCreate() invocations - test DBHelper.getDevice() for a start
This commit is contained in:
parent
38c4be4379
commit
49b8b9ebca
1
TODO.md
1
TODO.md
@ -3,6 +3,7 @@ TODO before 0.12.0 release:
|
||||
* ~~Support importing Pebble Health data from old database~~ DONE, needs check.
|
||||
* Fix user attribute table being spammed
|
||||
* Add onboarding activity on first startup (to merge old data)
|
||||
* Add hwVersion / revision to Device
|
||||
|
||||
Non blocking issues:
|
||||
|
||||
|
@ -99,6 +99,11 @@ public class GBApplication extends Application {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
if (lockHandler != null) {
|
||||
// guard against multiple invocations (robolectric)
|
||||
return;
|
||||
}
|
||||
|
||||
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
prefs = new Prefs(sharedPrefs);
|
||||
gbPrefs = new GBPrefs(prefs);
|
||||
|
@ -2,6 +2,7 @@ package nodomain.freeyourgadget.gadgetbridge.database;
|
||||
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -13,13 +14,19 @@ import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoMaster;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.User;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.UserAttributes;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.UserAttributesDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.UserDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
@ -32,16 +39,26 @@ public class EntitiesTest {
|
||||
private DaoSession daoSession;
|
||||
private UserDao userDao;
|
||||
private UserAttributesDao userAttributesDao;
|
||||
private DBHandler dbHandler;
|
||||
private GBApplication app = (GBApplication) RuntimeEnvironment.application;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DaoMaster.DevOpenHelper openHelper = new DaoMaster.DevOpenHelper(RuntimeEnvironment.application, null, null);
|
||||
public void setUp() throws GBException {
|
||||
// dbHandler = GBApplication.acquireDB();
|
||||
// daoSession = dbHandler.getDaoSession();
|
||||
DaoMaster.DevOpenHelper openHelper = new DaoMaster.DevOpenHelper(app, null, null);
|
||||
SQLiteDatabase db = openHelper.getWritableDatabase();
|
||||
daoSession = new DaoMaster(db).newSession();
|
||||
userDao = daoSession.getUserDao();
|
||||
userAttributesDao = daoSession.getUserAttributesDao();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
// GBApplication.releaseDB();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUser() {
|
||||
User user = new User();
|
||||
@ -78,5 +95,21 @@ public class EntitiesTest {
|
||||
assertNull(userDao.load(user.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDBHelper() {
|
||||
// DBHelper dbHelper = new DBHelper(RuntimeEnvironment.application);
|
||||
GBDevice dummyGBDevice = new GBDevice("00:00:00:00:00", "Testie", DeviceType.TEST);
|
||||
dummyGBDevice.setFirmwareVersion("1.2.3");
|
||||
dummyGBDevice.setHardwareVersion("4.0");
|
||||
Device device = DBHelper.getDevice(dummyGBDevice, daoSession);
|
||||
assertNotNull(device);
|
||||
assertEquals("00:00:00:00:00", device.getIdentifier());
|
||||
assertEquals("Testie", device.getName());
|
||||
// assertEquals("4.0", device.get());
|
||||
assertEquals(DeviceType.TEST.getKey(), device.getType());
|
||||
DeviceAttributes attributes = device.getDeviceAttributesList().get(0);
|
||||
assertNotNull(attributes);
|
||||
assertEquals("1.2.3", attributes.getFirmwareVersion1());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user