package Ġcom . sk t . n ugu . sdk . platform . android . ux . template . controller Ċ Ċ import Ġcom . sk t . n ugu . sdk . agent . Default Audio Player Agent Ċ import Ġcom . sk t . n ugu . sdk . agent . aud iop layer . Audio Player Agent Interface Ċ import Ġcom . sk t . n ugu . sdk . agent . playback . Playback Button Ċ import Ġcom . sk t . n ugu . sdk . agent . playback . Playback Router Ċ import Ġcom . sk t . n ugu . sdk . core . interfaces . common . Namespace And Name Ċ import Ġcom . sk t . n ugu . sdk . core . interfaces . message . Directive Ċ import Ġcom . sk t . n ugu . sdk . platform . android . N ugu Android Client Ċ import Ġcom . sk t . n ugu . sdk . platform . android . ux . template . presenter . Template Renderer Ċ import Ġcom . sk t . n ugu . sdk . platform . android . ux . template . view . media . Player Command Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito .` when ` Ċ import Ġorg . mockito . Mockito Annotations Ċ import Ġorg . mockito . kotlin .* Ċ Ċ class ĠTemplate Media Handler Test Ġ{ ĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġclient Listener : ĠTemplate Handler . Client Listener ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġn ugu Android Client : ĠN ugu Android Client ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġaudio Player Agent : ĠDefault Audio Player Agent ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġplayback Router : ĠPlay back Router ĊĊĠĠĠ Ġprivate Ġval Ġn ugu Android Provider Ġ= Ġobject Ġ: ĠTemplate Renderer . N ugu Client Provider Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget N ugu Client (): ĠN ugu Android Client Ġ= Ġn ugu Android Client ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġvar Ġmedia Context Sample Ġ= ĠAudio Player Agent Interface . Context ("", Ġ" template Id ", Ġ"", Ġ 1 0 L , Ġ"") ĊĊĠĠĠ Ġprivate Ġvar Ġmedia Context Diff Sample Ġ= ĠAudio Player Agent Interface . Context ("", Ġ" template Id Diff ", Ġ"", Ġ 1 0 L , Ġ"") ĊĊĠĠĠ Ġprivate Ġval Ġtemplate Info Ġ= ĠTemplate Handler . Template Info (" template Id ", Ġ" template Type ") ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmedia Template Handler : ĠTemplate Media Handler ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito Annotations . open Mocks ( this ) ĊĠĠĠĠĠĠĠ Ġmedia Template Handler Ġ= ĠTemplate Media Handler ( n ugu Android Provider , Ġtemplate Info ) ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . set Client Listener ( client Listener ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Media Progress Sending () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// period ically Ġsending ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . start Media Progress Sending () ĊĠĠĠĠĠĠĠ Ġverify ( client Listener , Ġtimeout ( 2 5 0 0 ). times ( 2 )). on Media Progress Changed ( any (), Ġany ()) ĊĊĠĠĠĠĠĠĠ Ġ// after Ġstop . Ġthere Ġwill Ġbe Ġno Ġprogress Ġsending ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . clear () ĊĠĠĠĠĠĠĠ Ġverify No More Interactions ( client Listener ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Media Retrieve () Ġ{ ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . media Duration Listener . on Retrie ved ( 1 0 0 0 L , Ġmedia Context Sample ) ĊĠĠĠĠĠĠĠ Ġverify ( client Listener ). on Media Duration Retrie ved ( 1 0 0 0 L ) ĊĊĠĠĠĠĠĠĠ Ġmedia Template Handler . media Duration Listener . on Retrie ved ( null , Ġmedia Context Sample ) ĊĠĠĠĠĠĠĠ Ġverify ( client Listener ). on Media Duration Retrie ved ( 0 L ) ĊĊĠĠĠĠĠĠĠ Ġmedia Template Handler . media Duration Listener . on Retrie ved ( null , Ġmedia Context Diff Sample ) ĊĠĠĠĠĠĠĠ Ġverify No More Interactions ( client Listener ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġcheck Ġnull Ġcondition ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . set Client Listener ( null ) ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . media Duration Listener . on Retrie ved ( 1 0 0 0 L , Ġmedia Context Sample ) ĊĠĠĠĠĠĠĠ Ġverify No More Interactions ( client Listener ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Media State Listener () Ġ{ ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . media State Listener . on StateChanged ( Audio Player Agent Interface . State . PLAY ING , Ġmedia Context Sample ) ĊĠĠĠĠĠĠĠ Ġverify ( client Listener ). on Media StateChanged ( eq ( Audio Player Agent Interface . State . PLAY ING ), Ġany (), Ġany (), Ġeq ( false )) ĊĊĠĠĠĠĠĠĠ Ġmedia Template Handler . media State Listener . on StateChanged ( Audio Player Agent Interface . State . STOP PED , Ġmedia Context Sample ) ĊĠĠĠĠĠĠĠ Ġverify ( client Listener ). on Media StateChanged ( eq ( Audio Player Agent Interface . State . STOP PED ), Ġany (), Ġany (), Ġeq ( false )) ĊĊĠĠĠĠĠĠĠ Ġ// Ġcheck Ġnull Ġcondition ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . set Client Listener ( null ) ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . media State Listener . on StateChanged ( Audio Player Agent Interface . State . STOP PED , Ġmedia Context Sample ) ĊĠĠĠĠĠĠĠ Ġverify No More Interactions ( client Listener ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Player Command With Empty Param () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġwhenever ( n ugu Android Client . get Playback Router ()). thenReturn ( playback Router ) ĊĠĠĠĠĠĠĠ Ġwhenever ( n ugu Android Client . audio Player Agent ). thenReturn ( audio Player Agent ) ĊĊĠĠĠĠĠĠĠ Ġmedia Template Handler . on Player Command ( Player Command . PLAY , Ġ"") ĊĠĠĠĠĠĠĠ Ġverify ( playback Router ). button Pressed ( Playback Button . PLAY ) ĊĊĠĠĠĠĠĠĠ Ġmedia Template Handler . on Player Command ( Player Command . STOP , Ġ"") ĊĠĠĠĠĠĠĠ Ġverify ( playback Router ). button Pressed ( Playback Button . STOP ) ĊĊĠĠĠĠĠĠĠ Ġmedia Template Handler . on Player Command ( Player Command . PAUSE , Ġ"") ĊĠĠĠĠĠĠĠ Ġverify ( playback Router ). button Pressed ( Playback Button . PAUSE ) ĊĊĠĠĠĠĠĠĠ Ġmedia Template Handler . on Player Command ( Player Command . PREV , Ġ"") ĊĠĠĠĠĠĠĠ Ġverify ( playback Router ). button Pressed ( Playback Button . PREVIOUS ) ĊĊĠĠĠĠĠĠĠ Ġmedia Template Handler . on Player Command ( Player Command . NEXT , Ġ"") ĊĠĠĠĠĠĠĠ Ġverify ( playback Router ). button Pressed ( Playback Button . NEXT ) ĊĊĠĠĠĠĠĠĠ Ġmedia Template Handler . on Player Command ( Player Command . SH UFF LE , Ġ" true ") ĊĠĠĠĠĠĠĠ Ġverify ( audio Player Agent ). request Shuffle Command ( true ) ĊĊĠĠĠĠĠĠĠ Ġmedia Template Handler . on Player Command ( Player Command . SH UFF LE , Ġ"") ĊĠĠĠĠĠĠĠ Ġverify ( audio Player Agent ). request Shuffle Command ( false ) ĊĊĠĠĠĠĠĠĠ ĠAudio Player Agent Interface . Repeat Mode . values (). forEach Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmedia Template Handler . on Player Command ( Player Command . REPEAT , Ġit . name ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( audio Player Agent ). request Repeat Command ( it ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġmedia Template Handler . on Player Command ( Player Command . REPEAT , Ġ"") ĊĊĠĠĠĠĠĠĠ Ġmedia Template Handler . on Player Command ( Player Command . FA V OR ITE , Ġ" true ") ĊĠĠĠĠĠĠĠ Ġverify ( audio Player Agent ). request Favorite Command ( true ) ĊĊĠĠĠĠĠĠĠ Ġmedia Template Handler . on Player Command ( Player Command . FA V OR ITE , Ġ"") ĊĠĠĠĠĠĠĠ Ġverify ( audio Player Agent ). request Favorite Command ( false ) ĊĊĠĠĠĠĠĠĠ Ġmedia Template Handler . on Player Command ( Player Command . UNKNOWN , Ġ"") ĊĊĠĠĠĠĠĠĠ Ġ` when `( n ugu Android Client . audio Player Agent ). thenReturn ( null ) ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . on Player Command ( Player Command . REPEAT , Ġ" ALL ") ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . on Player Command ( Player Command . SH UFF LE , Ġ"") ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . on Player Command ( Player Command . FA V OR ITE , Ġ" true ") ĊĊĠĠĠĠĠĠĠ Ġverify No More Interactions ( audio Player Agent ) ĊĠĠĠĠĠĠĠ Ġverify No More Interactions ( playback Router ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Pause Directive () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdirective : ĠDirective Ġ= Ġmock () ĊĠĠĠĠĠĠĠ Ġ` when `( directive . getName space And Name ()). thenReturn ( Namespace And Name ( Default Audio Player Agent . NAMESPACE , ĠDefault Audio Player Agent . NAME _ PAUSE )) ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . directive Handling Listener . on Completed ( directive ) ĊĠĠĠĠĠĠĠ Ġverify ( client Listener ). on Media StateChanged ( eq ( Audio Player Agent Interface . State . PA USED ), Ġany (), Ġany (), Ġeq ( true )) ĊĊĠĠĠĠĠĠĠ Ġ// Ġcheck Ġnot ĠPA USE Ġdirective ĊĠĠĠĠĠĠĠ Ġ` when `( directive . getName space And Name ()). thenReturn ( Namespace And Name (" I 'm Ġnot ", Ġ" PAUSE ")) ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . directive Handling Listener . on Completed ( directive ) ĊĠĠĠĠĠĠĠ Ġverify No More Interactions ( client Listener ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġcheck Ġnull Ġcondition ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . set Client Listener ( null ) ĊĠĠĠĠĠĠĠ Ġ` when `( directive . getName space And Name ()). thenReturn ( Namespace And Name ( Default Audio Player Agent . NAMESPACE , ĠDefault Audio Player Agent . NAME _ PAUSE )) ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . directive Handling Listener . on Completed ( directive ) ĊĠĠĠĠĠĠĠ Ġverify No More Interactions ( client Listener ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġmeaning less ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . directive Handling Listener . on Requested ( directive ) ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . directive Handling Listener . on Canceled ( directive ) ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . directive Handling Listener . on Failed ( directive , Ġ"") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġobserve Media State () Ġ{ ĊĠĠĠĠĠĠĠ Ġ` when `( n ugu Android Client . audio Player Agent ). thenReturn ( audio Player Agent ) ĊĊĠĠĠĠĠĠĠ Ġmedia Template Handler . set Client Listener ( client Listener ) ĊĊĠĠĠĠĠĠĠ Ġverify ( audio Player Agent ). remove Listener ( media Template Handler . media State Listener ) ĊĠĠĠĠĠĠĠ Ġverify ( audio Player Agent ). addListener ( media Template Handler . media State Listener ) ĊĠĠĠĠĠĠĠ Ġverify ( audio Player Agent ). remove On Duration Listener ( media Template Handler . media Duration Listener ) ĊĠĠĠĠĠĠĠ Ġverify ( audio Player Agent ). add On Duration Listener ( media Template Handler . media Duration Listener ) ĊĠĠĠĠĠĠĠ Ġverify ( n ugu Android Client , Ġat Least Once ()). add On Directive Handling Listener ( media Template Handler . directive Handling Listener ) ĊĊĊĠĠĠĠĠĠĠ Ġ// Ġcheck Ġnull Ġcondition ĊĠĠĠĠĠĠĠ Ġ` when `( n ugu Android Client . audio Player Agent ). thenReturn ( null ) ĊĠĠĠĠĠĠĠ Ġverify No More Interactions ( audio Player Agent ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Clear () Ġ{ ĊĠĠĠĠĠĠĠ Ġ` when `( n ugu Android Client . audio Player Agent ). thenReturn ( audio Player Agent ) ĊĊĠĠĠĠĠĠĠ Ġmedia Template Handler . clear () ĊĊĠĠĠĠĠĠĠ Ġverify ( audio Player Agent ). remove Listener ( media Template Handler . media State Listener ) ĊĠĠĠĠĠĠĠ Ġverify ( audio Player Agent ). remove On Duration Listener ( media Template Handler . media Duration Listener ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġcheck Ġnull Ġcondition ĊĠĠĠĠĠĠĠ Ġ` when `( n ugu Android Client . audio Player Agent ). thenReturn ( null ) ĊĠĠĠĠĠĠĠ Ġmedia Template Handler . clear () ĊĠĠĠĠĠĠĠ Ġverify No More Interactions ( audio Player Agent ) ĊĠĠĠĠĠĠĠ Ġverify ( n ugu Android Client , Ġtimes ( 2 )). remove On Directive Handling Listener ( media Template Handler . directive Handling Listener ) ĊĠĠĠ Ġ} Ċ }