// ĠCopyright Ġ 2 0 0 0 - 2 0 1 9 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe ĠLICENSE Ġfile . Ċ package Ġcom . intellij . serialization Ċ Ċ import Ġcom . intellij . openapi . util . io . Buffer Ex posing ByteArray OutputStream Ċ import Ġcom . intellij . test Framework . Platform TestUtil Ċ import Ġcom . intellij . test Framework . assertions . Assertions . assertThat Ċ import Ġcom . intellij . test Framework . assertions . Cleanup Snapshots Ċ import Ġcom . intellij . util . io . sanitize FileName Ċ import Ġorg . junit . Class Rule Ċ import Ġorg . junit . rules . Test Name Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . junit . runners . Suite Ċ import Ġjava . nio . file . Paths Ċ Ċ internal Ġval Ġtest Snapshot Dir Ġ= ĠPaths . get ( Platform TestUtil . get Community Path (), Ġ" platform / object - serializer / test Snapshots ") Ċ Ċ internal Ġval Ġobject Serializer ĊĠ Ġget () Ġ= ĠObject Serializer . instance Ċ Ċ @ RunWith ( Suite :: class ) Ċ @ Suite . Suite Classes ( Object Serializer Test :: class , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠNon Default Constructor Test :: class , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠMap Test :: class , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠList Test :: class ) Ċ class ĠObject Serializer TestSuite Ġ{ ĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġ@ Class Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġval Ġcleanup Snapshots Ġ= ĠCleanup Snapshots ( test Snapshot Dir ) ĊĠ Ġ} Ċ } Ċ Ċ internal Ġval Ġdefault Test Write Configuration Ġ= ĠWrite Configuration ( binary Ġ= Ġfalse ) Ċ Ċ // Ġdon 't Ġuse Ġserialization Ġfilter Ġin Ġtests Ġto Ġmake Ġsure Ġthat Ġtest Ġare Ġcloser Ġto Ġproduction Ġusage Ġ( e . g . Ġnot Ġnull Ġarg Ġwas Ġnot Ġcaught Ġby Ġtests Ġbecause Ġof Ġnull Ġfil tration ) Ċ internal Ġfun Ġ< T Ġ: ĠAny > Ġtest ( bean : ĠT , Ġtest Name : ĠTest Name , Ġwrite Configuration : ĠWrite Configuration , Ġread Configuration : ĠRead Configuration ? Ġ= Ġnull ): ĠT Ġ{ ĊĠ Ġval Ġout Ġ= ĠBuffer Ex posing ByteArray OutputStream ( 8 Ġ* Ġ 1 0 2 4 ) ĊĊĠ Ġ// Ġjust Ġto Ġtest Ġbinary ĊĠ Ġobject Serializer . write ( bean , Ġout , Ġwrite Configuration . copy ( binary Ġ= Ġtrue )) ĊĠ ĠassertThat ( out . size () Ġ> Ġ 0 ) ĊĠ Ġout . reset () ĊĊĠ Ġobject Serializer . write ( bean , Ġout , Ġwrite Configuration ) ĊĊĠ Ġval Ġion Text Ġ= Ġout . toString () ĊĠ Ġout . reset () ĊĊĠ Ġval Ġdeserialized Bean Ġ= Ġobject Serializer . read ( bean . java Class , Ġion Text , Ġconfiguration Ġ= Ġread Configuration Ġ?: ĠRead Configuration ( allow Any Sub Types Ġ= Ġwrite Configuration . allow Any Sub Types )) ĊĠ Ġobject Serializer . write ( de serialized Bean , Ġout , Ġwrite Configuration ) ĊĠ ĠassertThat ( out . toString ()). isEqualTo ( ion Text ) ĊĊĠ ĠassertThat ( ion Text . trim ()). toMatchSnapshot ( test Snapshot Dir . resolve ("${ sanitize FileName ( test Name . methodName )}. ion ")) ĊĠ Ġreturn Ġdeserialized Bean Ċ }