package Ġuk . gov . just ice . digital . as sess ments . services Ċ Ċ import Ġio . mock k . every Ċ import Ġio . mock k . junit 5 . Mock K Extension Ċ import Ġio . mock k . just Run Ċ import Ġio . mock k . mock k Ċ import Ġio . mock k . verify Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . DisplayName Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . assert Throws Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . entities . Assessment Schema Code Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . entities . as sess ments . Assessment Entity Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . entities . as sess ments . Assessment Episode Entity Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . entities . as sess ments . Author Entity Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . entities . as sess ments . Subject Entity Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . repositories . as sess ments . Assessment Repository Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . repositories . as sess ments . Episode Repository Ċ import Ġuk . gov . just ice . digital . as sess ments . services . exceptions . Cannot Close Episode Exception Ċ import Ġjava . time . LocalDate Ċ import Ġjava . time . LocalDateTime Ċ import Ġjava . util . UUID Ċ Ċ @ Extend With ( Mock K Extension :: class ) Ċ @ DisplayName (" Assessment ĠService ĠComplete ĠTests ") Ċ class ĠAssessment Update Service Close Test Ġ{ ĊĠ Ġprivate Ġval Ġassessment Repository : ĠAssessment Repository Ġ= Ġmock k () ĊĠ Ġprivate Ġval Ġepisode Repository : ĠEp isode Repository Ġ= Ġmock k () ĊĠ Ġprivate Ġval Ġquestion Service : ĠQuestion Service Ġ= Ġmock k () ĊĠ Ġprivate Ġval Ġrisk Predict ors Service : ĠR isk Predict ors Service Ġ= Ġmock k () ĊĠ Ġprivate Ġval Ġo as ys Assessment Update Service : ĠO as ys Assessment Update Service Ġ= Ġmock k () ĊĠ Ġprivate Ġval Ġassessment Service : ĠAssessment Service Ġ= Ġmock k () ĊĠ Ġprivate Ġval Ġauthor Service : ĠAuthor Service Ġ= Ġmock k () ĊĠ Ġprivate Ġval Ġaudit Service : ĠAudit Service Ġ= Ġmock k () ĊĠ Ġprivate Ġval Ġtelemetry Service : ĠTe lemetry Service Ġ= Ġmock k () ĊĊĠ Ġprivate Ġval Ġassessment Update Service Ġ= ĠAssessment Update Service ( ĊĠĠĠ Ġassessment Repository , ĊĠĠĠ Ġepisode Repository , ĊĠĠĠ Ġquestion Service , ĊĠĠĠ Ġrisk Predict ors Service , ĊĠĠĠ Ġo as ys Assessment Update Service , ĊĠĠĠ Ġassessment Service , ĊĠĠĠ Ġauthor Service , ĊĠĠĠ Ġaudit Service , ĊĠĠĠ Ġtelemetry Service ĊĠ Ġ) ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` clo ses Ġan Ġepisode `() Ġ{ ĊĠĠĠ Ġval Ġassessment Ġ= Ġassessment Entity () ĊĠĠĠ Ġjust Run Ġ{ Ġaudit Service . create Audit Event ( any (), Ġany (), Ġany (), Ġany (), Ġany (), Ġany ()) Ġ} ĊĠĠĠ Ġjust Run Ġ{ ĊĠĠĠĠĠ Ġtelemetry Service . track Assessment Event ( ĊĠĠĠĠĠĠĠ ĠTe lemetry EventType . AS SESS MENT _ CLOSED , ĊĠĠĠĠĠĠĠ Ġany (), ĊĠĠĠĠĠĠĠ Ġany (), ĊĠĠĠĠĠĠĠ Ġany (), ĊĠĠĠĠĠĠĠ Ġany (), ĊĠĠĠĠĠĠĠ Ġany () ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( any ()) Ġ} Ġreturns Ġassessment ĊĠĠĠ Ġevery Ġ{ Ġepisode Repository . save ( any ()) Ġ} Ġreturns Ġassessment . episodes [ 0 ] ĊĠĠĠ Ġval Ġassessment Episode Ġ= Ġassessment . episodes . first () ĊĠĠĠ Ġval Ġauthor Ġ= ĠAuthor Entity ( userId Ġ= Ġ" 1 ", ĠuserName Ġ= Ġ" USER ", Ġuser Auth Source Ġ= Ġ" source ", Ġuser FullName Ġ= Ġ" full Ġname ") ĊĠĠĠ Ġevery Ġ{ Ġauthor Service . get OrCreate Author () Ġ} Ġreturns Ġauthor ĊĊĠĠĠ Ġval Ġepisode Ġ= Ġassessment Update Service . close Episode ( assessment Episode ) ĊĊĠĠĠ Ġverify ( exact ly Ġ= Ġ 1 ) Ġ{ Ġepisode Repository . save ( any ()) Ġ} ĊĠĠĠ ĠassertThat ( episode . closed Date ). isEqualTo Ign oring Minutes ( LocalDateTime . now ()) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` throws Ġwhen Ġtrying Ġto Ġclose Ġa Ġcompleted Ġepisode `() Ġ{ ĊĠĠĠ Ġval Ġassessment Ġ= Ġassessment Entity () ĊĠĠĠ Ġval Ġepisode Ġ= Ġassessment . episodes [ 0 ] ĊĠĠĠ Ġepisode . endDate Ġ= ĠLocalDateTime . now () ĊĊĠĠĠ Ġjust Run Ġ{ Ġaudit Service . create Audit Event ( any (), Ġany (), Ġany (), Ġany (), Ġany (), Ġany ()) Ġ} ĊĠĠĠ Ġjust Run Ġ{ ĊĠĠĠĠĠ Ġtelemetry Service . track Assessment Event ( ĊĠĠĠĠĠĠĠ ĠTe lemetry EventType . AS SESS MENT _ CLOSED , ĊĠĠĠĠĠĠĠ Ġany (), ĊĠĠĠĠĠĠĠ Ġany (), ĊĠĠĠĠĠĠĠ Ġany (), ĊĠĠĠĠĠĠĠ Ġany (), ĊĠĠĠĠĠĠĠ Ġany () ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( any ()) Ġ} Ġreturns Ġassessment ĊĠĠĠ Ġevery Ġ{ Ġepisode Repository . save ( any ()) Ġ} Ġreturns Ġassessment . episodes [ 0 ] ĊĠĠĠ Ġval Ġassessment Episode Ġ= Ġassessment . episodes . first () ĊĠĠĠ Ġval Ġauthor Ġ= ĠAuthor Entity ( userId Ġ= Ġ" 1 ", ĠuserName Ġ= Ġ" USER ", Ġuser Auth Source Ġ= Ġ" source ", Ġuser FullName Ġ= Ġ" full Ġname ") ĊĠĠĠ Ġevery Ġ{ Ġauthor Service . get OrCreate Author () Ġ} Ġreturns Ġauthor ĊĊĠĠĠ ĠassertThrows < Cannot Close Episode Exception > Ġ{ Ġassessment Update Service . close Episode ( assessment Episode ) Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassessment Entity (): ĠAssessment Entity Ġ{ ĊĠĠĠ Ġval Ġsubject Ġ= ĠSubject Entity ( ĊĠĠĠĠĠ Ġo as ys Off ender Pk Ġ= Ġ 9 9 9 9 , ĊĠĠĠĠĠ Ġdate OfBirth Ġ= ĠLocalDate . of ( 1 9 8 9 , Ġ 1 , Ġ 1 ), ĊĠĠĠĠĠ Ġcr n Ġ= Ġ" X 1 3 4 5 " ĊĠĠĠ Ġ) ĊĠĠĠ Ġval Ġepisode s Ġ= Ġmutable ListOf < Assessment Episode Entity >() ĊĠĠĠ Ġval Ġassessment Ġ= ĠAssessment Entity ( ĊĠĠĠĠĠ Ġassessment Uuid Ġ= ĠUUID . fromString (" 7 b 4 de 6 d 5 - 4 4 8 8 - 4 c 2 9 - a 9 0 9 - 7 d 3 fdf 1 5 3 9 3 d "), ĊĠĠĠĠĠ Ġassessment Id Ġ= Ġ 1 , ĊĠĠĠĠĠ Ġepisode s Ġ= Ġepisode s , ĊĠĠĠĠĠ Ġsubject Ġ= Ġsubject ĊĠĠĠ Ġ) ĊĠĠĠ Ġepisode s . add ( ĊĠĠĠĠĠ ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠ Ġepisode Uuid Ġ= ĠUUID . fromString (" 6 6 9 cdd 1 0 - 1 0 6 1 - 4 2 ec - 9 0 d 4 - e 3 4 ba ab 1 9 5 6 6 "), ĊĠĠĠĠĠĠĠ Ġepisode Id Ġ= Ġ 1 2 3 4 , ĊĠĠĠĠĠĠĠ Ġassessment Ġ= Ġassessment , ĊĠĠĠĠĠĠĠ Ġassessment Schema Code Ġ= ĠAssessment Schema Code . RO SH , ĊĠĠĠĠĠĠĠ Ġchange Reason Ġ= Ġ" Change Ġof ĠC ir cs Ġ 2 ", ĊĠĠĠĠĠĠĠ Ġo as ys Set Pk Ġ= Ġ 7 7 7 7 , ĊĠĠĠĠĠĠĠ Ġcreated Date Ġ= ĠLocalDateTime . now (), ĊĠĠĠĠĠĠĠ Ġauthor Ġ= ĠAuthor Entity ( userId Ġ= Ġ" 1 ", ĠuserName Ġ= Ġ" USER ", Ġuser Auth Source Ġ= Ġ" source ", Ġuser FullName Ġ= Ġ" full Ġname "), ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĠĠĠ Ġreturn Ġassessment ĊĠ Ġ} Ċ } Ċ