Skip to content

Commit

Permalink
Split the equality testing based on code review comments for `ScalaOb…
Browse files Browse the repository at this point in the history
…jectSerializerTest` - the tests themselves now assert on *identity*, but the helpers are used to assert on *state*.
  • Loading branch information
sageserpent-open committed Sep 26, 2024
1 parent 98873f8 commit 09e1485
Showing 1 changed file with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@ package io.altoo.serialization.kryo.scala.serializer

import io.altoo.serialization.kryo.scala.testkit.AbstractKryoTest

object standalone
import java.util.UUID

object ScalaObjectSerializerTest
trait Snowflake {
val state: UUID = UUID.randomUUID()

override def hashCode(): Int = state.hashCode()

override def equals(another: Any): Boolean = another match {
case anotherSnowflake: Snowflake =>
// NOTE: don't worry about respecting different flavours of
// subclass, as all snowflakes are constructed different from
// each other to start with. Only copies can be equal!
this.state == anotherSnowflake.state
case _ => false
}
}

object standalone extends Snowflake

object ScalaObjectSerializerTest extends Snowflake

class ScalaObjectSerializerTest extends AbstractKryoTest {
private def configureKryo(): Unit = {
Expand All @@ -20,16 +37,16 @@ class ScalaObjectSerializerTest extends AbstractKryoTest {
it should "round trip standalone and companion objects" in {
configureKryo()

testSerializationOf(standalone)
(testSerializationOf(standalone) should be).theSameInstanceAs(standalone)

testSerializationOf(ScalaObjectSerializerTest)
(testSerializationOf(ScalaObjectSerializerTest) should be).theSameInstanceAs(ScalaObjectSerializerTest)
}

it should "support copying of standalone and companion objects" in {
configureKryo()

testCopyingOf(standalone)
(testCopyingOf(standalone) should be).theSameInstanceAs(standalone)

testCopyingOf(ScalaObjectSerializerTest)
(testCopyingOf(ScalaObjectSerializerTest) should be).theSameInstanceAs(ScalaObjectSerializerTest)
}
}

0 comments on commit 09e1485

Please sign in to comment.