diff --git a/src/test/java/cz/voho/jdbcis/operation/InsertQueriesTest.java b/src/test/java/cz/voho/jdbcis/operation/InsertQueriesTest.java index 5d141c1..3d18465 100644 --- a/src/test/java/cz/voho/jdbcis/operation/InsertQueriesTest.java +++ b/src/test/java/cz/voho/jdbcis/operation/InsertQueriesTest.java @@ -44,7 +44,6 @@ public void testInsertSingleRowAndGetKeyUsingPreparedStatement() throws Exceptio assertThat(actual).isGreaterThan(1); } - @Test public void testInsertSingleRowAndGetKeyUsingRawValues() throws Exception { final Long actual = toTest().insertSingleAndGetFirstLongKey("INSERT INTO t (c_text) VALUES ('testInsertSingleRowAndGetKeyUsingRawValues')"); diff --git a/src/test/java/cz/voho/jdbcis/operation/ListQueriesTest.java b/src/test/java/cz/voho/jdbcis/operation/ListQueriesTest.java index ca12145..5e2f4a3 100644 --- a/src/test/java/cz/voho/jdbcis/operation/ListQueriesTest.java +++ b/src/test/java/cz/voho/jdbcis/operation/ListQueriesTest.java @@ -15,13 +15,13 @@ public class ListQueriesTest extends AbstractOperationTest { @Test public void queryForListUsingPreparedStatement() throws Exception { final List list = toTest().queryForList( - "SELECT * FROM t WHERE c_text LIKE ?", + "SELECT c_pk,c_decimal,c_date,c_timestamp,c_double,c_integer,c_bigint,c_varchar,c_text,c_time FROM t WHERE c_text LIKE ?", preparedStatement -> DataType.STRING.setNullableToPreparedStatement(preparedStatement, 1, "Predefined-%"), TestRow.ROW_MAPPER ); assertThat(list) - .extracting(TestRow::getcString) + .extracting(TestRow::getcLongString) .contains( "Predefined-1", "Predefined-2", @@ -34,12 +34,12 @@ public void queryForListUsingPreparedStatement() throws Exception { @Test public void queryForListUsingRawValues() throws Exception { final List list = toTest().queryForList( - "SELECT * FROM t WHERE c_text LIKE 'Predefined-%'", + "SELECT c_pk,c_decimal,c_date,c_timestamp,c_double,c_integer,c_bigint,c_varchar,c_text,c_time FROM t WHERE c_text LIKE 'Predefined-%'", TestRow.ROW_MAPPER ); assertThat(list) - .extracting(TestRow::getcString) + .extracting(TestRow::getcLongString) .contains( "Predefined-1", "Predefined-2", diff --git a/src/test/java/cz/voho/jdbcis/operation/SingleQueriesTest.java b/src/test/java/cz/voho/jdbcis/operation/SingleQueriesTest.java index 726b530..0c34b70 100644 --- a/src/test/java/cz/voho/jdbcis/operation/SingleQueriesTest.java +++ b/src/test/java/cz/voho/jdbcis/operation/SingleQueriesTest.java @@ -12,21 +12,20 @@ public class SingleQueriesTest extends AbstractOperationTest { @Test public void queryForSingleRowUsingPreparedStatement() throws Exception { - TestRow row = toTest().queryForSingle( - "SELECT * FROM t WHERE c_pk = ?", + final TestRow row = toTest().queryForSingle( + "SELECT c_pk,c_decimal,c_date,c_timestamp,c_double,c_integer,c_bigint,c_varchar,c_text,c_time FROM t WHERE c_pk = ?", preparedStatement -> DataType.LONG.setNullableToPreparedStatement(preparedStatement, 1, 1L), TestRow.ROW_MAPPER); - assertThat(row.getcString()).isEqualTo("Predefined-1"); + assertThat(row.getcLongString()).isEqualTo("Predefined-1"); } - @Test public void queryForSingleRowUsingRawValues() throws Exception { - TestRow row = toTest().queryForSingle( - "SELECT * FROM t WHERE c_pk = 1", + final TestRow row = toTest().queryForSingle( + "SELECT c_pk,c_decimal,c_date,c_timestamp,c_double,c_integer,c_bigint,c_varchar,c_text,c_time FROM t WHERE c_pk = 1", TestRow.ROW_MAPPER); - assertThat(row.getcString()).isEqualTo("Predefined-1"); + assertThat(row.getcLongString()).isEqualTo("Predefined-1"); } } \ No newline at end of file diff --git a/src/test/java/cz/voho/jdbcis/operation/UpdateQueriesTest.java b/src/test/java/cz/voho/jdbcis/operation/UpdateQueriesTest.java index a6f154e..3768a40 100644 --- a/src/test/java/cz/voho/jdbcis/operation/UpdateQueriesTest.java +++ b/src/test/java/cz/voho/jdbcis/operation/UpdateQueriesTest.java @@ -11,7 +11,7 @@ public class UpdateQueriesTest extends AbstractOperationTest { @Test public void updateSingleRowUsingPreparedStatement() throws Exception { - long actual = toTest().update("UPDATE t SET c_text = ?", preparedStatement -> { + final long actual = toTest().update("UPDATE t SET c_text = ?", preparedStatement -> { DataType.STRING.setNullableToPreparedStatement(preparedStatement, 1, "updateSingleRowUsingPreparedStatement"); }); @@ -20,7 +20,7 @@ public void updateSingleRowUsingPreparedStatement() throws Exception { @Test public void updateSingleRowUsingRawValues() throws Exception { - long actual = toTest().update("UPDATE t SET c_text = 'updateSingleRowUsingRawValues'"); + final long actual = toTest().update("UPDATE t SET c_text = 'updateSingleRowUsingRawValues'"); assertThat(actual).isEqualTo(5L); } diff --git a/src/test/java/cz/voho/jdbcis/operation/model/TestRow.java b/src/test/java/cz/voho/jdbcis/operation/model/TestRow.java index bfd215a..9113039 100644 --- a/src/test/java/cz/voho/jdbcis/operation/model/TestRow.java +++ b/src/test/java/cz/voho/jdbcis/operation/model/TestRow.java @@ -8,39 +8,68 @@ import java.time.LocalDateTime; import java.time.LocalTime; +import static org.assertj.core.api.Assertions.assertThat; + /** * Test model object. */ public class TestRow { public static RowMapper ROW_MAPPER = resultSet -> { TestRow row = new TestRow(); + // primary key - row.setcLong(DataType.LONG.getNullableFromResultSet(resultSet, "c_pk")); + row.setcPK(DataType.LONG.getNullableFromResultSet(resultSet, "c_pk")); // other columns + row.setcBigDecimal(DataType.BIG_DECIMAL.getNullableFromResultSet(resultSet, "c_decimal")); row.setcLocalDate(DataType.DATE.getNullableFromResultSet(resultSet, "c_date")); row.setcLocalDateTime(DataType.DATE_TIME.getNullableFromResultSet(resultSet, "c_timestamp")); row.setcDouble(DataType.DOUBLE.getNullableFromResultSet(resultSet, "c_double")); row.setcInteger(DataType.INTEGER.getNullableFromResultSet(resultSet, "c_integer")); row.setcLong(DataType.LONG.getNullableFromResultSet(resultSet, "c_bigint")); - row.setcString(DataType.STRING.getNullableFromResultSet(resultSet, "c_text")); + row.setcShortString(DataType.STRING.getNullableFromResultSet(resultSet, "c_varchar")); + row.setcLongString(DataType.STRING.getNullableFromResultSet(resultSet, "c_text")); row.setcLocalTime(DataType.TIME.getNullableFromResultSet(resultSet, "c_time")); + + // primary key + assertThat(DataType.LONG.getNullableFromResultSet(resultSet, 1)).isEqualTo(row.getcPK()); + // other columns + assertThat(DataType.BIG_DECIMAL.getNullableFromResultSet(resultSet, 2)).isEqualTo(row.getcBigDecimal()); + assertThat(DataType.DATE.getNullableFromResultSet(resultSet, 3)).isEqualTo(row.getcLocalDate()); + assertThat(DataType.DATE_TIME.getNullableFromResultSet(resultSet, 4)).isEqualTo(row.getcLocalDateTime()); + assertThat(DataType.DOUBLE.getNullableFromResultSet(resultSet, 5)).isEqualTo(row.getcDouble()); + assertThat(DataType.INTEGER.getNullableFromResultSet(resultSet, 6)).isEqualTo(row.getcInteger()); + assertThat(DataType.LONG.getNullableFromResultSet(resultSet, 7)).isEqualTo(row.getcLong()); + assertThat(DataType.STRING.getNullableFromResultSet(resultSet, 8)).isEqualTo(row.getcShortString()); + assertThat(DataType.STRING.getNullableFromResultSet(resultSet, 9)).isEqualTo(row.getcLongString()); + assertThat(DataType.TIME.getNullableFromResultSet(resultSet, 10)).isEqualTo(row.getcLocalTime()); + return row; }; + private Long cPK; private BigDecimal cBigDecimal; private LocalDate cLocalDate; private LocalDateTime cLocalDateTime; private Double cDouble; private Integer cInteger; private Long cLong; - private String cString; + private String cShortString; + private String cLongString; private LocalTime cLocalTime; + public Long getcPK() { + return cPK; + } + + public void setcPK(final Long cPK) { + this.cPK = cPK; + } + public BigDecimal getcBigDecimal() { return cBigDecimal; } - public void setcBigDecimal(BigDecimal cBigDecimal) { + public void setcBigDecimal(final BigDecimal cBigDecimal) { this.cBigDecimal = cBigDecimal; } @@ -48,7 +77,7 @@ public LocalDate getcLocalDate() { return cLocalDate; } - public void setcLocalDate(LocalDate cLocalDate) { + public void setcLocalDate(final LocalDate cLocalDate) { this.cLocalDate = cLocalDate; } @@ -56,7 +85,7 @@ public LocalDateTime getcLocalDateTime() { return cLocalDateTime; } - public void setcLocalDateTime(LocalDateTime cLocalDateTime) { + public void setcLocalDateTime(final LocalDateTime cLocalDateTime) { this.cLocalDateTime = cLocalDateTime; } @@ -64,7 +93,7 @@ public Double getcDouble() { return cDouble; } - public void setcDouble(Double cDouble) { + public void setcDouble(final Double cDouble) { this.cDouble = cDouble; } @@ -72,7 +101,7 @@ public Integer getcInteger() { return cInteger; } - public void setcInteger(Integer cInteger) { + public void setcInteger(final Integer cInteger) { this.cInteger = cInteger; } @@ -80,23 +109,31 @@ public Long getcLong() { return cLong; } - public void setcLong(Long cLong) { + public void setcLong(final Long cLong) { this.cLong = cLong; } - public String getcString() { - return cString; + public String getcShortString() { + return cShortString; + } + + public void setcShortString(final String cShortString) { + this.cShortString = cShortString; + } + + public String getcLongString() { + return cLongString; } - public void setcString(String cString) { - this.cString = cString; + public void setcLongString(final String cLongString) { + this.cLongString = cLongString; } public LocalTime getcLocalTime() { return cLocalTime; } - public void setcLocalTime(LocalTime cLocalTime) { + public void setcLocalTime(final LocalTime cLocalTime) { this.cLocalTime = cLocalTime; } }