Search in sources :

Example 1 with FileUploadInProgress

use of com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress in project azure-iot-sdk-java by Azure.

the class FileUploadInProgressTest method isCancelledFalseSuccess.

/* Codes_SRS_FILEUPLOADINPROGRESS_21_006: [The isCancelled shall return the value of isCancelled on the `task`.] */
@Test
public void isCancelledFalseSuccess() {
    // arrange
    final Map<String, Object> context = new HashMap<>();
    FileUploadInProgress fileUploadInProgress = Deencapsulation.newInstance(FileUploadInProgress.class, new Class[] { IotHubEventCallback.class, Object.class }, mockIotHubEventCallback, context);
    Deencapsulation.invoke(fileUploadInProgress, "setTask", new Class[] { Future.class }, mockFuture);
    new NonStrictExpectations() {

        {
            mockFuture.isCancelled();
            result = false;
            times = 1;
        }
    };
    // act
    boolean result = (boolean) Deencapsulation.invoke(fileUploadInProgress, "isCancelled");
    // assert
    assertFalse(result);
}
Also used : FileUploadInProgress(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress) HashMap(java.util.HashMap) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 2 with FileUploadInProgress

use of com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress in project azure-iot-sdk-java by Azure.

the class FileUploadInProgressTest method isCancelledTrueSuccess.

/* Codes_SRS_FILEUPLOADINPROGRESS_21_006: [The isCancelled shall return the value of isCancelled on the `task`.] */
@Test
public void isCancelledTrueSuccess() {
    // arrange
    final Map<String, Object> context = new HashMap<>();
    FileUploadInProgress fileUploadInProgress = Deencapsulation.newInstance(FileUploadInProgress.class, new Class[] { IotHubEventCallback.class, Object.class }, mockIotHubEventCallback, context);
    Deencapsulation.invoke(fileUploadInProgress, "setTask", new Class[] { Future.class }, mockFuture);
    new NonStrictExpectations() {

        {
            mockFuture.isCancelled();
            result = true;
            times = 1;
        }
    };
    // act
    boolean result = (boolean) Deencapsulation.invoke(fileUploadInProgress, "isCancelled");
    // assert
    assertTrue(result);
}
Also used : FileUploadInProgress(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress) HashMap(java.util.HashMap) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 3 with FileUploadInProgress

use of com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress in project azure-iot-sdk-java by Azure.

the class FileUploadInProgressTest method triggerCallbackSuccess.

/* Codes_SRS_FILEUPLOADINPROGRESS_21_005: [The triggerCallback shall call the execute in `statusCallback` with the provided `iotHubStatusCode` and `statusCallbackContext`.] */
@Test
public void triggerCallbackSuccess() {
    // arrange
    final Map<String, Object> context = new HashMap<>();
    FileUploadInProgress fileUploadInProgress = Deencapsulation.newInstance(FileUploadInProgress.class, new Class[] { IotHubEventCallback.class, Object.class }, mockIotHubEventCallback, context);
    // act
    Deencapsulation.invoke(fileUploadInProgress, "triggerCallback", new Class[] { IotHubStatusCode.class }, IotHubStatusCode.OK);
    // assert
    new Verifications() {

        {
            Deencapsulation.invoke(mockIotHubEventCallback, "execute", new Class[] { IotHubStatusCode.class, Object.class }, IotHubStatusCode.OK, context);
            times = 1;
        }
    };
}
Also used : FileUploadInProgress(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress) HashMap(java.util.HashMap) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 4 with FileUploadInProgress

use of com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress in project azure-iot-sdk-java by Azure.

the class FileUploadInProgressTest method constructorSuccess.

/* Codes_SRS_FILEUPLOADINPROGRESS_21_001: [The constructor shall sore the content of the `statusCallback`, and `statusCallbackContext`.] */
@Test
public void constructorSuccess() {
    // arrange
    final Map<String, Object> context = new HashMap<>();
    // act
    FileUploadInProgress fileUploadInProgress = Deencapsulation.newInstance(FileUploadInProgress.class, new Class[] { IotHubEventCallback.class, Object.class }, mockIotHubEventCallback, context);
    // assert
    assertEquals(mockIotHubEventCallback, Deencapsulation.getField(fileUploadInProgress, "statusCallback"));
    assertEquals(context, Deencapsulation.getField(fileUploadInProgress, "statusCallbackContext"));
}
Also used : FileUploadInProgress(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 5 with FileUploadInProgress

use of com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress in project azure-iot-sdk-java by Azure.

the class FileUploadInProgressTest method setTaskThrows.

/* Codes_SRS_FILEUPLOADINPROGRESS_21_004: [If the `task` is null, the setTask shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void setTaskThrows() {
    // arrange
    final Map<String, Object> context = new HashMap<>();
    FileUploadInProgress fileUploadInProgress = Deencapsulation.newInstance(FileUploadInProgress.class, new Class[] { IotHubEventCallback.class, Object.class }, mockIotHubEventCallback, context);
    // act
    Deencapsulation.invoke(fileUploadInProgress, "setTask", new Class[] { Future.class }, (Future) null);
}
Also used : FileUploadInProgress(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

FileUploadInProgress (com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress)8 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 NonStrictExpectations (mockit.NonStrictExpectations)2 FileUpload (com.microsoft.azure.sdk.iot.device.fileupload.FileUpload)1 HttpsTransportManager (com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager)1 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1 Verifications (mockit.Verifications)1