package Ġcom . github . j actor . persistence . repository Ċ Ċ import Ġcom . github . j actor . persistence . dto . Address Internal Dto Ċ import Ġcom . github . j actor . persistence . dto . Persistent Dto Ċ import Ġcom . github . j actor . persistence . dto . Person Internal Dto Ċ import Ġcom . github . j actor . persistence . dto . User Internal Dto Ċ import Ġcom . github . j actor . persistence . entity . Person Entity Ċ import Ġcom . github . j actor . persistence . entity . Person Entity . Companion . a Person Ċ import Ġcom . github . j actor . persistence . entity . User Entity . Companion . a User Ċ import Ġjavax . persistence . EntityManager Ċ import Ġjavax . transaction . Transactional Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Assertions . assert All Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ Ċ @ SpringBootTest Ċ @ Transactional Ċ internal Ġclass ĠPerson Repository Test Ġ{ ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġperson Repository : ĠPerson Repository ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġentity Manager : ĠEntity Manager ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġfind Ġdefault Ġpersons `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġperson Entities Ġ= Ġperson Repository . findBy S urname (" J ac obs en ") ĊĠĠĠĠĠĠĠ Ġval Ġfirst Names : ĠMutable List < String > Ġ= ĠArrayList () ĊĊĠĠĠĠĠĠĠ Ġfor Ġ( person Entity Ġin Ġperson Entities ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfirst Names . add ( person Entity . firstName Ġ?: Ġ" unknown ") ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠassertThat ( first Names ). ` as ` (" first Ġnames "). contains (" Tor ĠE gil ", Ġ" S uth at ip ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġsave Ġthen Ġread Ġa Ġperson Ġentity `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġall ready Present People Ġ= ĠnumberOf ( person Repository . findAll ()) ĊĠĠĠĠĠĠĠ Ġval Ġaddress Ġ= ĠAddress Internal Dto ( zip Code Ġ= Ġ" 1 0 0 1 ", Ġaddress Line 1 Ġ= Ġ" Test ĠB ou le var Ġ 1 ", Ġcity Ġ= Ġ" Testing ton ") ĊĠĠĠĠĠĠĠ Ġval Ġperson To Persist Ġ= Ġa Person ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠPerson Internal Dto ( address Ġ= Ġaddress , Ġlocale Ġ= Ġ" no _ NO ", ĠfirstName Ġ= Ġ" B orn ", Ġs urname Ġ= Ġ" Some time ", Ġdescription Ġ= Ġ" Me , Ġmyself , Ġand ĠI ") ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġperson Repository . save ( person To Persist ) ĊĠĠĠĠĠĠĠ Ġentity Manager . flush () ĊĠĠĠĠĠĠĠ Ġentity Manager . clear () ĊĊĠĠĠĠĠĠĠ Ġval Ġpeople Ġ= Ġperson Repository . findAll () ĊĠĠĠĠĠĠĠ ĠassertThat ( people ). has Size ( all ready Present People Ġ+ Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġperson Entity Ġ= Ġperson Repository . findBy S urname (" Some time "). iterator (). next () ĊĊĠĠĠĠĠĠĠ Ġassert All ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ{ ĠassertThat ( person Entity . address Entity ). ` as ` (" address "). isEqualTo ( person To Persist . address Entity ) Ġ}, ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ{ ĠassertThat ( person Entity . description ). ` as ` (" description "). isEqualTo (" Me , Ġmyself , Ġand ĠI ") Ġ}, ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ{ ĠassertThat ( person Entity . locale ). ` as ` (" locale "). isEqualTo (" no _ NO ") Ġ}, ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ{ ĠassertThat ( person Entity . firstName ). ` as ` (" first Ġname "). isEqualTo (" B orn ") Ġ} ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġsave Ġthen Ġupdate Ġand Ġread Ġa Ġperson Ġentity `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġaddress Internal Dto Ġ= ĠAddress Internal Dto ( zip Code Ġ= Ġ" 1 0 0 1 ", Ġaddress Line 1 Ġ= Ġ" Test ĠB ou lev ard Ġ 1 ", Ġcity Ġ= Ġ" Testing ton ") ĊĠĠĠĠĠĠĠ Ġval Ġperson To Persist Ġ= Ġa Person ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠPerson Internal Dto ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġaddress Ġ= Ġaddress Internal Dto , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlocale Ġ= Ġ" no _ NO ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠfirstName Ġ= Ġ" B ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġs urname Ġ= Ġ" Mine ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdescription Ġ= Ġ" Just Ġme ..." ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġperson Repository . save ( person To Persist ) ĊĠĠĠĠĠĠĠ Ġentity Manager . flush () ĊĠĠĠĠĠĠĠ Ġentity Manager . clear () ĊĊĠĠĠĠĠĠĠ Ġval Ġmine Ġ= Ġperson Repository . findBy S urname (" Mine ") ĊĠĠĠĠĠĠĠ Ġval Ġperson Ġ= Ġmine . iterator (). next () ĊĊĠĠĠĠĠĠĠ Ġperson . description Ġ= Ġ" There Ġis Ġno Ġtry " ĊĠĠĠĠĠĠĠ Ġperson . locale Ġ= Ġ" dk _ DK " ĊĠĠĠĠĠĠĠ Ġperson . firstName Ġ= Ġ" Dr . ĠA ." ĊĠĠĠĠĠĠĠ Ġperson . surname Ġ= Ġ" C ula " ĊĊĠĠĠĠĠĠĠ Ġperson Repository . save ( person ) ĊĠĠĠĠĠĠĠ Ġentity Manager . flush () ĊĠĠĠĠĠĠĠ Ġentity Manager . clear () ĊĊĠĠĠĠĠĠĠ Ġval Ġfound C ula Ġ= Ġperson Repository . findBy S urname (" C ula ") ĊĠĠĠĠĠĠĠ Ġval Ġperson Entity Ġ= Ġfound C ula . iterator (). next () ĊĊĠĠĠĠĠĠĠ Ġassert All ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ{ ĠassertThat ( person Entity . description ). ` as ` (" description "). isEqualTo (" There Ġis Ġno Ġtry ") Ġ}, ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ{ ĠassertThat ( person Entity . locale ). ` as ` (" locale "). isEqualTo (" dk _ DK ") Ġ}, ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ{ ĠassertThat ( person Entity . firstName ). ` as ` (" first Ġname "). isEqualTo (" Dr . ĠA .") Ġ}, ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ{ ĠassertThat ( person Entity . get Users ()). isEqualTo ( person . get Users ()) Ġ} ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġbe Ġable Ġto Ġre late Ġa Ġuser `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġalready Present People Ġ= ĠnumberOf ( person Repository . findAll ()) ĊĠĠĠĠĠĠĠ Ġval Ġaddress Internal Dto Ġ= ĠAddress Internal Dto ( zip Code Ġ= Ġ" 1 0 0 1 ", Ġaddress Line 1 Ġ= Ġ" Test ĠB ou lev ard Ġ 1 ", Ġcity Ġ= Ġ" Testing ") ĊĠĠĠĠĠĠĠ Ġval Ġperson Internal Dto Ġ= ĠPerson Internal Dto ( address Ġ= Ġaddress Internal Dto , Ġs urname Ġ= Ġ" Ad der ") ĊĠĠĠĠĠĠĠ Ġval Ġuser Internal Dto Ġ= ĠUser Internal Dto ( Persistent Dto (), Ġperson Internal Dto , Ġemail Address Ġ= Ġ" public @ services . com ", Ġusername Ġ= Ġ" black ") ĊĠĠĠĠĠĠĠ Ġval Ġuser Entity Ġ= Ġa User ( user Internal Dto ) ĊĠĠĠĠĠĠĠ Ġval Ġperson To Persist Ġ= Ġuser Entity . fetch Person () !! ĊĊĠĠĠĠĠĠĠ Ġperson Repository . save < Person Entity >( person To Persist ) ĊĠĠĠĠĠĠĠ Ġentity Manager . flush () ĊĠĠĠĠĠĠĠ Ġentity Manager . clear () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( person Repository . findAll ()). has Size ( already Present People Ġ+ Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġperson Entity Ġ= Ġperson Repository . findBy S urname (" Ad der "). iterator (). next () ĊĠĠĠĠĠĠĠ ĠassertThat ( person Entity . get Users ()). ` as ` (" users "). has Size ( 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġpersisted User Ġ= Ġperson Entity . get Users (). iterator (). next () ĊĊĠĠĠĠĠĠĠ Ġassert All ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ{ ĠassertThat ( pers isted User . email Address ). ` as ` (" user Ġemail "). isEqualTo (" public @ services . com ") Ġ}, ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ{ ĠassertThat ( pers isted User . username ). ` as ` (" user Ġname "). isEqualTo (" black ") Ġ} ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠnumberOf ( people : ĠIterable < Person Entity ?> ): ĠInt Ġ{ ĊĠĠĠĠĠĠĠ Ġvar Ġcounter Ġ= Ġ 0 ĊĠĠĠĠĠĠĠ Ġval Ġpeople Iterator Ġ= Ġpeople . iterator () ĊĠĠĠĠĠĠĠ Ġwhile Ġ( people Iterator . hasNext ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpeople Iterator . next () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcounter ++ ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġcounter ĊĠĠĠ Ġ} Ċ }