package Ġole hak amin sk yi . li vest ream fails . player Ċ Ċ import Ġandroid . content . Context Ċ Ċ import Ġcom . google . android . ex op layer 2 . Exo Playback Exception Ċ import Ġcom . google . android . ex op layer 2 . Exo Player Ċ import Ġcom . google . android . ex op layer 2 . Player . EventListener Ċ import Ġcom . google . android . ex op layer 2 . Player . STATE _ ENDED Ċ import Ġcom . google . android . ex op layer 2 . Player . STATE _ BUFFER ING Ċ import Ġcom . google . android . ex op layer 2 . Player . STATE _ IDLE Ċ import Ġcom . google . android . ex op layer 2 . Player . STATE _ READY Ċ import Ġcom . google . android . ex op layer 2 . Player . REPEAT _ MODE _ OFF Ċ import Ġcom . google . android . ex op layer 2 . Player . REPEAT _ MODE _ ONE Ċ import Ġcom . google . android . ex op layer 2 . source . Media Source Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito . mock Ċ import Ġorg . mockito . Mockito .` when ` Ċ import Ġorg . mockito . Mockito . verify Ċ import Ġorg . mockito . Mockito . at Least Once Ċ import Ġorg . mockito . Mockito . never Ċ import Ġorg . mockito . Mockito . times Ċ import Ġorg . mockito . junit . Mockito JUnit Runner Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . eq Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . test . run Blocking Test Ċ import Ġole hak amin sk yi . li vest ream fails . player . Video Player Controller . State . Idle Ċ import Ġole hak amin sk yi . li vest ream fails . player . Video Player Controller . State . Buffer ing Ċ import Ġole hak amin sk yi . li vest ream fails . player . Video Player Controller . State . Ready Ċ import Ġole hak amin sk yi . li vest ream fails . tests . Cor outines Test Rule Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Rule Ċ import Ġjava . io . IOException Ċ Ċ @ Experimental Cor outines Api Ċ @ RunWith ( Mockito JUnit Runner :: class ) Ċ class ĠEx o Video Player Controller Test Ġ{ ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġtest Car oline Rule Ġ= ĠCor outines Test Rule () ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġlateinit Ġvar Ġplayer : ĠEx o Player ĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġlateinit Ġvar Ġsource Converter : ĠUrl Source Converter ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġplayer Controller : ĠEx o Video Player Controller ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġplayer Controller Ġ= ĠEx o Video Player Controller ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock ( Context :: class . java ), Ġplayer , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ_ source Converter Ġ= Ġsource Converter ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ` when `( source Converter . convert ( any (), Ġany ())). thenReturn ( mock ( Media Source :: class . java )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġset Repeat Mode () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġplayer Controller . repeat Mode Ġ= ĠVideo Player Controller . Repeat Mode . NONE ĊĠĠĠĠĠĠĠ Ġverify ( player , Ġtimes ( 1 )). repeat Mode Ġ= ĠRE PEAT _ MODE _ OFF ĊĠĠĠĠĠĠĠ Ġplayer Controller . repeat Mode Ġ= ĠVideo Player Controller . Repeat Mode . ONE ĊĠĠĠĠĠĠĠ Ġverify ( player , Ġtimes ( 1 )). repeat Mode Ġ= ĠRE PEAT _ MODE _ ONE ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġplay () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsource Ġ= ĠUrl Source (" some Ġurl Ġsource ") ĊĠĠĠĠĠĠĠ Ġplayer Controller . play ( source ) ĊĠĠĠĠĠĠĠ Ġverify ( player , Ġat Least Once ()). prepare ( any ()) ĊĠĠĠĠĠĠĠ Ġverify ( player , Ġat Least Once ()). play When Ready Ġ= Ġtrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġstop () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġplayer Controller . stop () ĊĠĠĠĠĠĠĠ Ġverify ( player , Ġtimes ( 1 )). stop ( true ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġresume () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġplayer Controller . resume () ĊĠĠĠĠĠĠĠ Ġverify ( player , Ġtimes ( 1 )). play When Ready Ġ= Ġtrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġpause () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġplayer Controller . pause () ĊĠĠĠĠĠĠĠ Ġverify ( player , Ġtimes ( 1 )). play When Ready Ġ= Ġfalse ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġadd Listener () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsource Ġ= ĠUrl Source (" some Ġurl Ġsource ") ĊĠĠĠĠĠĠĠ Ġval Ġvalue Holder Ġ= Ġobject Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlateinit Ġvar Ġevent Listener : ĠEvent Listener ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġlistener Ġ= Ġmock ( Video Player Controller . Listener :: class . java ) ĊĠĠĠĠĠĠĠ Ġ` when `( player . addListener ( any ())). then Answer Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvalue Holder . event Listener Ġ= Ġit . arguments [ 0 ] Ġas ĠEvent Listener ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnull ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġ// Ġstates Ġpopulation ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( player Controller . state , ĠId le ) ĊĠĠĠĠĠĠĠ Ġplayer Controller . play ( source ) ĊĠĠĠĠĠĠĠ Ġplayer Controller . addListener ( listener ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġerror ĊĠĠĠĠĠĠĠ Ġvalue Holder . event Listener . on Player Error ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠEx o Playback Exception . create For Source ( IOException ()) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġverify ( listener , Ġtimes ( 1 )). on StateChanged ( any (), Ġany ()) ĊĊĠĠĠĠĠĠĠ Ġ// ĠId le ĊĠĠĠĠĠĠĠ Ġvalue Holder . event Listener . on Player StateChanged ( true , ĠSTATE _ IDLE ) ĊĠĠĠĠĠĠĠ Ġverify ( listener , Ġtimes ( 1 )). on StateChanged ( source , ĠId le ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠBuffer ing ĊĠĠĠĠĠĠĠ Ġvalue Holder . event Listener . on Player StateChanged ( true , ĠSTATE _ BUFFER ING ) ĊĠĠĠĠĠĠĠ Ġverify ( listener , Ġtimes ( 1 )). on StateChanged ( source , ĠBuffer ing ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠReady ĊĠĠĠĠĠĠĠ Ġvalue Holder . event Listener . on Player StateChanged ( true , ĠSTATE _ READY ) ĊĠĠĠĠĠĠĠ Ġverify ( listener , Ġtimes ( 1 )). on StateChanged ( source , ĠReady ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠEn ded ĊĠĠĠĠĠĠĠ Ġvalue Holder . event Listener . on Player StateChanged ( true , ĠSTATE _ ENDED ) ĊĠĠĠĠĠĠĠ Ġverify ( listener , Ġtimes ( 1 )). on StateChanged ( source , ĠReady ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġremove Listener () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsource Ġ= ĠUrl Source (" some Ġurl Ġsource ") ĊĠĠĠĠĠĠĠ Ġval Ġvalue Holder Ġ= Ġobject Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlateinit Ġvar Ġevent Listener : ĠEvent Listener ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġlistener Ġ= Ġmock ( Video Player Controller . Listener :: class . java ) ĊĠĠĠĠĠĠĠ Ġ` when `( player . addListener ( any ())). then Answer Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvalue Holder . event Listener Ġ= Ġit . arguments [ 0 ] Ġas ĠEvent Listener ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnull ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġplayer Controller . play ( source ) ĊĠĠĠĠĠĠĠ Ġplayer Controller . addListener ( listener ) ĊĠĠĠĠĠĠĠ Ġplayer Controller . remove Listener ( listener ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġerror ĊĠĠĠĠĠĠĠ Ġvalue Holder . event Listener . on Player Error ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠEx o Playback Exception . create For Source ( IOException ()) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġloading Ġtrue ĊĠĠĠĠĠĠĠ Ġvalue Holder . event Listener . on Loading Changed ( true ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġloading Ġfalse ĊĠĠĠĠĠĠĠ Ġvalue Holder . event Listener . on Loading Changed ( false ) ĊĊĠĠĠĠĠĠĠ ĠarrayOf ( STATE _ IDLE , ĠSTATE _ BUFFER ING , ĠSTATE _ READY , ĠSTATE _ ENDED ). forEach Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvalue Holder . event Listener . on Player StateChanged ( true , Ġit ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġverify ( listener , Ġnever ()). on StateChanged ( eq ( source ), Ġany ()) ĊĠĠĠ Ġ} Ċ }