/* Ċ Copyright Ġ 2 0 2 0 - 2 0 2 1 Ġli in ah am ari Ċ Ċ Permission Ġis Ġhereby Ġgranted , Ġfree Ġof Ġcharge , Ġto Ġany Ġperson Ġobtaining Ġa Ġcopy Ġof Ġthis Ġsoftware Ġand Ġassociated Ġdocumentation Ġfiles Ġ Ċ ( the Ġ" Software "), Ġto Ġdeal Ġin Ġthe ĠSoftware Ġwithout Ġrestriction , Ġincluding Ġwithout Ġlimitation Ġthe Ġrights Ġto Ġuse , Ġcopy , Ġmodify , Ġmerge , Ġ Ċ publish , Ġdistribute , Ġsublicense , Ġand / or Ġsell Ġcopies Ġof Ġthe ĠSoftware , Ġand Ġto Ġpermit Ġpersons Ġto Ġwhom Ġthe ĠSoftware Ġis Ġfurnished Ġto Ġdo Ġso , Ġ Ċ subject Ġto Ġthe Ġfollowing Ġconditions : Ċ Ċ The Ġabove Ġcopyright Ġnotice Ġand Ġthis Ġpermission Ġnotice Ġshall Ġbe Ġincluded Ġin Ġall Ġcopies Ġor Ġsubstantial Ġportions Ġof Ġthe ĠSoftware . Ċ Ċ THE ĠSOFTWARE ĠIS ĠPROVIDED Ġ" AS ĠIS ", ĠWITHOUT ĠWARRANTY ĠOF ĠANY ĠKIND , ĠEXPRESS ĠOR ĠIMPLIED , ĠINCLUDING ĠBUT ĠNOT ĠLIMITED ĠTO ĠTHE ĠWARRANTIES ĠOF Ġ Ċ MER CHANTABILITY , ĠFITNESS ĠFOR ĠA ĠPARTICULAR ĠPURPOSE ĠAND ĠNONINFRINGEMENT . ĠIN ĠNO ĠEVENT ĠSHALL ĠTHE ĠAUTHORS ĠOR ĠCOPYRIGHT ĠHOLDERS ĠBE ĠLIABLE ĠFOR Ġ Ċ ANY ĠCLAIM , ĠDAMAGES ĠOR ĠOTHER ĠLIABILITY , ĠWHETHER ĠIN ĠAN ĠACTION ĠOF ĠCONTRACT , ĠTORT ĠOR ĠOTHERWISE , ĠARISING ĠFROM , ĠOUT ĠOF ĠOR ĠIN ĠCONNECTION ĠWITH ĠTHE Ġ Ċ SOFTWARE ĠOR ĠTHE ĠUSE ĠOR ĠOTHER ĠDEALINGS ĠIN ĠTHE ĠSOFTWARE . Ċ */ Ċ Ċ package Ġdev . li in ah am ari . follow er Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . Intent Ċ import Ġandroid . location . Location Ċ import Ġandroid . location . Location Manager Ċ import Ġandroid . os . IB inder Ċ import Ġandroidx . room . Room Ċ import Ġandroidx . test . core . app . Application Provider . getApplicationContext Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġandroidx . test . rule . Service Test Rule Ċ import Ġdagger . Module Ċ import Ġdev . li in ah am ari . follow er . db . Tracks Db Ċ import Ġdev . li in ah am ari . follow er . di . components . D agger App Component Ċ import Ġdev . li in ah am ari . follow er . di . modules . Database Module Ċ import Ġdev . li in ah am ari . follow er . di . modules . Service Module Ċ import Ġdev . li in ah am ari . follow er . services . location _ tracking . ACTION _ START _ TRACK ING Ċ import Ġdev . li in ah am ari . follow er . services . location _ tracking . Location Tracking Service Ċ import Ġjunit . framework . TestCase . assertNotNull Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Mockito .` when ` Ċ import Ġorg . mockito . Mockito . mock Ċ Ċ private Ġconst Ġval ĠSO ME _ LAT Ġ= Ġ. 1 Ċ private Ġconst Ġval ĠSO ME _ LON Ġ= Ġ. 2 Ċ private Ġconst Ġval ĠSO ME _ PROV Ġ= Ġ" prov " Ċ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠSample Service Test Ġ{ ĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġservice Rule Ġ= ĠService Test Rule () ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Service () Ġ= Ġservice Rule . start Service ( Intent ( getApplicationContext (), ĠLocation Tracking Service :: class . java )) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Bound Service () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbinder : ĠI Binder Ġ= Ġservice Rule . bind Service ( Intent ( getApplicationContext (), ĠLocation Tracking Service :: class . java )) ĊĠĠĠĠĠĠĠ Ġval Ġservice : ĠLocation Tracking Service Ġ= Ġ( binder Ġas ĠLocation Tracking Service . Location Service Binder ). getService () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( service ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġstart Tracking __ ACTION _ START _ TRACK ING __ setup () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdb Ġ= ĠRoom . in Memory Database Builder ( getApplicationContext < Follower App >(), ĠTrack s Db :: class . java ). allow MainThread Queries (). build () ĊĊĠĠĠĠĠĠĠ Ġval Ġapp Ġ= Ġget ApplicationContext < Follower App >(). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsetup D agger ( D agger App Component ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. builder () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. application ( this ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. service Module ( Fake Service Module ( create Mock ed Location Manager ())) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. db Module ( Fake Db Module ( db )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġservice Rule . start Service ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠIntent ( app , ĠLocation Tracking Service :: class . java ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġaction Ġ= ĠACTION _ START _ TRACK ING ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ}) ĊĊĠĠĠĠĠĠĠ Ġval Ġbinder : ĠI Binder Ġ= Ġservice Rule . bind Service ( Intent ( app , ĠLocation Tracking Service :: class . java )) ĊĠĠĠĠĠĠĠ Ġval Ġservice : ĠLocation Tracking Service Ġ= Ġ( binder Ġas ĠLocation Tracking Service . Location Service Binder ). getService () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( service ) ĊĠĠĠĠĠĠĠ Ġassert ( service . is Tracking . value Ġ== Ġtrue ) ĊĠĠĠĠĠĠĠ Ġassert ( service . is Track Empty ) ĊĠĠĠĠĠĠĠ Ġassert ( db . get Track Dao (). getCount () Ġ== Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( db . get Way Point Dao (). getCount () Ġ== Ġ 0 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Mock ed Location Manager (): ĠLocation Manager Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġloc Ġ= Ġmock ( Location :: class . java ). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` when `( longitude ). thenReturn ( SO ME _ LON ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` when `( latitude ). thenReturn ( SO ME _ LAT ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` when `( provider ). thenReturn ( SO ME _ PROV ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġmock ( Location Manager :: class . java ). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` when `( getLast Known Location ( Location Manager . NETWORK _ PROVIDER )). thenReturn ( loc ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` when `( getLast Known Location ( Location Manager . GPS _ PROVIDER )). thenReturn ( loc ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ Ċ @ Module Ċ class ĠFake Service Module ( private Ġval Ġlock Mng : ĠLocation Manager ) Ġ: ĠService Module () Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġprovide Location Manager ( context : ĠContext ): ĠLocation Manager Ġ= Ġlock Mng Ċ } Ċ Ċ @ Module Ċ class ĠFake Db Module ( private Ġval Ġdb : ĠTrack s Db ): ĠDatabase Module (){ ĊĠĠĠ Ġoverride Ġfun Ġprovide Tracks Db ( context : ĠContext ): ĠTrack s Db Ġ= Ġdb Ċ }