package Ġcom . far mer bb . task bar . service Ċ Ċ import Ġandroid . content . SharedPreferences Ċ import Ġandroid . service . quick settings . Tile Ċ import Ġcom . far mer bb . task bar . Constants . UNSUPPORTED Ċ import Ġcom . far mer bb . task bar . R Ċ import Ġcom . far mer bb . task bar . mockito . Boolean Answer Ċ import Ġcom . far mer bb . task bar . util . Constants Ċ import Ġcom . far mer bb . task bar . util . U Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . power mock . api . mockito . Power Mockito Ċ import Ġorg . power mock . core . class loader . annotations . Power Mock Ignore Ċ import Ġorg . power mock . core . class loader . annotations . Prepare For Test Ċ import Ġorg . power mock . modules . junit 4 . rule . Power Mock Rule Ċ import Ġorg . ro bo lectric . Ro bo lectric Ċ import Ġorg . ro bo lectric . Ro bo lectric TestRunner Ċ import Ġorg . ro bo lectric . Shadow s Ċ Ċ @ RunWith ( Ro bo lectric TestRunner :: class ) Ċ @ Power Mock Ignore (" org . mockito .* ", Ġ" org . ro bo lectric .* ", Ġ" android .* ", Ġ" android x .* ") Ċ @ Prepare For Test ( value Ġ= Ġ[ U :: class ]) Ċ class ĠQuick Settings Tile Service Test Ġ{ ĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġrule Ġ= ĠPower Mock Rule () ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġtile Service : ĠQuick Settings Tile Service ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġprefs : ĠSharedPreferences ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġtile Service Ġ= ĠRo bo lectric . setup Service ( Quick Settings Tile Service :: class . java ) ĊĠĠĠĠĠĠĠ Ġprefs Ġ= ĠU . get SharedPreferences ( tile Service ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Update State For Icon () Ġ{ ĊĠĠĠĠĠĠĠ Ġprefs . edit (). putString ( Constants . PRE F _ START _ BUTTON _ IMAGE , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠConstants . PRE F _ START _ BUTTON _ IMAGE _ APP _ LOG O ). apply () ĊĠĠĠĠĠĠĠ Ġtile Service . update State () ĊĠĠĠĠĠĠĠ Ġvar Ġicon Ġ= Ġtile Service . qs Tile . icon ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( R . drawable . tb _ system . to Long (), ĠShadow s . shadow Of ( icon ). res Id . to Long ()) ĊĠĠĠĠĠĠĠ Ġprefs . edit (). putString ( Constants . PRE F _ START _ BUTTON _ IMAGE , ĠUNS UP PORT ED ). apply () ĊĠĠĠĠĠĠĠ Ġtile Service . update State () ĊĠĠĠĠĠĠĠ Ġicon Ġ= Ġtile Service . qs Tile . icon ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( R . drawable . tb _ all apps . to Long (), ĠShadow s . shadow Of ( icon ). res Id . to Long ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Update State For State () Ġ{ ĊĠĠĠĠĠĠĠ ĠPower Mockito . spy ( U :: class . java ) ĊĠĠĠĠĠĠĠ Ġval Ġcan Draw Overlay s Answer Ġ= ĠBoolean Answer () ĊĠĠĠĠĠĠĠ ĠPower Mockito .` when `( U . can Draw Overlay s ( tile Service )). then Answer ( can Draw Overlay s Answer ) ĊĠĠĠĠĠĠĠ Ġval Ġis Service Running Answer Ġ= ĠBoolean Answer () ĊĠĠĠĠĠĠĠ ĠPower Mockito .` when `( U . is Service Running ( tile Service , ĠNotification Service :: class . java )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. then Answer ( is Service Running Answer ) ĊĠĠĠĠĠĠĠ Ġcan Draw Overlay s Answer . answer Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġis Service Running Answer . answer Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġtile Service . update State () ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Tile . STATE _ ACTIVE . to Long (), Ġtile Service . qs Tile . state . to Long ()) ĊĠĠĠĠĠĠĠ Ġcan Draw Overlay s Answer . answer Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġis Service Running Answer . answer Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġtile Service . update State () ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Tile . STATE _ IN ACTIVE . to Long (), Ġtile Service . qs Tile . state . to Long ()) ĊĠĠĠĠĠĠĠ Ġcan Draw Overlay s Answer . answer Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġis Service Running Answer . answer Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġtile Service . update State () ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Tile . STATE _ UN AVAILABLE . to Long (), Ġtile Service . qs Tile . state . to Long ()) ĊĠĠĠĠĠĠĠ Ġcan Draw Overlay s Answer . answer Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġis Service Running Answer . answer Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġtile Service . update State () ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Tile . STATE _ UN AVAILABLE . to Long (), Ġtile Service . qs Tile . state . to Long ()) ĊĠĠĠ Ġ} Ċ } Ċ