### Question:
RFC6838MediaRangeValidator implements MediaRangeValidator { @Override public void checkSubType(final String subType) { validateLength(subType,"Subtype"); validateFirstChar(subType,"subtype"); validateOtherChars(subType,"subtype"); } RFC6838MediaRangeValidator(); @Override void checkType(final String type); @Override void checkSubType(final String subType); @Override void checkSuffix(final String suffix);  }### Answer:
@Test public void failsForSubTypeWithInvalidFirstChar() throws Exception { try { sut.checkSubType(".invalidFirstChar"); fail("Should fail subtype check if first char is not valid"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(),equalTo("Invalid character '.' in subtype '.invalidFirstChar' at 0")); } }
@Test public void failsForSubTypeWithInvalidOtherChar() throws Exception { try { sut.checkSubType("invalidÓtherChar"); fail("Should fail subtype check if other char is not valid"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(),equalTo("Invalid character 'Ó' in subtype 'invalidÓtherChar' at 7")); } }
@Test public void failsIfSubtypeLengthIsGreaterThanExpected() throws Exception { try { sut.checkSubType(longName()); fail("Should fail subtype check if length is greater than expected"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(),equalTo("Subtype length cannot be greater than 127 ('"+longName()+"' has 128)")); } }
@Test public void acceptsMinimalSubtype() { sut.checkSubType("A"); }
@Test public void acceptsWildcardSubType() { sut.checkSubType("*"); }
@Test public void failsForWrongWildcardSubType() { try { sut.checkSubType("*bad"); fail("Should fail subtype check if bad wildcard subtype is defined"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(),equalTo("Invalid character '*' in subtype '*bad' at 0")); } }