use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.
the class DeviceMethodTest method invokeThrowOnGetUrlMethodFailed.
/* Tests_SRS_DEVICEMETHOD_21_008: [The invoke shall build the Method URL `{iot hub}/twins/{device id}/methods/` by calling getUrlMethod.] */
@Test(expected = IllegalArgumentException.class)
public void invokeThrowOnGetUrlMethodFailed(@Mocked final MethodParser methodParser) throws Exception {
// arrange
DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
new NonStrictExpectations() {
{
methodParser.toJson();
result = STANDARD_JSON;
IotHubConnectionString.getUrlMethod(anyString, STANDARD_DEVICEID);
result = new IllegalArgumentException();
}
};
// act
testMethod.invoke(STANDARD_DEVICEID, STANDARD_METHODNAME, STANDARD_TIMEOUT_SECONDS, STANDARD_TIMEOUT_SECONDS, STANDARD_PAYLOAD_MAP);
}
use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.
the class BaseDeviceTest method constructor_create_symmetrickey.
// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_12_005: [If the input symmetric key is empty, the constructor shall create
// a new SymmetricKey instance using AES encryption and store it into a member variable]
@Test
public void constructor_create_symmetrickey() throws NoSuchAlgorithmException {
// Arrange
String encryptionMethod = "AES";
String deviceId = "xxx-device";
new NonStrictExpectations() {
{
SymmetricKey symmetricKey = new SymmetricKey();
KeyGenerator.getInstance(encryptionMethod);
}
};
// Act
BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, deviceId, SymmetricKey.class);
// Assert
assertNotEquals(device.getSymmetricKey(), null);
}
use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.
the class X509CertificatesTest method constructorStorePrimaryAndSecondaryCertsSucceed.
/* SRS_X509_CERTIFICATES_21_003: [If the secondary certificate is not null or empty, the constructor shall create a new instance of the X509CertificateWithInfo using the provided secondary certificate, and store it as the secondary Certificate.] */
@Test
public void constructorStorePrimaryAndSecondaryCertsSucceed(@Mocked final X509CertificateWithInfo mockedX509CertificateWithInfo) throws IllegalArgumentException {
// arrange
new NonStrictExpectations() {
{
Deencapsulation.newInstance(X509CertificateWithInfo.class, new Class[] { String.class }, PUBLIC_CERTIFICATE_STRING);
result = mockedX509CertificateWithInfo;
times = 2;
}
};
// act
X509Certificates x509Certificates = Deencapsulation.newInstance(X509Certificates.class, new Class[] { String.class, String.class }, PUBLIC_CERTIFICATE_STRING, PUBLIC_CERTIFICATE_STRING);
// assert
assertNotNull(Deencapsulation.getField(x509Certificates, "primary"));
assertNotNull(Deencapsulation.getField(x509Certificates, "secondary"));
}
use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.
the class X509CertificatesTest method constructorStorePrimaryCertSucceed.
/* SRS_X509_CERTIFICATES_21_002: [The constructor shall create a new instance of the X509CertificateWithInfo using the provided primary certificate, and store is as the primary Certificate.] */
/* SRS_X509_CERTIFICATES_21_003: [If the secondary certificate is not null or empty, the constructor shall create a new instance of the X509CertificateWithInfo using the provided secondary certificate, and store it as the secondary Certificate.] */
@Test
public void constructorStorePrimaryCertSucceed(@Mocked final X509CertificateWithInfo mockedX509CertificateWithInfo) throws IllegalArgumentException {
// arrange
new NonStrictExpectations() {
{
Deencapsulation.newInstance(X509CertificateWithInfo.class, new Class[] { String.class }, PUBLIC_CERTIFICATE_STRING);
result = mockedX509CertificateWithInfo;
times = 1;
}
};
// act
X509Certificates x509Certificates = Deencapsulation.newInstance(X509Certificates.class, new Class[] { String.class, String.class }, PUBLIC_CERTIFICATE_STRING, null);
// assert
assertNotNull(Deencapsulation.getField(x509Certificates, "primary"));
assertNull(Deencapsulation.getField(x509Certificates, "secondary"));
}
use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.
the class ProvisioningServiceClientTest method getEnrollmentGroupSucceed.
/* SRS_PROVISIONING_SERVICE_CLIENT_21_017: [The getEnrollmentGroup shall retrieve the enrollmentGroup information for the provided enrollmentGroupId by calling the get in the enrollmentGroupManager.] */
@Test
public void getEnrollmentGroupSucceed(@Mocked final EnrollmentGroup mockedEnrollmentGroup) throws ProvisioningServiceClientException {
// arrange
final String enrollmentGroupId = "valid-enrollmentGroupId";
ProvisioningServiceClient provisioningServiceClient = createClient();
new NonStrictExpectations() {
{
Deencapsulation.invoke(mockedEnrollmentGroupManager, "get", enrollmentGroupId);
result = mockedEnrollmentGroup;
times = 1;
}
};
// act
EnrollmentGroup result = provisioningServiceClient.getEnrollmentGroup(enrollmentGroupId);
// assert
assertNotNull(result);
}
Aggregations