IfMatchPreconditionHeader implements PreconditionHeader<EntityTag> { @Override public boolean meetsConditionFor(@Nullable final EntityTag entityTag) { if (entityTag == null) { return false; } return entityTagsToMatch.stream().anyMatch(entityTagToMatch -> entityTagToMatch.strongMatch(entityTag)); } private  IfMatchPreconditionHeader(final EntityTagMatchers entityTagsToMatch); @Override String getKey(); @Override String getValue(); @Override boolean meetsConditionFor(@Nullable final EntityTag entityTag); static Optional<IfMatchPreconditionHeader> fromDittoHeaders(final DittoHeaders dittoHeaders);  }
@Test public void meetsCondition() { final IfMatchPreconditionHeader ifMatchPreconditionHeader = createIfMatchPreconditionHeader(fromCommaSeparatedString("\"4711\"")); assertThat(ifMatchPreconditionHeader.meetsConditionFor(EntityTag.fromString("\"4711\""))).isTrue(); }
@Test public void doesNotMeetConditionForNull() { final IfMatchPreconditionHeader ifMatchPreconditionHeader = createIfMatchPreconditionHeader(fromCommaSeparatedString("\"4711\"")); assertThat(ifMatchPreconditionHeader.meetsConditionFor(null)).isFalse(); }
@Test public void asteriskDoesNotMeetConditionForNull() { final IfMatchPreconditionHeader ifMatchPreconditionHeader = createIfMatchPreconditionHeader(fromCommaSeparatedString("*")); assertThat(ifMatchPreconditionHeader.meetsConditionFor(null)).isFalse(); }
@Test public void asteriskMeetsConditionForNonNull() { final IfMatchPreconditionHeader ifMatchPreconditionHeader = createIfMatchPreconditionHeader(fromCommaSeparatedString("*")); assertThat(ifMatchPreconditionHeader.meetsConditionFor(EntityTag.fromString("\"4711\""))).isTrue(); assertThat(ifMatchPreconditionHeader.meetsConditionFor(EntityTag.fromString("\"foo\""))).isTrue(); }
@Test public void ListMeetsConditionIfContained() { final IfMatchPreconditionHeader ifMatchPreconditionHeader = createIfMatchPreconditionHeader(fromCommaSeparatedString("\"foo\",\"bar\"")); assertThat(ifMatchPreconditionHeader.meetsConditionFor(EntityTag.fromString("\"bar\""))).isTrue(); }
@Test public void ListDoesNotMeetConditionIfNotContained() { final IfMatchPreconditionHeader ifMatchPreconditionHeader = createIfMatchPreconditionHeader(fromCommaSeparatedString("\"foo\",\"bar\"")); assertThat(ifMatchPreconditionHeader.meetsConditionFor(EntityTag.fromString("\"baz\""))).isFalse(); }