package Ġru . ot us . spring . k ush ch enko . hw 1 3 . controller Ċ Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify No More Interactions Ċ import Ġcom . n ha ar man . mockito _ kotlin . wh enever Ċ import Ġorg . hamcrest . Core Matchers . has Item Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . autoconfigure . web . servlet . Web Mvc Test Ċ import Ġorg . springframework . boot . test . mock . mockito . Mock Bean Ċ import Ġorg . springframework . security . test . context . support . With Mock User Ċ import Ġorg . springframework . test . context . junit . jupiter . Spring Extension Ċ 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 . model Ċ import Ġorg . springframework . test . web . servlet . result . MockMvc Result Matchers . status Ċ import Ġorg . springframework . test . web . servlet . result . MockMvc Result Matchers . view Ċ import Ġru . ot us . spring . k ush ch enko . hw 1 3 . service . Author Service Ċ Ċ /** Ċ Ġ* ĠCreated Ġby ĠÐķ Ð»ÐµÐ½ Ð° Ġon ĠÐĿ Ð¾Ñı Ð± ., Ġ 2 0 1 8 Ċ Ġ*/ Ċ @ Extend With ( Spring Extension :: class ) Ċ @ Web Mvc Test ( Author Controller :: class ) Ċ class ĠAuthor Controller Test Ġ{ ĊĠĠĠ Ġprivate Ġval ĠBASE _ URL Ġ= Ġ"/ authors " ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmock Mvc : ĠMock Mvc ĊĠĠĠ Ġ@ Mock Bean ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġservice : ĠAuthor Service ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ With Mock User ĊĠĠĠ Ġfun ĠgetAll () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġauthor 1 Ġ= Ġ" Author 1 " ĊĠĠĠĠĠĠĠ Ġval Ġauthor 2 Ġ= Ġ" Author 2 " ĊĠĠĠĠĠĠĠ Ġval Ġauthors Ġ= ĠlistOf ( author 1 , Ġauthor 2 ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( service . getAll ()). thenReturn ( authors ) ĊĊĠĠĠĠĠĠĠ Ġmock Mvc . perform ( get ( BASE _ URL )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( view (). name (" authors ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( model (). attribute (" authors ", Ġhas Item ( author 1 ))) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( model (). attribute (" authors ", Ġhas Item ( author 2 ))) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. andReturn (). response ĊĊĠĠĠĠĠĠĠ Ġverify ( service ). getAll () ĊĠĠĠĠĠĠĠ Ġverify No More Interactions ( service ) ĊĠĠĠ Ġ} Ċ }