Skip to content

Commit d4c9c69

Browse files
committed
Removed usage of Junit4 asserts
1 parent 913e773 commit d4c9c69

File tree

1 file changed

+91
-94
lines changed

1 file changed

+91
-94
lines changed

jdbc/src/test/java/tech/ydb/jdbc/impl/YdbPreparedStatementTest.java

Lines changed: 91 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.time.temporal.ChronoField;
2020
import java.time.temporal.ChronoUnit;
2121

22-
import org.junit.Assert;
2322
import org.junit.jupiter.api.AfterAll;
2423
import org.junit.jupiter.api.Assertions;
2524
import org.junit.jupiter.api.BeforeAll;
@@ -37,8 +36,6 @@
3736
import tech.ydb.table.values.PrimitiveType;
3837
import tech.ydb.table.values.PrimitiveValue;
3938
import tech.ydb.table.values.StructValue;
40-
import static tech.ydb.table.values.Type.Kind.OPTIONAL;
41-
import static tech.ydb.table.values.Type.Kind.PRIMITIVE;
4239
import tech.ydb.table.values.Value;
4340
import tech.ydb.test.junit5.YdbHelperExtension;
4441

@@ -261,44 +258,44 @@ private void fillRowValues(PreparedStatement statement, int id) throws SQLExcept
261258
}
262259

263260
private void assertRowValues(ResultSet rs, int id) throws SQLException {
264-
Assert.assertTrue(rs.next());
261+
Assertions.assertTrue(rs.next());
265262

266-
Assert.assertEquals(id, rs.getInt("key"));
263+
Assertions.assertEquals(id, rs.getInt("key"));
267264

268-
Assert.assertEquals(id % 2 == 0, rs.getBoolean("c_Bool"));
265+
Assertions.assertEquals(id % 2 == 0, rs.getBoolean("c_Bool"));
269266

270-
Assert.assertEquals(id + 1, rs.getByte("c_Int8"));
271-
Assert.assertEquals(id + 2, rs.getShort("c_Int16"));
272-
Assert.assertEquals(id + 3, rs.getInt("c_Int32"));
273-
Assert.assertEquals(id + 4, rs.getLong("c_Int64"));
267+
Assertions.assertEquals(id + 1, rs.getByte("c_Int8"));
268+
Assertions.assertEquals(id + 2, rs.getShort("c_Int16"));
269+
Assertions.assertEquals(id + 3, rs.getInt("c_Int32"));
270+
Assertions.assertEquals(id + 4, rs.getLong("c_Int64"));
274271

275-
Assert.assertEquals(id + 5, rs.getByte("c_Uint8"));
276-
Assert.assertEquals(id + 6, rs.getShort("c_Uint16"));
277-
Assert.assertEquals(id + 7, rs.getInt("c_Uint32"));
278-
Assert.assertEquals(id + 8, rs.getLong("c_Uint64"));
272+
Assertions.assertEquals(id + 5, rs.getByte("c_Uint8"));
273+
Assertions.assertEquals(id + 6, rs.getShort("c_Uint16"));
274+
Assertions.assertEquals(id + 7, rs.getInt("c_Uint32"));
275+
Assertions.assertEquals(id + 8, rs.getLong("c_Uint64"));
279276

280-
Assert.assertEquals(1.5f * id, rs.getFloat("c_Float"), 0.001f);
281-
Assert.assertEquals(2.5d * id, rs.getDouble("c_Double"), 0.001d);
277+
Assertions.assertEquals(1.5f * id, rs.getFloat("c_Float"), 0.001f);
278+
Assertions.assertEquals(2.5d * id, rs.getDouble("c_Double"), 0.001d);
282279

283-
Assert.assertArrayEquals(new byte[] { (byte)id }, rs.getBytes("c_Bytes"));
284-
Assert.assertEquals("Text_" + id, rs.getString("c_Text"));
285-
Assert.assertEquals("{\"json\": " + id + "}", rs.getString("c_Json"));
286-
Assert.assertEquals("{\"jsonDoc\":" + id + "}", rs.getString("c_JsonDocument"));
287-
Assert.assertEquals("{yson=" + id + "}", rs.getString("c_Yson"));
280+
Assertions.assertArrayEquals(new byte[] { (byte)id }, rs.getBytes("c_Bytes"));
281+
Assertions.assertEquals("Text_" + id, rs.getString("c_Text"));
282+
Assertions.assertEquals("{\"json\": " + id + "}", rs.getString("c_Json"));
283+
Assertions.assertEquals("{\"jsonDoc\":" + id + "}", rs.getString("c_JsonDocument"));
284+
Assertions.assertEquals("{yson=" + id + "}", rs.getString("c_Yson"));
288285

289286

290287
Date sqlDate = new Date(TEST_TS.toEpochMilli());
291288
LocalDateTime dateTime = LocalDateTime.ofInstant(TEST_TS, ZoneOffset.UTC).plusMinutes(id)
292289
.truncatedTo(ChronoUnit.SECONDS);
293290
Timestamp timestamp = Timestamp.from(truncToMicros(TEST_TS.plusSeconds(id)));
294291

295-
Assert.assertEquals(sqlDate.toLocalDate(), rs.getDate("c_Date").toLocalDate());
296-
Assert.assertEquals(dateTime, rs.getObject("c_Datetime"));
297-
Assert.assertEquals(timestamp, rs.getTimestamp("c_Timestamp"));
298-
Assert.assertEquals(Duration.ofMinutes(id), rs.getObject("c_Interval"));
292+
Assertions.assertEquals(sqlDate.toLocalDate(), rs.getDate("c_Date").toLocalDate());
293+
Assertions.assertEquals(dateTime, rs.getObject("c_Datetime"));
294+
Assertions.assertEquals(timestamp, rs.getTimestamp("c_Timestamp"));
295+
Assertions.assertEquals(Duration.ofMinutes(id), rs.getObject("c_Interval"));
299296

300-
Assert.assertNull(rs.getString("c_Decimal"));
301-
Assert.assertTrue(rs.wasNull());
297+
Assertions.assertNull(rs.getString("c_Decimal"));
298+
Assertions.assertTrue(rs.wasNull());
302299
}
303300

