EntityTag { public static boolean isValid(@Nullable final CharSequence entityTag) { boolean result = false; if (null != entityTag) { final Matcher matcher = ENTITY_TAG_REGEX_PATTERN.matcher(entityTag); result = matcher.matches(); } return result; } private  EntityTag(final boolean weak, final String opaqueTag); static boolean isValid(@Nullable final CharSequence entityTag); String getOpaqueTag(); boolean isWeak(); boolean strongCompareTo(final EntityTag otherEntityTag); boolean weakCompareTo(final EntityTag otherEntityTag); static EntityTag fromString(final String entityTag); static Optional<EntityTag> fromEntity(@Nullable final Object entity); static EntityTag strong(final String opaqueTag); static EntityTag weak(final String opaqueTag); @Override String toString(); @Override boolean equals(@Nullable final Object o); @Override int hashCode();  }
@Test public void weakPrefixIsCaseSensitive() { final String invalidEntityTag = "w/\"hallo\""; softly.assertThat(EntityTag.isValid(invalidEntityTag)).isFalse(); assertExceptionWhenCreatingFromString(invalidEntityTag); }
@Test public void weakEntityTagMustNotContainAsteriskInOpaqueTag() { final String invalidEntityTag = "w/\"*\""; softly.assertThat(EntityTag.isValid(invalidEntityTag)).isFalse(); assertExceptionWhenCreatingFromString(invalidEntityTag); }
@Test public void strongEntityTagMustNotContainAsteriskInOpaqueTag() { final String invalidEntityTag = "\"*\""; softly.assertThat(EntityTag.isValid(invalidEntityTag)).isFalse(); assertExceptionWhenCreatingFromString(invalidEntityTag); }
@Test public void weakEntityTagOpaqueTagMustStartWithDoubleQuotes() { final String invalidEntityTag = "W/hallo\""; softly.assertThat(EntityTag.isValid(invalidEntityTag)).isFalse(); assertExceptionWhenCreatingFromString(invalidEntityTag, "hallo\""); }
@Test public void strongEntityTagOpaqueTagMustStartWithDoubleQuotes() { final String invalidEntityTag = "hallo\""; softly.assertThat(EntityTag.isValid(invalidEntityTag)).isFalse(); assertExceptionWhenCreatingFromString(invalidEntityTag); }
@Test public void weakEntityTagOpaqueTagMustEndWithDoubleQuotes() { final String invalidEntityTag = "W/\"hallo"; softly.assertThat(EntityTag.isValid(invalidEntityTag)).isFalse(); assertExceptionWhenCreatingFromString(invalidEntityTag, "\"hallo"); }
@Test public void strongEntityTagOpaqueTagMustEndWithDoubleQuotes() { final String invalidEntityTag = "\"hallo"; softly.assertThat(EntityTag.isValid(invalidEntityTag)).isFalse(); assertExceptionWhenCreatingFromString(invalidEntityTag); }
@Test public void weakEntityTagOpaqueTagMustNotContainMoreThanTwoDoubleQuotes() { final String invalidEntityTag = "\"\"W/\\\"hal\\\"l\\\"o\\\"\""; softly.assertThat(EntityTag.isValid(invalidEntityTag)).isFalse(); assertExceptionWhenCreatingFromString(invalidEntityTag); }
@Test public void strongEntityTagOpaqueTagMustNotContainMoreThanTwoDoubleQuotes() { final String invalidEntityTag = "\"hal\"l\"o\""; softly.assertThat(EntityTag.isValid(invalidEntityTag)).isFalse(); assertExceptionWhenCreatingFromString(invalidEntityTag); }