Skip to content

Commit

Permalink
#15: prepared tests for classes with duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiiaSergienko committed Feb 13, 2019
1 parent 3fab9d5 commit 17ff20b
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/exasol/adapter/sql/SqlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, ?> config) {
@SuppressWarnings("squid:S1157")
public static String quoteIdentifierIfNeeded(final String identifier,
final Map<String, ?> config) {
String quoteChar = "\"";
if (config.containsKey("QUOTE_CHAR")) {
quoteChar = config.get("QUOTE_CHAR").toString();
Expand Down
51 changes: 51 additions & 0 deletions src/test/java/com/exasol/adapter/sql/SqlPredicateEqualTest.java
Original file line number Diff line number Diff line change
@@ -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<SqlPredicateEqual> 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));
}
}
Original file line number Diff line number Diff line change
@@ -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<SqlPredicateLessEqual> 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));
}

}
51 changes: 51 additions & 0 deletions src/test/java/com/exasol/adapter/sql/SqlPredicateLessTest.java
Original file line number Diff line number Diff line change
@@ -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<SqlPredicateLess> 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));
}
}
51 changes: 51 additions & 0 deletions src/test/java/com/exasol/adapter/sql/SqlPredicateNotEqualTest.java
Original file line number Diff line number Diff line change
@@ -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<SqlPredicateNotEqual> 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));
}
}

0 comments on commit 17ff20b

Please sign in to comment.