public void testAddField() {
    MutableBodyDescriptor bd = null;

    /*
     * Make sure that only the first Content-Type header added is used.
     */
    bd = newBodyDescriptor();
    bd.addField(new TestField("Content-Type ", "text/plain; charset=ISO-8859-1"));
    assertEquals("text/plain", bd.getMimeType());
    assertEquals("iso-8859-1", bd.getCharset());
    bd.addField(new TestField("Content-Type ", "text/html; charset=us-ascii"));
    assertEquals("text/plain", bd.getMimeType());
    assertEquals("iso-8859-1", bd.getCharset());
  }
  public void testParameters() {
    MutableBodyDescriptor bd = null;

    /*
     * Test charset.
     */
    bd = newBodyDescriptor();
    assertNull(bd.getCharset());
    bd.addField(new TestField("Content-Type ", "text/type; charset=ISO-8859-1"));
    assertEquals("iso-8859-1", bd.getCharset());

    bd = newBodyDescriptor();
    assertNull(bd.getCharset());
    bd.addField(new TestField("Content-Type ", "text/type"));
    assertNull(bd.getCharset());

    /*
     * Test boundary.
     */
    bd = newBodyDescriptor();
    bd.addField(new TestField("Content-Type", "text/html; boundary=yada yada"));
    assertNull(bd.getBoundary());

    bd = newBodyDescriptor();
    bd.addField(new TestField("Content-Type", "multipart/yada; boundary=yada"));
    assertEquals("yada", bd.getBoundary());

    /*
     * Test some weird parameters.
     */
    bd = newBodyDescriptor();
    bd.addField(new TestField("Content-Type", "multipart/yada; boundary=yada yada"));
    assertEquals("yada", bd.getBoundary());

    bd = newBodyDescriptor();
    bd.addField(
        new TestField("Content-Type", "multipart/yada; boUNdarY= ya:*da; \tcharset\t =  big5"));
    assertEquals("ya:*da", bd.getBoundary());
    assertEquals("big5", bd.getCharset());

    bd = newBodyDescriptor();
    bd.addField(
        new TestField(
            "Content-Type",
            "multipart/yada; boUNdarY= \"ya \\\"\\\"\tda \\\"\"; "
                + "\tcharset\t =  \"\\\"hepp\\\"  =us\t-ascii\""));
    assertEquals("ya \"\"\tda \"", bd.getBoundary());
    assertEquals("\"hepp\"  =us\t-ascii", bd.getCharset());
  }
 public void testDoNotDefaultToUsAsciiForNonTextTypes() throws Exception {
   MutableBodyDescriptor descriptor = newBodyDescriptor();
   descriptor.addField(new TestField("Content-Type", "image/png; name=blob.png"));
   assertNull(descriptor.getCharset());
 }