--
You received this message because you are subscribed to the Google Groups "mockito" group.
To post to this group, send email to moc...@googlegroups.com.
To unsubscribe from this group, send email to mockito+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mockito?hl=en.
If you're only calling one method on the request, you could just hand-roll the mock. If you're using Spring, it has a ready-made request mock.
Moandji
Sent from my phone
Thanks,
James
You can wrap your ByteArrayInputStream in a custom ServletInputSream:
when(request.getInputStream()).thenReturn(createServletInputStream("the
string"));
public static ServletInputStream createServletInputStream(Object
object) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(baos );
os.writeObject(object);
final InputStream bais = new
ByteArrayInputStream(baos.toByteArray());
return new ServletInputStream() {
@Override
public int read() throws IOException {
return bais.read();
}
};
}
Balazs
Sorry not very familiar with the terminology what do you mean by "hand
rolling the mock"?