diff --git a/src/main/java/com/exasol/adapter/sql/SqlUtils.java b/src/main/java/com/exasol/adapter/sql/SqlUtils.java index 5f37a495..f487cdd4 100644 --- a/src/main/java/com/exasol/adapter/sql/SqlUtils.java +++ b/src/main/java/com/exasol/adapter/sql/SqlUtils.java @@ -3,11 +3,13 @@ import java.util.Map; public final class SqlUtils { - private SqlUtils(){ + private SqlUtils() { //Intentionally left blank } - public static String quoteIdentifierIfNeeded(final String identifier, final Map config) { + @SuppressWarnings("squid:S1157") + public static String quoteIdentifierIfNeeded(final String identifier, + final Map config) { String quoteChar = "\""; if (config.containsKey("QUOTE_CHAR")) { quoteChar = config.get("QUOTE_CHAR").toString(); diff --git a/src/test/java/com/exasol/adapter/sql/SqlPredicateEqualTest.java b/src/test/java/com/exasol/adapter/sql/SqlPredicateEqualTest.java new file mode 100644 index 00000000..bda7584c --- /dev/null +++ b/src/test/java/com/exasol/adapter/sql/SqlPredicateEqualTest.java @@ -0,0 +1,51 @@ +package com.exasol.adapter.sql; + +import com.exasol.adapter.AdapterException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class SqlPredicateEqualTest { + private SqlPredicateEqual sqlPredicateEqual; + private SqlLiteralDouble sqlLiteralDoubleLeft; + private SqlLiteralDouble sqlLiteralDoubleRight; + + @BeforeEach + void setUp() { + this.sqlLiteralDoubleLeft = new SqlLiteralDouble(20.5); + this.sqlLiteralDoubleRight = new SqlLiteralDouble(20.5); + this.sqlPredicateEqual = + new SqlPredicateEqual(this.sqlLiteralDoubleLeft, this.sqlLiteralDoubleRight); + } + + @Test + void testToSimpleSql() { + assertThat(this.sqlPredicateEqual.toSimpleSql(), equalTo("20.5 = 20.5")); + } + + @Test + void testGetType() { + assertThat(this.sqlPredicateEqual.getType(), equalTo(SqlNodeType.PREDICATE_EQUAL)); + } + + @Test + void testAccept() throws AdapterException { + final SqlNodeVisitor visitor = mock(SqlNodeVisitor.class); + when(visitor.visit(this.sqlPredicateEqual)).thenReturn(this.sqlPredicateEqual); + assertThat(this.sqlPredicateEqual.accept(visitor), equalTo(this.sqlPredicateEqual)); + } + + @Test + void testGetLeft() { + assertThat(this.sqlPredicateEqual.getLeft(), equalTo(this.sqlLiteralDoubleLeft)); + } + + @Test + void testGetRight() { + assertThat(this.sqlPredicateEqual.getRight(), equalTo(this.sqlLiteralDoubleRight)); + } +} \ No newline at end of file diff --git a/src/test/java/com/exasol/adapter/sql/SqlPredicateLessEqualTest.java b/src/test/java/com/exasol/adapter/sql/SqlPredicateLessEqualTest.java new file mode 100644 index 00000000..21ba67b8 --- /dev/null +++ b/src/test/java/com/exasol/adapter/sql/SqlPredicateLessEqualTest.java @@ -0,0 +1,52 @@ +package com.exasol.adapter.sql; + +import com.exasol.adapter.AdapterException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class SqlPredicateLessEqualTest { + private SqlPredicateLessEqual sqlPredicateLessEqual; + private SqlLiteralDouble sqlLiteralDoubleLeft; + private SqlLiteralDouble sqlLiteralDoubleRight; + + @BeforeEach + void setUp() { + this.sqlLiteralDoubleLeft = new SqlLiteralDouble(20.5); + this.sqlLiteralDoubleRight = new SqlLiteralDouble(21.5); + this.sqlPredicateLessEqual = + new SqlPredicateLessEqual(this.sqlLiteralDoubleLeft, this.sqlLiteralDoubleRight); + } + + @Test + void testToSimpleSql() { + assertThat(this.sqlPredicateLessEqual.toSimpleSql(), equalTo("20.5 <= 21.5")); + } + + @Test + void testGetType() { + assertThat(this.sqlPredicateLessEqual.getType(), equalTo(SqlNodeType.PREDICATE_LESSEQUAL)); + } + + @Test + void testAccept() throws AdapterException { + final SqlNodeVisitor visitor = mock(SqlNodeVisitor.class); + when(visitor.visit(this.sqlPredicateLessEqual)).thenReturn(this.sqlPredicateLessEqual); + assertThat(this.sqlPredicateLessEqual.accept(visitor), equalTo(this.sqlPredicateLessEqual)); + } + + @Test + void testGetLeft() { + assertThat(this.sqlPredicateLessEqual.getLeft(), equalTo(this.sqlLiteralDoubleLeft)); + } + + @Test + void testGetRight() { + assertThat(this.sqlPredicateLessEqual.getRight(), equalTo(this.sqlLiteralDoubleRight)); + } + +} \ No newline at end of file diff --git a/src/test/java/com/exasol/adapter/sql/SqlPredicateLessTest.java b/src/test/java/com/exasol/adapter/sql/SqlPredicateLessTest.java new file mode 100644 index 00000000..2c413c06 --- /dev/null +++ b/src/test/java/com/exasol/adapter/sql/SqlPredicateLessTest.java @@ -0,0 +1,51 @@ +package com.exasol.adapter.sql; + +import com.exasol.adapter.AdapterException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class SqlPredicateLessTest { + private SqlPredicateLess sqlPredicateLess; + private SqlLiteralDouble sqlLiteralDoubleLeft; + private SqlLiteralDouble sqlLiteralDoubleRight; + + @BeforeEach + void setUp() { + this.sqlLiteralDoubleLeft = new SqlLiteralDouble(20.5); + this.sqlLiteralDoubleRight = new SqlLiteralDouble(21.5); + this.sqlPredicateLess = + new SqlPredicateLess(this.sqlLiteralDoubleLeft, this.sqlLiteralDoubleRight); + } + + @Test + void testToSimpleSql() { + assertThat(this.sqlPredicateLess.toSimpleSql(), equalTo("20.5 < 21.5")); + } + + @Test + void testGetType() { + assertThat(this.sqlPredicateLess.getType(), equalTo(SqlNodeType.PREDICATE_LESS)); + } + + @Test + void testAccept() throws AdapterException { + final SqlNodeVisitor visitor = mock(SqlNodeVisitor.class); + when(visitor.visit(this.sqlPredicateLess)).thenReturn(this.sqlPredicateLess); + assertThat(this.sqlPredicateLess.accept(visitor), equalTo(this.sqlPredicateLess)); + } + + @Test + void testGetLeft() { + assertThat(this.sqlPredicateLess.getLeft(), equalTo(this.sqlLiteralDoubleLeft)); + } + + @Test + void testGetRight() { + assertThat(this.sqlPredicateLess.getRight(), equalTo(this.sqlLiteralDoubleRight)); + } +} \ No newline at end of file diff --git a/src/test/java/com/exasol/adapter/sql/SqlPredicateNotEqualTest.java b/src/test/java/com/exasol/adapter/sql/SqlPredicateNotEqualTest.java new file mode 100644 index 00000000..bc41149c --- /dev/null +++ b/src/test/java/com/exasol/adapter/sql/SqlPredicateNotEqualTest.java @@ -0,0 +1,51 @@ +package com.exasol.adapter.sql; + +import com.exasol.adapter.AdapterException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class SqlPredicateNotEqualTest { + private SqlPredicateNotEqual sqlPredicateNotEqual; + private SqlLiteralDouble sqlLiteralDoubleLeft; + private SqlLiteralDouble sqlLiteralDoubleRight; + + @BeforeEach + void setUp() { + this.sqlLiteralDoubleLeft = new SqlLiteralDouble(21.5); + this.sqlLiteralDoubleRight = new SqlLiteralDouble(20.5); + this.sqlPredicateNotEqual = + new SqlPredicateNotEqual(this.sqlLiteralDoubleLeft, this.sqlLiteralDoubleRight); + } + + @Test + void testToSimpleSql() { + assertThat(this.sqlPredicateNotEqual.toSimpleSql(), equalTo("21.5 != 20.5")); + } + + @Test + void testGetType() { + assertThat(this.sqlPredicateNotEqual.getType(), equalTo(SqlNodeType.PREDICATE_NOTEQUAL)); + } + + @Test + void testAccept() throws AdapterException { + final SqlNodeVisitor visitor = mock(SqlNodeVisitor.class); + when(visitor.visit(this.sqlPredicateNotEqual)).thenReturn(this.sqlPredicateNotEqual); + assertThat(this.sqlPredicateNotEqual.accept(visitor), equalTo(this.sqlPredicateNotEqual)); + } + + @Test + void testGetLeft() { + assertThat(this.sqlPredicateNotEqual.getLeft(), equalTo(this.sqlLiteralDoubleLeft)); + } + + @Test + void testGetRight() { + assertThat(this.sqlPredicateNotEqual.getRight(), equalTo(this.sqlLiteralDoubleRight)); + } +} \ No newline at end of file