package Ġcom . example . background . workers Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġandroidx . work . One Time Work RequestBuilder Ċ import Ġandroidx . work . Work Info Ċ import Ġorg . hamcrest . Core Matchers .` is ` Ċ import Ġorg . hamcrest . Matcher Assert . assertThat Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ Ċ /** Ċ Ġ* Ġ ĠTest ĠCleanup Worker , Ġto Ġcheck Ġthat Ġit Ġactually Ġdeletes Ġthe Ġfiles . Ċ Ġ* Ġ ĠTo Ġdo Ġthis , copy Ġthe Ġtest Ġimage Ġon Ġthe Ġdevice Ġin Ġthe Ġtest , Ċ Ġ* Ġ Ġand Ġthen Ġcheck Ġif Ġit 's Ġthere Ġafter Ġthe ĠCleanup Worker Ġhas Ġbeen Ġexecuted . Ċ Ġ*/ Ċ class ĠCleanup Worker Test Ġ{ ĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġinstant Task Executor Rule Ġ= ĠInstant Task Executor Rule () ĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġwm Rule Ġ= ĠWork Manager Test Rule () ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Cleanup Work () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtest Uri Ġ= Ġcopy File From Test To Target Ctx ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwm Rule . test Context , Ġwm Rule . target Context , Ġ" test _ img . jpg ") ĊĠĠĠĠĠĠĠ ĠassertThat ( uri File Exists ( wm Rule . target Context , Ġtest Uri . toString ()), Ġ` is `( true )) ĊĊĠĠĠĠĠĠĠ Ġ// ĠCreate Ġrequest ĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= ĠOne Time Work RequestBuilder < Cleanup Worker >(). build () ĊĊĠĠĠĠĠĠĠ Ġ// ĠEn queue Ġand Ġwait Ġfor Ġresult . ĠThis Ġalso Ġruns Ġthe ĠWorker Ġsynchronous ly ĊĠĠĠĠĠĠĠ Ġ// Ġbecause Ġwe Ġare Ġusing Ġa ĠS ynchronous Executor . ĊĠĠĠĠĠĠĠ Ġwm Rule . work Manager . enqueue ( request ). result . get () ĊĠĠĠĠĠĠĠ Ġ// ĠGet ĠWork Info ĊĠĠĠĠĠĠĠ Ġval Ġwork Info Ġ= Ġwm Rule . work Manager . get Work Info ById ( request . id ). get () ĊĊĠĠĠĠĠĠĠ Ġ// ĠAssert ĊĠĠĠĠĠĠĠ ĠassertThat ( uri File Exists ( wm Rule . target Context , Ġtest Uri . toString ()), Ġ` is `( false )) ĊĠĠĠĠĠĠĠ ĠassertThat ( work Info . state , Ġ` is `( Work Info . State . SUCCEEDED )) ĊĠĠĠ Ġ} Ċ }