Search in sources :

Example 6 with Template

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

the class TemplateTest method testAddToSetThrowsIfNullInputSet.

// Tests_SRS_TEMPLATE_99_011: [The method shall throw IllegalArgumentException if the collection to be added was either empty or null .]
@Test(expected = IllegalArgumentException.class)
public void testAddToSetThrowsIfNullInputSet() {
    //arrange
    final String testString = "testString";
    final Set<String> newSet = null;
    /* Set any expectations on mocked object */
    new NonStrictExpectations() {

        {
        }
    };
    /* Put the class in expected state before testing it */
    Template testObject = Deencapsulation.newInstance(Template.class, testString);
    Deencapsulation.invoke(testObject, "open");
    //act
    /* Use Deencapsulation or reflection to access objects that are not scoped for test */
    testObject.addToSet(newSet);
//assert
/* Throws exception */
}
Also used : NonStrictExpectations(mockit.NonStrictExpectations) Template(com.microsoft.azure.sdk.iot.device.Template) Test(org.junit.Test)

Example 7 with Template

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

the class TemplateTest method testGetUnionSetGets.

// Tests_SRS_TEMPLATE_99_009: [The method shall return the current instance of the union set.]
@Test
public void testGetUnionSetGets(@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);
    Deencapsulation.invoke(testObject, "open");
    //act
    final Set<String> actualSet = (Set<String>) testObject.getUnionSet();
    //assert
    /* Verify that getter gets as expected */
    assertEquals(actualSet, mockedSet);
    /* Verify any call flow on mocked objects that is expected on act */
    new Verifications() {

        {
        }
    };
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Template(com.microsoft.azure.sdk.iot.device.Template) Test(org.junit.Test)

Example 8 with Template

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

the class TemplateTest method testConstructor.

// Mock global objects which you do not want to test for this class
/*
        Some common objects to be considered for mocking :
        1. Usually you mock objects that are input or output to the class under test
        2. You can also mock objects belonging to JDK which you do not want to test
        3. You can mock objects to control the expected behavior for the method under test
     */
// Tests_SRS_TEMPLATE_99_001: [The constructor shall save the input parameters.]
// Tests_SRS_TEMPLATE_99_003: [The constructor shall create a new instance of the public and private objects.]
@Test
public /* Mock objects specific for this test */
void testConstructor(@Mocked final Set<String> mockedSet) {
    //arrange
    final String testString = "testString";
    /* Set any expectations on mocked object */
    new NonStrictExpectations() {

        {
        }
    };
    //act
    /* Use Deencapsulation or reflection to access objects that are not scoped for test */
    Template testObject = Deencapsulation.newInstance(Template.class, testString);
    //assert
    /* Verify that constructor initializes */
    assertNotNull(testObject.templateTestPublic);
    /* Use Deencapsulation or reflection to access objects that are not scoped for test */
    final String actualString = Deencapsulation.getField(testObject, "templateTestPrivate");
    /* Verify that constructor sets as expected */
    assertEquals(actualString, testString);
    /* Verify any call flow on mocked objects that is expected on act */
    new Verifications() {

        {
        }
    };
}
Also used : Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Template(com.microsoft.azure.sdk.iot.device.Template) Test(org.junit.Test)

Example 9 with Template

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

the class TemplateTest method testCloseDestroysSet.

// Tests_SRS_TEMPLATE_99_006: [This method shall clear the unionSet and set all the members ready for garbage collection.]
@Test
public void testCloseDestroysSet(@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);
    /*Use Dencapsulation to control the expected value of private fields */
    Deencapsulation.setField(testObject, "unionSet", mockedSet);
    //act
    /* Use Deencapsulation or reflection to access objects that are not scoped for test */
    Deencapsulation.invoke(testObject, "close");
    //assert
    /* Use Deencapsulation or reflection to access objects that are not scoped for test */
    final Set actualSet = Deencapsulation.getField(testObject, "unionSet");
    /* Verify that close indeed set the value to null */
    assertNull(actualSet);
    /* Verify any call flow on mocked objects that is expected on close */
    new Verifications() {

        {
            mockedSet.clear();
            times = 1;
        }
    };
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Template(com.microsoft.azure.sdk.iot.device.Template) Test(org.junit.Test)

Example 10 with Template

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

the class TemplateTest method testGetTemplateTestPrivateGets.

// Tests_SRS_TEMPLATE_99_008: [The method shall return the private member object.]
@Test
public void testGetTemplateTestPrivateGets() {
    //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
    final String actualString = (String) testObject.getTemplateTestPrivate();
    //assert
    /* Verify that getter gets as expected */
    assertEquals(actualString, testString);
    /* Verify any call flow on mocked objects that is expected on act */
    new Verifications() {

        {
        }
    };
}
Also used : Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Template(com.microsoft.azure.sdk.iot.device.Template) Test(org.junit.Test)

Aggregations

Template (com.microsoft.azure.sdk.iot.device.Template)11 NonStrictExpectations (mockit.NonStrictExpectations)11 Test (org.junit.Test)11 Verifications (mockit.Verifications)8 HashSet (java.util.HashSet)6 Set (java.util.Set)5