Skip to content

Commit

Permalink
make some tests compile with scala 3
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsimpson committed Nov 28, 2023
1 parent 87506be commit e18a32f
Show file tree
Hide file tree
Showing 33 changed files with 182 additions and 201 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.github.tminglei.slickpg

import java.util.concurrent.Executors

import argonaut.Argonaut._
import argonaut._
import org.scalatest.funsuite.AnyFunSuite
import slick.jdbc.{GetResult, PostgresProfile}

import scala.concurrent.{Await, ExecutionContext}
import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutorService}
import scala.concurrent.duration._

class PgArgonautSupportSuite extends AnyFunSuite with PostgresContainer {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))
implicit val testExecContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

trait MyPostgresProfile extends PostgresProfile
with PgArgonautSupport
Expand All @@ -24,7 +23,7 @@ class PgArgonautSupportSuite extends AnyFunSuite with PostgresContainer {

///
trait API extends JdbcAPI with JsonImplicits {
implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val strListTypeMapper: DriverJdbcType[List[JsonField]] = new SimpleArrayJdbcType[String]("text").to(_.toList)
}
}
object MyPostgresProfile extends MyPostgresProfile
Expand All @@ -40,7 +39,7 @@ class PgArgonautSupportSuite extends AnyFunSuite with PostgresContainer {
def id = column[Long]("id", O.AutoInc, O.PrimaryKey)
def json = column[Json]("json")

def * = (id, json) <> (JsonBean.tupled, JsonBean.unapply)
def * = (id, json) <> ((JsonBean.apply _).tupled, JsonBean.unapply)
}
val JsonTests = TableQuery[JsonTestTable]

Expand Down Expand Up @@ -158,7 +157,7 @@ class PgArgonautSupportSuite extends AnyFunSuite with PostgresContainer {
test("Argonaut json Plain SQL support") {
import MyPostgresProfile.plainAPI._

implicit val getJsonBeanResult = GetResult(r => JsonBean(r.nextLong(), r.nextJson()))
implicit val getJsonBeanResult: GetResult[JsonBean] = GetResult(r => JsonBean(r.nextLong(), r.nextJson()))

val b = JsonBean(34L, """ { "a":101, "b":"aaa", "c":[3,4,5,9] } """.parseOption.getOrElse(jNull))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.github.tminglei.slickpg

import java.util.concurrent.Executors

import cats.syntax.either._
import io.circe._
import io.circe.parser._
import org.scalatest.funsuite.AnyFunSuite
import slick.jdbc.{GetResult, PostgresProfile}

import scala.concurrent.{Await, ExecutionContext}
import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutorService}
import scala.concurrent.duration._

class PgCirceJsonSupportSuite extends AnyFunSuite with PostgresContainer {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))
implicit val testExecContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

trait MyPostgresProfile extends PostgresProfile
with PgCirceJsonSupport
Expand All @@ -25,7 +24,7 @@ class PgCirceJsonSupportSuite extends AnyFunSuite with PostgresContainer {

///
trait API extends JdbcAPI with JsonImplicits {
implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val strListTypeMapper: DriverJdbcType[List[String]] = new SimpleArrayJdbcType[String]("text").to(_.toList)
}
}
object MyPostgresProfile extends MyPostgresProfile
Expand All @@ -40,7 +39,7 @@ class PgCirceJsonSupportSuite extends AnyFunSuite with PostgresContainer {
def id = column[Long]("id", O.AutoInc, O.PrimaryKey)
def json = column[Json]("json")

def * = (id, json) <> (JsonBean.tupled, JsonBean.unapply)
def * = (id, json) <> ((JsonBean.apply _).tupled, JsonBean.unapply)
}
val JsonTests = TableQuery[JsonTestTable]

Expand Down Expand Up @@ -137,7 +136,7 @@ class PgCirceJsonSupportSuite extends AnyFunSuite with PostgresContainer {
test("Circe json Plain SQL support") {
import MyPostgresProfile.plainAPI._

implicit val getJsonBeanResult = GetResult(r => JsonBean(r.nextLong(), r.nextJson()))
implicit val getJsonBeanResult: GetResult[JsonBean] = GetResult(r => JsonBean(r.nextLong(), r.nextJson()))

val b = JsonBean(34L, parse(""" { "a":101, "b":"aaa", "c":[3,4,5,9] } """).getOrElse(Json.Null))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package com.github.tminglei.slickpg

import java.util.concurrent.Executors

import org.typelevel.jawn._
import org.typelevel.jawn.ast._

import org.scalatest.funsuite.AnyFunSuite
import slick.jdbc.{GetResult, PostgresProfile}

import scala.concurrent.{Await, ExecutionContext}
import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutorService}
import scala.concurrent.duration._

class PgJawnJsonSupportSuite extends AnyFunSuite with PostgresContainer {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))
implicit val testExecContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

