-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from sageserpent-open/scala-object-serializer-…
…supports-is-immutable Scala object serializer supports copying.
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...c/test/scala/io/altoo/serialization/kryo/scala/serializer/ScalaObjectSerializerTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.altoo.serialization.kryo.scala.serializer | ||
|
||
import io.altoo.serialization.kryo.scala.testkit.AbstractKryoTest | ||
|
||
import java.util.UUID | ||
|
||
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 = { | ||
kryo.setRegistrationRequired(false) | ||
// NOTE: to support building under Scala 2.12, use the Java approach of obtaining | ||
// a singleton object's class at runtime, rather than `classOf[singleton.type]` | ||
kryo.addDefaultSerializer(standalone.getClass, classOf[ScalaObjectSerializer[Any]]) | ||
kryo.addDefaultSerializer(ScalaObjectSerializerTest.getClass, classOf[ScalaObjectSerializer[Any]]) | ||
} | ||
|
||
behavior of "ScalaObjectSerializer" | ||
|
||
it should "round trip standalone and companion objects" in { | ||
configureKryo() | ||
|
||
(testSerializationOf(standalone) should be).theSameInstanceAs(standalone) | ||
|
||
(testSerializationOf(ScalaObjectSerializerTest) should be).theSameInstanceAs(ScalaObjectSerializerTest) | ||
} | ||
|
||
it should "support copying of standalone and companion objects" in { | ||
configureKryo() | ||
|
||
(testCopyingOf(standalone) should be).theSameInstanceAs(standalone) | ||
|
||
(testCopyingOf(ScalaObjectSerializerTest) should be).theSameInstanceAs(ScalaObjectSerializerTest) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters