jdaugherty commented on code in PR #16490:
URL: https://github.com/apache/grails-core/pull/16490#discussion_r4174499084


##########
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:
   Added `testResetUsesCharacterEncodingChosenAfterReset` in 8bd0204061. It 
writes text first so a writer exists, resets, sets UTF-8 through 
`response.characterEncoding`, writes `café €` through `webRequest.out`, and 
asserts the UTF-8 bytes. With the previous `reset()` it fails (6 bytes instead 
of 9) because the writer opened during reset was already set to ISO-8859-1.



-- 
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]

Reply via email to