package Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . verify Ċ Ċ 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 Map Ċ import Ġorg . mockito . Argument Matchers . any String Ċ import Ġorg . mockito . kotlin . any Ċ import Ġorg . mockito . kotlin . check Ċ import Ġorg . mockito . kotlin . eq Ċ import Ġorg . mockito . kotlin . isNull Ċ import Ġorg . mockito . kotlin . mock Ċ import Ġorg . mockito . kotlin . never Ċ import Ġorg . mockito . kotlin . verify Ċ import Ġorg . mockito . kotlin . wh enever Ċ import Ġorg . springframework . security . authentication . Locked Exception Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . auth . model . Person Ċ 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 . model . User Token Ċ 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 . auth . repository . User Token Repository Ċ 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 . nom is . model . Account Status Ċ 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 . security . Auth Source . auth Ċ 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 . User Person Details Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . security . UserService Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . service . Delegating UserService Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . verify . Reset Password ServiceImpl . Reset Password Exception Ċ import Ġuk . gov . service . notify . Notification Client Api Ċ import Ġuk . gov . service . notify . Notification ClientException Ċ import Ġjava . util . Map . entry Ċ import Ġjava . util . Optional Ċ Ċ class ĠReset Password Service Test Ġ{ ĊĠ Ġprivate Ġval Ġuser Repository : ĠUser Repository Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġuser Token Repository : ĠUser Token Repository Ġ= Ġmock () ĊĠ Ġprivate Ġval ĠuserService : ĠUserService Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġdeleg ating UserService : ĠDeleg ating UserService Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġnotification Client : ĠNotification Client Api Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġreset Password Service Ġ= ĠReset Password ServiceImpl ( ĊĠĠĠ Ġuser Repository , Ġuser Token Repository , ĊĠĠĠ ĠuserService , Ġdeleg ating UserService , Ġnotification Client , ĊĠĠĠ Ġ" reset Template ", Ġ" reset Unavailable Template ", Ġ" reset Unavailable Email NotFound Template ", Ġ" reset - confirm " ĊĠ Ġ) ĊĊĠ Ġ@ Nested ĊĠ Ġinner Ġclass Ġrequest Reset Password Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ no User Email () Ġ{ ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠ Ġwhenever ( userService . find Master User Person Details ( any String ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠ Ġval Ġoptional Ġ= Ġreset Password Service . request Reset Password (" user ", Ġ" url ") ĊĠĠĠĠĠ ĠassertThat ( optional ). isEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ no Email () Ġ{ ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( create Sample User ( username Ġ= Ġ" user "))) ĊĠĠĠĠĠ Ġval Ġoptional Ġ= Ġreset Password Service . request Reset Password (" user ", Ġ" url ") ĊĠĠĠĠĠ ĠassertThat ( optional ). isEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ no Email _ email In Del ius () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( ĊĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" some user ", ĊĠĠĠĠĠĠĠ Ġemail Ġ= Ġ" email ", ĊĠĠĠĠĠĠĠ Ġperson Ġ= ĠPerson (" Bob ", Ġ" Sm ith "), ĊĠĠĠĠĠĠĠ Ġenabled Ġ= Ġtrue ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Email ( any ())). thenReturn ( listOf ( user , Ġuser )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( user ) ĊĊĠĠĠĠĠ Ġval Ġoptional Ġ= Ġreset Password Service . request Reset Password (" email @ address ", Ġ" http :// url ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Template "), ĊĠĠĠĠĠĠĠ Ġeq (" email "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). contains Only ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" firstName ", Ġ" Bob "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" fullName ", Ġ" Bob ĠSmith "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" reset Link ", Ġoptional . get ()) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional ). isPresent ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ no Nom is User () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" USER ", Ġemail Ġ= Ġ" email ", Ġverified Ġ= Ġtrue , Ġsource Ġ= Ġnom is ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Master User Person Details ( any String ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠ Ġval Ġoptional Ġ= Ġreset Password Service . request Reset Password (" user ", Ġ" url ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Unavailable Template "), ĊĠĠĠĠĠĠĠ Ġeq (" email "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). contains Only ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" firstName ", Ġ" first "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" fullName ", Ġ" first Ġlast "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" nom is User ", Ġtrue ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" deli us User ", Ġfalse ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" auth User ", Ġfalse ) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional ). isEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ no Del ius User () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" USER ", Ġemail Ġ= Ġ" email ", Ġverified Ġ= Ġtrue , Ġsource Ġ= Ġdeli us ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Master User Person Details ( any String ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠ Ġwhenever ( userService . get Master User Person Details ( any String (), Ġany ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠ Ġval Ġoptional Ġ= Ġreset Password Service . request Reset Password (" user ", Ġ" url ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Unavailable Template "), ĊĠĠĠĠĠĠĠ Ġeq (" email "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). contains Only ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" firstName ", Ġ" first "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" fullName ", Ġ" first Ġlast "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" deli us User ", Ġtrue ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" nom is User ", Ġfalse ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" auth User ", Ġfalse ) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional ). isEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ email Address Different In Del ius () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" USER ", Ġemail Ġ= Ġ" email ", Ġperson Ġ= ĠPerson (" Bob ", Ġ" Sm ith "), Ġenabled Ġ= Ġtrue , Ġsource Ġ= Ġdeli us ) ĊĠĠĠĠĠ Ġval Ġuser From Del ius Ġ= Ġcreate Sample User ( username Ġ= Ġ" USER ", Ġemail Ġ= Ġ" email From Del ius ", Ġperson Ġ= ĠPerson (" Bob ", Ġ" Sm ith "), Ġenabled Ġ= Ġtrue , Ġsource Ġ= Ġdeli us ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Email ( any ())). thenReturn ( listOf ( user , Ġuser )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( user ) ĊĠĠĠĠĠ Ġwhenever ( userService . get Master User Person Details ( any String (), Ġany ())). thenReturn ( Optional . of ( user From Del ius )) ĊĊĠĠĠĠĠ Ġval Ġoptional Link Ġ= Ġreset Password Service . request Reset Password (" some user @ some where ", Ġ" http :// url ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Template "), ĊĠĠĠĠĠĠĠ Ġeq (" email From Del ius "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). contains Only ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" firstName ", Ġ" Bob "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" fullName ", Ġ" Bob ĠSmith "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" reset Link ", Ġoptional Link . get ()) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional Link ). isPresent ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ inactive () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" some user ", Ġemail Ġ= Ġ" email ", Ġsource Ġ= Ġnom is , Ġverified Ġ= Ġtrue ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġval Ġstaff User Account Ġ= ĊĠĠĠĠĠĠĠ Ġnom is User Person Details ( Account Status . EXPI RED _ LOCK ED , Ġenabled Ġ= Ġfalse , Ġactive Ġ= Ġfalse ) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( staff User Account ) ĊĠĠĠĠĠ Ġval Ġoptional Ġ= Ġreset Password Service . request Reset Password (" user ", Ġ" url ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Unavailable Template "), ĊĠĠĠĠĠĠĠ Ġeq (" email "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). contains Only ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" firstName ", Ġ" Bob "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" fullName ", Ġ" Bob ĠSmith "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" nom is User ", Ġtrue ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" deli us User ", Ġfalse ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" auth User ", Ġfalse ) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional ). isEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ auth Locked () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( ĊĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" some user ", ĊĠĠĠĠĠĠĠ Ġemail Ġ= Ġ" email ", ĊĠĠĠĠĠĠĠ Ġverified Ġ= Ġtrue , ĊĠĠĠĠĠĠĠ Ġlocked Ġ= Ġtrue , ĊĠĠĠĠĠĠĠ ĠfirstName Ġ= Ġ" Bob ", ĊĠĠĠĠĠĠĠ ĠlastName Ġ= Ġ" Sm ith ", ĊĠĠĠĠĠĠĠ Ġenabled Ġ= Ġtrue ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( user ) ĊĊĠĠĠĠĠ Ġval Ġoptional Link Ġ= Ġreset Password Service . request Reset Password (" user ", Ġ" url ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Template "), ĊĠĠĠĠĠĠĠ Ġeq (" email "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). contains Only ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" firstName ", Ġ" Bob "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" fullName ", Ġ" Bob ĠSmith "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" reset Link ", Ġoptional Link . get ()) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional Link ). isPresent ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ not Auth Locked () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" some user ", Ġemail Ġ= Ġ" email ", Ġverified Ġ= Ġtrue , Ġsource Ġ= Ġnom is ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( staff User Account Locked For Bob ) ĊĠĠĠĠĠ Ġval Ġoptional Link Ġ= Ġreset Password Service . request Reset Password (" user ", Ġ" url ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Template "), ĊĠĠĠĠĠĠĠ Ġeq (" email "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). contains Only ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" firstName ", Ġ" Bob "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" fullName ", Ġ" Bob ĠSmith "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" reset Link ", Ġoptional Link . get ()) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional Link ). isPresent ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ user Locked () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" some user ", Ġemail Ġ= Ġ" email ", Ġsource Ġ= Ġnom is , Ġverified Ġ= Ġtrue ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( staff User Account Expired Locked For Bob ) ĊĠĠĠĠĠ Ġval Ġoptional Link Ġ= Ġreset Password Service . request Reset Password (" user ", Ġ" url ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Template "), ĊĠĠĠĠĠĠĠ Ġeq (" email "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). contains Only ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" firstName ", Ġ" Bob "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" fullName ", Ġ" Bob ĠSmith "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" reset Link ", Ġoptional Link . get ()) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional Link ). isPresent ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ existing Token () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" some user ", Ġemail Ġ= Ġ" email ", Ġverified Ġ= Ġtrue , Ġlocked Ġ= Ġtrue ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Master User Person Details ( any String ())). thenReturn ( staff User Account For Bob Optional ) ĊĠĠĠĠĠ Ġval Ġexisting User Token Ġ= Ġuser . create Token ( User Token . TokenType . RESET ) ĊĠĠĠĠĠ Ġreset Password Service . request Reset Password (" user ", Ġ" url ") ĊĠĠĠĠĠ ĠassertThat ( user . tokens ). extract ing < String > Ġ{ Ġit . token Ġ}. contains Exactly ( existing User Token . token ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ verify Token () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( ĊĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" some user ", ĊĠĠĠĠĠĠĠ Ġperson Ġ= ĠPerson (" Bob ", Ġ" Sm ith "), ĊĠĠĠĠĠĠĠ Ġemail Ġ= Ġ" email ", ĊĠĠĠĠĠĠĠ Ġlocked Ġ= Ġtrue , ĊĠĠĠĠĠĠĠ Ġsource Ġ= Ġnom is ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( staff User Account For Bob ) ĊĠĠĠĠĠ Ġval Ġoptional Link Ġ= Ġreset Password Service . request Reset Password (" user ", Ġ" url ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Template "), ĊĠĠĠĠĠĠĠ Ġeq (" email "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). contains Only ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" firstName ", Ġ" Bob "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" fullName ", Ġ" Bob ĠSmith "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" reset Link ", Ġoptional Link . get ()) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional Link ). isPresent ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ uppercase Username () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" SO ME USER ", Ġemail Ġ= Ġ" email ", Ġlocked Ġ= Ġtrue , Ġsource Ġ= Ġnom is ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( staff User Account For Bob ) ĊĠĠĠĠĠ Ġreset Password Service . request Reset Password (" some user ", Ġ" url ") ĊĠĠĠĠĠ Ġverify ( user Repository ). findBy Username (" SO ME USER ") ĊĠĠĠĠĠ Ġverify ( userService ). find Enabled Or Nom is Locked User Person Details (" SO ME USER ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ verify Notification () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" some user ", Ġemail Ġ= Ġ" email ", Ġlocked Ġ= Ġtrue , Ġsource Ġ= Ġnom is ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( staff User Account For Bob ) ĊĠĠĠĠĠ Ġval Ġlink Optional Ġ= Ġreset Password Service . request Reset Password (" user ", Ġ" url ") ĊĠĠĠĠĠ Ġval Ġvalue Ġ= Ġuser . tokens . stream (). findFirst (). orElse Throw () ĊĠĠĠĠĠ ĠassertThat ( link Optional ). get (). isEqualTo ( String . format (" url - confirm ? token =% s ", Ġvalue . token )) ĊĠĠĠĠĠ ĠassertThat ( value . token Type ). isEqualTo ( User Token . TokenType . RESET ) ĊĠĠĠĠĠ ĠassertThat ( value . user . email ). isEqualTo (" email ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ send Failure () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" some user ", Ġemail Ġ= Ġ" email ", Ġlocked Ġ= Ġtrue , Ġsource Ġ= Ġnom is ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( staff User Account For Bob ) ĊĠĠĠĠĠ Ġwhenever ( notification Client . send Email ( any String (), Ġany String (), Ġany Map < String , ĠAny ?> (), Ġis Null ())). then Throw ( ĊĠĠĠĠĠĠĠ ĠNotification ClientException (" message ") ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat Thrown By Ġ{ ĊĠĠĠĠĠĠĠ Ġreset Password Service . request Reset Password ( ĊĠĠĠĠĠĠĠĠĠ Ġ" user ", ĊĠĠĠĠĠĠĠĠĠ Ġ" url " ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ}. has Message Containing (" Notification ClientException : Ġmessage ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ email Address NotFound () Ġ{ ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Email ( any ())). thenReturn ( emptyList ()) ĊĠĠĠĠĠ Ġval Ġoptional Ġ= Ġreset Password Service . request Reset Password (" some user @ some where ", Ġ" url ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Unavailable Email NotFound Template "), ĊĠĠĠĠĠĠĠ Ġeq (" some user @ some where "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). isEmpty () ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional ). isEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ email Address NotFound _ format Email Input () Ġ{ ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Email ( any ())). thenReturn ( emptyList ()) ĊĠĠĠĠĠ Ġval Ġoptional Ġ= Ġreset Password Service . request Reset Password (" some . u âĢĻ ser @ SO ME where ", Ġ" url ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Unavailable Email NotFound Template "), ĊĠĠĠĠĠĠĠ Ġeq (" some . u 's er @ some where "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). isEmpty () ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional ). isEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ multiple Email Addresses () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( ĊĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" some user ", ĊĠĠĠĠĠĠĠ Ġemail Ġ= Ġ" email ", ĊĠĠĠĠĠĠĠ Ġperson Ġ= ĠPerson (" Bob ", Ġ" Sm ith "), ĊĠĠĠĠĠĠĠ Ġenabled Ġ= Ġtrue ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Email ( any ())). thenReturn ( listOf ( user , Ġuser )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( user ) ĊĊĠĠĠĠĠ Ġval Ġoptional Ġ= Ġreset Password Service . request Reset Password (" some user @ some where ", Ġ" http :// url ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Template "), ĊĠĠĠĠĠĠĠ Ġeq (" email "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). contains Only ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" firstName ", Ġ" Bob "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" fullName ", Ġ" Bob ĠSmith "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" reset Link ", Ġoptional . get ()) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional ). isPresent ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ multiple Email Addresses _ verify Token () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( ĊĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" some user ", ĊĠĠĠĠĠĠĠ Ġemail Ġ= Ġ" email ", ĊĠĠĠĠĠĠĠ Ġperson Ġ= ĠPerson (" Bob ", Ġ" Sm ith "), ĊĠĠĠĠĠĠĠ Ġenabled Ġ= Ġtrue ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Email ( any ())). thenReturn ( listOf ( user , Ġuser )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( user ) ĊĠĠĠĠĠ Ġval Ġlink Optional Ġ= Ġreset Password Service . request Reset Password (" some user @ some where ", Ġ" http :// url ") ĊĠĠĠĠĠ Ġval Ġuser Token Ġ= Ġuser . tokens . stream (). findFirst (). orElse Throw () ĊĠĠĠĠĠ ĠassertThat ( link Optional ). get (). isEqualTo ( String . format (" http :// url - select ? token =% s ", Ġuser Token . token )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ multiple Email Addresses _ none Can Be Reset () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= ĊĠĠĠĠĠĠĠ Ġcreate Sample User ( username Ġ= Ġ" some user ", Ġemail Ġ= Ġ" email ", Ġlocked Ġ= Ġtrue , Ġperson Ġ= ĠPerson (" Bob ", Ġ" Sm ith ")) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Email ( any ())). thenReturn ( listOf ( user , Ġuser )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( user ) ĊĠĠĠĠĠ Ġval Ġoptional Ġ= Ġreset Password Service . request Reset Password (" some user @ some where ", Ġ" http :// url ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Unavailable Template "), ĊĠĠĠĠĠĠĠ Ġeq (" email "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). contains Only ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" firstName ", Ġ" Bob "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" fullName ", Ġ" Bob ĠSmith "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" nom is User ", Ġfalse ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" deli us User ", Ġfalse ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" auth User ", Ġtrue ) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional ). isEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequest Reset Password _ by Email () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" some user ", Ġemail Ġ= Ġ" email ", Ġlocked Ġ= Ġtrue , Ġsource Ġ= Ġnom is ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Email ( any String ())). thenReturn ( listOf ( user )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( staff User Account For Bob ) ĊĠĠĠĠĠ Ġval Ġoptional Link Ġ= Ġreset Password Service . request Reset Password (" user @ where ", Ġ" url ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Template "), ĊĠĠĠĠĠĠĠ Ġeq (" email "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). contains Only ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" firstName ", Ġ" Bob "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" fullName ", Ġ" Bob ĠSmith "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" reset Link ", Ġoptional Link . get ()) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional Link ). isPresent ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Nom is ĠUser Ġwho Ġhas Ġnot Ġlogged Ġinto Ġauth Ġcan Ġreset Ġpassword `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠ Ġval Ġstandard User Ġ= Ġbuild Standard User (" user ") ĊĠĠĠĠĠ Ġwhenever ( userService . find Master User Person Details ( any String ())). thenReturn ( Optional . of ( standard User )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( standard User ) ĊĠĠĠĠĠ Ġwhenever ( userService . get EmailAddress From Nom is ( any String ())). thenReturn ( Optional . of (" Bob . smith @ just ice . gov . uk ")) ĊĠĠĠĠĠ Ġval Ġoptional Link Ġ= Ġreset Password Service . request Reset Password (" user ", Ġ" url ") ĊĠĠĠĠĠ ĠassertThat ( optional Link ). isPresent ĊĠĠĠĠĠ Ġverify ( user Repository ). save ( ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ Ġuser Ġ-> ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( user . username ). isEqualTo (" user ") ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( user . email ). isEqualTo (" Bob . smith @ just ice . gov . uk ") ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( user . verified ). isTrue ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( user . source ). isEqualTo ( nom is ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Nom is ĠUser Ġwho Ġhas Ġnot Ġlogged Ġinto ĠD PS Ġcan Ġreset Ġpassword Ġwith Ġemail `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Person Details Ġ= Ġbuild Standard User (" user ") ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" some user ", Ġemail Ġ= Ġ" a @ b . com ", Ġperson Ġ= ĠPerson (" Bob ", Ġ" Sm ith "), Ġenabled Ġ= Ġtrue , Ġsource Ġ= Ġnom is , Ġverified Ġ= Ġtrue ) ĊĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Email ( any String ())). thenReturn ( listOf (), ĠlistOf ( user )) ĊĠĠĠĠĠ Ġwhenever ( userService . find User Person Details By Email ( any String (), Ġeq ( nom is ))). thenReturn ( ĊĠĠĠĠĠĠĠ ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠ Ġcreate Sample Nom is User (" user ", Ġemail Ġ= Ġ" Bob . smith @ just ice . gov . uk ", ĠfirstName Ġ= Ġ" Bob ", ĠlastName Ġ= Ġ" Sm ith ") ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġwhenever ( userService . get EmailAddress From Nom is ( any String ())). thenReturn ( Optional . of (" Bob . smith @ just ice . gov . uk ")) ĊĠĠĠĠĠ Ġwhenever ( userService . find Master User Person Details ( any String ())). thenReturn ( Optional . of ( user Person Details )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( user Person Details ) ĊĊĠĠĠĠĠ Ġval Ġoptional Link Ġ= Ġreset Password Service . request Reset Password (" some user @ some where ", Ġ" http :// url ") ĊĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Template "), ĊĠĠĠĠĠĠĠ Ġeq (" a @ b . com "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). contains Only ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" firstName ", Ġ" Bob "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" fullName ", Ġ" Bob ĠSmith "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" reset Link ", Ġoptional Link . get ()) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional Link ). isPresent ĊĊĠĠĠĠĠ Ġverify ( user Repository ). save ( ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it . username ). isEqualTo (" user ") ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it . email ). isEqualTo (" Bob . smith @ just ice . gov . uk ") ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it . verified ). isTrue ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it . source ). isEqualTo ( nom is ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` User Ġwho Ġhas Ġnot Ġlogged Ġinto ĠD PS Ġthat Ġhas Ġaccounts Ġin Ġboth Ġnom is Ġand Ġdeli us Ġ( with Ġthe Ġsame Ġemail ) Ġcannot Ġreset Ġpassword Ġwith Ġemail `() Ġ{ ĊĠĠĠĠĠ Ġval Ġnom is UserDetails Ġ= Ġbuild Standard User (" user ") ĊĠĠĠĠĠ Ġval Ġdeli us UserDetails Ġ= Ġcreate Del ius User () ĊĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Email ( any String ())). thenReturn ( listOf ()) Ġ// Ġno Ġuser Ġin Ġauth ĊĠĠĠĠĠ Ġwhenever ( userService . find User Person Details By Email ( any String (), Ġeq ( nom is ))). thenReturn ( listOf ( nom is UserDetails )) ĊĠĠĠĠĠ Ġwhenever ( userService . find User Person Details By Email ( any String (), Ġeq ( deli us ))). thenReturn ( listOf ( deli us UserDetails )) ĊĠĠĠĠĠ Ġwhenever ( userService . get EmailAddress From Nom is ( any String ())). thenReturn ( Optional . of (" Bob . smith @ just ice . gov . uk ")) ĊĠĠĠĠĠ Ġwhenever ( userService . find Master User Person Details ( any String ())). thenReturn ( Optional . of ( nom is UserDetails )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( nom is UserDetails ) ĊĊĠĠĠĠĠ Ġval Ġoptional Link Ġ= Ġreset Password Service . request Reset Password (" some user @ some where ", Ġ" http :// url ") ĊĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Unavailable Email NotFound Template "), ĊĠĠĠĠĠĠĠ Ġeq (" some user @ some where "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). isEmpty () ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional Link ). isEmpty ĊĠĠĠĠĠ Ġverify ( user Repository , Ġnever ()). save ( any ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Nom is ĠUser Ġwho Ġhas Ġnot Ġlogged Ġreset Ġpassword Ġrequest Ġno Ġemail `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠ Ġwhenever ( userService . find Master User Person Details ( any String ())). thenReturn ( Optional . of ( build Standard User (" user "))) ĊĠĠĠĠĠ Ġwhenever ( userService . get EmailAddress From Nom is ( any String ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠ Ġval Ġoptional Ġ= Ġreset Password Service . request Reset Password (" user ", Ġ" url ") ĊĠĠĠĠĠ ĠassertThat ( optional ). isEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Del ius ĠUser Ġwho Ġhas Ġnot Ġlogged Ġinto ĠD PS Ġreset Ġpassword Ġrequest `() Ġ{ ĊĠĠĠĠĠ Ġval Ġdeli us User Ġ= Ġcreate Del ius User () ĊĠĠĠĠĠ Ġwhenever ( userService . find Master User Person Details ( any String ())). thenReturn ( Optional . of ( deli us User )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( deli us User ) ĊĠĠĠĠĠ Ġval Ġoptional Link Ġ= Ġreset Password Service . request Reset Password (" user ", Ġ" url ") ĊĠĠĠĠĠ ĠassertThat ( optional Link ). isPresent ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Del ius ĠUser Ġwho Ġhas Ġnot Ġlogged Ġinto ĠD PS Ġcan Ġreset Ġpassword Ġrequest Ġwith Ġemail `() Ġ{ ĊĠĠĠĠĠ Ġval Ġdeli us UserDetails Ġ= Ġcreate Del ius User () ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" some user ", Ġemail Ġ= Ġ" a @ b . com ", Ġperson Ġ= ĠPerson (" Bob ", Ġ" Sm ith "), Ġenabled Ġ= Ġtrue , Ġsource Ġ= Ġdeli us , Ġverified Ġ= Ġtrue ) ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Email ( any String ())). thenReturn ( listOf (), ĠlistOf ( user )) Ġ// Ġno Ġuser Ġin Ġauth ĊĠĠĠĠĠ Ġwhenever ( userService . find User Person Details By Email ( any String (), Ġeq ( deli us ))). thenReturn ( listOf ( deli us UserDetails )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( deli us UserDetails ) ĊĊĠĠĠĠĠ Ġval Ġoptional Link Ġ= Ġreset Password Service . request Reset Password (" a @ b . com ", Ġ" http :// url ") ĊĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Template "), ĊĠĠĠĠĠĠĠ Ġeq (" a @ b . com "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). contains Only ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" firstName ", Ġ" F "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" fullName ", Ġ" F ĠL "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry (" reset Link ", Ġoptional Link . get ()) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional Link ). isPresent ĊĊĠĠĠĠĠ Ġverify ( user Repository ). save ( ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it . username ). isEqualTo (" user ") ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it . email ). isEqualTo (" a @ b . com ") ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it . verified ). isTrue ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it . source ). isEqualTo ( deli us ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Del ius ĠUser Ġwho Ġhas Ġnot Ġlogged Ġinto ĠD PS Ġwith Ġmultiple Ġemail Ġaccounts Ġcan Ġnot Ġbe Ġreset `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Del ius User () ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . empty ()) Ġ// Ġno Ġuser Ġin Ġauth ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( user ) ĊĠĠĠĠĠ Ġwhenever ( userService . find User Person Details By Email ( any String (), Ġany ())). thenReturn ( listOf ( user , Ġuser )) ĊĠĠĠĠĠ Ġval Ġoptional Ġ= Ġreset Password Service . request Reset Password (" some user @ some where ", Ġ" http :// url ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġeq (" reset Unavailable Email NotFound Template "), ĊĠĠĠĠĠĠĠ Ġeq (" some user @ some where "), ĊĠĠĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). isEmpty () ĊĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠ Ġis Null () ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ ĠassertThat ( optional ). isEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Del ius ĠUser Ġnot Ġenabled Ġwho Ġhas Ġnot Ġlogged Ġinto ĠD PS Ġreset Ġpassword Ġrequest `() Ġ{ ĊĠĠĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠ Ġval Ġdeli us User Not Enabled Ġ= Ġcreate Del ius User Not Enabled () ĊĠĠĠĠĠ Ġwhenever ( userService . find Master User Person Details ( any String ())). thenReturn ( Optional . of ( deli us User Not Enabled )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( deli us User Not Enabled ) ĊĠĠĠĠĠ Ġval Ġoptional Ġ= Ġreset Password Service . request Reset Password (" user ", Ġ" url ") ĊĠĠĠĠĠ ĠassertThat ( optional ). isEmpty ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġval Ġstaff User Account For Bob : ĠNom is User Person Details ĊĠĠĠ Ġget () Ġ{ ĊĠĠĠĠĠ Ġreturn Ġnom is User Person Details ( Account Status . OPEN ) ĊĠĠĠ Ġ} ĊĠ Ġprivate Ġval Ġstaff User Account Locked For Bob : ĠNom is User Person Details ĊĠĠĠ Ġget () Ġ{ ĊĠĠĠĠĠ Ġreturn Ġnom is User Person Details ( Account Status . LOCK ED ) ĊĠĠĠ Ġ} ĊĠ Ġprivate Ġval Ġstaff User Account Expired Locked For Bob : ĠNom is User Person Details ĊĠĠĠ Ġget () Ġ{ ĊĠĠĠĠĠ Ġreturn Ġnom is User Person Details ( Account Status . EXPI RED _ LOCK ED _ TIME D ) ĊĠĠĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġnom is User Person Details ( account Status : ĠAccount Status , Ġenabled : ĠBoolean Ġ= Ġtrue , Ġlocked : ĠBoolean Ġ= Ġfalse , Ġactive : ĠBoolean Ġ= Ġtrue ): ĠNom is User Person Details Ġ= ĊĠĠĠ Ġcreate Sample Nom is User ( account Status Ġ= Ġaccount Status , ĠfirstName Ġ= Ġ" Bob ", ĠlastName Ġ= Ġ" Sm ith ", Ġenabled Ġ= Ġenabled , Ġlocked Ġ= Ġlocked , Ġactive Ġ= Ġactive ) ĊĊĠ Ġprivate Ġval Ġstaff User Account For Bob Optional : ĠOptional < User Person Details > Ġ= ĠOptional . of ( staff User Account For Bob ) ĊĊĠ Ġ@ Nested ĊĠ Ġinner Ġclass Ġset Password Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġreset Password () Ġ{ ĊĠĠĠĠĠ Ġval Ġstaff User Account For Bob Ġ= Ġstaff User Account For Bob ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( staff User Account For Bob ) ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" USER ", Ġperson Ġ= ĠPerson (" First ", Ġ" Last "), Ġsource Ġ= Ġnom is ) ĊĠĠĠĠĠ Ġval Ġuser Token Ġ= Ġuser . create Token ( User Token . TokenType . RESET ) ĊĠĠĠĠĠ Ġwhenever ( user Token Repository . findById ( any String ())). thenReturn ( Optional . of ( user Token )) ĊĠĠĠĠĠ Ġreset Password Service . set Password (" bob ", Ġ" pass ") ĊĠĠĠĠĠ ĠassertThat ( user . tokens ). isEmpty () ĊĠĠĠĠĠ Ġverify ( user Repository ). save ( user ) ĊĠĠĠĠĠ Ġverify ( deleg ating UserService ). change Password With Unlock ( staff User Account For Bob , Ġ" pass ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġ" reset - confirm ", ĊĠĠĠĠĠĠĠ Ġnull , ĊĠĠĠĠĠĠĠ Ġmap Of (" firstName " Ġto Ġ" First ", Ġ" fullName " Ġto Ġ" First ĠLast ", Ġ" username " Ġto Ġ" USER "), ĊĠĠĠĠĠĠĠ Ġnull ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Reset Ġpassword Ġ- Ġwhen Ġusername Ġis Ġemail Ġaddress , Ġreset Ġpassword Ġemail Ġtext Ġto Ġcontain Ġusername Ġin Ġlower Ġcase `() Ġ{ ĊĠĠĠĠĠ Ġval Ġstaff User Account For Bob Ġ= Ġstaff User Account For Bob ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( staff User Account For Bob ) ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( ĊĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" SO ME USER @ SO ME WHERE . COM ", ĊĠĠĠĠĠĠĠ Ġperson Ġ= ĠPerson (" First ", Ġ" Last "), ĊĠĠĠĠĠĠĠ Ġsource Ġ= Ġnom is , ĊĠĠĠĠĠĠĠ Ġemail Ġ= Ġ" some user @ some where . com " ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġval Ġuser Token Ġ= Ġuser . create Token ( User Token . TokenType . RESET ) ĊĠĠĠĠĠ Ġwhenever ( user Token Repository . findById ( any String ())). thenReturn ( Optional . of ( user Token )) ĊĠĠĠĠĠ Ġreset Password Service . set Password (" bob ", Ġ" pass ") ĊĠĠĠĠĠ ĠassertThat ( user . tokens ). isEmpty () ĊĠĠĠĠĠ Ġverify ( user Repository ). save ( user ) ĊĠĠĠĠĠ Ġverify ( deleg ating UserService ). change Password With Unlock ( staff User Account For Bob , Ġ" pass ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġ" reset - confirm ", ĊĠĠĠĠĠĠĠ Ġ" some user @ some where . com ", ĊĠĠĠĠĠĠĠ Ġmap Of (" firstName " Ġto Ġ" First ", Ġ" fullName " Ġto Ġ" First ĠLast ", Ġ" username " Ġto Ġ" some user @ some where . com "), ĊĠĠĠĠĠĠĠ Ġnull ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġreset Password _ auth User () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( ĊĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" user ", ĊĠĠĠĠĠĠĠ Ġperson Ġ= ĠPerson (" First ", Ġ" Last "), ĊĠĠĠĠĠĠĠ Ġenabled Ġ= Ġtrue , ĊĠĠĠĠĠĠĠ Ġsource Ġ= Ġauth , ĊĠĠĠĠĠĠĠ Ġlocked Ġ= Ġtrue ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġval Ġuser Token Ġ= Ġuser . create Token ( User Token . TokenType . RESET ) ĊĠĠĠĠĠ Ġwhenever ( user Token Repository . findById ( any String ())). thenReturn ( Optional . of ( user Token )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details (" user ")). thenReturn ( user ) ĊĠĠĠĠĠ Ġreset Password Service . set Password (" bob ", Ġ" pass ") ĊĠĠĠĠĠ ĠassertThat ( user . tokens ). isEmpty () ĊĠĠĠĠĠ Ġverify ( user Repository ). save ( user ) ĊĠĠĠĠĠ Ġverify ( deleg ating UserService ). change Password With Unlock ( any (), Ġany String ()) ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġ" reset - confirm ", ĊĠĠĠĠĠĠĠ Ġnull , ĊĠĠĠĠĠĠĠ Ġmap Of (" firstName " Ġto Ġ" First ", Ġ" fullName " Ġto Ġ" First ĠLast ", Ġ" username " Ġto Ġ" user "), ĊĠĠĠĠĠĠĠ Ġnull ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġreset Password _ deli us User () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= ĊĠĠĠĠĠĠĠ Ġcreate Sample User ( ĊĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" user ", ĊĠĠĠĠĠĠĠĠĠ Ġperson Ġ= ĠPerson (" First ", Ġ" Last "), ĊĠĠĠĠĠĠĠĠĠ Ġenabled Ġ= Ġtrue , ĊĠĠĠĠĠĠĠĠĠ Ġsource Ġ= Ġdeli us , ĊĠĠĠĠĠĠĠĠĠ Ġlocked Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġval Ġuser Token Ġ= Ġuser . create Token ( User Token . TokenType . RESET ) ĊĠĠĠĠĠ Ġval Ġdeli us User Person Details Ġ= ĊĠĠĠĠĠĠĠ ĠDel ius User Person Details (" user ", Ġ" 1 2 3 4 5 ", Ġ" Del ius ", Ġ" Sm ith ", Ġ" a @ b . com ", Ġtrue , Ġfalse , Ġset Of ()) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details (" user ")). thenReturn ( deli us User Person Details ) ĊĠĠĠĠĠ Ġwhenever ( user Token Repository . findById ( any String ())). thenReturn ( Optional . of ( user Token )) ĊĠĠĠĠĠ Ġreset Password Service . set Password (" bob ", Ġ" pass ") ĊĠĠĠĠĠ ĠassertThat ( user . tokens ). isEmpty () ĊĠĠĠĠĠ Ġverify ( user Repository ). save ( user ) ĊĠĠĠĠĠ Ġverify ( deleg ating UserService ). change Password With Unlock ( any (), Ġany String ()) ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġ" reset - confirm ", ĊĠĠĠĠĠĠĠ Ġnull , ĊĠĠĠĠĠĠĠ Ġmap Of (" firstName " Ġto Ġ" First ", Ġ" fullName " Ġto Ġ" First ĠLast ", Ġ" username " Ġto Ġ" user "), ĊĠĠĠĠĠĠĠ Ġnull ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġreset Password Expired () Ġ{ ĊĠĠĠĠĠ Ġval Ġstaff User Account Ġ= Ġnom is User Person Details ( Account Status . EXPI RED , Ġenabled Ġ= Ġtrue , Ġlocked Ġ= Ġfalse , Ġactive Ġ= Ġfalse ) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( staff User Account ) ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" USER ", Ġperson Ġ= ĠPerson (" First ", Ġ" Last "), Ġsource Ġ= Ġnom is ) ĊĠĠĠĠĠ Ġval Ġuser Token Ġ= Ġuser . create Token ( User Token . TokenType . RESET ) ĊĠĠĠĠĠ Ġwhenever ( user Token Repository . findById ( any String ())). thenReturn ( Optional . of ( user Token )) ĊĠĠĠĠĠ Ġreset Password Service . set Password (" bob ", Ġ" pass ") ĊĠĠĠĠĠ ĠassertThat ( user . tokens ). isEmpty () ĊĠĠĠĠĠ Ġverify ( user Repository ). save ( user ) ĊĠĠĠĠĠ Ġverify ( deleg ating UserService ). change Password With Unlock ( staff User Account , Ġ" pass ") ĊĠĠĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠĠĠ Ġ" reset - confirm ", ĊĠĠĠĠĠĠĠ Ġnull , ĊĠĠĠĠĠĠĠ Ġmap Of (" firstName " Ġto Ġ" First ", Ġ" fullName " Ġto Ġ" First ĠLast ", Ġ" username " Ġto Ġ" USER "), ĊĠĠĠĠĠĠĠ Ġnull ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġreset Password Locked Account () Ġ{ ĊĠĠĠĠĠ Ġval Ġstaff User Account Ġ= ĊĠĠĠĠĠĠĠ Ġnom is User Person Details ( Account Status . EXPI RED _ LOCK ED , Ġenabled Ġ= Ġfalse , Ġlocked Ġ= Ġtrue , Ġactive Ġ= Ġfalse ) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details ( any String ())). thenReturn ( staff User Account ) ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" user ", Ġsource Ġ= Ġnom is , Ġlocked Ġ= Ġfalse ) ĊĠĠĠĠĠ Ġval Ġuser Token Ġ= Ġuser . create Token ( User Token . TokenType . RESET ) ĊĠĠĠĠĠ Ġwhenever ( user Token Repository . findById ( any String ())). thenReturn ( Optional . of ( user Token )) ĊĠĠĠĠĠ ĠassertThat Thrown By Ġ{ Ġreset Password Service . set Password (" bob ", Ġ" pass ") Ġ}. isInstanceOf ( Locked Exception :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġreset Password Locked Account _ auth User () Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" user ") ĊĠĠĠĠĠ Ġval Ġuser Token Ġ= Ġuser . create Token ( User Token . TokenType . RESET ) ĊĠĠĠĠĠ Ġwhenever ( user Token Repository . findById ( any String ())). thenReturn ( Optional . of ( user Token )) ĊĠĠĠĠĠ Ġwhenever ( userService . find Enabled Or Nom is Locked User Person Details (" user ")). thenReturn ( user ) ĊĠĠĠĠĠ ĠassertThat Thrown By Ġ{ Ġreset Password Service . set Password (" bob ", Ġ" pass ") Ġ}. isInstanceOf ( Locked Exception :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` set Ġpassword Ġno Ġenabled Ġaccount `() Ġ{ ĊĠĠĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" user ") ĊĠĠĠĠĠ Ġval Ġuser Token Ġ= Ġuser . create Token ( User Token . TokenType . RESET ) ĊĠĠĠĠĠ Ġwhenever ( user Token Repository . findById ( any String ())). thenReturn ( Optional . of ( user Token )) ĊĠĠĠĠĠ ĠassertThat Thrown By Ġ{ Ġreset Password Service . set Password (" bob ", Ġ" pass ") Ġ}. isInstanceOf ( Reset Password Exception :: class . java ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġmove Token To Account _ missing Username () Ġ{ ĊĠĠĠ ĠassertThat Thrown By Ġ{ ĊĠĠĠĠĠ Ġreset Password Service . move Token To Account ( ĊĠĠĠĠĠĠĠ Ġ" token ", ĊĠĠĠĠĠĠĠ Ġ" Ġ Ġ" ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ}. has Message Containing (" failed Ġwith Ġreason : Ġmissing ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġmove Token To Account _ username NotFound () Ġ{ ĊĠĠĠ ĠassertThat Thrown By Ġ{ ĊĠĠĠĠĠ Ġreset Password Service . move Token To Account ( ĊĠĠĠĠĠĠĠ Ġ" token ", ĊĠĠĠĠĠĠĠ Ġ" no one " ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ}. has Message Containing (" failed Ġwith Ġreason : Ġnot found ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġmove Token To Account _ different Email () Ġ{ ĊĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( ĊĠĠĠĠĠ ĠOptional . of ( ĊĠĠĠĠĠĠĠ Ġcreate Sample User ( username Ġ= Ġ" user ", Ġemail Ġ= Ġ" email ", Ġverified Ġ= Ġtrue , Ġlocked Ġ= Ġtrue ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĠĠĠ Ġval Ġbuilt User Ġ= Ġcreate Sample User ( username Ġ= Ġ" other ", Ġemail Ġ= Ġ" em ai lo ther ", Ġverified Ġ= Ġtrue ) ĊĠĠĠ Ġwhenever ( user Token Repository . findById (" token ")). thenReturn ( Optional . of ( built User . create Token ( User Token . TokenType . RESET ))) ĊĠĠĠ ĠassertThat Thrown By Ġ{ ĊĠĠĠĠĠ Ġreset Password Service . move Token To Account ( ĊĠĠĠĠĠĠĠ Ġ" token ", ĊĠĠĠĠĠĠĠ Ġ" no one " ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ}. has Message Containing (" failed Ġwith Ġreason : Ġemail ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġmove Token To Account _ disabled () Ġ{ ĊĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( ĊĠĠĠĠĠ ĠOptional . of ( create Sample User ( username Ġ= Ġ" user ", Ġemail Ġ= Ġ" email ", Ġverified Ġ= Ġtrue )) ĊĠĠĠ Ġ) ĊĠĠĠ Ġval Ġbuilt User Ġ= Ġcreate Sample User ( username Ġ= Ġ" other ", Ġemail Ġ= Ġ" email ", Ġverified Ġ= Ġtrue ) ĊĠĠĠ Ġwhenever ( user Token Repository . findById (" token ")). thenReturn ( Optional . of ( built User . create Token ( User Token . TokenType . RESET ))) ĊĠĠĠ ĠassertThat Thrown By Ġ{ Ġreset Password Service . move Token To Account (" token ", Ġ" no one ") Ġ}. extract ing (" reason ") ĊĠĠĠĠĠ Ġ. isEqualTo (" locked ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġmove Token To Account _ same User Account () Ġ{ ĊĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" USER ", Ġemail Ġ= Ġ" email ", Ġverified Ġ= Ġtrue , Ġenabled Ġ= Ġtrue ) ĊĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠ Ġwhenever ( user Token Repository . findById (" token ")). thenReturn ( Optional . of ( user . create Token ( User Token . TokenType . RESET ))) ĊĠĠĠ Ġval Ġnew Token Ġ= Ġreset Password Service . move Token To Account (" token ", Ġ" USER ") ĊĠĠĠ ĠassertThat ( new Token ). isEqualTo (" token ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġmove Token To Account _ different Account () Ġ{ ĊĠĠĠ Ġval Ġuser Ġ= Ġcreate Sample User ( username Ġ= Ġ" USER ", Ġemail Ġ= Ġ" email ", Ġverified Ġ= Ġtrue , Ġenabled Ġ= Ġtrue ) ĊĠĠĠ Ġwhenever ( user Repository . findBy Username ( any String ())). thenReturn ( Optional . of ( user )) ĊĠĠĠ Ġval Ġbuilt User Ġ= Ġcreate Sample User ( username Ġ= Ġ" other ", Ġemail Ġ= Ġ" email ", Ġverified Ġ= Ġtrue ) ĊĠĠĠ Ġval Ġuser Token Ġ= Ġbuilt User . create Token ( User Token . TokenType . RESET ) ĊĠĠĠ Ġwhenever ( user Token Repository . findById (" token ")). thenReturn ( Optional . of ( user Token )) ĊĠĠĠ Ġval Ġnew Token Ġ= Ġreset Password Service . move Token To Account (" token ", Ġ" USER ") ĊĠĠĠ ĠassertThat ( new Token ). has Size ( 3 6 ) ĊĠĠĠ Ġverify ( user Token Repository ). delete ( user Token ) ĊĠĠĠ ĠassertThat ( user . tokens ). extract ing < String > Ġ{ Ġobj : ĠUser Token Ġ-> Ġobj . token Ġ}. contains Exactly ( new Token ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġcreate Del ius User () Ġ= ĊĠĠĠ ĠDel ius User Person Details ( ĊĠĠĠĠĠ Ġusername Ġ= Ġ" user ", ĊĠĠĠĠĠ ĠuserId Ġ= Ġ" 1 2 3 4 5 ", ĊĠĠĠĠĠ ĠfirstName Ġ= Ġ" F ", ĊĠĠĠĠĠ Ġs urname Ġ= Ġ" L ", ĊĠĠĠĠĠ Ġemail Ġ= Ġ" a @ b . com ", ĊĠĠĠĠĠ Ġenabled Ġ= Ġtrue ĊĠĠĠ Ġ) ĊĊĠ Ġprivate Ġfun Ġcreate Del ius User Not Enabled () Ġ= ĊĠĠĠ ĠDel ius User Person Details ( ĊĠĠĠĠĠ Ġusername Ġ= Ġ" user ", ĊĠĠĠĠĠ ĠuserId Ġ= Ġ" 1 2 3 4 5 ", ĊĠĠĠĠĠ ĠfirstName Ġ= Ġ" F ", ĊĠĠĠĠĠ Ġs urname Ġ= Ġ" L ", ĊĠĠĠĠĠ Ġemail Ġ= Ġ" a @ b . com ", ĊĠĠĠĠĠ Ġenabled Ġ= Ġfalse ĊĠĠĠ Ġ) ĊĊĠ Ġprivate Ġfun Ġbuild Standard User ( ĊĠĠĠ Ġusername : ĠString , ĊĠĠĠ Ġaccount Status : ĠAccount Status Ġ= ĠAccount Status . OPEN , ĊĠĠĠ Ġaccount Non Locked : ĠBoolean Ġ= Ġtrue , ĊĠĠĠ Ġcredentials Non Expired : ĠBoolean Ġ= Ġtrue , ĊĠĠĠ Ġenabled : ĠBoolean Ġ= Ġtrue ĊĠ Ġ): ĠNom is User Person Details Ġ{ ĊĠĠĠ Ġreturn ĠNom is User Person Details ( ĊĠĠĠĠĠ Ġusername Ġ= Ġusername , ĊĠĠĠĠĠ Ġaccount Status Ġ= Ġaccount Status , ĊĠĠĠĠĠ ĠuserId Ġ= Ġ" 1 ", ĊĠĠĠĠĠ ĠfirstName Ġ= Ġ" Bob ", ĊĠĠĠĠĠ Ġs urname Ġ= Ġ" Sm ith ", ĊĠĠĠĠĠ Ġactive Case Load Id Ġ= Ġ" BX I ", ĊĠĠĠĠĠ Ġemail Ġ= Ġ" Bob . smith @ just ice . gov . uk ", ĊĠĠĠĠĠ Ġaccount Non Locked Ġ= Ġaccount Non Locked , ĊĠĠĠĠĠ Ġcredentials Non Expired Ġ= Ġcredentials Non Expired , ĊĠĠĠĠĠ Ġenabled Ġ= Ġenabled , ĊĠĠĠĠĠ Ġactive Ġ= Ġtrue ĊĠĠĠ Ġ) ĊĠ Ġ} Ċ } Ċ