MockHttpServletRequest returns a single InputStream or Reader
Issue: SPR-16505 Issue: SPR-16499
This commit is contained in:
@@ -47,6 +47,7 @@ import static org.junit.Assert.*;
|
||||
* @author Sam Brannen
|
||||
* @author Brian Clozel
|
||||
* @author Jakub Narloch
|
||||
* @author Av Pinzur
|
||||
*/
|
||||
public class MockHttpServletRequestTests {
|
||||
|
||||
@@ -112,6 +113,38 @@ public class MockHttpServletRequestTests {
|
||||
assertNull(request.getContentAsByteArray());
|
||||
}
|
||||
|
||||
@Test // SPR-16505
|
||||
public void getReaderTwice() throws IOException {
|
||||
byte[] bytes = "body".getBytes(Charset.defaultCharset());
|
||||
request.setContent(bytes);
|
||||
assertSame(request.getReader(), request.getReader());
|
||||
}
|
||||
|
||||
@Test // SPR-16505
|
||||
public void getInputStreamTwice() throws IOException {
|
||||
byte[] bytes = "body".getBytes(Charset.defaultCharset());
|
||||
request.setContent(bytes);
|
||||
assertSame(request.getInputStream(), request.getInputStream());
|
||||
}
|
||||
|
||||
@Test // SPR-16499
|
||||
public void getReaderAfterGettingInputStream() throws IOException {
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectMessage(
|
||||
"Cannot call getReader() after getInputStream() has already been called for the current request");
|
||||
request.getInputStream();
|
||||
request.getReader();
|
||||
}
|
||||
|
||||
@Test // SPR-16499
|
||||
public void getInputStreamAfterGettingReader() throws IOException {
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectMessage(
|
||||
"Cannot call getInputStream() after getReader() has already been called for the current request");
|
||||
request.getReader();
|
||||
request.getInputStream();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setContentType() {
|
||||
String contentType = "test/plain";
|
||||
|
||||
Reference in New Issue
Block a user