package Ġuk . gov . just ice . digital . h mp ps . deli us api . service . contact Ċ Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . eq Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . never Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . times Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġorg . mockito . Inject Mocks Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . junit . jupiter . Mockito Extension Ċ import Ġuk . gov . just ice . digital . h mp ps . deli us api . entity . Contact Ċ import Ġuk . gov . just ice . digital . h mp ps . deli us api . entity . Event Ċ import Ġuk . gov . just ice . digital . h mp ps . deli us api . repository . Contact Repository Ċ import Ġuk . gov . just ice . digital . h mp ps . deli us api . repository . Event Repository Ċ import Ġuk . gov . just ice . digital . h mp ps . deli us api . util . Fake Ċ import Ġuk . gov . just ice . digital . h mp ps . deli us api . util . has Property Ċ import Ġjava . time . LocalDate Ċ Ċ @ Extend With ( Mockito Extension :: class ) Ċ class ĠContact En forcement Service Test Ġ{ ĊĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġcontact Repository : ĠContact Repository ĊĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġevent Repository : ĠEvent Repository ĊĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġsystem Contact Service : ĠSystem Contact Service ĊĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġcontact B reach Service : ĠContact B reach Service ĊĠ Ġ@ Inject Mocks Ġprivate Ġlateinit Ġvar Ġsubject : ĠContact En forcement Service ĊĊĠ Ġprivate Ġval Ġenforce ment Contact Ġ= ĠFake . contact () ĊĠ Ġprivate Ġlateinit Ġvar Ġcontact : ĠContact ĊĠ Ġprivate Ġval Ġnew F tc Count Ġ= ĠFake . count () ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Updating Ġfailure Ġto Ġcomp ly Ġwithout Ġevent `() Ġ{ ĊĠĠĠ Ġhaving Contact ( having Event Ġ= Ġfalse ) ĊĠĠĠ Ġwhen Updating Failure To Comp ly () ĊĠĠĠ Ġshould Update F tc Count ( false ) ĊĠĠĠ Ġshould Update B reach ( false ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Updating Ġfailure Ġto Ġcomp ly Ġwith Ġnon - national Ġstandards Ġcontact `() Ġ{ ĊĠĠĠ Ġhaving Contact ( having National Standard s Contact Ġ= Ġfalse ) ĊĠĠĠ Ġwhen Updating Failure To Comp ly () ĊĠĠĠ Ġshould Update F tc Count ( false ) ĊĠĠĠ Ġshould Update B reach ( false ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Updating Ġfailure Ġto Ġcomp ly Ġwithout Ġoutcome Ġbut Ġf tc Ġcount Ġnot Ġchanged `() Ġ{ ĊĠĠĠ Ġhaving Contact ( having Outcome Ġ= Ġfalse ) ĊĠĠĠ Ġhaving Current F tc Count Changed ( false ) ĊĠĠĠ Ġwhen Updating Failure To Comp ly () ĊĠĠĠ Ġshould Update F tc Count ( false ) ĊĠĠĠ Ġshould Update B reach ( false ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Updating Ġfailure Ġto Ġcomp ly Ġwithout Ġoutcome Ġand Ġf tc Ġcount Ġchanged `() Ġ{ ĊĠĠĠ Ġhaving Contact ( having Outcome Ġ= Ġfalse ) ĊĠĠĠ Ġhaving Current F tc Count Changed () ĊĠĠĠ Ġwhen Updating Failure To Comp ly () ĊĠĠĠ Ġshould Update F tc Count () ĊĠĠĠ Ġshould Update B reach ( false ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Updating Ġfailure Ġto Ġcomp ly Ġwithout Ġdis posal Ġand Ġf tc Ġcount Ġnot Ġchanged `() Ġ{ ĊĠĠĠ Ġhaving Contact ( having Dis posal Ġ= Ġfalse ) ĊĠĠĠ Ġwhen Updating Failure To Comp ly () ĊĠĠĠ Ġshould Update F tc Count ( false ) ĊĠĠĠ Ġshould Update B reach ( false ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Updating Ġfailure Ġto Ġcomp ly Ġbut Ġcompliant Ġacceptable `() Ġ{ ĊĠĠĠ Ġhaving Contact ( having Comp liant Accept able Ġ= Ġtrue ) ĊĠĠĠ Ġwhen Updating Failure To Comp ly () ĊĠĠĠ Ġshould Update F tc Count ( false ) ĊĠĠĠ Ġshould Update B reach ( false ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Updating Ġfailure Ġto Ġcomp ly Ġand Ġf tc Ġcount Ġchanged Ġbut Ġenforce ment Ġalready Ġiniti ates Ġa Ġb reach `() Ġ{ ĊĠĠĠ Ġhaving Contact ( having En forcement Contact Type Ġ= ĠWell Known Contact Type . BRE ACH _ INIT ) ĊĠĠĠ Ġhaving Current F tc Count Changed () ĊĠĠĠ Ġwhen Updating Failure To Comp ly () ĊĠĠĠ Ġshould Update F tc Count ( true ) ĊĠĠĠ Ġshould Update B reach ( false ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Updating Ġfailure Ġto Ġcomp ly Ġbut Ġevent Ġalready Ġin Ġb reach Ġby Ġflag `() Ġ{ ĊĠĠĠ Ġhaving Contact ( having Event Already In B reach By Flag Ġ= Ġtrue ) ĊĠĠĠ Ġwhen Updating Failure To Comp ly () ĊĠĠĠ Ġshould Update F tc Count ( false ) ĊĠĠĠ Ġshould Update B reach ( false ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Updating Ġfailure Ġto Ġcomp ly Ġbut Ġevent Ġalready Ġin Ġb reach Ġby Ġdate `() Ġ{ ĊĠĠĠ Ġhaving Contact ( having Event Already In B reach By Date Ġ= Ġtrue ) ĊĠĠĠ Ġwhen Updating Failure To Comp ly () ĊĠĠĠ Ġshould Update F tc Count ( false ) ĊĠĠĠ Ġshould Update B reach ( false ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Updating Ġfailure Ġto Ġcomp ly Ġbut Ġevent Ġhas Ġno Ġsentence `() Ġ{ ĊĠĠĠ Ġhaving Contact ( having Sentence Type Ġ= Ġfalse ) ĊĠĠĠ Ġwhen Updating Failure To Comp ly () ĊĠĠĠ Ġshould Update F tc Count ( false ) ĊĠĠĠ Ġshould Update B reach ( false ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Updating Ġfailure Ġto Ġcomp ly Ġbut Ġf tc Ġlimit Ġnot Ġbre ached `() Ġ{ ĊĠĠĠ Ġhaving Contact ( having F tc Limit Bre ached Ġ= Ġfalse ) ĊĠĠĠ Ġwhen Updating Failure To Comp ly () ĊĠĠĠ Ġshould Update F tc Count ( false ) ĊĠĠĠ Ġshould Update B reach ( false ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Updating Ġfailure Ġto Ġcomp ly Ġbut Ġenforce ment Ġunder Ġreview `() Ġ{ ĊĠĠĠ Ġhaving Contact () ĊĠĠĠ Ġhaving En forcement Under Review () ĊĠĠĠ Ġwhen Updating Failure To Comp ly () ĊĠĠĠ Ġshould Update F tc Count ( false ) ĊĠĠĠ Ġshould Update B reach ( false ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Updating Ġfailure Ġto Ġcomp ly `() Ġ{ ĊĠĠĠ Ġhaving Contact () ĊĠĠĠ Ġhaving En forcement Under Review ( false ) ĊĠĠĠ Ġhaving En forcement Contact () ĊĠĠĠ Ġwhen Updating Failure To Comp ly () ĊĠĠĠ Ġshould Update F tc Count ( false ) ĊĠĠĠ Ġshould Update B reach ( true ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Updating Ġfailure Ġto Ġcomp ly Ġfor Ġrelease Ġfrom Ġcust ody Ġcontact `() Ġ{ ĊĠĠĠ Ġhaving Contact ( having Contact Type Ġ= ĠWell Known Contact Type . RELEASE _ FROM _ C UST ODY , Ġhaving National Standard s Contact Ġ= Ġfalse ) ĊĠĠĠ Ġhaving Current F tc Count Changed () ĊĠĠĠ Ġwhen Updating Failure To Comp ly () ĊĠĠĠ Ġshould Update F tc Count ( true ) ĊĠĠĠ Ġshould Update B reach ( false ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġhaving Contact ( ĊĠĠĠ Ġhaving Contact Type : ĠWell Known Contact Type ? Ġ= Ġnull , ĊĠĠĠ Ġhaving Event : ĠBoolean Ġ= Ġtrue , ĊĠĠĠ Ġhaving Event Already In B reach By Flag : ĠBoolean Ġ= Ġfalse , ĊĠĠĠ Ġhaving Event Already In B reach By Date : ĠBoolean Ġ= Ġfalse , ĊĠĠĠ Ġhaving Outcome : ĠBoolean Ġ= Ġtrue , ĊĠĠĠ Ġhaving Action Required : ĠBoolean Ġ= Ġtrue , ĊĠĠĠ Ġhaving Comp liant Accept able : ĠBoolean Ġ= Ġfalse , ĊĠĠĠ Ġhaving Dis posal : ĠBoolean Ġ= Ġtrue , ĊĠĠĠ Ġhaving Sentence Type : ĠBoolean Ġ= Ġtrue , ĊĠĠĠ Ġhaving National Standard s Contact : ĠBoolean Ġ= Ġtrue , ĊĠĠĠ Ġhaving En forcement Contact Type : ĠWell Known Contact Type Ġ= ĠWell Known Contact Type . BRE ACH _ CON CL UDE D , ĊĠĠĠ Ġhaving F tc Limit Bre ached : ĠBoolean Ġ= Ġtrue , ĊĠ Ġ) Ġ{ ĊĠĠĠ Ġcontact Ġ= ĠFake . contact (). apply Ġ{ ĊĠĠĠĠĠ Ġdate Ġ= ĠLocalDate . of ( 2 0 2 1 , Ġ 3 , Ġ 1 8 ) ĊĠĠĠĠĠ Ġtype . apply Ġ{ ĊĠĠĠĠĠĠĠ Ġnational Standard s Contact Ġ= Ġhaving National Standard s Contact ĊĠĠĠĠĠĠĠ Ġif Ġ( having Contact Type Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġcode Ġ= Ġhaving Contact Type . code ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġif Ġ(! having Event ) Ġevent Ġ= Ġnull ĊĠĠĠĠĠ Ġif Ġ(! having Outcome ) Ġoutcome Ġ= Ġnull ĊĠĠĠĠĠ Ġevent ?. apply Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ(! having Dis posal ) Ġdis posal Ġ= Ġnull ĊĠĠĠĠĠĠĠ Ġin B reach Ġ= Ġhaving Event Already In B reach By Flag ĊĠĠĠĠĠĠĠ Ġb reach End Ġ= Ġif Ġ( having Event Already In B reach By Date ) ĠLocalDate . of ( 2 0 2 1 , Ġ 3 , Ġ 1 9 ) Ġelse Ġnull ĊĠĠĠĠĠĠĠ Ġf tc Count Ġ= Ġif Ġ( having F tc Limit Bre ached ) Ġ 1 0 0 Ġelse Ġ 9 9 ĊĠĠĠĠĠĠĠ Ġdis posal ?. apply Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġif Ġ(! having Sentence Type ) Ġtype ?. sentence Type Ġ= Ġnull ĊĠĠĠĠĠĠĠĠĠ Ġtype ?. failure To Comp ly Limit Ġ= Ġ 1 0 0 ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġoutcome ?. apply Ġ{ ĊĠĠĠĠĠĠĠ Ġaction Required Ġ= Ġhaving Action Required ĊĠĠĠĠĠĠĠ Ġcompliant Accept able Ġ= Ġhaving Comp liant Accept able ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġenforce ment ?. apply Ġ{ ĊĠĠĠĠĠĠĠ Ġaction ?. contact Type ?. code Ġ= Ġhaving En forcement Contact Type . code ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġhaving Current F tc Count Changed ( having : ĠBoolean Ġ= Ġtrue ) Ġ{ ĊĠĠĠ Ġval Ġevent Ġ= Ġcontact . event !! ĊĠĠĠ Ġval Ġcount Ġ= Ġif Ġ( having ) Ġnew F tc Count Ġelse Ġevent . ft c Count ĊĠĠĠ Ġwhenever ( contact Repository . count Failure To Comp ly ( eq ( event . id ), Ġany ())) ĊĠĠĠĠĠ Ġ. thenReturn ( count ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġhaving En forcement Under Review ( having : ĠBoolean Ġ= Ġtrue ) Ġ{ ĊĠĠĠ Ġval Ġevent Ġ= Ġcontact . event !! ĊĠĠĠ Ġwhenever ( contact Repository . count En forcement Under Review ( event . id , ĠWell Known Contact Type . RE VIEW _ EN FORCE MENT _ STATUS . code , Ġevent . bre ach End )) ĊĠĠĠĠĠ Ġ. thenReturn ( if Ġ( having ) Ġ 1 Ġelse Ġ 0 ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġhaving En forcement Contact () Ġ{ ĊĠĠĠ Ġwhenever ( system Contact Service . create Linked System Contact ( contact , ĠWell Known Contact Type . RE VIEW _ EN FORCE MENT _ STATUS )) ĊĠĠĠĠĠ Ġ. thenReturn ( en forcement Contact ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġwhen Updating Failure To Comp ly () Ġ= Ġsubject . update Failure To Comp ly ( contact ) ĊĊĠ Ġprivate Ġfun Ġshould Update F tc Count ( should : ĠBoolean Ġ= Ġtrue ) Ġ{ ĊĠĠĠ Ġif Ġ( should ) Ġ{ ĊĠĠĠĠĠ Ġverify ( event Repository , Ġtimes ( 1 )). save And Flush ( contact . event ) ĊĠĠĠĠĠ ĠassertThat ( contact . event !! ) ĊĠĠĠĠĠĠĠ Ġ. has Property ( Event :: ft c Count , Ġnew F tc Count ) ĊĠĠĠ Ġ} Ġelse Ġverify ( event Repository , Ġnever ()). save And Flush ( any ()) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġshould Update B reach ( should : ĠBoolean Ġ= Ġtrue ) Ġ{ ĊĠĠĠ Ġif Ġ( should ) Ġverify ( contact B reach Service , Ġtimes ( 1 )). update B reach On Insert Contact ( en forcement Contact ) ĊĠĠĠ Ġelse Ġverify ( contact B reach Service , Ġnever ()). update B reach On Insert Contact ( any ()) ĊĠ Ġ} Ċ } Ċ