From c39435e391dfc487360ca811d606f3bc461b0fa2 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sun, 22 Dec 2024 09:53:19 +0100 Subject: [PATCH] Replace `@MethodSource` with `@FieldSource` --- .../batch/extensions/notion/FilterTests.java | 915 +++++++++--------- .../batch/extensions/notion/SortTests.java | 60 +- .../extensions/notion/mapping/TestData.java | 32 +- 3 files changed, 491 insertions(+), 516 deletions(-) diff --git a/spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/FilterTests.java b/spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/FilterTests.java index bf6ec4ad..61173a81 100644 --- a/spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/FilterTests.java +++ b/spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/FilterTests.java @@ -24,16 +24,15 @@ import notion.api.v1.model.databases.query.filter.condition.SelectFilter; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.FieldSource; import java.util.List; import java.util.function.Supplier; import java.util.stream.Stream; -import static org.springframework.batch.extensions.notion.Filter.where; -import static java.util.function.Function.identity; import static org.assertj.core.api.BDDAssertions.then; import static org.junit.jupiter.params.provider.Arguments.arguments; +import static org.springframework.batch.extensions.notion.Filter.where; /** * @author Stefano Cordio @@ -41,7 +40,7 @@ class FilterTests { @ParameterizedTest - @MethodSource({ "propertyFilters", "compoundFilters", "nestedFilters" }) + @FieldSource({ "PROPERTY_FILTERS", "COMPOUND_FILTERS", "NESTED_FILTERS" }) void toQueryTopLevelFilter(Filter underTest, QueryTopLevelFilter expected) { // WHEN QueryTopLevelFilter result = underTest.toQueryTopLevelFilter(); @@ -49,478 +48,462 @@ void toQueryTopLevelFilter(Filter underTest, QueryTopLevelFilter expected) { then(result).usingRecursiveComparison().isEqualTo(expected); } - static Stream propertyFilters() { - return Stream.of( // - checkboxFilters(), // - multiSelectFilters(), // - numberFilters(), // - selectFilters()) // - .flatMap(identity()); - } - - static Stream checkboxFilters() { - return Stream.of(true, false) - .flatMap(value -> Stream.of( // - arguments( // - where().checkbox("property").isEqualTo(value), // - supply(() -> { - CheckboxFilter checkboxFilter = new CheckboxFilter(); - checkboxFilter.setEquals(value); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setCheckbox(checkboxFilter); - return propertyFilter; - })), - arguments( // - where().checkbox("property").isNotEqualTo(value), // - supply(() -> { - CheckboxFilter checkboxFilter = new CheckboxFilter(); - checkboxFilter.setDoesNotEqual(value); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setCheckbox(checkboxFilter); - return propertyFilter; - })))); - } - - static Stream multiSelectFilters() { - return Stream.of( // - arguments( // - where().multiSelect("property").contains("value"), // - supply(() -> { - MultiSelectFilter multiSelectFilter = new MultiSelectFilter(); - multiSelectFilter.setContains("value"); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setMultiSelect(multiSelectFilter); - return propertyFilter; - })), - arguments( // - where().multiSelect("property").doesNotContain("value"), // - supply(() -> { - MultiSelectFilter multiSelectFilter = new MultiSelectFilter(); - multiSelectFilter.setDoesNotContain("value"); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setMultiSelect(multiSelectFilter); - return propertyFilter; - })), - arguments( // - where().multiSelect("property").isEmpty(), // - supply(() -> { - MultiSelectFilter multiSelectFilter = new MultiSelectFilter(); - multiSelectFilter.setEmpty(true); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setMultiSelect(multiSelectFilter); - return propertyFilter; - })), - arguments( // - where().multiSelect("property").isNotEmpty(), // - supply(() -> { - MultiSelectFilter multiSelectFilter = new MultiSelectFilter(); - multiSelectFilter.setNotEmpty(true); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setMultiSelect(multiSelectFilter); - return propertyFilter; - }))); - } - - static Stream numberFilters() { - return Stream.of( // + static final List CHECKBOX_FILTERS = Stream.of(true, false) + .flatMap(value -> Stream.of( // arguments( // - where().number("property").isEqualTo(42), // + where().checkbox("property").isEqualTo(value), // supply(() -> { - NumberFilter numberFilter = new NumberFilter(); - numberFilter.setEquals(42); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setNumber(numberFilter); - return propertyFilter; - })), - arguments( // - where().number("property").isNotEqualTo(42), // - supply(() -> { - NumberFilter numberFilter = new NumberFilter(); - numberFilter.setDoesNotEqual(42); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setNumber(numberFilter); - return propertyFilter; - })), - arguments( // - where().number("property").isGreaterThan(42), // - supply(() -> { - NumberFilter numberFilter = new NumberFilter(); - numberFilter.setGreaterThan(42); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setNumber(numberFilter); - return propertyFilter; - })), - arguments( // - where().number("property").isGreaterThanOrEqualTo(42), // - supply(() -> { - NumberFilter numberFilter = new NumberFilter(); - numberFilter.setGreaterThanOrEqualTo(42); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setNumber(numberFilter); - return propertyFilter; - })), - arguments( // - where().number("property").isLessThan(42), // - supply(() -> { - NumberFilter numberFilter = new NumberFilter(); - numberFilter.setLessThan(42); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setNumber(numberFilter); - return propertyFilter; - })), - arguments( // - where().number("property").isLessThanOrEqualTo(42), // - supply(() -> { - NumberFilter numberFilter = new NumberFilter(); - numberFilter.setLessThanOrEqualTo(42); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setNumber(numberFilter); - return propertyFilter; - })), - arguments( // - where().number("property").isEmpty(), // - supply(() -> { - NumberFilter numberFilter = new NumberFilter(); - numberFilter.setEmpty(true); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setNumber(numberFilter); - return propertyFilter; - })), - arguments( // - where().number("property").isNotEmpty(), // - supply(() -> { - NumberFilter numberFilter = new NumberFilter(); - numberFilter.setNotEmpty(true); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setNumber(numberFilter); - return propertyFilter; - }))); - } - - static Stream selectFilters() { - return Stream.of( // - arguments( // - where().select("property").isEqualTo("value"), // - supply(() -> { - SelectFilter selectFilter = new SelectFilter(); - selectFilter.setEquals("value"); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setSelect(selectFilter); - return propertyFilter; - })), - arguments( // - where().select("property").isNotEqualTo("value"), // - supply(() -> { - SelectFilter selectFilter = new SelectFilter(); - selectFilter.setDoesNotEqual("value"); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setSelect(selectFilter); - return propertyFilter; - })), - arguments( // - where().select("property").isEmpty(), // - supply(() -> { - SelectFilter selectFilter = new SelectFilter(); - selectFilter.setEmpty(true); + CheckboxFilter checkboxFilter = new CheckboxFilter(); + checkboxFilter.setEquals(value); PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setSelect(selectFilter); + propertyFilter.setCheckbox(checkboxFilter); return propertyFilter; })), arguments( // - where().select("property").isNotEmpty(), // - supply(() -> { - SelectFilter selectFilter = new SelectFilter(); - selectFilter.setNotEmpty(true); - PropertyFilter propertyFilter = new PropertyFilter("property"); - propertyFilter.setSelect(selectFilter); - return propertyFilter; - }))); - } - - static Stream compoundFilters() { - return Stream.of(andFilters(), orFilters()).flatMap(identity()); - } - - static Stream andFilters() { - return Stream.of( // - arguments( // @formatter:off - where().checkbox("active").isEqualTo(false) - .and().select("another").isNotEmpty(), // - // @formatter:on - supply(() -> { - CompoundFilter compoundFilter = new CompoundFilter(); - - compoundFilter.setAnd(List.of( // - supply(() -> { - CheckboxFilter checkboxFilter = new CheckboxFilter(); - checkboxFilter.setEquals(false); - PropertyFilter propertyFilter = new PropertyFilter("active"); - propertyFilter.setCheckbox(checkboxFilter); - return propertyFilter; - }), supply(() -> { - SelectFilter selectFilter = new SelectFilter(); - selectFilter.setNotEmpty(true); - PropertyFilter propertyFilter = new PropertyFilter("another"); - propertyFilter.setSelect(selectFilter); - return propertyFilter; - }))); - - return compoundFilter; - })), - arguments( // @formatter:off - where().checkbox("active").isEqualTo(false) - .and(where().select("another").isNotEmpty()), - // @formatter:on - supply(() -> { - CompoundFilter compoundFilter = new CompoundFilter(); - - compoundFilter.setAnd(List.of( // - supply(() -> { - CheckboxFilter checkboxFilter = new CheckboxFilter(); - checkboxFilter.setEquals(false); - PropertyFilter propertyFilter = new PropertyFilter("active"); - propertyFilter.setCheckbox(checkboxFilter); - return propertyFilter; - }), supply(() -> { - SelectFilter selectFilter = new SelectFilter(); - selectFilter.setNotEmpty(true); - PropertyFilter propertyFilter = new PropertyFilter("another"); - propertyFilter.setSelect(selectFilter); - return propertyFilter; - }))); - - return compoundFilter; - })), - arguments( // @formatter:off - where().checkbox("active").isEqualTo(false) - .and(where().select("another").isNotEmpty()) - .and().checkbox("one-more").isNotEqualTo(true) - .and(where().select("another-more").isEmpty()), - // @formatter:on - supply(() -> { - CompoundFilter compoundFilter = new CompoundFilter(); - - compoundFilter.setAnd(List.of( // - supply(() -> { - CheckboxFilter checkboxFilter = new CheckboxFilter(); - checkboxFilter.setEquals(false); - PropertyFilter propertyFilter = new PropertyFilter("active"); - propertyFilter.setCheckbox(checkboxFilter); - return propertyFilter; - }), // - supply(() -> { - SelectFilter selectFilter = new SelectFilter(); - selectFilter.setNotEmpty(true); - PropertyFilter propertyFilter = new PropertyFilter("another"); - propertyFilter.setSelect(selectFilter); - return propertyFilter; - }), // - supply(() -> { - CheckboxFilter checkboxFilter = new CheckboxFilter(); - checkboxFilter.setDoesNotEqual(true); - PropertyFilter propertyFilter = new PropertyFilter("one-more"); - propertyFilter.setCheckbox(checkboxFilter); - return propertyFilter; - }), // - supply(() -> { - SelectFilter selectFilter = new SelectFilter(); - selectFilter.setEmpty(true); - PropertyFilter propertyFilter = new PropertyFilter("another-more"); - propertyFilter.setSelect(selectFilter); - return propertyFilter; - }))); - - return compoundFilter; - }))); - } - - static Stream orFilters() { - return Stream.of( // - arguments( // @formatter:off - where().checkbox("active").isEqualTo(false) - .or().select("another").isNotEmpty(), - // @formatter:on - supply(() -> { - CompoundFilter compoundFilter = new CompoundFilter(); - - compoundFilter.setOr(List.of( // - supply(() -> { - CheckboxFilter checkboxFilter = new CheckboxFilter(); - checkboxFilter.setEquals(false); - PropertyFilter propertyFilter = new PropertyFilter("active"); - propertyFilter.setCheckbox(checkboxFilter); - return propertyFilter; - }), // - supply(() -> { - SelectFilter selectFilter = new SelectFilter(); - selectFilter.setNotEmpty(true); - PropertyFilter propertyFilter = new PropertyFilter("another"); - propertyFilter.setSelect(selectFilter); - return propertyFilter; - }))); - - return compoundFilter; - })), - arguments( // @formatter:off - where().checkbox("active").isEqualTo(false) - .or(where().select("another").isNotEmpty()), - // @formatter:on - supply(() -> { - CompoundFilter compoundFilter = new CompoundFilter(); - - compoundFilter.setOr(List.of( // - supply(() -> { - CheckboxFilter checkboxFilter = new CheckboxFilter(); - checkboxFilter.setEquals(false); - PropertyFilter propertyFilter = new PropertyFilter("active"); - propertyFilter.setCheckbox(checkboxFilter); - return propertyFilter; - }), // - supply(() -> { - SelectFilter selectFilter = new SelectFilter(); - selectFilter.setNotEmpty(true); - PropertyFilter propertyFilter = new PropertyFilter("another"); - propertyFilter.setSelect(selectFilter); - return propertyFilter; - }))); - - return compoundFilter; - })), - arguments( // @formatter:off - where().checkbox("active").isEqualTo(false) - .or(where().select("another").isNotEmpty()) - .or().checkbox("one-more").isNotEqualTo(true) - .or(where().select("another-more").isEmpty()), - // @formatter:on - supply(() -> { - CompoundFilter compoundFilter = new CompoundFilter(); - - compoundFilter.setOr(List.of( // - supply(() -> { - CheckboxFilter checkboxFilter = new CheckboxFilter(); - checkboxFilter.setEquals(false); - PropertyFilter propertyFilter = new PropertyFilter("active"); - propertyFilter.setCheckbox(checkboxFilter); - return propertyFilter; - }), // - supply(() -> { - SelectFilter selectFilter = new SelectFilter(); - selectFilter.setNotEmpty(true); - PropertyFilter propertyFilter = new PropertyFilter("another"); - propertyFilter.setSelect(selectFilter); - return propertyFilter; - }), // - supply(() -> { - CheckboxFilter checkboxFilter = new CheckboxFilter(); - checkboxFilter.setDoesNotEqual(true); - PropertyFilter propertyFilter = new PropertyFilter("one-more"); - propertyFilter.setCheckbox(checkboxFilter); - return propertyFilter; - }), // - supply(() -> { - SelectFilter selectFilter = new SelectFilter(); - selectFilter.setEmpty(true); - PropertyFilter propertyFilter = new PropertyFilter("another-more"); - propertyFilter.setSelect(selectFilter); - return propertyFilter; - }))); - - return compoundFilter; - }))); - } - - static Stream nestedFilters() { - return Stream.of( // - arguments( // @formatter:off - where(where().checkbox("active").isEqualTo(true)), - // @formatter:on + where().checkbox("property").isNotEqualTo(value), // supply(() -> { CheckboxFilter checkboxFilter = new CheckboxFilter(); - checkboxFilter.setEquals(true); - PropertyFilter propertyFilter = new PropertyFilter("active"); + checkboxFilter.setDoesNotEqual(value); + PropertyFilter propertyFilter = new PropertyFilter("property"); propertyFilter.setCheckbox(checkboxFilter); return propertyFilter; - })), - arguments( // @formatter:off - where().checkbox("active").isEqualTo(true) - .and(where().select("another").isEmpty().or().select("another").isEqualTo("value")), - // @formatter:on - supply(() -> { - CompoundFilter compoundFilter = new CompoundFilter(); - - compoundFilter.setAnd(List.of( // - supply(() -> { - CheckboxFilter checkboxFilter = new CheckboxFilter(); - checkboxFilter.setEquals(true); - PropertyFilter propertyFilter = new PropertyFilter("active"); - propertyFilter.setCheckbox(checkboxFilter); - return propertyFilter; - }), // - supply(() -> { - CompoundFilter innerFilter = new CompoundFilter(); - - innerFilter.setOr(List.of( // - supply(() -> { - SelectFilter selectFilter = new SelectFilter(); - selectFilter.setEmpty(true); - PropertyFilter propertyFilter = new PropertyFilter("another"); - propertyFilter.setSelect(selectFilter); - return propertyFilter; - }), // - supply(() -> { - SelectFilter selectFilter = new SelectFilter(); - selectFilter.setEquals("value"); - PropertyFilter propertyFilter = new PropertyFilter("another"); - propertyFilter.setSelect(selectFilter); - return propertyFilter; - }))); - - return innerFilter; - }))); - - return compoundFilter; - })), - arguments( // @formatter:off - where(where().checkbox("active").isEqualTo(false) - .or().select("another").isNotEmpty()) - .and().select("one-more").isEmpty(), - // @formatter:on - supply(() -> { - CompoundFilter compoundFilter = new CompoundFilter(); - - compoundFilter.setAnd(List.of( // - supply(() -> { - CompoundFilter innerFilter = new CompoundFilter(); - - innerFilter.setOr(List.of( // - supply(() -> { - CheckboxFilter checkboxFilter = new CheckboxFilter(); - checkboxFilter.setEquals(false); - PropertyFilter propertyFilter = new PropertyFilter("active"); - propertyFilter.setCheckbox(checkboxFilter); - return propertyFilter; - }), // - supply(() -> { - SelectFilter selectFilter = new SelectFilter(); - selectFilter.setNotEmpty(true); - PropertyFilter propertyFilter = new PropertyFilter("another"); - propertyFilter.setSelect(selectFilter); - return propertyFilter; - }))); - - return innerFilter; - }), // - supply(() -> { - SelectFilter selectFilter = new SelectFilter(); - selectFilter.setEmpty(true); - PropertyFilter propertyFilter = new PropertyFilter("one-more"); - propertyFilter.setSelect(selectFilter); - return propertyFilter; - }))); - - return compoundFilter; - }))); - } + })))) + .toList(); + + static final List MULTI_SELECT_FILTERS = List.of( // + arguments( // + where().multiSelect("property").contains("value"), // + supply(() -> { + MultiSelectFilter multiSelectFilter = new MultiSelectFilter(); + multiSelectFilter.setContains("value"); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setMultiSelect(multiSelectFilter); + return propertyFilter; + })), + arguments( // + where().multiSelect("property").doesNotContain("value"), // + supply(() -> { + MultiSelectFilter multiSelectFilter = new MultiSelectFilter(); + multiSelectFilter.setDoesNotContain("value"); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setMultiSelect(multiSelectFilter); + return propertyFilter; + })), + arguments( // + where().multiSelect("property").isEmpty(), // + supply(() -> { + MultiSelectFilter multiSelectFilter = new MultiSelectFilter(); + multiSelectFilter.setEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setMultiSelect(multiSelectFilter); + return propertyFilter; + })), + arguments( // + where().multiSelect("property").isNotEmpty(), // + supply(() -> { + MultiSelectFilter multiSelectFilter = new MultiSelectFilter(); + multiSelectFilter.setNotEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setMultiSelect(multiSelectFilter); + return propertyFilter; + }))); + + static final List NUMBER_FILTERS = List.of( // + arguments( // + where().number("property").isEqualTo(42), // + supply(() -> { + NumberFilter numberFilter = new NumberFilter(); + numberFilter.setEquals(42); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setNumber(numberFilter); + return propertyFilter; + })), + arguments( // + where().number("property").isNotEqualTo(42), // + supply(() -> { + NumberFilter numberFilter = new NumberFilter(); + numberFilter.setDoesNotEqual(42); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setNumber(numberFilter); + return propertyFilter; + })), + arguments( // + where().number("property").isGreaterThan(42), // + supply(() -> { + NumberFilter numberFilter = new NumberFilter(); + numberFilter.setGreaterThan(42); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setNumber(numberFilter); + return propertyFilter; + })), + arguments( // + where().number("property").isGreaterThanOrEqualTo(42), // + supply(() -> { + NumberFilter numberFilter = new NumberFilter(); + numberFilter.setGreaterThanOrEqualTo(42); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setNumber(numberFilter); + return propertyFilter; + })), + arguments( // + where().number("property").isLessThan(42), // + supply(() -> { + NumberFilter numberFilter = new NumberFilter(); + numberFilter.setLessThan(42); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setNumber(numberFilter); + return propertyFilter; + })), + arguments( // + where().number("property").isLessThanOrEqualTo(42), // + supply(() -> { + NumberFilter numberFilter = new NumberFilter(); + numberFilter.setLessThanOrEqualTo(42); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setNumber(numberFilter); + return propertyFilter; + })), + arguments( // + where().number("property").isEmpty(), // + supply(() -> { + NumberFilter numberFilter = new NumberFilter(); + numberFilter.setEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setNumber(numberFilter); + return propertyFilter; + })), + arguments( // + where().number("property").isNotEmpty(), // + supply(() -> { + NumberFilter numberFilter = new NumberFilter(); + numberFilter.setNotEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setNumber(numberFilter); + return propertyFilter; + }))); + + static final List SELECT_FILTERS = List.of( // + arguments( // + where().select("property").isEqualTo("value"), // + supply(() -> { + SelectFilter selectFilter = new SelectFilter(); + selectFilter.setEquals("value"); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setSelect(selectFilter); + return propertyFilter; + })), + arguments( // + where().select("property").isNotEqualTo("value"), // + supply(() -> { + SelectFilter selectFilter = new SelectFilter(); + selectFilter.setDoesNotEqual("value"); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setSelect(selectFilter); + return propertyFilter; + })), + arguments( // + where().select("property").isEmpty(), // + supply(() -> { + SelectFilter selectFilter = new SelectFilter(); + selectFilter.setEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setSelect(selectFilter); + return propertyFilter; + })), + arguments( // + where().select("property").isNotEmpty(), // + supply(() -> { + SelectFilter selectFilter = new SelectFilter(); + selectFilter.setNotEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("property"); + propertyFilter.setSelect(selectFilter); + return propertyFilter; + }))); + + static final List PROPERTY_FILTERS = Stream.of( // + CHECKBOX_FILTERS, // + MULTI_SELECT_FILTERS, // + NUMBER_FILTERS, // + SELECT_FILTERS) // + .flatMap(List::stream) + .toList(); + + static final List AND_FILTERS = List.of( // + arguments( // @formatter:off + where().checkbox("active").isEqualTo(false) + .and().select("another").isNotEmpty(), // + // @formatter:on + supply(() -> { + CompoundFilter compoundFilter = new CompoundFilter(); + + compoundFilter.setAnd(List.of( // + supply(() -> { + CheckboxFilter checkboxFilter = new CheckboxFilter(); + checkboxFilter.setEquals(false); + PropertyFilter propertyFilter = new PropertyFilter("active"); + propertyFilter.setCheckbox(checkboxFilter); + return propertyFilter; + }), supply(() -> { + SelectFilter selectFilter = new SelectFilter(); + selectFilter.setNotEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("another"); + propertyFilter.setSelect(selectFilter); + return propertyFilter; + }))); + + return compoundFilter; + })), + arguments( // @formatter:off + where().checkbox("active").isEqualTo(false) + .and(where().select("another").isNotEmpty()), + // @formatter:on + supply(() -> { + CompoundFilter compoundFilter = new CompoundFilter(); + + compoundFilter.setAnd(List.of( // + supply(() -> { + CheckboxFilter checkboxFilter = new CheckboxFilter(); + checkboxFilter.setEquals(false); + PropertyFilter propertyFilter = new PropertyFilter("active"); + propertyFilter.setCheckbox(checkboxFilter); + return propertyFilter; + }), supply(() -> { + SelectFilter selectFilter = new SelectFilter(); + selectFilter.setNotEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("another"); + propertyFilter.setSelect(selectFilter); + return propertyFilter; + }))); + + return compoundFilter; + })), + arguments( // @formatter:off + where().checkbox("active").isEqualTo(false) + .and(where().select("another").isNotEmpty()) + .and().checkbox("one-more").isNotEqualTo(true) + .and(where().select("another-more").isEmpty()), + // @formatter:on + supply(() -> { + CompoundFilter compoundFilter = new CompoundFilter(); + + compoundFilter.setAnd(List.of( // + supply(() -> { + CheckboxFilter checkboxFilter = new CheckboxFilter(); + checkboxFilter.setEquals(false); + PropertyFilter propertyFilter = new PropertyFilter("active"); + propertyFilter.setCheckbox(checkboxFilter); + return propertyFilter; + }), // + supply(() -> { + SelectFilter selectFilter = new SelectFilter(); + selectFilter.setNotEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("another"); + propertyFilter.setSelect(selectFilter); + return propertyFilter; + }), // + supply(() -> { + CheckboxFilter checkboxFilter = new CheckboxFilter(); + checkboxFilter.setDoesNotEqual(true); + PropertyFilter propertyFilter = new PropertyFilter("one-more"); + propertyFilter.setCheckbox(checkboxFilter); + return propertyFilter; + }), // + supply(() -> { + SelectFilter selectFilter = new SelectFilter(); + selectFilter.setEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("another-more"); + propertyFilter.setSelect(selectFilter); + return propertyFilter; + }))); + + return compoundFilter; + }))); + + static final List OR_FILTERS = List.of( // + arguments( // @formatter:off + where().checkbox("active").isEqualTo(false) + .or().select("another").isNotEmpty(), + // @formatter:on + supply(() -> { + CompoundFilter compoundFilter = new CompoundFilter(); + + compoundFilter.setOr(List.of( // + supply(() -> { + CheckboxFilter checkboxFilter = new CheckboxFilter(); + checkboxFilter.setEquals(false); + PropertyFilter propertyFilter = new PropertyFilter("active"); + propertyFilter.setCheckbox(checkboxFilter); + return propertyFilter; + }), // + supply(() -> { + SelectFilter selectFilter = new SelectFilter(); + selectFilter.setNotEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("another"); + propertyFilter.setSelect(selectFilter); + return propertyFilter; + }))); + + return compoundFilter; + })), + arguments( // @formatter:off + where().checkbox("active").isEqualTo(false) + .or(where().select("another").isNotEmpty()), + // @formatter:on + supply(() -> { + CompoundFilter compoundFilter = new CompoundFilter(); + + compoundFilter.setOr(List.of( // + supply(() -> { + CheckboxFilter checkboxFilter = new CheckboxFilter(); + checkboxFilter.setEquals(false); + PropertyFilter propertyFilter = new PropertyFilter("active"); + propertyFilter.setCheckbox(checkboxFilter); + return propertyFilter; + }), // + supply(() -> { + SelectFilter selectFilter = new SelectFilter(); + selectFilter.setNotEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("another"); + propertyFilter.setSelect(selectFilter); + return propertyFilter; + }))); + + return compoundFilter; + })), + arguments( // @formatter:off + where().checkbox("active").isEqualTo(false) + .or(where().select("another").isNotEmpty()) + .or().checkbox("one-more").isNotEqualTo(true) + .or(where().select("another-more").isEmpty()), + // @formatter:on + supply(() -> { + CompoundFilter compoundFilter = new CompoundFilter(); + + compoundFilter.setOr(List.of( // + supply(() -> { + CheckboxFilter checkboxFilter = new CheckboxFilter(); + checkboxFilter.setEquals(false); + PropertyFilter propertyFilter = new PropertyFilter("active"); + propertyFilter.setCheckbox(checkboxFilter); + return propertyFilter; + }), // + supply(() -> { + SelectFilter selectFilter = new SelectFilter(); + selectFilter.setNotEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("another"); + propertyFilter.setSelect(selectFilter); + return propertyFilter; + }), // + supply(() -> { + CheckboxFilter checkboxFilter = new CheckboxFilter(); + checkboxFilter.setDoesNotEqual(true); + PropertyFilter propertyFilter = new PropertyFilter("one-more"); + propertyFilter.setCheckbox(checkboxFilter); + return propertyFilter; + }), // + supply(() -> { + SelectFilter selectFilter = new SelectFilter(); + selectFilter.setEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("another-more"); + propertyFilter.setSelect(selectFilter); + return propertyFilter; + }))); + + return compoundFilter; + }))); + + static final List COMPOUND_FILTERS = Stream.of(AND_FILTERS, OR_FILTERS).flatMap(List::stream).toList(); + + static final List NESTED_FILTERS = List.of( // + arguments( // @formatter:off + where(where().checkbox("active").isEqualTo(true)), + // @formatter:on + supply(() -> { + CheckboxFilter checkboxFilter = new CheckboxFilter(); + checkboxFilter.setEquals(true); + PropertyFilter propertyFilter = new PropertyFilter("active"); + propertyFilter.setCheckbox(checkboxFilter); + return propertyFilter; + })), + arguments( // @formatter:off + where().checkbox("active").isEqualTo(true) + .and(where().select("another").isEmpty().or().select("another").isEqualTo("value")), + // @formatter:on + supply(() -> { + CompoundFilter compoundFilter = new CompoundFilter(); + + compoundFilter.setAnd(List.of( // + supply(() -> { + CheckboxFilter checkboxFilter = new CheckboxFilter(); + checkboxFilter.setEquals(true); + PropertyFilter propertyFilter = new PropertyFilter("active"); + propertyFilter.setCheckbox(checkboxFilter); + return propertyFilter; + }), // + supply(() -> { + CompoundFilter innerFilter = new CompoundFilter(); + + innerFilter.setOr(List.of( // + supply(() -> { + SelectFilter selectFilter = new SelectFilter(); + selectFilter.setEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("another"); + propertyFilter.setSelect(selectFilter); + return propertyFilter; + }), // + supply(() -> { + SelectFilter selectFilter = new SelectFilter(); + selectFilter.setEquals("value"); + PropertyFilter propertyFilter = new PropertyFilter("another"); + propertyFilter.setSelect(selectFilter); + return propertyFilter; + }))); + + return innerFilter; + }))); + + return compoundFilter; + })), + arguments( // @formatter:off + where(where().checkbox("active").isEqualTo(false) + .or().select("another").isNotEmpty()) + .and().select("one-more").isEmpty(), + // @formatter:on + supply(() -> { + CompoundFilter compoundFilter = new CompoundFilter(); + + compoundFilter.setAnd(List.of( // + supply(() -> { + CompoundFilter innerFilter = new CompoundFilter(); + + innerFilter.setOr(List.of( // + supply(() -> { + CheckboxFilter checkboxFilter = new CheckboxFilter(); + checkboxFilter.setEquals(false); + PropertyFilter propertyFilter = new PropertyFilter("active"); + propertyFilter.setCheckbox(checkboxFilter); + return propertyFilter; + }), // + supply(() -> { + SelectFilter selectFilter = new SelectFilter(); + selectFilter.setNotEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("another"); + propertyFilter.setSelect(selectFilter); + return propertyFilter; + }))); + + return innerFilter; + }), // + supply(() -> { + SelectFilter selectFilter = new SelectFilter(); + selectFilter.setEmpty(true); + PropertyFilter propertyFilter = new PropertyFilter("one-more"); + propertyFilter.setSelect(selectFilter); + return propertyFilter; + }))); + + return compoundFilter; + }))); private static T supply(Supplier supplier) { return supplier.get(); diff --git a/spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/SortTests.java b/spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/SortTests.java index ac8c53c8..995243ac 100644 --- a/spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/SortTests.java +++ b/spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/SortTests.java @@ -20,14 +20,10 @@ import notion.api.v1.model.databases.query.sort.QuerySortTimestamp; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.FieldSource; -import java.util.stream.Stream; +import java.util.List; -import static org.springframework.batch.extensions.notion.Sort.Direction.ASCENDING; -import static org.springframework.batch.extensions.notion.Sort.Direction.DESCENDING; -import static org.springframework.batch.extensions.notion.Sort.Timestamp.CREATED_TIME; -import static org.springframework.batch.extensions.notion.Sort.Timestamp.LAST_EDITED_TIME; import static notion.api.v1.model.databases.query.sort.QuerySortDirection.Ascending; import static notion.api.v1.model.databases.query.sort.QuerySortDirection.Descending; import static notion.api.v1.model.databases.query.sort.QuerySortTimestamp.CreatedTime; @@ -35,6 +31,10 @@ import static org.assertj.core.api.BDDAssertions.from; import static org.assertj.core.api.BDDAssertions.then; import static org.junit.jupiter.params.provider.Arguments.arguments; +import static org.springframework.batch.extensions.notion.Sort.Direction.ASCENDING; +import static org.springframework.batch.extensions.notion.Sort.Direction.DESCENDING; +import static org.springframework.batch.extensions.notion.Sort.Timestamp.CREATED_TIME; +import static org.springframework.batch.extensions.notion.Sort.Timestamp.LAST_EDITED_TIME; /** * @author Stefano Cordio @@ -42,7 +42,7 @@ class SortTests { @ParameterizedTest - @MethodSource + @FieldSource void toQuerySort(Sort underTest, String property, QuerySortTimestamp timestamp, QuerySortDirection direction) { // WHEN QuerySort result = underTest.toQuerySort(); @@ -53,21 +53,19 @@ void toQuerySort(Sort underTest, String property, QuerySortTimestamp timestamp, .returns(timestamp, from(QuerySort::getTimestamp)); } - static Stream toQuerySort() { - return Stream.of( // - arguments(Sort.by("property"), "property", null, Ascending), - arguments(Sort.by("property", ASCENDING), "property", null, Ascending), - arguments(Sort.by("property", DESCENDING), "property", null, Descending), - arguments(Sort.by(CREATED_TIME), null, CreatedTime, Ascending), - arguments(Sort.by(CREATED_TIME, ASCENDING), null, CreatedTime, Ascending), - arguments(Sort.by(CREATED_TIME, DESCENDING), null, CreatedTime, Descending), - arguments(Sort.by(LAST_EDITED_TIME), null, LastEditedTime, Ascending), - arguments(Sort.by(LAST_EDITED_TIME, ASCENDING), null, LastEditedTime, Ascending), - arguments(Sort.by(LAST_EDITED_TIME, DESCENDING), null, LastEditedTime, Descending)); - } + static List toQuerySort = List.of( // + arguments(Sort.by("property"), "property", null, Ascending), + arguments(Sort.by("property", ASCENDING), "property", null, Ascending), + arguments(Sort.by("property", DESCENDING), "property", null, Descending), + arguments(Sort.by(CREATED_TIME), null, CreatedTime, Ascending), + arguments(Sort.by(CREATED_TIME, ASCENDING), null, CreatedTime, Ascending), + arguments(Sort.by(CREATED_TIME, DESCENDING), null, CreatedTime, Descending), + arguments(Sort.by(LAST_EDITED_TIME), null, LastEditedTime, Ascending), + arguments(Sort.by(LAST_EDITED_TIME, ASCENDING), null, LastEditedTime, Ascending), + arguments(Sort.by(LAST_EDITED_TIME, DESCENDING), null, LastEditedTime, Descending)); @ParameterizedTest - @MethodSource + @FieldSource void testToString(Sort underTest, String expected) { // WHEN String result = underTest.toString(); @@ -75,17 +73,15 @@ void testToString(Sort underTest, String expected) { then(result).isEqualTo(expected); } - static Stream testToString() { - return Stream.of( // - arguments(Sort.by("property"), "property: ASCENDING"), - arguments(Sort.by("property", ASCENDING), "property: ASCENDING"), - arguments(Sort.by("property", DESCENDING), "property: DESCENDING"), - arguments(Sort.by(CREATED_TIME), "CREATED_TIME: ASCENDING"), - arguments(Sort.by(CREATED_TIME, ASCENDING), "CREATED_TIME: ASCENDING"), - arguments(Sort.by(CREATED_TIME, DESCENDING), "CREATED_TIME: DESCENDING"), - arguments(Sort.by(LAST_EDITED_TIME), "LAST_EDITED_TIME: ASCENDING"), - arguments(Sort.by(LAST_EDITED_TIME, ASCENDING), "LAST_EDITED_TIME: ASCENDING"), - arguments(Sort.by(LAST_EDITED_TIME, DESCENDING), "LAST_EDITED_TIME: DESCENDING")); - } + static List testToString = List.of( // + arguments(Sort.by("property"), "property: ASCENDING"), + arguments(Sort.by("property", ASCENDING), "property: ASCENDING"), + arguments(Sort.by("property", DESCENDING), "property: DESCENDING"), + arguments(Sort.by(CREATED_TIME), "CREATED_TIME: ASCENDING"), + arguments(Sort.by(CREATED_TIME, ASCENDING), "CREATED_TIME: ASCENDING"), + arguments(Sort.by(CREATED_TIME, DESCENDING), "CREATED_TIME: DESCENDING"), + arguments(Sort.by(LAST_EDITED_TIME), "LAST_EDITED_TIME: ASCENDING"), + arguments(Sort.by(LAST_EDITED_TIME, ASCENDING), "LAST_EDITED_TIME: ASCENDING"), + arguments(Sort.by(LAST_EDITED_TIME, DESCENDING), "LAST_EDITED_TIME: DESCENDING")); } diff --git a/spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/mapping/TestData.java b/spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/mapping/TestData.java index f0946a6e..e8c19372 100644 --- a/spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/mapping/TestData.java +++ b/spring-batch-notion/src/test/java/org/springframework/batch/extensions/notion/mapping/TestData.java @@ -15,11 +15,11 @@ */ package org.springframework.batch.extensions.notion.mapping; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.FieldSource; import java.lang.annotation.Retention; +import java.util.List; import java.util.Map; -import java.util.stream.Stream; import static java.lang.annotation.RetentionPolicy.RUNTIME; @@ -29,31 +29,27 @@ class TestData { @Retention(RUNTIME) - @MethodSource("org.springframework.batch.extensions.notion.mapping.TestData#all_properties") + @FieldSource("org.springframework.batch.extensions.notion.mapping.TestData#ALL_PROPERTIES") @interface AllPropertiesSource { } - static Stream> all_properties() { - return Stream.of( - // FIXME not working with BeanWrapperPropertyMapper - // Map.of("FIELD1", "Value1", "FIELD2", "Value2"), // - Map.of("Field1", "Value1", "Field2", "Value2"), // - Map.of("field1", "Value1", "field2", "Value2")); - } + static final List> ALL_PROPERTIES = List.of( + // FIXME not working with BeanWrapperPropertyMapper + // Map.of("FIELD1", "Value1", "FIELD2", "Value2"), // + Map.of("Field1", "Value1", "Field2", "Value2"), // + Map.of("field1", "Value1", "field2", "Value2")); @Retention(RUNTIME) - @MethodSource("org.springframework.batch.extensions.notion.mapping.TestData#partial_properties") + @FieldSource("org.springframework.batch.extensions.notion.mapping.TestData#PARTIAL_PROPERTIES") @interface PartialPropertiesSource { } - static Stream> partial_properties() { - return Stream.of( - // FIXME not working with BeanWrapperPropertyMapper - // Map.of("FIELD1", "Value1"), // - Map.of("Field1", "Value1"), // - Map.of("field1", "Value1")); - } + static final List> PARTIAL_PROPERTIES = List.of( + // FIXME not working with BeanWrapperPropertyMapper + // Map.of("FIELD1", "Value1"), // + Map.of("Field1", "Value1"), // + Map.of("field1", "Value1")); }