Search in sources :

Example 1 with BadFormatException

use of com.microsoft.azure.sdk.iot.device.exceptions.BadFormatException in project azure-iot-sdk-java by Azure.

the class FileUploadTaskTest method sendNotificationChecksHttpStatusCode.

@Test
public void sendNotificationChecksHttpStatusCode() throws IOException, IllegalArgumentException, URISyntaxException {
    // arrange
    FileUploadTask fileUploadTask = Deencapsulation.newInstance(FileUploadTask.class, new Class[] { String.class, InputStream.class, long.class, HttpsTransportManager.class, IotHubEventCallback.class, Object.class }, VALID_BLOB_NAME, mockInputStream, VALID_STREAM_LENGTH, mockHttpsTransportManager, mockIotHubEventCallback, VALID_CALLBACK_CONTEXT);
    new Expectations() {

        {
            mockHttpsTransportManager.sendFileUploadNotification((IotHubTransportMessage) any);
            result = mockResponseMessage;
            mockResponseMessage.getStatus();
            result = IotHubStatusCode.BAD_FORMAT;
        }
    };
    // act
    try {
        fileUploadTask.sendNotification(mockFileUploadNotification);
        fail("Test should have thrown an IOException with a nested BadFormatException");
    } catch (IOException e) {
        assertNotNull(e.getCause());
        assertTrue(e.getCause() instanceof BadFormatException);
    }
}
Also used : Expectations(mockit.Expectations) NonStrictExpectations(mockit.NonStrictExpectations) FileUploadTask(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask) BadFormatException(com.microsoft.azure.sdk.iot.device.exceptions.BadFormatException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

BadFormatException (com.microsoft.azure.sdk.iot.device.exceptions.BadFormatException)1 FileUploadTask (com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask)1 IOException (java.io.IOException)1 Expectations (mockit.Expectations)1 NonStrictExpectations (mockit.NonStrictExpectations)1 Test (org.junit.Test)1