From 0afc624009a4e6ed7e61fe4fafddb8aeb1409be4 Mon Sep 17 00:00:00 2001 From: "E.G" <146701565+GlobalStar117@users.noreply.github.com> Date: Fri, 16 Jan 2026 06:09:25 +1100 Subject: [PATCH] [2.x] test: Migrate SingletonCacheSpec.scala to verify.BasicTestSuite (#8546) Migrate SingletonCacheSpec.scala from ScalaTest's AnyFlatSpec to verify.BasicTestSuite, following the pattern established by other test files in the util-cache module. Changes: - Replace AnyFlatSpec class with BasicTestSuite object - Convert 'should ... in' syntax to 'test(...)' syntax - Use Scala 3 syntax with colon indentation - Change === to == for assertions (BasicTestSuite style) - Replace intercept[Exception] with scala.util.Try pattern - Add 'end SingletonCacheSpec' and 'end ComplexType' markers Related to the ongoing test migration effort. Co-authored-by: GlobalStar117 --- .../src/test/scala/SingletonCacheSpec.scala | 48 ++++++++----------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/util-cache/src/test/scala/SingletonCacheSpec.scala b/util-cache/src/test/scala/SingletonCacheSpec.scala index 0d2972b8c..939b71c7d 100644 --- a/util-cache/src/test/scala/SingletonCacheSpec.scala +++ b/util-cache/src/test/scala/SingletonCacheSpec.scala @@ -14,16 +14,18 @@ import sbt.io.syntax.* import CacheImplicits.* import sjsonnew.{ Builder, deserializationError, JsonFormat, Unbuilder } -import org.scalatest.flatspec.AnyFlatSpec +import verify.BasicTestSuite -class SingletonCacheSpec extends AnyFlatSpec { +import scala.util.Try + +object SingletonCacheSpec extends BasicTestSuite: case class ComplexType(x: Int, y: String, z: List[Int]) - object ComplexType { + object ComplexType: given format: JsonFormat[ComplexType] = - new JsonFormat[ComplexType] { - override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): ComplexType = { - jsOpt match { + new JsonFormat[ComplexType]: + override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): ComplexType = + jsOpt match case Some(js) => unbuilder.beginObject(js) val x = unbuilder.readField[Int]("x") @@ -34,53 +36,41 @@ class SingletonCacheSpec extends AnyFlatSpec { case None => deserializationError("Exception JObject but found None") - } - } - override def write[J](obj: ComplexType, builder: Builder[J]): Unit = { + override def write[J](obj: ComplexType, builder: Builder[J]): Unit = builder.beginObject() builder.addField("x", obj.x) builder.addField("y", obj.y) builder.addField("z", obj.z) builder.endObject() - } - } - } + end ComplexType - "A singleton cache" should "throw an exception if read without being written previously" in { + test("A singleton cache should throw an exception if read without being written previously"): testCache[Int] { (cache, store) => - intercept[Exception] { - cache.read(store) - } - () + val result = Try(cache.read(store)) + assert(result.isFailure, "Expected exception but read succeeded") } - } - it should "write a very simple value" in { + test("A singleton cache should write a very simple value"): testCache[Int] { (cache, store) => cache.write(store, 5) } - } - it should "return the simple value that has been previously written" in { + test("A singleton cache should return the simple value that has been previously written"): testCache[Int] { (cache, store) => val value = 5 cache.write(store, value) val read = cache.read(store) - - assert(read === value); () + assert(read == value) } - } - it should "write a complex value" in { + test("A singleton cache should write a complex value"): testCache[ComplexType] { (cache, store) => val value = ComplexType(1, "hello, world!", (1 to 10 by 3).toList) cache.write(store, value) val read = cache.read(store) - - assert(read === value); () + assert(read == value) } - } private def testCache[T](f: (SingletonCache[T], CacheStore) => Unit)(using cache: SingletonCache[T] @@ -90,4 +80,4 @@ class SingletonCacheSpec extends AnyFlatSpec { f(cache, store) } -} +end SingletonCacheSpec