use of com.microsoft.azure.sdk.iot.deps.serializer.TwinParser in project azure-iot-sdk-java by Azure.
the class DeviceTwinTest method subscribeToDesiredDoesNotSubscribeIfAlreadySubscribed.
@Test
public void subscribeToDesiredDoesNotSubscribeIfAlreadySubscribed(@Mocked final TwinParser mockedTwinParserObject, @Mocked final DeviceTwinMessage mockedDeviceTwinMessage, @Mocked final PropertyCallBack<String, Object> mockedDesiredCB) throws IOException {
new NonStrictExpectations() {
{
new TwinParser(withAny(new TwinChangedCallback() {
@Override
public void execute(Map<String, Object> map) {
}
}), withAny(new TwinChangedCallback() {
@Override
public void execute(Map<String, Object> map) {
}
}));
result = mockedTwinParserObject;
new DeviceTwinMessage(withAny(new byte[0]));
result = mockedDeviceTwinMessage;
}
};
DeviceTwin testTwin = new DeviceTwin(mockedDeviceIO, mockedConfig, mockedStatusCB, null, mockedGenericPropertyCB, null);
Map<Property, Pair<PropertyCallBack<String, Object>, Object>> desiredMap = new HashMap<>();
desiredMap.put(new Property("DesiredProp1", "DesiredValue1"), new Pair<>(mockedDesiredCB, null));
testTwin.subscribeDesiredPropertiesNotification(desiredMap);
Deencapsulation.setField(testTwin, "isSubscribed", true);
desiredMap.put(new Property("DesiredProp2", "DesiredValue2"), new Pair<>(mockedDesiredCB, null));
testTwin.subscribeDesiredPropertiesNotification(desiredMap);
final ConcurrentSkipListMap<String, Pair<PropertyCallBack<String, Object>, Object>> actualMap = Deencapsulation.getField(testTwin, "onDesiredPropertyChangeMap");
assertNotNull(actualMap);
assertFalse(actualMap.isEmpty());
assertTrue(actualMap.containsKey("DesiredProp1"));
assertTrue(actualMap.containsKey("DesiredProp2"));
assertEquals(actualMap.get("DesiredProp2").getKey(), mockedDesiredCB);
new Verifications() {
{
mockedDeviceTwinMessage.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_REQUEST);
times = 1;
mockedDeviceIO.sendEventAsync(mockedDeviceTwinMessage, (IotHubEventCallback) any, null);
times = 1;
}
};
}
Aggregations