package Ġcom . cock t ails guru . app . user . service Ċ Ċ import Ġcom . cock t ails guru . app . user . domain . Fb User Ċ import Ġcom . cock t ails guru . app . user . domain . Google User Ċ import Ġcom . cock t ails guru . app . user . repository . Fb UserRepository Ċ import Ġcom . cock t ails guru . app . user . repository . Google UserRepository Ċ import Ġcom . cock t ails guru . app . user . repository . User Token Repository Ċ import Ġcom . n ha ar man . mockito _ kotlin .* Ċ import Ġjunit . framework . TestCase .* Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . junit . Mockito JUnit Runner Ċ import Ġjava . util .* Ċ Ċ @ RunWith ( Mockito JUnit Runner :: class ) Ċ class ĠUser ServiceImpl Test Ġ{ ĊĠĠĠ Ġprivate Ġval Ġany Fb UserRepository Ġ= Ġmock < Fb UserRepository >() ĊĠĠĠ Ġprivate Ġval Ġany Google UserRepository Ġ= Ġmock < Google UserRepository >() ĊĠĠĠ Ġprivate Ġval Ġuser To ke Repository Ġ= Ġmock < User Token Repository >() ĊĊĠĠĠ Ġprivate Ġval ĠuserService : ĠUserService Ġ= ĠUser ServiceImpl ( any Fb UserRepository , Ġany Google UserRepository , Ġuser To ke Repository ) ĊĊĠĠĠ Ġprivate Ġval Ġany Id Ġ= Ġ 1 2 3 L ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġgiven No User When Request ing User ById Should Return Null () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( any Fb UserRepository . findById ( any ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠĠĠ Ġwhenever ( any Google UserRepository . findById ( any ())). thenReturn ( Optional . empty ()) ĊĊĠĠĠĠĠĠĠ ĠassertNull ( userService . find User ById ( any Id )) ĊĊĠĠĠĠĠĠĠ Ġverify ( any Fb UserRepository ). findById ( any Id ) ĊĠĠĠĠĠĠĠ Ġverify ( any Google UserRepository ). findById ( any Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġgiven Existing Fb User Only When Request ing User ById Should Return Fb User () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġany Fb User Ġ= Ġmock < Fb User >() ĊĊĠĠĠĠĠĠĠ Ġwhenever ( any Fb UserRepository . findById ( any Id )). thenReturn ( Optional . of ( any Fb User )) ĊĊĠĠĠĠĠĠĠ Ġval Ġfound User Ġ= ĠuserService . find User ById ( any Id ) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( found User ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( found User Ġis ĠF b User ) ĊĊĠĠĠĠĠĠĠ Ġverify ( any Fb UserRepository ). findById ( any Id ) ĊĠĠĠĠĠĠĠ Ġverify Zero Interactions ( any Google UserRepository ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġgiven Existing Google User Only When Request ing User ById Should Return Google User () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġany Google User Ġ= Ġmock < Google User >() ĊĊĠĠĠĠĠĠĠ Ġwhenever ( any Fb UserRepository . findById ( any ())). thenReturn ( Optional . empty ()) ĊĠĠĠĠĠĠĠ Ġwhenever ( any Google UserRepository . findById ( any Id )). thenReturn ( Optional . of ( any Google User )) ĊĊĠĠĠĠĠĠĠ Ġval Ġfound User Ġ= ĠuserService . find User ById ( any Id ) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( found User ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( found User Ġis ĠGoogle User ) ĊĊĠĠĠĠĠĠĠ Ġverify ( any Fb UserRepository ). findById ( any Id ) ĊĠĠĠĠĠĠĠ Ġverify ( any Google UserRepository ). findById ( any Id ) ĊĠĠĠ Ġ} Ċ } Ċ