diff --git a/CHANGELOG.md b/CHANGELOG.md index daede5a99..9f8b8d774 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,9 @@ types - which is a rare usage. Please let us know if this causes an undo hardshi your code accordingly. ([#662](https://github.com/mybatis/mybatis-dynamic-sql/pull/662)) 2. Added the ability to code a bound value in rendered SQL. This is similar to a constant, but the value is added to the parameter map and a bind parameter marker is rendered. ([#738](https://github.com/mybatis/mybatis-dynamic-sql/pull/738)) +3. Refactored the conditions to separate the concept of an empty condition from that of a renderable condition. This + will enable a future change where conditions could decide to allow rendering even if they are considered empty (such + as rendering empty lists). This change should be transparent to users unless they have implemented custom conditions. ## Release 1.5.0 - April 21, 2023 diff --git a/src/main/java/org/mybatis/dynamic/sql/AbstractListValueCondition.java b/src/main/java/org/mybatis/dynamic/sql/AbstractListValueCondition.java index af7eea300..c324398fd 100644 --- a/src/main/java/org/mybatis/dynamic/sql/AbstractListValueCondition.java +++ b/src/main/java/org/mybatis/dynamic/sql/AbstractListValueCondition.java @@ -35,8 +35,8 @@ public final Stream mapValues(Function mapper) { } @Override - public boolean shouldRender() { - return !values.isEmpty(); + public boolean isEmpty() { + return values.isEmpty(); } @Override @@ -56,20 +56,20 @@ private Collection applyFilter(Predicate predicate) { protected > S filterSupport(Predicate predicate, Function, S> constructor, S self, Supplier emptySupplier) { - if (shouldRender()) { + if (isEmpty()) { + return self; + } else { Collection filtered = applyFilter(predicate); return filtered.isEmpty() ? emptySupplier.get() : constructor.apply(filtered); - } else { - return self; } } protected > S mapSupport(Function mapper, Function, S> constructor, Supplier emptySupplier) { - if (shouldRender()) { - return constructor.apply(applyMapper(mapper)); - } else { + if (isEmpty()) { return emptySupplier.get(); + } else { + return constructor.apply(applyMapper(mapper)); } } diff --git a/src/main/java/org/mybatis/dynamic/sql/AbstractNoValueCondition.java b/src/main/java/org/mybatis/dynamic/sql/AbstractNoValueCondition.java index 16e0d3f05..d6b1c384b 100644 --- a/src/main/java/org/mybatis/dynamic/sql/AbstractNoValueCondition.java +++ b/src/main/java/org/mybatis/dynamic/sql/AbstractNoValueCondition.java @@ -27,10 +27,10 @@ public R accept(ConditionVisitor visitor) { protected > S filterSupport(BooleanSupplier booleanSupplier, Supplier emptySupplier, S self) { - if (shouldRender()) { - return booleanSupplier.getAsBoolean() ? self : emptySupplier.get(); - } else { + if (isEmpty()) { return self; + } else { + return booleanSupplier.getAsBoolean() ? self : emptySupplier.get(); } } diff --git a/src/main/java/org/mybatis/dynamic/sql/AbstractSingleValueCondition.java b/src/main/java/org/mybatis/dynamic/sql/AbstractSingleValueCondition.java index 7a89a2cbd..1e70adb31 100644 --- a/src/main/java/org/mybatis/dynamic/sql/AbstractSingleValueCondition.java +++ b/src/main/java/org/mybatis/dynamic/sql/AbstractSingleValueCondition.java @@ -37,19 +37,19 @@ public R accept(ConditionVisitor visitor) { protected > S filterSupport(Predicate predicate, Supplier emptySupplier, S self) { - if (shouldRender()) { - return predicate.test(value) ? self : emptySupplier.get(); - } else { + if (isEmpty()) { return self; + } else { + return predicate.test(value) ? self : emptySupplier.get(); } } protected > S mapSupport(Function mapper, Function constructor, Supplier emptySupplier) { - if (shouldRender()) { - return constructor.apply(mapper.apply(value)); - } else { + if (isEmpty()) { return emptySupplier.get(); + } else { + return constructor.apply(mapper.apply(value)); } } diff --git a/src/main/java/org/mybatis/dynamic/sql/AbstractTwoValueCondition.java b/src/main/java/org/mybatis/dynamic/sql/AbstractTwoValueCondition.java index b6659ee27..ee8b3c577 100644 --- a/src/main/java/org/mybatis/dynamic/sql/AbstractTwoValueCondition.java +++ b/src/main/java/org/mybatis/dynamic/sql/AbstractTwoValueCondition.java @@ -45,10 +45,10 @@ public R accept(ConditionVisitor visitor) { protected > S filterSupport(BiPredicate predicate, Supplier emptySupplier, S self) { - if (shouldRender()) { - return predicate.test(value1, value2) ? self : emptySupplier.get(); - } else { + if (isEmpty()) { return self; + } else { + return predicate.test(value1, value2) ? self : emptySupplier.get(); } } @@ -59,10 +59,10 @@ protected > S filterSupport(Predicate> S mapSupport(Function mapper1, Function mapper2, BiFunction constructor, Supplier emptySupplier) { - if (shouldRender()) { - return constructor.apply(mapper1.apply(value1), mapper2.apply(value2)); - } else { + if (isEmpty()) { return emptySupplier.get(); + } else { + return constructor.apply(mapper1.apply(value1), mapper2.apply(value2)); } } diff --git a/src/main/java/org/mybatis/dynamic/sql/VisitableCondition.java b/src/main/java/org/mybatis/dynamic/sql/VisitableCondition.java index 5cbb7e28c..f13076bfe 100644 --- a/src/main/java/org/mybatis/dynamic/sql/VisitableCondition.java +++ b/src/main/java/org/mybatis/dynamic/sql/VisitableCondition.java @@ -15,22 +15,34 @@ */ package org.mybatis.dynamic.sql; +import org.mybatis.dynamic.sql.render.RenderingContext; + @FunctionalInterface public interface VisitableCondition { R accept(ConditionVisitor visitor); /** * Subclasses can override this to inform the renderer if the condition should not be included - * in the rendered SQL. For example, IsEqualWhenPresent will not render if the value is null. + * in the rendered SQL. Typically, conditions will not render if they are empty. * * @return true if the condition should render. */ - default boolean shouldRender() { - return true; + default boolean shouldRender(RenderingContext renderingContext) { + return !isEmpty(); + } + + /** + * Subclasses can override this to indicate whether the condition is considered empty. This is primarily used in + * map and filter operations - the map and filter functions will not be applied if the condition is empty. + * + * @return true if the condition is empty. + */ + default boolean isEmpty() { + return false; } /** - * This method will be called during rendering when {@link VisitableCondition#shouldRender()} + * This method will be called during rendering when {@link VisitableCondition#shouldRender(RenderingContext)} * returns false. */ default void renderingSkipped() {} diff --git a/src/main/java/org/mybatis/dynamic/sql/select/aggregate/Sum.java b/src/main/java/org/mybatis/dynamic/sql/select/aggregate/Sum.java index b8c59921f..345bf53de 100644 --- a/src/main/java/org/mybatis/dynamic/sql/select/aggregate/Sum.java +++ b/src/main/java/org/mybatis/dynamic/sql/select/aggregate/Sum.java @@ -36,7 +36,7 @@ private Sum(BindableColumn column) { private Sum(BindableColumn column, VisitableCondition condition) { super(column); renderer = rc -> { - Validator.assertTrue(condition.shouldRender(), "ERROR.37", "sum"); //$NON-NLS-1$ //$NON-NLS-2$ + Validator.assertTrue(condition.shouldRender(rc), "ERROR.37", "sum"); //$NON-NLS-1$ //$NON-NLS-2$ DefaultConditionVisitor visitor = new DefaultConditionVisitor.Builder() .withColumn(column) diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsBetween.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsBetween.java index d14139078..ff21433d0 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsBetween.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsBetween.java @@ -25,8 +25,8 @@ public class IsBetween extends AbstractTwoValueCondition { private static final IsBetween EMPTY = new IsBetween(null, null) { @Override - public boolean shouldRender() { - return false; + public boolean isEmpty() { + return true; } }; diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsEqualTo.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsEqualTo.java index f58af9125..2682dd602 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsEqualTo.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsEqualTo.java @@ -24,8 +24,8 @@ public class IsEqualTo extends AbstractSingleValueCondition { private static final IsEqualTo EMPTY = new IsEqualTo(null) { @Override - public boolean shouldRender() { - return false; + public boolean isEmpty() { + return true; } }; diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsGreaterThan.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsGreaterThan.java index 9e1bb2577..3e45574ad 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsGreaterThan.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsGreaterThan.java @@ -23,8 +23,8 @@ public class IsGreaterThan extends AbstractSingleValueCondition { private static final IsGreaterThan EMPTY = new IsGreaterThan(null) { @Override - public boolean shouldRender() { - return false; + public boolean isEmpty() { + return true; } }; diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsGreaterThanOrEqualTo.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsGreaterThanOrEqualTo.java index ac15ad8c5..8212a3b5b 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsGreaterThanOrEqualTo.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsGreaterThanOrEqualTo.java @@ -23,8 +23,8 @@ public class IsGreaterThanOrEqualTo extends AbstractSingleValueCondition { private static final IsGreaterThanOrEqualTo EMPTY = new IsGreaterThanOrEqualTo(null) { @Override - public boolean shouldRender() { - return false; + public boolean isEmpty() { + return true; } }; diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsLessThan.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsLessThan.java index d90a08c37..516331e0b 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsLessThan.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsLessThan.java @@ -23,8 +23,8 @@ public class IsLessThan extends AbstractSingleValueCondition { private static final IsLessThan EMPTY = new IsLessThan(null) { @Override - public boolean shouldRender() { - return false; + public boolean isEmpty() { + return true; } }; diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsLessThanOrEqualTo.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsLessThanOrEqualTo.java index 37c6a303f..83c45cca2 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsLessThanOrEqualTo.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsLessThanOrEqualTo.java @@ -23,8 +23,8 @@ public class IsLessThanOrEqualTo extends AbstractSingleValueCondition { private static final IsLessThanOrEqualTo EMPTY = new IsLessThanOrEqualTo(null) { @Override - public boolean shouldRender() { - return false; + public boolean isEmpty() { + return true; } }; diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsLike.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsLike.java index 8de5b4235..864ddb432 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsLike.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsLike.java @@ -23,8 +23,8 @@ public class IsLike extends AbstractSingleValueCondition { private static final IsLike EMPTY = new IsLike(null) { @Override - public boolean shouldRender() { - return false; + public boolean isEmpty() { + return true; } }; diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsLikeCaseInsensitive.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsLikeCaseInsensitive.java index 11bdcfd0d..3b13d1748 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsLikeCaseInsensitive.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsLikeCaseInsensitive.java @@ -25,8 +25,8 @@ public class IsLikeCaseInsensitive extends AbstractSingleValueCondition implements CaseInsensitiveVisitableCondition { private static final IsLikeCaseInsensitive EMPTY = new IsLikeCaseInsensitive(null) { @Override - public boolean shouldRender() { - return false; + public boolean isEmpty() { + return true; } }; diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotBetween.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotBetween.java index 9e231c765..f380449fd 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotBetween.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotBetween.java @@ -25,8 +25,8 @@ public class IsNotBetween extends AbstractTwoValueCondition { private static final IsNotBetween EMPTY = new IsNotBetween(null, null) { @Override - public boolean shouldRender() { - return false; + public boolean isEmpty() { + return true; } }; diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotEqualTo.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotEqualTo.java index adb6e6a11..f35516e56 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotEqualTo.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotEqualTo.java @@ -23,8 +23,8 @@ public class IsNotEqualTo extends AbstractSingleValueCondition { private static final IsNotEqualTo EMPTY = new IsNotEqualTo(null) { @Override - public boolean shouldRender() { - return false; + public boolean isEmpty() { + return true; } }; diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotLike.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotLike.java index 4bde66326..79d97ca15 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotLike.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotLike.java @@ -23,8 +23,8 @@ public class IsNotLike extends AbstractSingleValueCondition { private static final IsNotLike EMPTY = new IsNotLike(null) { @Override - public boolean shouldRender() { - return false; + public boolean isEmpty() { + return true; } }; diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotLikeCaseInsensitive.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotLikeCaseInsensitive.java index d390506df..eb0450135 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotLikeCaseInsensitive.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotLikeCaseInsensitive.java @@ -25,8 +25,8 @@ public class IsNotLikeCaseInsensitive extends AbstractSingleValueCondition extends AbstractNoValueCondition { private static final IsNotNull EMPTY = new IsNotNull() { @Override - public boolean shouldRender() { - return false; + public boolean isEmpty() { + return true; } }; diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNull.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNull.java index 016328f18..61fe53da2 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNull.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNull.java @@ -22,8 +22,8 @@ public class IsNull extends AbstractNoValueCondition { private static final IsNull EMPTY = new IsNull() { @Override - public boolean shouldRender() { - return false; + public boolean isEmpty() { + return true; } }; diff --git a/src/main/java/org/mybatis/dynamic/sql/where/render/CriterionRenderer.java b/src/main/java/org/mybatis/dynamic/sql/where/render/CriterionRenderer.java index 3709736f1..f5942a5e2 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/render/CriterionRenderer.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/render/CriterionRenderer.java @@ -110,7 +110,7 @@ public Optional render(List subCriteria, } private Optional renderColumnAndCondition(ColumnAndConditionCriterion criterion) { - if (criterion.condition().shouldRender()) { + if (criterion.condition().shouldRender(renderingContext)) { return Optional.of(renderCondition(criterion)); } else { criterion.condition().renderingSkipped(); diff --git a/src/test/java/org/mybatis/dynamic/sql/where/condition/FilterAndMapTest.java b/src/test/java/org/mybatis/dynamic/sql/where/condition/FilterAndMapTest.java index d37372bfd..dda5efdba 100644 --- a/src/test/java/org/mybatis/dynamic/sql/where/condition/FilterAndMapTest.java +++ b/src/test/java/org/mybatis/dynamic/sql/where/condition/FilterAndMapTest.java @@ -30,7 +30,7 @@ class FilterAndMapTest { @Test void testTypeConversion() { IsEqualTo cond = SqlBuilder.isEqualTo("1").map(Integer::parseInt); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); assertThat(cond.value()).isEqualTo(1); } @@ -45,14 +45,14 @@ void testTypeConversionWithNullThrowsException() { @Test void testTypeConversionWithNullAndFilterDoesNotThrowException() { IsEqualTo cond = SqlBuilder.isEqualTo((String) null).filter(Objects::nonNull).map(Integer::parseInt); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); } @Test void testIsNullRenderableTruePredicateShouldReturnSameObject() { IsNull cond = SqlBuilder.isNull(); IsNull filtered = cond.filter(() -> true); - assertThat(filtered.shouldRender()).isTrue(); + assertThat(filtered.isEmpty()).isFalse(); assertThat(cond).isSameAs(filtered); } @@ -60,15 +60,15 @@ void testIsNullRenderableTruePredicateShouldReturnSameObject() { void testIsNullRenderableFalsePredicate() { IsNull cond = SqlBuilder.isNull(); IsNull filtered = cond.filter(() -> false); - assertThat(cond.shouldRender()).isTrue(); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); } @Test void testIsNullFilterUnRenderableShouldReturnSameObject() { IsNull cond = SqlBuilder.isNull().filter(() -> false); IsNull filtered = cond.filter(() -> true); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); assertThat(cond).isSameAs(filtered); } @@ -76,7 +76,7 @@ void testIsNullFilterUnRenderableShouldReturnSameObject() { void testIsNotNullRenderableTruePredicateShouldReturnSameObject() { IsNotNull cond = SqlBuilder.isNotNull(); IsNotNull filtered = cond.filter(() -> true); - assertThat(filtered.shouldRender()).isTrue(); + assertThat(filtered.isEmpty()).isFalse(); assertThat(cond).isSameAs(filtered); } @@ -84,15 +84,15 @@ void testIsNotNullRenderableTruePredicateShouldReturnSameObject() { void testIsNotNullRenderableFalsePredicate() { IsNotNull cond = SqlBuilder.isNotNull(); IsNotNull filtered = cond.filter(() -> false); - assertThat(cond.shouldRender()).isTrue(); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); } @Test void testIsNotNullFilterUnRenderableShouldReturnSameObject() { IsNotNull cond = SqlBuilder.isNotNull().filter(() -> false); IsNotNull filtered = cond.filter(() -> true); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); assertThat(cond).isSameAs(filtered); } @@ -100,7 +100,7 @@ void testIsNotNullFilterUnRenderableShouldReturnSameObject() { void testIsEqualRenderableTruePredicateShouldReturnSameObject() { IsEqualTo cond = SqlBuilder.isEqualTo("Fred"); IsEqualTo filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isTrue(); + assertThat(filtered.isEmpty()).isFalse(); assertThat(cond).isSameAs(filtered); } @@ -108,15 +108,15 @@ void testIsEqualRenderableTruePredicateShouldReturnSameObject() { void testIsEqualRenderableFalsePredicate() { IsEqualTo cond = SqlBuilder.isEqualTo("Fred"); IsEqualTo filtered = cond.filter(s -> false); - assertThat(cond.shouldRender()).isTrue(); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); } @Test void testIsEqualFilterUnRenderableShouldReturnSameObject() { IsEqualTo cond = SqlBuilder.isEqualTo("Fred").filter(s -> false); IsEqualTo filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); assertThat(cond).isSameAs(filtered); } @@ -124,7 +124,7 @@ void testIsEqualFilterUnRenderableShouldReturnSameObject() { void testIsEqualMapUnRenderableShouldNotThrowNullPointerException() { IsEqualTo cond = SqlBuilder.isEqualTo("Fred").filter(s -> false); IsEqualTo mapped = cond.map(String::toUpperCase); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); assertThat(cond.value()).isNull(); assertThat(cond).isSameAs(mapped); } @@ -133,7 +133,7 @@ void testIsEqualMapUnRenderableShouldNotThrowNullPointerException() { void testIsNotEqualRenderableTruePredicateShouldReturnSameObject() { IsNotEqualTo cond = SqlBuilder.isNotEqualTo("Fred"); IsNotEqualTo filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isTrue(); + assertThat(filtered.isEmpty()).isFalse(); assertThat(cond).isSameAs(filtered); } @@ -141,15 +141,15 @@ void testIsNotEqualRenderableTruePredicateShouldReturnSameObject() { void testIsNotEqualRenderableFalsePredicate() { IsNotEqualTo cond = SqlBuilder.isNotEqualTo("Fred"); IsNotEqualTo filtered = cond.filter(s -> false); - assertThat(cond.shouldRender()).isTrue(); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); } @Test void testIsNotEqualFilterUnRenderableShouldReturnSameObject() { IsNotEqualTo cond = SqlBuilder.isNotEqualTo("Fred").filter(s -> false); IsNotEqualTo filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); assertThat(cond).isSameAs(filtered); } @@ -157,7 +157,7 @@ void testIsNotEqualFilterUnRenderableShouldReturnSameObject() { void testIsNotEqualMapUnRenderableShouldNotThrowNullPointerException() { IsNotEqualTo cond = SqlBuilder.isNotEqualTo("Fred").filter(s -> false); IsNotEqualTo mapped = cond.map(String::toUpperCase); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); assertThat(cond.value()).isNull(); assertThat(cond).isSameAs(mapped); } @@ -166,7 +166,7 @@ void testIsNotEqualMapUnRenderableShouldNotThrowNullPointerException() { void testIsLessThanRenderableTruePredicateShouldReturnSameObject() { IsLessThan cond = SqlBuilder.isLessThan("Fred"); IsLessThan filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isTrue(); + assertThat(filtered.isEmpty()).isFalse(); assertThat(cond).isSameAs(filtered); } @@ -174,15 +174,15 @@ void testIsLessThanRenderableTruePredicateShouldReturnSameObject() { void testIsLessThanRenderableFalsePredicate() { IsLessThan cond = SqlBuilder.isLessThan("Fred"); IsLessThan filtered = cond.filter(s -> false); - assertThat(cond.shouldRender()).isTrue(); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); } @Test void testIsLessThanFilterUnRenderableShouldReturnSameObject() { IsLessThan cond = SqlBuilder.isLessThan("Fred").filter(s -> false); IsLessThan filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); assertThat(cond).isSameAs(filtered); } @@ -190,7 +190,7 @@ void testIsLessThanFilterUnRenderableShouldReturnSameObject() { void testIsLessThanMapUnRenderableShouldNotThrowNullPointerException() { IsLessThan cond = SqlBuilder.isLessThan("Fred").filter(s -> false); IsLessThan mapped = cond.map(String::toUpperCase); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); assertThat(cond.value()).isNull(); assertThat(cond).isSameAs(mapped); } @@ -199,7 +199,7 @@ void testIsLessThanMapUnRenderableShouldNotThrowNullPointerException() { void testIsLessThanOrEqualRenderableTruePredicateShouldReturnSameObject() { IsLessThanOrEqualTo cond = SqlBuilder.isLessThanOrEqualTo("Fred"); IsLessThanOrEqualTo filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isTrue(); + assertThat(filtered.isEmpty()).isFalse(); assertThat(cond).isSameAs(filtered); } @@ -207,15 +207,15 @@ void testIsLessThanOrEqualRenderableTruePredicateShouldReturnSameObject() { void testIsLessThanOrEqualRenderableFalsePredicate() { IsLessThanOrEqualTo cond = SqlBuilder.isLessThanOrEqualTo("Fred"); IsLessThanOrEqualTo filtered = cond.filter(s -> false); - assertThat(cond.shouldRender()).isTrue(); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); } @Test void testIsLessThanOrEqualFilterUnRenderableShouldReturnSameObject() { IsLessThanOrEqualTo cond = SqlBuilder.isLessThanOrEqualTo("Fred").filter(s -> false); IsLessThanOrEqualTo filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); assertThat(cond).isSameAs(filtered); } @@ -223,7 +223,7 @@ void testIsLessThanOrEqualFilterUnRenderableShouldReturnSameObject() { void testIsLessThanOrEqualMapUnRenderableShouldNotThrowNullPointerException() { IsLessThanOrEqualTo cond = SqlBuilder.isLessThanOrEqualTo("Fred").filter(s -> false); IsLessThanOrEqualTo mapped = cond.map(String::toUpperCase); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); assertThat(cond.value()).isNull(); assertThat(cond).isSameAs(mapped); } @@ -232,7 +232,7 @@ void testIsLessThanOrEqualMapUnRenderableShouldNotThrowNullPointerException() { void testIsGreaterThanRenderableTruePredicateShouldReturnSameObject() { IsGreaterThan cond = SqlBuilder.isGreaterThan("Fred"); IsGreaterThan filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isTrue(); + assertThat(filtered.isEmpty()).isFalse(); assertThat(cond).isSameAs(filtered); } @@ -240,15 +240,15 @@ void testIsGreaterThanRenderableTruePredicateShouldReturnSameObject() { void testIsGreaterThanRenderableFalsePredicate() { IsGreaterThan cond = SqlBuilder.isGreaterThan("Fred"); IsGreaterThan filtered = cond.filter(s -> false); - assertThat(cond.shouldRender()).isTrue(); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); } @Test void testIsGreaterThanFilterUnRenderableShouldReturnSameObject() { IsGreaterThan cond = SqlBuilder.isGreaterThan("Fred").filter(s -> false); IsGreaterThan filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); assertThat(cond).isSameAs(filtered); } @@ -256,7 +256,7 @@ void testIsGreaterThanFilterUnRenderableShouldReturnSameObject() { void testIsGreaterThanMapUnRenderableShouldNotThrowNullPointerException() { IsGreaterThan cond = SqlBuilder.isGreaterThan("Fred").filter(s -> false); IsGreaterThan mapped = cond.map(String::toUpperCase); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); assertThat(cond.value()).isNull(); assertThat(cond).isSameAs(mapped); } @@ -265,7 +265,7 @@ void testIsGreaterThanMapUnRenderableShouldNotThrowNullPointerException() { void testIsGreaterThanOrEqualRenderableTruePredicateShouldReturnSameObject() { IsGreaterThanOrEqualTo cond = SqlBuilder.isGreaterThanOrEqualTo("Fred"); IsGreaterThanOrEqualTo filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isTrue(); + assertThat(filtered.isEmpty()).isFalse(); assertThat(cond).isSameAs(filtered); } @@ -273,15 +273,15 @@ void testIsGreaterThanOrEqualRenderableTruePredicateShouldReturnSameObject() { void testIsGreaterThanOrEqualRenderableFalsePredicate() { IsGreaterThanOrEqualTo cond = SqlBuilder.isGreaterThanOrEqualTo("Fred"); IsGreaterThanOrEqualTo filtered = cond.filter(s -> false); - assertThat(cond.shouldRender()).isTrue(); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); } @Test void testIsGreaterThanOrEqualFilterUnRenderableShouldReturnSameObject() { IsGreaterThanOrEqualTo cond = SqlBuilder.isGreaterThanOrEqualTo("Fred").filter(s -> false); IsGreaterThanOrEqualTo filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); assertThat(cond).isSameAs(filtered); } @@ -289,7 +289,7 @@ void testIsGreaterThanOrEqualFilterUnRenderableShouldReturnSameObject() { void testIsGreaterThanOrEqualMapUnRenderableShouldNotThrowNullPointerException() { IsGreaterThanOrEqualTo cond = SqlBuilder.isGreaterThanOrEqualTo("Fred").filter(s -> false); IsGreaterThanOrEqualTo mapped = cond.map(String::toUpperCase); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); assertThat(cond.value()).isNull(); assertThat(cond).isSameAs(mapped); } @@ -298,7 +298,7 @@ void testIsGreaterThanOrEqualMapUnRenderableShouldNotThrowNullPointerException() void testIsLikeRenderableTruePredicateShouldReturnSameObject() { IsLike cond = SqlBuilder.isLike("Fred"); IsLike filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isTrue(); + assertThat(filtered.isEmpty()).isFalse(); assertThat(cond).isSameAs(filtered); } @@ -306,15 +306,15 @@ void testIsLikeRenderableTruePredicateShouldReturnSameObject() { void testIsLikeRenderableFalsePredicate() { IsLike cond = SqlBuilder.isLike("Fred"); IsLike filtered = cond.filter(s -> false); - assertThat(cond.shouldRender()).isTrue(); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); } @Test void testIsLikeFilterUnRenderableShouldReturnSameObject() { IsLike cond = SqlBuilder.isLike("Fred").filter(s -> false); IsLike filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); assertThat(cond).isSameAs(filtered); } @@ -322,7 +322,7 @@ void testIsLikeFilterUnRenderableShouldReturnSameObject() { void testIsLikeMapUnRenderableShouldNotThrowNullPointerException() { IsLike cond = SqlBuilder.isLike("Fred").filter(s -> false); IsLike mapped = cond.map(String::toUpperCase); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); assertThat(cond.value()).isNull(); assertThat(cond).isSameAs(mapped); } @@ -332,7 +332,7 @@ void testIsLikeCaseInsensitiveRenderableTruePredicateShouldReturnSameObject() { IsLikeCaseInsensitive cond = SqlBuilder.isLikeCaseInsensitive("Fred"); IsLikeCaseInsensitive filtered = cond.filter(s -> true); assertThat(filtered.value()).isEqualTo("FRED"); - assertThat(filtered.shouldRender()).isTrue(); + assertThat(filtered.isEmpty()).isFalse(); assertThat(cond).isSameAs(filtered); } @@ -340,15 +340,15 @@ void testIsLikeCaseInsensitiveRenderableTruePredicateShouldReturnSameObject() { void testIsLikeCaseInsensitiveRenderableFalsePredicate() { IsLikeCaseInsensitive cond = SqlBuilder.isLikeCaseInsensitive("Fred"); IsLikeCaseInsensitive filtered = cond.filter(s -> false); - assertThat(cond.shouldRender()).isTrue(); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); } @Test void testIsLikeCaseInsensitiveFilterUnRenderableShouldReturnSameObject() { IsLikeCaseInsensitive cond = SqlBuilder.isLikeCaseInsensitive("Fred").filter(s -> false); IsLikeCaseInsensitive filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); assertThat(cond).isSameAs(filtered); } @@ -356,7 +356,7 @@ void testIsLikeCaseInsensitiveFilterUnRenderableShouldReturnSameObject() { void testIsLikeCaseInsensitiveMapUnRenderableShouldNotThrowNullPointerException() { IsLikeCaseInsensitive cond = SqlBuilder.isLikeCaseInsensitive("Fred").filter(s -> false); IsLikeCaseInsensitive mapped = cond.map(String::toUpperCase); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); assertThat(cond.value()).isNull(); assertThat(cond).isSameAs(mapped); } @@ -365,7 +365,7 @@ void testIsLikeCaseInsensitiveMapUnRenderableShouldNotThrowNullPointerException( void testIsNotLikeRenderableTruePredicateShouldReturnSameObject() { IsNotLike cond = SqlBuilder.isNotLike("Fred"); IsNotLike filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isTrue(); + assertThat(filtered.isEmpty()).isFalse(); assertThat(cond).isSameAs(filtered); } @@ -373,15 +373,15 @@ void testIsNotLikeRenderableTruePredicateShouldReturnSameObject() { void testIsNotLikeRenderableFalsePredicate() { IsNotLike cond = SqlBuilder.isNotLike("Fred"); IsNotLike filtered = cond.filter(s -> false); - assertThat(cond.shouldRender()).isTrue(); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); } @Test void testIsNotLikeFilterUnRenderableShouldReturnSameObject() { IsNotLike cond = SqlBuilder.isNotLike("Fred").filter(s -> false); IsNotLike filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); assertThat(cond).isSameAs(filtered); } @@ -389,7 +389,7 @@ void testIsNotLikeFilterUnRenderableShouldReturnSameObject() { void testIsNotLikeMapUnRenderableShouldNotThrowNullPointerException() { IsNotLike cond = SqlBuilder.isNotLike("Fred").filter(s -> false); IsNotLike mapped = cond.map(String::toUpperCase); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); assertThat(cond.value()).isNull(); assertThat(cond).isSameAs(mapped); } @@ -399,7 +399,7 @@ void testIsNotLikeCaseInsensitiveRenderableTruePredicateShouldReturnSameObject() IsNotLikeCaseInsensitive cond = SqlBuilder.isNotLikeCaseInsensitive("Fred"); IsNotLikeCaseInsensitive filtered = cond.filter(s -> true); assertThat(filtered.value()).isEqualTo("FRED"); - assertThat(filtered.shouldRender()).isTrue(); + assertThat(filtered.isEmpty()).isFalse(); assertThat(cond).isSameAs(filtered); } @@ -407,15 +407,15 @@ void testIsNotLikeCaseInsensitiveRenderableTruePredicateShouldReturnSameObject() void testIsNotLikeCaseInsensitiveRenderableFalsePredicate() { IsNotLikeCaseInsensitive cond = SqlBuilder.isNotLikeCaseInsensitive("Fred"); IsNotLikeCaseInsensitive filtered = cond.filter(s -> false); - assertThat(cond.shouldRender()).isTrue(); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); } @Test void testIsNotLikeCaseInsensitiveFilterUnRenderableShouldReturnSameObject() { IsNotLikeCaseInsensitive cond = SqlBuilder.isNotLikeCaseInsensitive("Fred").filter(s -> false); IsNotLikeCaseInsensitive filtered = cond.filter(s -> true); - assertThat(filtered.shouldRender()).isFalse(); + assertThat(filtered.isEmpty()).isTrue(); assertThat(cond).isSameAs(filtered); } @@ -423,7 +423,7 @@ void testIsNotLikeCaseInsensitiveFilterUnRenderableShouldReturnSameObject() { void testIsNotLikeCaseInsensitiveMapUnRenderableShouldNotThrowNullPointerException() { IsNotLikeCaseInsensitive cond = SqlBuilder.isNotLikeCaseInsensitive("Fred").filter(s -> false); IsNotLikeCaseInsensitive mapped = cond.map(String::toUpperCase); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); assertThat(cond.value()).isNull(); assertThat(cond).isSameAs(mapped); } @@ -431,7 +431,7 @@ void testIsNotLikeCaseInsensitiveMapUnRenderableShouldNotThrowNullPointerExcepti @Test void testIsInRenderableMapShouldReturnMappedObject() { IsIn cond = SqlBuilder.isIn("Fred", "Wilma"); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); IsIn mapped = cond.map(String::toUpperCase); List mappedValues = mapped.mapValues(Function.identity()).collect(Collectors.toList()); assertThat(mappedValues).containsExactly("FRED", "WILMA"); @@ -440,7 +440,7 @@ void testIsInRenderableMapShouldReturnMappedObject() { @Test void testIsNotInRenderableMapShouldReturnMappedObject() { IsNotIn cond = SqlBuilder.isNotIn("Fred", "Wilma"); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); IsNotIn mapped = cond.map(String::toUpperCase); List mappedValues = mapped.mapValues(Function.identity()).collect(Collectors.toList()); assertThat(mappedValues).containsExactly("FRED", "WILMA"); @@ -451,7 +451,7 @@ void testIsNotInCaseInsensitiveRenderableMapShouldReturnMappedObject() { IsNotInCaseInsensitive cond = SqlBuilder.isNotInCaseInsensitive("Fred ", "Wilma "); List values = cond.mapValues(Function.identity()).collect(Collectors.toList()); assertThat(values).containsExactly("FRED ", "WILMA "); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); IsNotInCaseInsensitive mapped = cond.map(String::trim); List mappedValues = mapped.mapValues(Function.identity()).collect(Collectors.toList()); @@ -463,7 +463,7 @@ void testIsInCaseInsensitiveRenderableMapShouldReturnMappedObject() { IsInCaseInsensitive cond = SqlBuilder.isInCaseInsensitive("Fred ", "Wilma "); List values = cond.mapValues(Function.identity()).collect(Collectors.toList()); assertThat(values).containsExactly("FRED ", "WILMA "); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); IsInCaseInsensitive mapped = cond.map(String::trim); List mappedValues = mapped.mapValues(Function.identity()).collect(Collectors.toList()); @@ -473,7 +473,7 @@ void testIsInCaseInsensitiveRenderableMapShouldReturnMappedObject() { @Test void testBetweenUnRenderableFilterShouldReturnSameObject() { IsBetween cond = SqlBuilder.isBetween(3).and(4).filter((i1, i2) -> false); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); IsBetween filtered = cond.filter((v1, v2) -> true); assertThat(cond).isSameAs(filtered); } @@ -481,7 +481,7 @@ void testBetweenUnRenderableFilterShouldReturnSameObject() { @Test void testBetweenUnRenderableFirstNullFilterShouldReturnSameObject() { IsBetween cond = SqlBuilder.isBetween((Integer) null).and(4).filter(Objects::nonNull); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); IsBetween filtered = cond.filter(v -> true); assertThat(cond).isSameAs(filtered); } @@ -489,7 +489,7 @@ void testBetweenUnRenderableFirstNullFilterShouldReturnSameObject() { @Test void testBetweenUnRenderableSecondNullFilterShouldReturnSameObject() { IsBetween cond = SqlBuilder.isBetween(3).and((Integer) null).filter(Objects::nonNull); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); IsBetween filtered = cond.filter(v -> true); assertThat(cond).isSameAs(filtered); } @@ -497,7 +497,7 @@ void testBetweenUnRenderableSecondNullFilterShouldReturnSameObject() { @Test void testBetweenMapWithSingleMapper() { IsBetween cond = SqlBuilder.isBetween("3").and("4").map(Integer::parseInt); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); assertThat(cond.value1()).isEqualTo(3); assertThat(cond.value2()).isEqualTo(4); } @@ -505,7 +505,7 @@ void testBetweenMapWithSingleMapper() { @Test void testNotBetweenUnRenderableFilterShouldReturnSameObject() { IsNotBetween cond = SqlBuilder.isNotBetween(3).and(4).filter((i1, i2) -> false); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); IsNotBetween filtered = cond.filter((v1, v2) -> true); assertThat(cond).isSameAs(filtered); } @@ -513,7 +513,7 @@ void testNotBetweenUnRenderableFilterShouldReturnSameObject() { @Test void testNotBetweenUnRenderableFirstNullFilterShouldReturnSameObject() { IsNotBetween cond = SqlBuilder.isNotBetween((Integer) null).and(4).filter(Objects::nonNull); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); IsNotBetween filtered = cond.filter(v -> true); assertThat(cond).isSameAs(filtered); } @@ -521,7 +521,7 @@ void testNotBetweenUnRenderableFirstNullFilterShouldReturnSameObject() { @Test void testNotBetweenUnRenderableSecondNullFilterShouldReturnSameObject() { IsNotBetween cond = SqlBuilder.isNotBetween(3).and((Integer) null).filter(Objects::nonNull); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); IsNotBetween filtered = cond.filter(v -> true); assertThat(cond).isSameAs(filtered); } @@ -529,7 +529,7 @@ void testNotBetweenUnRenderableSecondNullFilterShouldReturnSameObject() { @Test void testNotBetweenMapWithSingleMapper() { IsNotBetween cond = SqlBuilder.isNotBetween("3").and("4").map(Integer::parseInt); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); assertThat(cond.value1()).isEqualTo(3); assertThat(cond.value2()).isEqualTo(4); } diff --git a/src/test/java/org/mybatis/dynamic/sql/where/condition/SupplierTest.java b/src/test/java/org/mybatis/dynamic/sql/where/condition/SupplierTest.java index 803536232..ed8cf7c5b 100644 --- a/src/test/java/org/mybatis/dynamic/sql/where/condition/SupplierTest.java +++ b/src/test/java/org/mybatis/dynamic/sql/where/condition/SupplierTest.java @@ -28,7 +28,7 @@ void testIsBetween() { IsBetween cond = SqlBuilder.isBetween(() -> 3).and(() -> 4); assertThat(cond.value1()).isEqualTo(3); assertThat(cond.value2()).isEqualTo(4); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test @@ -36,7 +36,7 @@ void testIsBetweenNull() { IsBetween cond = SqlBuilder.isBetween(() -> (Integer) null).and(() -> null); assertThat(cond.value1()).isNull(); assertThat(cond.value2()).isNull(); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test @@ -44,7 +44,7 @@ void testIsBetweenWhenPresent() { IsBetween cond = SqlBuilder.isBetweenWhenPresent(() -> 3).and(() -> 4); assertThat(cond.value1()).isEqualTo(3); assertThat(cond.value2()).isEqualTo(4); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test @@ -52,7 +52,7 @@ void testIsBetweenWhenPresentNull() { IsBetween cond = SqlBuilder.isBetweenWhenPresent(() -> (Integer) null).and(() -> null); assertThat(cond.value1()).isNull(); assertThat(cond.value2()).isNull(); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); } @Test @@ -60,7 +60,7 @@ void testIsNotBetween() { IsNotBetween cond = SqlBuilder.isNotBetween(() -> 3).and(() -> 4); assertThat(cond.value1()).isEqualTo(3); assertThat(cond.value2()).isEqualTo(4); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test @@ -68,7 +68,7 @@ void testIsNotBetweenNull() { IsNotBetween cond = SqlBuilder.isNotBetween(() -> (Integer) null).and(() -> null); assertThat(cond.value1()).isNull(); assertThat(cond.value2()).isNull(); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test @@ -76,7 +76,7 @@ void testIsNotBetweenWhenPresent() { IsNotBetween cond = SqlBuilder.isNotBetweenWhenPresent(() -> 3).and(() -> 4); assertThat(cond.value1()).isEqualTo(3); assertThat(cond.value2()).isEqualTo(4); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test @@ -84,272 +84,272 @@ void testIsNotBetweenWhenPresentNull() { IsNotBetween cond = SqlBuilder.isNotBetweenWhenPresent(() -> (Integer) null).and(() -> null); assertThat(cond.value1()).isNull(); assertThat(cond.value2()).isNull(); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); } @Test void testIsEqualToWhenPresent() { IsEqualTo cond = SqlBuilder.isEqualToWhenPresent(() -> 3); assertThat(cond.value()).isEqualTo(3); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsEqualToWhenPresentNull() { IsEqualTo cond = SqlBuilder.isEqualToWhenPresent(() -> null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); } @Test void testIsNotEqualTo() { IsNotEqualTo cond = SqlBuilder.isNotEqualTo(() -> 3); assertThat(cond.value()).isEqualTo(3); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsNotEqualToNull() { IsNotEqualTo cond = SqlBuilder.isNotEqualTo(() -> (Integer) null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsNotEqualToWhenPresent() { IsNotEqualTo cond = SqlBuilder.isNotEqualToWhenPresent(() -> 3); assertThat(cond.value()).isEqualTo(3); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsNotEqualToWhenPresentNull() { IsNotEqualTo cond = SqlBuilder.isNotEqualToWhenPresent(() -> null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); } @Test void testIsGreaterThan() { IsGreaterThan cond = SqlBuilder.isGreaterThan(() -> 3); assertThat(cond.value()).isEqualTo(3); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsGreaterThanNull() { IsGreaterThan cond = SqlBuilder.isGreaterThan(() -> (Integer) null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsGreaterThanWhenPresent() { IsGreaterThan cond = SqlBuilder.isGreaterThanWhenPresent(() -> 3); assertThat(cond.value()).isEqualTo(3); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsGreaterThanWhenPresentNull() { IsGreaterThan cond = SqlBuilder.isGreaterThanWhenPresent(() -> null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); } @Test void testIsGreaterThanOrEqualTo() { IsGreaterThanOrEqualTo cond = SqlBuilder.isGreaterThanOrEqualTo(() -> 3); assertThat(cond.value()).isEqualTo(3); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsGreaterThanOrEqualToNull() { IsGreaterThanOrEqualTo cond = SqlBuilder.isGreaterThanOrEqualTo(() -> (Integer) null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsGreaterThanOrEqualToWhenPresent() { IsGreaterThanOrEqualTo cond = SqlBuilder.isGreaterThanOrEqualToWhenPresent(() -> 3); assertThat(cond.value()).isEqualTo(3); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsGreaterThanOrEqualToWhenPresentNull() { IsGreaterThanOrEqualTo cond = SqlBuilder.isGreaterThanOrEqualToWhenPresent(() -> null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); } @Test void testIsLessThan() { IsLessThan cond = SqlBuilder.isLessThan(() -> 3); assertThat(cond.value()).isEqualTo(3); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsLessThanNull() { IsLessThan cond = SqlBuilder.isLessThan(() -> (Integer) null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsLessThanWhenPresent() { IsLessThan cond = SqlBuilder.isLessThanWhenPresent(() -> 3); assertThat(cond.value()).isEqualTo(3); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsLessThanWhenPresentNull() { IsLessThan cond = SqlBuilder.isLessThanWhenPresent(() -> null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); } @Test void testIsLessThanOrEqualTo() { IsLessThanOrEqualTo cond = SqlBuilder.isLessThanOrEqualTo(() -> 3); assertThat(cond.value()).isEqualTo(3); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsLessThanOrEqualToNull() { IsLessThanOrEqualTo cond = SqlBuilder.isLessThanOrEqualTo(() -> (Integer) null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsLessThanOrEqualToWhenPresent() { IsLessThanOrEqualTo cond = SqlBuilder.isLessThanOrEqualToWhenPresent(() -> 3); assertThat(cond.value()).isEqualTo(3); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsLessThanOrEqualToWhenPresentNull() { IsLessThanOrEqualTo cond = SqlBuilder.isLessThanOrEqualToWhenPresent(() -> null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); } @Test void testIsLike() { IsLike cond = SqlBuilder.isLike(() -> "%F%"); assertThat(cond.value()).isEqualTo("%F%"); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsLikeNull() { IsLike cond = SqlBuilder.isLike(() -> null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsLikeCaseInsensitive() { IsLikeCaseInsensitive cond = SqlBuilder.isLikeCaseInsensitive(() -> "%f%"); assertThat(cond.value()).isEqualTo("%F%"); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsLikeCaseInsensitiveNull() { IsLikeCaseInsensitive cond = SqlBuilder.isLikeCaseInsensitive(() -> null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsLikeCaseInsensitiveWhenPresent() { IsLikeCaseInsensitive cond = SqlBuilder.isLikeCaseInsensitiveWhenPresent(() -> "%f%"); assertThat(cond.value()).isEqualTo("%F%"); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsLikeCaseInsensitiveWhenPresentNull() { IsLikeCaseInsensitive cond = SqlBuilder.isLikeCaseInsensitiveWhenPresent(() -> null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); } @Test void testIsLikeWhenPresent() { IsLike cond = SqlBuilder.isLikeWhenPresent(() -> "%F%"); assertThat(cond.value()).isEqualTo("%F%"); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsLikeWhenPresentNull() { IsLike cond = SqlBuilder.isLikeWhenPresent(() -> null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); } @Test void testIsNotLike() { IsNotLike cond = SqlBuilder.isNotLike(() -> "%F%"); assertThat(cond.value()).isEqualTo("%F%"); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsNotLikeNull() { IsNotLike cond = SqlBuilder.isNotLike(() -> null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsNotLikeWhenPresent() { IsNotLike cond = SqlBuilder.isNotLikeWhenPresent(() -> "%F%"); assertThat(cond.value()).isEqualTo("%F%"); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsNotLikeWhenPresentNull() { IsNotLike cond = SqlBuilder.isNotLikeWhenPresent(() -> null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); } @Test void testIsNotLikeCaseInsensitive() { IsNotLikeCaseInsensitive cond = SqlBuilder.isNotLikeCaseInsensitive(() -> "%f%"); assertThat(cond.value()).isEqualTo("%F%"); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsNotLikeCaseInsensitiveNull() { IsNotLikeCaseInsensitive cond = SqlBuilder.isNotLikeCaseInsensitive(() -> null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsNotLikeCaseInsensitiveWhenPresent() { IsNotLikeCaseInsensitive cond = SqlBuilder.isNotLikeCaseInsensitiveWhenPresent(() -> "%f%"); assertThat(cond.value()).isEqualTo("%F%"); - assertThat(cond.shouldRender()).isTrue(); + assertThat(cond.isEmpty()).isFalse(); } @Test void testIsNotLikeCaseInsensitiveWhenPresentNull() { IsNotLikeCaseInsensitive cond = SqlBuilder.isNotLikeCaseInsensitiveWhenPresent(() -> null); assertThat(cond.value()).isNull(); - assertThat(cond.shouldRender()).isFalse(); + assertThat(cond.isEmpty()).isTrue(); } }