package Ġuk . gov . just ice . digital . h mp ps . pec s . j pc . controller Ċ Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . never Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Zero Interactions Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . autoconfigure . web . servlet . Auto Configure MockMvc Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ import Ġorg . springframework . boot . test . mock . mockito . Mock Bean Ċ import Ġorg . springframework . test . context . Active Profiles Ċ import Ġorg . springframework . test . context . Context Configuration Ċ import Ġorg . springframework . test . web . servlet . get Ċ import Ġorg . springframework . test . web . servlet . post Ċ import Ġorg . springframework . test . web . servlet . setup . MockMvc Builders Ċ import Ġorg . springframework . web . context . Web ApplicationContext Ċ import Ġuk . gov . just ice . digital . h mp ps . pec s . j pc . Test Config Ċ import Ġuk . gov . just ice . digital . h mp ps . pec s . j pc . location . Location Ċ import Ġuk . gov . just ice . digital . h mp ps . pec s . j pc . location . Location Type Ċ import Ġuk . gov . just ice . digital . h mp ps . pec s . j pc . service . Locations Service Ċ Ċ @ SpringBootTest Ċ @ Auto Configure MockMvc Ċ @ Active Profiles (" test ") Ċ @ Context Configuration ( classes Ġ= Ġ[ Test Config :: class ]) Ċ class ĠManage Schedule 3 4 Locations Controller Test (@ Autowired Ġprivate Ġval Ġw ac : ĠWeb ApplicationContext ) Ġ{ ĊĊĠ Ġprivate Ġval Ġmock Mvc Ġ= ĠMock Mvc Builders . web AppContext Setup ( w ac ). build () ĊĊĠ Ġ@ Mock Bean ĊĠ Ġlateinit Ġvar Ġservice : ĠLoc ations Service ĊĊĠ Ġ@ Test ĊĠ Ġinternal Ġfun Ġ` get Ġand Ġdisplay Ġsearch Ġlocations Ġscreen `() Ġ{ ĊĠĠĠ Ġmock Mvc . get ("/ search - locations ") ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġmodel Ġ{ Ġattribute (" form ", ĠManage Schedule 3 4 Locations Controller . Search Location Form ()) Ġ} Ġ} ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġview Ġ{ Ġname (" search - locations ") Ġ} Ġ} ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġstatus Ġ{ Ġis Ok () Ġ} Ġ} ĊĊĠĠĠ Ġverify Zero Interactions ( service ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġinternal Ġfun Ġ` search Ġfor Ġexisting Ġlocation Ġredirects Ġto Ġmanage Ġlocation Ġscreen `() Ġ{ ĊĠĠĠ Ġwhenever ( service . find Location By Site Name (" LOCATION ĠNAME ")). thenReturn ( Location ( Location Type . PR , Ġ" AG ENCY _ ID ", Ġ" LOCATION ĠNAME ")) ĊĊĠĠĠ Ġmock Mvc . post ("/ search - locations ") Ġ{ ĊĠĠĠĠĠ Ġparam (" location ", Ġ" LOCATION ĠNAME ") ĊĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġstatus Ġ{ Ġis 3 xx Red irection () Ġ} Ġ} ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġredirected Url ("/ manage - location / AG ENCY _ ID ") Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġinternal Ġfun Ġ` perform Ġlocation Ġchange Ġsucceeds `() Ġ{ ĊĠĠĠ Ġmock Mvc . post ("/ manage - location ") Ġ{ ĊĠĠĠĠĠ Ġparam (" agency Id ", Ġ" AG ENCY _ ID ") ĊĠĠĠĠĠ Ġparam (" location Name ", Ġ" LOCATION ĠNAME ") ĊĠĠĠĠĠ Ġparam (" location Type ", Ġ" PR ") ĊĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġstatus Ġ{ Ġis 3 xx Red irection () Ġ} Ġ} ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġredirected Url (" search - locations ") Ġ} ĊĊĠĠĠ Ġverify ( service ). location AlreadyExists (" AG ENCY _ ID ", Ġ" LOCATION ĠNAME ") ĊĠĠĠ Ġverify ( service ). setLocation Details (" AG ENCY _ ID ", Ġ" LOCATION ĠNAME ", ĠLocation Type . PR ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġinternal Ġfun Ġ` perform Ġlocation Ġchange Ġfails Ġon Ġduplicate Ġname `() Ġ{ ĊĠĠĠ Ġwhenever ( service . location AlreadyExists (" AG ENCY _ ID ", Ġ" DUPLIC ATE ĠLOC ATION ĠNAME ")). thenReturn ( true ) ĊĊĠĠĠ Ġmock Mvc . post ("/ manage - location ") Ġ{ ĊĠĠĠĠĠ Ġparam (" agency Id ", Ġ" AG ENCY _ ID ") ĊĠĠĠĠĠ Ġparam (" location Name ", Ġ" DUPLIC ATE ĠLOC ATION ĠNAME ") ĊĠĠĠĠĠ Ġparam (" location Type ", Ġ" PR ") ĊĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġstatus Ġ{ Ġis 2 xx Successful () Ġ} Ġ} ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġview Ġ{ Ġname (" manage - location ") Ġ} Ġ} ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġmodel Ġ{ Ġattribute Has Field ErrorCode (" form ", Ġ" location Name ", Ġ" duplicate ") Ġ} Ġ} ĊĊĠĠĠ Ġverify ( service ). location AlreadyExists (" AG ENCY _ ID ", Ġ" DUPLIC ATE ĠLOC ATION ĠNAME ") ĊĠĠĠ Ġverify ( service , Ġnever ()). setLocation Details ( any (), Ġany (), Ġany ()) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġinternal Ġfun Ġ` search Ġfor Ġlocation Ġlocation Ġnot Ġfound Ġreturns Ġback Ġto Ġsearch Ġscreen `() Ġ{ ĊĠĠĠ Ġwhenever ( service . find Location By Site Name ( any ())). thenReturn ( null ) ĊĊĠĠĠ Ġmock Mvc . post ("/ search - locations ") Ġ{ ĊĠĠĠĠĠ Ġparam (" location ", Ġ" LOCATION ĠNAME ") ĊĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġstatus Ġ{ Ġis 2 xx Successful () Ġ} Ġ} ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġview Ġ{ Ġname (" search - locations ") Ġ} Ġ} ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġmodel Ġ{ Ġattribute Has Field ErrorCode (" form ", Ġ" location ", Ġ" not found ") Ġ} Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġinternal Ġfun Ġ` search Ġfor Ġempty Ġlocation Ġreturns Ġback Ġto Ġsearch Ġscreen `() Ġ{ ĊĠĠĠ Ġmock Mvc . post ("/ search - locations ") Ġ{ ĊĠĠĠĠĠ Ġparam (" location ", Ġ"") ĊĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġstatus Ġ{ Ġis 2 xx Successful () Ġ} Ġ} ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġview Ġ{ Ġname (" search - locations ") Ġ} Ġ} ĊĊĠĠĠ Ġverify Zero Interactions ( service ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġinternal Ġfun Ġ` search Ġfor Ġblank Ġlocation Ġreturns Ġback Ġto Ġsearch Ġscreen `() Ġ{ ĊĠĠĠ Ġmock Mvc . post ("/ search - locations ") Ġ{ ĊĠĠĠĠĠ Ġparam (" location ", Ġ" Ġ") ĊĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġstatus Ġ{ Ġis 2 xx Successful () Ġ} Ġ} ĊĠĠĠĠĠ Ġ. andExpect Ġ{ Ġview Ġ{ Ġname (" search - locations ") Ġ} Ġ} ĊĊĠĠĠ Ġverify Zero Interactions ( service ) ĊĠ Ġ} Ċ } Ċ