michael-o commented on code in PR #483:
URL: 
https://github.com/apache/httpcomponents-core/pull/483#discussion_r1771184701


##########
httpcore5/src/test/java/org/apache/hc/core5/http/TestContentType.java:
##########
@@ -183,4 +183,143 @@ void testWithParams() throws Exception {
         Assertions.assertEquals("text/blah; charset=ISO-8859-1; p=blah", 
contentType.toString());
     }
 
+
+    @Test
+    void testImplicitCharsetTrue() {
+        // ContentType with implicitCharset = true
+        final ContentType contentType = ContentType.create("application/json", 
StandardCharsets.UTF_8, true);
+
+        // Check that the charset is not added to the toString() output
+        Assertions.assertEquals("application/json", contentType.toString());
+        // Check that the charset is still stored
+        Assertions.assertEquals(StandardCharsets.UTF_8, 
contentType.getCharset());
+    }
+
+    @Test
+    void testImplicitCharsetFalse() {
+        // ContentType with implicitCharset = false
+        final ContentType contentType = ContentType.create("application/json", 
StandardCharsets.UTF_8, false);
+
+        // Check that the charset is included in the toString() output
+        Assertions.assertEquals("application/json; charset=UTF-8", 
contentType.toString());
+        // Check that the charset is correctly stored
+        Assertions.assertEquals(StandardCharsets.UTF_8, 
contentType.getCharset());
+    }
+
+    @Test
+    void testImplicitCharsetForTextPlain() {
+        // ContentType for text/plain with implicitCharset = true
+        final ContentType contentType = ContentType.create("text/plain", 
StandardCharsets.UTF_8, true);
+
+        // Check that the charset is not included in the toString() output
+        Assertions.assertEquals("text/plain", contentType.toString());
+        // Check that the charset is correctly stored
+        Assertions.assertEquals(StandardCharsets.UTF_8, 
contentType.getCharset());
+    }
+
+    @Test
+    void testNoCharsetWithImplicitCharset() {
+        // ContentType without a charset, implicitCharset = true
+        final ContentType contentType = 
ContentType.create("application/octet-stream", null, true);

Review Comment:
   This test does not make sense to me since the last param does not matter 
when no charset has been provided no? The behavior should be undefined if 
something string-like has been passed, no?



-- 
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: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org

Reply via email to