/* Ċ Ġ* ĠCopyright Ġ 2 0 2 1 ĠOn a ĠSystems , ĠInc Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġorg . smart register . fhir core . engine . auth Ċ Ċ import Ġandroid . accounts . Account Ċ import Ġandroid . accounts . Account Manager Ċ import Ġandroidx . core . os . bundle Of Ċ import Ġandroidx . test . core . app . Application Provider Ċ import Ġdagger . h ilt . android . testing . H ilt Android Rule Ċ import Ġdagger . h ilt . android . testing . H ilt Android Test Ċ import Ġdagger . h ilt . android . testing . H ilt Test Application Ċ import Ġio . json web token . Unsupported Jwt Exception Ċ import Ġio . mock k . every Ċ import Ġio . mock k . spy k Ċ import Ġjavax . inject . Inject Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . smart register . fhir core . engine . app . f akes . Fake Model . auth Credentials Ċ import Ġorg . smart register . fhir core . engine . configuration . app . Config Service Ċ import Ġorg . smart register . fhir core . engine . ro bo lectric . Ro bo lectric Test Ċ import Ġorg . smart register . fhir core . engine . util . Secure Shared Preference Ċ Ċ @ H ilt Android Test Ċ class ĠToken Manager Service Test Ġ: ĠRo bo lectric Test () Ġ{ ĊĊĠ Ġ@ get : Rule Ġval Ġh ilt Rule Ġ= ĠH ilt Android Rule ( this ) ĊĊĠ Ġ@ Inject Ġlateinit Ġvar Ġaccount Manager : ĠAccount Manager ĊĊĠ Ġ@ Inject Ġlateinit Ġvar Ġsecure Shared Preference : ĠSecure Shared Preference ĊĊĠ Ġ@ Inject Ġlateinit Ġvar Ġconfig Service : ĠConfig Service ĊĊĠ Ġprivate Ġlateinit Ġvar Ġtoken Manager Service : ĠToken Manager Service ĊĊĠ Ġprivate Ġval Ġcontext Ġ= ĠApplication Provider . getApplicationContext < H ilt Test Application >() ĊĊĠ Ġ@ Before ĊĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠ Ġh ilt Rule . inject () ĊĠĠĠ Ġtoken Manager Service Ġ= ĊĠĠĠĠĠ Ġspy k ( ĊĠĠĠĠĠĠĠ ĠToken Manager Service ( ĊĠĠĠĠĠĠĠĠĠ Ġcontext Ġ= Ġcontext , ĊĠĠĠĠĠĠĠĠĠ Ġaccount Manager Ġ= Ġaccount Manager , ĊĠĠĠĠĠĠĠĠĠ Ġconfig Service Ġ= Ġconfig Service , ĊĠĠĠĠĠĠĠĠĠ Ġsecure Shared Preference Ġ= Ġsecure Shared Preference ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġ@ After ĊĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠ Ġsecure Shared Preference . delete Credentials () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Local Session Token With Inactive Token () Ġ{ ĊĠĠĠ ĠAssert . assertNull ( token Manager Service . getLocal Session Token ()) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Local Session Token With Active Token () Ġ{ ĊĠĠĠ Ġevery Ġ{ Ġtoken Manager Service . is Token Active ( auth Credentials . session Token ) Ġ} Ġreturns Ġtrue ĊĠĠĠ Ġsecure Shared Preference . save Credentials ( auth Credentials ) ĊĠĠĠ ĠAssert . assertEquals ( auth Credentials . session Token , Ġtoken Manager Service . getLocal Session Token ()) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Is Token Active With Null Token () Ġ{ ĊĠĠĠ ĠAssert . assertFalse ( token Manager Service . is Token Active ( null )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Throws ( Unsupported Jwt Exception :: class ) ĊĠ Ġfun Ġtest Is Token Active With Malformed Jwt Token () Ġ{ ĊĠĠĠ ĠAssert . assertFalse ( token Manager Service . is Token Active (" g ib ber ish - token ")) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Active Account () Ġ{ ĊĠĠĠ Ġsecure Shared Preference . save Credentials ( auth Credentials ) ĊĠĠĠ Ġaccount Manager . add Account Explicit ly ( ĊĠĠĠĠĠ ĠAccount ( auth Credentials . username , Ġconfig Service . provide Auth Configuration (). account Type ), ĊĠĠĠĠĠ Ġauth Credentials . password , ĊĠĠĠĠĠ Ġbundle Of () ĊĠĠĠ Ġ) ĊĠĠĠ Ġval Ġactive Account Ġ= Ġtoken Manager Service . getActive Account () ĊĠĠĠ ĠAssert . assertNotNull ( active Account ) ĊĠĠĠ ĠAssert . assertEquals ( auth Credentials . username , Ġactive Account !!. name ) ĊĠĠĠ ĠAssert . assertEquals ( config Service . provide Auth Configuration (). account Type , Ġactive Account . type ) ĊĠ Ġ} Ċ } Ċ