304301
private void assertStructMember(PrimitiveValue value, StructValue sv, String name) {
@@ -323,7 +320,7 @@ private void assertStructMember(PrimitiveValue value, StructValue sv, String nam
323320
}
324321

325322
private void assertTableRow(ResultSet rs, int id) throws SQLException {
326-
Assert.assertTrue(rs.next());
323+
Assertions.assertTrue(rs.next());
327324

328325
Object obj = rs.getObject(1);
329326
Assertions.assertNotNull(obj);
@@ -407,7 +404,7 @@ public void batchUpsertAllTest(SqlQueries.JdbcQuery query) throws SQLException {
407404
assertRowValues(rs, 3);
408405
assertRowValues(rs, 6);
409406

410-
Assert.assertFalse(rs.next());
407+
Assertions.assertFalse(rs.next());
411408
}
412409
}
413410
};
@@ -429,7 +426,7 @@ public void tableRowTest() throws SQLException {
429426
try (ResultSet rs = statement.executeQuery(selectTableRow)) {
430427
assertTableRow(rs, 1);
431428
assertTableRow(rs, 2);
432-
Assert.assertFalse(rs.next());
429+
Assertions.assertFalse(rs.next());
433430
}
434431
}
435432
};
@@ -510,45 +507,45 @@ public void int32Test(SqlQueries.JdbcQuery query) throws SQLException {
510507
assertNextInt32(rs, 8, (int) TEST_TS.atZone(ZoneId.systemDefault()).toLocalDate().toEpochDay());
511508
assertNextInt32(rs, 9, (int) TEST_TS.toEpochMilli());
512509

513-
Assert.assertFalse(rs.next());
510+
Assertions.assertFalse(rs.next());
514511
}
515512
}
516513
};
517514

