If you think the Android project LeBlue listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package houtbecke.rs.le.session;
//fromwww.java2s.comimport java.util.ArrayList;
import java.util.List;
import houtbecke.rs.le.LeGattStatus;
importstatic houtbecke.rs.le.session.EventType.remoteDeviceConnect;
importstatic houtbecke.rs.le.session.EventType.remoteDeviceGetAddress;
importstatic houtbecke.rs.le.session.EventType.remoteDeviceGetName;
importstatic houtbecke.rs.le.session.EventType.mockRemoteDeviceConnected;
importstatic houtbecke.rs.le.session.EventType.mockRemoteDeviceServicesDiscovered;
importstatic houtbecke.rs.le.session.EventType.remoteDeviceStartServiceDiscovery;
publicclass RemoteDeviceMockerObject extends MockerObject {
public RemoteDeviceMockerObject(SessionObject sessionObject, int sessionSource) {
super(sessionObject, sessionSource);
}
int mockedDeviceSource;
public RemoteDeviceMockerObject mocksRemoteDevice(String address, String name) {
return mocksRemoteDevice(address, name, true);
}
public RemoteDeviceMockerObject mocksRemoteDevice(String address, String name, boolean connects) {
return mocksRemoteDevice(EventSinkFiller.DEFAULT_DEVICE_ID, address, name, connects);
}
// can only be called once per mocker, you can after all use different mocker object for different devices.
public RemoteDeviceMockerObject mocksRemoteDevice(int deviceId, String address, String name, boolean connects) {
this.mockedDeviceSource = deviceId;
withMock(remoteDeviceGetAddress, address);
withMock(remoteDeviceGetName, name);
if (connects)
withMock(remoteDeviceConnect, new MockedResponseObject(new Event(mockRemoteDeviceConnected, getDelay(), sessionSource, deviceId + "")));
returnthis;
}
public RemoteDeviceMockerObject hasServices(int... services) {
return hasServices(LeGattStatus.SUCCESS, services);
}
public RemoteDeviceMockerObject hasServices(LeGattStatus status, int... services) {
List<String> params = new ArrayList<>();
params.add(mockedDeviceSource +"");
params.add(status.toString());
for (int service: services) {
params.add(service+"");
}
withMock(remoteDeviceStartServiceDiscovery, new MockedResponseObject(new Event(mockRemoteDeviceServicesDiscovered, getDelay(), sessionSource, params.toArray(new String[params.size()]))));
returnthis;
}
public RemoteDeviceMockerObject withFakeCharacteristicsListeners() {
mockCharacteristicsListeners = true;
returnthis;
}
public RemoteDeviceMockerObject withFakeRemoteDeviceListeners() {
mockRemoteDeviceListeners = true;
returnthis;
}
}