MockHttpServletRequest returns a single InputStream or Reader

Issue: SPR-16505
Issue: SPR-16499
This commit is contained in:
Juergen Hoeller
2018-06-13 22:03:16 +02:00
parent 9aed9bf823
commit 3fc8ec498c
5 changed files with 113 additions and 38 deletions

View File

@@ -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";