package Ġorg . simple . clin ic . edit patient Ċ Ċ import Ġcom . n ha ar man . mockito _ kotlin . any Ċ import Ġcom . n ha ar man . mockito _ kotlin . do Return Ċ import Ġcom . n ha ar man . mockito _ kotlin . mock Ċ import Ġcom . n ha ar man . mockito _ kotlin . never Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify No More Interactions Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify Zero Interactions Ċ import Ġcom . n ha ar man . mockito _ kotlin . wh enever Ċ import Ġio . reactivex . Comp letable Ċ import Ġio . reactivex . Observable Ċ import Ġio . reactivex . Single Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Test Ċ import Ġorg . simple . clin ic . facility . Facility Repository Ċ import Ġorg . simple . clin ic . mob ius . Effect Handler TestCase Ċ import Ġorg . simple . clin ic . patient . Patient M ocker Ċ import Ġorg . simple . clin ic . patient . Patient Repository Ċ import Ġorg . simple . clin ic . patient . business id . Identifier Ċ import Ġorg . simple . clin ic . user . User Session Ċ import Ġorg . simple . clin ic . util . Test User Clock Ċ import Ġorg . simple . clin ic . util . Test Utc Clock Ċ import Ġorg . simple . clin ic . util . scheduler . Tr amp oline Schedulers Provider Ċ import Ġorg . simple . clin ic . util . to Optional Ċ import Ġorg . th reet en . bp . Instant Ċ import Ġorg . th reet en . bp . LocalDate Ċ import Ġorg . th reet en . bp . format . DateTime Formatter Ċ import Ġjava . util . Locale Ċ import Ġjava . util . UUID Ċ Ċ class ĠEdit Patient Effect Handler Test Ġ{ ĊĊĠ Ġprivate Ġval Ġdate Ġ= ĠLocalDate . parse (" 2 0 1 8 - 0 1 - 0 1 ") ĊĠ Ġprivate Ġval Ġui Ġ= Ġmock < Edit Patient Ui >() ĊĠ Ġprivate Ġval Ġuser Session Ġ= Ġmock < User Session >() ĊĠ Ġprivate Ġval Ġfacility Repository Ġ= Ġmock < Facility Repository >() ĊĠ Ġprivate Ġval Ġuser Clock Ġ= ĠTest User Clock ( date ) ĊĠ Ġprivate Ġval Ġut c Clock Ġ= ĠTest Utc Clock ( Instant . parse (" 2 0 1 8 - 0 1 - 0 1 T 0 0 : 0 0 : 0 0 Z ")) ĊĠ Ġprivate Ġval Ġpatient Repository Ġ= Ġmock < Patient Repository >() ĊĠ Ġprivate Ġval Ġdate OfBirth Formatter Ġ= ĠDateTime Formatter . of Pattern (" dd / MM / yyyy ", ĠLocale . EN GL ISH ) ĊĊĠ Ġprivate Ġval Ġpatient Address Ġ= ĠPatient M ocker . address ( uuid Ġ= ĠUUID . fromString (" 8 5 d 0 b 5 f 1 - af 8 4 - 4 a 6 b - 9 3 8 e - 5 1 6 6 f 8 c 2 7 6 6 6 ")) ĊĠ Ġprivate Ġval Ġpatient Ġ= ĠPatient M ocker . patient ( ĊĠĠĠĠĠ Ġuuid Ġ= ĠUUID . fromString (" c 9 c 9 d 4 db - cd 8 0 - 4 b 6 7 - bf 6 9 - 3 7 8 de 9 6 5 6 b 4 9 "), ĊĠĠĠĠĠ Ġaddress Uuid Ġ= Ġpatient Address . uuid , ĊĠĠĠĠĠ Ġage Ġ= Ġnull , ĊĠĠĠĠĠ Ġdate OfBirth Ġ= ĠLocalDate . now ( user Clock ). minus Years ( 3 0 ) ĊĠ Ġ) ĊĠ Ġprivate Ġval ĠphoneNumber Ġ= ĠPatient M ocker . phoneNumber ( ĊĠĠĠĠĠ Ġuuid Ġ= ĠUUID . fromString (" 6 1 6 3 8 7 7 5 - 2 8 1 5 - 4 f 5 9 - b 5 1 3 - 6 4 3 cc 2 fe 3 c 9 0 "), ĊĠĠĠĠĠ Ġpatient Uuid Ġ= Ġpatient . uuid ĊĠ Ġ) ĊĊĠ Ġprivate Ġval Ġb ang l ade sh National Id Ġ= ĠPatient M ocker . business Id ( ĊĠĠĠĠĠ Ġuuid Ġ= ĠUUID . fromString (" 7 7 bd 5 3 8 7 - 6 4 1 b - 4 2 f 8 - ab 8 d - d 6 6 2 b cee 9 b 0 0 "), ĊĠĠĠĠĠ Ġpatient Uuid Ġ= Ġpatient . uuid , ĊĠĠĠĠĠ Ġidentifier Ġ= ĠIdentifier ( value Ġ= Ġ" 1 2 3 4 5 6 7 8 9 0 abcd ", Ġtype Ġ= ĠIdentifier . Identifier Type . Bang l ade sh National Id ) ĊĠ Ġ) ĊĊĠ Ġprivate Ġval Ġentry Ġ= ĠEdit able Patient Entry . from ( ĊĠĠĠĠĠ Ġpatient Ġ= Ġpatient , ĊĠĠĠĠĠ Ġaddress Ġ= Ġpatient Address , ĊĠĠĠĠĠ ĠphoneNumber Ġ= ĠphoneNumber , ĊĠĠĠĠĠ Ġdate OfBirth Formatter Ġ= Ġdate OfBirth Formatter , ĊĠĠĠĠĠ Ġb ang l ade sh National Id Ġ= Ġnull ĊĠ Ġ) ĊĊĠ Ġprivate Ġval Ġuser Ġ= ĠPatient M ocker . logged In User ( uuid Ġ= ĠUUID . fromString (" 3 c 3 d 0 0 5 7 - d 6 f 6 - 4 2 be - 9 bf 6 - 5 cc acb 8 bc 5 4 d ")) ĊĠ Ġprivate Ġval Ġfacility Ġ= ĠPatient M ocker . facility ( uuid Ġ= ĠUUID . fromString (" d 6 6 8 5 d 5 1 - f 8 8 2 - 4 9 9 5 - b 9 2 2 - a 6 c 6 3 7 eed 0 a 5 ")) ĊĊĠ Ġprivate Ġval Ġeffect Handler Ġ= ĠEdit Patient Effect Handler ( ĊĠĠĠĠĠ Ġui Ġ= Ġui , ĊĠĠĠĠĠ Ġuser Clock Ġ= Ġuser Clock , ĊĠĠĠĠĠ Ġpatient Repository Ġ= Ġpatient Repository , ĊĠĠĠĠĠ Ġut c Clock Ġ= Ġut c Clock , ĊĠĠĠĠĠ Ġs chedulers Provider Ġ= ĠTr amp oline Schedulers Provider (), ĊĠĠĠĠĠ Ġuser Session Ġ= Ġuser Session , ĊĠĠĠĠĠ Ġfacility Repository Ġ= Ġfacility Repository , ĊĠĠĠĠĠ Ġdate OfBirth Formatter Ġ= Ġdate OfBirth Formatter ĊĠ Ġ) ĊĊĠ Ġprivate Ġval ĠtestCase Ġ= ĠEffect Handler TestCase ( effect Handler . build ()) ĊĊĠ Ġ@ After ĊĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠ ĠtestCase . dispose () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` editing Ġa Ġpatient Ġwith Ġa Ġblank Ġb ang l ade sh ĠID Ġshould Ġdelete Ġthe Ġbusiness ĠID `() Ġ{ ĊĠĠĠ Ġ// Ġgiven ĊĠĠĠ Ġwhenever ( patient Repository . update Patient ( patient )) Ġdo Return ĠComp letable . complete () ĊĠĠĠ Ġwhenever ( patient Repository . update Address For Patient ( patient . uuid , Ġpatient Address )) Ġdo Return ĠComp letable . complete () ĊĠĠĠ Ġwhenever ( patient Repository . update PhoneNumber For Patient ( patient . uuid , ĠphoneNumber )) Ġdo Return ĠComp letable . complete () ĊĠĠĠ Ġwhenever ( patient Repository . delete Business Id ( bang l ade sh National Id )) Ġdo Return ĠComp letable . complete () ĊĊĠĠĠ Ġ// Ġwhen ĊĠĠĠ ĠtestCase . dispatch ( Save Patient Effect ( entry . update Bang l ade sh National Id (""), Ġpatient , Ġpatient Address , ĠphoneNumber , Ġb ang l ade sh National Id )) ĊĊĠĠĠ Ġ// Ġthen ĊĠĠĠ Ġverify ( patient Repository ). update Patient ( patient ) ĊĠĠĠ Ġverify ( patient Repository ). update Address For Patient ( patient . uuid , Ġpatient Address ) ĊĠĠĠ Ġverify ( patient Repository ). update PhoneNumber For Patient ( patient . uuid , ĠphoneNumber ) ĊĠĠĠ Ġverify ( patient Repository ). delete Business Id ( bang l ade sh National Id ) ĊĠĠĠ Ġverify ( patient Repository , Ġnever ()). save Business Id ( any ()) ĊĠĠĠ Ġverify ( patient Repository , Ġnever ()). add Identifier To Patient ( any (), Ġany (), Ġany (), Ġany ()) ĊĠĠĠ Ġverify No More Interactions ( patient Repository ) ĊĠĠĠ ĠtestCase . assert Outgoing Events ( Patient Saved ) ĊĠĠĠ Ġverify Zero Interactions ( ui ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` editing Ġa Ġpatient Ġwith Ġa Ġnull Ġb ang l ade sh ĠID Ġshould Ġnot Ġsave Ġthe Ġbusiness ĠID `() Ġ{ ĊĠĠĠ Ġ// Ġgiven ĊĠĠĠ Ġwhenever ( patient Repository . update Patient ( patient )) Ġdo Return ĠComp letable . complete () ĊĠĠĠ Ġwhenever ( patient Repository . update Address For Patient ( patient . uuid , Ġpatient Address )) Ġdo Return ĠComp letable . complete () ĊĠĠĠ Ġwhenever ( patient Repository . update PhoneNumber For Patient ( patient . uuid , ĠphoneNumber )) Ġdo Return ĠComp letable . complete () ĊĠĠĠ Ġwhenever ( patient Repository . delete Business Id ( bang l ade sh National Id )) Ġdo Return ĠComp letable . complete () ĊĊĠĠĠ Ġ// Ġwhen ĊĠĠĠ ĠtestCase . dispatch ( Save Patient Effect ( entry , Ġpatient , Ġpatient Address , ĠphoneNumber , Ġb ang l ade sh National Id )) ĊĊĠĠĠ Ġ// Ġthen ĊĠĠĠ Ġverify ( patient Repository ). update Patient ( patient ) ĊĠĠĠ Ġverify ( patient Repository ). update Address For Patient ( patient . uuid , Ġpatient Address ) ĊĠĠĠ Ġverify ( patient Repository ). update PhoneNumber For Patient ( patient . uuid , ĠphoneNumber ) ĊĠĠĠ Ġverify ( patient Repository ). delete Business Id ( bang l ade sh National Id ) ĊĠĠĠ Ġverify ( patient Repository , Ġnever ()). save Business Id ( any ()) ĊĠĠĠ Ġverify ( patient Repository , Ġnever ()). add Identifier To Patient ( any (), Ġany (), Ġany (), Ġany ()) ĊĠĠĠ Ġverify No More Interactions ( patient Repository ) ĊĠĠĠ ĠtestCase . assert Outgoing Events ( Patient Saved ) ĊĠĠĠ Ġverify Zero Interactions ( ui ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` editing Ġa Ġpatient Ġwith Ġa Ġnon - blank Ġb ang l ade sh ĠID Ġshould Ġsave Ġthe Ġbusiness ĠID `() Ġ{ ĊĠĠĠ Ġ// Ġgiven ĊĠĠĠ Ġval Ġb ang l ade sh National Id Text Ġ= Ġ" 1 5 6 9 2 7 3 " ĊĠĠĠ Ġval Ġongoing Entry With Bang l ade sh Id Ġ= Ġentry . update Bang l ade sh National Id ( bang l ade sh National Id Text ) ĊĠĠĠ Ġval Ġupdated Bang l ade sh National Id Ġ= Ġb ang l ade sh National Id . update Identifier Value ( bang l ade sh National Id Text ) ĊĊĠĠĠ Ġwhenever ( patient Repository . update Patient ( patient )) Ġdo Return ĠComp letable . complete () ĊĠĠĠ Ġwhenever ( patient Repository . update Address For Patient ( patient . uuid , Ġpatient Address )) Ġdo Return ĠComp letable . complete () ĊĠĠĠ Ġwhenever ( patient Repository . update PhoneNumber For Patient ( patient . uuid , ĠphoneNumber )) Ġdo Return ĠComp letable . complete () ĊĠĠĠ Ġwhenever ( patient Repository . save Business Id ( updated Bang l ade sh National Id )) Ġdo Return ĠComp letable . complete () ĊĊĠĠĠ Ġ// Ġwhen ĊĠĠĠ ĠtestCase . dispatch ( Save Patient Effect ( ongo ing Entry With Bang l ade sh Id , Ġpatient , Ġpatient Address , ĠphoneNumber , Ġb ang l ade sh National Id )) ĊĊĠĠĠ Ġ// Ġthen ĊĠĠĠ Ġverify ( patient Repository ). update Patient ( patient ) ĊĠĠĠ Ġverify ( patient Repository ). update Address For Patient ( patient . uuid , Ġpatient Address ) ĊĠĠĠ Ġverify ( patient Repository ). update PhoneNumber For Patient ( patient . uuid , ĠphoneNumber ) ĊĠĠĠ Ġverify ( patient Repository ). save Business Id ( updated Bang l ade sh National Id ) ĊĠĠĠ Ġverify ( patient Repository , Ġnever ()). add Identifier To Patient ( any (), Ġany (), Ġany (), Ġany ()) ĊĠĠĠ Ġverify No More Interactions ( patient Repository ) ĊĠĠĠ ĠtestCase . assert Outgoing Events ( Patient Saved ) ĊĠĠĠ Ġverify Zero Interactions ( ui ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` adding Ġan Ġid Ġto Ġan Ġempty ĠB ang l ade sh Ġid Ġshould Ġcreate Ġa Ġnew ĠBusiness Ġid `() Ġ{ ĊĠĠĠ Ġ// given ĊĠĠĠ Ġval Ġidentifier Ġ= Ġb ang l ade sh National Id . identifier ĊĊĠĠĠ Ġwhenever ( patient Repository . update Patient ( patient )) Ġdo Return ĠComp letable . complete () ĊĠĠĠ Ġwhenever ( patient Repository . update Address For Patient ( patient . uuid , Ġpatient Address )) Ġdo Return ĠComp letable . complete () ĊĠĠĠ Ġwhenever ( patient Repository . update PhoneNumber For Patient ( patient . uuid , ĠphoneNumber )) Ġdo Return ĠComp letable . complete () ĊĠĠĠ Ġwhenever ( patient Repository . save Business Id ( bang l ade sh National Id )) Ġdo Return ĠComp letable . complete () ĊĠĠĠ Ġwhenever ( user Session . logged In User ()) Ġdo Return Ġ( Observable . just ( user . to Optional ())) ĊĠĠĠ Ġwhenever ( facility Repository . current Facility ( user )) Ġdo Return Ġ( Observable . just ( facility )) ĊĠĠĠ Ġwhenever ( patient Repository . add Identifier To Patient ( patient . uuid , Ġidentifier , Ġuser , Ġfacility )) Ġdo Return ĠSingle . just ( bang l ade sh National Id ) ĊĊĠĠĠ Ġ// when ĊĠĠĠ ĠtestCase . dispatch ( Save Patient Effect ( ĊĠĠĠĠĠĠĠ Ġentry . update Bang l ade sh National Id ( identifier . value ), ĊĠĠĠĠĠĠĠ Ġpatient , ĊĠĠĠĠĠĠĠ Ġpatient Address , ĊĠĠĠĠĠĠĠ ĠphoneNumber , ĊĠĠĠĠĠĠĠ Ġnull ĊĠĠĠ Ġ)) ĊĊĠĠĠ Ġ// then ĊĠĠĠ Ġverify ( patient Repository ). update Patient ( patient ) ĊĠĠĠ Ġverify ( patient Repository ). update Address For Patient ( patient . uuid , Ġpatient Address ) ĊĠĠĠ Ġverify ( patient Repository ). update PhoneNumber For Patient ( patient . uuid , ĠphoneNumber ) ĊĠĠĠ Ġverify ( patient Repository ). add Identifier To Patient ( patient . uuid , Ġidentifier , Ġuser , Ġfacility ) ĊĠĠĠ Ġverify ( patient Repository , Ġnever ()). save Business Id ( any ()) ĊĠĠĠ Ġverify No More Interactions ( patient Repository ) ĊĠĠĠ ĠtestCase . assert Outgoing Events ( Patient Saved ) ĊĠĠĠ Ġverify Zero Interactions ( ui ) ĊĠ Ġ} Ċ } Ċ