jamesfredley commented on code in PR #16490:
URL: https://github.com/apache/grails-core/pull/16490#discussion_r4174363341
##########
grails-test-suite-uber/src/test/groovy/org/grails/plugins/testing/GrailsMockHttpServletResponseTests.groovy:
##########
@@ -19,15 +19,89 @@
package org.grails.plugins.testing
import org.grails.plugins.testing.GrailsMockHttpServletResponse
+import org.grails.web.servlet.mvc.GrailsWebRequest
import org.junit.jupiter.api.Test
+import org.springframework.web.context.request.RequestAttributes
+import org.springframework.web.context.request.RequestContextHolder
+import static org.junit.jupiter.api.Assertions.assertArrayEquals
import static org.junit.jupiter.api.Assertions.assertEquals
import static org.junit.jupiter.api.Assertions.assertFalse
/**
* Test case for {@link
org.grails.plugins.testing.GrailsMockHttpServletResponse}.
*/
class GrailsMockHttpServletResponseTests {
+ @Test
+ void testResetDoesNotSelectAWriterBeforeBinaryOutput() {
+ withBoundWebRequest { response, webRequest ->
+ response.reset()
+
+ byte[] data = [0, 1, 127, -1] as byte[]
+ response.outputStream.write(data)
+
+ assertArrayEquals data, response.contentAsByteArray
+ }
+ }
+
+ @Test
+ void testResetAllowsBinaryOutputAfterText() {
+ withBoundWebRequest { response, webRequest ->
+ webRequest.out.write('previous text')
+ response.flushBuffer()
+
+ response.reset()
+ byte[] data = [0, 1, 127, -1] as byte[]
+ response.outputStream.write(data)
+
+ assertArrayEquals data, response.contentAsByteArray
+ }
+ }
+
+ @Test
+ void testResetAllowsTextOutputAfterBinary() {
Review Comment:
The post-reset text assertions use only ASCII (`new text`). They do not show
that a charset chosen after `reset()` still reaches the lazily opened writer,
rather than a writer that already captured the default encoding.
Non-blocking follow-up: reset, set UTF-8 through the public response API,
write non-ASCII text, and assert the UTF-8 bytes. The writer/stream selection
bug itself is already covered.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]