Search in sources :

Example 56 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class CustomLoggerTest method testLogInfo.

// Tests_SRS_CUSTOMERLOGGER_25_002: [The function shall print message for INFO level.]
@Test
public void testLogInfo(@Mocked final Logger mockLogger) {
    final String message = "This is INFO message";
    new NonStrictExpectations() {

        {
            Logger.getLogger((Class) any);
            result = mockLogger;
            mockLogger.isEnabledFor(Level.INFO);
            result = true;
        }
    };
    new CustomLogger(this.getClass()).LogInfo(message);
    new Verifications() {

        {
            mockLogger.info(anyString);
            times = 1;
        }
    };
}
Also used : CustomLogger(com.microsoft.azure.sdk.iot.device.CustomLogger) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 57 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class CustomLoggerTest method testLogError.

// Tests_SRS_CUSTOMERLOGGER_25_002: [The function shall print message for ERROR level.]
@Test
public void testLogError(@Mocked final Logger mockLogger) {
    final String message = "This is CUSTOM ERROR message";
    new NonStrictExpectations() {

        {
            Logger.getLogger((Class) any);
            result = mockLogger;
            mockLogger.isEnabledFor(Level.ERROR);
            result = true;
        }
    };
    new CustomLogger(this.getClass()).LogError(message);
    new Verifications() {

        {
            mockLogger.error(anyString);
            times = 1;
        }
    };
    new NonStrictExpectations() {

        {
            Logger.getLogger((Class) any);
            result = mockLogger;
            mockLogger.isEnabledFor(Level.ERROR);
            result = true;
        }
    };
    new CustomLogger(this.getClass()).LogError(new Throwable("This is ERROR message"));
    new Verifications() {

        {
            mockLogger.error(any);
            times = 1;
        }
    };
}
Also used : CustomLogger(com.microsoft.azure.sdk.iot.device.CustomLogger) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 58 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class CustomLoggerTest method testLogDebug.

// Tests_SRS_CUSTOMERLOGGER_25_002: [The function shall print message for DEBUG level.]
@Test
public void testLogDebug(@Mocked final Logger mockLogger) {
    final String message = "This is DEBUG message";
    new NonStrictExpectations() {

        {
            Logger.getLogger((Class) any);
            result = mockLogger;
            mockLogger.isEnabledFor(Level.DEBUG);
            result = true;
        }
    };
    new CustomLogger(this.getClass()).LogDebug(message);
    new Verifications() {

        {
            mockLogger.debug(anyString);
            times = 1;
        }
    };
}
Also used : CustomLogger(com.microsoft.azure.sdk.iot.device.CustomLogger) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 59 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class AmqpsMessageTest method acknowledgeSetsRejectedDispositionForReject.

// Tests_SRS_AMQPSMESSAGE_14_003: [If the ACK_TYPE is REJECT, the function shall set a Rejected disposition on the private Delivery object.]
@Test
public void acknowledgeSetsRejectedDispositionForReject(@Mocked final Rejected mockRejected) {
    new NonStrictExpectations() {

        {
            new Rejected();
            result = mockRejected;
        }
    };
    AmqpsMessage message = new AmqpsMessage();
    message.setDelivery(mockDelivery);
    message.acknowledge(AmqpsMessage.ACK_TYPE.REJECT);
    final Delivery expectedDelivery = mockDelivery;
    new Verifications() {

        {
            expectedDelivery.disposition(mockRejected);
        }
    };
}
Also used : Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) Delivery(org.apache.qpid.proton.engine.Delivery) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) AmqpsMessage(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsMessage) Test(org.junit.Test)

Example 60 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class IotHubReceiveTaskTest method runDoesNotCrashFromThrowable.

// Tests_SRS_IOTHUBRECEIVETASK_11_005: [The function shall not crash because of any error or exception thrown by the transport.]
@Test
public void runDoesNotCrashFromThrowable() throws IOException, URISyntaxException {
    new NonStrictExpectations() {

        {
            mockTransport.handleMessage();
            result = new Throwable("Test if the receive task does not crash.");
        }
    };
    IotHubReceiveTask receiveTask = new IotHubReceiveTask(mockTransport);
    receiveTask.run();
}
Also used : IotHubReceiveTask(com.microsoft.azure.sdk.iot.device.transport.IotHubReceiveTask) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Aggregations

NonStrictExpectations (mockit.NonStrictExpectations)476 Test (org.junit.Test)470 Verifications (mockit.Verifications)154 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)77 IOException (java.io.IOException)64 HttpConnection (com.microsoft.azure.sdk.iot.service.transport.http.HttpConnection)51 HttpMethod (com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod)51 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)47 MessageProperty (com.microsoft.azure.sdk.iot.device.MessageProperty)32 HttpsSingleMessage (com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage)31 HttpConnection (com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection)26 HttpMethod (com.microsoft.azure.sdk.iot.deps.transport.http.HttpMethod)26 HttpsConnection (com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection)26 HttpsMethod (com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod)26 HashMap (java.util.HashMap)26 JobClient (com.microsoft.azure.sdk.iot.service.jobs.JobClient)25 IotHubConnectionString (com.microsoft.azure.sdk.iot.device.IotHubConnectionString)17 Date (java.util.Date)16 HashSet (java.util.HashSet)16 Query (com.microsoft.azure.sdk.iot.service.devicetwin.Query)15