package Ġme . h uf man . android aut oid rive . music Ċ Ċ import Ġandroid . app . Notification Ċ import Ġandroid . app . Notification Channel Ċ import Ġandroid . app . Notification Manager Ċ import Ġandroid . app . Pending Intent Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . Intent Ċ import Ġandroid . os . Handler Ċ import Ġandroidx . core . app . Notification Compat Ċ import Ġcom . adam rat z man . spotify .* Ċ import Ġcom . adam rat z man . spotify . endpoints . client . Client Library Api Ċ import Ġcom . adam rat z man . spotify . endpoints . client . Client Playlist Api Ċ import Ġcom . adam rat z man . spotify . endpoints . pub . Artist Api Ċ import Ġcom . adam rat z man . spotify . endpoints . pub . Search Api Ċ import Ġcom . adam rat z man . spotify . models .* Ċ import Ġcom . n ha ar man . mockito _ kotlin .* Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġme . h uf man . android aut oid rive . AppSettings Ċ import Ġme . h uf man . android aut oid rive . Mock AppSettings Ċ import Ġme . h uf man . android aut oid rive . Mutable AppSettings Ċ import Ġme . h uf man . android aut oid rive . R Ċ import Ġme . h uf man . android aut oid rive . music . controllers . Spot ify App Controller Ċ import Ġme . h uf man . android aut oid rive . music . spotify . Spot ify WebApi Ċ import Ġme . h uf man . android aut oid rive . music . spotify . Spot ify Auth StateManager Ċ import Ġme . h uf man . android aut oid rive . music . spotify . Spot ify Client Api Builder Helper Ċ import Ġme . h uf man . android aut oid rive . music . spotify . Spot ify Music Metadata Ċ import Ġme . h uf man . android aut oid rive . phone ui . Spot ify Authorization Activity Ċ import Ġnet . openid . app auth .* Ċ import Ġorg . junit . Assert .* Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Argument Matchers . any Int Ċ import Ġorg . mockito . internal . util . reflection . Field Setter Ċ import Ġorg . power mock . api . mockito . Power Mockito Ċ import Ġorg . power mock . core . class loader . annotations . Prepare For Test Ċ import Ġorg . power mock . modules . junit 4 . Power Mock Runner Ċ import Ġorg . power mock . reflect . White box Ċ import Ġjava . lang . Exception Ċ Ċ @ RunWith ( Power Mock Runner :: class ) Ċ @ Prepare For Test ( Spot ify WebApi :: class , ĠSpotify App Controller :: class , ĠPending Intent :: class , ĠSpotify Auth StateManager :: class , ĠSpotify Client Api Builder Helper :: class ) Ċ class ĠSpotify WebApi Test Ġ{ ĊĊ ĉ late init Ġvar Ġcontext : ĠContext Ċ ĉ late init Ġvar Ġspot ify Auth StateManager : ĠSpotify Auth StateManager Ċ ĉ late init Ġvar Ġspot ify WebApi : ĠSpotify WebApi Ċ ĉ late init Ġvar Ġapp Settings : ĠMutable AppSettings Ċ ĉ val ĠclientId : ĠString Ġ= Ġ" clientId " ĊĊ ĉ @ Before Ċ ĉ fun Ġsetup () Ċ ĉ { Ċĉ ĉ context Ġ= Ġmock () Ċĉ ĉ spotify Auth StateManager Ġ= Ġmock () Ċĉ ĉ app Settings Ġ= ĠMock AppSettings () ĊĊĉ ĉ Power Mockito . mock Static ( Spot ify Auth StateManager :: class . java ) Ċĉ ĉ val Ġcompanion Ġ= ĠPower Mockito . mock ( Spot ify Auth StateManager . Companion :: class . java ) Ċĉ ĉ White box . set Internal State ( Spot ify Auth StateManager :: class . java , Ġ" Companion ", Ġcompanion ) Ċĉ ĉ Power Mockito .` when `( Spot ify Auth StateManager . getInstance ( app Settings )). thenReturn ( spotify Auth StateManager ) ĊĊĉ ĉ Power Mockito . mock Static ( Spot ify App Controller :: class . java ) Ċĉ ĉ val Ġspot ify App Controller Companion Ġ= ĠPower Mockito . mock ( Spot ify App Controller . Companion :: class . java ) Ċĉ ĉ White box . set Internal State ( Spot ify App Controller :: class . java , Ġ" Companion ", Ġspot ify App Controller Companion ) Ċĉ ĉ Power Mockito .` when `( spotify App Controller Companion . getClient Id ( context )). thenReturn ( clientId ) ĊĊĉ ĉ spotify WebApi Ġ= ĠWhite box . invoke Constructor ( Spot ify WebApi :: class . java , Ġcontext , Ġapp Settings ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Initialize WebApi _ WebApi Existing () Ċ ĉ { Ċĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ spotify WebApi . initialize WebApi () ĊĊĉ ĉ assertEquals ( web Api , ĠWhite box . get Internal State ( spotify WebApi , Ġ" web Api ")) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Initialize WebApi _ Valid AccessToken () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val ĠaccessToken Ġ= Ġ" valid AccessToken " Ċĉ ĉ val Ġexpiration In : ĠLong Ġ= Ġ 5 Ċĉ ĉ val Ġrefresh Token Ġ= Ġ" refresh Token " Ċĉ ĉ val Ġscope String Ġ= Ġ" scope String " Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken ()). thenReturn ( accessToken ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken Expiration In ()). thenReturn ( expiration In ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get RefreshToken ()). thenReturn ( refresh Token ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get Scope String ()). thenReturn ( scope String ) ĊĊĉ ĉ val Ġexpires At : ĠLong Ġ= Ġ 2 Ċĉ ĉ val Ġtoken : ĠToken Ġ= Ġmock () Ċĉ ĉ wh enever ( token . refresh Token ). thenReturn ( refresh Token ) Ċĉ ĉ wh enever ( token . accessToken ). thenReturn ( accessToken ) Ċĉ ĉ wh enever ( token . expires At ). thenReturn ( expires At ) Ċĉ ĉ wh enever ( token . scopes ). thenReturn ( listOf ( Spot ify Scope . USER _ LIBRARY _ READ )) Ċĉ ĉ Power Mockito . when New ( Token :: class . java ). with Arguments ( accessToken , Ġ" Bearer ", Ġexpiration In . toInt (), Ġrefresh Token , Ġscope String ). thenReturn ( token ) ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . token ). thenReturn ( token ) ĊĊĉ ĉ val Ġapi Builder : ĠSpotify Client Api Builder Ġ= Ġmock () Ċĉ ĉ wh enever ( api Builder . options ). do Answer Ġ{ Ġmock () Ġ} Ċĉ ĉ wh enever ( api Builder . build ()). thenReturn ( web Api ) ĊĊĉ ĉ Power Mockito . mock Static ( Spot ify Client Api Builder Helper :: class . java ) Ċĉ ĉ val Ġcompanion Ġ= ĠPower Mockito . mock ( Spot ify Client Api Builder Helper . Companion :: class . java ) Ċĉ ĉ White box . set Internal State ( Spot ify Client Api Builder Helper :: class . java , Ġ" Companion ", Ġcompanion ) Ċĉ ĉ Power Mockito .` when `( comp anion . create Api Builder With AccessToken ( clientId , Ġtoken )). thenReturn ( api Builder ) ĊĊĉ ĉ do Nothing (). wh enever ( spotify Auth StateManager ). update Token Response With Token ( token , ĠclientId ) ĊĊĉ ĉ val Ġhandler : ĠHandler Ġ= Ġmock () Ċĉ ĉ Power Mockito . when New ( Handler :: class . java ). with Any Arguments (). thenReturn ( handler ) Ċĉ ĉ val Ġmusic App Discovery : ĠMusic App Discovery Ġ= Ġmock () Ċĉ ĉ Power Mockito . when New ( Music App Discovery :: class . java ). with Arguments ( context , Ġhandler ). thenReturn ( music App Discovery ) ĊĊĉ ĉ spotify WebApi . initialize WebApi () ĊĊĉ ĉ verify ( spotify Auth StateManager ). update Token Response With Token ( token , ĠclientId ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Initialize WebApi _ Invalid AccessToken () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val ĠaccessToken Ġ= Ġ" in Valid AccessToken " Ċĉ ĉ val Ġexpiration In : ĠLong Ġ= Ġ 5 Ċĉ ĉ val Ġrefresh Token Ġ= Ġ" refresh Token " Ċĉ ĉ val Ġscope String Ġ= Ġ" scope String " Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken ()). thenReturn ( accessToken ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken Expiration In ()). thenReturn ( expiration In ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get RefreshToken ()). thenReturn ( refresh Token ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get Scope String ()). thenReturn ( scope String ) ĊĊĉ ĉ val Ġexpires At : ĠLong Ġ= Ġ 2 Ċĉ ĉ val Ġtoken : ĠToken Ġ= Ġmock () Ċĉ ĉ wh enever ( token . refresh Token ). thenReturn ( refresh Token ) Ċĉ ĉ wh enever ( token . accessToken ). thenReturn ( accessToken ) Ċĉ ĉ wh enever ( token . expires At ). thenReturn ( expires At ) Ċĉ ĉ wh enever ( token . scopes ). thenReturn ( listOf ( Spot ify Scope . USER _ LIBRARY _ READ )) Ċĉ ĉ Power Mockito . when New ( Token :: class . java ). with Arguments ( accessToken , Ġ" Bearer ", Ġexpiration In . toInt (), Ġrefresh Token , Ġscope String ). thenReturn ( token ) ĊĊĉ ĉ val Ġexception Ġ= ĠSpotify Exception . Authentication Exception (" message ") Ċĉ ĉ val Ġapi Builder : ĠSpotify Client Api Builder Ġ= Ġmock () Ċĉ ĉ wh enever ( api Builder . options ). do Answer Ġ{ Ġmock () Ġ} Ċĉ ĉ wh enever ( api Builder . build ()). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ Power Mockito . mock Static ( Spot ify Client Api Builder Helper :: class . java ) Ċĉ ĉ val Ġcompanion Ġ= ĠPower Mockito . mock ( Spot ify Client Api Builder Helper . Companion :: class . java ) Ċĉ ĉ White box . set Internal State ( Spot ify Client Api Builder Helper :: class . java , Ġ" Companion ", Ġcompanion ) Ċĉ ĉ Power Mockito .` when `( comp anion . create Api Builder With AccessToken ( clientId , Ġtoken )). thenReturn ( api Builder ) ĊĊĉ ĉ do Nothing (). wh enever ( spotify Auth StateManager ). add AccessToken Authorization Exception ( exception ) ĊĊĉ ĉ val Ġnotification Manager : ĠNotification Manager Ġ= Ġmock () Ċĉ ĉ wh enever ( context . getSystem Service ( Notification Manager :: class . java )). thenReturn ( notification Manager ) ĊĊĉ ĉ spotify WebApi . initialize WebApi () ĊĊĉ ĉ verify ( spotify Auth StateManager ). add AccessToken Authorization Exception ( exception ) Ċĉ ĉ verify ( notification Manager , Ġnever ()). notify ( any (), Ġany ()) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Initialize WebApi _ Invalid AccessToken _ Exception Thrown () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val ĠaccessToken Ġ= Ġ" valid AccessToken " Ċĉ ĉ val Ġexpiration In : ĠLong Ġ= Ġ 5 Ċĉ ĉ val Ġrefresh Token Ġ= Ġ" refresh Token " Ċĉ ĉ val Ġscope String Ġ= Ġ" scope String " Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken ()). thenReturn ( accessToken ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken Expiration In ()). thenReturn ( expiration In ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get RefreshToken ()). thenReturn ( refresh Token ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get Scope String ()). thenReturn ( scope String ) ĊĊĉ ĉ val Ġexpires At : ĠLong Ġ= Ġ 2 Ċĉ ĉ val Ġtoken : ĠToken Ġ= Ġmock () Ċĉ ĉ wh enever ( token . refresh Token ). thenReturn ( refresh Token ) Ċĉ ĉ wh enever ( token . accessToken ). thenReturn ( accessToken ) Ċĉ ĉ wh enever ( token . expires At ). thenReturn ( expires At ) Ċĉ ĉ wh enever ( token . scopes ). thenReturn ( listOf ( Spot ify Scope . USER _ LIBRARY _ READ )) Ċĉ ĉ Power Mockito . when New ( Token :: class . java ). with Arguments ( accessToken , Ġ" Bearer ", Ġexpiration In . toInt (), Ġrefresh Token , Ġscope String ). thenReturn ( token ) ĊĊĉ ĉ val Ġexception : ĠException Ġ= Ġmock () Ċĉ ĉ val Ġapi Builder : ĠSpotify Client Api Builder Ġ= Ġmock () Ċĉ ĉ wh enever ( api Builder . options ). do Answer Ġ{ Ġmock () Ġ} Ċĉ ĉ wh enever ( api Builder . build ()). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ Power Mockito . mock Static ( Spot ify Client Api Builder Helper :: class . java ) Ċĉ ĉ val Ġcompanion Ġ= ĠPower Mockito . mock ( Spot ify Client Api Builder Helper . Companion :: class . java ) Ċĉ ĉ White box . set Internal State ( Spot ify Client Api Builder Helper :: class . java , Ġ" Companion ", Ġcompanion ) Ċĉ ĉ Power Mockito .` when `( comp anion . create Api Builder With AccessToken ( clientId , Ġtoken )). thenReturn ( api Builder ) ĊĊĉ ĉ val Ġnotification Manager : ĠNotification Manager Ġ= Ġmock () Ċĉ ĉ wh enever ( context . getSystem Service ( Notification Manager :: class . java )). thenReturn ( notification Manager ) ĊĊĉ ĉ spotify WebApi . initialize WebApi () ĊĊĉ ĉ verify ( notification Manager , Ġnever ()). notify ( any (), Ġany ()) Ċĉ ĉ verify ( spotify Auth StateManager , Ġnever ()). add AccessToken Authorization Exception ( any ()) Ċĉ ĉ verify ( spotify Auth StateManager , Ġnever ()). update Token Response With Token ( token , ĠclientId ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Initialize WebApi _ Null Authorization Code () Ġ{ Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken ()). thenReturn ( null ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get Authorization Code ()). thenReturn ( null ) ĊĊĉ ĉ val Ġnotification Manager : ĠNotification Manager Ġ= Ġmock () Ċĉ ĉ wh enever ( context . getSystem Service ( Notification Manager :: class . java )). thenReturn ( notification Manager ) ĊĊĉ ĉ spotify WebApi . initialize WebApi () ĊĊĉ ĉ verify ( notification Manager , Ġnever ()). notify ( any (), Ġany ()) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Initialize WebApi _ Valid Authorization Code () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġauthorization Code Ġ= Ġ" authorization Code " Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken ()). thenReturn ( null ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get Authorization Code ()). thenReturn ( authorization Code ) ĊĊĉ ĉ val Ġrefresh Token Ġ= Ġ" refresh Token " Ċĉ ĉ val ĠaccessToken Ġ= Ġ" accessToken " Ċĉ ĉ val Ġexpires At : ĠLong Ġ= Ġ 2 Ċĉ ĉ val Ġtoken : ĠToken Ġ= Ġmock () Ċĉ ĉ wh enever ( token . refresh Token ). thenReturn ( refresh Token ) Ċĉ ĉ wh enever ( token . accessToken ). thenReturn ( accessToken ) Ċĉ ĉ wh enever ( token . expires At ). thenReturn ( expires At ) Ċĉ ĉ wh enever ( token . scopes ). thenReturn ( listOf ( Spot ify Scope . USER _ LIBRARY _ READ )) ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . token ). thenReturn ( token ) ĊĊĉ ĉ val Ġapi Builder : ĠSpotify Client Api Builder Ġ= Ġmock () Ċĉ ĉ wh enever ( api Builder . options ). do Answer Ġ{ Ġmock () Ġ} Ċĉ ĉ wh enever ( api Builder . build ()). thenReturn ( web Api ) ĊĊĉ ĉ Power Mockito . mock Static ( Spot ify Client Api Builder Helper :: class . java ) Ċĉ ĉ val Ġcompanion Ġ= ĠPower Mockito . mock ( Spot ify Client Api Builder Helper . Companion :: class . java ) Ċĉ ĉ White box . set Internal State ( Spot ify Client Api Builder Helper :: class . java , Ġ" Companion ", Ġcompanion ) Ċĉ ĉ Power Mockito .` when `( comp anion . create Api Builder With Authorization Code ( clientId , Ġauthorization Code )). thenReturn ( api Builder ) ĊĊĉ ĉ val Ġauthorization Service Config : ĠAuthorization Service Configuration Ġ= Ġmock () Ċĉ ĉ wh enever ( spotify Auth StateManager . get Authorization Service Configuration ()). thenReturn ( authorization Service Config ) ĊĊĉ ĉ do Nothing (). wh enever ( spotify Auth StateManager ). update Token Response With Token ( token , ĠclientId ) ĊĊĉ ĉ val Ġhandler : ĠHandler Ġ= Ġmock () Ċĉ ĉ Power Mockito . when New ( Handler :: class . java ). with Any Arguments (). thenReturn ( handler ) Ċĉ ĉ val Ġmusic App Discovery : ĠMusic App Discovery Ġ= Ġmock () Ċĉ ĉ Power Mockito . when New ( Music App Discovery :: class . java ). with Arguments ( context , Ġhandler ). thenReturn ( music App Discovery ) ĊĊĉ ĉ spotify WebApi . initialize WebApi () ĊĊĉ ĉ verify ( spotify Auth StateManager ). update Token Response With Token ( token , ĠclientId ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Initialize WebApi _ Invalid Authorization Code () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġauthorization Code Ġ= Ġ" authorization Code " Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken ()). thenReturn ( null ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get Authorization Code ()). thenReturn ( authorization Code ) ĊĊĉ ĉ val Ġexception Ġ= ĠSpotify Exception . Authentication Exception (" message ") Ċĉ ĉ val Ġapi Builder : ĠSpotify Client Api Builder Ġ= Ġmock () Ċĉ ĉ wh enever ( api Builder . options ). do Answer Ġ{ Ġmock () Ġ} Ċĉ ĉ wh enever ( api Builder . build ()). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ Power Mockito . mock Static ( Spot ify Client Api Builder Helper :: class . java ) Ċĉ ĉ val Ġcompanion Ġ= ĠPower Mockito . mock ( Spot ify Client Api Builder Helper . Companion :: class . java ) Ċĉ ĉ White box . set Internal State ( Spot ify Client Api Builder Helper :: class . java , Ġ" Companion ", Ġcompanion ) Ċĉ ĉ Power Mockito .` when `( comp anion . create Api Builder With Authorization Code ( clientId , Ġauthorization Code )). thenReturn ( api Builder ) ĊĊĉ ĉ do Nothing (). wh enever ( spotify Auth StateManager ). add Authorization Code Authorization Exception ( exception ) ĊĊĉ ĉ val Ġnotification Manager : ĠNotification Manager Ġ= Ġmock () Ċĉ ĉ wh enever ( context . getSystem Service ( Notification Manager :: class . java )). thenReturn ( notification Manager ) ĊĊĉ ĉ spotify WebApi . initialize WebApi () ĊĊĉ ĉ verify ( spotify Auth StateManager ). add Authorization Code Authorization Exception ( exception ) Ċĉ ĉ verify ( notification Manager , Ġnever ()). notify ( any (), Ġany ()) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Initialize WebApi _ Invalid Authorization Code _ Exception Thrown () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġauthorization Code Ġ= Ġ" authorization Code " Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken ()). thenReturn ( null ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get Authorization Code ()). thenReturn ( authorization Code ) ĊĊĉ ĉ val Ġexception : ĠException Ġ= Ġmock () Ċĉ ĉ val Ġapi Builder : ĠSpotify Client Api Builder Ġ= Ġmock () Ċĉ ĉ wh enever ( api Builder . options ). do Answer Ġ{ Ġmock () Ġ} Ċĉ ĉ wh enever ( api Builder . build ()). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ Power Mockito . mock Static ( Spot ify Client Api Builder Helper :: class . java ) Ċĉ ĉ val Ġcompanion Ġ= ĠPower Mockito . mock ( Spot ify Client Api Builder Helper . Companion :: class . java ) Ċĉ ĉ White box . set Internal State ( Spot ify Client Api Builder Helper :: class . java , Ġ" Companion ", Ġcompanion ) Ċĉ ĉ Power Mockito .` when `( comp anion . create Api Builder With Authorization Code ( clientId , Ġauthorization Code )). thenReturn ( api Builder ) ĊĊĉ ĉ val Ġnotification Manager : ĠNotification Manager Ġ= Ġmock () Ċĉ ĉ wh enever ( context . getSystem Service ( Notification Manager :: class . java )). thenReturn ( notification Manager ) ĊĊĉ ĉ spotify WebApi . initialize WebApi () ĊĊĉ ĉ verify ( notification Manager , Ġnever ()). notify ( any (), Ġany ()) Ċĉ ĉ verify ( spotify Auth StateManager , Ġnever ()). add Authorization Code Authorization Exception ( any ()) Ċĉ ĉ verify ( spotify Auth StateManager , Ġnever ()). update Token Response With Token ( any (), Ġany ()) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Initialize WebApi _ Get Lik ed S ongs Pending Queue Metadata Create () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġauthorization Code Ġ= Ġ" authorization Code " Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken ()). thenReturn ( null ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get Authorization Code ()). thenReturn ( authorization Code ) ĊĊĉ ĉ val Ġrefresh Token Ġ= Ġ" refresh Token " Ċĉ ĉ val ĠaccessToken Ġ= Ġ" accessToken " Ċĉ ĉ val Ġexpires At : ĠLong Ġ= Ġ 2 Ċĉ ĉ val Ġtoken : ĠToken Ġ= Ġmock () Ċĉ ĉ wh enever ( token . refresh Token ). thenReturn ( refresh Token ) Ċĉ ĉ wh enever ( token . accessToken ). thenReturn ( accessToken ) Ċĉ ĉ wh enever ( token . expires At ). thenReturn ( expires At ) Ċĉ ĉ wh enever ( token . scopes ). thenReturn ( listOf ( Spot ify Scope . USER _ LIBRARY _ READ )) ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . token ). thenReturn ( token ) ĊĊĉ ĉ val Ġapi Builder : ĠSpotify Client Api Builder Ġ= Ġmock () Ċĉ ĉ wh enever ( api Builder . options ). do Answer Ġ{ Ġmock () Ġ} Ċĉ ĉ wh enever ( api Builder . build ()). thenReturn ( web Api ) ĊĊĉ ĉ Power Mockito . mock Static ( Spot ify Client Api Builder Helper :: class . java ) Ċĉ ĉ val Ġcompanion Ġ= ĠPower Mockito . mock ( Spot ify Client Api Builder Helper . Companion :: class . java ) Ċĉ ĉ White box . set Internal State ( Spot ify Client Api Builder Helper :: class . java , Ġ" Companion ", Ġcompanion ) Ċĉ ĉ Power Mockito .` when `( comp anion . create Api Builder With Authorization Code ( clientId , Ġauthorization Code )). thenReturn ( api Builder ) ĊĊĉ ĉ val Ġauthorization Service Config : ĠAuthorization Service Configuration Ġ= Ġmock () Ċĉ ĉ wh enever ( spotify Auth StateManager . get Authorization Service Configuration ()). thenReturn ( authorization Service Config ) ĊĊĉ ĉ do Nothing (). wh enever ( spotify Auth StateManager ). update Token Response With Token ( token , ĠclientId ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ do Nothing (). wh enever ( spotify App Controller ). create Lik ed S ongs Queue Metadata () ĊĊĉ ĉ val Ġhandler : ĠHandler Ġ= Ġmock () Ċĉ ĉ Power Mockito . when New ( Handler :: class . java ). with Any Arguments (). thenReturn ( handler ) Ċĉ ĉ val Ġmusic App Discovery : ĠMusic App Discovery Ġ= Ġmock () Ċĉ ĉ Power Mockito . when New ( Music App Discovery :: class . java ). with Arguments ( context , Ġhandler ). thenReturn ( music App Discovery ) ĊĊĉ ĉ val Ġlik ed S ongs Ġ= Ġspot ify WebApi . get Lik ed S ongs ( spotify App Controller ) Ċĉ ĉ assertEquals ( emptyList < Spot ify Music Metadata >(), Ġlik ed S ongs ) ĊĊĉ ĉ spotify WebApi . initialize WebApi () ĊĊĉ ĉ verify ( spotify Auth StateManager ). update Token Response With Token ( token , ĠclientId ) Ċĉ ĉ verify ( spotify App Controller ). create Lik ed S ongs Queue Metadata () ĊĊĉ ĉ val Ġinternal Pending Queue Metadata Create : Ġ(() Ġ-> ĠUnit )? Ġ= ĠWhite box . get Internal State ( spotify WebApi , Ġ" pending Queue Metadata Create ") Ċĉ ĉ assertNull ( internal Pending Queue Metadata Create ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Initialize WebApi _ Get Artist Top S ongs Pending Queue Metadata Create () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġauthorization Code Ġ= Ġ" authorization Code " Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken ()). thenReturn ( null ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get Authorization Code ()). thenReturn ( authorization Code ) ĊĊĉ ĉ val Ġrefresh Token Ġ= Ġ" refresh Token " Ċĉ ĉ val ĠaccessToken Ġ= Ġ" accessToken " Ċĉ ĉ val Ġexpires At : ĠLong Ġ= Ġ 2 Ċĉ ĉ val Ġtoken : ĠToken Ġ= Ġmock () Ċĉ ĉ wh enever ( token . refresh Token ). thenReturn ( refresh Token ) Ċĉ ĉ wh enever ( token . accessToken ). thenReturn ( accessToken ) Ċĉ ĉ wh enever ( token . expires At ). thenReturn ( expires At ) Ċĉ ĉ wh enever ( token . scopes ). thenReturn ( listOf ( Spot ify Scope . USER _ LIBRARY _ READ )) ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . token ). thenReturn ( token ) ĊĊĉ ĉ val Ġapi Builder : ĠSpotify Client Api Builder Ġ= Ġmock () Ċĉ ĉ wh enever ( api Builder . options ). do Answer Ġ{ Ġmock () Ġ} Ċĉ ĉ wh enever ( api Builder . build ()). thenReturn ( web Api ) ĊĊĉ ĉ Power Mockito . mock Static ( Spot ify Client Api Builder Helper :: class . java ) Ċĉ ĉ val Ġcompanion Ġ= ĠPower Mockito . mock ( Spot ify Client Api Builder Helper . Companion :: class . java ) Ċĉ ĉ White box . set Internal State ( Spot ify Client Api Builder Helper :: class . java , Ġ" Companion ", Ġcompanion ) Ċĉ ĉ Power Mockito .` when `( comp anion . create Api Builder With Authorization Code ( clientId , Ġauthorization Code )). thenReturn ( api Builder ) ĊĊĉ ĉ val Ġauthorization Service Config : ĠAuthorization Service Configuration Ġ= Ġmock () Ċĉ ĉ wh enever ( spotify Auth StateManager . get Authorization Service Configuration ()). thenReturn ( authorization Service Config ) ĊĊĉ ĉ do Nothing (). wh enever ( spotify Auth StateManager ). update Token Response With Token ( token , ĠclientId ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ do Nothing (). wh enever ( spotify App Controller ). create Artist Top S ongs Queue Metadata () ĊĊĉ ĉ val Ġhandler : ĠHandler Ġ= Ġmock () Ċĉ ĉ Power Mockito . when New ( Handler :: class . java ). with Any Arguments (). thenReturn ( handler ) Ċĉ ĉ val Ġmusic App Discovery : ĠMusic App Discovery Ġ= Ġmock () Ċĉ ĉ Power Mockito . when New ( Music App Discovery :: class . java ). with Arguments ( context , Ġhandler ). thenReturn ( music App Discovery ) ĊĊĉ ĉ val Ġlik ed S ongs Ġ= Ġspot ify WebApi . get Artist Top S ongs ( spotify App Controller , Ġ" artist Uri ") Ċĉ ĉ assertEquals ( emptyList < Spot ify Music Metadata >(), Ġlik ed S ongs ) ĊĊĉ ĉ spotify WebApi . initialize WebApi () ĊĊĉ ĉ verify ( spotify Auth StateManager ). update Token Response With Token ( token , ĠclientId ) Ċĉ ĉ verify ( spotify App Controller ). create Artist Top S ongs Queue Metadata () ĊĊĉ ĉ val Ġinternal Pending Queue Metadata Create : Ġ(() Ġ-> ĠUnit )? Ġ= ĠWhite box . get Internal State ( spotify WebApi , Ġ" pending Queue Metadata Create ") Ċĉ ĉ assertNull ( internal Pending Queue Metadata Create ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Initialize WebApi _ Null Authentication Code _ Show Un authenticated Notification Setting True () Ġ{ Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken ()). thenReturn ( null ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get Authorization Code ()). thenReturn ( null ) ĊĊĉ ĉ app Settings [ AppSettings . KEYS . SP OT IFY _ SHOW _ UN AUTHENT IC ATED _ NOTIFICATION ] Ġ= Ġ" true " ĊĊĉ ĉ val Ġnotify Intent : ĠIntent Ġ= Ġmock () Ċĉ ĉ Power Mockito . when New ( Intent :: class . java ). with Arguments ( context , ĠSpotify Authorization Activity :: class . java ). thenReturn ( notify Intent ) ĊĊĉ ĉ val ĠgetString Text Ġ= Ġ" string " Ċĉ ĉ wh enever ( context . getString ( any ())). thenReturn ( getString Text ) ĊĊĉ ĉ val Ġcontent Intent : ĠPending Intent Ġ= Ġmock () Ċĉ ĉ Power Mockito . mock Static ( Pending Intent :: class . java ) Ċĉ ĉ Power Mockito .` when `( Pending Intent . getActivity ( context , ĠSpotify WebApi . NOTIFICATION _ REQ _ ID , Ġnotify Intent , ĠPending Intent . FLAG _ UPDATE _ CURRENT )). then Answer Ġ{ Ġcontent Intent Ġ} ĊĊĉ ĉ val Ġnotification : ĠNotification Ġ= Ġmock () Ċĉ ĉ val Ġnotification Builder : ĠNotification Compat . Builder Ġ= Ġmock () Ċĉ ĉ wh enever ( notification Builder . setContent Title ( getString Text )). thenReturn ( notification Builder ) Ċĉ ĉ wh enever ( notification Builder . setContent Text ( getString Text )). thenReturn ( notification Builder ) Ċĉ ĉ wh enever ( notification Builder . set Small Icon ( any Int ())). thenReturn ( notification Builder ) Ċĉ ĉ wh enever ( notification Builder . setContent Intent ( content Intent )). thenReturn ( notification Builder ) Ċĉ ĉ wh enever ( notification Builder . build ()). thenReturn ( notification ) Ċĉ ĉ Power Mockito . when New ( Notification Compat . Builder :: class . java ). with Arguments ( context , ĠSpotify WebApi . NOTIFICATION _ CHANNEL _ ID ). thenReturn ( notification Builder ) ĊĊĉ ĉ val Ġnotification Channel : ĠNotification Channel Ġ= Ġmock () Ċĉ ĉ Power Mockito . when New ( Notification Channel :: class . java ). with Arguments ( Spot ify WebApi . NOTIFICATION _ CHANNEL _ ID , Ġ" Spot ify ĠAuthorization ", ĠNotification Manager . IMPORT ANCE _ HIGH ). thenReturn ( notification Channel ) ĊĊĉ ĉ val Ġnotification Manager : ĠNotification Manager Ġ= Ġmock () Ċĉ ĉ do Nothing (). wh enever ( notification Manager ). create Notification Channel ( notification Channel ) Ċĉ ĉ wh enever ( context . getString ( R . string . notification _ channel _ spotify )). thenReturn (" Spot ify ĠAuthorization ") Ċĉ ĉ wh enever ( context . getSystem Service ( Notification Manager :: class . java )). thenReturn ( notification Manager ) ĊĊĉ ĉ do Nothing (). wh enever ( notification Manager ). notify ( Spot ify WebApi . NOTIFICATION _ REQ _ ID , Ġnotification ) ĊĊĉ ĉ spotify WebApi . initialize WebApi () ĊĊĉ ĉ verify ( notification Manager ). create Notification Channel ( notification Channel ) Ċĉ ĉ verify ( notification Manager ). notify ( Spot ify WebApi . NOTIFICATION _ REQ _ ID , Ġnotification ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Initialize WebApi _ Music App Discovery Not Search able () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val ĠaccessToken Ġ= Ġ" valid AccessToken " Ċĉ ĉ val Ġexpiration In : ĠLong Ġ= Ġ 5 Ċĉ ĉ val Ġrefresh Token Ġ= Ġ" refresh Token " Ċĉ ĉ val Ġscope String Ġ= Ġ" scope String " Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken ()). thenReturn ( accessToken ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken Expiration In ()). thenReturn ( expiration In ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get RefreshToken ()). thenReturn ( refresh Token ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get Scope String ()). thenReturn ( scope String ) ĊĊĉ ĉ val Ġexpires At : ĠLong Ġ= Ġ 2 Ċĉ ĉ val Ġtoken : ĠToken Ġ= Ġmock () Ċĉ ĉ wh enever ( token . refresh Token ). thenReturn ( refresh Token ) Ċĉ ĉ wh enever ( token . accessToken ). thenReturn ( accessToken ) Ċĉ ĉ wh enever ( token . expires At ). thenReturn ( expires At ) Ċĉ ĉ wh enever ( token . scopes ). thenReturn ( listOf ( Spot ify Scope . USER _ LIBRARY _ READ )) Ċĉ ĉ Power Mockito . when New ( Token :: class . java ). with Arguments ( accessToken , Ġ" Bearer ", Ġexpiration In . toInt (), Ġrefresh Token , Ġscope String ). thenReturn ( token ) ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . token ). thenReturn ( token ) ĊĊĉ ĉ val Ġapi Builder : ĠSpotify Client Api Builder Ġ= Ġmock () Ċĉ ĉ wh enever ( api Builder . options ). do Answer Ġ{ Ġmock () Ġ} Ċĉ ĉ wh enever ( api Builder . build ()). thenReturn ( web Api ) ĊĊĉ ĉ Power Mockito . mock Static ( Spot ify Client Api Builder Helper :: class . java ) Ċĉ ĉ val Ġcompanion Ġ= ĠPower Mockito . mock ( Spot ify Client Api Builder Helper . Companion :: class . java ) Ċĉ ĉ White box . set Internal State ( Spot ify Client Api Builder Helper :: class . java , Ġ" Companion ", Ġcompanion ) Ċĉ ĉ Power Mockito .` when `( comp anion . create Api Builder With AccessToken ( clientId , Ġtoken )). thenReturn ( api Builder ) ĊĊĉ ĉ do Nothing (). wh enever ( spotify Auth StateManager ). update Token Response With Token ( token , ĠclientId ) ĊĊĉ ĉ val Ġhandler : ĠHandler Ġ= Ġmock () Ċĉ ĉ Power Mockito . when New ( Handler :: class . java ). with Any Arguments (). thenReturn ( handler ) Ċĉ ĉ val Ġspot ify Music App Ġ= ĠMusic App Info (" Spot ify ", Ġmock (), Ġ" com . spotify . music ", Ġnull ) Ċĉ ĉ spotify Music App . search able Ġ= Ġfalse Ċĉ ĉ val Ġmusic App InfoList Ġ= ĠlistOf ( spotify Music App ) Ċĉ ĉ val Ġmusic App Discovery : ĠMusic App Discovery Ġ= Ġmock () Ċĉ ĉ do Nothing (). wh enever ( music App Discovery ). load Installed Music Apps () Ċĉ ĉ wh enever ( music App Discovery . all Apps ). thenReturn ( music App InfoList ) Ċĉ ĉ Power Mockito . when New ( Music App Discovery :: class . java ). with Arguments ( context , Ġhandler ). thenReturn ( music App Discovery ) ĊĊĉ ĉ spotify WebApi . initialize WebApi () ĊĊĉ ĉ verify ( spotify Auth StateManager ). update Token Response With Token ( token , ĠclientId ) Ċĉ ĉ verify ( music App Discovery ). probe App ( spotify Music App ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Initialize WebApi _ Music App Discovery Search able () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val ĠaccessToken Ġ= Ġ" valid AccessToken " Ċĉ ĉ val Ġexpiration In : ĠLong Ġ= Ġ 5 Ċĉ ĉ val Ġrefresh Token Ġ= Ġ" refresh Token " Ċĉ ĉ val Ġscope String Ġ= Ġ" scope String " Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken ()). thenReturn ( accessToken ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get AccessToken Expiration In ()). thenReturn ( expiration In ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get RefreshToken ()). thenReturn ( refresh Token ) Ċĉ ĉ wh enever ( spotify Auth StateManager . get Scope String ()). thenReturn ( scope String ) ĊĊĉ ĉ val Ġexpires At : ĠLong Ġ= Ġ 2 Ċĉ ĉ val Ġtoken : ĠToken Ġ= Ġmock () Ċĉ ĉ wh enever ( token . refresh Token ). thenReturn ( refresh Token ) Ċĉ ĉ wh enever ( token . accessToken ). thenReturn ( accessToken ) Ċĉ ĉ wh enever ( token . expires At ). thenReturn ( expires At ) Ċĉ ĉ wh enever ( token . scopes ). thenReturn ( listOf ( Spot ify Scope . USER _ LIBRARY _ READ )) Ċĉ ĉ Power Mockito . when New ( Token :: class . java ). with Arguments ( accessToken , Ġ" Bearer ", Ġexpiration In . toInt (), Ġrefresh Token , Ġscope String ). thenReturn ( token ) ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . token ). thenReturn ( token ) ĊĊĉ ĉ val Ġapi Builder : ĠSpotify Client Api Builder Ġ= Ġmock () Ċĉ ĉ wh enever ( api Builder . options ). do Answer Ġ{ Ġmock () Ġ} Ċĉ ĉ wh enever ( api Builder . build ()). thenReturn ( web Api ) ĊĊĉ ĉ Power Mockito . mock Static ( Spot ify Client Api Builder Helper :: class . java ) Ċĉ ĉ val Ġcompanion Ġ= ĠPower Mockito . mock ( Spot ify Client Api Builder Helper . Companion :: class . java ) Ċĉ ĉ White box . set Internal State ( Spot ify Client Api Builder Helper :: class . java , Ġ" Companion ", Ġcompanion ) Ċĉ ĉ Power Mockito .` when `( comp anion . create Api Builder With AccessToken ( clientId , Ġtoken )). thenReturn ( api Builder ) ĊĊĉ ĉ do Nothing (). wh enever ( spotify Auth StateManager ). update Token Response With Token ( token , ĠclientId ) ĊĊĉ ĉ val Ġhandler : ĠHandler Ġ= Ġmock () Ċĉ ĉ Power Mockito . when New ( Handler :: class . java ). with Any Arguments (). thenReturn ( handler ) Ċĉ ĉ val Ġspot ify Music App Ġ= ĠMusic App Info (" Spot ify ", Ġmock (), Ġ" com . spotify . music ", Ġnull ) Ċĉ ĉ spotify Music App . search able Ġ= Ġtrue Ċĉ ĉ val Ġmusic App InfoList Ġ= ĠlistOf ( spotify Music App ) Ċĉ ĉ val Ġmusic App Discovery : ĠMusic App Discovery Ġ= Ġmock () Ċĉ ĉ do Nothing (). wh enever ( music App Discovery ). load Installed Music Apps () Ċĉ ĉ wh enever ( music App Discovery . all Apps ). thenReturn ( music App InfoList ) Ċĉ ĉ Power Mockito . when New ( Music App Discovery :: class . java ). with Arguments ( context , Ġhandler ). thenReturn ( music App Discovery ) ĊĊĉ ĉ spotify WebApi . initialize WebApi () ĊĊĉ ĉ verify ( spotify Auth StateManager ). update Token Response With Token ( token , ĠclientId ) Ċĉ ĉ verify ( music App Discovery , Ġnever ()). probe App ( spotify Music App ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Disconnect _ Some Instances Disconnected () Ġ{ Ċĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () ĊĊĉ ĉ val Ġinstance 1 Ġ= ĠSpotify WebApi . getInstance ( context , Ġapp Settings ) Ċĉ ĉ Field Setter . setField ( instance 1 , Ġinstance 1 :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġinstance 2 Ġ= ĠSpotify WebApi . getInstance ( context , Ġapp Settings ) Ċĉ ĉ Field Setter . setField ( instance 2 , Ġinstance 2 :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ instance 1 . is Using Spot ify Ġ= Ġtrue ĊĊĉ ĉ instance 1 . disconnect () ĊĊĉ ĉ verify ( web Api , Ġnever ()). shutdown () Ċĉ ĉ assertTrue ( instance 2 . is Using Spot ify ) ĊĊĉ ĉ // Ġcleanup Ċĉ ĉ instance 2 . disconnect () Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Disconnect _ All Instances Disconnected () Ġ{ Ċĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ do Nothing (). wh enever ( web Api ). shutdown () ĊĊĉ ĉ val Ġinstance 1 Ġ= ĠSpotify WebApi . getInstance ( context , Ġapp Settings ) Ċĉ ĉ Field Setter . setField ( instance 1 , Ġinstance 1 :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġinstance 2 Ġ= ĠSpotify WebApi . getInstance ( context , Ġapp Settings ) Ċĉ ĉ Field Setter . setField ( instance 2 , Ġinstance 2 :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ instance 1 . is Using Spot ify Ġ= Ġtrue ĊĊĉ ĉ instance 1 . disconnect () Ċĉ ĉ instance 2 . disconnect () ĊĊĉ ĉ verify ( web Api ). shutdown () Ċĉ ĉ assertFalse ( instance 2 . is Using Spot ify ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet Lik ed S ongs _ Null WebApi () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġnull ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġlik ed S ongs Ġ= Ġspot ify WebApi . get Lik ed S ongs ( spotify App Controller ) ĊĊĉ ĉ assertEquals ( emptyList < Spot ify Music Metadata >(), Ġlik ed S ongs ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet Lik ed S ongs _ Success () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġuri Id 1 Ġ= Ġ" uri Id 1 " Ċĉ ĉ val Ġtrack Name 1 Ġ= Ġ" Track Ġ 1 " Ċĉ ĉ val Ġartist Name 1 Ġ= Ġ" Artist Ġ 1 " Ċĉ ĉ val Ġalbum Name 1 Ġ= Ġ" Album Ġ 1 " Ċĉ ĉ val Ġcover Art Code 1 Ġ= Ġ"/ cover Art Code 1 " ĊĊĉ ĉ val Ġuri Id 2 Ġ= Ġ" uri Id 2 " Ċĉ ĉ val Ġtrack Name 2 Ġ= Ġ" Track Ġ 2 " Ċĉ ĉ val Ġartist Name 2 Ġ= Ġ" Artist Ġ 2 " Ċĉ ĉ val Ġalbum Name 2 Ġ= Ġ" Album Ġ 2 " Ċĉ ĉ val Ġcover Art Code 2 Ġ= Ġ"/ cover Art Code 2 " ĊĊĉ ĉ val Ġsaved Tracks Ġ= ĠlistOf ( Ċĉĉĉ ĉ create Saved Track ( uri Id 1 , Ġtrack Name 1 , Ġartist Name 1 , Ġalbum Name 1 , Ġcover Art Code 1 ), Ċĉĉĉ ĉ create Saved Track ( uri Id 2 , Ġtrack Name 2 , Ġartist Name 2 , Ġalbum Name 2 , Ġcover Art Code 2 , Ġ 6 0 0 ) Ċĉ ĉ ) ĊĊĉ ĉ val Ġpaging Object : ĠP aging Object < Saved Track > Ġ= Ġmock () Ċĉ ĉ wh enever ( paging Object . getAll Items NotNull ()). thenReturn ( saved Tracks ) ĊĊĉ ĉ val Ġclient Library Api : ĠClient Library Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Library Api . get Saved Tracks ( 5 0 )). do Answer Ġ{ Ġpaging Object Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . library ). thenReturn ( client Library Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġlik ed S ongs Ġ= Ġspot ify WebApi . get Lik ed S ongs ( spotify App Controller ) ĊĊĉ ĉ assertNotNull ( lik ed S ongs ) Ċĉ ĉ assertEquals ( 2 , Ġlik ed S ongs !!. size ) ĊĊĉ ĉ val Ġmetadata 1 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : track :${ uri Id 1 }", Ġcover Art Code 1 , Ġartist Name 1 , Ġalbum Name 1 , Ġtrack Name 1 , Ġnull , Ġfalse , Ġfalse ) Ċĉ ĉ assertEquals ( metadata 1 , Ġlik ed S ongs [ 0 ]) ĊĊĉ ĉ val Ġmetadata 2 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : track :${ uri Id 2 }", Ġnull , Ġartist Name 2 , Ġalbum Name 2 , Ġtrack Name 2 , Ġnull , Ġfalse , Ġfalse ) Ċĉ ĉ assertEquals ( metadata 2 , Ġlik ed S ongs [ 1 ]) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet Lik ed S ongs _ Authentication Exception () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġexception Ġ= ĠSpotify Exception . Authentication Exception (" message ") Ċĉ ĉ val Ġclient Library Api : ĠClient Library Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Library Api . get Saved Tracks ( 5 0 )). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . library ). thenReturn ( client Library Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ do Nothing (). wh enever ( spotify Auth StateManager ). add AccessToken Authorization Exception ( exception ) ĊĊĉ ĉ val Ġnotification Manager : ĠNotification Manager Ġ= Ġmock () Ċĉ ĉ wh enever ( context . getSystem Service ( Notification Manager :: class . java )). thenReturn ( notification Manager ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġlik ed S ongs Ġ= Ġspot ify WebApi . get Lik ed S ongs ( spotify App Controller ) ĊĊĉ ĉ verify ( notification Manager , Ġnever ()). notify ( any (), Ġany ()) ĊĊĉ ĉ assertEquals ( null , Ġlik ed S ongs ) Ċĉ ĉ val Ġinternal WebApi : ĠSpotify Client Api ? Ġ= ĠWhite box . get Internal State ( spotify WebApi , Ġ" web Api ") Ċĉ ĉ assertNull ( internal WebApi ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet Lik ed S ongs _ Spot ify Exception () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġexception Ġ= ĠSpotify Exception . BadRequest Exception (" message ") Ċĉ ĉ val Ġclient Library Api : ĠClient Library Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Library Api . get Saved Tracks ( 5 0 )). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . library ). thenReturn ( client Library Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġlik ed S ongs Ġ= Ġspot ify WebApi . get Lik ed S ongs ( spotify App Controller ) ĊĊĉ ĉ assertEquals ( null , Ġlik ed S ongs ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet Artist Top S ongs _ Null WebApi () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġnull ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġartist Top S ongs Ġ= Ġspot ify WebApi . get Artist Top S ongs ( spotify App Controller , Ġ" artist Uri ") ĊĊĉ ĉ assertEquals ( emptyList < Spot ify Music Metadata >(), Ġartist Top S ongs ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet Artist Top S ongs _ Success () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġuri Id 1 Ġ= Ġ" uri Id 1 " Ċĉ ĉ val Ġtrack Name 1 Ġ= Ġ" Track Ġ 1 " Ċĉ ĉ val Ġartist Name 1 Ġ= Ġ" Artist Ġ 1 " Ċĉ ĉ val Ġalbum Name 1 Ġ= Ġ" Album Ġ 1 " Ċĉ ĉ val Ġcover Art Code 1 Ġ= Ġ"/ cover Art Code 1 " ĊĊĉ ĉ val Ġuri Id 2 Ġ= Ġ" uri Id 2 " Ċĉ ĉ val Ġtrack Name 2 Ġ= Ġ" Track Ġ 2 " Ċĉ ĉ val Ġartist Name 2 Ġ= Ġ" Artist Ġ 2 " Ċĉ ĉ val Ġalbum Name 2 Ġ= Ġ" Album Ġ 2 " Ċĉ ĉ val Ġcover Art Code 2 Ġ= Ġ"/ cover Art Code 2 " ĊĊĉ ĉ val Ġartist Uri Ġ= Ġ" artist Uri " ĊĊĉ ĉ val Ġtop Tracks Ġ= ĠlistOf ( Ċĉĉĉ ĉ create Track ( uri Id 1 , Ġ" album Uri 1 ", Ġcover Art Code 1 , Ġartist Name 1 , Ġtrack Name 1 , Ġalbum Name 1 ), Ċĉĉĉ ĉ create Track ( uri Id 2 , Ġ" album Uri 2 ", Ġcover Art Code 2 , Ġartist Name 2 , Ġtrack Name 2 , Ġalbum Name 2 ) Ċĉ ĉ ) ĊĊĉ ĉ val Ġartist Api : ĠArtist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( artist Api . get Artist Top Tracks ( artist Uri )). do Answer Ġ{ Ġtop Tracks Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . artists ). thenReturn ( artist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġartist Top S ongs Ġ= Ġspot ify WebApi . get Artist Top S ongs ( spotify App Controller , Ġartist Uri ) ĊĊĉ ĉ assertNotNull ( artist Top S ongs ) Ċĉ ĉ assertEquals ( 2 , Ġartist Top S ongs !!. size ) ĊĊĉ ĉ val Ġmetadata 1 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : track :${ uri Id 1 }", Ġcover Art Code 1 , Ġartist Name 1 , Ġalbum Name 1 , Ġtrack Name 1 , Ġnull , Ġfalse , Ġfalse ) Ċĉ ĉ assertEquals ( metadata 1 , Ġartist Top S ongs [ 0 ]) ĊĊĉ ĉ val Ġmetadata 2 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : track :${ uri Id 2 }", Ġcover Art Code 2 , Ġartist Name 2 , Ġalbum Name 2 , Ġtrack Name 2 , Ġnull , Ġfalse , Ġfalse ) Ċĉ ĉ assertEquals ( metadata 2 , Ġartist Top S ongs [ 1 ]) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet Artist Top S ongs _ Authentication Exception () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġartist Uri Ġ= Ġ" artist Uri " Ċĉ ĉ val Ġexception Ġ= ĠSpotify Exception . Authentication Exception (" message ") Ċĉ ĉ val Ġartist Api : ĠArtist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( artist Api . get Artist Top Tracks ( artist Uri )). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . artists ). thenReturn ( artist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ do Nothing (). wh enever ( spotify Auth StateManager ). add AccessToken Authorization Exception ( exception ) ĊĊĉ ĉ val Ġnotification Manager : ĠNotification Manager Ġ= Ġmock () Ċĉ ĉ wh enever ( context . getSystem Service ( Notification Manager :: class . java )). thenReturn ( notification Manager ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġartist Top S ongs Ġ= Ġspot ify WebApi . get Artist Top S ongs ( spotify App Controller , Ġartist Uri ) ĊĊĉ ĉ verify ( notification Manager , Ġnever ()). notify ( any (), Ġany ()) ĊĊĉ ĉ assertEquals ( null , Ġartist Top S ongs ) Ċĉ ĉ val Ġinternal WebApi : ĠSpotify Client Api ? Ġ= ĠWhite box . get Internal State ( spotify WebApi , Ġ" web Api ") Ċĉ ĉ assertNull ( internal WebApi ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet Artist Top S ongs _ Spot ify Exception () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġartist Uri Ġ= Ġ" artist Uri " Ċĉ ĉ val Ġexception Ġ= ĠSpotify Exception . BadRequest Exception (" message ") Ċĉ ĉ val Ġartist Api : ĠArtist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( artist Api . get Artist Top Tracks ( artist Uri )). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . artists ). thenReturn ( artist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġartist Top S ongs Ġ= Ġspot ify WebApi . get Artist Top S ongs ( spotify App Controller , Ġartist Uri ) ĊĊĉ ĉ assertEquals ( null , Ġartist Top S ongs ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Is Authorized () Ġ{ Ċĉ ĉ wh enever ( spotify Auth StateManager . is Authorized ()). thenReturn ( true ) ĊĊĉ ĉ assertEquals ( true , Ġspot ify WebApi . is Authorized ()) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Clear Pending Queue Metadata Create () Ġ{ Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" pending Queue Metadata Create "), Ġ{ Ġfail () Ġ}) ĊĊĉ ĉ spotify WebApi . clear Pending Queue Metadata Create () ĊĊĉ ĉ val Ġinternal Pending Queue Metadata Create : Ġ(() Ġ-> ĠUnit )? Ġ= ĠWhite box . get Internal State ( spotify WebApi , Ġ" pending Queue Metadata Create ") Ċĉ ĉ assertNull ( internal Pending Queue Metadata Create ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Search For Query _ Null WebApi () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġsearch Results Ġ= Ġspot ify WebApi . search For Query ( mock (), Ġ"") ĊĊĉ ĉ assertEquals ( emptyList < Spot ify Music Metadata >(), Ġsearch Results ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Search For Query _ Album Results () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġquery Ġ= Ġ" query " ĊĊĉ ĉ val Ġuri Id 1 Ġ= Ġ" uri Id 1 " Ċĉ ĉ val Ġartist Name 1 Ġ= Ġ" Artist Ġ 1 " Ċĉ ĉ val Ġalbum Name 1 Ġ= Ġ" Album Ġ 1 " Ċĉ ĉ val Ġcover Art Code 1 Ġ= Ġ"/ cover Art Code 1 " ĊĊĉ ĉ val Ġuri Id 2 Ġ= Ġ" uri Id 2 " Ċĉ ĉ val Ġartist Name 2 Ġ= Ġ" Artist Ġ 2 " Ċĉ ĉ val Ġalbum Name 2 Ġ= Ġ" Album Ġ 2 " Ċĉ ĉ val Ġcover Art Code 2 Ġ= Ġ"/ cover Art Code 2 " ĊĊĉ ĉ val Ġalbum 1 Ġ= Ġcreate Simple Album ( uri Id 1 , Ġartist Name 1 , Ġalbum Name 1 , Ġcover Art Code 1 ) Ċĉ ĉ val Ġalbum 2 Ġ= Ġcreate Simple Album ( uri Id 2 , Ġartist Name 2 , Ġalbum Name 2 , Ġcover Art Code 2 ) ĊĊĉ ĉ val Ġpaging Object : ĠP aging Object < Simple Album > Ġ= Ġmock () Ċĉ ĉ wh enever ( paging Object . items ). thenReturn ( listOf ( album 1 , Ġalbum 2 )) ĊĊĉ ĉ val Ġspot ify SearchResult : ĠSpotify SearchResult Ġ= Ġmock () Ċĉ ĉ wh enever ( spotify SearchResult . albums ). do Answer Ġ{ Ġpaging Object Ġ} ĊĊĉ ĉ val Ġclient Search Api : ĠSearch Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Search Api . search ( query , Ġ* Search Api . Search Type . values (), Ġlimit = 8 )). do Answer Ġ{ Ġspot ify SearchResult Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . search ). thenReturn ( client Search Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġsearch Results Ġ= Ġspot ify WebApi . search For Query ( spotify App Controller , Ġquery ) ĊĊĉ ĉ assertNotNull ( search Results ) Ċĉ ĉ assertEquals ( 2 , Ġsearch Results !!. size ) Ċĉ ĉ val Ġmetadata 1 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : album :${ uri Id 1 }", Ġcover Art Code 1 , Ġartist Name 1 , Ġalbum Name 1 , Ġalbum Name 1 , Ġ" Album ", Ġtrue , Ġfalse ) Ċĉ ĉ assertEquals ( metadata 1 , Ġsearch Results [ 0 ]) Ċĉ ĉ val Ġmetadata 2 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : album :${ uri Id 2 }", Ġcover Art Code 2 , Ġartist Name 2 , Ġalbum Name 2 , Ġalbum Name 2 , Ġ" Album ", Ġtrue , Ġfalse ) Ċĉ ĉ assertEquals ( metadata 2 , Ġsearch Results [ 1 ]) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Search For Query _ Song Results () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġquery Ġ= Ġ" query " ĊĊĉ ĉ val Ġuri Id 1 Ġ= Ġ" uri Id 1 " Ċĉ ĉ val Ġalbum Uri Id 1 Ġ= Ġ" album Uri Id 1 " Ċĉ ĉ val Ġartist Name 1 Ġ= Ġ" Artist Ġ 1 " Ċĉ ĉ val Ġtrack Name 1 Ġ= Ġ" Track Ġ 1 " Ċĉ ĉ val Ġcover Art Code 1 Ġ= Ġ"/ cover Art Code 1 " Ċĉ ĉ val Ġalbum Name 1 Ġ= Ġ" Album Ġ 1 " ĊĊĉ ĉ val Ġuri Id 2 Ġ= Ġ" uri Id 2 " Ċĉ ĉ val Ġalbum Uri Id 2 Ġ= Ġ" album Uri Id 2 " Ċĉ ĉ val Ġartist Name 2 Ġ= Ġ" Artist Ġ 2 " Ċĉ ĉ val Ġtrack Name 2 Ġ= Ġ" Track Ġ 2 " Ċĉ ĉ val Ġcover Art Code 2 Ġ= Ġ"/ cover Art Code 2 " Ċĉ ĉ val Ġalbum Name 2 Ġ= Ġ" Album Ġ 2 " ĊĊĉ ĉ val Ġtrack 1 Ġ= Ġcreate Track ( uri Id 1 , Ġalbum Uri Id 1 , Ġcover Art Code 1 , Ġartist Name 1 , Ġtrack Name 1 , Ġalbum Name 1 ) Ċĉ ĉ val Ġtrack 2 Ġ= Ġcreate Track ( uri Id 2 , Ġalbum Uri Id 2 , Ġcover Art Code 2 , Ġartist Name 2 , Ġtrack Name 2 , Ġalbum Name 2 ) ĊĊĉ ĉ val Ġpaging Object : ĠP aging Object < Track > Ġ= Ġmock () Ċĉ ĉ wh enever ( paging Object . items ). thenReturn ( listOf ( track 1 , Ġtrack 2 )) ĊĊĉ ĉ val Ġspot ify SearchResult : ĠSpotify SearchResult Ġ= Ġmock () Ċĉ ĉ wh enever ( spotify SearchResult . tracks ). do Answer Ġ{ Ġpaging Object Ġ} ĊĊĉ ĉ val Ġclient Search Api : ĠSearch Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Search Api . search ( query , Ġ* Search Api . Search Type . values (), Ġlimit = 8 )). do Answer Ġ{ Ġspot ify SearchResult Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . search ). thenReturn ( client Search Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġsearch Results Ġ= Ġspot ify WebApi . search For Query ( spotify App Controller , Ġquery ) ĊĊĉ ĉ assertNotNull ( search Results ) Ċĉ ĉ assertEquals ( 2 , Ġsearch Results !!. size ) Ċĉ ĉ val Ġmetadata 1 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : track :${ uri Id 1 }", Ġcover Art Code 1 , Ġartist Name 1 , Ġ" spotify : album :${ album Uri Id 1 }", Ġtrack Name 1 , Ġ" Track ", Ġtrue , Ġfalse ) Ċĉ ĉ assertEquals ( metadata 1 , Ġsearch Results [ 0 ]) Ċĉ ĉ val Ġmetadata 2 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : track :${ uri Id 2 }", Ġcover Art Code 2 , Ġartist Name 2 , Ġ" spotify : album :${ album Uri Id 2 }", Ġtrack Name 2 , Ġ" Track ", Ġtrue , Ġfalse ) Ċĉ ĉ assertEquals ( metadata 2 , Ġsearch Results [ 1 ]) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Search For Query _ Artist Results () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġquery Ġ= Ġ" query " ĊĊĉ ĉ val Ġuri Id 1 Ġ= Ġ" uri Id 1 " Ċĉ ĉ val Ġartist Name 1 Ġ= Ġ" Artist Ġ 1 " Ċĉ ĉ val Ġcover Art Code 1 Ġ= Ġ"/ cover Art Code 1 " ĊĊĉ ĉ val Ġuri Id 2 Ġ= Ġ" uri Id 2 " Ċĉ ĉ val Ġartist Name 2 Ġ= Ġ" Artist Ġ 2 " Ċĉ ĉ val Ġcover Art Code 2 Ġ= Ġ"/ cover Art Code 2 " ĊĊĉ ĉ val Ġartist 1 Ġ= Ġcreate Artist ( uri Id 1 , Ġcover Art Code 1 , Ġartist Name 1 ) Ċĉ ĉ val Ġartist 2 Ġ= Ġcreate Artist ( uri Id 2 , Ġcover Art Code 2 , Ġartist Name 2 ) ĊĊĉ ĉ val Ġpaging Object : ĠP aging Object < Artist > Ġ= Ġmock () Ċĉ ĉ wh enever ( paging Object . items ). thenReturn ( listOf ( artist 1 , Ġartist 2 )) ĊĊĉ ĉ val Ġspot ify SearchResult : ĠSpotify SearchResult Ġ= Ġmock () Ċĉ ĉ wh enever ( spotify SearchResult . artists ). do Answer Ġ{ Ġpaging Object Ġ} ĊĊĉ ĉ val Ġclient Search Api : ĠSearch Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Search Api . search ( query , Ġ* Search Api . Search Type . values (), Ġlimit = 8 )). do Answer Ġ{ Ġspot ify SearchResult Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . search ). thenReturn ( client Search Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġsearch Results Ġ= Ġspot ify WebApi . search For Query ( spotify App Controller , Ġquery ) ĊĊĉ ĉ assertNotNull ( search Results ) Ċĉ ĉ assertEquals ( 2 , Ġsearch Results !!. size ) Ċĉ ĉ val Ġmetadata 1 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : artist :${ uri Id 1 }", Ġcover Art Code 1 , Ġartist Name 1 , Ġnull , Ġartist Name 1 , Ġ" Artist ", Ġfalse , Ġtrue ) Ċĉ ĉ assertEquals ( metadata 1 , Ġsearch Results [ 0 ]) Ċĉ ĉ val Ġmetadata 2 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : artist :${ uri Id 2 }", Ġcover Art Code 2 , Ġartist Name 2 , Ġnull , Ġartist Name 2 , Ġ" Artist ", Ġfalse , Ġtrue ) Ċĉ ĉ assertEquals ( metadata 2 , Ġsearch Results [ 1 ]) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Search For Query _ Show Results () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġquery Ġ= Ġ" query " ĊĊĉ ĉ val Ġuri Id 1 Ġ= Ġ" uri Id 1 " Ċĉ ĉ val Ġshow Name 1 Ġ= Ġ" Show Ġ 1 " Ċĉ ĉ val Ġpublisher Name 1 Ġ= Ġ" Publisher Ġ 1 " Ċĉ ĉ val Ġcover Art Code 1 Ġ= Ġ"/ cover Art Code 1 " ĊĊĉ ĉ val Ġuri Id 2 Ġ= Ġ" uri Id 2 " Ċĉ ĉ val Ġshow Name 2 Ġ= Ġ" Show Ġ 2 " Ċĉ ĉ val Ġpublisher Name 2 Ġ= Ġ" Publisher Ġ 2 " Ċĉ ĉ val Ġcover Art Code 2 Ġ= Ġ"/ cover Art Code 2 " ĊĊĉ ĉ val Ġshow 1 Ġ= Ġcreate Simple Show ( uri Id 1 , Ġshow Name 1 , Ġpublisher Name 1 , Ġcover Art Code 1 ) Ċĉ ĉ val Ġshow 2 Ġ= Ġcreate Simple Show ( uri Id 2 , Ġshow Name 2 , Ġpublisher Name 2 , Ġcover Art Code 2 ) ĊĊĉ ĉ val Ġpaging Object : ĠNullable Paging Object < Simple Show > Ġ= Ġmock () Ċĉ ĉ wh enever ( paging Object . items ). thenReturn ( listOf ( show 1 , Ġshow 2 )) ĊĊĉ ĉ val Ġspot ify SearchResult : ĠSpotify SearchResult Ġ= Ġmock () Ċĉ ĉ wh enever ( spotify SearchResult . shows ). do Answer Ġ{ Ġpaging Object Ġ} ĊĊĉ ĉ val Ġclient Search Api : ĠSearch Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Search Api . search ( query , Ġ* Search Api . Search Type . values (), Ġlimit = 8 )). do Answer Ġ{ Ġspot ify SearchResult Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . search ). thenReturn ( client Search Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġsearch Results Ġ= Ġspot ify WebApi . search For Query ( spotify App Controller , Ġquery ) ĊĊĉ ĉ assertNotNull ( search Results ) Ċĉ ĉ assertEquals ( 2 , Ġsearch Results !!. size ) Ċĉ ĉ val Ġmetadata 1 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : show :${ uri Id 1 }", Ġcover Art Code 1 , Ġpublisher Name 1 , Ġnull , Ġshow Name 1 , Ġ" Show ", Ġfalse , Ġtrue ) Ċĉ ĉ assertEquals ( metadata 1 , Ġsearch Results [ 0 ]) Ċĉ ĉ val Ġmetadata 2 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : show :${ uri Id 2 }", Ġcover Art Code 2 , Ġpublisher Name 2 , Ġnull , Ġshow Name 2 , Ġ" Show ", Ġfalse , Ġtrue ) Ċĉ ĉ assertEquals ( metadata 2 , Ġsearch Results [ 1 ]) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Search For Query _ Episode Results () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġquery Ġ= Ġ" query " ĊĊĉ ĉ val Ġuri Id 1 Ġ= Ġ" uri Id 1 " Ċĉ ĉ val Ġepisode Name 1 Ġ= Ġ" Episode Ġ 1 " Ċĉ ĉ val Ġcover Art Code 1 Ġ= Ġ"/ cover Art Code 1 " ĊĊĉ ĉ val Ġuri Id 2 Ġ= Ġ" uri Id 2 " Ċĉ ĉ val Ġepisode Name 2 Ġ= Ġ" Episode Ġ 2 " Ċĉ ĉ val Ġcover Art Code 2 Ġ= Ġ"/ cover Art Code 2 " ĊĊĉ ĉ val Ġepisode 1 Ġ= Ġcreate Simple Episode ( uri Id 1 , Ġepisode Name 1 , Ġcover Art Code 1 ) Ċĉ ĉ val Ġepisode 2 Ġ= Ġcreate Simple Episode ( uri Id 2 , Ġepisode Name 2 , Ġcover Art Code 2 ) ĊĊĉ ĉ val Ġpaging Object : ĠNullable Paging Object < Simple Episode > Ġ= Ġmock () Ċĉ ĉ wh enever ( paging Object . items ). thenReturn ( listOf ( episode 1 , Ġepisode 2 )) ĊĊĉ ĉ val Ġspot ify SearchResult : ĠSpotify SearchResult Ġ= Ġmock () Ċĉ ĉ wh enever ( spotify SearchResult . episodes ). do Answer Ġ{ Ġpaging Object Ġ} ĊĊĉ ĉ val Ġclient Search Api : ĠSearch Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Search Api . search ( query , Ġ* Search Api . Search Type . values (), Ġlimit = 8 )). do Answer Ġ{ Ġspot ify SearchResult Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . search ). thenReturn ( client Search Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġsearch Results Ġ= Ġspot ify WebApi . search For Query ( spotify App Controller , Ġquery ) ĊĊĉ ĉ assertNotNull ( search Results ) Ċĉ ĉ assertEquals ( 2 , Ġsearch Results !!. size ) Ċĉ ĉ val Ġmetadata 1 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : episode :${ uri Id 1 }", Ġcover Art Code 1 , Ġnull , Ġnull , Ġepisode Name 1 , Ġ" Episode ", Ġtrue , Ġfalse ) Ċĉ ĉ assertEquals ( metadata 1 , Ġsearch Results [ 0 ]) Ċĉ ĉ val Ġmetadata 2 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : episode :${ uri Id 2 }", Ġcover Art Code 2 , Ġnull , Ġnull , Ġepisode Name 2 , Ġ" Episode ", Ġtrue , Ġfalse ) Ċĉ ĉ assertEquals ( metadata 2 , Ġsearch Results [ 1 ]) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Search For Query _ No Results () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġquery Ġ= Ġ" query " ĊĊĉ ĉ val Ġspot ify SearchResult : ĠSpotify SearchResult Ġ= Ġmock () ĊĊĉ ĉ val Ġclient Search Api : ĠSearch Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Search Api . search ( query , Ġ* Search Api . Search Type . values (), Ġlimit = 8 )). do Answer Ġ{ Ġspot ify SearchResult Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . search ). thenReturn ( client Search Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġsearch Results Ġ= Ġspot ify WebApi . search For Query ( spotify App Controller , Ġquery ) ĊĊĉ ĉ assertNotNull ( search Results ) Ċĉ ĉ assertTrue ( search Results !!. isEmpty ()) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Search For Query _ OneOf Each Result () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġquery Ġ= Ġ" query " ĊĊĉ ĉ val Ġalbum Uri Id Ġ= Ġ" album Uri Id " Ċĉ ĉ val Ġalbum Artist Name Ġ= Ġ" album ĠArtist " Ċĉ ĉ val Ġalbum Name Ġ= Ġ" album ĠAlbum " Ċĉ ĉ val Ġalbum Cover Art Code Ġ= Ġ"/ album Cover Art Code " Ċĉ ĉ val Ġalbum Ġ= Ġcreate Simple Album ( album Uri Id , Ġalbum Artist Name , Ġalbum Name , Ġalbum Cover Art Code ) Ċĉ ĉ val Ġalbum Paging Object : ĠP aging Object < Simple Album > Ġ= Ġmock () Ċĉ ĉ wh enever ( album Paging Object . items ). thenReturn ( listOf ( album )) ĊĊĉ ĉ val Ġtrack Uri Id Ġ= Ġ" track Uri Id 1 " Ċĉ ĉ val Ġtrack Album Uri Id Ġ= Ġ" track Album Uri Id " Ċĉ ĉ val Ġtrack Artist Name Ġ= Ġ" track ĠArtist Ġ 1 " Ċĉ ĉ val Ġtrack Name Ġ= Ġ" track ĠTrack Ġ 1 " Ċĉ ĉ val Ġtrack Cover Art Code Ġ= Ġ"/ track Cover Art Code " Ċĉ ĉ val Ġtrack Ġ= Ġcreate Track ( track Uri Id , Ġtrack Album Uri Id , Ġtrack Cover Art Code , Ġtrack Artist Name , Ġtrack Name , Ġalbum Name ) Ċĉ ĉ val Ġtrack Paging Object : ĠP aging Object < Track > Ġ= Ġmock () Ċĉ ĉ wh enever ( track Paging Object . items ). thenReturn ( listOf ( track )) ĊĊĉ ĉ val Ġartist Uri Id Ġ= Ġ" artist Uri Id " Ċĉ ĉ val Ġartist Name Ġ= Ġ" artist ĠArtist Ġ 1 " Ċĉ ĉ val Ġartist Cover Art Code Ġ= Ġ"/ artist Cover Art Code " Ċĉ ĉ val Ġartist Ġ= Ġcreate Artist ( artist Uri Id , Ġartist Cover Art Code , Ġartist Name ) Ċĉ ĉ val Ġartist Paging Object : ĠP aging Object < Artist > Ġ= Ġmock () Ċĉ ĉ wh enever ( artist Paging Object . items ). thenReturn ( listOf ( artist )) ĊĊĉ ĉ val Ġshow Uri Id Ġ= Ġ" show Uri Id " Ċĉ ĉ val Ġshow Name Ġ= Ġ" Show Ġ 1 " Ċĉ ĉ val Ġshow Publisher Name Ġ= Ġ" Publisher Ġ 1 " Ċĉ ĉ val Ġshow Cover Art Code Ġ= Ġ"/ show Cover Art Code " Ċĉ ĉ val Ġshow Ġ= Ġcreate Simple Show ( show Uri Id , Ġshow Name , Ġshow Publisher Name , Ġshow Cover Art Code ) Ċĉ ĉ val Ġshow Paging Object : ĠNullable Paging Object < Simple Show > Ġ= Ġmock () Ċĉ ĉ wh enever ( show Paging Object . items ). thenReturn ( listOf ( show )) ĊĊĉ ĉ val Ġepisode Uri Id Ġ= Ġ" episode Uri Id " Ċĉ ĉ val Ġepisode Name Ġ= Ġ" Episode Ġ 1 " Ċĉ ĉ val Ġepisode Cover Art Code Ġ= Ġ"/ episode Cover Art Code " Ċĉ ĉ val Ġepisode Ġ= Ġcreate Simple Episode ( episode Uri Id , Ġepisode Name , Ġepisode Cover Art Code ) Ċĉ ĉ val Ġepisode Paging Object : ĠNullable Paging Object < Simple Episode > Ġ= Ġmock () Ċĉ ĉ wh enever ( episode Paging Object . items ). thenReturn ( listOf ( episode )) ĊĊĉ ĉ val Ġspot ify SearchResult : ĠSpotify SearchResult Ġ= Ġmock () Ċĉ ĉ wh enever ( spotify SearchResult . albums ). do Answer Ġ{ Ġalbum Paging Object Ġ} Ċĉ ĉ wh enever ( spotify SearchResult . tracks ). do Answer Ġ{ Ġtrack Paging Object Ġ} Ċĉ ĉ wh enever ( spotify SearchResult . artists ). do Answer Ġ{ Ġartist Paging Object Ġ} Ċĉ ĉ wh enever ( spotify SearchResult . shows ). do Answer Ġ{ Ġshow Paging Object Ġ} Ċĉ ĉ wh enever ( spotify SearchResult . episodes ). do Answer Ġ{ Ġepisode Paging Object Ġ} ĊĊĉ ĉ val Ġclient Search Api : ĠSearch Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Search Api . search ( query , Ġ* Search Api . Search Type . values (), Ġlimit = 8 )). do Answer Ġ{ Ġspot ify SearchResult Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . search ). thenReturn ( client Search Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġsearch Results Ġ= Ġspot ify WebApi . search For Query ( spotify App Controller , Ġquery ) ĊĊĉ ĉ assertNotNull ( search Results ) Ċĉ ĉ assertEquals ( 5 , Ġsearch Results !!. size ) Ċĉ ĉ val Ġmetadata 1 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : album :${ album Uri Id }", Ġalbum Cover Art Code , Ġalbum Artist Name , Ġalbum Name , Ġalbum Name , Ġ" Album ", Ġtrue , Ġfalse ) Ċĉ ĉ assertEquals ( metadata 1 , Ġsearch Results [ 0 ]) Ċĉ ĉ val Ġmetadata 2 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : track :${ track Uri Id }", Ġtrack Cover Art Code , Ġtrack Artist Name , Ġ" spotify : album :${ track Album Uri Id }", Ġtrack Name , Ġ" Track ", Ġtrue , Ġfalse ) Ċĉ ĉ assertEquals ( metadata 2 , Ġsearch Results [ 1 ]) Ċĉ ĉ val Ġmetadata 3 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : artist :${ artist Uri Id }", Ġartist Cover Art Code , Ġartist Name , Ġnull , Ġartist Name , Ġ" Artist ", Ġfalse , Ġtrue ) Ċĉ ĉ assertEquals ( metadata 3 , Ġsearch Results [ 2 ]) Ċĉ ĉ val Ġmetadata 4 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : show :${ show Uri Id }", Ġshow Cover Art Code , Ġshow Publisher Name , Ġnull , Ġshow Name , Ġ" Show ", Ġfalse , Ġtrue ) Ċĉ ĉ assertEquals ( metadata 4 , Ġsearch Results [ 3 ]) Ċĉ ĉ val Ġmetadata 5 Ġ= Ġcreate Spot ify Music Metadata ( spotify App Controller , Ġ" spotify : episode :${ episode Uri Id }", Ġepisode Cover Art Code , Ġnull , Ġnull , Ġepisode Name , Ġ" Episode ", Ġtrue , Ġfalse ) Ċĉ ĉ assertEquals ( metadata 5 , Ġsearch Results [ 4 ]) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Search For Query _ Authentication Exception () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġquery Ġ= Ġ" query " ĊĊĉ ĉ val Ġexception Ġ= ĠSpotify Exception . Authentication Exception (" message ") ĊĊĉ ĉ val Ġclient Search Api : ĠSearch Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Search Api . search ( query , Ġ* Search Api . Search Type . values (), Ġlimit = 8 )). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . search ). thenReturn ( client Search Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ do Nothing (). wh enever ( spotify Auth StateManager ). add AccessToken Authorization Exception ( exception ) ĊĊĉ ĉ val Ġnotification Manager : ĠNotification Manager Ġ= Ġmock () Ċĉ ĉ wh enever ( context . getSystem Service ( Notification Manager :: class . java )). thenReturn ( notification Manager ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġsearch Results Ġ= Ġspot ify WebApi . search For Query ( spotify App Controller , Ġquery ) ĊĊĉ ĉ assertNull ( search Results ) ĊĊĉ ĉ val Ġinternal WebApi : ĠSpotify Client Api ? Ġ= ĠWhite box . get Internal State ( spotify WebApi , Ġ" web Api ") Ċĉ ĉ assertNull ( internal WebApi ) ĊĊĉ ĉ verify ( spotify Auth StateManager ). add AccessToken Authorization Exception ( exception ) Ċĉ ĉ verify ( notification Manager , Ġnever ()). notify ( any (), Ġany ()) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Search For Query _ Spot ify Exception () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġquery Ġ= Ġ" query " ĊĊĉ ĉ val Ġexception Ġ= ĠSpotify Exception . BadRequest Exception (" message ") ĊĊĉ ĉ val Ġclient Search Api : ĠSearch Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Search Api . search ( query , Ġ* Search Api . Search Type . values (), Ġlimit = 8 )). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . search ). thenReturn ( client Search Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġspot ify App Controller : ĠSpotify App Controller Ġ= Ġmock () Ċĉ ĉ val Ġsearch Results Ġ= Ġspot ify WebApi . search For Query ( spotify App Controller , Ġquery ) ĊĊĉ ĉ assertNull ( search Results ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Create Playlist () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Name Ġ= Ġ" playlist Name " Ċĉ ĉ val Ġplaylist Uri : ĠPlaylist Uri Ġ= Ġmock () Ċĉ ĉ val Ġplaylist : ĠPlaylist Ġ= Ġmock () Ċĉ ĉ wh enever ( playlist . uri ) Ġdo Answer Ġ{ Ġplaylist Uri Ġ} ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . create Client Playlist ( name Ġ= Ġplaylist Name , Ġdescription Ġ= Ġnull , Ġpublic Ġ= Ġfalse )). do Answer Ġ{ Ġplaylist Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġplaylist Create Result Ġ= Ġspot ify WebApi . create Playlist ( playlist Name ) ĊĊĉ ĉ assertEquals ( playlist Create Result , Ġplaylist Uri ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Create Playlist _ Authentication Exception () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Name Ġ= Ġ" playlist Name " ĊĊĉ ĉ val Ġexception Ġ= ĠSpotify Exception . Authentication Exception (" message ") Ċĉ ĉ do Nothing (). wh enever ( spotify Auth StateManager ). add AccessToken Authorization Exception ( exception ) ĊĊĉ ĉ val Ġnotification Manager : ĠNotification Manager Ġ= Ġmock () Ċĉ ĉ wh enever ( context . getSystem Service ( Notification Manager :: class . java )). thenReturn ( notification Manager ) ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . create Client Playlist ( name Ġ= Ġplaylist Name , Ġdescription Ġ= Ġnull , Ġpublic Ġ= Ġfalse )). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġplaylist Create Result Ġ= Ġspot ify WebApi . create Playlist ( playlist Name ) ĊĊĉ ĉ val Ġinternal WebApi : ĠSpotify Client Api ? Ġ= ĠWhite box . get Internal State ( spotify WebApi , Ġ" web Api ") Ċĉ ĉ assertNull ( internal WebApi ) Ċĉ ĉ assertNull ( playlist Create Result ) ĊĊĉ ĉ verify ( notification Manager , Ġnever ()). notify ( any (), Ġany ()) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Create Playlist _ Spot ify Exception () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Name Ġ= Ġ" playlist Name " ĊĊĉ ĉ val Ġexception Ġ= ĠSpotify Exception . BadRequest Exception (" message ") ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . create Client Playlist ( name Ġ= Ġplaylist Name , Ġdescription Ġ= Ġnull , Ġpublic Ġ= Ġfalse )). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġplaylist Create Result Ġ= Ġspot ify WebApi . create Playlist ( playlist Name ) ĊĊĉ ĉ assertNull ( playlist Create Result ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Add S ongsTo Playlist () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Id Ġ= Ġ" playlist Id " Ċĉ ĉ val Ġsongs Ġ= ĠlistOf ( Ċĉĉĉ ĉ Music Metadata (" media Id 1 ", Ġ 1 , Ġtrue , Ġfalse , Ġ 5 , Ġnull , Ġ" cover Art Uri 1 ", Ġnull , Ġ" Artist Ġ 1 ", Ġ" Album Ġ 1 ", Ġ" Title Ġ 1 "), Ċĉĉĉ ĉ Music Metadata (" media Id 2 ", Ġ 2 , Ġtrue , Ġfalse , Ġ 3 , Ġnull ," cover Art Uri 2 ", Ġnull , Ġ" Artist Ġ 2 ", Ġ" Album Ġ 2 ", Ġ" Title Ġ 2 ") Ċĉ ĉ ) ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . add Play ables To Client Playlist ( playlist Id , ĠPlay able Uri ( songs [ 0 ]. media Id !! ), ĠPlay able Uri ( songs [ 1 ]. media Id !! ))). do Answer Ġ{ Ġ Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ spotify WebApi . add S ongsTo Playlist ( playlist Id , Ġsongs ) ĊĊĉ ĉ verify ( client Playlist Api ). add Play ables To Client Playlist ( playlist Id , ĠPlay able Uri ( songs [ 0 ]. media Id !! ), ĠPlay able Uri ( songs [ 1 ]. media Id !! )) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Add S ongsTo Playlist _ Authentication Exception () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Id Ġ= Ġ" playlist Id " Ċĉ ĉ val Ġsongs Ġ= ĠlistOf ( Ċĉĉĉ ĉ Music Metadata (" media Id 1 ", Ġ 1 , Ġtrue , Ġfalse , Ġ 5 , Ġnull , Ġ" cover Art Uri 1 ", Ġnull , Ġ" Artist Ġ 1 ", Ġ" Album Ġ 1 ", Ġ" Title Ġ 1 "), Ċĉĉĉ ĉ Music Metadata (" media Id 2 ", Ġ 2 , Ġtrue , Ġfalse , Ġ 3 , Ġnull ," cover Art Uri 2 ", Ġnull , Ġ" Artist Ġ 2 ", Ġ" Album Ġ 2 ", Ġ" Title Ġ 2 ") Ċĉ ĉ ) ĊĊĉ ĉ val Ġexception Ġ= ĠSpotify Exception . Authentication Exception (" message ") Ċĉ ĉ do Nothing (). wh enever ( spotify Auth StateManager ). add AccessToken Authorization Exception ( exception ) ĊĊĉ ĉ val Ġnotification Manager : ĠNotification Manager Ġ= Ġmock () Ċĉ ĉ wh enever ( context . getSystem Service ( Notification Manager :: class . java )). thenReturn ( notification Manager ) ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . add Play ables To Client Playlist ( playlist Id , ĠPlay able Uri ( songs [ 0 ]. media Id !! ), ĠPlay able Uri ( songs [ 1 ]. media Id !! ))). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ spotify WebApi . add S ongsTo Playlist ( playlist Id , Ġsongs ) ĊĊĉ ĉ val Ġinternal WebApi : ĠSpotify Client Api ? Ġ= ĠWhite box . get Internal State ( spotify WebApi , Ġ" web Api ") Ċĉ ĉ assertNull ( internal WebApi ) ĊĊĉ ĉ verify ( client Playlist Api ). add Play ables To Client Playlist ( playlist Id , ĠPlay able Uri ( songs [ 0 ]. media Id !! ), ĠPlay able Uri ( songs [ 1 ]. media Id !! )) Ċĉ ĉ verify ( notification Manager , Ġnever ()). notify ( any (), Ġany ()) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Add S ongsTo Playlist _ Spot ify Exception () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Id Ġ= Ġ" playlist Id " Ċĉ ĉ val Ġsongs Ġ= ĠlistOf ( Ċĉĉĉ ĉ Music Metadata (" media Id 1 ", Ġ 1 , Ġtrue , Ġfalse , Ġ 5 , Ġnull , Ġ" cover Art Uri 1 ", Ġnull , Ġ" Artist Ġ 1 ", Ġ" Album Ġ 1 ", Ġ" Title Ġ 1 "), Ċĉĉĉ ĉ Music Metadata (" media Id 2 ", Ġ 2 , Ġtrue , Ġfalse , Ġ 3 , Ġnull ," cover Art Uri 2 ", Ġnull , Ġ" Artist Ġ 2 ", Ġ" Album Ġ 2 ", Ġ" Title Ġ 2 ") Ċĉ ĉ ) ĊĊĉ ĉ val Ġexception Ġ= ĠSpotify Exception . BadRequest Exception (" message ") ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . add Play ables To Client Playlist ( playlist Id , ĠPlay able Uri ( songs [ 0 ]. media Id !! ), ĠPlay able Uri ( songs [ 1 ]. media Id !! ))). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ spotify WebApi . add S ongsTo Playlist ( playlist Id , Ġsongs ) ĊĊĉ ĉ verify ( client Playlist Api ). add Play ables To Client Playlist ( playlist Id , ĠPlay able Uri ( songs [ 0 ]. media Id !! ), ĠPlay able Uri ( songs [ 1 ]. media Id !! )) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Replace Playlist S ongs () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Id Ġ= Ġ" playlist Id " Ċĉ ĉ val Ġsongs Ġ= ĠlistOf ( Ċĉĉĉ ĉ Music Metadata (" media Id 1 ", Ġ 1 , Ġtrue , Ġfalse , Ġ 5 , Ġnull , Ġ" cover Art Uri 1 ", Ġnull , Ġ" Artist Ġ 1 ", Ġ" Album Ġ 1 ", Ġ" Title Ġ 1 "), Ċĉĉĉ ĉ Music Metadata (" media Id 2 ", Ġ 2 , Ġtrue , Ġfalse , Ġ 3 , Ġnull ," cover Art Uri 2 ", Ġnull , Ġ" Artist Ġ 2 ", Ġ" Album Ġ 2 ", Ġ" Title Ġ 2 ") Ċĉ ĉ ) ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . replace Client Playlist Play ables ( playlist Id , ĠPlay able Uri ( songs [ 0 ]. media Id !! ), ĠPlay able Uri ( songs [ 1 ]. media Id !! ))). do Answer Ġ{ Ġ Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ spotify WebApi . replace Playlist S ongs ( playlist Id , Ġsongs ) ĊĊĉ ĉ verify ( client Playlist Api ). replace Client Playlist Play ables ( playlist Id , ĠPlay able Uri ( songs [ 0 ]. media Id !! ), ĠPlay able Uri ( songs [ 1 ]. media Id !! )) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Replace Playlist S ongs _ Large NumberOf S ongs () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Id Ġ= Ġ" playlist Id " Ċĉ ĉ val Ġsongs Ġ= Ġ( 0 .. 1 2 0 ). map Ġ{ ĠMusic Metadata (" media Id $ it ", Ġit . to Long (), Ġtrue , Ġfalse , Ġ 2 , Ġnull , Ġ" cover Art Uri $ it ", Ġnull , Ġ" Artist Ġ$ it ", Ġ" Album Ġ$ it ", Ġ" Title Ġ$ it ") Ġ} ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . replace Client Playlist Play ables ( playlist Id )). do Answer Ġ{ Ġ Ġ} Ċĉ ĉ wh enever ( client Playlist Api . add Play ables To Client Playlist ( eq ( playlist Id ), Ġany Var arg (), Ġposition Ġ= Ġis Null ())). do Answer Ġ{ Ġ Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ spotify WebApi . replace Playlist S ongs ( playlist Id , Ġsongs ) ĊĊĉ ĉ verify ( client Playlist Api ). replace Client Playlist Play ables ( playlist Id ) Ċĉ ĉ verify ( client Playlist Api , Ġtimes ( 2 )). add Play ables To Client Playlist ( eq ( playlist Id ), Ġany Var arg (), Ġposition Ġ= Ġis Null ()) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Replace Playlist S ongs _ Authentication Exception () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Id Ġ= Ġ" playlist Id " Ċĉ ĉ val Ġsongs Ġ= ĠlistOf ( Ċĉĉĉ ĉ Music Metadata (" media Id 1 ", Ġ 1 , Ġtrue , Ġfalse , Ġ 5 , Ġnull , Ġ" cover Art Uri 1 ", Ġnull , Ġ" Artist Ġ 1 ", Ġ" Album Ġ 1 ", Ġ" Title Ġ 1 "), Ċĉĉĉ ĉ Music Metadata (" media Id 2 ", Ġ 2 , Ġtrue , Ġfalse , Ġ 3 , Ġnull ," cover Art Uri 2 ", Ġnull , Ġ" Artist Ġ 2 ", Ġ" Album Ġ 2 ", Ġ" Title Ġ 2 ") Ċĉ ĉ ) ĊĊĉ ĉ val Ġexception Ġ= ĠSpotify Exception . Authentication Exception (" message ") Ċĉ ĉ do Nothing (). wh enever ( spotify Auth StateManager ). add AccessToken Authorization Exception ( exception ) ĊĊĉ ĉ val Ġnotification Manager : ĠNotification Manager Ġ= Ġmock () Ċĉ ĉ wh enever ( context . getSystem Service ( Notification Manager :: class . java )). thenReturn ( notification Manager ) ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . replace Client Playlist Play ables ( playlist Id , ĠPlay able Uri ( songs [ 0 ]. media Id !! ), ĠPlay able Uri ( songs [ 1 ]. media Id !! ))). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ spotify WebApi . replace Playlist S ongs ( playlist Id , Ġsongs ) ĊĊĉ ĉ val Ġinternal WebApi : ĠSpotify Client Api ? Ġ= ĠWhite box . get Internal State ( spotify WebApi , Ġ" web Api ") Ċĉ ĉ assertNull ( internal WebApi ) ĊĊĉ ĉ verify ( client Playlist Api ). replace Client Playlist Play ables ( playlist Id , ĠPlay able Uri ( songs [ 0 ]. media Id !! ), ĠPlay able Uri ( songs [ 1 ]. media Id !! )) Ċĉ ĉ verify ( notification Manager , Ġnever ()). notify ( any (), Ġany ()) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Replace Playlist S ongs _ Spot ify Exception () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Id Ġ= Ġ" playlist Id " Ċĉ ĉ val Ġsongs Ġ= ĠlistOf ( Ċĉĉĉ ĉ Music Metadata (" media Id 1 ", Ġ 1 , Ġtrue , Ġfalse , Ġ 5 , Ġnull , Ġ" cover Art Uri 1 ", Ġnull , Ġ" Artist Ġ 1 ", Ġ" Album Ġ 1 ", Ġ" Title Ġ 1 "), Ċĉĉĉ ĉ Music Metadata (" media Id 2 ", Ġ 2 , Ġtrue , Ġfalse , Ġ 3 , Ġnull ," cover Art Uri 2 ", Ġnull , Ġ" Artist Ġ 2 ", Ġ" Album Ġ 2 ", Ġ" Title Ġ 2 ") Ċĉ ĉ ) ĊĊĉ ĉ val Ġexception Ġ= ĠSpotify Exception . BadRequest Exception (" message ") ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . replace Client Playlist Play ables ( playlist Id , ĠPlay able Uri ( songs [ 0 ]. media Id !! ), ĠPlay able Uri ( songs [ 1 ]. media Id !! ))). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ spotify WebApi . replace Playlist S ongs ( playlist Id , Ġsongs ) ĊĊĉ ĉ verify ( client Playlist Api ). replace Client Playlist Play ables ( playlist Id , ĠPlay able Uri ( songs [ 0 ]. media Id !! ), ĠPlay able Uri ( songs [ 1 ]. media Id !! )) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet Playlist Uri _ Matching Playlist () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Name Ġ= Ġ" playlist Name " Ċĉ ĉ val Ġuri Id Ġ= Ġ" uri Id " Ċĉ ĉ val Ġplay lists Ġ= ĠlistOf ( Ċĉĉĉ ĉ create Simple Playlist ( uri Id , Ġplaylist Name ) Ċĉ ĉ ) ĊĊĉ ĉ val Ġpaging Object : ĠP aging Object < Simple Playlist > Ġ= Ġmock () Ċĉ ĉ wh enever ( paging Object . items ). do Answer Ġ{ Ġplay lists Ġ} ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . getClient Play lists ( any (), Ġany ())). do Answer Ġ{ Ġpaging Object Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġplaylist Uri Ġ= Ġspot ify WebApi . get Playlist Uri ( playlist Name ) ĊĊĉ ĉ assertNotNull ( playlist Uri ) Ċĉ ĉ assertEquals ( uri Id , Ġplaylist Uri !!. id ) Ċĉ ĉ assertEquals (" spotify : playlist :${ uri Id }", Ġplaylist Uri . uri ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet Playlist Uri _ Pagination _ Matching Playlist () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Name Ġ= Ġ" playlist Name " Ċĉ ĉ val Ġuri Id Ġ= Ġ" uri Id " Ċĉ ĉ val Ġplay lists Not Containing Match Ġ= ĠlistOf ( Ċĉĉĉ ĉ create Simple Playlist (" bad Uri Id ", Ġ" not Matching ") Ċĉ ĉ ) Ċĉ ĉ val Ġplay lists Containing Match Ġ= ĠlistOf ( Ċĉĉĉ ĉ create Simple Playlist ( uri Id , Ġplaylist Name ) Ċĉ ĉ ) ĊĊĉ ĉ val Ġnext Paging Object : ĠP aging Object < Simple Playlist > Ġ= Ġmock () Ċĉ ĉ wh enever ( next Paging Object . items ). do Answer Ġ{ Ġplay lists Containing Match Ġ} ĊĊĉ ĉ val Ġpaging Object : ĠP aging Object < Simple Playlist > Ġ= Ġmock () Ċĉ ĉ wh enever ( paging Object . items ). do Answer Ġ{ Ġplay lists Not Containing Match Ġ} Ċĉ ĉ wh enever ( paging Object . getNext ()). do Answer Ġ{ Ġnext Paging Object Ġ} ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . getClient Play lists ( any (), Ġany ())). do Answer Ġ{ Ġpaging Object Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġplaylist Uri Ġ= Ġspot ify WebApi . get Playlist Uri ( playlist Name ) ĊĊĉ ĉ assertNotNull ( playlist Uri ) Ċĉ ĉ assertEquals ( uri Id , Ġplaylist Uri !!. id ) Ċĉ ĉ assertEquals (" spotify : playlist :${ uri Id }", Ġplaylist Uri . uri ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet Playlist Uri _ No Matching Playlist () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Name Ġ= Ġ" playlist Name " Ċĉ ĉ val Ġuri Id Ġ= Ġ" uri Id " Ċĉ ĉ val Ġplay lists Ġ= ĠlistOf ( Ċĉĉĉ ĉ create Simple Playlist ( uri Id , Ġplaylist Name ) Ċĉ ĉ ) ĊĊĉ ĉ val Ġpaging Object : ĠP aging Object < Simple Playlist > Ġ= Ġmock () Ċĉ ĉ wh enever ( paging Object . items ). do Answer Ġ{ Ġplay lists Ġ} ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . getClient Play lists ( any (), Ġany ())). do Answer Ġ{ Ġpaging Object Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġplaylist Uri Ġ= Ġspot ify WebApi . get Playlist Uri (" other Ġplaylist ") ĊĊĉ ĉ assertNull ( playlist Uri ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet Playlist Uri _ Pagination _ No Matching Playlist () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist 1 Ġ= ĠlistOf ( Ċĉĉĉ ĉ create Simple Playlist (" uri Id 1 ", Ġ" playlist Name 1 ") Ċĉ ĉ ) Ċĉ ĉ val Ġplaylist 2 Ġ= ĠlistOf ( Ċĉĉĉ ĉ create Simple Playlist (" uri Id 2 ", Ġ" playlist Name 2 ") Ċĉ ĉ ) ĊĊĉ ĉ val Ġnext Paging Object : ĠP aging Object < Simple Playlist > Ġ= Ġmock () Ċĉ ĉ wh enever ( next Paging Object . items ). do Answer Ġ{ Ġplaylist 1 Ġ} ĊĊĉ ĉ val Ġpaging Object : ĠP aging Object < Simple Playlist > Ġ= Ġmock () Ċĉ ĉ wh enever ( paging Object . items ). do Answer Ġ{ Ġplaylist 2 Ġ} Ċĉ ĉ wh enever ( paging Object . getNext ()). do Answer Ġ{ Ġnext Paging Object Ġ} ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . getClient Play lists ( any (), Ġany ())). do Answer Ġ{ Ġpaging Object Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġplaylist Uri Ġ= Ġspot ify WebApi . get Playlist Uri (" other Ġplaylist ") ĊĊĉ ĉ assertNull ( playlist Uri ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet Playlist Uri _ Authentication Exception () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Name Ġ= Ġ" playlist Name " ĊĊĉ ĉ val Ġexception Ġ= ĠSpotify Exception . Authentication Exception (" message ") Ċĉ ĉ do Nothing (). wh enever ( spotify Auth StateManager ). add AccessToken Authorization Exception ( exception ) ĊĊĉ ĉ val Ġnotification Manager : ĠNotification Manager Ġ= Ġmock () Ċĉ ĉ wh enever ( context . getSystem Service ( Notification Manager :: class . java )). thenReturn ( notification Manager ) ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . getClient Play lists ( any (), Ġany ())). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġplaylist Uri Ġ= Ġspot ify WebApi . get Playlist Uri ( playlist Name ) ĊĊĉ ĉ assertNull ( playlist Uri ) ĊĊĉ ĉ val Ġinternal WebApi : ĠSpotify Client Api ? Ġ= ĠWhite box . get Internal State ( spotify WebApi , Ġ" web Api ") Ċĉ ĉ assertNull ( internal WebApi ) ĊĊĉ ĉ verify ( notification Manager , Ġnever ()). notify ( any (), Ġany ()) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet Playlist Uri _ Spot ify Exception () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Name Ġ= Ġ" playlist Name " ĊĊĉ ĉ val Ġexception Ġ= ĠSpotify Exception . BadRequest Exception (" message ") ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . getClient Play lists ( any (), Ġany ())). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ val Ġplaylist Uri Ġ= Ġspot ify WebApi . get Playlist Uri ( playlist Name ) ĊĊĉ ĉ assertNull ( playlist Uri ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Set Playlist Image () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Id Ġ= Ġ" playlist Id " Ċĉ ĉ val Ġcover Art ImageData Ġ= Ġ" cover Art ImageData " ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . upload Client Playlist Cover ( playlist Id , Ġimage Data Ġ= Ġcover Art ImageData )). do Answer Ġ{ Ġ Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ spotify WebApi . set Playlist Image ( playlist Id , Ġcover Art ImageData ) ĊĊĉ ĉ verify ( client Playlist Api ). upload Client Playlist Cover ( playlist Id , Ġimage Data Ġ= Ġcover Art ImageData ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Set Playlist Image _ Authentication Exception () Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Id Ġ= Ġ" playlist Id " Ċĉ ĉ val Ġcover Art ImageData Ġ= Ġ" cover Art ImageData " ĊĊĉ ĉ val Ġexception Ġ= ĠSpotify Exception . Authentication Exception (" message ") Ċĉ ĉ do Nothing (). wh enever ( spotify Auth StateManager ). add AccessToken Authorization Exception ( exception ) ĊĊĉ ĉ val Ġnotification Manager : ĠNotification Manager Ġ= Ġmock () Ċĉ ĉ wh enever ( context . getSystem Service ( Notification Manager :: class . java )). thenReturn ( notification Manager ) ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . upload Client Playlist Cover ( playlist Id , Ġimage Data Ġ= Ġcover Art ImageData )). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ spotify WebApi . set Playlist Image ( playlist Id , Ġcover Art ImageData ) ĊĊĉ ĉ val Ġinternal WebApi : ĠSpotify Client Api ? Ġ= ĠWhite box . get Internal State ( spotify WebApi , Ġ" web Api ") Ċĉ ĉ assertNull ( internal WebApi ) ĊĊĉ ĉ verify ( notification Manager , Ġnever ()). notify ( any (), Ġany ()) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Set Playlist Image _ Spot ify Exception (): ĠUnit Ġ= Ġrun Blocking Ġ{ Ċĉ ĉ val Ġplaylist Id Ġ= Ġ" playlist Id " Ċĉ ĉ val Ġcover Art ImageData Ġ= Ġ" cover Art ImageData " ĊĊĉ ĉ val Ġexception Ġ= ĠSpotify Exception . BadRequest Exception (" message ") ĊĊĉ ĉ val Ġclient Playlist Api : ĠClient Playlist Api Ġ= Ġmock () Ċĉ ĉ wh enever ( client Playlist Api . upload Client Playlist Cover ( playlist Id , Ġimage Data Ġ= Ġcover Art ImageData )). do Answer Ġ{ Ġthrow Ġexception Ġ} ĊĊĉ ĉ val Ġweb Api : ĠSpotify Client Api Ġ= Ġmock () Ċĉ ĉ wh enever ( web Api . play lists ). thenReturn ( client Playlist Api ) Ċĉ ĉ Field Setter . setField ( spotify WebApi , Ġspot ify WebApi :: class . java . getDeclared Field (" web Api "), Ġweb Api ) ĊĊĉ ĉ spotify WebApi . set Playlist Image ( playlist Id , Ġcover Art ImageData ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġcreate Spot ify Music Metadata ( spotify App Controller : ĠSpotify App Controller , Ġuri Id : ĠString , Ġcover Art Code : ĠString ?, Ġartist Name : ĠString ?, Ġalbum Name : ĠString ?, Ġtrack Name : ĠString , Ġsubtitle : ĠString ?, Ġplay able : ĠBoolean , Ġbrowse able : ĠBoolean ): ĠSpotify Music Metadata Ġ{ Ċĉ ĉ val Ġcover Art Uri Ġ= Ġif Ġ( cover Art Code Ġ!= Ġnull ) Ġ{ Ċĉĉ ĉ " spotify : image :${ cover Art Code . drop ( 1 )}" Ċĉ ĉ } Ġelse Ġ{ Ċĉĉ ĉ null Ċĉ ĉ } Ċĉ ĉ return ĠSpotify Music Metadata ( spotify App Controller , Ġuri Id , Ġuri Id . hashCode (). to Long (), Ġcover Art Uri , Ġartist Name , Ġalbum Name , Ġtrack Name , Ġsubtitle , Ġplay able , Ġbrowse able ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġcreate Saved Track ( uri Id : ĠString , Ġtrack Name : ĠString , Ġartist Name : ĠString , Ġalbum Name : ĠString , Ġcover Art Code : ĠString , Ġheight To Match : ĠInt Ġ= Ġ 3 0 0 ): ĠSaved Track Ġ{ Ċĉ ĉ val Ġimages Ġ= ĠlistOf ( Spot ify Image ( height To Match , Ġcover Art Code , Ġ 3 0 0 )) Ċĉ ĉ val Ġartists Ġ= ĠlistOf ( Simple Artist ( empty Map (), Ġ" href ", Ġ" id ", ĠArtist Uri (" artist Uri "), Ġartist Name , Ġ" type ")) Ċĉ ĉ val Ġalbum Ġ= ĠSimple Album (" album ", Ġempty List (), Ġempty Map (), Ġ" href ", Ġ" id ", ĠAlbum Uri (" album Uri "), Ġartists , Ġimages , Ġalbum Name , Ġ" type ", Ġnull , Ġ" 1 9 5 0 ", Ġ" year ") Ċĉ ĉ return Ġ ĉ Saved Track (" value ", ĠTrack ( empty Map (), Ġempty Map (), Ġempty List (), Ġ"", Ġ"", ĠPlay able Uri ( uri Id ), Ġalbum , Ġartists , Ġtrue , Ġ 1 , Ġ 5 , Ġfalse , Ġnull , Ġtrack Name , Ġ 1 , Ġnull , Ġ 1 , Ġ"")) Ċ ĉ } ĊĊ ĉ private Ġfun Ġcreate Simple Album ( uri Id : ĠString , Ġartist Name : ĠString , Ġalbum Name : ĠString , Ġcover Art Code : ĠString ): ĠSimple Album Ġ{ Ċĉ ĉ val Ġimages Ġ= ĠlistOf ( Spot ify Image ( 3 0 0 , Ġcover Art Code , Ġ 3 0 0 )) Ċĉ ĉ val Ġartist Ġ= ĠlistOf ( Simple Artist ( empty Map (), Ġ" href ", Ġ" id ", ĠArtist Uri (" artist Uri "), Ġartist Name , Ġ" artist ")) Ċĉ ĉ return ĠSimple Album (" album ", Ġempty List (), Ġempty Map (), Ġ" href ", Ġ" id ", ĠAlbum Uri ( uri Id ), Ġartist , Ġimages , Ġalbum Name , Ġ" album ", Ġnull , Ġ" 1 9 9 0 ", Ġ" year ") Ċ ĉ } ĊĊ ĉ private Ġfun Ġcreate Track ( uri Id : ĠString , Ġalbum Uri Id : ĠString , Ġcover Art Code : ĠString , Ġartist Name : ĠString , Ġtrack Name : ĠString , Ġalbum Name : ĠString ): ĠTrack Ġ{ Ċĉ ĉ val Ġalbum Ġ= Ġcreate Simple Album ( album Uri Id , Ġ" artist Name ", Ġalbum Name , Ġcover Art Code ) Ċĉ ĉ val Ġartist Ġ= ĠlistOf ( Simple Artist ( empty Map (), Ġ" href ", Ġ" id ", ĠArtist Uri (" artist Uri "), Ġartist Name , Ġ" artist ")) Ċĉ ĉ return ĠTrack ( empty Map (), Ġempty Map (), Ġempty List (), Ġ" href ", Ġ" id ", ĠPlay able Uri ( uri Id ), Ġalbum , Ġartist , Ġtrue , Ġ 0 , Ġ 1 0 0 0 , Ġfalse , Ġnull , Ġtrack Name , Ġ 1 , Ġnull , Ġ 1 , Ġ" track ", Ġnull , Ġnull , Ġnull , Ġnull ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġcreate Artist ( uri Id : ĠString , Ġcover Art Code : ĠString , Ġartist Name : ĠString ): ĠArtist Ġ{ Ċĉ ĉ val Ġimages Ġ= ĠlistOf ( Spot ify Image ( 3 2 0 , Ġcover Art Code , Ġ 3 2 0 )) Ċĉ ĉ return ĠArtist ( empty Map (), Ġ" href ", Ġ" id ", ĠArtist Uri ( uri Id ), Ġmock (), Ġempty List (), Ġimages , Ġartist Name , Ġ 1 , Ġ" artist ") Ċ ĉ } ĊĊ ĉ private Ġfun Ġcreate Simple Show ( uri Id : ĠString , Ġshow Name : ĠString , Ġpublisher Name : ĠString , Ġcover Art Code : ĠString ): ĠSimple Show Ġ{ Ċĉ ĉ val Ġimages Ġ= ĠlistOf ( Spot ify Image ( 3 0 0 , Ġcover Art Code , Ġ 3 0 0 )) Ċĉ ĉ val Ġspot ify Uri : ĠSpotify Uri Ġ= Ġmock () Ċĉ ĉ wh enever ( spotify Uri . uri ). thenReturn (" spotify : show :${ uri Id }") Ċĉ ĉ return ĠSimple Show ( emptyList (), Ġempty Map (), Ġempty List (), Ġ" description ", Ġfalse , Ġ" href ", Ġ" id ", Ġimages , Ġnull , Ġempty List (), Ġ" media Type ", Ġshow Name , Ġpublisher Name , Ġ" show ", Ġspot ify Uri ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġcreate Simple Episode ( uri Id : ĠString , Ġepisode Name : ĠString , Ġcover Art Code : ĠString ): ĠSimple Episode Ġ{ Ċĉ ĉ val Ġimages Ġ= ĠlistOf ( Spot ify Image ( 3 0 0 , Ġcover Art Code , Ġ 3 0 0 )) Ċĉ ĉ val Ġspot ify Uri : ĠSpotify Uri Ġ= Ġmock () Ċĉ ĉ wh enever ( spotify Uri . uri ). thenReturn (" spotify : episode :${ uri Id }") Ċĉ ĉ return ĠSimple Episode ( null , Ġnull , Ġ 1 , Ġfalse , Ġempty Map (), Ġ" href ", Ġ" id ", Ġimages , Ġfalse , Ġtrue , Ġnull , Ġempty List (), Ġepisode Name , Ġ" release Date Str ", Ġ" year ", Ġnull , Ġ" episode ", Ġspot ify Uri ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġcreate Simple Playlist ( uri Id : ĠString , Ġplaylist Name : ĠString ): ĠSimple Playlist Ġ{ Ċĉ ĉ val Ġimages Ġ= ĠlistOf ( Spot ify Image ( 3 0 0 , Ġ" uri ", Ġ 3 0 0 )) Ċĉ ĉ val Ġspot ify Uri : ĠSpotify Uri Ġ= Ġmock () Ċĉ ĉ wh enever ( spotify Uri . uri ). thenReturn (" spotify : playlist :${ uri Id }") Ċĉ ĉ wh enever ( spotify Uri . id ). thenReturn ( uri Id ) Ċĉ ĉ return ĠSimple Playlist ( empty Map (), Ġ" href ", Ġ" id ", Ġspot ify Uri , Ġfalse , Ġimages , Ġplaylist Name , Ġ" description ", Ġmock (), Ġ" color ", Ġfalse , Ġ" snapshot Id ", Ġmock (), Ġ" playlist ") Ċ ĉ } Ċ }