@Test
public void testWithParams() throws Exception {
ContentType contentType = ContentType.create("text/plain",
new BasicNameValuePair("charset", "UTF-8"),
new BasicNameValuePair("p", "this"),
new BasicNameValuePair("p", "that"));
Assert.assertEquals("text/plain", contentType.getMimeType());
Assert.assertEquals(StandardCharsets.UTF_8, contentType.getCharset());
Assert.assertEquals("text/plain; charset=UTF-8; p=this; p=that", contentType.toString());
contentType = contentType.withParameters(
new BasicNameValuePair("charset", "ascii"),
new BasicNameValuePair("p", "this and that"));
Assert.assertEquals("text/plain", contentType.getMimeType());
Assert.assertEquals(StandardCharsets.US_ASCII, contentType.getCharset());
Assert.assertEquals("text/plain; charset=ascii; p=\"this and that\"", contentType.toString());
contentType = ContentType.create("text/blah").withParameters(
new BasicNameValuePair("p", "blah"));
Assert.assertEquals("text/blah", contentType.getMimeType());
Assert.assertEquals(null, contentType.getCharset());
Assert.assertEquals("text/blah; p=blah", contentType.toString());
contentType = ContentType.create("text/blah", StandardCharsets.ISO_8859_1).withParameters(
new BasicNameValuePair("p", "blah"));
Assert.assertEquals("text/blah", contentType.getMimeType());
Assert.assertEquals(StandardCharsets.ISO_8859_1, contentType.getCharset());
Assert.assertEquals("text/blah; charset=ISO-8859-1; p=blah", contentType.toString());
}