IfNoneMatchPreconditionHeader implements PreconditionHeader<EntityTag> { @Override public boolean meetsConditionFor(@Nullable final EntityTag entityTag) { if (entityTag == null) { return true; } return entityTagsToMatch.stream().noneMatch(entityTagToMatch -> entityTagToMatch.weakMatch(entityTag)); } private  IfNoneMatchPreconditionHeader(final EntityTagMatchers entityTagsToMatch); @Override String getKey(); @Override String getValue(); @Override boolean meetsConditionFor(@Nullable final EntityTag entityTag); static Optional<IfNoneMatchPreconditionHeader> fromDittoHeaders(final DittoHeaders dittoHeaders);  }
@Test public void doesNotMeetConditionForEqualOpaqueTag() { final IfNoneMatchPreconditionHeader ifNoneMatchPreconditionHeader = createIfNoneMatchPreconditionHeader(EntityTagMatchers.fromCommaSeparatedString("\"4711\"")); assertThat(ifNoneMatchPreconditionHeader.meetsConditionFor(EntityTag.fromString("\"4711\""))).isFalse(); assertThat(ifNoneMatchPreconditionHeader.meetsConditionFor(EntityTag.fromString("W/\"4711\""))).isFalse(); }
@Test public void meetsConditionForNull() { final IfNoneMatchPreconditionHeader ifNoneMatchPreconditionHeader = createIfNoneMatchPreconditionHeader(EntityTagMatchers.fromCommaSeparatedString("\"4711\"")); assertThat(ifNoneMatchPreconditionHeader.meetsConditionFor(null)).isTrue(); }
@Test public void asteriskMeetsConditionForNull() { final IfNoneMatchPreconditionHeader ifNoneMatchPreconditionHeader = createIfNoneMatchPreconditionHeader(EntityTagMatchers.fromCommaSeparatedString("*")); assertThat(ifNoneMatchPreconditionHeader.meetsConditionFor(null)).isTrue(); }
@Test public void asteriskDoesNotMeetConditionForNonNull() { final IfNoneMatchPreconditionHeader ifNoneMatchPreconditionHeader = createIfNoneMatchPreconditionHeader(EntityTagMatchers.fromCommaSeparatedString("*")); assertThat(ifNoneMatchPreconditionHeader.meetsConditionFor(EntityTag.fromString("\"4711\""))).isFalse(); assertThat(ifNoneMatchPreconditionHeader.meetsConditionFor(EntityTag.fromString("\"foo\""))).isFalse(); }
@Test public void ListMeetsConditionIfNotContained() { final IfNoneMatchPreconditionHeader ifNoneMatchPreconditionHeader = createIfNoneMatchPreconditionHeader(fromCommaSeparatedString("\"foo\",\"bar\"")); assertThat(ifNoneMatchPreconditionHeader.meetsConditionFor(EntityTag.fromString("\"baz\""))).isTrue(); }
@Test public void ListDoesNotMeetConditionIfContained() { final IfNoneMatchPreconditionHeader ifNoneMatchPreconditionHeader = createIfNoneMatchPreconditionHeader(fromCommaSeparatedString("\"foo\",\"bar\"")); assertThat(ifNoneMatchPreconditionHeader.meetsConditionFor(EntityTag.fromString("\"bar\""))).isFalse(); }