518515
private void assertNextInt32(ResultSet rs, int key, Integer value) throws SQLException {
519-
Assert.assertTrue(rs.next());
520-
Assert.assertEquals(key, rs.getInt("key"));
516+
Assertions.assertTrue(rs.next());
517+
Assertions.assertEquals(key, rs.getInt("key"));
521518

522519
Object obj = rs.getObject("c_Int32");
523-
Assert.assertTrue(obj instanceof Integer);
524-
Assert.assertEquals(value, obj);
520+
Assertions.assertTrue(obj instanceof Integer);
521+
Assertions.assertEquals(value, obj);
525522

526523
if (value.byteValue() == value.intValue()) {
527-
Assert.assertEquals(value.intValue(), rs.getByte("c_Int32"));
524+
Assertions.assertEquals(value.intValue(), rs.getByte("c_Int32"));
528525
} else {
529526
String msg = String.format("Cannot cast [Int32] with value [%s] to [byte]", value);
530527
ExceptionAssert.sqlException(msg, () -> rs.getByte("c_Int32"));
531528
}
532529

533530
if (value.shortValue() == value.intValue()) {
534-
Assert.assertEquals(value.intValue(), rs.getShort("c_Int32"));
531+
Assertions.assertEquals(value.intValue(), rs.getShort("c_Int32"));
535532
} else {
536533
String msg = String.format("Cannot cast [Int32] with value [%s] to [short]", value);
537534
ExceptionAssert.sqlException(msg, () -> rs.getShort("c_Int32"));
538535
}
539536

540-
Assert.assertEquals(value.intValue(), rs.getInt("c_Int32"));
541-
Assert.assertEquals(value.longValue(), rs.getLong("c_Int32"));
537+
Assertions.assertEquals(value.intValue(), rs.getInt("c_Int32"));
538+
Assertions.assertEquals(value.longValue(), rs.getLong("c_Int32"));
542539

543540
if (value >= 0 && value < 24 * 3600) {
544-
Assert.assertEquals(Time.valueOf(LocalTime.ofSecondOfDay(value)), rs.getTime("c_Int32"));
541+
Assertions.assertEquals(Time.valueOf(LocalTime.ofSecondOfDay(value)), rs.getTime("c_Int32"));
545542
} else {
546543
String msg = String.format("Cannot cast [Int32] with value [%s] to [class java.sql.Time]", value);
547544
ExceptionAssert.sqlException(msg, () -> rs.getTime("c_Int32"));
548545
}
549546

550-
Assert.assertEquals(Date.valueOf(LocalDate.ofEpochDay(value)), rs.getDate("c_Int32"));
551-
Assert.assertEquals(new Timestamp(value), rs.getTimestamp("c_Int32"));
547+
Assertions.assertEquals(Date.valueOf(LocalDate.ofEpochDay(value)), rs.getDate("c_Int32"));
548+
Assertions.assertEquals(new Timestamp(value), rs.getTimestamp("c_Int32"));
552549
}
553550

554551
@ParameterizedTest(name = "with {0}")
@@ -632,57 +629,57 @@ public void int64Test(SqlQueries.JdbcQuery query) throws SQLException {
632629
assertNextInt64(rs, 9, TEST_TS.atZone(ZoneId.systemDefault()).toLocalDate().toEpochDay());
633630
assertNextInt64(rs, 10, TEST_TS.toEpochMilli());
634631

635-
Assert.assertFalse(rs.next());
632+
Assertions.assertFalse(rs.next());
636633
}
637634
}
638635
};
639636

