package Ġio . h oly gu ac am ole . web . controller Ċ Ċ import Ġassert k . assert Ċ import Ġassert k . assertions . isEqualTo Ċ import Ġcom . n ha ar man . mockito _ kotlin . mock Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify Ċ import Ġcom . n ha ar man . mockito _ kotlin . wh enever Ċ import Ġio . h oly gu ac am ole . bot . message . Av oc ado Receipt Repository Ċ import Ġio . h oly gu ac am ole . bot . user . UserRepository Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . springframework . test . web . servlet . MockMvc Ċ import Ġorg . springframework . test . web . servlet . request . MockMvc Request Builders . get Ċ import Ġorg . springframework . test . web . servlet . result . MockMvc Result Matchers . content Ċ import Ġorg . springframework . test . web . servlet . setup . MockMvc Builders Ċ import Ġorg . springframework . ui . Model Ċ import Ġorg . thy me leaf . spring 5 . Spring Template Engine Ċ import Ġorg . thy me leaf . spring 5 . view . Th y me leaf View Resolver Ċ Ċ class ĠView Controller Test Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġservice : ĠLeader board Service Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġcontroller Ġ= ĠView Controller ( service ) ĊĠĠĠ Ġprivate Ġval Ġmock Mvc : ĠMock Mvc Ġ= ĊĠĠĠĠĠĠĠ ĠMock Mvc Builders . standalone Setup ( controller ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. setView Resolvers ( Th y me leaf View Resolver (). apply Ġ{ Ġtemplate Engine Ġ= ĠSpring Template Engine () Ġ}) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠ Ġprivate Ġval Ġmock Model : ĠModel Ġ= Ġmock () ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( service . get Leader board ()). thenReturn ( Mock Leader board . all ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` direct s Ġindex Ġrequest Ġto Ġwelcome Ġtemplate `() Ġ{ ĊĠĠĠĠĠĠĠ Ġmock Mvc . perform ( get ("/ ")). andExpect ( content (). string (" welcome ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` direct s Ġleader board Ġrequest Ġto Ġleader board Ġtemplate `() Ġ{ ĊĠĠĠĠĠĠĠ Ġmock Mvc . perform ( get ("/ leader board ")). andExpect ( content (). string (" leader board ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` passes Ġcount Ġand Ġleader board Ġto Ġmodel `() Ġ{ ĊĠĠĠĠĠĠĠ Ġcontroller . get Leader board ( mock Model ) ĊĠĠĠĠĠĠĠ Ġverify ( mock Model ). addAttribute (" total Count ", ĠMock Leader board . all . total Count ) ĊĠĠĠĠĠĠĠ Ġverify ( mock Model ). addAttribute (" leader board ", ĠMock Leader board . all . le aders ) ĊĠĠĠ Ġ} Ċ } Ċ Ċ class ĠLeader board Service Test Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġuser Repository : ĠUser Repository Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġav oc ado Receipt Repository : ĠAv oc ado Receipt Repository Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġservice Ġ= ĠLeader board Service ( user Repository , Ġav oc ado Receipt Repository ) ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( user Repository . findAll ()). thenReturn ( Mock Users . all ) ĊĠĠĠĠĠĠĠ Ġwhenever ( av oc ado Receipt Repository . get Leader board ( Mock Av oc ado Counts . all . size . to Long ())). thenReturn ( Mock Av oc ado Counts . all ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` returns Ġleader board `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġleader board Ġ= Ġservice . get Leader board () ĊĠĠĠĠĠĠĠ Ġassert ( leader board ). isEqualTo ( Mock Leader board . all ) ĊĠĠĠ Ġ} Ċ }