From 9ebda5e10da8bce83e139cb9ccdcdf4b9d11d9c8 Mon Sep 17 00:00:00 2001 From: takapi327 Date: Mon, 30 Dec 2024 18:52:21 +0900 Subject: [PATCH] Update tests --- .../src/test/scala/ldbc/tests/CodecTest.scala | 2 +- .../tests/SQLStringContextQueryTest.scala | 75 ++++--------------- 2 files changed, 16 insertions(+), 61 deletions(-) diff --git a/tests/src/test/scala/ldbc/tests/CodecTest.scala b/tests/src/test/scala/ldbc/tests/CodecTest.scala index d3aa46d33..58a2e636b 100644 --- a/tests/src/test/scala/ldbc/tests/CodecTest.scala +++ b/tests/src/test/scala/ldbc/tests/CodecTest.scala @@ -294,7 +294,7 @@ trait CodecTest extends CatsEffectSuite: (for _ <- sql"CREATE TABLE none_test (none INT)".update _ <- sql"INSERT INTO none_test (none) VALUES (NULL)".update - result <- sql"SELECT * FROM none_test WHERE none IS NULL".query[None.type].to[Option] + result <- sql"SELECT * FROM none_test WHERE none IS NULL".query[Option[String]].to[Option] yield result).transaction(conn) }, Some(None) diff --git a/tests/src/test/scala/ldbc/tests/SQLStringContextQueryTest.scala b/tests/src/test/scala/ldbc/tests/SQLStringContextQueryTest.scala index ae460b9af..3ab054dfe 100644 --- a/tests/src/test/scala/ldbc/tests/SQLStringContextQueryTest.scala +++ b/tests/src/test/scala/ldbc/tests/SQLStringContextQueryTest.scala @@ -33,36 +33,6 @@ class LdbcSQLStringContextQueryTest extends SQLStringContextQueryTest: ssl = SSL.Trusted ) - test( - "If the acquired column name and the field name of the class to be mapped are different, an exception is raised." - ) { - case class City(id: Int, title: String) - - interceptIO[ldbc.connector.exception.SQLException]( - connection.use { conn => - sql"SELECT Id, Name FROM city LIMIT 1" - .query[City] - .to[Option] - .readOnly(conn) - } - ) - } - - test( - "If the number of columns retrieved is different from the number of fields in the class to be mapped, an exception is raised." - ) { - case class City(id: Int, name: String, age: Int) - - interceptIO[ldbc.connector.exception.SQLException]( - connection.use { conn => - sql"SELECT Id, Name FROM city LIMIT 1" - .query[City] - .to[Option] - .readOnly(conn) - } - ) - } - class JdbcSQLStringContextQueryTest extends SQLStringContextQueryTest: val ds = new MysqlDataSource() @@ -75,36 +45,6 @@ class JdbcSQLStringContextQueryTest extends SQLStringContextQueryTest: override def connection: Resource[IO, Connection[IO]] = Resource.make(jdbc.connector.MysqlDataSource[IO](ds).getConnection)(_.close()) - test( - "If the acquired column name and the field name of the class to be mapped are different, an exception is raised." - ) { - case class City(id: Int, title: String) - - interceptIO[java.sql.SQLException]( - connection.use { conn => - sql"SELECT Id, Name FROM city LIMIT 1" - .query[City] - .to[Option] - .readOnly(conn) - } - ) - } - - test( - "If the number of columns retrieved is different from the number of fields in the class to be mapped, an exception is raised." - ) { - case class City(id: Int, name: String, age: Int) - - interceptIO[java.sql.SQLException]( - connection.use { conn => - sql"SELECT Id, Name FROM city LIMIT 1" - .query[City] - .to[Option] - .readOnly(conn) - } - ) - } - trait SQLStringContextQueryTest extends CatsEffectSuite: given Tracer[IO] = Tracer.noop[IO] @@ -788,3 +728,18 @@ trait SQLStringContextQueryTest extends CatsEffectSuite: Some((City(1, "Kabul"), Country("AFG", "Afghanistan"))) ) } + + test( + "If the number of columns retrieved is different from the number of fields in the class to be mapped, an exception is raised." + ) { + case class City(id: Int, name: String, age: Int) + + interceptIO[ArrayIndexOutOfBoundsException]( + connection.use { conn => + sql"SELECT Id, Name FROM city LIMIT 1" + .query[City] + .to[Option] + .readOnly(conn) + } + ) + }