640637
private void assertNextInt64(ResultSet rs, int key, Long value) throws SQLException {
641-
Assert.assertTrue(rs.next());
642-
Assert.assertEquals(key, rs.getInt("key"));
638+
Assertions.assertTrue(rs.next());
639+
Assertions.assertEquals(key, rs.getInt("key"));
643640

644641
Object obj = rs.getObject("c_Int64");
645-
Assert.assertTrue(obj instanceof Long);
646-
Assert.assertEquals(value, obj);
642+
Assertions.assertTrue(obj instanceof Long);
643+
Assertions.assertEquals(value, obj);
647644

648645
if (value.byteValue() == value.intValue()) {
649-
Assert.assertEquals(value.intValue(), rs.getByte("c_Int64"));
646+
Assertions.assertEquals(value.intValue(), rs.getByte("c_Int64"));
650647
} else {
651648
String msg = String.format("Cannot cast [Int64] with value [%s] to [byte]", value);
652649
ExceptionAssert.sqlException(msg, () -> rs.getByte("c_Int64"));
653650
}
654651

655652
if (value.shortValue() == value.intValue()) {
656-
Assert.assertEquals(value.intValue(), rs.getShort("c_Int64"));
653+
Assertions.assertEquals(value.intValue(), rs.getShort("c_Int64"));
657654
} else {
658655
String msg = String.format("Cannot cast [Int64] with value [%s] to [short]", value);
659656
ExceptionAssert.sqlException(msg, () -> rs.getShort("c_Int64"));
660657
}
661658

662659
if (value.intValue() == value.longValue()) {
663-
Assert.assertEquals(value.intValue(), rs.getInt("c_Int64"));
660+
Assertions.assertEquals(value.intValue(), rs.getInt("c_Int64"));
664661
} else {
665662
String msg = String.format("Cannot cast [Int64] with value [%s] to [int]", value);
666663
ExceptionAssert.sqlException(msg, () -> rs.getInt("c_Int64"));
667664
}
668665

669-
Assert.assertEquals(value.longValue(), rs.getLong("c_Int64"));
666+
Assertions.assertEquals(value.longValue(), rs.getLong("c_Int64"));
670667

671668
if (value >= 0 && value < 24 * 3600) {
672-
Assert.assertEquals(Time.valueOf(LocalTime.ofSecondOfDay(value)), rs.getTime("c_Int64"));
669+
Assertions.assertEquals(Time.valueOf(LocalTime.ofSecondOfDay(value)), rs.getTime("c_Int64"));
673670
} else {
674671
String msg = String.format("Cannot cast [Int64] with value [%s] to [class java.sql.Time]", value);
675672
ExceptionAssert.sqlException(msg, () -> rs.getTime("c_Int64"));
676673
}
677674

678675
if (ChronoField.EPOCH_DAY.range().isValidValue(value)) {
679-
Assert.assertEquals(Date.valueOf(LocalDate.ofEpochDay(value)), rs.getDate("c_Int64"));
676+
Assertions.assertEquals(Date.valueOf(LocalDate.ofEpochDay(value)), rs.getDate("c_Int64"));
680677
} else {
681678
String msg = String.format("Cannot cast [Int64] with value [%s] to [class java.sql.Date]", value);
682679
ExceptionAssert.sqlException(msg, () -> rs.getDate("c_Int64"));
683680
}
684681

685-
Assert.assertEquals(new Timestamp(value), rs.getTimestamp("c_Int64"));
682+
Assertions.assertEquals(new Timestamp(value), rs.getTimestamp("c_Int64"));
686683
}
687684

688685
@ParameterizedTest(name = "with {0}")
@@ -742,30 +739,30 @@ public void timestampTest(SqlQueries.JdbcQuery query) throws SQLException {
742739
assertNextTimestamp(rs, 6, Instant.ofEpochMilli(1585932011123l));
743740
assertNextTimestamp(rs, 7, Instant.parse("2011-12-03T10:15:30.456789000Z"));
744741

745-
Assert.assertFalse(rs.next());
742+
Assertions.assertFalse(rs.next());
746743
}
747744
}
748745
};
749746

