package Ġme . h uf man . android aut oid rive ĊĊ Ċ import Ġandroid . content . Broadcast Receiver Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . Intent Ċ import Ġandroid . content . Intent Filter Ċ import Ġandroid . graphics . drawable . Icon Ċ import Ġandroid . support . test . Instrumentation Registry Ċ import Ġandroid . support . test . runner . Android JUnit 4 Ċ import Ġandroid . util . Log Ċ import Ġme . h uf man . android aut oid rive . notifications . Notification Listener ServiceImpl Ċ Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ Ċ import Ġcom . n ha ar man . mockito _ kotlin .* Ċ import Ġme . h uf man . android aut oid rive . notifications . Car Notification Ċ import Ġme . h uf man . android aut oid rive . notifications . Car Notification Controller Intent Ċ import Ġme . h uf man . android aut oid rive . car app . notifications . Phone Notifications Ċ import Ġme . h uf man . android aut oid rive . notifications . Notification Updater Controller Intent Ċ import Ġorg . await ility . Await ility . await Ċ Ċ /** Ċ Ġ* ĠInstrument ed Ġtest , Ġwhich Ġwill Ġexecute Ġon Ġan ĠAndroid Ġdevice . Ċ Ġ* Ċ Ġ* ĠSee Ġ[ testing Ġdocumentation ]( http :// d . android . com / tools / testing ). Ċ Ġ*/ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠInstrument ed Test Notification App Ġ{ ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Notification Update () Ġ{ Ċĉ ĉ /** ĠTest Ġthat Ġa Ġnew Ġnotification Ġp okes Ġthe Ġcar Ġ*/ Ċĉ ĉ // ĠContext Ġof Ġthe Ġapp Ġunder Ġtest . Ċĉ ĉ val Ġapp Context Ġ= ĠInstrument ation Registry . getTarget Context () ĊĊĉ ĉ // Ġprepare Ġto Ġlisten Ġto Ġupdates Ġfrom Ġthe Ġphone Ċĉ ĉ val Ġmock Listener Ġ= Ġmock < Phone Notifications . Phone Notification Listener > Ġ{} Ċĉ ĉ val Ġupdate Listener Ġ= ĠNotification Updater Controller Intent . Receiver ( mock Listener ) Ċĉ ĉ val Ġupdate Receiver Ġ= Ġobject : ĠBroadcast Receiver () Ġ{ Ċĉĉ ĉ override Ġfun Ġon Receive ( p 0 : ĠContext ?, Ġp 1 : ĠIntent ?) Ġ{ Ċĉĉĉ ĉ update Listener . on Receive ( p 1 !! ) Ċĉĉ ĉ } Ċĉ ĉ } Ċĉ ĉ update Listener . register ( app Context , Ġupdate Receiver , Ġnull ) ĊĊĉ ĉ // Ġprepare Ġa Ġnotification Ċĉ ĉ val Ġicon Ġ= ĠIcon . create With Resource ( app Context , ĠR . mip map . ic _ launcher ) Ċĉ ĉ val Ġnotification Ġ= ĠCar Notification ( app Context . packageName , Ġ" test ", Ġicon , Ġtrue , ĠlistOf (), Ċĉĉĉ ĉ " Test ", Ġ" Test ĠText ", Ġnull , Ġnull , Ġnull ) ĊĊĉ ĉ // Ġsend Ġan Ġupdate Ġfrom Ġthe Ġphone Ċĉ ĉ val Ġcontroller Ġ= ĠNotification Updater Controller Intent ( app Context ) Ċĉ ĉ controller . on Updated List () ĊĊĉ ĉ // Ġverify Ġthat Ġit Ġmade Ġit Ġacross Ċĉ ĉ await (). until Assert ed Ġ{ Ġverify ( mock Listener , Ġtimes ( 1 )). on Updated List () Ġ} Ċĉ ĉ Log . i (" Testing ", Ġ" Finished Ġthe Ġtests ") Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Notification Control () Ġ{ Ċĉ ĉ /** ĠTest Ġthat Ġa Ġcar Ġbutton Ġpress Ġp okes Ġthe Ġphone Ġ*/ Ċĉ ĉ // ĠContext Ġof Ġthe Ġapp Ġunder Ġtest . Ċĉ ĉ val Ġapp Context Ġ= ĠInstrument ation Registry . getTarget Context () ĊĊĉ ĉ // Ġprepare Ġto Ġlisten Ġto Ġthe Ġinteraction Ġfrom Ġthe Ġcar Ċĉ ĉ val Ġmock Listener Ġ= Ġmock < Notification Listener ServiceImpl . Car Notification Controller Listener > Ġ{ Ġ} Ċĉ ĉ val Ġcontroller Listener Ġ= ĠCar Notification Controller Intent . Receiver ( mock Listener ) Ċĉ ĉ val Ġinteraction Listener Ġ= ĠNotification Listener ServiceImpl . Notification Interaction Listener ( controller Listener , Ġmock ()) Ċĉ ĉ val Ġinteraction Receiver Ġ= Ġobject : ĠBroadcast Receiver () Ġ{ Ċĉĉ ĉ override Ġfun Ġon Receive ( p 0 : ĠContext ?, Ġp 1 : ĠIntent ?) Ġ{ Ċĉĉĉ ĉ interaction Listener . on Receive ( p 1 !! ) Ċĉĉ ĉ } Ċĉ ĉ } Ċĉ ĉ controller Listener . register ( app Context , Ġinteraction Receiver ) Ċĉ ĉ app Context . register Receiver ( interaction Receiver , ĠIntent Filter ( Notification Listener ServiceImpl . INT ENT _ REQUEST _ DATA )) ĊĊĉ ĉ // Ġprepare Ġa Ġnotification Ċĉ ĉ val Ġicon Ġ= ĠIcon . create With Resource ( app Context , ĠR . mip map . ic _ launcher ) Ċĉ ĉ val Ġnotification Ġ= ĠCar Notification ( app Context . packageName , Ġ" test ", Ġicon , Ġtrue , ĠlistOf (), Ċĉĉĉ ĉ " Test ", Ġ" Test ĠText ", Ġnull , Ġnull , Ġnull ) ĊĊĉ ĉ val Ġcar Controller Ġ= ĠCar Notification Controller Intent ( app Context ) Ċĉ ĉ // Ġsend Ġan Ġinteraction Ġfrom Ġthe Ġcar Ċĉ ĉ car Controller . clear ( notification . key ) Ċĉ ĉ await (). until Assert ed Ġ{ Ġverify ( mock Listener , Ġtimes ( 1 )). clear ( notification . key ) Ġ} Ċĉ ĉ // Ġsend Ġa Ġcustom Ġaction Ġfrom Ġthe Ġcar Ċĉ ĉ car Controller . action ( notification . key , Ġ" custom ") Ċĉ ĉ await (). until Assert ed Ġ{ Ġverify ( mock Listener , Ġtimes ( 1 )). action ( notification . key , Ġ" custom ") Ġ} Ċĉ ĉ // Ġsend Ġa Ġreply Ġfrom Ġthe Ġcar Ċĉ ĉ car Controller . reply ( notification . key , Ġ" reply ", Ġ" text ") Ċĉ ĉ await (). until Assert ed Ġ{ Ġverify ( mock Listener , Ġtimes ( 1 )). reply ( notification . key , Ġ" reply ", Ġ" text ") Ġ} Ċ ĉ } Ċ } Ċ