package Ġuk . gov . just ice . digital . h mp ps . h mp ps inter vention ss ervice . service Ċ Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . argument Captor Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . eq Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Zero Interactions Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġorg . assertj . core . api . Assertions Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . assert Throws Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps inter vention ss ervice . component . Email Sender Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps inter vention ss ervice . events . Appointment Event Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps inter vention ss ervice . events . Appointment EventType Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps inter vention ss ervice . jpa . entity . At tended Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps inter vention ss ervice . jpa . entity . Sample Data Ċ import Ġjava . time . Offset DateTime Ċ import Ġjava . util . UUID Ċ Ċ class ĠNotify Appointment Service Test Ġ{ ĊĠ Ġprivate Ġval Ġemail Sender Ġ= Ġmock < Email Sender >() ĊĠ Ġprivate Ġval Ġh mp ps Auth Service Ġ= Ġmock < H MP PS Auth Service >() ĊĊĠ Ġprivate Ġfun Ġappointment Event ( type : ĠAppointment EventType , Ġnotify PP : ĠBoolean ): ĠAppointment Event Ġ{ ĊĠĠĠ Ġreturn ĠAppointment Event ( ĊĠĠĠĠĠ Ġ" source ", ĊĠĠĠĠĠ Ġtype , ĊĠĠĠĠĠ ĠSample Data . sample Action Plan Appointment ( ĊĠĠĠĠĠĠĠ Ġid Ġ= ĠUUID . fromString (" 4 2 c 7 d 2 6 7 - 0 7 7 6 - 4 2 7 2 - a 8 e 8 - a 6 7 3 bfe 3 0 d 0 d "), ĊĠĠĠĠĠĠĠ Ġaction Plan Ġ= ĠSample Data . sample Action Plan ( ĊĠĠĠĠĠĠĠĠĠ Ġref erral Ġ= ĠSample Data . sample Ref erral ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" X 1 2 3 4 5 6 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" Har mony ĠL iving ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġid Ġ= ĠUUID . fromString (" 6 8 df 9 f 6 c - 3 fcb - 4 ec 6 - 8 fcf - 9 6 5 5 1 cd 9 b 0 8 0 "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreference Number Ġ= Ġ" HAS 7 1 2 6 3 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsent At Ġ= ĠOffset DateTime . parse (" 2 0 2 0 - 1 2 - 0 4 T 1 0 : 4 2 : 4 3 + 0 0 : 0 0 "), ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠ Ġcreated By Ġ= ĠSample Data . sample Auth User (), ĊĠĠĠĠĠĠĠ Ġat tended Ġ= ĠAtt ended . YES , ĊĠĠĠĠĠ Ġ), ĊĠĠĠĠĠ Ġ" http :// localhost : 8 0 8 0 / appointment / 4 2 c 7 d 2 6 7 - 0 7 7 6 - 4 2 7 2 - a 8 e 8 - a 6 7 3 bfe 3 0 d 0 d ", ĊĠĠĠĠĠ Ġnotify PP , ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġnotify Service (): ĠNotify Appointment Service Ġ{ ĊĠĠĠ Ġreturn ĠNotify Appointment Service ( ĊĠĠĠĠĠ Ġ" template ", ĊĠĠĠĠĠ Ġ" template ", ĊĠĠĠĠĠ Ġ" http :// example . com ", ĊĠĠĠĠĠ Ġ"/ ref erral /{ id }/ progress ", ĊĠĠĠĠĠ Ġemail Sender , ĊĠĠĠĠĠ Ġh mp ps Auth Service , ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` appointment Ġatt endance Ġrecorded Ġevent Ġdoes Ġnot Ġsend Ġemail Ġwhen Ġuser Ġdetails Ġare Ġnot Ġavailable `() Ġ{ ĊĠĠĠ Ġwhenever ( h mp ps Auth Service . getUser Detail ( any ())). then Throw ( RuntimeException :: class . java ) ĊĠĠĠ ĠassertThrows < RuntimeException > Ġ{ ĊĠĠĠĠĠ Ġnotify Service (). on Application Event ( appointment Event ( Appointment EventType . ATT END ANCE _ REC OR DED , Ġtrue )) ĊĠĠĠ Ġ} ĊĠĠĠ Ġverify Zero Interactions ( email Sender ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` appointment Ġatt endance Ġrecorded Ġevent Ġdoes Ġnot Ġsend Ġemail Ġwhen Ġnotify PP Ġis Ġfalse `() Ġ{ ĊĠĠĠ Ġnotify Service (). on Application Event ( appointment Event ( Appointment EventType . ATT END ANCE _ REC OR DED , Ġfalse )) ĊĠĠĠ Ġverify Zero Interactions ( email Sender ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` appointment Ġatt endance Ġrecorded Ġevent Ġcalls Ġemail Ġclient `() Ġ{ ĊĠĠĠ Ġwhenever ( h mp ps Auth Service . getUser Detail ( any ())). thenReturn ( User Detail (" abc ", Ġ" abc @ abc . com ")) ĊĊĠĠĠ Ġnotify Service (). on Application Event ( appointment Event ( Appointment EventType . ATT END ANCE _ REC OR DED , Ġtrue )) ĊĠĠĠ Ġval Ġpersonal isation Captor Ġ= Ġargument Captor < Map < String , ĠString >>() ĊĠĠĠ Ġverify ( email Sender ). send Email ( eq (" template "), Ġeq (" abc @ abc . com "), Ġpersonal isation Captor . capture ()) ĊĠĠĠ ĠAssertions . assertThat ( personal isation Captor . first Value [" pp FirstName "]). isEqualTo (" abc ") ĊĠĠĠ ĠAssertions . assertThat ( personal isation Captor . first Value [" reference Number "]). isEqualTo (" HAS 7 1 2 6 3 ") ĊĠĠĠ ĠAssertions . assertThat ( personal isation Captor . first Value [" attendance Url "]). isEqualTo (" http :// example . com / ref erral / 6 8 df 9 f 6 c - 3 fcb - 4 ec 6 - 8 fcf - 9 6 5 5 1 cd 9 b 0 8 0 / progress ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` appointment Ġbehaviour Ġrecorded Ġevent Ġdoes Ġnot Ġsend Ġemail Ġwhen Ġuser Ġdetails Ġare Ġnot Ġavailable `() Ġ{ ĊĠĠĠ Ġwhenever ( h mp ps Auth Service . getUser Detail ( any ())). then Throw ( RuntimeException :: class . java ) ĊĠĠĠ ĠassertThrows < RuntimeException > Ġ{ ĊĠĠĠĠĠ Ġnotify Service (). on Application Event ( appointment Event ( Appointment EventType . BE HAV IO UR _ REC OR DED , Ġtrue )) ĊĠĠĠ Ġ} ĊĠĠĠ Ġverify Zero Interactions ( email Sender ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` appointment Ġbehaviour Ġrecorded Ġevent Ġdoes Ġnot Ġsend Ġemail Ġwhen Ġnotify PP Ġis Ġfalse `() Ġ{ ĊĠĠĠ Ġnotify Service (). on Application Event ( appointment Event ( Appointment EventType . BE HAV IO UR _ REC OR DED , Ġfalse )) ĊĠĠĠ Ġverify Zero Interactions ( email Sender ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` appointment Ġbehaviour Ġrecorded Ġevent Ġcalls Ġemail Ġclient `() Ġ{ ĊĠĠĠ Ġwhenever ( h mp ps Auth Service . getUser Detail ( any ())). thenReturn ( User Detail (" abc ", Ġ" abc @ abc . com ")) ĊĊĠĠĠ Ġnotify Service (). on Application Event ( appointment Event ( Appointment EventType . BE HAV IO UR _ REC OR DED , Ġtrue )) ĊĠĠĠ Ġval Ġpersonal isation Captor Ġ= Ġargument Captor < Map < String , ĠString >>() ĊĠĠĠ Ġverify ( email Sender ). send Email ( eq (" template "), Ġeq (" abc @ abc . com "), Ġpersonal isation Captor . capture ()) ĊĠĠĠ ĠAssertions . assertThat ( personal isation Captor . first Value [" pp FirstName "]). isEqualTo (" abc ") ĊĠĠĠ ĠAssertions . assertThat ( personal isation Captor . first Value [" reference Number "]). isEqualTo (" HAS 7 1 2 6 3 ") ĊĠĠĠ ĠAssertions . assertThat ( personal isation Captor . first Value [" session Url "]). isEqualTo (" http :// example . com / ref erral / 6 8 df 9 f 6 c - 3 fcb - 4 ec 6 - 8 fcf - 9 6 5 5 1 cd 9 b 0 8 0 / progress ") ĊĠ Ġ} Ċ } Ċ