package Ġcom . ke vin . mockito . sample . test Ċ Ċ import Ġcom . ke vin . mockito . sample . domain . dto . User DTO Ċ import Ġcom . ke vin . mockito . sample . service . UserService Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Inject Mocks Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito Annotations Ċ import Ġorg . mockito . junit . Mockito JUnit Runner Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ import Ġorg . springframework . test . context . junit 4 . Spring Runner Ċ Ċ @ RunWith ( Mockito JUnit Runner :: class ) Ċ @ SpringBootTest Ċ class ĠUserService Tests Ġ{ ĊĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġval Ġusers ervice : ĠUserService ? Ġ= Ġnull ĊĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġinit () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito Annotations . init Mocks ( this ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠgetUser Test () Ġ{ Ċ Ċ // ĠĠĠĠĠĠĠ Ġorg . mockito . Mockito . when ( users ervice ?. getUser (" 0 0 1 ")). thenReturn ( User DTO ( 1 2 3 ," zhang san ")) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( users ervice ?. getUser (" 0 0 1 ")). thenReturn ( User DTO ( 1 2 3 , Ġ" zhang san ")) ĊĊĠĠĠĠĠĠĠ Ġval Ġuser Ġ= Ġusers ervice ?. getUser (" 0 0 1 ") ĊĠĠĠĠĠĠĠ Ġverify ( user ) ĊĊĠĠĠ Ġ} ĊĊ Ċ }