trait MyPostgresProfile extends PostgresProfile
with PgJawnJsonSupport
Expand All @@ -25,8 +23,8 @@ class PgJawnJsonSupportSuite extends AnyFunSuite with PostgresContainer {

///
trait API extends JdbcAPI with JsonImplicits {
implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val jsonArrayTypeMapper =
implicit val strListTypeMapper: DriverJdbcType[List[String]] = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val jsonArrayTypeMapper: DriverJdbcType[List[JValue]] =
new AdvancedArrayJdbcType[JValue](pgjson,
(s) => utils.SimpleArrayUtils.fromString[JValue](JParser.parseUnsafe(_))(s).orNull,
(v) => utils.SimpleArrayUtils.mkString[JValue](_.toString())(v)
Expand All @@ -47,7 +45,7 @@ class PgJawnJsonSupportSuite extends AnyFunSuite with PostgresContainer {
def json = column[JValue]("json", O.Default(JParser.parseUnsafe(""" {"a":"v1","b":2} """)))
def jsons = column[List[JValue]]("jsons")

def * = (id, json, jsons) <> (JsonBean.tupled, JsonBean.unapply)
def * = (id, json, jsons) <> ((JsonBean.apply _).tupled, JsonBean.unapply)
}
val JsonTests = TableQuery[JsonTestTable]

Expand Down Expand Up @@ -173,7 +171,7 @@ class PgJawnJsonSupportSuite extends AnyFunSuite with PostgresContainer {
test("Json Plain SQL support") {
import MyPostgresProfile.plainAPI._

implicit val getJsonBeanResult = GetResult(r => JsonBean1(r.nextLong(), r.nextJson()))
implicit val getJsonBeanResult: GetResult[JsonBean1] = GetResult(r => JsonBean1(r.nextLong(), r.nextJson()))

val b = JsonBean1(34L, JParser.parseUnsafe(""" { "a":101, "b":"aaa", "c":[3,4,5,9] } """))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.github.tminglei.slickpg

import java.util.concurrent.Executors

import org.joda.time._
import org.scalatest.funsuite.AnyFunSuite
import slick.jdbc.{GetResult, PostgresProfile}

import scala.concurrent.{Await, ExecutionContext}
import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutorService}

class PgDateSupportJodaSuite extends AnyFunSuite with PostgresContainer {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))
implicit val testExecContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

trait MyPostgresProfile extends PostgresProfile
with PgDateSupportJoda {
Expand Down Expand Up @@ -47,7 +46,7 @@ class PgDateSupportJodaSuite extends AnyFunSuite with PostgresContainer {
def interval = column[Period]("interval")
def instant = column[Instant]("instant")

def * = (id, date, time, datetime, datetimetz, interval, instant) <> (DatetimeBean.tupled, DatetimeBean.unapply)
def * = (id, date, time, datetime, datetimetz, interval, instant) <> ((DatetimeBean.apply _).tupled, DatetimeBean.unapply)
}
val Datetimes = TableQuery[DatetimeTable]

Expand Down Expand Up @@ -248,7 +247,7 @@ class PgDateSupportJodaSuite extends AnyFunSuite with PostgresContainer {
test("Joda time Plain SQL support") {
import MyPostgresProfile.plainAPI._

implicit val getDateBean = GetResult(r => DatetimeBean(
implicit val getDateBean: GetResult[DatetimeBean] = GetResult(r => DatetimeBean(
r.nextLong(), r.nextLocalDate(), r.nextLocalTime(), r.nextLocalDateTime(), r.nextZonedDateTime(), r.nextPeriod(), r.nextInstant()))

val b1 = new DatetimeBean(107L, LocalDate.parse("2010-11-03"), LocalTime.parse("12:33:01.101357"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.github.tminglei.slickpg

import java.util.concurrent.Executors

import org.json4s._
import org.scalatest.funsuite.AnyFunSuite
import slick.jdbc.{GetResult, PostgresProfile}

import scala.concurrent.{Await, ExecutionContext}
import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutorService}
import scala.concurrent.duration._

class PgJson4sSupportSuite extends AnyFunSuite with PostgresContainer {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))
implicit val testExecContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

trait MyPostgresProfile extends PostgresProfile
with PgJson4sSupport
Expand All @@ -26,8 +25,8 @@ class PgJson4sSupportSuite extends AnyFunSuite with PostgresContainer {

///
trait API extends JdbcAPI with JsonImplicits {
implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val json4sJsonArrayTypeMapper =
implicit val strListTypeMapper: DriverJdbcType[List[String]] = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val json4sJsonArrayTypeMapper: DriverJdbcType[List[JValue]] =
new AdvancedArrayJdbcType[JValue](pgjson,
(s) => utils.SimpleArrayUtils.fromString[JValue](jsonMethods.parse(_))(s).orNull,
(v) => utils.SimpleArrayUtils.mkString[JValue](j=>jsonMethods.compact(jsonMethods.render(j)))(v)
Expand All @@ -49,7 +48,7 @@ class PgJson4sSupportSuite extends AnyFunSuite with PostgresContainer {
def json = column[JValue]("json")
def jsons = column[List[JValue]]("jsons")

def * = (id, json, jsons) <> (JsonBean.tupled, JsonBean.unapply)
def * = (id, json, jsons) <> ((JsonBean.apply _).tupled, JsonBean.unapply)
}
val JsonTests = TableQuery[JsonTestTable]

Expand Down Expand Up @@ -175,7 +174,7 @@ class PgJson4sSupportSuite extends AnyFunSuite with PostgresContainer {
test("Json4s Plain SQL support") {
import MyPostgresProfile.plainAPI._

implicit val getJsonBeanResult = GetResult(r => JsonBean1(r.nextLong(), r.nextJson()))
implicit val getJsonBeanResult: GetResult[JsonBean1] = GetResult(r => JsonBean1(r.nextLong(), r.nextJson()))

val b = JsonBean1(34L, parse(""" { "a":101, "b":"aaa", "c":[3,4,5,9] } """))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.github.tminglei.slickpg

import java.util.concurrent.Executors

import scala.concurrent.duration._
import scala.concurrent.{Await, ExecutionContext}

import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutorService}
import slick.jdbc.GetResult

import com.vividsolutions.jts.geom.{Geometry, Point}
import com.vividsolutions.jts.io.{WKBWriter, WKTReader, WKTWriter}
import org.scalatest.funsuite.AnyFunSuite


class PgPostGISSupportSuite extends AnyFunSuite with PostgresContainer {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))
implicit val testExecContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

trait MyPostgresProfile extends ExPostgresProfile with PgPostGISSupport {

Expand Down Expand Up @@ -41,7 +38,7 @@ class PgPostGISSupportSuite extends AnyFunSuite with PostgresContainer {
def geom = column[Geometry]("geom")
def geog = column[Geography]("geog")

def * = (id, geom, geog) <> (GeometryBean.tupled, GeometryBean.unapply)
def * = (id, geom, geog) <> ((GeometryBean.apply _).tupled, GeometryBean.unapply)
}
val GeomTests = TableQuery[GeomTestTable]

Expand All @@ -52,7 +49,7 @@ class PgPostGISSupportSuite extends AnyFunSuite with PostgresContainer {
def id = column[Long]("id", O.AutoInc, O.PrimaryKey)
def point = column[Point]("point")

def * = (id, point) <> (PointBean.tupled, PointBean.unapply)
def * = (id, point) <> ((PointBean.apply _).tupled, PointBean.unapply)
}
val PointTests = TableQuery[PointTestTable]

Expand Down Expand Up @@ -830,7 +827,7 @@ class PgPostGISSupportSuite extends AnyFunSuite with PostgresContainer {
test("PostGIS Plain SQL support") {
import MyPostgresProfile.plainAPI._

implicit val GetPointBeanResult = GetResult(r => PointBean(r.nextLong(), r.nextGeometry[Point]()))
implicit val GetPointBeanResult: GetResult[PointBean] = GetResult(r => PointBean(r.nextLong(), r.nextGeometry[Point]()))

val b = PointBean(77L, wktReader.read("POINT(4 5)").asInstanceOf[Point])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.github.tminglei.slickpg

import java.util.concurrent.Executors

import scala.concurrent.duration._
import scala.concurrent.{Await, ExecutionContext}

import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutorService}
import slick.jdbc.GetResult

import org.locationtech.jts.geom.{Geometry, Point}
import org.locationtech.jts.io.{WKBWriter, WKTReader, WKTWriter}
import org.scalatest.funsuite.AnyFunSuite


class PgPostGISSupportSuite extends AnyFunSuite with PostgresContainer {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))
implicit val testExecContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

trait MyPostgresProfile extends ExPostgresProfile with PgPostGISSupport {

Expand Down Expand Up @@ -41,7 +38,7 @@ class PgPostGISSupportSuite extends AnyFunSuite with PostgresContainer {
def geom = column[Geometry]("geom")
def geog = column[Geography]("geog")

def * = (id, geom, geog) <> (GeometryBean.tupled, GeometryBean.unapply)
def * = (id, geom, geog) <> ((GeometryBean.apply _).tupled, GeometryBean.unapply)
}
val GeomTests = TableQuery[GeomTestTable]

Expand All @@ -52,7 +49,7 @@ class PgPostGISSupportSuite extends AnyFunSuite with PostgresContainer {
def id = column[Long]("id", O.AutoInc, O.PrimaryKey)
def point = column[Point]("point")

def * = (id, point) <> (PointBean.tupled, PointBean.unapply)
def * = (id, point) <> ((PointBean.apply _).tupled, PointBean.unapply)
}
val PointTests = TableQuery[PointTestTable]

Expand Down Expand Up @@ -816,7 +813,7 @@ class PgPostGISSupportSuite extends AnyFunSuite with PostgresContainer {
test("PostGIS (lt) Plain SQL support") {
import MyPostgresProfile.plainAPI._

implicit val GetPointBeanResult = GetResult(r => PointBean(r.nextLong(), r.nextGeometry[Point]()))
implicit val GetPointBeanResult: GetResult[PointBean] = GetResult(r => PointBean(r.nextLong(), r.nextGeometry[Point]()))

val b = PointBean(77L, wktReader.read("POINT(4 5)").asInstanceOf[Point])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package com.github.tminglei.slickpg

import java.util.concurrent.Executors

import scala.concurrent.duration._
import scala.concurrent.{Await, ExecutionContext}

import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutorService}
import play.api.libs.json._
import slick.jdbc.{GetResult, PostgresProfile}

import slick.jdbc.{GetResult, JdbcType, PostgresProfile}
import com.github.tminglei.slickpg.utils.JsonUtils
import org.scalatest.funsuite.AnyFunSuite
import slick.ast.BaseTypedType


class PgPlayJsonSupportSuite extends AnyFunSuite with PostgresContainer {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))
implicit val testExecContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

case class JBean(name: String, count: Int)
object JBean {
implicit val jbeanFmt = Json.format[JBean]
implicit val jbeanWrt = Json.writes[JBean]
implicit val jbeanFmt: OFormat[JBean] = Json.format[JBean]
implicit val jbeanWrt: OWrites[JBean] = Json.writes[JBean]
}

trait MyPostgresProfile extends PostgresProfile
Expand All @@ -32,14 +30,14 @@ class PgPlayJsonSupportSuite extends AnyFunSuite with PostgresContainer {

///
trait API extends JdbcAPI with JsonImplicits {
implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val beanJsonTypeMapper = MappedJdbcType.base[JBean, JsValue](Json.toJson(_), _.as[JBean])
implicit val jsonArrayTypeMapper =
implicit val strListTypeMapper: DriverJdbcType[List[String]] = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val beanJsonTypeMapper: JdbcType[JBean] with BaseTypedType[JBean] = MappedJdbcType.base[JBean, JsValue](Json.toJson(_), _.as[JBean])
implicit val jsonArrayTypeMapper: DriverJdbcType[List[JsValue]] =
new AdvancedArrayJdbcType[JsValue](pgjson,
(s) => utils.SimpleArrayUtils.fromString[JsValue](Json.parse(_))(s).orNull,
(v) => utils.SimpleArrayUtils.mkString[JsValue](_.toString())(v)
).to(_.toList)
implicit val beanArrayTypeMapper =
implicit val beanArrayTypeMapper: DriverJdbcType[List[JBean]] =
new AdvancedArrayJdbcType[JBean](pgjson,
(s) => utils.SimpleArrayUtils.fromString[JBean](Json.parse(_).as[JBean])(s).orNull,
(v) => utils.SimpleArrayUtils.mkString[JBean](b => Json.stringify(Json.toJson(b)))(v)
Expand All @@ -62,7 +60,7 @@ class PgPlayJsonSupportSuite extends AnyFunSuite with PostgresContainer {
def jbean = column[JBean]("jbean")
def jbeans = column[List[JBean]]("jbeans")

def * = (id, json, jsons, jbean, jbeans) <> (JsonBean.tupled, JsonBean.unapply)
def * = (id, json, jsons, jbean, jbeans) <> ((JsonBean.apply _).tupled, JsonBean.unapply)
}
val JsonTests = TableQuery[JsonTestTable]

Expand Down Expand Up @@ -207,7 +205,7 @@ class PgPlayJsonSupportSuite extends AnyFunSuite with PostgresContainer {
test("Json Plain SQL support") {
import MyPostgresProfile.plainAPI._

implicit val getJsonBeanResult = GetResult(r => JsonBean1(r.nextLong(), r.nextJson()))
implicit val getJsonBeanResult: GetResult[JsonBean1] = GetResult(r => JsonBean1(r.nextLong(), r.nextJson()))

val b = JsonBean1(34L, Json.parse(""" { "a":101, "b":"aaa", "c":[3,4,5,9] } """))

Expand Down
Loading

0 comments on commit e18a32f

Please sign in to comment.