package Ġcom . r ak uten . tech . mobile . in app messaging . runtime . work manager . schedul ers Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . os . Build Ċ import Ġandroid . provider . Settings Ċ import Ġandroidx . test . core . app . Application Provider Ċ import Ġandroidx . work . One Time Work Request Ċ import Ġandroidx . work . Work Manager Ċ import Ġandroidx . work . testing . Work Manager Test Init Helper Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . argument Captor Ċ import Ġcom . r ak uten . tech . mobile . in app messaging . runtime . Base Test Ċ import Ġcom . r ak uten . tech . mobile . in app messaging . runtime . In App Ċ import Ġcom . r ak uten . tech . mobile . in app messaging . runtime . In App Messaging Ċ import Ġcom . r ak uten . tech . mobile . in app messaging . runtime . exception . In App Messaging Exception Ċ import Ġcom . r ak uten . tech . mobile . in app messaging . runtime . utils . Retry Delay Util Ċ import Ġorg . am sh ove . k lu ent .* Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Argument Matchers Ċ import Ġorg . mockito . Mockito Ċ import Ġorg . mockito . Mockito .` when ` Ċ import Ġorg . ro bo lectric . Ro bo lectric TestRunner Ċ import Ġorg . ro bo lectric . annotation . Config Ċ Ċ /** Ċ Ġ* ĠTesting Ġclass Ġof ĠConfig Scheduler . Ċ Ġ*/ Ċ @ RunWith ( Ro bo lectric TestRunner :: class ) Ċ @ Config ( sdk Ġ= Ġ[ Build . VERSION _ CODES . O _ MR 1 ]) Ċ class ĠConfig Scheduler Spec Ġ: ĠBaseTest () Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġmock Work Manager Ġ= ĠMockito . mock ( Work Manager :: class . java ) ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġoverride Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . setup () ĊĠĠĠĠĠĠĠ Ġ` when `( mock Work Manager . begin Unique Work ( any (), Ġany (), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠArgument Matchers . any ( One Time Work Request :: class . java ))). then Throw ( IllegalStateException (" test ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġnot Ġthrow Ġexception `() Ġ{ ĊĠĠĠĠĠĠĠ ĠWork Manager Test Init Helper . initialize Test Work Manager ( Application Provider . getApplicationContext ()) ĊĠĠĠĠĠĠĠ ĠSettings . Secure . putString ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠApplication Provider . getApplicationContext < Context >(). content Resolver , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSettings . Secure . ANDROID _ ID , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test _ device _ id ") ĊĠĠĠĠĠĠĠ ĠIn App Messaging . initialize ( Application Provider . getApplicationContext (), Ġtrue ) ĊĠĠĠĠĠĠĠ ĠConfig Scheduler . instance (). start Config () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġnot Ġthrow Ġexception Ġwhen Ġwork manager Ġis Ġnot Ġinitialized `() Ġ{ ĊĠĠĠĠĠĠĠ ĠIn App Messaging . initialize ( Application Provider . getApplicationContext (), Ġtrue ) ĊĠĠĠĠĠĠĠ ĠConfig Scheduler . instance (). start Config ( 0 , Ġmock Work Manager ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġnot Ġthrow Ġexception Ġwhen Ġwork manager Ġis Ġnot Ġinitialized Ġwith Ġcallback `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġfunction : Ġ( ex : ĠException ) Ġ-> ĠUnit Ġ= Ġ{} ĊĠĠĠĠĠĠĠ Ġval Ġmock Callback Ġ= ĠMockito . mock ( function . java Class ) ĊĠĠĠĠĠĠĠ ĠIn App . error Callback Ġ= Ġmock Callback ĊĊĠĠĠĠĠĠĠ ĠIn App Messaging . initialize ( Application Provider . getApplicationContext (), Ġtrue ) ĊĠĠĠĠĠĠĠ ĠConfig Scheduler . instance (). start Config ( 0 , Ġmock Work Manager ) ĊĊĠĠĠĠĠĠĠ Ġval Ġcapt or Ġ= Ġargument Captor < In App Messaging Exception >() ĊĠĠĠĠĠĠĠ ĠMockito . verify ( mock Callback ). invoke ( capt or . capture ()) ĊĠĠĠĠĠĠĠ Ġcapt or . first Value ĠshouldBe InstanceOf ĠIn App Messaging Exception :: class . java ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġbe Ġcalled Ġonce `() Ġ{ ĊĠĠĠĠĠĠĠ ĠWork Manager Test Init Helper . initialize Test Work Manager ( Application Provider . getApplicationContext ()) ĊĠĠĠĠĠĠĠ ĠSettings . Secure . putString ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠApplication Provider . getApplicationContext < Context >(). content Resolver , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSettings . Secure . ANDROID _ ID , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test _ device _ id ") ĊĠĠĠĠĠĠĠ Ġval Ġmock Config Scheduler Ġ= ĠMockito . mock ( Config Scheduler :: class . java ) ĊĊĠĠĠĠĠĠĠ ĠIn App Messaging . initialize ( Application Provider . getApplicationContext (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġconfig Scheduler Ġ= Ġmock Config Scheduler ) ĊĊĠĠĠĠĠĠĠ ĠMockito . verify ( mock Config Scheduler ). start Config () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġreset Ġdelay Ġwhen Ġmax Ġis Ġencountered `() Ġ{ ĊĠĠĠĠĠĠĠ ĠIn App Messaging . init ( Application Provider . getApplicationContext ()). shouldBe True () ĊĠĠĠĠĠĠĠ ĠConfig Scheduler . curr Delay Ġ*= Ġ 2 ĊĠĠĠĠĠĠĠ ĠConfig Scheduler . instance (). start Config ( Long . MAX _ VALUE Ġ- ĠSystem . currentTimeMillis () Ġ+ Ġ 2 ) ĊĠĠĠĠĠĠĠ ĠConfig Scheduler . curr Delay ĠshouldBe EqualTo ĠRetry Delay Util . INITIAL _ BACK OFF _ DELAY ĊĠĠĠ Ġ} Ċ } Ċ