asolimando commented on a change in pull request #139:
URL: https://github.com/apache/calcite-avatica/pull/139#discussion_r580491936



##########
File path: 
core/src/test/java/org/apache/calcite/avatica/util/AbstractCursorTest.java
##########
@@ -0,0 +1,106 @@
+/*
+ * 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.calcite.avatica.util;
+
+import org.apache.calcite.avatica.ColumnMetaData;
+
+import org.junit.Test;
+
+import java.sql.Types;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.function.BiFunction;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test class for verifying functionality in abstract cursors.
+ */
+public class AbstractCursorTest {
+
+  private static final double DELTA = 1e-15;
+
+  @Test
+  public void resultSetFromIntegerArray() throws Exception {
+    BiFunction<Object, Object, Void> validator = (Object o1, Object o2) -> {
+      assertEquals((int) o1, (int) o2);
+      return null;
+    };
+
+    ColumnMetaData.ScalarType intType =
+        ColumnMetaData.scalar(Types.INTEGER, "INTEGER", 
ColumnMetaData.Rep.INTEGER);
+
+    List<List<Object>> rowsValues = Arrays.asList(Arrays.asList(1, 2),
+        Collections.singletonList(3), Arrays.asList(4, 5, 6));
+
+    UtilTestCommon.assertResultSetFromArray(intType, rowsValues, validator, 
false);

Review comment:
       I have tried to split it along different subcomponents, now the 
signature is as follow:
   ```
   static void assertRowsValuesMatchCursorContentViaArrayAccessor(
         List<List<Object>> rowsValues, ColumnMetaData.ScalarType 
arrayContentMetadata,
         Cursor cursorOverArray, ColumnMetaData arrayMetaData, 
ArrayImpl.Factory factory,
         Validator validator) throws Exception
   ```
   
   In a nut-shell, the method check that a collection of values (`rowsValues`) 
matches the values retrieved by a cursor via the array accessor (the input 
values are a List<List>, which should match the row<array> the cursor exposes).
   
   What "matches" means is defined via the input `Validator` (I moved away from 
the generic interface to adopt a per-test one, as suggested).
   
   The method signature is still a bit long unfortunately, but the metadata and 
factory are needed to properly instantiate the accessor. Moving the accessor as 
parameter would remove 2 parameters and add 1, and to me it makes sense to 
delegate the accessor creation to the method.




----------------------------------------------------------------
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.

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


Reply via email to