diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/ComparisonTestTest.java b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/ComparisonTestTest.java index 90006f4728..9ced180ff0 100644 --- a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/ComparisonTestTest.java +++ b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/ComparisonTestTest.java @@ -5,13 +5,14 @@ package org.opensearch.sql.correctness.tests; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.util.Arrays; -import java.util.List; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -51,14 +52,14 @@ public void testSuccess() { .thenReturn( new DBResult( "OpenSearch", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John"))))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John"))))); when(otherDbConnection.select(anyString())) .thenReturn( new DBResult( "Other DB", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John"))))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John"))))); TestReport expected = new TestReport(); expected.addTestCase(new SuccessTestCase(1, "SELECT * FROM accounts")); @@ -71,18 +72,20 @@ public void testFailureDueToInconsistency() { DBResult openSearchResult = new DBResult( "OpenSearch", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John")))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John")))); DBResult otherDbResult = new DBResult( - "Other DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("JOHN")))); + "Other DB", + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("JOHN")))); when(openSearchConnection.select(anyString())).thenReturn(openSearchResult); when(otherDbConnection.select(anyString())).thenReturn(otherDbResult); TestReport expected = new TestReport(); expected.addTestCase( new FailedTestCase( - 1, "SELECT * FROM accounts", Arrays.asList(openSearchResult, otherDbResult), "")); + 1, "SELECT * FROM accounts", asList(openSearchResult, otherDbResult), "")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); } @@ -98,16 +101,18 @@ public void testSuccessFinally() { DBResult openSearchResult = new DBResult( "OpenSearch", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John")))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John")))); DBResult otherDbResult = new DBResult( - "Other DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("JOHN")))); + "Other DB", + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("JOHN")))); DBResult anotherDbResult = new DBResult( "Another DB", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John")))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John")))); when(openSearchConnection.select(anyString())).thenReturn(openSearchResult); when(anotherDbConnection.select(anyString())).thenReturn(anotherDbResult); @@ -129,14 +134,18 @@ public void testFailureDueToEventualInconsistency() { DBResult openSearchResult = new DBResult( "OpenSearch", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John")))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John")))); DBResult otherDbResult = new DBResult( - "Other DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("JOHN")))); + "Other DB", + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("JOHN")))); DBResult anotherDbResult = new DBResult( - "ZZZ DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("Hank")))); + "ZZZ DB", + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("Hank")))); when(openSearchConnection.select(anyString())).thenReturn(openSearchResult); when(otherDbConnection.select(anyString())).thenReturn(otherDbResult); when(anotherDbConnection.select(anyString())).thenReturn(anotherDbResult); @@ -146,7 +155,7 @@ public void testFailureDueToEventualInconsistency() { new FailedTestCase( 1, "SELECT * FROM accounts", - Arrays.asList(openSearchResult, otherDbResult, anotherDbResult), + asList(openSearchResult, otherDbResult, anotherDbResult), "")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); @@ -170,8 +179,8 @@ public void testErrorDueToNoOtherDBSupportThisQuery() { .thenReturn( new DBResult( "OpenSearch", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John"))))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John"))))); when(otherDbConnection.select(anyString())) .thenThrow(new RuntimeException("Unsupported feature")); @@ -197,14 +206,14 @@ public void testSuccessWhenOneDBSupportThisQuery() { .thenReturn( new DBResult( "OpenSearch", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John"))))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John"))))); when(anotherDbConnection.select(anyString())) .thenReturn( new DBResult( "Another DB", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John"))))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John"))))); TestReport expected = new TestReport(); expected.addTestCase(new SuccessTestCase(1, "SELECT * FROM accounts")); @@ -223,9 +232,10 @@ public void testFailureDueToInconsistencyAndExceptionMixed() { DBResult openSearchResult = new DBResult( "OpenSearch", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John")))); - DBResult otherResult = new DBResult("Other", List.of(new Type("firstname", "text")), List.of()); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John")))); + DBResult otherResult = + new DBResult("Other", singletonList(new Type("firstname", "text")), emptyList()); when(openSearchConnection.select(anyString())).thenReturn(openSearchResult); when(otherDbConnection.select(anyString())).thenReturn(otherResult); @@ -237,7 +247,7 @@ public void testFailureDueToInconsistencyAndExceptionMixed() { new FailedTestCase( 1, "SELECT * FROM accounts", - Arrays.asList(openSearchResult, otherResult), + asList(openSearchResult, otherResult), "Unsupported feature;")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestReportTest.java b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestReportTest.java index 42b46a5086..435c9f0e1e 100644 --- a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestReportTest.java +++ b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestReportTest.java @@ -5,10 +5,10 @@ package org.opensearch.sql.correctness.tests; +import static java.util.Arrays.asList; +import static java.util.Collections.singleton; import static org.junit.Assert.fail; -import java.util.Arrays; -import java.util.List; import org.json.JSONObject; import org.junit.Test; import org.opensearch.sql.correctness.report.ErrorTestCase; @@ -56,15 +56,15 @@ public void testFailedReport() { new FailedTestCase( 1, "SELECT * FROM accounts", - Arrays.asList( + asList( new DBResult( "OpenSearch", - List.of(new Type("firstName", "text")), - List.of(new Row(List.of("hello")))), + singleton(new Type("firstName", "text")), + singleton(new Row(singleton("hello")))), new DBResult( "H2", - List.of(new Type("firstName", "text")), - List.of(new Row(List.of("world"))))), + singleton(new Type("firstName", "text")), + singleton(new Row(singleton("world"))))), "[SQLITE_ERROR] SQL error or missing database;")); JSONObject actual = new JSONObject(report); JSONObject expected = diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/executor/format/BindingTupleResultSetTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/executor/format/BindingTupleResultSetTest.java index 3c0cc4fdaa..8216a5fdbb 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/executor/format/BindingTupleResultSetTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/executor/format/BindingTupleResultSetTest.java @@ -13,7 +13,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import java.util.Arrays; import java.util.List; import java.util.Map; import org.hamcrest.Matcher; @@ -30,10 +29,10 @@ public class BindingTupleResultSetTest { public void buildDataRowsFromBindingTupleShouldPass() { assertThat( row( - Arrays.asList( + List.of( ColumnNode.builder().name("age").type(Schema.Type.INTEGER).build(), ColumnNode.builder().name("gender").type(Schema.Type.TEXT).build()), - Arrays.asList( + List.of( BindingTuple.from(ImmutableMap.of("age", 31, "gender", "m")), BindingTuple.from(ImmutableMap.of("age", 31, "gender", "f")), BindingTuple.from(ImmutableMap.of("age", 39, "gender", "m")), @@ -49,10 +48,10 @@ public void buildDataRowsFromBindingTupleShouldPass() { public void buildDataRowsFromBindingTupleIncludeLongValueShouldPass() { assertThat( row( - Arrays.asList( + List.of( ColumnNode.builder().name("longValue").type(Schema.Type.LONG).build(), ColumnNode.builder().name("gender").type(Schema.Type.TEXT).build()), - Arrays.asList( + List.of( BindingTuple.from(ImmutableMap.of("longValue", Long.MAX_VALUE, "gender", "m")), BindingTuple.from(ImmutableMap.of("longValue", Long.MIN_VALUE, "gender", "f")))), containsInAnyOrder( @@ -66,7 +65,7 @@ public void buildDataRowsFromBindingTupleIncludeLongValueShouldPass() { public void buildDataRowsFromBindingTupleIncludeDateShouldPass() { assertThat( row( - Arrays.asList( + List.of( ColumnNode.builder().alias("dateValue").type(Schema.Type.DATE).build(), ColumnNode.builder().alias("gender").type(Schema.Type.TEXT).build()), List.of(