750747
private void assertNextTimestamp(ResultSet rs, int key, Instant ts) throws SQLException {
751-
Assert.assertTrue(rs.next());
752-
Assert.assertEquals(key, rs.getInt("key"));
748+
Assertions.assertTrue(rs.next());
749+
Assertions.assertEquals(key, rs.getInt("key"));
753750

754751
Object obj = rs.getObject("c_Timestamp");
755-
Assert.assertTrue(obj instanceof Instant);
756-
Assert.assertEquals(ts, obj);
752+
Assertions.assertTrue(obj instanceof Instant);
753+
Assertions.assertEquals(ts, obj);
757754

758-
Assert.assertEquals(ts.toEpochMilli(), rs.getLong("c_Timestamp"));
755+
Assertions.assertEquals(ts.toEpochMilli(), rs.getLong("c_Timestamp"));
759756

760-
Assert.assertEquals(new Date(ts.toEpochMilli()), rs.getDate("c_Timestamp"));
761-
Assert.assertEquals(Timestamp.from(ts), rs.getTimestamp("c_Timestamp"));
762-
Assert.assertEquals(ts.toString(), rs.getString("c_Timestamp"));
757+
Assertions.assertEquals(new Date(ts.toEpochMilli()), rs.getDate("c_Timestamp"));
758+
Assertions.assertEquals(Timestamp.from(ts), rs.getTimestamp("c_Timestamp"));
759+
Assertions.assertEquals(ts.toString(), rs.getString("c_Timestamp"));
763760

764761
LocalDateTime ldt = LocalDateTime.ofInstant(ts, ZoneId.systemDefault());
765-
Assert.assertEquals(Long.valueOf(ts.toEpochMilli()), rs.getObject("c_Timestamp", Long.class));
766-
Assert.assertEquals(ldt.toLocalDate(), rs.getObject("c_Timestamp", LocalDate.class));
767-
Assert.assertEquals(ldt, rs.getObject("c_Timestamp", LocalDateTime.class));
768-
Assert.assertEquals(ts, rs.getObject("c_Timestamp", Instant.class));
762+
Assertions.assertEquals(Long.valueOf(ts.toEpochMilli()), rs.getObject("c_Timestamp", Long.class));
763+
Assertions.assertEquals(ldt.toLocalDate(), rs.getObject("c_Timestamp", LocalDate.class));
764+
Assertions.assertEquals(ldt, rs.getObject("c_Timestamp", LocalDateTime.class));
765+
Assertions.assertEquals(ts, rs.getObject("c_Timestamp", Instant.class));
769766
}
770767

771768
@ParameterizedTest(name = "with {0}")
@@ -837,29 +834,29 @@ public void datetimeTest(SqlQueries.JdbcQuery query) throws SQLException {
837834
assertNextDatetime(rs, 5, LocalDateTime.of(2021, Month.JULY, 21, 0, 0, 0));
838835
assertNextDatetime(rs, 6, LocalDateTime.of(2011, Month.DECEMBER, 3, 10, 15, 30));
839836
assertNextDatetime(rs, 7, ts);
840-
Assert.assertFalse(rs.next());
837+
Assertions.assertFalse(rs.next());
841838
}
842839
}
843840
};
844841

845842
private void assertNextDatetime(ResultSet rs, int key, LocalDateTime ldt) throws SQLException {
846-
Assert.assertTrue(rs.next());
847-
Assert.assertEquals(key, rs.getInt("key"));
843+
Assertions.assertTrue(rs.next());
844+
Assertions.assertEquals(key, rs.getInt("key"));
848845

849846
Object obj = rs.getObject("c_Datetime");
850-
Assert.assertTrue(obj instanceof LocalDateTime);
851-
Assert.assertEquals(ldt, obj);
847+
Assertions.assertTrue(obj instanceof LocalDateTime);
848+
Assertions.assertEquals(ldt, obj);
852849

853-
Assert.assertEquals(ldt.toEpochSecond(ZoneOffset.UTC), rs.getLong("c_Datetime"));
850+
Assertions.assertEquals(ldt.toEpochSecond(ZoneOffset.UTC), rs.getLong("c_Datetime"));
854851

855-
Assert.assertEquals(Date.valueOf(ldt.toLocalDate()), rs.getDate("c_Datetime"));
856-
Assert.assertEquals(Timestamp.valueOf(ldt), rs.getTimestamp("c_Datetime"));
857-
Assert.assertEquals(ldt.toString(), rs.getString("c_Datetime"));
852+
Assertions.assertEquals(Date.valueOf(ldt.toLocalDate()), rs.getDate("c_Datetime"));
853+
Assertions.assertEquals(Timestamp.valueOf(ldt), rs.getTimestamp("c_Datetime"));
854+
Assertions.assertEquals(ldt.toString(), rs.getString("c_Datetime"));
858855

859-
Assert.assertEquals(Long.valueOf(ldt.toEpochSecond(ZoneOffset.UTC)), rs.getObject("c_Datetime", Long.class));
860-
Assert.assertEquals(ldt.toLocalDate(), rs.getObject("c_Datetime", LocalDate.class));
861-
Assert.assertEquals(ldt, rs.getObject("c_Datetime", LocalDateTime.class));
862-
Assert.assertEquals(ldt.atZone(ZoneId.systemDefault()).toInstant(), rs.getObject("c_Datetime", Instant.class));
856+
Assertions.assertEquals(Long.valueOf(ldt.toEpochSecond(ZoneOffset.UTC)), rs.getObject("c_Datetime", Long.class));
857+
Assertions.assertEquals(ldt.toLocalDate(), rs.getObject("c_Datetime", LocalDate.class));
858+
Assertions.assertEquals(ldt, rs.getObject("c_Datetime", LocalDateTime.class));
859+
Assertions.assertEquals(ldt.atZone(ZoneId.systemDefault()).toInstant(), rs.getObject("c_Datetime", Instant.class));
863860
}
864861

