package Ġcom . r mar in 1 7 . nb ap layers . domain . inter actors Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġcom . r mar in 1 7 . nb ap layers . data . network . Player Services Ċ import Ġcom . r mar in 1 7 . nb ap layers . data . network . models . Data Response Model Ċ import Ġcom . r mar in 1 7 . nb ap layers . data . network . models . Player Response Model Ċ import Ġcom . r mar in 1 7 . nb ap layers . data . network . models . Team Response Model Ċ import Ġcom . r mar in 1 7 . nb ap layers . test . Rx Test Scheduler Rule Ċ import Ġcom . r mar in 1 7 . nb ap layers . ui . models . Player Ui Model . Companion . MOCK _ PLAYER _ IMAGE Ċ import Ġio . reactivex . rx java 3 . core . Observable Ċ import Ġjunit . framework . TestCase Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . junit . Mockito JUnit Runner Ċ Ċ /** Ċ Ġ* ĠUnit Ġtest Ġof ĠFetch Players Interactor Impl Test . Ċ Ġ*/ Ċ @ RunWith ( Mockito JUnit Runner :: class ) Ċ class ĠFetch Players Interactor Impl Test Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġplayers Service : ĠPlayer Services Ġ= Ġmock () ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġfetch Players Interactor : ĠFetch Players Interactor ĊĊĠĠĠ Ġprivate Ġval ĠP LAYER _ 1 Ġ= Ġmock Player Response Model ( 1 ) ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġtest Scheduler Ġ= ĠRx Test Scheduler Rule () ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġrule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġfetch Players Interactor Ġ= ĠFetch Players Interactor Impl ( players Service ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when ĠgetAll Players Ġis Ġcalled Ġand Ġresult Ġis Ġsuccess , Ġthe Ġcheck Ġresponse `() Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( players Service . get Players ()). thenReturn ( Observable . just ( mock Data Response Model ())) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġfetch Players Interactor . getAll Players (). blocking Get (). first () ĊĠĠĠĠĠĠĠ ĠTestCase . assertTrue ( result . id Ġ== ĠP LAYER _ 1 . id ) ĊĠĠĠĠĠĠĠ ĠTestCase . assertTrue ( result . name Ġ== Ġ"${ PLAYER _ 1 . firstName } Ġ${ PLAYER _ 1 . lastName }") ĊĠĠĠĠĠĠĠ ĠTestCase . assertTrue ( result . image Ġ== ĠMOCK _ PLAYER _ IMAGE ) ĊĠĠĠĠĠĠĠ ĠTestCase . assertTrue ( result . team Ġ== ĠP LAYER _ 1 . team . transform To Team Ui Model ()) ĊĠĠĠĠĠĠĠ ĠTestCase . assertTrue ( result . position Ġ== ĠP LAYER _ 1 . position ) ĊĠĠĠĠĠĠĠ ĠTestCase . assertTrue ( result . weight Ġ== ĠP LAYER _ 1 . weight P ound s ) ĊĠĠĠĠĠĠĠ ĠTestCase . assertTrue ( result . height Ġ== ĠP LAYER _ 1 . height In ches ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠThrowable :: class ) ĊĠĠĠ Ġfun Ġ` when ĠgetAll Players Ġis Ġcalled Ġand Ġresult Ġis Ġerror , Ġthe Ġcheck Ġresponse `() Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( players Service . get Players ()). thenReturn ( Observable . error ( Throwable (" test "))) ĊĠĠĠĠĠĠĠ Ġfetch Players Interactor . getAll Players (). blocking Get () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġget Players By Query Ġis Ġcalled Ġand Ġresult Ġis Ġsuccess , Ġthe Ġcheck Ġresponse `() Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( players Service . get Players By Query ( any ())). thenReturn ( Observable . just ( mock Data Response Model ())) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġfetch Players Interactor . get Players By Query (" test "). blocking Get (). first () ĊĠĠĠĠĠĠĠ ĠTestCase . assertTrue ( result . id Ġ== ĠP LAYER _ 1 . id ) ĊĠĠĠĠĠĠĠ ĠTestCase . assertTrue ( result . name Ġ== Ġ"${ PLAYER _ 1 . firstName } Ġ${ PLAYER _ 1 . lastName }") ĊĠĠĠĠĠĠĠ ĠTestCase . assertTrue ( result . image Ġ== ĠMOCK _ PLAYER _ IMAGE ) ĊĠĠĠĠĠĠĠ ĠTestCase . assertTrue ( result . team Ġ== ĠP LAYER _ 1 . team . transform To Team Ui Model ()) ĊĠĠĠĠĠĠĠ ĠTestCase . assertTrue ( result . position Ġ== ĠP LAYER _ 1 . position ) ĊĠĠĠĠĠĠĠ ĠTestCase . assertTrue ( result . weight Ġ== ĠP LAYER _ 1 . weight P ound s ) ĊĠĠĠĠĠĠĠ ĠTestCase . assertTrue ( result . height Ġ== ĠP LAYER _ 1 . height In ches ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠThrowable :: class ) ĊĠĠĠ Ġfun Ġ` when Ġget Players By Query Ġis Ġcalled Ġand Ġresult Ġis Ġerror , Ġthe Ġcheck Ġresponse `() Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( players Service . get Players By Query ( any ())). thenReturn ( Observable . error ( Throwable (" test "))) ĊĠĠĠĠĠĠĠ Ġfetch Players Interactor . get Players By Query (" test "). blocking Get () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġmock Data Response Model (): ĠData Response Model Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠData Response Model ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( PLAYER _ 1 ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġmock Player Response Model ( id : ĠInt ): ĠPlayer Response Model Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠPlayer Response Model ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġid Ġ= Ġid , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfirstName Ġ= Ġ" name ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlastName Ġ= Ġ" last Ġname ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġheight Fe et Ġ= Ġ 1 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġheight In ches Ġ= Ġ 2 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġposition Ġ= Ġ" C - F ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġteam Ġ= ĠTeam Response Model ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġid Ġ= Ġ 1 , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġabbre viation Ġ= Ġ" L AL ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcity Ġ= Ġ" Los ĠAnge les ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġconference Ġ= Ġ" east ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdivision Ġ= Ġ" test ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠfullName Ġ= Ġ" full Ġname ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġname Ġ= Ġ" name " ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġweight P ound s Ġ= Ġ 1 ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} Ċ } Ċ