/* Ċ Ġ* ĠCopyright ĠÂ© Ġ 2 0 1 9 . ĠS ir ĠWell ing ton . Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* ĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġtech . sir well ing ton . alchemy . kotlin . extensions Ċ Ċ import Ġcom . nat pr y ce . ham k rest . and Ċ import Ġcom . nat pr y ce . ham k rest . assertion . assertThat Ċ import Ġcom . nat pr y ce . ham k rest . equalTo Ċ import Ġcom . nat pr y ce . ham k rest . same Instance Ċ import Ġorg . junit . Assert . assertFalse Ċ import Ġorg . junit . Assert . assertTrue Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġtech . sir well ing ton . alchemy . generator . String Generators Ċ import Ġtech . sir well ing ton . alchemy . generator . one Ċ import Ġtech . sir well ing ton . alchemy . test . hamcrest . isNull Ċ import Ġtech . sir well ing ton . alchemy . test . hamcrest . notNull Ċ import Ġtech . sir well ing ton . alchemy . test . junit . runners . Alchemy TestRunner Ċ Ċ @ RunWith ( Alchemy TestRunner :: class ) Ċ class ĠReferences Plus Test Ċ { ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġoriginal Reference : ĠString ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġoriginal Reference Ġ= Ġone ( String Generators . alphabet ic Strings ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest As Weak () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġweak Reference Ġ= Ġoriginal Reference . as Weak () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( weak Reference , Ġnot Null ) ĊĠĠĠĠĠĠĠ ĠassertThat ( weak Reference . get (), Ġnot Null Ġand ĠequalTo ( original Reference )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest As Weak When Collected () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġweak Reference Ġ= Ġoriginal Reference . as Weak () ĊĠĠĠĠĠĠĠ Ġoriginal Reference Ġ= Ġone ( String Generators . alphabet ic Strings ()) ĊĊĠĠĠĠĠĠĠ ĠSystem . gc () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( weak Reference , Ġnot Null ) ĊĠĠĠĠĠĠĠ ĠassertThat ( weak Reference . get (), Ġis Null ) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Is The Same Reference As () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġfirst Ġ= Ġoriginal Reference . as Weak () ĊĠĠĠĠĠĠĠ Ġval Ġsecond Ġ= Ġoriginal Reference . as Weak () ĊĠĠĠĠĠĠĠ ĠassertThat ( first , Ġ! same Instance ( second )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Already Contains Weak Ref () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġfirst Ġ= Ġoriginal Reference . as Weak () ĊĠĠĠĠĠĠĠ Ġval Ġlist Ġ= Ġmutable ListOf ( first ) ĊĠĠĠĠĠĠĠ Ġval Ġsecond Ġ= Ġoriginal Reference . as Weak () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( first , Ġ! equalTo ( second )) ĊĠĠĠĠĠĠĠ ĠassertTrue ( list . already Contains Weak Ref ( second )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Already Contains Weak Ref When It DoesNot () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġfirst Ref Ġ= Ġoriginal Reference . as Weak () ĊĠĠĠĠĠĠĠ Ġval Ġsecond Value Ġ= Ġone ( String Generators . alphabet ic Strings ()) ĊĠĠĠĠĠĠĠ Ġval Ġsecond Ref Ġ= Ġsecond Value . as Weak () ĊĊĠĠĠĠĠĠĠ Ġval Ġlist Ġ= Ġmutable ListOf ( first Ref ) ĊĊĠĠĠĠĠĠĠ ĠassertTrue ( list . already Contains Weak Ref ( original Reference . as Weak ())) ĊĠĠĠĠĠĠĠ ĠassertFalse ( list . already Contains Weak Ref ( second Ref )) ĊĊĠĠĠĠĠĠĠ Ġlist . add ( second Ref ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( list . size , ĠequalTo ( 2 )) ĊĠĠĠ Ġ} Ċ Ċ }