/** {@inheritDoc} */ @Override public SELF is(Condition<? super ACTUAL> condition) { conditions.assertIs(info, actual, condition); return myself; }
/** {@inheritDoc} */ @Override public SELF doesNotHave(Condition<? super ACTUAL> condition) { conditions.assertDoesNotHave(info, actual, condition); return myself; }
/** {@inheritDoc} */ @Override public SELF has(Condition<? super ACTUAL> condition) { conditions.assertHas(info, actual, condition); return myself; }
private void assertNotNull(Condition<?> condition) { Conditions.instance().assertIsNotNull(condition); }
/** * Asserts the given <code>{@link Condition}</code> is not null. * @param condition the given {@code Condition}. * @throws NullPointerException if the given {@code Condition} is {@code null}. */ public void assertIsNotNull(Condition<?> condition) { assertIsNotNull(condition, "The condition to evaluate should not be null"); }
/** {@inheritDoc} */ @Override public SELF isNot(Condition<? super ACTUAL> condition) { conditions.assertIsNot(info, actual, condition); return myself; }
/** {@inheritDoc} */ @Override public SELF satisfies(Condition<? super ACTUAL> condition) { conditions.assertSatisfies(info, actual, condition); return myself; }
/** * Asserts the given <code>{@link Condition}</code> is not null. * @param condition the given {@code Condition}. * @throws NullPointerException if the given {@code Condition} is {@code null}. */ public void assertIsNotNull(Condition<?> condition) { assertIsNotNull(condition, "The condition to evaluate should not be null"); }
private void assertNotNull(Condition<?> condition) { Conditions.instance().assertIsNotNull(condition); }
/** {@inheritDoc} */ @Override public SELF isNot(Condition<? super ACTUAL> condition) { conditions.assertIsNot(info, actual, condition); return myself; }
/** {@inheritDoc} */ @Override public SELF satisfies(Condition<? super ACTUAL> condition) { conditions.assertSatisfies(info, actual, condition); return myself; }
/** * Verifies that the given {@code Map} contains an entry with key satisfying {@code keyCondition} * and value satisfying {@code valueCondition}. * * @param <K> key type * @param <V> value type * @param info contains information about the assertion. * @param actual the given {@code Map}. * @param keyCondition the condition for entry key. * @param valueCondition the condition for entry value. * @throws NullPointerException if any of the given conditions is {@code null}. * @throws AssertionError if the actual map is {@code null}. * @throws AssertionError if there is no entry matching given {@code keyCondition} and {@code valueCondition}. * @since 2.7.0 / 3.7.0 */ public <K, V> void assertHasEntrySatisfyingConditions(AssertionInfo info, Map<K, V> actual, Condition<? super K> keyCondition, Condition<? super V> valueCondition) { assertNotNull(info, actual); conditions.assertIsNotNull(keyCondition, "The condition to evaluate for entries key should not be null"); conditions.assertIsNotNull(valueCondition, "The condition to evaluate for entries value should not be null"); for (Map.Entry<K, V> entry : actual.entrySet()) { if (keyCondition.matches(entry.getKey()) && valueCondition.matches(entry.getValue())) return; } throw failures.failure(info, shouldContainEntry(actual, keyCondition, valueCondition)); }
/** {@inheritDoc} */ @Override public SELF is(Condition<? super ACTUAL> condition) { conditions.assertIs(info, actual, condition); return myself; }
private void assertNotNull(Condition<?> condition) { Conditions.instance().assertIsNotNull(condition); }
/** {@inheritDoc} */ @Override public S isNot(Condition<? super A> condition) { conditions.assertIsNot(info, actual, condition); return myself; }
/** {@inheritDoc} */ @Override public SELF has(Condition<? super ACTUAL> condition) { conditions.assertHas(info, actual, condition); return myself; }
/** {@inheritDoc} */ @Override public SELF doesNotHave(Condition<? super ACTUAL> condition) { conditions.assertDoesNotHave(info, actual, condition); return myself; }
/** * Asserts that the actual value does not satisfy the given <code>{@link Condition}</code>. * @param <T> the type of the actual value and the type of values that given {@code Condition} takes. * @param info contains information about the assertion. * @param actual the actual value. * @param condition the given {@code Condition}. * @throws NullPointerException if the given {@code Condition} is {@code null}. * @throws AssertionError if the actual value satisfies the given {@code Condition}. */ public <T> void assertIsNot(AssertionInfo info, T actual, Condition<? super T> condition) { assertIsNotNull(condition); if (condition.matches(actual)) throw failures.failure(info, shouldNotBe(actual, condition)); }
/** * Verifies that the actual {@link Optional} contains a value which satisfies the given {@link Condition}. * <p> * Examples: * <pre><code class='java'> Condition<TolkienCharacter> isAnElf = new Condition<>(character -> character.getRace() == ELF, "an elf"); * * TolkienCharacter legolas = new TolkienCharacter("Legolas", 1000, ELF); * TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT); * * // assertion succeeds * assertThat(Optional.of(legolas)).hasValueSatisfying(isAnElf); * * // assertion fails * assertThat(Optional.of(frodo)).hasValueSatisfying(isAnElf);</code></pre> * * @param condition the given condition. * @return this assertion object. * @throws AssertionError if the actual {@link Optional} is null or empty. * @throws NullPointerException if the given condition is {@code null}. * @throws AssertionError if the actual value does not satisfy the given condition. * @since 3.6.0 */ public SELF hasValueSatisfying(Condition<? super VALUE> condition) { assertValueIsPresent(); conditions.assertIs(info, actual.get(), condition); return myself; }
/** {@inheritDoc} */ @Override public S has(Condition<? super A> condition) { conditions.assertHas(info, actual, condition); return myself; }