mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-24 16:21:16 +02:00
Fix tests after DeviceService changes
This commit is contained in:
parent
65e054a747
commit
7892b8be6a
@ -84,6 +84,10 @@ public class GBDeviceService implements DeviceService {
|
||||
return new GBDeviceService(mContext, device);
|
||||
}
|
||||
|
||||
public GBDevice getDevice() {
|
||||
return mDevice;
|
||||
}
|
||||
|
||||
protected Intent createIntent() {
|
||||
return new Intent(mContext, mServiceClass);
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ public class DeviceCommunicationServiceTestCase extends TestBase {
|
||||
public void ensureConnected() {
|
||||
mDeviceService.start();
|
||||
// connection goes synchronously here
|
||||
mDeviceService.connect(getDevice());
|
||||
mDeviceService.forDevice(getDevice()).connect();
|
||||
Mockito.verify(mockSupport, Mockito.times(1)).connect();
|
||||
assertTrue(getDevice().isInitialized());
|
||||
}
|
||||
|
@ -7,7 +7,9 @@ import android.content.Intent;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.android.controller.ServiceController;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
||||
|
||||
/**
|
||||
* Extends GBDeviceServer so that communication with the service works
|
||||
@ -17,15 +19,28 @@ class TestDeviceService extends GBDeviceService {
|
||||
private final ServiceController<DeviceCommunicationService> serviceController;
|
||||
private final DeviceCommunicationService service;
|
||||
|
||||
TestDeviceService(Context context) throws Exception {
|
||||
super(context);
|
||||
TestDeviceService(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
TestDeviceService(final Context context, final GBDevice device) {
|
||||
super(context, device);
|
||||
|
||||
serviceController = Robolectric.buildService(DeviceCommunicationService.class, createIntent());
|
||||
service = serviceController.create().get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceService forDevice(final GBDevice device) {
|
||||
return new TestDeviceService(mContext, device);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void invokeService(Intent intent) {
|
||||
if (getDevice() != null) {
|
||||
intent.putExtra(GBDevice.EXTRA_DEVICE, getDevice());
|
||||
}
|
||||
|
||||
// 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));
|
||||
|
Loading…
Reference in New Issue
Block a user