/** Testing {@link MediaType#valueOf(String)} and {@link MediaType#register(String, String)} */
  public void testValueOf() {
    assertSame(MediaType.APPLICATION_XML, MediaType.valueOf("application/xml"));
    assertSame(MediaType.ALL, MediaType.valueOf("*/*"));
    final MediaType newType = MediaType.valueOf("application/x-restlet-test");
    assertEquals("application", newType.getMainType());
    assertEquals("x-restlet-test", newType.getSubType());
    assertEquals("application/x-restlet-test", newType.getName());

    // Should not have got registered by call to valueOf() alone
    assertNotSame(newType, MediaType.valueOf("application/x-restlet-test"));

    final MediaType registeredType =
        MediaType.register("application/x-restlet-test", "Restlet testcase");
    assertNotSame(newType, registeredType); // didn't touch old value
    assertEquals("application/x-restlet-test", registeredType.getName());
    assertEquals("Restlet testcase", registeredType.getDescription());

    // Later valueOf calls always returns the registered type
    assertSame(registeredType, MediaType.valueOf("application/x-restlet-test"));
    assertSame(registeredType, MediaType.valueOf("application/x-restlet-test"));

    // Test toString() equivalence
    MediaType mediaType = MediaType.valueOf("application/atom+xml; name=value");
    assertEquals("application/atom+xml; name=value", mediaType.toString());
    assertEquals(MediaType.APPLICATION_ATOM, mediaType.getParent());
  }
  /**
   * Makes sure that a {@link MediaType} instance initialized on the specified name has the expected
   * values.
   *
   * @param name type to analyze.
   * @param main expected main type.
   * @param sub expected subtype.
   * @param concrete expected 'concrete' flag.
   */
  public void assertMediaType(String name, String main, String sub, boolean concrete) {
    MediaType type;

    type = new MediaType(name);
    assertEquals(main, type.getMainType());
    assertEquals(sub, type.getSubType());
    assertEquals(concrete, type.isConcrete());
  }