/** * Creates a MimeType instance with the given type and sub-type values. * * @param type * the type to assign to the mimetype * @param subType * the subtype to assign to the mimetype * * @return a MimeType instance with the given type, sub-type, and an empty parameters map. */ public static MimeType of(final Type type, final SubType subType) { return of(type, subType, new HashMap<>()); }
@Test public void test_mimetype_to_string_works () { final Map<String,String> parameters = new HashMap<>(); parameters.put("key","value"); final MimeType complex = MimeType.of( MimeType.Type.EXAMPLE, MimeType.SubType.of(MimeType.Facet.PERSONAL, "niketest", Optional.of("json")), parameters ); assertThat(complex.toString()).isEqualTo("example/prs.niketest+json;key=value"); }
@Test public void test_mimetype_compares_two_indentical_instances_correctly () { final MimeType one = MimeType.of(MimeType.Type.APPLICATION, MimeType.SubType.of("json")); final MimeType two = MimeType.of(MimeType.Type.APPLICATION, MimeType.SubType.of("json")); assertThat(one).isEqualTo(two); assertThat(one.hashCode()).isEqualTo(two.hashCode()); }
@Test public void test_mimetype_compares_two_different_instances_correctly () { final MimeType one = MimeType.of(MimeType.Type.APPLICATION, MimeType.SubType.of("json")); final MimeType two = MimeType.of(MimeType.Type.APPLICATION, MimeType.SubType.of(MimeType.Facet.STANDARD, "schema", Optional.of("json"))); assertThat(one).isNotEqualTo(two); assertThat(one.hashCode()).isNotEqualTo(two.hashCode()); }
MimeType givenMimeType = MimeType.of(givenType, givenSubType, Collections.emptyMap());