package Ġuk . gov . just ice . digital . h mp ps . deli us api . service . staff Ċ Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify No More Interactions Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . assert Throws Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġorg . mockito . Argument Matchers Ċ import Ġorg . mockito . Inject Mocks Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . junit . jupiter . Mockito Extension Ċ import Ġorg . mockito . junit . jupiter . Mockito Settings Ċ import Ġorg . mockito . quality . Strict ness Ċ import Ġuk . gov . just ice . digital . h mp ps . deli us api . dto . v 1 . staff . New Staff Ċ import Ġuk . gov . just ice . digital . h mp ps . deli us api . exception . BadRequest Exception Ċ import Ġuk . gov . just ice . digital . h mp ps . deli us api . mapper . Staff Mapper Ċ import Ġuk . gov . just ice . digital . h mp ps . deli us api . repository . Provider Repository Ċ import Ġuk . gov . just ice . digital . h mp ps . deli us api . repository . Staff Repository Ċ import Ġuk . gov . just ice . digital . h mp ps . deli us api . util . Fake Ċ Ċ @ Extend With ( Mockito Extension :: class ) Ċ @ Mockito Settings ( strict ness Ġ= ĠStrict ness . LEN IENT ) Ċ class ĠStaff Service Test Ġ{ ĊĊĠ Ġ@ Mock ĊĠ Ġprivate Ġlateinit Ġvar Ġstaff Repository : ĠStaff Repository ĊĊĠ Ġ@ Mock ĊĠ Ġprivate Ġlateinit Ġvar Ġprovider Repository : ĠProvider Repository ĊĊĠ Ġ@ Mock ĊĠ Ġprivate Ġlateinit Ġvar Ġmapper : ĠStaff Mapper ĊĊĠ Ġ@ Inject Mocks ĊĠ Ġlateinit Ġvar Ġsubject : ĠStaff Service ĊĊĠ Ġprivate Ġlateinit Ġvar Ġrequest : ĠNew Staff ĊĊĠ Ġprivate Ġval Ġprovider Ġ= ĠFake . provider () ĊĊĠ Ġprivate Ġval Ġstaff Ġ= ĠFake . staff ( provider ) ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` creating Ġstaff Ġmember `() Ġ{ ĊĠĠĠ Ġwith Request () ĊĠĠĠ Ġhaving Repositories () ĊĠĠĠ Ġwhen Calling Create Staff () ĊĠĠĠ Ġshould Save Staff () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` at tempting Ġto Ġcreate Ġstaff Ġwith Ġinvalid Ġprovider `() Ġ{ ĊĠĠĠ Ġwith Request () ĊĠĠĠ Ġhaving Repositories ( provider Exists Ġ= Ġfalse ) ĊĠĠĠ Ġshould Throw BadRequest () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` at tempting Ġto Ġcreate Ġstaff Ġwith Ġinvalid Ġteam `() Ġ{ ĊĠĠĠ Ġwith Request ( invalid Team Ġ= Ġtrue ) ĊĠĠĠ Ġshould Throw BadRequest () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġwith Request ( invalid Team : ĠBoolean Ġ= Ġfalse ) Ġ{ ĊĊĠĠĠ Ġif Ġ(! invalid Team ) Ġ{ ĊĠĠĠĠĠ Ġstaff . apply Ġ{ ĊĠĠĠĠĠĠĠ Ġstaff . teams . clear () ĊĠĠĠĠĠĠĠ Ġthis . add Team ( provider !!. teams . first ()) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġrequest Ġ= ĠFake . staff Mapper . to New ( Fake . staff Mapper . to Dto ( staff )) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġhaving Repositories ( provider Exists : ĠBoolean Ġ= Ġtrue ) Ġ{ ĊĠĠĠ Ġif Ġ( provider Exists ) Ġ{ ĊĠĠĠĠĠ Ġwhenever ( provider Repository . findBy Code And Selectable IsTrue ( any ())). thenReturn ( provider ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġwhenever ( provider Repository . getNext Staff Code ( any ())). thenReturn (" ABC 0 0 1 ") ĊĠĠĠ Ġwhenever ( staff Repository . save And Flush ( any ())). thenReturn ( staff ) ĊĠĠĠ Ġwhenever ( mapper . to Dto ( any ())). thenReturn ( Fake . staff Mapper . to Dto ( staff )) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġwhen Calling Create Staff () Ġ{ ĊĠĠĠ Ġval Ġresponse Ġ= Ġsubject . create Staff ( request ) ĊĠĠĠ Ġval Ġexpected Response Ġ= ĠFake . staff Mapper . to Dto ( staff ) ĊĊĠĠĠ ĠassertThat ( response ). isEqualTo ( expected Response ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġshould Throw BadRequest () Ġ{ ĊĠĠĠ ĠassertThrows < BadRequest Exception > Ġ{ ĊĠĠĠĠĠ Ġsubject . create Staff ( request ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġshould Save Staff () Ġ{ ĊĠĠĠ Ġverify ( staff Repository ). save And Flush ( ĊĠĠĠĠĠ ĠArgument Matchers . arg That Ġ{ ĊĠĠĠĠĠĠĠ Ġ! it . private Staff Ġ&& ĊĠĠĠĠĠĠĠĠĠ Ġit . code Ġ== Ġ" ABC 0 0 1 " Ġ&& ĊĠĠĠĠĠĠĠĠĠ Ġit . firstName Ġ== Ġrequest . firstName Ġ&& ĊĠĠĠĠĠĠĠĠĠ Ġit . lastName Ġ== Ġrequest . lastName Ġ&& ĊĠĠĠĠĠĠĠĠĠ Ġit . provider Ġ== Ġprovider ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġverify No More Interactions ( staff Repository ) ĊĠ Ġ} Ċ } Ċ