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 . assertj . core . api . Assertions . assertThat Thrown By Ċ 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 . api . Create Assessment Dto Ċ import Ġuk . gov . just ice . digital . as sess ments . api . Off ender Dto Ċ import Ġuk . gov . just ice . digital . as sess ments . api . Update Assessment Episode Dto Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . entities . Answer Entity Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . entities . Answer Schema Entity Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . entities . Answer Schema Group Entity Ċ 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 . O AS ys Mapping Entity Ċ import Ġuk . gov . just ice . digital . as sess ments . jpa . entities . Question Schema Entity Ċ 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 . rest client . cour t case api . Cour t Case Ċ import Ġuk . gov . just ice . digital . as sess ments . services . dto . O as ys Answers Ċ import Ġuk . gov . just ice . digital . as sess ments . services . exceptions . Entity NotFoundException Ċ import Ġuk . gov . just ice . digital . as sess ments . services . exceptions . Update Closed Episode Exception Ċ import Ġjava . time . LocalDateTime Ċ import Ġjava . util . UUID Ċ Ċ @ Extend With ( Mock K Extension :: class ) Ċ @ DisplayName (" Assessment ĠService ĠTests ") Ċ class ĠAssessment Service 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 ĊĠ Ġ) ĊĊĠ Ġprivate Ġval Ġassessment Uuid Ġ= ĠUUID . randomUUID () ĊĠ Ġprivate Ġval Ġassessment Id Ġ= Ġ 1 L ĊĠ Ġprivate Ġval Ġassessment Type Ġ= ĠAssessment Type . SHORT _ FORM _ PS R ĊĊĠ Ġprivate Ġval Ġo as ys Off ender Pk Ġ= Ġ 1 L ĊĠ Ġprivate Ġval Ġcr n Ġ= Ġ" X 1 2 3 4 5 " ĊĠ Ġprivate Ġval Ġo as ys Set Pk Ġ= Ġ 1 L ĊĊĠ Ġprivate Ġval Ġepisode Id 1 Ġ= Ġ 1 L ĊĠ Ġprivate Ġval Ġepisode Id 2 Ġ= Ġ 2 L ĊĠ Ġprivate Ġval Ġepisode Id 3 Ġ= Ġ 3 L ĊĊĠ Ġprivate Ġval Ġepisode Uuid Ġ= ĠUUID . randomUUID () ĊĊĠ Ġprivate Ġval Ġexisting Question Uuid Ġ= ĠUUID . randomUUID () ĊĊĠ Ġprivate Ġval Ġquestion 1 Uuid Ġ= ĠUUID . randomUUID () ĊĠ Ġprivate Ġval Ġquestion 2 Uuid Ġ= ĠUUID . randomUUID () ĊĠ Ġprivate Ġval Ġquestion 3 Uuid Ġ= ĠUUID . randomUUID () ĊĠ Ġprivate Ġval Ġanswer 1 Uuid Ġ= ĠUUID . randomUUID () ĊĠ Ġprivate Ġval Ġanswer 2 Uuid Ġ= ĠUUID . randomUUID () ĊĠ Ġprivate Ġval Ġanswer 3 Uuid Ġ= ĠUUID . randomUUID () ĊĊĠ Ġprivate Ġval Ġcourt Code Ġ= Ġ" SH F 0 6 " ĊĠ Ġprivate Ġval Ġcase Number Ġ= Ġ" 6 6 8 9 1 1 2 5 3 " ĊĊĠ Ġprivate Ġval Ġdeli us Source Ġ= Ġ" DE LI US " ĊĠ Ġprivate Ġval Ġevent Id Ġ= Ġ 1 L ĊĊĠ Ġ@ Nested ĊĠ Ġ@ DisplayName (" creating Ġassess ments Ġfrom ĠDel ius ") ĊĠ Ġinner Ġclass ĠCreating Del ius As sess ments Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` create Ġnew Ġoff ender Ġwith Ġnew Ġassessment Ġfrom Ġdeli us Ġevent Ġid Ġand Ġcr n `() Ġ{ ĊĠĠĠĠĠ Ġevery Ġ{ Ġsubject Repository . findBy Source And Source Id And Cr n ( deli us Source , Ġevent Id . toString (), Ġcr n ) Ġ} Ġreturns Ġnull ĊĠĠĠĠĠ Ġevery Ġ{ Ġoff ender Service . get Off ender (" X 1 2 3 4 5 ") Ġ} Ġreturns ĠOff ender Dto () ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Update RestClient . create O as ys Off ender ( cr n Ġ= Ġcr n , Ġdeli us Event Ġ= Ġevent Id ) Ġ} Ġreturns Ġo as ys Off ender Pk ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Update RestClient . create Assessment ( o as ys Off ender Pk , Ġassessment Type ) Ġ} Ġreturns Ġo as ys Set Pk ĊĠĠĠĠĠ Ġevery Ġ{ Ġepisode Service . pre populate ( any ()) Ġ} Ġreturns Argument Ġ 0 ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . save ( any ()) Ġ} Ġreturns ĠAssessment Entity ( assessment Id Ġ= Ġassessment Id ) ĊĊĠĠĠĠĠ Ġassess ments Service . createNew Assessment ( ĊĠĠĠĠĠĠĠ ĠCreate Assessment Dto ( ĊĠĠĠĠĠĠĠĠĠ Ġdeli us EventId Ġ= Ġevent Id , ĊĠĠĠĠĠĠĠĠĠ Ġcr n Ġ= Ġcr n , ĊĠĠĠĠĠĠĠĠĠ Ġassessment Type Ġ= Ġassessment Type ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġverify ( exact ly Ġ= Ġ 1 ) Ġ{ Ġassessment Repository . save ( any ()) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` return Ġexisting Ġassessment Ġfrom Ġdeli us Ġevent Ġid Ġand Ġcr n Ġif Ġone Ġalready Ġexists `() Ġ{ ĊĠĠĠĠĠ Ġevery Ġ{ Ġsubject Repository . findBy Source And Source Id And Cr n ( deli us Source , Ġevent Id . toString (), Ġcr n ) Ġ} Ġreturns ĊĠĠĠĠĠĠĠ ĠSubject Entity ( assessment Ġ= ĠAssessment Entity ( assessment Id Ġ= Ġassessment Id , Ġassessment Uuid Ġ= Ġassessment Uuid )) ĊĊĠĠĠĠĠ Ġval Ġassessment Dto Ġ= ĊĠĠĠĠĠĠĠ Ġassess ments Service . createNew Assessment ( ĊĠĠĠĠĠĠĠĠĠ ĠCreate Assessment Dto ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeli us EventId Ġ= Ġevent Id , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcr n Ġ= Ġcr n , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġassessment Type Ġ= Ġassessment Type ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( assessment Dto . assessment Uuid ). isEqualTo ( assessment Uuid ) ĊĠĠĠĠĠ Ġverify ( exact ly Ġ= Ġ 0 ) Ġ{ Ġassessment Repository . save ( any ()) Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` throw Ġexception Ġif Ġcr n Ġis Ġnull `() Ġ{ ĊĠĠĠ ĠassertThrows < IllegalStateException > Ġ{ ĊĠĠĠĠĠ Ġassess ments Service . createNew Assessment ( ĊĠĠĠĠĠĠĠ ĠCreate Assessment Dto ( ĊĠĠĠĠĠĠĠĠĠ Ġdeli us EventId Ġ= Ġevent Id , ĊĠĠĠĠĠĠĠĠĠ Ġcr n Ġ= Ġnull , ĊĠĠĠĠĠĠĠĠĠ Ġassessment Type Ġ= Ġassessment Type ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġverify ( exact ly Ġ= Ġ 0 ) Ġ{ Ġassessment Repository . save ( any ()) Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` throw Ġexception Ġif Ġdeli us Ġevent Ġid Ġis Ġnull `() Ġ{ ĊĠĠĠ ĠassertThrows < IllegalStateException > Ġ{ ĊĠĠĠĠĠ Ġassess ments Service . createNew Assessment ( ĊĠĠĠĠĠĠĠ ĠCreate Assessment Dto ( ĊĠĠĠĠĠĠĠĠĠ Ġdeli us EventId Ġ= Ġnull , ĊĠĠĠĠĠĠĠĠĠ Ġcr n Ġ= Ġcr n , ĊĠĠĠĠĠĠĠĠĠ Ġassessment Type Ġ= Ġassessment Type ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġverify ( exact ly Ġ= Ġ 0 ) Ġ{ Ġassessment Repository . save ( any ()) Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` throw Ġexception Ġif Ġoff ender Ġis Ġnot Ġreturned Ġfrom ĠDel ius `() Ġ{ ĊĠĠĠ Ġevery Ġ{ Ġsubject Repository . findBy Source And Source Id And Cr n ( deli us Source , Ġevent Id . toString (), Ġcr n ) Ġ} Ġreturns Ġnull ĊĠĠĠ Ġevery Ġ{ Ġoff ender Service . get Off ender (" X 1 2 3 4 5 ") Ġ} Ġthrows ĠEntity NotFoundException ("") ĊĊĠĠĠ ĠassertThrows < Entity NotFoundException > Ġ{ ĊĠĠĠĠĠ Ġassess ments Service . createNew Assessment ( ĊĠĠĠĠĠĠĠ ĠCreate Assessment Dto ( ĊĠĠĠĠĠĠĠĠĠ Ġdeli us EventId Ġ= Ġevent Id , ĊĠĠĠĠĠĠĠĠĠ Ġcr n Ġ= Ġcr n , ĊĠĠĠĠĠĠĠĠĠ Ġassessment Type Ġ= Ġassessment Type ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġverify ( exact ly Ġ= Ġ 0 ) Ġ{ Ġassessment Repository . save ( any ()) Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġ@ DisplayName (" creating Ġassess ments Ġfrom Ġcourt ") ĊĠ Ġinner Ġclass ĠCreating Cour t As sess ments Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` create Ġnew Ġassessment Ġfrom Ġcourt `() Ġ{ ĊĠĠĠĠĠ Ġevery Ġ{ ĊĠĠĠĠĠĠĠ Ġsubject Repository . findBy Source And Source Id ( ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Service . cour t Source , ĊĠĠĠĠĠĠĠĠĠ Ġ"$ cour t Code |$ case Number " ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ} Ġreturns Ġnull ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . save ( any ()) Ġ} Ġreturns ĠAssessment Entity ( assessment Id Ġ= Ġassessment Id ) ĊĠĠĠĠĠ Ġevery Ġ{ Ġcourt Case RestClient . getC our t Case ( cour t Code , Ġcase Number ) Ġ} Ġreturns ĠCour t Case ( cr n Ġ= Ġcr n ) ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Update RestClient . create O as ys Off ender ( cr n ) Ġ} Ġreturns Ġo as ys Off ender Pk ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Update RestClient . create Assessment ( o as ys Off ender Pk , Ġassessment Type ) Ġ} Ġreturns Ġo as ys Set Pk ĊĠĠĠĠĠ Ġevery Ġ{ Ġepisode Service . pre populate ( any ()) Ġ} Ġreturns Argument Ġ 0 ĊĊĠĠĠĠĠ Ġassess ments Service . createNew Assessment ( ĊĠĠĠĠĠĠĠ ĠCreate Assessment Dto ( ĊĠĠĠĠĠĠĠĠĠ Ġcourt Code Ġ= Ġcourt Code , ĊĠĠĠĠĠĠĠĠĠ Ġcase Number Ġ= Ġcase Number , ĊĠĠĠĠĠĠĠĠĠ Ġassessment Type Ġ= Ġassessment Type ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġverify ( exact ly Ġ= Ġ 1 ) Ġ{ Ġassessment Repository . save ( any ()) Ġ} ĊĠĠĠĠĠ Ġverify ( exact ly Ġ= Ġ 1 ) Ġ{ Ġcourt Case RestClient . getC our t Case ( cour t Code , Ġcase Number ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` return Ġexisting Ġassessment Ġif Ġone Ġexists Ġfrom Ġcourt `() Ġ{ ĊĠĠĠĠĠ Ġevery Ġ{ ĊĠĠĠĠĠĠĠ Ġsubject Repository . findBy Source And Source Id ( ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Service . cour t Source , ĊĠĠĠĠĠĠĠĠĠ Ġ"$ cour t Code |$ case Number " ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ} Ġreturns ĠSubject Entity ( assessment Ġ= ĠAssessment Entity ( assessment Id Ġ= Ġ 1 )) ĊĊĠĠĠĠĠ Ġassess ments Service . createNew Assessment ( ĊĠĠĠĠĠĠĠ ĠCreate Assessment Dto ( ĊĠĠĠĠĠĠĠĠĠ Ġcourt Code Ġ= Ġcourt Code , ĊĠĠĠĠĠĠĠĠĠ Ġcase Number Ġ= Ġcase Number , ĊĠĠĠĠĠĠĠĠĠ Ġassessment Type Ġ= ĠAssessment Type . SHORT _ FORM _ PS R ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġverify ( exact ly Ġ= Ġ 0 ) Ġ{ Ġassessment Repository . save ( any ()) Ġ} ĊĠĠĠĠĠ Ġverify ( exact ly Ġ= Ġ 0 ) Ġ{ Ġcourt Case RestClient . getC our t Case ( cour t Code , Ġcase Number ) Ġ} ĊĠĠĠĠĠ Ġverify ( exact ly Ġ= Ġ 0 ) Ġ{ Ġassessment Repository . save ( any ()) Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġ@ DisplayName (" episodes ") ĊĠ Ġinner Ġclass ĠCreating Episode Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` create Ġnew Ġepisode `() Ġ{ ĊĠĠĠĠĠ Ġval Ġassessment : ĠAssessment Entity Ġ= Ġmock k () ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment . assessment Uuid Ġ} Ġreturns Ġassessment Uuid ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment . assessment Id Ġ} Ġreturns Ġ 0 ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment . new Episode (" Change Ġof ĠC ir cs ", Ġassessment Type Ġ= Ġassessment Type ) Ġ} Ġreturns ĠAssessment Episode Entity ( episode Id Ġ= Ġepisode Id 1 , Ġassessment Ġ= Ġassessment ) ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġassessment ĊĠĠĠĠĠ Ġevery Ġ{ Ġepisode Service . pre populate ( any ()) Ġ} Ġreturns Argument Ġ 0 ĊĊĠĠĠĠĠ Ġval Ġepisode Dto Ġ= Ġassess ments Service . createNew Episode ( assessment Uuid , Ġ" Change Ġof ĠC ir cs ", Ġassessment Type ) ĊĊĠĠĠĠĠ ĠassertThat ( episode Dto . assessment Uuid ). isEqualTo ( assessment Uuid ) ĊĠĠĠĠĠ ĠassertThat ( episode Dto . episode Id ). isEqualTo ( episode Id 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` fetch Ġall Ġepisode s Ġfor Ġan Ġassessment `() Ġ{ ĊĠĠĠĠĠ Ġval Ġassessment Ġ= ĠAssessment Entity ( ĊĠĠĠĠĠĠĠ Ġassessment Id Ġ= Ġassessment Id , ĊĠĠĠĠĠĠĠ Ġepisode s Ġ= Ġmutable ListOf ( ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( episode Id Ġ= Ġepisode Id 1 , Ġchange Reason Ġ= Ġ" Change Ġof ĠC ir cs Ġ 1 "), ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( episode Id Ġ= Ġepisode Id 2 , Ġchange Reason Ġ= Ġ" Change Ġof ĠC ir cs Ġ 2 ") ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġassessment ĊĊĠĠĠĠĠ Ġval Ġepisode Dto s Ġ= Ġassess ments Service . get Assessment Episode s ( assessment Uuid ) ĊĠĠĠĠĠ ĠassertThat ( episode Dto s ). has Size ( 2 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` throw Ġexception Ġif Ġassessment Ġdoes Ġnot Ġexist `() Ġ{ ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġnull ĊĊĠĠĠĠĠ ĠassertThat Thrown By Ġ{ Ġassess ments Service . get Assessment Episode s ( assessment Uuid ) Ġ} ĊĠĠĠĠĠĠĠ Ġ. isInstanceOf ( Entity NotFoundException :: class . java ) ĊĠĠĠĠĠĠĠ Ġ. has Message (" Assessment Ġ$ assessment Uuid Ġnot Ġfound ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Ġlatest Ġassessment Ġepisode `() Ġ{ ĊĠĠĠĠĠ Ġval Ġassessment Ġ= ĠAssessment Entity ( ĊĠĠĠĠĠĠĠ Ġassessment Id Ġ= Ġassessment Id , ĊĠĠĠĠĠĠĠ Ġepisode s Ġ= Ġmutable ListOf ( ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( episode Id Ġ= Ġepisode Id 1 , Ġchange Reason Ġ= Ġ" Change Ġof ĠC ir cs Ġ 1 ", ĠendDate Ġ= ĠLocalDateTime . now (). minus Days ( 1 )), ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( episode Id Ġ= Ġepisode Id 2 , Ġchange Reason Ġ= Ġ" Change Ġof ĠC ir cs Ġ 2 ") ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġassessment ĊĊĠĠĠĠĠ Ġval Ġepisode Dto Ġ= Ġassess ments Service . getCurrent Assessment Episode ( assessment Uuid ) ĊĠĠĠĠĠ ĠassertThat ( episode Dto . episode Id ). isEqualTo ( episode Id 2 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Ġcurrent Ġepisode Ġthrows Ġexception Ġif Ġassessment Ġdoes Ġnot Ġexist `() Ġ{ ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġnull ĊĊĠĠĠĠĠ ĠassertThat Thrown By Ġ{ Ġassess ments Service . getCurrent Assessment Episode ( assessment Uuid ) Ġ} ĊĠĠĠĠĠĠĠ Ġ. isInstanceOf ( Entity NotFoundException :: class . java ) ĊĠĠĠĠĠĠĠ Ġ. has Message (" Assessment Ġ$ assessment Uuid Ġnot Ġfound ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Ġcurrent Ġepisode Ġthrows Ġexception Ġif Ġno Ġcurrent Ġepisode Ġexists `() Ġ{ ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġnull ĊĊĠĠĠĠĠ ĠassertThat Thrown By Ġ{ Ġassess ments Service . getCurrent Assessment Episode ( assessment Uuid ) Ġ} ĊĠĠĠĠĠĠĠ Ġ. isInstanceOf ( Entity NotFoundException :: class . java ) ĊĠĠĠĠĠĠĠ Ġ. has Message (" Assessment Ġ$ assessment Uuid Ġnot Ġfound ") ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġ@ DisplayName (" update Ġepisode ") ĊĠ Ġinner Ġclass ĠUpdate Answers Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` update Ġepisode Ġthrows Ġexception Ġif Ġepisode Ġdoes Ġnot Ġexist `() Ġ{ ĊĊĠĠĠĠĠ Ġval Ġassessment Ġ= ĠAssessment Entity ( ĊĠĠĠĠĠĠĠ Ġassessment Id Ġ= Ġassessment Id , ĊĠĠĠĠĠĠĠ Ġepisode s Ġ= Ġmutable ListOf ( ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( episode Uuid Ġ= ĠUUID . randomUUID (), Ġepisode Id Ġ= Ġepisode Id 2 , Ġchange Reason Ġ= Ġ" Change Ġof ĠC ir cs Ġ 2 ") ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġval Ġupdated Answers Ġ= ĠUpdate Assessment Episode Dto ( map Of ()) ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġassessment ĊĊĠĠĠĠĠ ĠassertThat Thrown By Ġ{ Ġassess ments Service . update Episode ( assessment Uuid , Ġepisode Uuid , Ġupdated Answers ) Ġ} ĊĠĠĠĠĠĠĠ Ġ. isInstanceOf ( Entity NotFoundException :: class . java ) ĊĠĠĠĠĠĠĠ Ġ. has Message (" No ĠEp isode Ġ$ episode Uuid Ġfor Ġ$ assessment Uuid ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` add Ġnew Ġanswers Ġto Ġexisting Ġquestion Ġfor Ġan Ġepisode `() Ġ{ ĊĠĠĠĠĠ Ġval Ġanswers Ġ= Ġmutable Map Of ( ĊĠĠĠĠĠĠĠ Ġexisting Question Uuid Ġto ĠAnswer Entity (" free Ġtext ") ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġval Ġassessment Ġ= Ġassessment Entity ( answers ) ĊĊĠĠĠĠĠ Ġval Ġnew Question Uuid Ġ= ĠUUID . randomUUID () ĊĠĠĠĠĠ Ġval Ġupdated Answers Ġ= ĠUpdate Assessment Episode Dto ( ĊĠĠĠĠĠĠĠ Ġmap Of ( new Question Uuid Ġto ĠlistOf (" tro users ")) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġassessment ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . save ( any ()) Ġ} Ġreturns Ġnull ĊĊĠĠĠĠĠ Ġval Ġepisode Dto Ġ= Ġassess ments Service . update Episode ( assessment Uuid , Ġepisode Uuid , Ġupdated Answers ) ĊĊĠĠĠĠĠ ĠassertThat ( episode Dto . answers ). has Size ( 2 ) ĊĠĠĠĠĠ Ġwith ( episode Dto . answers [ existing Question Uuid ] !! ) Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( size ). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( first ()). isEqualTo (" free Ġtext ") ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġwith ( episode Dto . answers [ new Question Uuid ] !! ) Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( size ). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( first ()). isEqualTo (" tro users ") ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` change Ġan Ġexisting Ġanswer Ġfor Ġan Ġepisode `() Ġ{ ĊĠĠĠĠĠ Ġval Ġanswers Ġ= Ġmutable Map Of ( ĊĠĠĠĠĠĠĠ Ġexisting Question Uuid Ġto ĠAnswer Entity (" free Ġtext ") ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġval Ġassessment Ġ= Ġassessment Entity ( answers ) ĊĊĠĠĠĠĠ Ġval Ġupdated Answers Ġ= ĠUpdate Assessment Episode Dto ( ĊĠĠĠĠĠĠĠ Ġmap Of ( existing Question Uuid Ġto ĠlistOf (" new Ġfree Ġtext ")) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġassessment ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . save ( any ()) Ġ} Ġreturns Ġnull ĊĊĠĠĠĠĠ Ġval Ġepisode Dto Ġ= Ġassess ments Service . update Episode ( assessment Uuid , Ġepisode Uuid , Ġupdated Answers ) ĊĊĠĠĠĠĠ ĠassertThat ( episode Dto . answers ). has Size ( 1 ) ĊĠĠĠĠĠ Ġwith ( episode Dto . answers [ existing Question Uuid ] !! ) Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( size ). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( first ()). isEqualTo (" new Ġfree Ġtext ") ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` remove Ġanswers Ġfor Ġan Ġexisting Ġquestion Ġfor Ġan Ġepisode `() Ġ{ ĊĠĠĠĠĠ Ġval Ġanswers Ġ= Ġmutable Map Of ( ĊĠĠĠĠĠĠĠ Ġexisting Question Uuid Ġto ĠAnswer Entity ( listOf (" free Ġtext ", Ġ" fruit Ġloops ", Ġ" bis cu its ")) ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġval Ġassessment Ġ= Ġassessment Entity ( answers ) ĊĊĠĠĠĠĠ Ġval Ġupdated Answers Ġ= ĠUpdate Assessment Episode Dto ( ĊĠĠĠĠĠĠĠ Ġmap Of ( existing Question Uuid Ġto ĠlistOf (" fruit Ġloops ", Ġ" cust ard ")) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġassessment ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . save ( any ()) Ġ} Ġreturns Ġnull ĊĊĠĠĠĠĠ Ġval Ġepisode Dto Ġ= Ġassess ments Service . update Episode ( assessment Uuid , Ġepisode Uuid , Ġupdated Answers ) ĊĊĠĠĠĠĠ ĠassertThat ( episode Dto . answers ). has Size ( 1 ) ĊĠĠĠĠĠ Ġwith ( episode Dto . answers [ existing Question Uuid ] !! ) Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( size ). isEqualTo ( 2 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( this ). contains All ( listOf (" fruit Ġloops ", Ġ" cust ard ")) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` do Ġnot Ġupdate Ġa Ġclosed Ġepisode `() Ġ{ ĊĠĠĠĠĠ Ġval Ġassessment Ġ= ĠAssessment Entity ( ĊĠĠĠĠĠĠĠ Ġassessment Id Ġ= Ġassessment Id , ĊĠĠĠĠĠĠĠ Ġepisode s Ġ= Ġmutable ListOf ( ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġepisode Uuid Ġ= Ġepisode Uuid , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġepisode Id Ġ= Ġepisode Id 2 , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠendDate Ġ= ĠLocalDateTime . now (). minus Days ( 1 ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġchange Reason Ġ= Ġ" Change Ġof ĠC ir cs Ġ 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġanswers Ġ= Ġmutable Map Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġexisting Question Uuid Ġto ĠAnswer Entity (" free Ġtext ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġassessment Ġ= ĠAssessment Entity ( assessment Uuid Ġ= Ġassessment Uuid ) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġassessment ĊĊĠĠĠĠĠ ĠassertThat Thrown By Ġ{ Ġassess ments Service . update Episode ( assessment Uuid , Ġepisode Uuid , ĠUpdate Assessment Episode Dto ( answers Ġ= Ġempty Map ())) Ġ} ĊĠĠĠĠĠĠĠ Ġ. isInstanceOf ( Update Closed Episode Exception :: class . java ) ĊĠĠĠĠĠĠĠ Ġ. has Message (" Cannot Ġupdate Ġclosed ĠEp isode Ġ$ episode Uuid Ġfor Ġassessment Ġ$ assessment Uuid ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` returns Ġvalidation Ġerrors Ġfrom ĠO AS ys `() Ġ{ ĊĠĠĠĠĠ Ġval Ġanswers Ġ= Ġmutable Map Of ( ĊĠĠĠĠĠĠĠ Ġexisting Question Uuid Ġto ĠAnswer Entity ( listOf (" free Ġtext ", Ġ" fruit Ġloops ", Ġ" bis cu its ")) ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġval Ġassessment Ġ= Ġassessment Entity With O as ys Off ender ( answers ) ĊĊĠĠĠĠĠ Ġval Ġo a Sys Mappings Ġ= Ġmutable ListOf < O AS ys Mapping Entity >() ĊĠĠĠĠĠ Ġval Ġquestion Ġ= ĠQuestion Schema Entity ( ĊĠĠĠĠĠĠĠ Ġquestion Schema Id Ġ= Ġ 9 , ĊĠĠĠĠĠĠĠ Ġquestion Schema Uuid Ġ= Ġexisting Question Uuid , ĊĠĠĠĠĠĠĠ Ġquestion Code Ġ= Ġ" question ", ĊĠĠĠĠĠĠĠ Ġquestion Text Ġ= Ġ" fav our ite Ġbreak fast Ġc ere al ?", ĊĠĠĠĠĠĠĠ Ġo as ys Mappings Ġ= Ġo a Sys Mappings ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġo a Sys Mappings . add ( ĊĠĠĠĠĠĠĠ ĠO AS ys Mapping Entity ( ĊĠĠĠĠĠĠĠĠĠ Ġmapping Id Ġ= Ġ 1 , ĊĠĠĠĠĠĠĠĠĠ Ġsection Code Ġ= Ġ" section 1 ", ĊĠĠĠĠĠĠĠĠĠ Ġlogical Page Ġ= Ġnull , ĊĠĠĠĠĠĠĠĠĠ Ġquestion Code Ġ= Ġ" Q 1 ", ĊĠĠĠĠĠĠĠĠĠ Ġquestion Schema Ġ= Ġquestion ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġquestion Service . getAll Questions () Ġ} Ġreturns ĠQuestion Schema Entities ( listOf ( question )) ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġassessment ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . save ( any ()) Ġ} Ġreturns Ġnull Ġ// Ġshould Ġsave Ġwhen Ġerrors ? ĊĠĠĠĠĠ Ġval Ġo as ys Error Ġ= ĠUpdate Assessment Answers Response Dto ( ĊĠĠĠĠĠĠĠĠ 7 7 7 7 , ĊĠĠĠĠĠĠĠ Ġset Of ( ĊĠĠĠĠĠĠĠĠĠ ĠValidationError Dto (" section 1 ", Ġnull , Ġ" Q 1 ", Ġ" O OPS ", Ġ" NO ", Ġfalse ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Update RestClient . update Assessment ( any (), Ġany (), Ġany (), Ġany (), Ġany (), Ġany ()) Ġ} Ġreturns Ġo as ys Error ĊĠĠĠĠĠ Ġ// ĠChrist , Ġwhat Ġa Ġlot Ġof Ġset Ġup ĊĊĠĠĠĠĠ Ġ// ĠApply Ġthe Ġupdate ĊĠĠĠĠĠ Ġval Ġupdated Answers Ġ= ĠUpdate Assessment Episode Dto ( ĊĠĠĠĠĠĠĠ Ġmap Of ( existing Question Uuid Ġto ĠlistOf (" fruit Ġloops ", Ġ" cust ard ")) ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġval Ġepisode Dto Ġ= Ġassess ments Service . update Episode ( assessment Uuid , Ġepisode Uuid , Ġupdated Answers ) ĊĊĠĠĠĠĠ Ġ// ĠUpdated Ġanswers Ġin Ġreturned ĠD TO ĊĠĠĠĠĠ ĠassertThat ( episode Dto . answers ). has Size ( 1 ) ĊĠĠĠĠĠ Ġwith ( episode Dto . answers [ existing Question Uuid ] !! ) Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( size ). isEqualTo ( 2 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( this ). contains All ( listOf (" fruit Ġloops ", Ġ" cust ard ")) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġ// ĠBut Ġalso Ġerrors ! ĊĠĠĠĠĠ ĠassertThat ( episode Dto . errors ). has Size ( 1 ) ĊĠĠĠĠĠ Ġwith ( episode Dto . errors ! ![ existing Question Uuid ] !! ) Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( size ). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( this ). contains (" NO ") ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġ@ DisplayName (" coded Ġanswers ") ĊĠ Ġinner Ġclass ĠCode d Answers Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` fetch Ġanswers Ġfor Ġall Ġepisode s `() Ġ{ ĊĊĠĠĠĠĠ Ġsetup Question Codes () ĊĊĠĠĠĠĠ Ġval Ġassessment Ġ= ĠAssessment Entity ( ĊĠĠĠĠĠĠĠ Ġassessment Id Ġ= Ġassessment Id , ĊĠĠĠĠĠĠĠ Ġepisode s Ġ= Ġmutable ListOf ( ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġepisode Id Ġ= Ġepisode Id 1 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġanswers Ġ= Ġmutable Map Of ( question 1 Uuid Ġto ĠAnswer Entity (" YES ")) ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġepisode Id Ġ= Ġepisode Id 2 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġanswers Ġ= Ġmutable Map Of ( question 2 Uuid Ġto ĠAnswer Entity (" NO ")) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġassessment ĊĊĠĠĠĠĠ Ġval Ġresult Ġ= Ġassess ments Service . getCurrent Assessment Coded Answers ( assessment Uuid ) ĊĊĠĠĠĠĠ ĠassertThat ( result . assessment Uuid ). isEqualTo ( assessment Uuid ) ĊĠĠĠĠĠ ĠassertThat ( result . answers [" Q 1 "] ?. first ()?. answer Schema Uuid ). isEqualTo ( answer 1 Uuid ) ĊĠĠĠĠĠ ĠassertThat ( result . answers [" Q 2 "] ?. first ()?. answer Schema Uuid ). isEqualTo ( answer 3 Uuid ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` overwrite Ġolder Ġepisode Ġanswers Ġwith Ġnewer Ġepisode Ġanswers `() Ġ{ ĊĠĠĠĠĠ Ġsetup Question Codes () ĊĊĠĠĠĠĠ Ġval Ġassessment Ġ= ĠAssessment Entity ( ĊĠĠĠĠĠĠĠ Ġassessment Id Ġ= Ġassessment Id , ĊĠĠĠĠĠĠĠ Ġepisode s Ġ= Ġmutable ListOf ( ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġepisode Id Ġ= Ġepisode Id 1 , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠendDate Ġ= ĠLocalDateTime . of ( 2 0 2 0 , Ġ 1 0 , Ġ 1 , Ġ 9 , Ġ 0 , Ġ 0 ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġanswers Ġ= Ġmutable Map Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġquestion 1 Uuid Ġto ĠAnswer Entity (" YES ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġepisode Id Ġ= Ġepisode Id 3 , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠendDate Ġ= ĠLocalDateTime . of ( 2 0 2 0 , Ġ 1 0 , Ġ 2 , Ġ 1 0 , Ġ 0 , Ġ 0 ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġanswers Ġ= Ġmutable Map Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġquestion 2 Uuid Ġto ĠAnswer Entity (" MAYBE ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġepisode Id Ġ= Ġepisode Id 2 , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠendDate Ġ= ĠLocalDateTime . of ( 2 0 2 0 , Ġ 1 0 , Ġ 2 , Ġ 9 , Ġ 0 , Ġ 0 ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġanswers Ġ= Ġmutable Map Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġquestion 2 Uuid Ġto ĠAnswer Entity (" NO ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġassessment ĊĠĠĠĠĠ Ġval Ġresult Ġ= Ġassess ments Service . getCurrent Assessment Coded Answers ( assessment Uuid ) ĊĠĠĠĠĠ ĠassertThat ( result . answers [" Q 1 "] ?. first ()?. answer Schema Uuid ). isEqualTo ( answer 1 Uuid ) ĊĠĠĠĠĠ ĠassertThat ( result . answers [" Q 2 "] ?. first ()?. answer Schema Uuid ). isEqualTo ( answer 2 Uuid ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` overwrite Ġolder Ġepisode Ġanswers Ġlatest Ġepisode Ġanswers `() Ġ{ ĊĠĠĠĠĠ Ġsetup Question Codes () ĊĠĠĠĠĠ Ġval Ġassessment Ġ= ĠAssessment Entity ( ĊĠĠĠĠĠĠĠ Ġassessment Id Ġ= Ġassessment Id , ĊĠĠĠĠĠĠĠ Ġepisode s Ġ= Ġmutable ListOf ( ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġepisode Id Ġ= Ġepisode Id 1 , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠendDate Ġ= ĠLocalDateTime . of ( 2 0 2 0 , Ġ 1 0 , Ġ 1 , Ġ 9 , Ġ 0 , Ġ 0 ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġanswers Ġ= Ġmutable Map Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġquestion 1 Uuid Ġto ĠAnswer Entity (" YES ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġepisode Id Ġ= Ġepisode Id 3 , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠendDate Ġ= Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġanswers Ġ= Ġmutable Map Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġquestion 2 Uuid Ġto ĠAnswer Entity (" NO ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġepisode Id Ġ= Ġepisode Id 2 , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠendDate Ġ= ĠLocalDateTime . of ( 2 0 2 0 , Ġ 1 0 , Ġ 2 , Ġ 9 , Ġ 0 , Ġ 0 ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġanswers Ġ= Ġmutable Map Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġquestion 2 Uuid Ġto ĠAnswer Entity (" MAYBE ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġassessment ĊĊĠĠĠĠĠ Ġval Ġresult Ġ= Ġassess ments Service . getCurrent Assessment Coded Answers ( assessment Uuid ) ĊĠĠĠĠĠ ĠassertThat ( result . answers [" Q 1 "] ?. first ()?. answer Schema Uuid ). isEqualTo ( answer 1 Uuid ) ĊĠĠĠĠĠ ĠassertThat ( result . answers [" Q 2 "] ?. first ()?. answer Schema Uuid ). isEqualTo ( answer 3 Uuid ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` only Ġfetch Ġcoded Ġanswers `() Ġ{ ĊĠĠĠĠĠ Ġsetup Question Codes () ĊĊĠĠĠĠĠ Ġval Ġassessment Ġ= ĠAssessment Entity ( ĊĠĠĠĠĠĠĠ Ġassessment Id Ġ= Ġassessment Id , ĊĠĠĠĠĠĠĠ Ġepisode s Ġ= Ġmutable ListOf ( ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġepisode Id Ġ= Ġepisode Id 1 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġanswers Ġ= Ġmutable Map Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġquestion 1 Uuid Ġto ĠAnswer Entity (" YES "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġquestion 3 Uuid Ġto ĠAnswer Entity (" free Ġtext ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġassessment ĊĠĠĠĠĠ Ġval Ġresult Ġ= Ġassess ments Service . getCurrent Assessment Coded Answers ( assessment Uuid ) ĊĊĠĠĠĠĠ ĠassertThat ( result . assessment Uuid ). isEqualTo ( assessment Uuid ) ĊĠĠĠĠĠ ĠassertThat ( result . answers [" Q 1 "] ?. first ()?. answer Schema Uuid ). isEqualTo ( answer 1 Uuid ) ĊĠĠĠĠĠ ĠassertThat ( result . answers ). does Not Contain Key (" Q 2 ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` throw Ġexception Ġwhen Ġquestion Ġcode Ġlookup Ġfails `() Ġ{ ĊĠĠĠĠĠ Ġevery Ġ{ Ġquestion Service . getAll Questions () Ġ} Ġreturns ĠQuestion Schema Entities ( ĊĠĠĠĠĠĠĠ ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠ ĠQuestion Schema Entity ( question Schema Id Ġ= Ġ 2 , Ġquestion Schema Uuid Ġ= Ġquestion 2 Uuid , Ġanswer Schema Group Ġ= ĠAnswer Schema Group Entity ( 1 )) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġquestion Service . getAll Answers () Ġ} Ġreturns ĠlistOf () ĊĊĠĠĠĠĠ Ġval Ġassessment Ġ= ĠAssessment Entity ( ĊĠĠĠĠĠĠĠ Ġassessment Id Ġ= Ġassessment Id , ĊĠĠĠĠĠĠĠ Ġepisode s Ġ= Ġmutable ListOf ( ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġepisode Id Ġ= Ġepisode Id 1 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġanswers Ġ= Ġmutable Map Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġquestion 2 Uuid Ġto ĠAnswer Entity (" YES ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġassessment ĊĠĠĠĠĠ ĠassertThat Thrown By Ġ{ ĊĠĠĠĠĠĠĠ Ġassess ments Service . getCurrent Assessment Coded Answers ( assessment Uuid ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ. isInstanceOf ( IllegalStateException :: class . java ) ĊĠĠĠĠĠĠĠ Ġ. has Message (" Question ĠCode Ġnot Ġfound Ġfor ĠUUID Ġ$ question 2 Uuid ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` throw Ġexception Ġwhen Ġanswer Ġcode Ġlookup Ġfails `() Ġ{ ĊĠĠĠĠĠ Ġsetup Question Codes () ĊĊĠĠĠĠĠ Ġval Ġassessment Ġ= ĠAssessment Entity ( ĊĠĠĠĠĠĠĠ Ġassessment Id Ġ= Ġassessment Id , ĊĠĠĠĠĠĠĠ Ġepisode s Ġ= Ġmutable ListOf ( ĊĠĠĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġepisode Id Ġ= Ġepisode Id 1 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġanswers Ġ= Ġmutable Map Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġquestion 1 Uuid Ġto ĠAnswer Entity (" NO ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Repository . findBy Assessment Uuid ( assessment Uuid ) Ġ} Ġreturns Ġassessment ĊĠĠĠĠĠ ĠassertThat Thrown By Ġ{ Ġassess ments Service . getCurrent Assessment Coded Answers ( assessment Uuid ) Ġ} ĊĠĠĠĠĠĠĠ Ġ. isInstanceOf ( IllegalStateException :: class . java ) ĊĠĠĠĠĠĠĠ Ġ. has Message (" Answer ĠCode Ġnot Ġfound Ġfor Ġquestion Ġ$ question 1 Uuid Ġanswer Ġvalue ĠNO ") ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġ@ DisplayName (" O As ys ") ĊĠ Ġinner Ġclass ĠUpdating O As ys Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġupdate ĠO AS ys Ġif ĠO AS ys Set Ġstored Ġagainst Ġepisode `() Ġ{ ĊĠĠĠĠĠ Ġsetup Question Codes () ĊĊĠĠĠĠĠ Ġval Ġepisode Ġ= ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠ Ġepisode Id Ġ= Ġepisode Id 1 , ĊĠĠĠĠĠĠĠ Ġassessment Type Ġ= ĠAssessment Type . SHORT _ FORM _ PS R , ĊĠĠĠĠĠĠĠ Ġo as ys Set Pk Ġ= Ġo as ys Set Pk ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Update RestClient . update Assessment ( o as ys Off ender Pk , Ġo as ys Set Pk , Ġassessment Type , Ġany ()) Ġ} Ġreturns ĠUpdate Assessment Answers Response Dto () ĊĠĠĠĠĠ Ġassess ments Service . update O AS ys Assessment ( o as ys Off ender Pk , Ġepisode ) ĊĠĠĠĠĠ Ġverify ( exact ly Ġ= Ġ 1 ) Ġ{ Ġassessment Update RestClient . update Assessment ( o as ys Off ender Pk , Ġo as ys Set Pk , Ġassessment Type , Ġany ()) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġnot Ġupdate ĠO AS ys Ġif Ġno ĠO AS ys Set Ġstored Ġagainst Ġepisode `() Ġ{ ĊĠĠĠĠĠ Ġsetup Question Codes () ĊĊĠĠĠĠĠ Ġval Ġepisode Ġ= ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠ Ġo as ys Set Pk Ġ= Ġo as ys Set Pk ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġevery Ġ{ Ġassessment Update RestClient . update Assessment ( o as ys Off ender Pk , Ġo as ys Set Pk , Ġassessment Type , Ġany ()) Ġ} Ġreturns ĠUpdate Assessment Answers Response Dto () ĊĠĠĠĠĠ Ġassess ments Service . update O AS ys Assessment ( o as ys Off ender Pk , Ġepisode ) ĊĠĠĠĠĠ Ġverify ( exact ly Ġ= Ġ 0 ) Ġ{ Ġassessment Update RestClient . update Assessment ( o as ys Off ender Pk , Ġo as ys Set Pk , Ġassessment Type , Ġany ()) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġcreate ĠO as ys ĠAnswer Ġfrom Ġfree Ġtext Ġanswer `() Ġ{ ĊĠĠĠĠĠ Ġval Ġmapping Ġ= ĠO AS ys Mapping Entity ( section Code Ġ= Ġ" 1 ", Ġquestion Code Ġ= Ġ" R 1 . 3 ", Ġlogical Page Ġ= Ġ 1 , Ġfixed _ field Ġ= Ġfalse , Ġmapping Id Ġ= Ġ 1 , Ġquestion Schema Ġ= ĠQuestion Schema Entity ( question Schema Id Ġ= Ġ 1 )) ĊĠĠĠĠĠ Ġval Ġresult Ġ= ĠO as ys Answers . map O as ys Answer ( mapping , ĠlistOf (" Free ĠText "), Ġ" rad ios ")[ 0 ] ĊĠĠĠĠĠ ĠassertThat ( result . answer ). isEqualTo (" Free ĠText ") ĊĠĠĠĠĠ ĠassertThat ( result . logical Page ). isEqualTo ( 1 ) ĊĠĠĠĠĠ ĠassertThat ( result . is Static ). isFalse () ĊĠĠĠĠĠ ĠassertThat ( result . question Code ). isEqualTo (" R 1 . 3 ") ĊĠĠĠĠĠ ĠassertThat ( result . section Code ). isEqualTo (" 1 ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġcreate ĠO as ys ĠAnswer Ġwith Ġcorrect Ġdate Ġformat `() Ġ{ ĊĠĠĠĠĠ Ġval Ġmapping Ġ= ĠO AS ys Mapping Entity ( section Code Ġ= Ġ" 1 ", Ġquestion Code Ġ= Ġ" R 1 . 3 ", Ġlogical Page Ġ= Ġ 1 , Ġfixed _ field Ġ= Ġfalse , Ġmapping Id Ġ= Ġ 1 , Ġquestion Schema Ġ= ĠQuestion Schema Entity ( question Schema Id Ġ= Ġ 1 )) ĊĠĠĠĠĠ Ġval Ġresult Ġ= ĠO as ys Answers . map O as ys Answer ( mapping , ĠlistOf (" 1 9 7 5 - 0 1 - 2 0 T 0 0 : 0 0 : 0 0 . 0 0 0 Z "), Ġ" date ")[ 0 ] ĊĠĠĠĠĠ ĠassertThat ( result . answer ). isEqualTo (" 2 0 / 0 1 / 1 9 7 5 ") ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġsetup Question Codes () Ġ{ ĊĠĠĠ Ġval Ġdummy Ġ= ĠAnswer Schema Group Entity ( answer Schema Id Ġ= Ġ 9 9 ) ĊĊĠĠĠ Ġval Ġyes Ġ= ĠAnswer Schema Entity ( answer Schema Id Ġ= Ġ 1 , Ġanswer Schema Uuid Ġ= Ġanswer 1 Uuid , Ġvalue Ġ= Ġ" YES ", Ġanswer Schema Group Ġ= Ġdummy ) ĊĠĠĠ Ġval Ġmaybe Ġ= ĠAnswer Schema Entity ( answer Schema Id Ġ= Ġ 2 , Ġanswer Schema Uuid Ġ= Ġanswer 2 Uuid , Ġvalue Ġ= Ġ" MAYBE ", Ġanswer Schema Group Ġ= Ġdummy ) ĊĠĠĠ Ġval Ġno Ġ= ĠAnswer Schema Entity ( answer Schema Id Ġ= Ġ 3 , Ġanswer Schema Uuid Ġ= Ġanswer 3 Uuid , Ġvalue Ġ= Ġ" NO ", Ġanswer Schema Group Ġ= Ġdummy ) ĊĊĠĠĠ Ġval Ġgroup 1 Ġ= ĠAnswer Schema Group Entity ( answer Schema Id Ġ= Ġ 1 , Ġanswer Schema Entities Ġ= ĠlistOf ( yes )) ĊĠĠĠ Ġval Ġgroup 2 Ġ= ĠAnswer Schema Group Entity ( answer Schema Id Ġ= Ġ 2 , Ġanswer Schema Entities Ġ= ĠlistOf ( maybe , Ġno )) ĊĊĠĠĠ Ġevery Ġ{ Ġquestion Service . getAll Questions () Ġ} Ġreturns ĠQuestion Schema Entities ( ĊĠĠĠĠĠ ĠlistOf ( ĊĠĠĠĠĠĠĠ ĠQuestion Schema Entity ( question Schema Id Ġ= Ġ 1 , Ġquestion Schema Uuid Ġ= Ġquestion 1 Uuid , Ġquestion Code Ġ= Ġ" Q 1 ", Ġanswer Schema Group Ġ= Ġgroup 1 ), ĊĠĠĠĠĠĠĠ ĠQuestion Schema Entity ( question Schema Id Ġ= Ġ 2 , Ġquestion Schema Uuid Ġ= Ġquestion 2 Uuid , Ġquestion Code Ġ= Ġ" Q 2 ", Ġanswer Schema Group Ġ= Ġgroup 2 ), ĊĠĠĠĠĠĠĠ ĠQuestion Schema Entity ( question Schema Id Ġ= Ġ 3 , Ġquestion Schema Uuid Ġ= Ġquestion 3 Uuid ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassessment Entity ( answers : ĠMutable Map < UUID , ĠAnswer Entity >): ĠAssessment Entity Ġ{ ĊĠĠĠ Ġreturn ĠAssessment Entity ( ĊĠĠĠĠĠ Ġassessment Id Ġ= Ġassessment Id , ĊĠĠĠĠĠ Ġepisode s Ġ= Ġmutable ListOf ( ĊĠĠĠĠĠĠĠ ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠĠĠ Ġepisode Uuid Ġ= Ġepisode Uuid , ĊĠĠĠĠĠĠĠĠĠ Ġepisode Id Ġ= Ġepisode Id 2 , ĊĠĠĠĠĠĠĠĠĠ Ġchange Reason Ġ= Ġ" Change Ġof ĠC ir cs Ġ 2 ", ĊĠĠĠĠĠĠĠĠĠ Ġanswers Ġ= Ġanswers ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassessment Entity With O as ys Off ender ( answers : ĠMutable Map < UUID , ĠAnswer 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 Id Ġ= Ġassessment Id , ĊĠĠĠĠĠ Ġepisode s Ġ= Ġepisode s , ĊĠĠĠĠĠ Ġsubject _ Ġ= Ġmutable ListOf ( subject ) ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġepisode s . add ( ĊĠĠĠĠĠ ĠAssessment Episode Entity ( ĊĠĠĠĠĠĠĠ Ġepisode Uuid Ġ= Ġepisode Uuid , ĊĠĠĠĠĠĠĠ Ġepisode Id Ġ= Ġepisode Id 2 , ĊĠĠĠĠĠĠĠ Ġ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 , ĊĠĠĠĠĠĠĠ Ġanswers Ġ= Ġanswers ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġreturn Ġassessment ĊĠ Ġ} Ċ } Ċ