use of mockit.Verifications in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method openDoesNothingIfAlreadyOpened.
// Tests_SRS_MQTTIOTHUBCONNECTION_15_006: [If the MQTT connection is already open, the function shall do nothing.]
@Test
public void openDoesNothingIfAlreadyOpened() throws IOException {
baseExpectations();
openExpectations();
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.open();
connection.open();
new Verifications() {
{
new MqttMessaging(sslPrefix + iotHubHostName + sslPortSuffix, deviceId, anyString, anyString, mockIotHubSSLContext);
times = 1;
}
};
}
use of mockit.Verifications in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method openThrowsIOExceptionIfConnectionFailsInTwin.
@Test(expected = IOException.class)
public void openThrowsIOExceptionIfConnectionFailsInTwin() throws IOException {
baseExpectations();
new NonStrictExpectations() {
{
new IotHubSasToken(mockConfig, anyLong);
result = mockToken;
new MqttMessaging(sslPrefix + iotHubHostName + sslPortSuffix, deviceId, anyString, anyString, mockIotHubSSLContext);
result = mockDeviceMessaging;
new MqttDeviceMethod();
result = mockDeviceMethods;
new MqttDeviceTwin();
result = new IOException(anyString);
}
};
try {
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.open();
} catch (Exception e) {
new Verifications() {
{
mockDeviceMessaging.stop();
times = 1;
mockDeviceMethods.stop();
times = 1;
}
};
throw e;
}
}
use of mockit.Verifications in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method sendEventSendsDeviceTwinMessage.
@Test
public void sendEventSendsDeviceTwinMessage(@Mocked final DeviceTwinMessage mockDeviceTwinMsg) throws IOException {
baseExpectations();
openExpectations();
final byte[] msgBody = { 0x61, 0x62, 0x63 };
new NonStrictExpectations() {
{
mockDeviceTwinMsg.getBytes();
result = msgBody;
mockDeviceTwinMsg.getMessageType();
result = MessageType.DeviceTwin;
}
};
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.open();
IotHubStatusCode result = connection.sendEvent(mockDeviceTwinMsg);
assertEquals(IotHubStatusCode.OK_EMPTY, result);
new Verifications() {
{
mockDeviceMethods.send((DeviceMethodMessage) any);
times = 0;
mockDeviceMessaging.send(mockDeviceTwinMsg);
times = 0;
mockDeviceTwin.start();
times = 1;
mockDeviceTwin.send(mockDeviceTwinMsg);
times = 1;
}
};
}
use of mockit.Verifications in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method openThrowsIOExceptionIfConnectionFailsInMethod.
@Test(expected = IOException.class)
public void openThrowsIOExceptionIfConnectionFailsInMethod() throws IOException {
baseExpectations();
new NonStrictExpectations() {
{
new IotHubSasToken(mockConfig, anyLong);
result = mockToken;
new MqttMessaging(sslPrefix + iotHubHostName + sslPortSuffix, deviceId, anyString, anyString, mockIotHubSSLContext);
result = mockDeviceMessaging;
new MqttDeviceMethod();
result = new IOException(anyString);
}
};
try {
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.open();
} catch (Exception e) {
new Verifications() {
{
mockDeviceMessaging.stop();
times = 1;
}
};
throw e;
}
}
use of mockit.Verifications in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method openThrowsIOExceptionIfConnectionFails.
// Tests_SRS_MQTTIOTHUBCONNECTION_15_005: [If an MQTT connection is unable to be established for any reason,
// the function shall throw an IOException.]
@Test(expected = IOException.class)
public void openThrowsIOExceptionIfConnectionFails() throws IOException {
baseExpectations();
new NonStrictExpectations() {
{
new IotHubSasToken(mockConfig, anyLong);
result = mockToken;
new MqttMessaging(sslPrefix + iotHubHostName + sslPortSuffix, deviceId, anyString, anyString, mockIotHubSSLContext);
result = new IOException(anyString);
}
};
try {
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.open();
} catch (Exception e) {
new Verifications() {
{
}
};
throw e;
}
}
Aggregations