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 . 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 . Nested Ċ 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 Entity Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . entities . Assessment Episode Entity Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . entities . Assessment Type Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . entities . Subject Entity Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . repositories . Assessment Repository Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . repositories . Episode Repository Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . repositories . Subject Repository Ċ import Ġuk . gov . just ice . digital . as sess ments . rest client . Assessment Update RestClient Ċ import Ġuk . gov . just ice . digital . as sess ments . rest client . Cour t Case RestClient Ċ import Ġuk . gov . just ice . digital . as sess ments . rest client . assessment update api . Update Assessment Answers Response Dto Ċ import Ġuk . gov . just ice . digital . as sess ments . rest client . assessment update api . ValidationError Dto Ċ import Ġuk . gov . just ice . digital . as sess ments . services . exceptions . Entity NotFoundException Ċ import Ġjava . time . LocalDateTime Ċ import Ġjava . util . UUID Ċ Ċ @ Extend With ( Mock K Extension :: class ) Ċ @ DisplayName (" Assessment ĠService ĠTests ") Ċ class ĠAssessment Service Complete Test Ġ{ ĊĠ Ġprivate Ġval Ġassessment Repository : ĠAssessment Repository Ġ= Ġmock k () ĊĠ Ġprivate Ġval Ġepisode Repository : ĠEp isode Repository Ġ= Ġmock k () ĊĠ Ġprivate Ġval Ġsubject Repository : ĠSubject Repository Ġ= Ġmock k () ĊĠ Ġprivate Ġval Ġquestion Service : ĠQuestion Service Ġ= Ġmock k () ĊĠ Ġprivate Ġval Ġcourt Case RestClient : ĠCour t Case RestClient Ġ= Ġmock k () ĊĠ Ġprivate Ġval Ġepisode Service : ĠEp isode Service Ġ= Ġmock k () ĊĠ Ġprivate Ġval Ġoff ender Service : ĠOff ender Service Ġ= Ġmock k () ĊĠ Ġprivate Ġval Ġassessment Update RestClient : ĠAssessment Update RestClient Ġ= Ġmock k () ĊĊĠ Ġprivate Ġval Ġassess ments Service Ġ= ĠAssessment Service ( ĊĠĠĠ Ġassessment Repository , ĊĠĠĠ Ġepisode Repository , ĊĠĠĠ Ġsubject Repository , ĊĠĠĠ Ġquestion Service , ĊĠĠĠ Ġepisode Service , ĊĠĠĠ Ġcourt Case RestClient , ĊĠĠĠ Ġassessment Update RestClient , ĊĠĠĠ Ġoff ender Service ĊĠ Ġ) ĊĊĠ Ġ@ Nested ĊĠ Ġ@ DisplayName (" comp leting Ġassess ments ") ĊĠ Ġinner Ġclass ĠComp leting As sess ments Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` close Ġepisode `() Ġ{ ĊĠĠĠĠĠ Ġval Ġassessment Ġ= Ġassessment Entity () ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( any ()) Ġ} Ġreturns Ġassessment ĊĠĠĠĠĠ Ġevery Ġ{ Ġepisode Repository . save ( any ()) Ġ} Ġreturns Ġassessment . episodes [ 0 ] ĊĠĠĠĠĠ Ġevery Ġ{ ĊĠĠĠĠĠĠĠ Ġassessment Update RestClient . complete Assessment ( 9 9 9 9 , Ġ 7 7 7 7 , ĠAssessment Type . SHORT _ FORM _ PS R ) ĊĠĠĠĠĠ Ġ} Ġreturns ĠUpdate Assessment Answers Response Dto ( 7 7 7 7 ) ĊĊĠĠĠĠĠ Ġval Ġepisode Ġ= Ġassess ments Service . close Current Episode ( 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 ")) ĊĊĠĠĠĠĠ Ġverify ( exact ly Ġ= Ġ 1 ) Ġ{ Ġepisode Repository . save ( any ()) Ġ} ĊĠĠĠĠĠ Ġverify ( exact ly Ġ= Ġ 1 ) Ġ{ Ġassessment Update RestClient . complete Assessment ( any (), Ġany (), Ġany (), Ġany ()) Ġ} ĊĠĠĠĠĠ ĠassertThat ( episode . ended ). isEqualTo Ign oring Minutes ( LocalDateTime . now ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` close Ġepisode Ġfor Ġassessment Ġwith Ġno Ġepisode s Ġthrows Ġexception `() Ġ{ ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( any ()) Ġ} Ġreturns Ġassessment With No Episode Entity () ĊĊĠĠĠĠĠ ĠassertThrows < Entity NotFoundException > Ġ{ Ġassess ments Service . close Current Episode ( 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 ")) Ġ} ĊĠĠĠĠĠ Ġverify ( exact ly Ġ= Ġ 0 ) Ġ{ Ġepisode Repository . save ( any ()) Ġ} ĊĠĠĠĠĠ Ġverify ( exact ly Ġ= Ġ 0 ) Ġ{ Ġassessment Update RestClient . complete Assessment ( any (), Ġany (), Ġany (), Ġany ()) Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` close Ġepisode Ġwith Ġo as ys Ġerrors Ġdoes Ġnot Ġclose Ġepisode `() Ġ{ ĊĠĠĠ Ġval Ġassessment Ġ= Ġassessment Entity () ĊĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( any ()) Ġ} Ġreturns Ġassessment ĊĠĠĠ Ġevery Ġ{ Ġepisode Repository . save ( any ()) Ġ} Ġreturns Ġassessment . episodes [ 0 ] ĊĠĠĠ Ġevery Ġ{ ĊĠĠĠĠĠ Ġassessment Update RestClient . complete Assessment ( 9 9 9 9 , Ġ 7 7 7 7 , ĠAssessment Type . SHORT _ FORM _ PS R ) ĊĠĠĠ Ġ} Ġreturns Ġo as ys Assessment Error () ĊĊĠĠĠ Ġval Ġepisode Ġ= Ġassess ments Service . close Current Episode ( 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 ")) ĊĊĠĠĠ Ġverify ( exact ly Ġ= Ġ 0 ) Ġ{ Ġepisode Repository . save ( any ()) Ġ} ĊĠĠĠ Ġverify ( exact ly Ġ= Ġ 1 ) Ġ{ Ġassessment Update RestClient . complete Assessment ( any (), Ġany (), Ġany (), Ġany ()) Ġ} ĊĠĠĠ ĠassertThat ( episode . ended ). isNull () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassessment Entity (): ĠAssessment Entity Ġ{ ĊĠĠĠ Ġval Ġsubject Ġ= ĠSubject Entity ( o as ys Off ender Pk Ġ= Ġ 9 9 9 9 ) ĊĠĠĠ Ġ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 _ Ġ= Ġmutable ListOf ( 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 Type Ġ= ĠAssessment Type . SHORT _ FORM _ PS R , ĊĠĠĠĠĠĠĠ Ġchange Reason Ġ= Ġ" Change Ġof ĠC ir cs Ġ 2 ", ĊĠĠĠĠĠĠĠ Ġo as ys Set Pk Ġ= Ġ 7 7 7 7 , ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĠĠĠ Ġreturn Ġassessment ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassessment With No Episode Entity (): ĠAssessment Entity Ġ{ ĊĠĠĠ Ġval Ġsubject Ġ= ĠSubject Entity ( o as ys Off ender Pk Ġ= Ġ 9 9 9 9 ) ĊĠĠĠ Ġval Ġepisode s Ġ= Ġmutable ListOf < Assessment Episode Entity >() ĊĠĠĠ Ġreturn Ġ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 _ Ġ= Ġmutable ListOf ( subject ) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġo as ys Assessment Error (): ĠUpdate Assessment Answers Response Dto Ġ{ ĊĠĠĠ Ġreturn ĠUpdate Assessment Answers Response Dto ( ĊĠĠĠĠĠĠ 7 7 7 7 , ĊĠĠĠĠĠ Ġset Of ( ĊĠĠĠĠĠĠĠ ĠValidationError Dto (" AS SESS MENT ", Ġnull , Ġ" Q 1 ", Ġ" O OPS ", Ġ" NO ", Ġfalse ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĠ Ġ} Ċ } Ċ