use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.
the class IotHubMessageUriTest method getHostnameIsCorrect.
// Tests_SRS_IOTHUBMESSAGEURI_11_003: [The function shall return the hostname given in the constructor.]
@Test
public void getHostnameIsCorrect() throws URISyntaxException {
final String iotHubHostname = "test.iothub";
final String deviceId = "test-deviceid";
final String hostname = "test-hostname";
new NonStrictExpectations() {
{
mockIotHubUri.getHostname();
result = hostname;
}
};
IotHubMessageUri messageUri = new IotHubMessageUri(iotHubHostname, deviceId);
String testHostname = messageUri.getHostname();
final String expectedHostname = hostname;
assertThat(testHostname, is(expectedHostname));
}
use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.
the class TemplateTest method testOpenCreatesNewSetOnlyOnce.
// Tests_SRS_TEMPLATE_99_005: [If open is already called then this method shall do nothing and return.]
@Test
public void testOpenCreatesNewSetOnlyOnce(@Mocked final Set<String> mockedSet) {
//arrange
final String testString = "testString";
/* Set any expectations on mocked object */
new NonStrictExpectations() {
{
}
};
/* Use Deencapsulation or reflection to access objects that are not scoped for test */
Template testObject = Deencapsulation.newInstance(Template.class, testString);
//act
/* Use Deencapsulation or reflection to access objects that are not scoped for test */
Deencapsulation.invoke(testObject, "open");
Deencapsulation.invoke(testObject, "open");
//assert
/* Use Deencapsulation or reflection to access objects that are not scoped for test */
final Set actualSet = Deencapsulation.getField(testObject, "unionSet");
assertNotNull(actualSet);
assertEquals(actualSet, mockedSet);
/* Verify any call flow on mocked objects that is expected on act */
new Verifications() {
{
new HashSet<>();
}
};
}
use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.
the class HttpsSingleMessageTest method toMessageCopiesBody.
// Tests_SRS_HTTPSSINGLEMESSAGE_11_007: [The function shall return an IoT Hub message with a copy of the message body as its body.]
@Test
public void toMessageCopiesBody(@Mocked final HttpsResponse mockResponse, @Mocked final MessageProperty mockProperty, @Mocked final Message mockMsg) {
final byte[] body = { 0x61, 0x62, 0x63 };
final Map<String, String> headerFields = new HashMap<>();
final String propertyName = "iothub-app-test-property-name";
final String propertyValue = "test-property-value";
headerFields.put(propertyName, propertyValue);
new NonStrictExpectations() {
{
mockResponse.getBody();
result = body;
mockResponse.getHeaderFields();
result = headerFields;
MessageProperty.isValidAppProperty(propertyName, propertyValue);
result = true;
new MessageProperty(propertyName, propertyValue);
result = mockProperty;
mockProperty.getName();
result = propertyName;
mockProperty.getValue();
result = propertyValue;
new Message(body);
result = mockMsg;
}
};
HttpsSingleMessage httpsMsg = HttpsSingleMessage.parseHttpsMessage(mockResponse);
httpsMsg.toMessage();
final byte[] expectedBody = body;
new Verifications() {
{
new Message(expectedBody);
}
};
}
use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.
the class HttpsSingleMessageTest method parseHttpsMessageFromResponseDoesNotBase64EncodeBody.
// Tests_SRS_HTTPSSINGLEMESSAGE_11_005: [The parsed HttpsSingleMessage shall not be Base64-encoded.]
@Test
public void parseHttpsMessageFromResponseDoesNotBase64EncodeBody(@Mocked final HttpsResponse mockResponse, @Mocked final MessageProperty mockProperty) {
final byte[] body = { 0x61, 0x62, 0x63 };
final Map<String, String> headerFields = new HashMap<>();
final String propertyName = "test-property-name";
final String propertyValue = "test-property-value";
headerFields.put(propertyName, propertyValue);
new NonStrictExpectations() {
{
mockResponse.getBody();
result = body;
mockResponse.getHeaderFields();
result = headerFields;
}
};
HttpsSingleMessage httpsMsg = HttpsSingleMessage.parseHttpsMessage(mockResponse);
boolean testBase64Encoded = httpsMsg.isBase64Encoded();
boolean expectedBase64Encoded = false;
assertThat(testBase64Encoded, is(expectedBase64Encoded));
}
use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.
the class HttpsSingleMessageTest method parseHttpsMessageFromResponseCopiesBody.
// Tests_SRS_HTTPSSINGLEMESSAGE_11_004: [The parsed HttpsSingleMessage shall have a copy of the original response body as its body.]
@Test
public void parseHttpsMessageFromResponseCopiesBody(@Mocked final HttpsResponse mockResponse, @Mocked final MessageProperty mockProperty) {
final byte[] body = { 0x61, 0x62, 0x63 };
final Map<String, String> headerFields = new HashMap<>();
final String propertyName = "test-property-name";
final String propertyValue = "test-property-value";
headerFields.put(propertyName, propertyValue);
new NonStrictExpectations() {
{
mockResponse.getBody();
result = body;
mockResponse.getHeaderFields();
result = headerFields;
}
};
HttpsSingleMessage httpsMsg = HttpsSingleMessage.parseHttpsMessage(mockResponse);
byte[] testBody = httpsMsg.getBody();
byte[] expectedBody = body;
assertThat(testBody, is(expectedBody));
expectedBody[0] = 0x34;
assertThat(testBody, is(not(expectedBody)));
}
Aggregations