mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-25 00:30:37 +02:00
Make DeviceCommunicationServiceTestCase runnable with robolectric
- enables the test for travis - tests operation when not connected - tests connecting - tests operation when connected
This commit is contained in:
parent
ee0f1f23c0
commit
c31049839a
@ -61,6 +61,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
private Context context;
|
private Context context;
|
||||||
private boolean autoReconnect;
|
private boolean autoReconnect;
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setContext(GBDevice gbDevice, BluetoothAdapter btAdapter, Context context) {
|
public void setContext(GBDevice gbDevice, BluetoothAdapter btAdapter, Context context) {
|
||||||
this.gbDevice = gbDevice;
|
this.gbDevice = gbDevice;
|
||||||
this.btAdapter = btAdapter;
|
this.btAdapter = btAdapter;
|
||||||
@ -281,11 +282,11 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
(BatteryState.BATTERY_LOW.equals(deviceEvent.state) ||
|
(BatteryState.BATTERY_LOW.equals(deviceEvent.state) ||
|
||||||
BatteryState.BATTERY_NORMAL.equals(deviceEvent.state))
|
BatteryState.BATTERY_NORMAL.equals(deviceEvent.state))
|
||||||
) {
|
) {
|
||||||
GB.updateBatteryNotification(context.getString(R.string.notif_battery_low_percent, gbDevice.getName(), deviceEvent.level),
|
GB.updateBatteryNotification(context.getString(R.string.notif_battery_low_percent, gbDevice.getName(), String.valueOf(deviceEvent.level)),
|
||||||
deviceEvent.extendedInfoAvailable() ?
|
deviceEvent.extendedInfoAvailable() ?
|
||||||
context.getString(R.string.notif_battery_low_percent, gbDevice.getName(), deviceEvent.level) + "\n" +
|
context.getString(R.string.notif_battery_low_percent, gbDevice.getName(), String.valueOf(deviceEvent.level)) + "\n" +
|
||||||
context.getString(R.string.notif_battery_low_bigtext_last_charge_time, DateFormat.getDateTimeInstance().format(deviceEvent.lastChargeTime.getTime())) +
|
context.getString(R.string.notif_battery_low_bigtext_last_charge_time, DateFormat.getDateTimeInstance().format(deviceEvent.lastChargeTime.getTime())) +
|
||||||
context.getString(R.string.notif_battery_low_bigtext_number_of_charges, deviceEvent.numCharges)
|
context.getString(R.string.notif_battery_low_bigtext_number_of_charges, String.valueOf(deviceEvent.numCharges))
|
||||||
: ""
|
: ""
|
||||||
, context);
|
, context);
|
||||||
}
|
}
|
||||||
|
@ -120,6 +120,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_URI
|
|||||||
|
|
||||||
public class DeviceCommunicationService extends Service implements SharedPreferences.OnSharedPreferenceChangeListener {
|
public class DeviceCommunicationService extends Service implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(DeviceCommunicationService.class);
|
private static final Logger LOG = LoggerFactory.getLogger(DeviceCommunicationService.class);
|
||||||
|
private static DeviceSupportFactory DEVICE_SUPPORT_FACTORY = null;
|
||||||
|
|
||||||
private boolean mStarted = false;
|
private boolean mStarted = false;
|
||||||
|
|
||||||
@ -138,6 +139,19 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
|||||||
|
|
||||||
private Random mRandom = new Random();
|
private Random mRandom = new Random();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For testing!
|
||||||
|
*
|
||||||
|
* @param factory
|
||||||
|
*/
|
||||||
|
public static void setDeviceSupportFactory(DeviceSupportFactory factory) {
|
||||||
|
DEVICE_SUPPORT_FACTORY = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceCommunicationService() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@ -178,13 +192,20 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
|||||||
LOG.debug("DeviceCommunicationService is being created");
|
LOG.debug("DeviceCommunicationService is being created");
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, new IntentFilter(GBDevice.ACTION_DEVICE_CHANGED));
|
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, new IntentFilter(GBDevice.ACTION_DEVICE_CHANGED));
|
||||||
mFactory = new DeviceSupportFactory(this);
|
mFactory = getDeviceSupportFactory();
|
||||||
|
|
||||||
if (hasPrefs()) {
|
if (hasPrefs()) {
|
||||||
getPrefs().getPreferences().registerOnSharedPreferenceChangeListener(this);
|
getPrefs().getPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DeviceSupportFactory getDeviceSupportFactory() {
|
||||||
|
if (DEVICE_SUPPORT_FACTORY != null) {
|
||||||
|
return DEVICE_SUPPORT_FACTORY;
|
||||||
|
}
|
||||||
|
return new DeviceSupportFactory(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized int onStartCommand(Intent intent, int flags, int startId) {
|
public synchronized int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
|
||||||
@ -461,15 +482,6 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
|||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* For testing!
|
|
||||||
*
|
|
||||||
* @param factory
|
|
||||||
*/
|
|
||||||
public void setDeviceSupportFactory(DeviceSupportFactory factory) {
|
|
||||||
mFactory = factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disposes the current DeviceSupport instance (if any) and sets a new device support instance
|
* Disposes the current DeviceSupport instance (if any) and sets a new device support instance
|
||||||
* (if not null).
|
* (if not null).
|
||||||
|
@ -4,97 +4,43 @@ import android.app.Application;
|
|||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
import org.junit.After;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import org.junit.Before;
|
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.test.GBMockApplication;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.test.GBMockContext;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.test.GBMockPackageManager;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.test.MockHelper;
|
import nodomain.freeyourgadget.gadgetbridge.test.MockHelper;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.test.TestBase;
|
||||||
|
|
||||||
public abstract class AbstractServiceTestCase<T extends Service> {
|
public abstract class AbstractServiceTestCase<T extends Service> extends TestBase {
|
||||||
private static final int ID = -1; // currently not supported
|
|
||||||
private final Class<T> mServiceClass;
|
|
||||||
private T mServiceInstance;
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private GBMockApplication mApplication;
|
private GBApplication mApplication;
|
||||||
private boolean wasStarted;
|
|
||||||
private PackageManager mPackageManager;
|
|
||||||
private NotificationManager mNotificationManager;
|
private NotificationManager mNotificationManager;
|
||||||
private MockHelper mMockHelper;
|
private MockHelper mMockHelper;
|
||||||
|
|
||||||
protected AbstractServiceTestCase(Class<T> serviceClass) {
|
protected AbstractServiceTestCase() {
|
||||||
mServiceClass = serviceClass;
|
|
||||||
Assert.assertNotNull(serviceClass);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Context getContext() {
|
public Context getContext() {
|
||||||
return mContext;
|
return mContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T getServiceInstance() {
|
|
||||||
return mServiceInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected MockHelper getmMockHelper() {
|
protected MockHelper getmMockHelper() {
|
||||||
return mMockHelper;
|
return mMockHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
mMockHelper = new MockHelper();
|
mMockHelper = new MockHelper();
|
||||||
mPackageManager = createPackageManager();
|
mApplication = (GBApplication) RuntimeEnvironment.application;
|
||||||
mApplication = createApplication(mPackageManager);
|
mContext = mApplication;
|
||||||
mContext = createContext(mApplication);
|
|
||||||
mNotificationManager = mMockHelper.createNotificationManager(mContext);
|
mNotificationManager = mMockHelper.createNotificationManager(mContext);
|
||||||
mServiceInstance = createService(mServiceClass, mApplication, mNotificationManager);
|
|
||||||
mServiceInstance.onCreate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
if (mServiceInstance != null) {
|
|
||||||
stopService();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startService(Intent intent) {
|
|
||||||
wasStarted = true;
|
|
||||||
mServiceInstance.onStartCommand(intent, Service.START_FLAG_REDELIVERY, ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopService() {
|
|
||||||
mServiceInstance.onDestroy();
|
|
||||||
mServiceInstance = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected GBMockApplication createApplication(PackageManager packageManager) {
|
|
||||||
return new GBMockApplication(packageManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected PackageManager createPackageManager() {
|
|
||||||
return new GBMockPackageManager();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Application getApplication() {
|
protected Application getApplication() {
|
||||||
return mApplication;
|
return mApplication;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Context createContext(final Application application) {
|
|
||||||
return new GBMockContext(application);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected T createService(Class<T> serviceClass, GBMockApplication application, NotificationManager notificationManager) throws Exception {
|
|
||||||
T service = mMockHelper.createService(serviceClass, application);
|
|
||||||
mMockHelper.addSystemServiceTo(service, Context.NOTIFICATION_SERVICE, notificationManager);
|
|
||||||
return service;
|
|
||||||
}
|
|
||||||
|
|
||||||
private NotificationManager getNotificationService() {
|
private NotificationManager getNotificationService() {
|
||||||
return mNotificationManager;
|
return mNotificationManager;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service;
|
package nodomain.freeyourgadget.gadgetbridge.service;
|
||||||
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.InOrder;
|
import org.mockito.InOrder;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@ -12,9 +10,8 @@ import org.mockito.Mockito;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.test.GBMockApplication;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class DeviceCommunicationServiceTestCase extends AbstractServiceTestCase<DeviceCommunicationService> {
|
public class DeviceCommunicationServiceTestCase extends AbstractServiceTestCase<DeviceCommunicationService> {
|
||||||
@ -40,41 +37,51 @@ public class DeviceCommunicationServiceTestCase extends AbstractServiceTestCase<
|
|||||||
private TestDeviceSupport mockSupport;
|
private TestDeviceSupport mockSupport;
|
||||||
|
|
||||||
public DeviceCommunicationServiceTestCase() {
|
public DeviceCommunicationServiceTestCase() {
|
||||||
super(DeviceCommunicationService.class);
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DeviceCommunicationService createService(Class<DeviceCommunicationService> serviceClass, GBMockApplication application, NotificationManager notificationManager) throws Exception {
|
|
||||||
DeviceCommunicationService service = getmMockHelper().createDeviceCommunicationService(serviceClass, application);
|
|
||||||
getmMockHelper().addSystemServiceTo(service, Context.NOTIFICATION_SERVICE, notificationManager);
|
|
||||||
return service;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
mockSupport = null;
|
mockSupport = null;
|
||||||
realSupport = new TestDeviceSupport();
|
realSupport = new TestDeviceSupport();
|
||||||
realSupport.setContext(new GBDevice(TEST_DEVICE_ADDRESS, "Test Device", DeviceType.TEST), null, getContext());
|
realSupport.setContext(new GBDevice(TEST_DEVICE_ADDRESS, "Test Device", DeviceType.TEST), null, getContext());
|
||||||
mockSupport = Mockito.spy(realSupport);
|
mockSupport = Mockito.spy(realSupport);
|
||||||
getServiceInstance().setDeviceSupportFactory(new TestDeviceSupportFactory(getContext()));
|
DeviceCommunicationService.setDeviceSupportFactory(new TestDeviceSupportFactory(getContext()));
|
||||||
|
|
||||||
mDeviceService = new TestDeviceService(this);
|
mDeviceService = new TestDeviceService(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected GBDevice getDevice() {
|
||||||
|
return realSupport.getDevice();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
mDeviceService.stopService(mDeviceService.createIntent());
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStart() {
|
public void testNotConnected() {
|
||||||
assertFalse("Service was already", getServiceInstance().isStarted());
|
GBDevice device = getDevice();
|
||||||
mDeviceService.start();
|
assertEquals(GBDevice.State.NOT_CONNECTED, device.getState());
|
||||||
assertTrue("Service should be started", getServiceInstance().isStarted());
|
|
||||||
|
// verify that the events like onFindDevice do not reach the DeviceSupport instance,
|
||||||
|
// because not connected
|
||||||
|
InOrder inOrder = Mockito.inOrder(mockSupport);
|
||||||
|
mDeviceService.onFindDevice(true);
|
||||||
|
inOrder.verify(mockSupport, Mockito.times(0)).onFindDevice(true);
|
||||||
|
inOrder.verifyNoMoreInteractions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ensureConnected() {
|
public void ensureConnected() {
|
||||||
mDeviceService.connect(realSupport.getDevice());
|
mDeviceService.start();
|
||||||
|
// connection goes synchronously here
|
||||||
|
mDeviceService.connect(getDevice());
|
||||||
Mockito.verify(mockSupport, Mockito.times(1)).connect();
|
Mockito.verify(mockSupport, Mockito.times(1)).connect();
|
||||||
assertTrue(realSupport.getDevice().isInitialized());
|
assertTrue(getDevice().isInitialized());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -88,4 +95,5 @@ public class DeviceCommunicationServiceTestCase extends AbstractServiceTestCase<
|
|||||||
inOrder.verify(mockSupport, Mockito.times(1)).onFindDevice(false);
|
inOrder.verify(mockSupport, Mockito.times(1)).onFindDevice(false);
|
||||||
inOrder.verifyNoMoreInteractions();
|
inOrder.verifyNoMoreInteractions();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,51 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service;
|
package nodomain.freeyourgadget.gadgetbridge.service;
|
||||||
|
|
||||||
|
import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService;
|
import org.robolectric.Robolectric;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.test.GBMockIntent;
|
import org.robolectric.util.ServiceController;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends GBDeviceServer so that communication with the service works
|
||||||
|
* with Robolectric.
|
||||||
|
*/
|
||||||
public class TestDeviceService extends GBDeviceService {
|
public class TestDeviceService extends GBDeviceService {
|
||||||
private final AbstractServiceTestCase<?> mTestCase;
|
private final AbstractServiceTestCase<?> mTestCase;
|
||||||
|
private final ServiceController<DeviceCommunicationService> serviceController;
|
||||||
|
private final DeviceCommunicationService service;
|
||||||
|
|
||||||
public TestDeviceService(AbstractServiceTestCase<?> testCase) throws Exception {
|
public TestDeviceService(AbstractServiceTestCase<?> testCase) throws Exception {
|
||||||
super(testCase.getContext());
|
super(testCase.getContext());
|
||||||
mTestCase = testCase;
|
mTestCase = testCase;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
serviceController = Robolectric.buildService(DeviceCommunicationService.class, createIntent());
|
||||||
protected Intent createIntent() {
|
service = serviceController.create().get();
|
||||||
return new GBMockIntent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void invokeService(Intent intent) {
|
protected void invokeService(Intent intent) {
|
||||||
mTestCase.startService(intent);
|
// calling though to the service natively does not work with robolectric,
|
||||||
|
// we have to use the ServiceController to do that
|
||||||
|
service.onStartCommand(intent, Service.START_FLAG_REDELIVERY, (int) (Math.random() * 10000));
|
||||||
|
// super.invokeService(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() {
|
||||||
|
super.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void stopService(Intent intent) {
|
||||||
|
super.stopService(intent);
|
||||||
|
serviceController.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Intent createIntent() {
|
||||||
|
return super.createIntent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.test;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.test.mock.MockApplication;
|
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBEnvironment;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
|
||||||
|
|
||||||
public class GBMockApplication extends MockApplication {
|
|
||||||
private static final String PREF_NAME = "testprefs";
|
|
||||||
private final PackageManager mPackageManager;
|
|
||||||
private Prefs prefs;
|
|
||||||
private GBPrefs gbPrefs;
|
|
||||||
|
|
||||||
public GBMockApplication(PackageManager packageManager) {
|
|
||||||
GB.environment = GBEnvironment.createDeviceEnvironment().createLocalTestEnvironment();
|
|
||||||
mPackageManager = packageManager;
|
|
||||||
prefs = new Prefs(PreferenceManager.getDefaultSharedPreferences(this));
|
|
||||||
gbPrefs = new GBPrefs(prefs);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Context getApplicationContext() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PackageManager getPackageManager() {
|
|
||||||
return mPackageManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Prefs getPrefs() {
|
|
||||||
return prefs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GBPrefs getGBPrefs() {
|
|
||||||
return gbPrefs;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.test;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.test.mock.MockContext;
|
|
||||||
|
|
||||||
public class GBMockContext extends MockContext {
|
|
||||||
private final Application mApplication;
|
|
||||||
|
|
||||||
public GBMockContext(Application application) {
|
|
||||||
mApplication = application;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Context getApplicationContext() {
|
|
||||||
return mApplication;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PackageManager getPackageManager() {
|
|
||||||
return mApplication.getPackageManager();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,387 +0,0 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.test;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class GBMockIntent extends Intent {
|
|
||||||
private String mAction;
|
|
||||||
private final Map<String, Object> extras = new HashMap<>();
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent setAction(String action) {
|
|
||||||
mAction = action;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAction() {
|
|
||||||
return mAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, boolean value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, byte value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, char value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, short value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, int value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, long value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, float value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, double value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, String value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, CharSequence value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, Parcelable value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, Parcelable[] value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Intent putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putIntegerArrayListExtra(String name, ArrayList<Integer> value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putStringArrayListExtra(String name, ArrayList<String> value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putCharSequenceArrayListExtra(String name, ArrayList<CharSequence> value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, Serializable value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, boolean[] value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, byte[] value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, short[] value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, char[] value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, int[] value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, long[] value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, float[] value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, double[] value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, String[] value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, CharSequence[] value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Intent putExtra(String name, Bundle value) {
|
|
||||||
extras.put(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getBooleanExtra(String name, boolean defaultValue) {
|
|
||||||
if (extras.containsKey(name)) {
|
|
||||||
return (boolean) extras.get(name);
|
|
||||||
}
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte getByteExtra(String name, byte defaultValue) {
|
|
||||||
if (extras.containsKey(name)) {
|
|
||||||
return (byte) extras.get(name);
|
|
||||||
}
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public short getShortExtra(String name, short defaultValue) {
|
|
||||||
if (extras.containsKey(name)) {
|
|
||||||
return (short) extras.get(name);
|
|
||||||
}
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public char getCharExtra(String name, char defaultValue) {
|
|
||||||
if (extras.containsKey(name)) {
|
|
||||||
return (char) extras.get(name);
|
|
||||||
}
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getIntExtra(String name, int defaultValue) {
|
|
||||||
if (extras.containsKey(name)) {
|
|
||||||
return (int) extras.get(name);
|
|
||||||
}
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getLongExtra(String name, long defaultValue) {
|
|
||||||
if (extras.containsKey(name)) {
|
|
||||||
return (long) extras.get(name);
|
|
||||||
}
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getFloatExtra(String name, float defaultValue) {
|
|
||||||
if (extras.containsKey(name)) {
|
|
||||||
return (float) extras.get(name);
|
|
||||||
}
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getDoubleExtra(String name, double defaultValue) {
|
|
||||||
if (extras.containsKey(name)) {
|
|
||||||
return (double) extras.get(name);
|
|
||||||
}
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence getCharSequenceExtra(String name) {
|
|
||||||
return (CharSequence) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T extends Parcelable> T getParcelableExtra(String name) {
|
|
||||||
return (T) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Parcelable[] getParcelableArrayExtra(String name) {
|
|
||||||
return (Parcelable[]) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T extends Parcelable> ArrayList<T> getParcelableArrayListExtra(String name) {
|
|
||||||
return (ArrayList<T>) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Serializable getSerializableExtra(String name) {
|
|
||||||
return (Serializable) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayList<Integer> getIntegerArrayListExtra(String name) {
|
|
||||||
return (ArrayList<Integer>) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayList<String> getStringArrayListExtra(String name) {
|
|
||||||
return (ArrayList<String>) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayList<CharSequence> getCharSequenceArrayListExtra(String name) {
|
|
||||||
return (ArrayList<CharSequence>) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean[] getBooleanArrayExtra(String name) {
|
|
||||||
return (boolean[]) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] getByteArrayExtra(String name) {
|
|
||||||
return (byte[]) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public short[] getShortArrayExtra(String name) {
|
|
||||||
return (short[]) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public char[] getCharArrayExtra(String name) {
|
|
||||||
return (char[]) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int[] getIntArrayExtra(String name) {
|
|
||||||
return (int[]) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long[] getLongArrayExtra(String name) {
|
|
||||||
return (long[]) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float[] getFloatArrayExtra(String name) {
|
|
||||||
return (float[]) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double[] getDoubleArrayExtra(String name) {
|
|
||||||
return (double[]) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] getStringArrayExtra(String name) {
|
|
||||||
return (String[]) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence[] getCharSequenceArrayExtra(String name) {
|
|
||||||
return (CharSequence[]) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getStringExtra(String name) {
|
|
||||||
return (String) extras.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "GBMockIntent: " + mAction;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.test;
|
|
||||||
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.test.mock.MockPackageManager;
|
|
||||||
|
|
||||||
public class GBMockPackageManager extends MockPackageManager {
|
|
||||||
@Override
|
|
||||||
public void setComponentEnabledSetting(ComponentName componentName, int newState, int flags) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,6 +12,7 @@ import org.robolectric.annotation.Config;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.util.ContextInitializer;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.Logging;
|
import nodomain.freeyourgadget.gadgetbridge.Logging;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||||
@ -27,35 +28,11 @@ import static org.junit.Assert.fail;
|
|||||||
* Test is currently disabled because logback-android does not work
|
* Test is currently disabled because logback-android does not work
|
||||||
* inside a plain junit test.
|
* inside a plain junit test.
|
||||||
*/
|
*/
|
||||||
@RunWith(RobolectricTestRunner.class)
|
public class LoggingTest extends TestBase {
|
||||||
@Config(constants = BuildConfig.class, sdk = 19)
|
|
||||||
// need sdk 19 because "WITHOUT ROWID" is not supported in robolectric/sqlite4java
|
|
||||||
public class LoggingTest {
|
|
||||||
|
|
||||||
private static File logFilesDir;
|
|
||||||
|
|
||||||
public LoggingTest() throws Exception {
|
public LoggingTest() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void setupSuite() throws Exception {
|
|
||||||
// properties might be preconfigured in build.gradle because of test ordering problems
|
|
||||||
String logDir = System.getProperty(Logging.PROP_LOGFILES_DIR);
|
|
||||||
if (logDir != null) {
|
|
||||||
logFilesDir = new File(logDir);
|
|
||||||
} else {
|
|
||||||
logFilesDir = FileUtils.createTempDir("logfiles");
|
|
||||||
System.setProperty(Logging.PROP_LOGFILES_DIR, logFilesDir.getAbsolutePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (System.getProperty("logback.configurationFile") == null) {
|
|
||||||
File workingDir = new File(System.getProperty("user.dir"));
|
|
||||||
File configFile = new File(workingDir, "src/main/assets/logback.xml");
|
|
||||||
System.out.println(configFile.getAbsolutePath());
|
|
||||||
System.setProperty("logback.configurationFile", configFile.getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Logging logging = new Logging() {
|
private Logging logging = new Logging() {
|
||||||
@Override
|
@Override
|
||||||
protected String createLogDirectory() throws IOException {
|
protected String createLogDirectory() throws IOException {
|
||||||
|
@ -11,14 +11,12 @@ import org.mockito.Mockito;
|
|||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
||||||
|
|
||||||
public class MockHelper {
|
public class MockHelper {
|
||||||
public <T extends Service> NotificationManager createNotificationManager(Context mContext) throws Exception {
|
public <T extends Service> NotificationManager createNotificationManager(Context mContext) throws Exception {
|
||||||
Constructor<?>[] constructors = NotificationManager.class.getDeclaredConstructors();
|
return (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
constructors[0].setAccessible(true);
|
|
||||||
Class<?>[] parameterTypes = constructors[0].getParameterTypes();
|
|
||||||
return (NotificationManager) constructors[0].newInstance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Service> T createService(Class<T> serviceClass, Application application) throws Exception {
|
public <T extends Service> T createService(Class<T> serviceClass, Application application) throws Exception {
|
||||||
@ -31,10 +29,10 @@ public class MockHelper {
|
|||||||
return mockedService;
|
return mockedService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends DeviceCommunicationService> T createDeviceCommunicationService(Class<T> serviceClass, GBMockApplication application) throws Exception {
|
public <T extends DeviceCommunicationService> T createDeviceCommunicationService(Class<T> serviceClass, GBApplication application) throws Exception {
|
||||||
T mockedService = createService(serviceClass, application);
|
T mockedService = createService(serviceClass, application);
|
||||||
Mockito.when(mockedService.getPrefs()).thenReturn(application.getPrefs());
|
Mockito.when(mockedService.getPrefs()).thenReturn(GBApplication.getPrefs());
|
||||||
Mockito.when(mockedService.getGBPrefs()).thenReturn(application.getGBPrefs());
|
Mockito.when(mockedService.getGBPrefs()).thenReturn(GBApplication.getGBPrefs());
|
||||||
return mockedService;
|
return mockedService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,19 +4,26 @@ import android.database.sqlite.SQLiteDatabase;
|
|||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.shadows.ShadowLog;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.util.ContextInitializer;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.Logging;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoMaster;
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoMaster;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@ -24,15 +31,38 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
@Config(constants = BuildConfig.class, sdk = 19)
|
@Config(constants = BuildConfig.class, sdk = 19)
|
||||||
// need sdk 19 because "WITHOUT ROWID" is not supported in robolectric/sqlite4java
|
// need sdk 19 because "WITHOUT ROWID" is not supported in robolectric/sqlite4java
|
||||||
public abstract class TestBase {
|
public abstract class TestBase {
|
||||||
|
protected static File logFilesDir;
|
||||||
|
|
||||||
protected GBApplication app = (GBApplication) RuntimeEnvironment.application;
|
protected GBApplication app = (GBApplication) RuntimeEnvironment.application;
|
||||||
protected DaoSession daoSession;
|
protected DaoSession daoSession;
|
||||||
protected DBHandler dbHandler;
|
protected DBHandler dbHandler;
|
||||||
|
|
||||||
|
// Make sure logging is set up for all testcases, so that we can debug problems
|
||||||
|
@BeforeClass
|
||||||
|
public static void setupSuite() throws Exception {
|
||||||
|
// print everything going to android.util.Log to System.out
|
||||||
|
ShadowLog.stream = System.out;
|
||||||
|
|
||||||
|
// properties might be preconfigured in build.gradle because of test ordering problems
|
||||||
|
String logDir = System.getProperty(Logging.PROP_LOGFILES_DIR);
|
||||||
|
if (logDir != null) {
|
||||||
|
logFilesDir = new File(logDir);
|
||||||
|
} else {
|
||||||
|
logFilesDir = FileUtils.createTempDir("logfiles");
|
||||||
|
System.setProperty(Logging.PROP_LOGFILES_DIR, logFilesDir.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (System.getProperty(ContextInitializer.CONFIG_FILE_PROPERTY) == null) {
|
||||||
|
File workingDir = new File(System.getProperty("user.dir"));
|
||||||
|
File configFile = new File(workingDir, "src/main/assets/logback.xml");
|
||||||
|
System.out.println(configFile.getAbsolutePath());
|
||||||
|
System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, configFile.getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
assertNotNull(app);
|
assertNotNull(app);
|
||||||
|
|
||||||
// doesn't work with Robolectric yet
|
// doesn't work with Robolectric yet
|
||||||
// dbHandler = GBApplication.acquireDB();
|
// dbHandler = GBApplication.acquireDB();
|
||||||
// daoSession = dbHandler.getDaoSession();
|
// daoSession = dbHandler.getDaoSession();
|
||||||
|
Loading…
Reference in New Issue
Block a user