use of com.microsoft.azure.sdk.iot.device.Template in project azure-iot-sdk-java by Azure.
the class TemplateTest method testCloseWhenCalledTwiceReturnsSuccessfully.
// Tests_SRS_TEMPLATE_99_007: [If close is already called then this method shall do nothing and return.]
@Test
public void testCloseWhenCalledTwiceReturnsSuccessfully(@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");
Deencapsulation.invoke(testObject, "close");
//assert
/* Verify any call flow and number of times the call is expected on mocked objects close is invoked */
new Verifications() {
{
mockedSet.clear();
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.Template in project azure-iot-sdk-java by Azure.
the class TemplateTest method testAddToSetThrowsIfEmptyInputSet.
// 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 testAddToSetThrowsIfEmptyInputSet(@Mocked final Set<String> mockedSet) {
//arrange
final String testString = "testString";
/* Set any expectations on mocked object */
new NonStrictExpectations() {
{
mockedSet.size();
result = 0;
}
};
/* Put the class in expected state before testing it */
Template testObject = Deencapsulation.newInstance(Template.class, testString);
Deencapsulation.invoke(testObject, "open");
//act
testObject.addToSet(mockedSet);
//assert
/* Throws exception */
}
use of com.microsoft.azure.sdk.iot.device.Template 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 com.microsoft.azure.sdk.iot.device.Template in project azure-iot-sdk-java by Azure.
the class TemplateTest method testAddToSetThrowsIfCalledWithoutOpen.
// Tests_SRS_TEMPLATE_99_012: [The method shall throw IllegalStateException if it is called before calling open. ]
@Test(expected = IllegalArgumentException.class)
public void testAddToSetThrowsIfCalledWithoutOpen() {
//arrange
final String testString = "testString";
final Set<String> newSet = new HashSet<>();
/* Set any expectations on mocked object */
new NonStrictExpectations() {
{
}
};
/* Put the class in expected state before testing it */
Template testObject = Deencapsulation.newInstance(Template.class, testString);
//act
/* Use Deencapsulation or reflection to access objects that are not scoped for test */
testObject.addToSet(newSet);
//assert
/* Throws exception */
}
use of com.microsoft.azure.sdk.iot.device.Template in project azure-iot-sdk-java by Azure.
the class TemplateTest method testAddToSetSucceeds.
// Tests_SRS_TEMPLATE_99_010: [The method shall add the collection to the union set .]
@Test
public void testAddToSetSucceeds() {
//arrange
final String testString = "testString";
final Set<String> newSet = new HashSet<>();
newSet.add("test1");
newSet.add("test2");
/* 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
/* Use Deencapsulation or reflection to access objects that are not scoped for test */
final Set actualSet = Deencapsulation.getField(testObject, "unionSet");
assertNotNull(actualSet);
assertTrue(actualSet.size() == 2);
/* Verify any call flow on mocked objects that is expected on act */
new Verifications() {
{
}
};
}
Aggregations