pgyori commented on code in PR #8670:
URL: https://github.com/apache/nifi/pull/8670#discussion_r1593902067


##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/Range.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.web.util;
+
+public class Range {
+    private final int lowerBoundary;
+    private final int higherBoundary;
+
+    /**
+     * @param lowerBoundary Inclusive index of lower boundary
+     * @param higherBoundary Exclusive index of higher boundary. In case of 0, 
the higher boundary is unspecified and the range is open.
+     */
+    public Range(final int lowerBoundary, final int higherBoundary) {
+        if (lowerBoundary < 0) {
+            throw new IllegalArgumentException("Lower boundary cannot be 
negative");
+        }
+
+        if (higherBoundary < 0) {
+            throw new IllegalArgumentException("Higher boundary cannot be 
negative");
+        }
+
+        if (higherBoundary <= lowerBoundary && higherBoundary != 0) {
+            throw new IllegalArgumentException("Higher boundary cannot be 
lower or equal to lower boundary expect when unspecified");

Review Comment:
   "Higher boundary cannot be lower than or equal to lower boundary except when 
unspecified"
   I think it would help to add that higherBoundary = 0 means unspecified.



##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/Range.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.web.util;
+
+public class Range {
+    private final int lowerBoundary;
+    private final int higherBoundary;
+
+    /**
+     * @param lowerBoundary Inclusive index of lower boundary
+     * @param higherBoundary Exclusive index of higher boundary. In case of 0, 
the higher boundary is unspecified and the range is open.
+     */
+    public Range(final int lowerBoundary, final int higherBoundary) {
+        if (lowerBoundary < 0) {
+            throw new IllegalArgumentException("Lower boundary cannot be 
negative");
+        }
+
+        if (higherBoundary < 0) {
+            throw new IllegalArgumentException("Higher boundary cannot be 
negative");
+        }
+
+        if (higherBoundary <= lowerBoundary && higherBoundary != 0) {
+            throw new IllegalArgumentException("Higher boundary cannot be 
lower or equal to lower boundary expect when unspecified");
+        }
+
+        this.lowerBoundary = lowerBoundary;
+        this.higherBoundary = higherBoundary;
+    }
+
+    public RelativePosition getOverlapping(final int otherRangeLowerBoundary, 
final int otherRangeHigherBoundary) {
+        if (otherRangeHigherBoundary < lowerBoundary) {
+            return RelativePosition.BEFORE_RANGE;
+        } else if (otherRangeLowerBoundary < lowerBoundary && 
otherRangeHigherBoundary >= higherBoundary && !isOpenEnded()) {
+            return RelativePosition.MIDDLE_IS_WITHIN_RANGE;
+        } else if (otherRangeLowerBoundary < lowerBoundary) {
+            return RelativePosition.TAIL_IS_WITHIN_RANGE;
+        } else if (otherRangeHigherBoundary < higherBoundary || isOpenEnded()) 
{

Review Comment:
   <= operator is needed.



##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/Range.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.web.util;
+
+public class Range {
+    private final int lowerBoundary;
+    private final int higherBoundary;
+
+    /**
+     * @param lowerBoundary Inclusive index of lower boundary
+     * @param higherBoundary Exclusive index of higher boundary. In case of 0, 
the higher boundary is unspecified and the range is open.
+     */
+    public Range(final int lowerBoundary, final int higherBoundary) {
+        if (lowerBoundary < 0) {
+            throw new IllegalArgumentException("Lower boundary cannot be 
negative");
+        }
+
+        if (higherBoundary < 0) {
+            throw new IllegalArgumentException("Higher boundary cannot be 
negative");
+        }
+
+        if (higherBoundary <= lowerBoundary && higherBoundary != 0) {
+            throw new IllegalArgumentException("Higher boundary cannot be 
lower or equal to lower boundary expect when unspecified");
+        }
+
+        this.lowerBoundary = lowerBoundary;
+        this.higherBoundary = higherBoundary;
+    }
+
+    public RelativePosition getOverlapping(final int otherRangeLowerBoundary, 
final int otherRangeHigherBoundary) {
+        if (otherRangeHigherBoundary < lowerBoundary) {
+            return RelativePosition.BEFORE_RANGE;
+        } else if (otherRangeLowerBoundary < lowerBoundary && 
otherRangeHigherBoundary >= higherBoundary && !isOpenEnded()) {
+            return RelativePosition.MIDDLE_IS_WITHIN_RANGE;
+        } else if (otherRangeLowerBoundary < lowerBoundary) {
+            return RelativePosition.TAIL_IS_WITHIN_RANGE;
+        } else if (otherRangeHigherBoundary < higherBoundary || isOpenEnded()) 
{
+            return RelativePosition.FULLY_WITHIN_RANGE;
+        } else if (otherRangeLowerBoundary < higherBoundary) {
+            return RelativePosition.HEAD_IS_WITHIN_RANGE;
+        } else {
+            return RelativePosition.AFTER_RANGE;
+        }
+    }
+
+    private boolean isOpenEnded() {
+        return higherBoundary == 0;
+    }
+
+    public enum RelativePosition {

Review Comment:
   I recommend the following enum items for brevity and clarity:
   BEFORE_RANGE
   TAIL_IN_RANGE
   IN_RANGE
   HEAD_IN_RANGE
   EXCEEDS_RANGE (instead of MIDDLE_IS_WITHIN_RANGE)
   AFTER_RANGE



##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java:
##########
@@ -5205,6 +5205,40 @@ public RegisteredFlow deleteVersionedFlow(final String 
registryId, final String
         }
     }
 
+    @Override
+    public FlowComparisonEntity getVersionDifference(final String registryId, 
final String bucketId, final String flowId, final String versionA, final String 
versionB) {
+        final FlowComparisonEntity result = new FlowComparisonEntity();
+
+        if (versionA == versionB) {

Review Comment:
   `versionA.equals(versionB)`



##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/Range.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.web.util;
+
+public class Range {
+    private final int lowerBoundary;
+    private final int higherBoundary;
+
+    /**
+     * @param lowerBoundary Inclusive index of lower boundary
+     * @param higherBoundary Exclusive index of higher boundary. In case of 0, 
the higher boundary is unspecified and the range is open.
+     */
+    public Range(final int lowerBoundary, final int higherBoundary) {
+        if (lowerBoundary < 0) {
+            throw new IllegalArgumentException("Lower boundary cannot be 
negative");
+        }
+
+        if (higherBoundary < 0) {
+            throw new IllegalArgumentException("Higher boundary cannot be 
negative");
+        }
+
+        if (higherBoundary <= lowerBoundary && higherBoundary != 0) {
+            throw new IllegalArgumentException("Higher boundary cannot be 
lower or equal to lower boundary expect when unspecified");
+        }
+
+        this.lowerBoundary = lowerBoundary;
+        this.higherBoundary = higherBoundary;
+    }
+
+    public RelativePosition getOverlapping(final int otherRangeLowerBoundary, 
final int otherRangeHigherBoundary) {

Review Comment:
   When comparing two ranges, there is `range` and `otherRange`.
   It looks to me that in this method `otherRange` is considered the basis of 
comparison whereas in RangeTest `range` is the basis of comparison. I recommend 
always considering `range` as the basis and telling the position of 
`otherRange` compared to that. For example, in the chart the blue line is the 
basis of comparison and in case 1 the black line is after the blue line, 
therefore it is marked as `AFTER_RANGE` because the black is after the blue.



##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/Range.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.web.util;
+
+public class Range {
+    private final int lowerBoundary;
+    private final int higherBoundary;
+
+    /**
+     * @param lowerBoundary Inclusive index of lower boundary
+     * @param higherBoundary Exclusive index of higher boundary. In case of 0, 
the higher boundary is unspecified and the range is open.
+     */
+    public Range(final int lowerBoundary, final int higherBoundary) {
+        if (lowerBoundary < 0) {
+            throw new IllegalArgumentException("Lower boundary cannot be 
negative");
+        }
+
+        if (higherBoundary < 0) {
+            throw new IllegalArgumentException("Higher boundary cannot be 
negative");
+        }
+
+        if (higherBoundary <= lowerBoundary && higherBoundary != 0) {
+            throw new IllegalArgumentException("Higher boundary cannot be 
lower or equal to lower boundary expect when unspecified");
+        }
+
+        this.lowerBoundary = lowerBoundary;
+        this.higherBoundary = higherBoundary;
+    }
+
+    public RelativePosition getOverlapping(final int otherRangeLowerBoundary, 
final int otherRangeHigherBoundary) {

Review Comment:
   The algorithm in this method does not handle every case correctly, please 
consider reworking it. I added some charts that might help: When comparing two 
ranges, there are 13 different positions. I attached an image depicting each 
case.
   <img width="1763" alt="Screenshot 2024-05-08 at 13 56 21" 
src="https://github.com/apache/nifi/assets/63872658/c4e5fe15-5056-42da-b8dc-d395cd8b90fa";>
   
   If we consider the object `this` as the basis of the comparison to which 
`otherRange` is compared, then the 13 cases can be categorized like this:
   <img width="348" alt="Screenshot 2024-05-08 at 13 57 14" 
src="https://github.com/apache/nifi/assets/63872658/424a8978-13ec-4dc7-8393-77f69921a276";>
   
   In my comment for RangeTest I added test cases that highlight the issue.



##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/Range.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.web.util;
+
+public class Range {
+    private final int lowerBoundary;
+    private final int higherBoundary;
+
+    /**
+     * @param lowerBoundary Inclusive index of lower boundary
+     * @param higherBoundary Exclusive index of higher boundary. In case of 0, 
the higher boundary is unspecified and the range is open.
+     */
+    public Range(final int lowerBoundary, final int higherBoundary) {
+        if (lowerBoundary < 0) {
+            throw new IllegalArgumentException("Lower boundary cannot be 
negative");
+        }
+
+        if (higherBoundary < 0) {
+            throw new IllegalArgumentException("Higher boundary cannot be 
negative");
+        }
+
+        if (higherBoundary <= lowerBoundary && higherBoundary != 0) {
+            throw new IllegalArgumentException("Higher boundary cannot be 
lower or equal to lower boundary expect when unspecified");
+        }
+
+        this.lowerBoundary = lowerBoundary;
+        this.higherBoundary = higherBoundary;
+    }
+
+    public RelativePosition getOverlapping(final int otherRangeLowerBoundary, 
final int otherRangeHigherBoundary) {
+        if (otherRangeHigherBoundary < lowerBoundary) {

Review Comment:
   Since the higher boundary is exclusive and the lower is inclusive, we need 
<= operator here.



##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/PaginationHelper.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.web.util;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+
+public class PaginationHelper {
+    public static <T, E> List<T> paginateByContainedItems(
+            final Iterable<T> original,
+            final int offset,
+            final int limit,
+            final Function<T, List<E>> getContainedItems,
+            final BiFunction<T, List<E>, T> createPartialItem
+    ) {
+        Objects.requireNonNull(original);
+        Objects.requireNonNull(getContainedItems);
+        Objects.requireNonNull(createPartialItem);
+
+        if (offset < 0) {
+            throw new IllegalArgumentException("Offset cannot be negative");
+        }
+
+        if (limit < 0) {
+            throw new IllegalArgumentException("Limit cannot be negative");
+        }
+
+        final List<T> result = new LinkedList<>();
+        final int higherBoundary = limit == 0 ? 0 : offset + limit;
+        final Range range = new Range(offset, higherBoundary);
+        int pointer = 0;
+
+        if (offset == 0 && limit == 0) {
+            original.forEach(result::add);
+            return result;
+        }
+
+        for (final T candidate : original) {
+            final List<E> containedItems = getContainedItems.apply(candidate);
+            final Range.RelativePosition position = 
range.getOverlapping(pointer, pointer + containedItems.size() - 1);
+
+            switch (position) {

Review Comment:
   Please consider renaming the enum items according to my suggestion in Range 
class.



##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/util/RangeTest.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.web.util;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.util.stream.Stream;
+
+class RangeTest {
+
+    @Test
+    public void testNegativeLowerBoundary() {
+        Assertions.assertThrows(IllegalArgumentException.class, () -> new 
Range(-1, 3));
+    }
+
+    @Test
+    public void testNegativeHigherBoundary() {
+        Assertions.assertThrows(IllegalArgumentException.class, () -> new 
Range(0, -1));
+    }
+
+    @Test
+    public void testReorderedBoundaries() {
+        Assertions.assertThrows(IllegalArgumentException.class, () -> new 
Range(7, 3));
+    }
+
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("givenTestData")
+    public void testCheckForOverlapping(final String name, final Range window, 
final int otherRangeLowerBoundary, final int otherRangeHigherBoundary, final 
Range.RelativePosition expectedResult) {
+        Assertions.assertEquals(expectedResult, 
window.getOverlapping(otherRangeLowerBoundary, otherRangeHigherBoundary));
+    }
+
+    private static Stream<Arguments> givenTestData() {

Review Comment:
   The 13 possible test cases are like this:
   <img width="1763" alt="Screenshot 2024-05-08 at 13 56 21" 
src="https://github.com/apache/nifi/assets/63872658/e8613d20-f0d1-4fd1-a051-0ae6a021afe7";>
   
   I recommend adding a test case for each:
   `Arguments.of("case 1", new Range(7, 10), 11, 13, 
Range.RelativePosition.AFTER_RANGE),
   Arguments.of("case 2", new Range(7,10), 10, 13, 
Range.RelativePosition.AFTER_RANGE),
   Arguments.of("case 3", new Range(7,10), 9, 13, 
Range.RelativePosition.HEAD_IN_RANGE),
   Arguments.of("case 4", new Range(7, 10), 8, 10, 
Range.RelativePosition.IN_RANGE),
   Arguments.of("case 5", new Range(7,10), 8, 9, 
Range.RelativePosition.IN_RANGE),
   Arguments.of("case 6", new Range(7,10), 7, 12, 
Range.RelativePosition.HEAD_IN_RANGE),
   Arguments.of("case 7", new Range(7,10), 7, 10, 
Range.RelativePosition.IN_RANGE),
   Arguments.of("case 8", new Range(7,10), 7, 9, 
Range.RelativePosition.IN_RANGE),
   Arguments.of("case 9", new Range(7,10), 6, 12, 
Range.RelativePosition.EXCEEDS_RANGE),
   Arguments.of("case 10", new Range(7,10), 5, 10, 
Range.RelativePosition.TAIL_IN_RANGE),
   Arguments.of("case 11", new Range(7,10), 5, 9, 
Range.RelativePosition.TAIL_IN_RANGE),
   Arguments.of("case 12", new Range(7,10), 2, 7, 
Range.RelativePosition.BEFORE_RANGE),
   Arguments.of("case 13", new Range(7,10), 2, 6, 
Range.RelativePosition.BEFORE_RANGE),`



##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/util/PaginationHelperTest.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.web.util;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+class PaginationHelperTest {
+
+    @Test
+    public void testCreatingWithNegativeOffset() {
+        Assertions.assertThrows(IllegalArgumentException.class, () -> 
PaginationHelper.paginateByContainedItems(getTestInput(), -1, 3, 
Function.identity(), (original, partialList) -> partialList));
+    }
+
+    @Test
+    public void testCreatingWithNegativeLimit() {
+        Assertions.assertThrows(IllegalArgumentException.class, () -> 
PaginationHelper.paginateByContainedItems(getTestInput(), 0, -1, 
Function.identity(), (original, partialList) -> partialList));
+    }
+
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("givenTestData")
+    public void testPaginateByContainedItems(final String name, final int 
offset, final int limit, final List<Integer> expectedResult) {
+        final List<List<Integer>> result = 
PaginationHelper.paginateByContainedItems(getTestInput(), offset, limit, 
Function.identity(), (original, partialList) -> partialList);
+        final List<Integer> flatten = 
result.stream().flatMap(Collection::stream).collect(Collectors.toList());
+        Assertions.assertIterableEquals(expectedResult, flatten);
+    }
+
+    private static Stream<Arguments> givenTestData() {

Review Comment:
   Considering the 13 cases shown in the chart attached to the review of Range 
class, cases 1, 2,3,4 and 5 need to be covered with `Assertions.assertThrows()` 
test cases. I'm pasting here the existing test cases, each marked with a 
comment showing which case it covers:
   ```
   Arguments.of("Full result set", 0, 0, Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 
9, 10, 11, 12)), // case 8
   
   Arguments.of("Offset only when starts with full", 3, 0, Arrays.asList(4, 5, 
6, 7, 8, 9, 10, 11, 12)), // case 11
   
   Arguments.of("Offset only when starts with partial", 4, 0, Arrays.asList(5, 
6, 7, 8, 9, 10, 11, 12)), // case 11
   
   Arguments.of("From beginning with partial", 0, 5, Arrays.asList(1, 2, 3, 4, 
5)), // case 6
   
   Arguments.of("Beginning with partial and offset", 1, 5, Arrays.asList(2, 3, 
4, 5, 6)), // case 9
   
   Arguments.of("Middle partial only", 4, 2, Arrays.asList(5, 6)), // case 9
   
   Arguments.of("From the end with partial", 9, 3, Arrays.asList(10, 11, 12)), 
// case 9
   
   Arguments.of("From the end with partial when spills over", 9, 5, 
Arrays.asList(10, 11, 12)), // case 11
   
   Arguments.of("Clear cut", 3, 5, Arrays.asList(4, 5, 6, 7, 8)), // case 9
   
   Arguments.of("Long result", 2, 8, Arrays.asList(3, 4, 5, 6, 7, 8, 9, 10)) // 
case 9
   ```
   
   And I recommend adding tests for the missing cases:
   ```
   Arguments.of("case 7", 0, 12, Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 
11, 12)),
   
   Arguments.of("case 10", 5, 7, Arrays.asList(6, 7, 8, 9, 10, 11, 12)),
   
   Arguments.of("case 12", 12, 3, Collections.emptyList()),
   
   Arguments.of("case 13", 14, 4, Collections.emptyList())
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to