ContentType { public boolean isCompatible(ContentType other) { if (other == null) { return false; } else if (getType().equals(WILDCARD) || other.getType().equals(WILDCARD)) { return true; } else if (getType().equals(other.getType())) { return getSubType().equals(WILDCARD) || other.getSubType().equals(WILDCARD) || getSubType().equals(other.getSubType()); } return false; } ContentType(
            String type,
            String subType,
            Map<String, String> parameters); static ContentType valueOf(String value); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); String getType(); boolean isWildcardType(); String getSubType(); boolean isWildcardSubType(); boolean isWildcard(); Map<String, String> getParameters(); boolean isCompatible(ContentType other);  }
@Test public void isCompatible_same() { ContentType contentType1 = new ContentType("text", "html", new HashMap<>()); ContentType contentType2 = new ContentType("text", "html", new HashMap<>()); boolean compatible = contentType1.isCompatible(contentType2); assertThat(compatible).isTrue(); }
@Test public void isCompatible_differentType() { ContentType contentType1 = new ContentType("text", "*", new HashMap<>()); ContentType contentType2 = new ContentType("application", "*", new HashMap<>()); boolean compatible = contentType1.isCompatible(contentType2); assertThat(compatible).isFalse(); }
@Test public void isCompatible_sameType_differentSubtype() { ContentType contentType1 = new ContentType("text", "css", new HashMap<>()); ContentType contentType2 = new ContentType("text", "html", new HashMap<>()); boolean compatible = contentType1.isCompatible(contentType2); assertThat(compatible).isFalse(); }
@Test public void isCompatible_wildCardType1() { ContentType contentType1 = new ContentType("*", "*", new HashMap<>()); ContentType contentType2 = new ContentType("application", "*", new HashMap<>()); boolean compatible = contentType1.isCompatible(contentType2); assertThat(compatible).isTrue(); }
@Test public void isCompatible_wildCardType2() { ContentType contentType1 = new ContentType("text", "*", new HashMap<>()); ContentType contentType2 = new ContentType("*", "*", new HashMap<>()); boolean compatible = contentType1.isCompatible(contentType2); assertThat(compatible).isTrue(); }
@Test public void isCompatible_sameType_wildcardSubType1() { ContentType contentType1 = new ContentType("text", "*", new HashMap<>()); ContentType contentType2 = new ContentType("text", "html", new HashMap<>()); boolean compatible = contentType1.isCompatible(contentType2); assertThat(compatible).isTrue(); }
@Test public void isCompatible_sameType_wildcardSubType2() { ContentType contentType1 = new ContentType("text", "html", new HashMap<>()); ContentType contentType2 = new ContentType("text", "*", new HashMap<>()); boolean compatible = contentType1.isCompatible(contentType2); assertThat(compatible).isTrue(); }
@Test public void isCompatible_null() { ContentType contentType1 = new ContentType("text", "html", new HashMap<>()); ContentType contentType2 = null; boolean compatible = contentType1.isCompatible(contentType2); assertThat(compatible).isFalse(); }