package Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . security Ċ Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any OrNull Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ 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 . assertj . core . api . Assertions . assertThat Thrown By Ċ import Ġorg . junit . jupiter . api . Nested Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . mockito . Argument Matchers . any List Ċ import Ġorg . mockito . Argument Matchers . any String Ċ import Ġorg . springframework . data . domain . Page Ċ import Ġorg . springframework . data . domain . Page able Ċ import Ġorg . springframework . security . core . Granted Authority Ċ import Ġorg . springframework . security . core . authority . Simple Granted Authority Ċ import Ġorg . springframework . security . core . user details . Username NotFoundException Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . auth . model . User Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . auth . model . User Filter Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . auth . model . User Helper . Companion . create Sample User Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . auth . repository . UserRepository Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . azure . Azure User Person Details Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . azure . service . Azure UserService Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . deli us . model . Del ius User Person Details Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . deli us . service . Del ius UserService Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . maint ain . Auth UserService Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . nom is . model . Nom is User Person Details Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . nom is . model . Nom is User Person Details Helper . Companion . create Sample Nom is User Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . nom is . model . Staff Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . security . Auth Source . auth Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . security . Auth Source . azure ad Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . security . Auth Source . deli us Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . security . Auth Source . nom is Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . security . Auth Source . none Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . verify . Verify Email Service Ċ import Ġjava . util . Optional Ċ Ċ class ĠUserService Test Ġ{ ĊĠ Ġprivate Ġval Ġnom is UserService : ĠNom is UserService Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġauth UserService : ĠAuth UserService Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġdeli us UserService : ĠDel ius UserService Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġazure UserService : ĠAzure UserService Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġuser Repository : ĠUser Repository Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġverify Email Service : ĠVerify Email Service Ġ= Ġmock () ĊĠ Ġprivate Ġval ĠuserService Ġ= ĠUserService ( ĊĠĠĠ Ġnom is UserService , ĊĠĠĠ Ġauth UserService , ĊĠĠĠ Ġdeli us UserService , ĊĠĠĠ Ġazure UserService , ĊĠĠĠ Ġuser Repository , ĊĠĠĠ Ġverify Email Service ĊĠ Ġ) ĊĊĠ Ġ@ Nested ĊĠ Ġinner Ġclass ĠFind Master User Person Details Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` find Master User Person Details Ġauth Ġuser `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( auth UserService . get Auth User By Username ( any String ())). thenReturn ( createUser ()) ĊĠĠĠĠĠ Ġval Ġuser Ġ= ĠuserService . find Master User Person Details (" ĠĠ Ġbob ĠĠ Ġ") ĊĠĠĠĠĠ ĠassertThat ( user ). isPresent . get (). extract ing Ġ{ Ġit . username Ġ}. isEqualTo (" some user ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` find Master User Person Details Ġnom is Ġuser `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( nom is UserService . get Nom is User By Username ( any String ())). thenReturn ( staff User Account For Bob ) ĊĠĠĠĠĠ Ġval Ġuser Ġ= ĠuserService . find Master User Person Details (" bob ") ĊĠĠĠĠĠ ĠassertThat ( user ). isPresent . get (). extract ing Ġ{ Ġit . username Ġ}. isEqualTo (" nom is user ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` find Master User Person Details Ġdeli us Ġuser `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( deli us UserService . get Del ius User By Username ( any String ())). thenReturn ( deli us User Account For Bob ) ĊĠĠĠĠĠ Ġval Ġuser Ġ= ĠuserService . find Master User Person Details (" bob ") ĊĠĠĠĠĠ ĠassertThat ( user ). isPresent . get (). extract ing Ġ{ Ġit . username Ġ}. isEqualTo (" deli us User ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` find Master User Person Details Ġazure Ġuser `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( azure UserService . get Azure User By Username ( any String ())). thenReturn ( azure User Account ) ĊĠĠĠĠĠ Ġval Ġuser Ġ= ĠuserService . find Master User Person Details (" bob ") ĊĠĠĠĠĠ ĠassertThat ( user ). isPresent . get (). extract ing Ġ{ Ġit . username Ġ}. isEqualTo (" D 6 1 6 5 AD 0 - A ED 3 - 4 1 4 6 - 9 EF 7 - 2 2 2 8 7 6 B 5 7 5 4 9 ") ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġinner Ġclass ĠFind Enabled Master User Person Details Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` find Enabled Master User Person Details Ġauth Ġuser `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( auth UserService . get Auth User By Username ( any String ())). thenReturn ( ĊĠĠĠĠĠĠĠ ĠOptional . of ( ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample User ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" some user ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġenabled Ġ= Ġtrue ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġval Ġuser Ġ= ĠuserService . find Enabled Master User Person Details (" ĠĠ Ġbob ĠĠ Ġ") ĊĠĠĠĠĠ ĠassertThat ( user ?. username ). isEqualTo (" some user ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` find Enabled Master User Person Details Ġnom is Ġuser `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( nom is UserService . get Nom is User By Username ( any String ())). thenReturn ( staff User Account For Bob ) ĊĠĠĠĠĠ Ġval Ġuser Ġ= ĠuserService . find Enabled Master User Person Details (" bob ") ĊĠĠĠĠĠ ĠassertThat ( user ?. username ). isEqualTo (" nom is user ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` find Enabled Master User Person Details Ġdeli us Ġuser `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( deli us UserService . get Del ius User By Username ( any String ())). thenReturn ( deli us User Account For Bob ) ĊĠĠĠĠĠ Ġval Ġuser Ġ= ĠuserService . find Enabled Master User Person Details (" bob ") ĊĠĠĠĠĠ ĠassertThat ( user ?. username ). isEqualTo (" deli us User ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` find Enabled Master User Person Details Ġazure Ġuser `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( azure UserService . get Azure User By Username ( any String ())). thenReturn ( azure User Account ) ĊĠĠĠĠĠ Ġval Ġuser Ġ= ĠuserService . find Enabled Master User Person Details (" bob ") ĊĠĠĠĠĠ ĠassertThat ( user ?. username ). isEqualTo (" D 6 1 6 5 AD 0 - A ED 3 - 4 1 4 6 - 9 EF 7 - 2 2 2 8 7 6 B 5 7 5 4 9 ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` find Enabled Master User Person Details Ġdeli us Ġuser Ġauth Ġuser Ġdisabled `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( auth UserService . get Auth User By Username ( any String ())). thenReturn ( createUser ()) ĊĠĠĠĠĠ Ġwhenever ( deli us UserService . get Del ius User By Username ( any String ())). thenReturn ( deli us User Account For Bob ) ĊĠĠĠĠĠ Ġval Ġuser Ġ= ĠuserService . find Enabled Master User Person Details (" bob ") ĊĠĠĠĠĠ ĠassertThat ( user ?. username ). isEqualTo (" deli us User ") ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġinner Ġclass ĠGet EmailAddress From Nom is Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get EmailAddress From Nom is Ġno Ġemail Ġaddresses `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( verify Email Service . get Existing Email Addresses For Username ( any String ())). thenReturn ( listOf ()) ĊĠĠĠĠĠ Ġval Ġoptional Address Ġ= ĠuserService . get EmailAddress From Nom is (" jo e ") ĊĠĠĠĠĠ ĠassertThat ( optional Address ). isEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get EmailAddress From Nom is Ġnot Ġa Ġjust ice Ġemail `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( verify Email Service . get Existing Email Addresses For Username ( any String ())). thenReturn ( listOf (" a @ b . gov . uk ")) ĊĠĠĠĠĠ Ġval Ġoptional Address Ġ= ĠuserService . get EmailAddress From Nom is (" jo e ") ĊĠĠĠĠĠ ĠassertThat ( optional Address ). isEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get EmailAddress From Nom is Ġone Ġjust ice Ġemail `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( verify Email Service . get Existing Email Addresses For Username ( any String ())). thenReturn ( ĊĠĠĠĠĠĠĠ ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠ Ġ" Bob . smith @ h mps . g si . gov . uk ", ĊĠĠĠĠĠĠĠĠĠ Ġ" Bob . smith @ just ice . gov . uk " ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġval Ġoptional Address Ġ= ĠuserService . get EmailAddress From Nom is (" jo e ") ĊĠĠĠĠĠ ĠassertThat ( optional Address ). hasValue (" Bob . smith @ just ice . gov . uk ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get EmailAddress From Nom is Ġmultiple Ġjust ice Ġemails `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( verify Email Service . get Existing Email Addresses For Username ( any String ())). thenReturn ( ĊĠĠĠĠĠĠĠ ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠ Ġ" Bob . smith @ h mps . g si . gov . uk ", ĊĠĠĠĠĠĠĠĠĠ Ġ" Bob . smith @ just ice . gov . uk ", ĊĠĠĠĠĠĠĠĠĠ Ġ" Bob . smith 2 @ just ice . gov . uk " ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġval Ġoptional Address Ġ= ĠuserService . get EmailAddress From Nom is (" jo e ") ĊĠĠĠĠĠ ĠassertThat ( optional Address ). isEmpty ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġinner Ġclass ĠGet OrCreate User Ġ{ ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get OrCreate User Ġuser Ġexists Ġalready `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User (" jo e ") ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username (" JO E ")). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġval Ġnew User Opt Ġ= ĠuserService . get OrCreate User (" jo e ") ĊĠĠĠĠĠ ĠassertThat ( new User Opt ). hasValue Satisf ying Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( it . username ). isEqualTo (" jo e ") ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get OrCreate User Ġmigrate Ġfrom ĠNO MIS `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠ Ġwhenever ( auth UserService . get Auth User By Username ( any String ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠ Ġwhenever ( nom is UserService . get Nom is User By Username (" jo e ")). thenReturn ( ĊĠĠĠĠĠĠĠ ĠOptional . of ( create Sample Nom is User ( username Ġ= Ġ" jo e ")) ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġwhenever ( verify Email Service . get Existing Email Addresses For Username ( any String ())). thenReturn ( listOf ()) ĊĠĠĠĠĠ Ġwhenever ( user Repository . save < User >( any ())). then Answer Ġ{ Ġit . arguments [ 0 ] Ġ} ĊĊĠĠĠĠĠ Ġval Ġnew User Ġ= ĠuserService . get OrCreate User (" jo e ") ĊĠĠĠĠĠ ĠassertThat ( new User ). hasValue Satisf ying Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( it . username ). isEqualTo (" jo e ") ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get OrCreate User Ġmigrate Ġfrom ĠNO MIS Ġwith Ġemail `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠ Ġwhenever ( auth UserService . get Auth User By Username ( any String ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠ Ġwhenever ( nom is UserService . get Nom is User By Username (" jo e ")). thenReturn ( ĊĠĠĠĠĠĠĠ ĠOptional . of ( create Sample Nom is User ( username Ġ= Ġ" jo e ")) ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġwhenever ( verify Email Service . get Existing Email Addresses For Username ( any String ())). thenReturn ( ĊĠĠĠĠĠĠĠ ĠlistOf (" a @ b . just ice . gov . uk ") ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . save < User >( any ())). then Answer Ġ{ Ġit . arguments [ 0 ] Ġ} ĊĊĠĠĠĠĠ Ġval Ġnew User Ġ= ĠuserService . get OrCreate User (" jo e ") ĊĠĠĠĠĠ ĠassertThat ( new User ). hasValue Satisf ying Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( it . username ). isEqualTo (" jo e ") ĊĠĠĠĠĠĠĠ ĠassertThat ( it . email ). isEqualTo (" a @ b . just ice . gov . uk ") ĊĠĠĠĠĠĠĠ ĠassertThat ( it . verified ). isTrue ĊĠĠĠĠĠĠĠ ĠassertThat ( it . auth Source ). isEqualTo ( nom is . name ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġinner Ġclass ĠGet OrCreate Users Ġ{ ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` user Ġexists Ġand Ġother Ġnot Ġfound `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User (" jo e ") ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username (" JO E ")). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġval Ġnew User Opt Ġ= ĠuserService . get OrCreate Users ( listOf (" jo e ", Ġ" f red ")) ĊĠĠĠĠĠ ĠassertThat ( new User Opt ). contains Exactly ( user ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` migrate Ġfrom ĠNO MIS `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠ Ġwhenever ( auth UserService . get Auth User By Username ( any String ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠ Ġwhenever ( nom is UserService . get Nom is User By Username (" jo e ")). thenReturn ( ĊĠĠĠĠĠĠĠ ĠOptional . of ( create Sample Nom is User ( username Ġ= Ġ" jo e ")) ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġwhenever ( verify Email Service . get Existing Email Addresses For Username ( any String ())). thenReturn ( listOf ()) ĊĠĠĠĠĠ Ġwhenever ( user Repository . save < User >( any ())). then Answer Ġ{ Ġit . arguments [ 0 ] Ġ} ĊĊĠĠĠĠĠ Ġval Ġnew User Ġ= ĠuserService . get OrCreate Users ( listOf (" jo e ")) ĊĠĠĠĠĠ ĠassertThat ( new User ). has Size ( 1 ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġinner Ġclass ĠFind User Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfind User () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate User () ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( user ) ĊĠĠĠĠĠ Ġval Ġfound Ġ= ĠuserService . find User (" bob ") ĊĠĠĠĠĠ ĠassertThat ( found ). is Same As ( user ) ĊĠĠĠĠĠ Ġverify ( user Repository ). findBy Username (" BO B ") ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġinner Ġclass ĠGetUser Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` getUser Ġfound `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate User () ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( user ) ĊĠĠĠĠĠ Ġval Ġfound Ġ= ĠuserService . getUser (" bob ") ĊĠĠĠĠĠ ĠassertThat ( found ). is Same As ( user . orElse Throw ()) ĊĠĠĠĠĠ Ġverify ( user Repository ). findBy Username (" BO B ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` getUser Ġnot Ġfound `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠ ĠassertThat Thrown By Ġ{ ĠuserService . getUser (" bob ") Ġ}. isInstanceOf ( Username NotFoundException :: class . java ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġinner Ġclass ĠHas Verified M fa Method Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` has Verified M fa Method Ġsuccess `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" jo e ", Ġemail Ġ= Ġ" some email ", Ġverified Ġ= Ġtrue ) ĊĠĠĠĠĠ ĠassertThat ( userService . has Verified M fa Method ( user )). isTrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` has Verified M fa Method Ġno Ġemail `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" jo e ", Ġverified Ġ= Ġtrue ) ĊĠĠĠĠĠ ĠassertThat ( userService . has Verified M fa Method ( user )). isFalse ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` has Verified M fa Method Ġnot Ġverified `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" jo e ", Ġemail Ġ= Ġ" some email ") ĊĠĠĠĠĠ ĠassertThat ( userService . has Verified M fa Method ( user )). isFalse ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġinner Ġclass ĠIs Same As Current Verified Mobile Ġ{ ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` is Same As Current Verified Mobile Ġnot Ġverified `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( mobile Ġ= Ġ" 0 7 7 0 0 9 0 0 0 0 1 ") ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġval ĠreturnValue Ġ= ĠuserService . is Same As Current Verified Mobile (" some user ", Ġ"") ĊĠĠĠĠĠ ĠassertThat ( returnValue ). isFalse ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` is Same As Current Verified Mobile Ġnew Ġdifferent Ġmobile Ġnumber `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( mobile Ġ= Ġ" 0 7 7 0 0 9 0 0 0 0 1 ", Ġmobile Verified Ġ= Ġtrue ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġval ĠreturnValue Ġ= ĠuserService . is Same As Current Verified Mobile (" some user ", Ġ" 0 7 7 0 0 9 0 0 0 0 0 ") ĊĠĠĠĠĠ ĠassertThat ( returnValue ). isFalse ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` is Same As Current Verified Mobile Ġnew Ġdifferent Ġmobile Ġnumber Ġwith Ġwhitespace `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( mobile Ġ= Ġ" 0 7 7 0 0 9 0 0 0 0 1 ", Ġmobile Verified Ġ= Ġtrue ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġval ĠreturnValue Ġ= ĠuserService . is Same As Current Verified Mobile (" some user ", Ġ" 0 7 7 0 Ġ 0 9 0 Ġ 0 0 0 0 ") ĊĠĠĠĠĠ ĠassertThat ( returnValue ). isFalse ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` is Same As Current Verified Mobile Ġsame Ġmobile Ġnumber `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( mobile Ġ= Ġ" 0 7 7 0 0 9 0 0 0 0 0 ", Ġmobile Verified Ġ= Ġtrue ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġval ĠreturnValue Ġ= ĠuserService . is Same As Current Verified Mobile (" some user ", Ġ" 0 7 7 0 0 9 0 0 0 0 0 ") ĊĠĠĠĠĠ ĠassertThat ( returnValue ). isTrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` is Same As Current Verified Mobile Ġsame Ġmobile Ġnumber Ġwith Ġwhitespace `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( mobile Ġ= Ġ" 0 7 7 0 0 9 0 0 0 0 0 ", Ġmobile Verified Ġ= Ġtrue ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġval ĠreturnValue Ġ= ĠuserService . is Same As Current Verified Mobile (" some user ", Ġ" 0 7 7 0 Ġ 0 9 0 Ġ 0 0 0 0 ") ĊĠĠĠĠĠ ĠassertThat ( returnValue ). isTrue ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġinner Ġclass Ġis Same As Current Verified Email Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` is Same As Current Verified Email Ġnot Ġverified Ġprimary Ġemail `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( email Ġ= Ġ" some email ", Ġverified Ġ= Ġfalse ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġval ĠreturnValue Ġ= ĠuserService . is Same As Current Verified Email (" some user ", Ġ" some email ", ĠUser . Email Type . PRIMARY ) ĊĠĠĠĠĠ ĠassertThat ( returnValue ). isFalse ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` is Same As Current Verified Email Ġnew Ġdifferent Ġemail Ġaddress Ġprimary Ġemail `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( email Ġ= Ġ" some email ", Ġverified Ġ= Ġtrue ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġval ĠreturnValue Ġ= ĠuserService . is Same As Current Verified Email (" some user ", Ġ" s omen ew email ", ĠUser . Email Type . PRIMARY ) ĊĠĠĠĠĠ ĠassertThat ( returnValue ). isFalse ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` is Same As Current Verified Email Ġsame Ġaddress Ġprimary Ġemail `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( email Ġ= Ġ" some email ", Ġverified Ġ= Ġtrue ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġval ĠreturnValue Ġ= ĠuserService . is Same As Current Verified Email (" some user ", Ġ" some email ", ĠUser . Email Type . PRIMARY ) ĊĠĠĠĠĠ ĠassertThat ( returnValue ). isTrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` is Same As Current Verified Email Ġnot Ġverified Ġsecondary Ġemail `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( secondary Email Ġ= Ġ" some email ") ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġval ĠreturnValue Ġ= ĠuserService . is Same As Current Verified Email (" some user ", Ġ" some email ", ĠUser . Email Type . SECOND ARY ) ĊĠĠĠĠĠ ĠassertThat ( returnValue ). isFalse ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` is Same As Current Verified Email Ġnew Ġdifferent Ġemail Ġaddress Ġsecondary Ġemail `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( secondary Email Ġ= Ġ" some email ", Ġsecondary Email Verified Ġ= Ġtrue ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġval ĠreturnValue Ġ= ĠuserService . is Same As Current Verified Email (" some user ", Ġ" s omen ew email ", ĠUser . Email Type . SECOND ARY ) ĊĠĠĠĠĠ ĠassertThat ( returnValue ). isFalse ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` is Same As Current Verified Email Ġsame Ġaddress Ġsecondary Ġemail `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( secondary Email Ġ= Ġ" some email ", Ġsecondary Email Verified Ġ= Ġtrue ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġval ĠreturnValue Ġ= ĠuserService . is Same As Current Verified Email (" some user ", Ġ" some email ", ĠUser . Email Type . SECOND ARY ) ĊĠĠĠĠĠ ĠassertThat ( returnValue ). isTrue ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġinner Ġclass ĠFind Pr ison Users By First And Last Names Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` no Ġmatches `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( nom is UserService . find Pr ison Users By First And Last Names (" first ", Ġ" last ")). thenReturn ( listOf ()) ĊĠĠĠĠĠ Ġwhenever ( auth UserService . find Auth Users ByUser names ( listOf ())). thenReturn ( listOf ()) ĊĠĠĠĠĠ Ġwhenever ( verify Email Service . get Existing Email Addresses ForUser names ( listOf ())). thenReturn ( map Of ()) ĊĊĠĠĠĠĠ ĠassertThat ( userService . find Pr ison Users By First And Last Names (" first ", Ġ" last ")). isEmpty () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` pr ison Ġusers Ġonly `() Ġ{ ĊĊĠĠĠĠĠ Ġwhenever ( auth UserService . find Auth Users ByUser names ( listOf ())). thenReturn ( listOf ()) ĊĊĠĠĠĠĠ Ġwhenever ( nom is UserService . find Pr ison Users By First And Last Names (" first ", Ġ" last ")). thenReturn ( ĊĠĠĠĠĠĠĠ ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample Nom is User ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstaff Ġ= ĠStaff ( firstName Ġ= Ġ" f 1 ", ĠlastName Ġ= Ġ" l 1 ", Ġstaff Id Ġ= Ġ 1 , Ġstatus Ġ= Ġ" IN ACTIVE "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġnull ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample Nom is User ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstaff Ġ= ĠStaff ( firstName Ġ= Ġ" f 2 ", ĠlastName Ġ= Ġ" l 2 ", Ġstaff Id Ġ= Ġ 2 , Ġstatus Ġ= Ġ" IN ACTIVE "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġnull ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample Nom is User ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstaff Ġ= ĠStaff ( firstName Ġ= Ġ" f 3 ", ĠlastName Ġ= Ġ" l 3 ", Ġstaff Id Ġ= Ġ 3 , Ġstatus Ġ= Ġ" IN ACTIVE "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 3 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġ" M DI " ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġwhenever ( verify Email Service . get Existing Email Addresses ForUser names ( any List ())) ĊĠĠĠĠĠĠĠ Ġ. thenReturn ( ĊĠĠĠĠĠĠĠĠĠ Ġmap Of ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" U 1 " Ġto Ġmutable Set Of (" u 1 @ just ice . gov . uk ", Ġ" u 1 @ something else . gov . uk "), ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠTwo Ġmatching Ġe - mail Ġsuffix es Ġresults Ġin Ġno Ġe - mail Ġaddress . ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" U 3 " Ġto Ġmutable Set Of (" u 3 @ just ice . gov . uk ", Ġ" another - u 3 @ just ice . gov . uk ") ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ ĠassertThat ( userService . find Pr ison Users By First And Last Names (" first ", Ġ" last ")) ĊĊĠĠĠĠĠĠĠ Ġ. contains Exactly In Any Order ( ĊĠĠĠĠĠĠĠĠĠ ĠPr ison User Dto ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġemail Ġ= Ġ" u 1 @ just ice . gov . uk ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġverified Ġ= Ġtrue , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠuserId Ġ= Ġ" 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfirstName Ġ= Ġ" F 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlastName Ġ= Ġ" l 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġnull ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ ĠPr ison User Dto ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġemail Ġ= Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġverified Ġ= Ġfalse , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠuserId Ġ= Ġ" 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfirstName Ġ= Ġ" F 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlastName Ġ= Ġ" l 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġnull ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ ĠPr ison User Dto ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 3 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġemail Ġ= Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġverified Ġ= Ġfalse , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠuserId Ġ= Ġ" 3 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfirstName Ġ= Ġ" F 3 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlastName Ġ= Ġ" l 3 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġ" M DI " ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġverify ( verify Email Service ). get Existing Email Addresses ForUser names ( listOf (" U 1 ", Ġ" U 2 ", Ġ" U 3 ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Pr ison Ġusers Ġmatched Ġin Ġauth `() Ġ{ ĊĊĠĠĠĠĠ Ġwhenever ( nom is UserService . find Pr ison Users By First And Last Names (" first ", Ġ" last ")). thenReturn ( ĊĠĠĠĠĠĠĠ ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample Nom is User ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstaff Ġ= ĠStaff ( firstName Ġ= Ġ" f 1 ", ĠlastName Ġ= Ġ" l 1 ", Ġstaff Id Ġ= Ġ 1 , Ġstatus Ġ= Ġ" IN ACTIVE "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġ" M DI " ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample Nom is User ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstaff Ġ= ĠStaff ( firstName Ġ= Ġ" f 2 ", ĠlastName Ġ= Ġ" l 2 ", Ġstaff Id Ġ= Ġ 2 , Ġstatus Ġ= Ġ" IN ACTIVE "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġnull ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample Nom is User ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstaff Ġ= ĠStaff ( firstName Ġ= Ġ" f 3 ", ĠlastName Ġ= Ġ" l 3 ", Ġstaff Id Ġ= Ġ 3 , Ġstatus Ġ= Ġ" IN ACTIVE "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 3 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġ" M DI " ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġwhenever ( auth UserService . find Auth Users ByUser names ( any List ())). thenReturn ( ĊĠĠĠĠĠĠĠ ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample User ( verified Ġ= Ġtrue , Ġsource Ġ= Ġnom is , Ġusername Ġ= Ġ" U 1 ", Ġemail Ġ= Ġ" u 1 @ b . com "), ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample User ( verified Ġ= Ġtrue , Ġsource Ġ= Ġnom is , Ġusername Ġ= Ġ" U 2 ", Ġemail Ġ= Ġ" u 2 @ b . com "), ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample User ( verified Ġ= Ġfalse , Ġsource Ġ= Ġnom is , Ġusername Ġ= Ġ" U 3 ", Ġemail Ġ= Ġ" u 3 @ b . com "), ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ ĠassertThat ( userService . find Pr ison Users By First And Last Names (" first ", Ġ" last ")) ĊĠĠĠĠĠĠĠ Ġ. contains Exactly In Any Order ( ĊĠĠĠĠĠĠĠĠĠ ĠPr ison User Dto ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġemail Ġ= Ġ" u 1 @ b . com ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġverified Ġ= Ġtrue , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠuserId Ġ= Ġ" 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfirstName Ġ= Ġ" F 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlastName Ġ= Ġ" l 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġ" M DI " ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ ĠPr ison User Dto ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġemail Ġ= Ġ" u 2 @ b . com ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġverified Ġ= Ġtrue , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠuserId Ġ= Ġ" 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfirstName Ġ= Ġ" F 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlastName Ġ= Ġ" l 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġnull ĊĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ ĠPr ison User Dto ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 3 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġemail Ġ= Ġ" u 3 @ b . com ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġverified Ġ= Ġfalse , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠuserId Ġ= Ġ" 3 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfirstName Ġ= Ġ" F 3 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlastName Ġ= Ġ" l 3 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġ" M DI " ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġverify ( verify Email Service ). get Existing Email Addresses ForUser names ( listOf ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Pr ison Ġusers Ġpartially Ġmatched Ġin Ġauth `() Ġ{ ĊĊĠĠĠĠĠ Ġwhenever ( nom is UserService . find Pr ison Users By First And Last Names (" first ", Ġ" last ")). thenReturn ( ĊĠĠĠĠĠĠĠ ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample Nom is User ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstaff Ġ= ĠStaff ( firstName Ġ= Ġ" f 1 ", ĠlastName Ġ= Ġ" l 1 ", Ġstaff Id Ġ= Ġ 1 , Ġstatus Ġ= Ġ" IN ACTIVE "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġ" M DI " ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample Nom is User ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstaff Ġ= ĠStaff ( firstName Ġ= Ġ" f 2 ", ĠlastName Ġ= Ġ" l 2 ", Ġstaff Id Ġ= Ġ 2 , Ġstatus Ġ= Ġ" IN ACTIVE "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġnull ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample Nom is User ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstaff Ġ= ĠStaff ( firstName Ġ= Ġ" f 3 ", ĠlastName Ġ= Ġ" l 3 ", Ġstaff Id Ġ= Ġ 3 , Ġstatus Ġ= Ġ" IN ACTIVE "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 3 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġnull ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample Nom is User ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstaff Ġ= ĠStaff ( firstName Ġ= Ġ" f 4 ", ĠlastName Ġ= Ġ" l 4 ", Ġstaff Id Ġ= Ġ 4 , Ġstatus Ġ= Ġ" IN ACTIVE "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 4 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġ" M DI " ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġwhenever ( auth UserService . find Auth Users ByUser names ( any List ())). thenReturn ( ĊĠĠĠĠĠĠĠ ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample User ( verified Ġ= Ġtrue , Ġsource Ġ= Ġnom is , Ġusername Ġ= Ġ" U 1 ", Ġemail Ġ= Ġ" u 1 @ b . com "), ĊĠĠĠĠĠĠĠĠĠ Ġ// ĠUser ĠU 2 Ġin Ġauth , Ġbut Ġno Ġemail Ġ- Ġso Ġsearch ĠNO MIS Ġfor Ġe - mail Ġfor Ġthis Ġuser ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample User ( verified Ġ= Ġtrue , Ġsource Ġ= Ġnom is , Ġusername Ġ= Ġ" U 2 ", Ġemail Ġ= Ġnull ), ĊĠĠĠĠĠĠĠĠĠ Ġ// ĠUser ĠU 3 Ġfound Ġin Ġauth , Ġbut Ġsource Ġis Ġnot Ġnom is ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample User ( verified Ġ= Ġtrue , Ġsource Ġ= Ġauth , Ġusername Ġ= Ġ" U 3 ", Ġemail Ġ= Ġ" u 3 @ b . com "), ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġwhenever ( verify Email Service . get Existing Email Addresses ForUser names ( any List ())) ĊĠĠĠĠĠĠĠ Ġ. thenReturn ( ĊĠĠĠĠĠĠĠĠĠ Ġmap Of ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠPair (" U 2 ", Ġmutable Set Of (" u 2 @ just ice . gov . uk ", Ġ" u 2 @ something else . gov . uk ")), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠPair (" U 3 ", Ġmutable Set Of (" u 3 @ just ice . gov . uk ")), ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ ĠassertThat ( userService . find Pr ison Users By First And Last Names (" first ", Ġ" last ")) ĊĠĠĠĠĠĠĠ Ġ. contains Exactly In Any Order ( ĊĠĠĠĠĠĠĠĠĠ ĠPr ison User Dto ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġemail Ġ= Ġ" u 1 @ b . com ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġverified Ġ= Ġtrue , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠuserId Ġ= Ġ" 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfirstName Ġ= Ġ" F 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlastName Ġ= Ġ" l 1 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġ" M DI " ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ ĠPr ison User Dto ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġemail Ġ= Ġ" u 2 @ just ice . gov . uk ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġverified Ġ= Ġtrue , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠuserId Ġ= Ġ" 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfirstName Ġ= Ġ" F 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlastName Ġ= Ġ" l 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġnull ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ ĠPr ison User Dto ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 3 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġemail Ġ= Ġ" u 3 @ just ice . gov . uk ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġverified Ġ= Ġtrue , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠuserId Ġ= Ġ" 3 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfirstName Ġ= Ġ" F 3 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlastName Ġ= Ġ" l 3 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġnull ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ ĠPr ison User Dto ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" U 4 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġemail Ġ= Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġverified Ġ= Ġfalse , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠuserId Ġ= Ġ" 4 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfirstName Ġ= Ġ" F 4 ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlastName Ġ= Ġ" l 4 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġ" M DI " ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġverify ( verify Email Service ). get Existing Email Addresses ForUser names ( listOf (" U 2 ", Ġ" U 3 ", Ġ" U 4 ")) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġinner Ġclass ĠGet Master User Person Details With Email Check Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġget Master User Person Details With Email Check Ġ- Ġauth Ġuser `() Ġ{ ĊĠĠĠĠĠ Ġval Ġauth User Ġ= ĊĠĠĠĠĠĠĠ ĠOptional . of ( create Sample User ( username Ġ= Ġ" bob ", Ġverified Ġ= Ġtrue , Ġemail Ġ= Ġ" jo e @ f red . com ")) ĊĠĠĠĠĠ Ġwhenever ( auth UserService . get Auth User By Username ( any String ())). thenReturn ( auth User ) ĊĠĠĠĠĠ Ġval Ġdetails Ġ= ĠuserService . get Master User Person Details With Email Check (" user ", Ġauth , Ġ" jo e @ f red . com ") ĊĠĠĠĠĠ ĠassertThat ( details ). isEqualTo ( auth User ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġget Master User Person Details With Email Check Ġ- Ġauth Ġuser Ġemail Ġnot Ġverified `() Ġ{ ĊĠĠĠĠĠ Ġval Ġauth User Ġ= ĊĠĠĠĠĠĠĠ ĠOptional . of ( create Sample User ( username Ġ= Ġ" bob ", Ġverified Ġ= Ġfalse , Ġemail Ġ= Ġ" jo e @ f red . com ")) ĊĠĠĠĠĠ Ġwhenever ( auth UserService . get Auth User By Username ( any String ())). thenReturn ( auth User ) ĊĠĠĠĠĠ Ġval Ġdetails Ġ= ĠuserService . get Master User Person Details With Email Check (" user ", Ġauth , Ġ" jo e @ f red . com ") ĊĠĠĠĠĠ ĠassertThat ( details ). isEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġget Master User Person Details With Email Check Ġ- Ġauth Ġuser Ġnot Ġmatched `() Ġ{ ĊĠĠĠĠĠ Ġval Ġauth User Ġ= ĊĠĠĠĠĠĠĠ ĠOptional . of ( create Sample User ( username Ġ= Ġ" bob ", Ġverified Ġ= Ġtrue , Ġemail Ġ= Ġ" har old @ hen ry . com ")) ĊĠĠĠĠĠ Ġwhenever ( auth UserService . get Auth User By Username ( any String ())). thenReturn ( auth User ) ĊĠĠĠĠĠ Ġval Ġdetails Ġ= ĠuserService . get Master User Person Details With Email Check (" user ", Ġauth , Ġ" jo e @ f red . com ") ĊĠĠĠĠĠ ĠassertThat ( details ). isEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġget Master User Person Details With Email Check Ġ- Ġnom is Ġuser `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( nom is UserService . get Nom is User By Username ( any String ())). thenReturn ( staff User Account For Bob ) ĊĠĠĠĠĠ Ġwhenever ( nom is UserService . get Nom is Users By Email ( any String ())). thenReturn ( listOf ( staff User Account For Bob . get ())) ĊĠĠĠĠĠ Ġval Ġdetails Ġ= ĠuserService . get Master User Person Details With Email Check (" user ", Ġnom is , Ġ" jo e @ f red . com ") ĊĠĠĠĠĠ ĠassertThat ( details ). isEqualTo ( staff User Account For Bob ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġget Master User Person Details With Email Check Ġ- Ġnom is Ġuser Ġnot Ġmatched `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( nom is UserService . get Nom is User By Username ( any String ())). thenReturn ( staff User Account For Bob ) ĊĠĠĠĠĠ Ġval Ġdetails Ġ= ĠuserService . get Master User Person Details With Email Check (" user ", Ġnom is , Ġ" jo e @ f red . com ") ĊĠĠĠĠĠ ĠassertThat ( details ). isEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġget Master User Person Details With Email Check Ġ- Ġdeli us Ġuser `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( deli us UserService . get Del ius User By Username ( any String ())). thenReturn ( deli us User Account For Bob ) ĊĠĠĠĠĠ Ġval Ġdetails Ġ= ĠuserService . get Master User Person Details With Email Check (" user ", Ġdeli us , Ġ" a @ b . com ") ĊĠĠĠĠĠ ĠassertThat ( details ). isEqualTo ( deli us User Account For Bob ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġget Master User Person Details With Email Check Ġ- Ġdeli us Ġuser Ġnot Ġmatched `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( deli us UserService . get Del ius User By Username ( any String ())). thenReturn ( deli us User Account For Bob ) ĊĠĠĠĠĠ Ġval Ġdetails Ġ= ĠuserService . get Master User Person Details With Email Check (" user ", Ġdeli us , Ġ" jo e @ f red . com ") ĊĠĠĠĠĠ ĠassertThat ( details ). isEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġget Master User Person Details With Email Check Ġ- Ġazure ad Ġuser `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( azure UserService . get Azure User By Username ( any String ())). thenReturn ( azure User Account ) ĊĠĠĠĠĠ Ġval Ġdetails Ġ= ĠuserService . get Master User Person Details With Email Check (" user ", Ġazure ad , Ġ" jo e . blog gs @ just ice . gov . uk ") ĊĠĠĠĠĠ ĠassertThat ( details ). isEqualTo ( azure User Account ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġget Master User Person Details With Email Check Ġ- Ġnone `() Ġ{ ĊĠĠĠĠĠ Ġval Ġdetails Ġ= ĠuserService . get Master User Person Details With Email Check (" user ", Ġnone , Ġ" jo e @ f red . com ") ĊĠĠĠĠĠ ĠassertThat ( details ). isEmpty ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Nested ĊĠ Ġinner Ġclass ĠUser Search Multiple Sources Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġsearch Ġuser Ġwith Ġmultiple Ġauth Ġsources Ġ` () Ġ{ ĊĠĠĠĠĠ Ġval Ġun page d Ġ= ĠPage able . un page d () ĊĠĠĠĠĠ Ġwhenever ( auth UserService . find Auth Users ( any String (), Ġany OrNull (), Ġany OrNull (), Ġany (), Ġany String (), Ġany List (), Ġany (), Ġany ())) ĊĠĠĠĠĠĠĠ Ġ. thenReturn ( Page . empty ()) ĊĊĠĠĠĠĠ ĠuserService . search Users In Multiple Source Systems ( ĊĠĠĠĠĠĠĠ Ġ" test ", Ġun page d , Ġ" bob ", ĠAUTH ORITY _ INTEL _ ADMIN , ĠUser Filter . Status . ALL , ĠlistOf ( nom is , Ġauth ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġverify ( auth UserService ). find Auth Users ( ĊĠĠĠĠĠĠĠ Ġ" test ", Ġempty List (), Ġempty List (), Ġun page d , Ġ" bob ", ĠAUTH ORITY _ INTEL _ ADMIN , ĠUser Filter . Status . ALL , ĠlistOf ( nom is , Ġauth ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġsearch Ġuser Ġwith Ġdefault Ġauth Ġsource Ġwhen Ġnot Ġprovided `() Ġ{ ĊĠĠĠĠĠ Ġval Ġun page d Ġ= ĠPage able . un page d () ĊĠĠĠĠĠ Ġwhenever ( auth UserService . find Auth Users ( any String (), Ġany OrNull (), Ġany OrNull (), Ġany (), Ġany String (), Ġany List (), Ġany (), Ġany ())) ĊĠĠĠĠĠĠĠ Ġ. thenReturn ( Page . empty ()) ĊĊĠĠĠĠĠ ĠuserService . search Users In Multiple Source Systems ( ĊĠĠĠĠĠĠĠ Ġ" test ", Ġun page d , Ġ" bob ", ĠAUTH ORITY _ INTEL _ ADMIN , ĠUser Filter . Status . ALL , Ġnull ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġverify ( auth UserService ). find Auth Users ( ĊĠĠĠĠĠĠĠ Ġ" test ", Ġempty List (), Ġempty List (), Ġun page d , Ġ" bob ", ĠAUTH ORITY _ INTEL _ ADMIN , ĠUser Filter . Status . ALL , ĠlistOf ( Auth Source . auth ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġcreate User () Ġ= ĠOptional . of ( create Sample User ( username Ġ= Ġ" some user ")) ĊĊĠ Ġprivate Ġval Ġstaff User Account For Bob : ĠOptional < Nom is User Person Details > ĊĠĠĠ Ġget () Ġ= ĊĠĠĠĠĠ ĠOptional . of ( ĊĠĠĠĠĠĠĠ Ġcreate Sample Nom is User ( ĊĠĠĠĠĠĠĠĠĠ Ġstaff Ġ= ĠStaff ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfirstName Ġ= Ġ" b Ob ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstatus Ġ= Ġ" ACTIVE ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlastName Ġ= Ġ" blog gs ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstaff Id Ġ= Ġ 5 ĊĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" nom is user " ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠ Ġprivate Ġval Ġdeli us User Account For Bob Ġ= ĊĠĠĠ ĠOptional . of ( Del ius User Person Details (" deli us User ", Ġ" 1 2 3 4 5 ", Ġ" Del ius ", Ġ" Sm ith ", Ġ" a @ b . com ", Ġtrue , Ġfalse , Ġset Of ())) ĊĊĠ Ġprivate Ġval Ġazure User Account Ġ= ĊĠĠĠ ĠOptional . of ( ĊĠĠĠĠĠ ĠAzure User Person Details ( ĊĠĠĠĠĠĠĠ ĠArrayList (), ĊĠĠĠĠĠĠĠ Ġtrue , ĊĠĠĠĠĠĠĠ Ġ" D 6 1 6 5 AD 0 - A ED 3 - 4 1 4 6 - 9 EF 7 - 2 2 2 8 7 6 B 5 7 5 4 9 ", ĊĠĠĠĠĠĠĠ Ġ" Jo e ", ĊĠĠĠĠĠĠĠ Ġ" Blog gs ", ĊĠĠĠĠĠĠĠ Ġ" jo e . blog gs @ just ice . gov . uk ", ĊĠĠĠĠĠĠĠ Ġtrue , ĊĠĠĠĠĠĠĠ Ġaccount Non Expired Ġ= Ġtrue , ĊĠĠĠĠĠĠĠ Ġaccount Non Locked Ġ= Ġtrue ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġprivate Ġval ĠAUTH ORITY _ INTEL _ ADMIN : ĠSet < Granted Authority > Ġ= ĊĠĠĠĠĠ Ġset Of ( Simple Granted Authority (" ROLE _ INTEL _ ADMIN ")) ĊĠ Ġ} Ċ } Ċ