use of mockit.Expectations 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.Expectations in project pulsar by yahoo.
the class AbstractStatelessLongHashTest method testCalculateReadOnlyByteBuffer.
@Test
public void testCalculateReadOnlyByteBuffer() {
final ByteBuffer input = ByteBuffer.allocate(20).asReadOnlyBuffer();
input.position(5);
input.limit(15);
new Expectations(hash) {
{
hash.calculateUnchecked(withInstanceOf(byte[].class), 0, 10);
}
};
hash.calculate(input);
assertEquals(input.limit(), input.position());
}
use of mockit.Expectations in project pulsar by yahoo.
the class AbstractIncrementalIntHashTest method testCalculateByteBuffer.
@Test
public void testCalculateByteBuffer() {
final ByteBuffer input = ByteBuffer.allocate(10);
new Expectations(hash) {
{
hash.initial();
result = 42;
hash.resume(42, input);
}
};
hash.calculate(input);
}
use of mockit.Expectations in project pulsar by yahoo.
the class AbstractIncrementalIntHashTest method testResumeIntReadOnlyByteBuffer.
@Test
public void testResumeIntReadOnlyByteBuffer() {
final ByteBuffer input = ByteBuffer.allocate(20).asReadOnlyBuffer();
input.position(5);
input.limit(15);
new Expectations(hash) {
{
hash.resumeUnchecked(42, withInstanceOf(byte[].class), 0, 10);
}
};
hash.resume(42, input);
assertEquals(input.limit(), input.position());
}
use of mockit.Expectations in project pulsar by yahoo.
the class AbstractIncrementalIntHashTest method testResumeIntByteBuffer.
@Test
public void testResumeIntByteBuffer() {
final ByteBuffer input = ByteBuffer.allocate(20);
input.position(5);
input.limit(15);
new Expectations(hash) {
{
hash.resumeUnchecked(42, input.array(), input.arrayOffset() + 5, 10);
}
};
hash.resume(42, input);
assertEquals(input.limit(), input.position());
}
Aggregations