865862
@ParameterizedTest(name = "with {0}")
@@ -940,29 +937,29 @@ public void dateTest(SqlQueries.JdbcQuery query) throws SQLException {
940937
assertNextDate(rs, 7, LocalDate.of(2011, Month.DECEMBER, 3));
941938
assertNextDate(rs, 8, LocalDate.of(2020, Month.MARCH, 3));
942939

943-
Assert.assertFalse(rs.next());
940+
Assertions.assertFalse(rs.next());
944941
}
945942
}
946943
};
947944

948945
private void assertNextDate(ResultSet rs, int key, LocalDate ld) throws SQLException {
949-
Assert.assertTrue(rs.next());
950-
Assert.assertEquals(key, rs.getInt("key"));
946+
Assertions.assertTrue(rs.next());
947+
Assertions.assertEquals(key, rs.getInt("key"));
951948

952949
Object obj = rs.getObject("c_Date");
953-
Assert.assertTrue(obj instanceof LocalDate);
954-
Assert.assertEquals(ld, obj);
950+
Assertions.assertTrue(obj instanceof LocalDate);
951+
Assertions.assertEquals(ld, obj);
955952

956-
Assert.assertEquals(ld.toEpochDay(), rs.getInt("c_Date"));
957-
Assert.assertEquals(ld.toEpochDay(), rs.getLong("c_Date"));
953+
Assertions.assertEquals(ld.toEpochDay(), rs.getInt("c_Date"));
954+
Assertions.assertEquals(ld.toEpochDay(), rs.getLong("c_Date"));
958955

959-
Assert.assertEquals(Date.valueOf(ld), rs.getDate("c_Date"));
960-
Assert.assertEquals(Timestamp.valueOf(ld.atStartOfDay()), rs.getTimestamp("c_Date"));
961-
Assert.assertEquals(ld.toString(), rs.getString("c_Date"));
956+
Assertions.assertEquals(Date.valueOf(ld), rs.getDate("c_Date"));
957+
Assertions.assertEquals(Timestamp.valueOf(ld.atStartOfDay()), rs.getTimestamp("c_Date"));
958+
Assertions.assertEquals(ld.toString(), rs.getString("c_Date"));
962959

963-
Assert.assertEquals(Long.valueOf(ld.toEpochDay()), rs.getObject("c_Date", Long.class));
964-
Assert.assertEquals(ld, rs.getObject("c_Date", LocalDate.class));
965-
Assert.assertEquals(ld.atStartOfDay(), rs.getObject("c_Date", LocalDateTime.class));
966-
Assert.assertEquals(ld.atStartOfDay(ZoneId.systemDefault()).toInstant(), rs.getObject("c_Date", Instant.class));
960+
Assertions.assertEquals(Long.valueOf(ld.toEpochDay()), rs.getObject("c_Date", Long.class));
961+
Assertions.assertEquals(ld, rs.getObject("c_Date", LocalDate.class));
962+
Assertions.assertEquals(ld.atStartOfDay(), rs.getObject("c_Date", LocalDateTime.class));
963+
Assertions.assertEquals(ld.atStartOfDay(ZoneId.systemDefault()).toInstant(), rs.getObject("c_Date", Instant.class));
967964
}
968965
}

0 commit comments

Comments
 (0)