use of mockit.Verifications in project jersey by jersey.
the class FormDataMultiPartReaderWriterTest method mimeTempFileRemovedAfterAbortedUpload.
/**
* Mocked JERSEY-2794 reproducer. Real test is under integration tests.
*/
@Test
public void mimeTempFileRemovedAfterAbortedUpload(@Mocked final MIMEMessage message) throws Exception {
new Expectations() {
{
message.getAttachments();
result = new MIMEParsingException();
}
};
final URL url = new URL(getBaseUri().toString() + "MediaTypeWithBoundaryResource");
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("PUT");
connection.setRequestProperty("Accept", "text/plain");
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=XXXX_YYYY");
connection.setDoOutput(true);
connection.connect();
final OutputStream outputStream = connection.getOutputStream();
outputStream.write("--XXXX_YYYY".getBytes());
outputStream.write('\n');
outputStream.write("Content-Type: text/plain".getBytes());
outputStream.write('\n');
outputStream.write("Content-Disposition: form-data; name=\"big-part\"".getBytes());
outputStream.write('\n');
outputStream.write('\n');
// Send big chunk of data.
for (int i = 0; i < 16 * 4096; i++) {
outputStream.write('E');
if (i % 1024 == 0) {
outputStream.flush();
}
}
// Do NOT send end of the MultiPart message to simulate the issue.
// Get Response ...
final int response = connection.getResponseCode();
// ... Disconnect.
connection.disconnect();
assertThat("Bad Request expected", response, is(400));
// Make sure that the Mimepull message and it's parts have been closed and temporary files deleted.
new Verifications() {
{
message.close();
times = 1;
}
};
}
use of mockit.Verifications 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 mockit.Verifications 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 mockit.Verifications in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method stopSucceedsDoesNotCallUnSubscribeIfNotStarted.
@Test
public void stopSucceedsDoesNotCallUnSubscribeIfNotStarted() throws IOException {
//arrange
MqttDeviceMethod testMethod = new MqttDeviceMethod();
//act
testMethod.stop();
//assert
new Verifications() {
{
Deencapsulation.invoke(mockedMqtt, "unsubscribe", anyString);
maxTimes = 0;
}
};
}
use of mockit.Verifications in project azure-iot-sdk-java by Azure.
the class HttpsSingleMessageTest method toMessageCopiesBody.
// Tests_SRS_HTTPSSINGLEMESSAGE_11_007: [The function shall return an IoT Hub message with a copy of the message body as its body.]
@Test
public void toMessageCopiesBody(@Mocked final HttpsResponse mockResponse, @Mocked final MessageProperty mockProperty, @Mocked final Message mockMsg) {
final byte[] body = { 0x61, 0x62, 0x63 };
final Map<String, String> headerFields = new HashMap<>();
final String propertyName = "iothub-app-test-property-name";
final String propertyValue = "test-property-value";
headerFields.put(propertyName, propertyValue);
new NonStrictExpectations() {
{
mockResponse.getBody();
result = body;
mockResponse.getHeaderFields();
result = headerFields;
MessageProperty.isValidAppProperty(propertyName, propertyValue);
result = true;
new MessageProperty(propertyName, propertyValue);
result = mockProperty;
mockProperty.getName();
result = propertyName;
mockProperty.getValue();
result = propertyValue;
new Message(body);
result = mockMsg;
}
};
HttpsSingleMessage httpsMsg = HttpsSingleMessage.parseHttpsMessage(mockResponse);
httpsMsg.toMessage();
final byte[] expectedBody = body;
new Verifications() {
{
new Message(expectedBody);
}
};
}
Aggregations