/** Ċ Ġ* Ġ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 Ġcom . t br uy elle . rx permissions 2 Ċ Ċ import Ġandroid . Manifest Ċ import Ġandroid . annotation . Target Api Ċ import Ġandroid . content . pm . PackageManager Ċ import Ġandroid . os . Build Ċ import Ġandroid . support . v 4 . app . Fragment Activity Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any Var arg Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . given Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . spy Ċ Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . ro bo lectric . Ro bo lectric Ċ import Ġorg . ro bo lectric . Ro bo lectric TestRunner Ċ import Ġorg . ro bo lectric . annotation . Config Ċ Ċ import Ġio . reactivex . Observable Ċ import Ġio . reactivex . ob servers . Test Observer Ċ Ċ @ RunWith ( Ro bo lectric TestRunner :: class ) Ċ @ Config ( constants Ġ= ĠBuild Config :: class , Ġsdk Ġ= Ġ[ Build . VERSION _ CODES . M ]) Ċ class ĠRx Permissions Test Ġ{ ĊĊĠ Ġprivate Ġvar Ġm Activity : ĠFragment Activity ? Ġ= Ġnull ĊĊĠ Ġprivate Ġvar Ġm Rx Permissions : ĠRx Permissions ? Ġ= Ġnull ĊĊĠ Ġ@ Before ĊĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠ Ġval Ġactivity Controller Ġ= ĠRo bo lectric . build Activity ( Fragment Activity :: class . java ) ĊĠĠĠ Ġm Activity Ġ= Ġspy ( activity Controller . setup (). get ()) ĊĠĠĠ Ġm Rx Permissions Ġ= Ġspy ( Rx Permissions ( m Activity !! )) ĊĠĠĠ Ġm Rx Permissions !!. m Rx Permissions Fragment Ġ= Ġspy ( m Rx Permissions !!. m Rx Permissions Fragment ) ĊĠĠĠ Ġval Ġrx Permissions Fragment Ġ= Ġspy ( m Rx Permissions !!. m Rx Permissions Fragment . get ()) ĊĠĠĠ Ġgiven ( rx Permissions Fragment . activity ). willReturn ( m Activity ) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. m Rx Permissions Fragment . get ()). willReturn ( rx Permissions Fragment ) ĊĠĠĠ Ġgiven Ġ{ Ġrx Permissions Fragment . is Granted ( any ()) Ġ}. willReturn ( false ) Ċ // ĠĠĠ Ġ// ĠDefault Ġdeny Ġall Ġpermissions Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( any ())). willReturn ( false ) Ċ // ĠĠĠ Ġ// ĠDefault Ġno Ġrev oked Ġpermissions Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Rev oked ( any ())). willReturn ( false ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġtrigger (): ĠObservable < Any > Ġ{ ĊĠĠĠ Ġreturn ĠObservable . just ( Rx Permissions . TRIGGER ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Target Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġsubscription _ pre M () Ġ{ ĊĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Boolean >() ĊĠĠĠ Ġval Ġpermission Ġ= ĠPermission ( Manifest . permission . READ _ PHONE _ STATE ) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( permission )). willReturn ( true ) ĊĊĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure ( permission )). subscribe ( sub ) ĊĊĠĠĠ Ġsub . assert No Errors () ĊĠĠĠ Ġsub . assert Terminated () ĊĠĠĠ Ġsub . assert Value ( true ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Target Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġsubscription _ gr anted () Ġ{ ĊĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Boolean >() ĊĠĠĠ Ġval Ġpermission Ġ= ĠPermission ( Manifest . permission . READ _ PHONE _ STATE ) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( permission )). willReturn ( false ) ĊĠĠĠ Ġval Ġresult Ġ= Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED ) ĊĊĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure ( permission )). subscribe ( sub ) ĊĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( array Of ( permission . name ), Ġresult ) ĊĊĠĠĠ Ġsub . assert No Errors () ĊĠĠĠ Ġsub . assert Terminated () ĊĠĠĠ Ġsub . assert Value ( true ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Target Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġeach Subscription _ gr anted () Ġ{ ĊĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() ĊĠĠĠ Ġval Ġpermission Ġ= ĠPermission ( Manifest . permission . READ _ PHONE _ STATE ) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( permission )). willReturn ( false ) ĊĠĠĠ Ġval Ġresult Ġ= Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED ) ĊĊĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure Each ( permission )). subscribe ( sub ) ĊĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( array Of ( permission . name ), Ġresult ) ĊĊĠĠĠ Ġsub . assert No Errors () ĊĠĠĠ Ġsub . assert Terminated () ĊĠĠĠ Ġsub . assert Value ( Permission ( permission . name , Ġgranted Ġ= Ġtrue )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Target Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġeach Subscription Combined _ gr anted () Ġ{ ĊĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() ĊĠĠĠ Ġval Ġpermission Ġ= ĠPermission ( Manifest . permission . READ _ PHONE _ STATE ) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( permission )). willReturn ( false ) ĊĠĠĠ Ġval Ġresult Ġ= Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED ) ĊĊĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure Each Combined ( permission )). subscribe ( sub ) ĊĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( array Of ( permission . name ), Ġresult ) ĊĊĠĠĠ Ġsub . assert No Errors () ĊĠĠĠ Ġsub . assert Terminated () ĊĠĠĠ Ġsub . assert Value ( Permission ( permission . name , Ġgranted Ġ= Ġtrue )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Target Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġeach Subscription _ pre M () Ġ{ ĊĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() ĊĠĠĠ Ġval Ġpermission Ġ= ĠPermission ( Manifest . permission . READ _ PHONE _ STATE ) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( permission )). willReturn ( true ) ĊĊĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure Each ( permission )). subscribe ( sub ) ĊĊĠĠĠ Ġsub . assert No Errors () ĊĠĠĠ Ġsub . assert Terminated () ĊĠĠĠ Ġsub . assert Value ( Permission ( permission . name , Ġgranted Ġ= Ġtrue )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Target Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġeach Subscription Combined _ pre M () Ġ{ ĊĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() ĊĠĠĠ Ġval Ġpermission Ġ= ĠPermission ( Manifest . permission . READ _ PHONE _ STATE ) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( permission )). willReturn ( true ) ĊĊĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure Each Combined ( permission )). subscribe ( sub ) ĊĊĠĠĠ Ġsub . assert No Errors () ĊĠĠĠ Ġsub . assert Terminated () ĊĠĠĠ Ġsub . assert Value ( Permission ( permission . name , Ġgranted Ġ= Ġtrue )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Target Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġsubscription _ already Granted () Ġ{ ĊĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Boolean >() ĊĠĠĠ Ġval Ġpermission Ġ= ĠPermission ( Manifest . permission . READ _ PHONE _ STATE ) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( permission )). willReturn ( true ) ĊĊĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure ( permission )). subscribe ( sub ) ĊĊĠĠĠ Ġsub . assert No Errors () ĊĠĠĠ Ġsub . assert Terminated () ĊĠĠĠ Ġsub . assert Value ( true ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Target Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġsubscription _ den ied () Ġ{ ĊĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Boolean >() ĊĠĠĠ Ġval Ġpermission Ġ= ĠPermission ( Manifest . permission . READ _ PHONE _ STATE ) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( permission )). willReturn ( false ) ĊĠĠĠ Ġval Ġresult Ġ= Ġint ArrayOf ( PackageManager . PERMISSION _ DEN IED ) ĊĊĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure ( permission )). subscribe ( sub ) ĊĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( array Of ( permission . name ), Ġresult ) ĊĊĠĠĠ Ġsub . assert No Errors () ĊĠĠĠ Ġsub . assert Terminated () ĊĠĠĠ Ġsub . assert Value ( false ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Target Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġeach Subscription _ den ied () Ġ{ ĊĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() ĊĠĠĠ Ġval Ġpermission Ġ= ĠPermission ( Manifest . permission . READ _ PHONE _ STATE ) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( permission )). willReturn ( false ) ĊĠĠĠ Ġval Ġresult Ġ= Ġint ArrayOf ( PackageManager . PERMISSION _ DEN IED ) ĊĊĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure Each ( permission )). subscribe ( sub ) ĊĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( array Of ( permission . name ), Ġresult ) ĊĊĠĠĠ Ġsub . assert No Errors () ĊĠĠĠ Ġsub . assert Terminated () ĊĠĠĠ Ġsub . assert Value ( Permission ( permission . name , Ġgranted Ġ= Ġfalse )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Target Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġeach Subscription Combined _ den ied () Ġ{ ĊĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() ĊĠĠĠ Ġval Ġpermission Ġ= ĠPermission ( Manifest . permission . READ _ PHONE _ STATE ) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( permission )). willReturn ( false ) ĊĠĠĠ Ġval Ġresult Ġ= Ġint ArrayOf ( PackageManager . PERMISSION _ DEN IED ) ĊĊĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure Each Combined ( permission )). subscribe ( sub ) ĊĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( array Of ( permission . name ), Ġresult ) ĊĊĠĠĠ Ġsub . assert No Errors () ĊĠĠĠ Ġsub . assert Terminated () ĊĠĠĠ Ġsub . assert Value ( Permission ( permission . name , Ġgranted Ġ= Ġfalse )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Target Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġsubscription _ rev oked () Ġ{ ĊĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Boolean >() ĊĠĠĠ Ġval Ġpermission Ġ= ĠPermission ( Manifest . permission . READ _ PHONE _ STATE ) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. is Rev oked ( permission )). willReturn ( true ) ĊĊĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure ( permission )). subscribe ( sub ) ĊĊĠĠĠ Ġsub . assert No Errors () ĊĠĠĠ Ġsub . assert Terminated () ĊĠĠĠ Ġsub . assert Value ( false ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Target Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġeach Subscription _ rev oked () Ġ{ ĊĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() ĊĠĠĠ Ġval Ġpermission Ġ= ĠPermission ( Manifest . permission . READ _ PHONE _ STATE ) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. is Rev oked ( permission )). willReturn ( true ) ĊĊĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure Each ( permission )). subscribe ( sub ) ĊĊĠĠĠ Ġsub . assert No Errors () ĊĠĠĠ Ġsub . assert Terminated () ĊĠĠĠ Ġsub . assert Value ( Permission ( permission . name , Ġgranted Ġ= Ġfalse )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Target Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġeach Subscription Combined _ rev oked () Ġ{ ĊĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() ĊĠĠĠ Ġval Ġpermission Ġ= ĠPermission ( Manifest . permission . READ _ PHONE _ STATE ) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. is Rev oked ( permission )). willReturn ( true ) ĊĊĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure Each Combined ( permission )). subscribe ( sub ) ĊĊĠĠĠ Ġsub . assert No Errors () ĊĠĠĠ Ġsub . assert Terminated () ĊĠĠĠ Ġsub . assert Value ( Permission ( permission . name , Ġgranted Ġ= Ġfalse )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Target Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġsubscription _ se veral Permissions _ gr anted () Ġ{ ĊĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Boolean >() ĊĠĠĠ Ġval Ġpermissions Ġ= ĠarrayOf ( Permission ( Manifest . permission . READ _ PHONE _ STATE ), ĠPermission ( Manifest . permission . CAMERA )) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( any Var arg ())). willReturn ( false ) ĊĠĠĠ Ġval Ġresult Ġ= Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED , ĠPackage Manager . PERMISSION _ GRAN TED ) ĊĊĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure (* permissions )). subscribe ( sub ) ĊĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( permissions . map Ġ{ Ġit . name Ġ}. to Typed Array (), Ġresult ) ĊĊĠĠĠ Ġsub . assert No Errors () ĊĠĠĠ Ġsub . assert Terminated () ĊĠĠĠ Ġsub . assert Value ( true ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Target Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġeach Subscription _ se veral Permissions _ gr anted () Ġ{ ĊĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() ĊĠĠĠ Ġval Ġpermissions Ġ= ĠarrayOf ( Permission ( Manifest . permission . READ _ PHONE _ STATE ), ĠPermission ( Manifest . permission . CAMERA )) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( any Var arg ())). willReturn ( false ) ĊĠĠĠ Ġval Ġresult Ġ= Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED , ĠPackage Manager . PERMISSION _ GRAN TED ) ĊĊĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure Each (* permissions )). subscribe ( sub ) ĊĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( permissions . map Ġ{ Ġit . name Ġ}. to Typed Array (), Ġresult ) ĊĊĠĠĠ Ġsub . assert No Errors () ĊĠĠĠ Ġsub . assert Terminated () ĊĠĠĠ Ġsub . assert Values ( Permission ( permissions . first (). name , Ġgranted Ġ= Ġtrue ), ĠPermission ( permissions [ 1 ]. name , Ġgranted Ġ= Ġtrue )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Target Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġeach Subscription Combined _ se veral Permissions _ gr anted () Ġ{ ĊĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() ĊĠĠĠ Ġval Ġpermissions Ġ= ĠarrayOf ( Permission ( Manifest . permission . READ _ PHONE _ STATE ), ĠPermission ( Manifest . permission . CAMERA )) ĊĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( any Var arg ())). willReturn ( false ) ĊĠĠĠ Ġval Ġresult Ġ= Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED , ĠPackage Manager . PERMISSION _ GRAN TED ) ĊĊĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure Each Combined (* permissions )). subscribe ( sub ) ĊĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( permissions . map Ġ{ Ġit . name Ġ}. to Typed Array (), Ġresult ) ĊĊĠĠĠ Ġsub . assert No Errors () ĊĠĠĠ Ġsub . assert Terminated () ĊĠĠĠ Ġsub . assert Values ( Permission ( permissions [ 0 ]. name , Ġgranted Ġ= Ġtrue ), ĠPermission ( permissions [ 1 ]. name , Ġgranted Ġ= Ġtrue )) ĊĠ Ġ} Ċ Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġsubscription _ se veral Permissions _ one Denied () Ġ{ Ċ // ĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Boolean >() Ċ // ĠĠĠ Ġval Ġpermissions Ġ= ĠarrayOf ( Manifest . permission . READ _ PHONE _ STATE , ĠManifest . permission . CAMERA ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( Matchers . any Var arg < String >() )). willReturn ( false ) Ċ // ĠĠĠ Ġval Ġresult Ġ= Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED , ĠPackage Manager . PERMISSION _ DEN IED ) Ċ // Ċ // ĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure (* permissions )). subscribe ( sub ) Ċ // ĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( permissions , Ġresult ) Ċ // Ċ // ĠĠĠ Ġsub . assert No Errors () Ċ // ĠĠĠ Ġsub . assert Terminated () Ċ // ĠĠĠ Ġsub . assert Value ( false ) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġsubscription _ se veral Permissions _ one Rev oked () Ġ{ Ċ // ĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Boolean >() Ċ // ĠĠĠ Ġval Ġpermissions Ġ= ĠarrayOf ( Manifest . permission . READ _ PHONE _ STATE , ĠManifest . permission . CAMERA ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( Matchers . any Var arg < String >() )). willReturn ( false ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Rev oked ( Manifest . permission . CAMERA )). willReturn ( true ) Ċ // Ċ // ĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure (* permissions )). subscribe ( sub ) Ċ // ĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( Ċ // ĠĠĠĠĠĠĠ ĠarrayOf ( Manifest . permission . READ _ PHONE _ STATE ), Ċ // ĠĠĠĠĠĠĠ Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED )) Ċ // Ċ // ĠĠĠ Ġsub . assert No Errors () Ċ // ĠĠĠ Ġsub . assert Terminated () Ċ // ĠĠĠ Ġsub . assert Value ( false ) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġeach Subscription _ se veral Permissions _ one Already Granted () Ġ{ Ċ // ĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() Ċ // ĠĠĠ Ġval Ġpermissions Ġ= ĠarrayOf ( Manifest . permission . READ _ PHONE _ STATE , ĠManifest . permission . CAMERA ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( Matchers . any Var arg < String >() )). willReturn ( false ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( Manifest . permission . CAMERA )). willReturn ( true ) Ċ // Ċ // ĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure Each (* permissions )). subscribe ( sub ) Ċ // ĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( Ċ // ĠĠĠĠĠĠĠ ĠarrayOf ( Manifest . permission . READ _ PHONE _ STATE ), Ċ // ĠĠĠĠĠĠĠ Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED )) Ċ // Ċ // ĠĠĠ Ġsub . assert No Errors () Ċ // ĠĠĠ Ġsub . assert Terminated () Ċ // ĠĠĠ Ġsub . assert Values ( Permission ( permission . names [ 0 ], Ġtrue ), ĠPermission ( permission . names [ 1 ], Ġtrue )) Ċ // ĠĠĠ Ġval Ġrequested Permissions Ġ= ĠArgument Captor . for Class ( Array < String >:: class . java ) Ċ // ĠĠĠ Ġverify < Rx Permissions >( m Rx Permissions ). request Permissions From Fragment ( requested Permissions . capture ()) Ċ // ĠĠĠ ĠassertEquals ( 1 , Ġrequested Permissions . value . size . to Long ()) Ċ // ĠĠĠ ĠassertEquals ( Manifest . permission . READ _ PHONE _ STATE , Ġrequested Permissions . value [ 0 ]) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġeach Subscription Combined _ se veral Permissions _ one Already Granted () Ġ{ Ċ // ĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() Ċ // ĠĠĠ Ġval Ġpermissions Ġ= ĠarrayOf ( Manifest . permission . READ _ PHONE _ STATE , ĠManifest . permission . CAMERA ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( Matchers . any Var arg < String >() )). willReturn ( false ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( Manifest . permission . CAMERA )). willReturn ( true ) Ċ // Ċ // ĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure Each Combined (* permissions )). subscribe ( sub ) Ċ // ĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( Ċ // ĠĠĠĠĠĠĠ ĠarrayOf ( Manifest . permission . READ _ PHONE _ STATE ), Ċ // ĠĠĠĠĠĠĠ Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED )) Ċ // Ċ // ĠĠĠ Ġsub . assert No Errors () Ċ // ĠĠĠ Ġsub . assert Terminated () Ċ // ĠĠĠ Ġsub . assert Values ( Permission ( permission . names [ 0 ] Ġ+ Ġ", Ġ" Ġ+ Ġpermissions [ 1 ], Ġtrue )) Ċ // ĠĠĠ Ġval Ġrequested Permissions Ġ= ĠArgument Captor . for Class ( Array < String >:: class . java ) Ċ // ĠĠĠ Ġverify < Rx Permissions >( m Rx Permissions ). request Permissions From Fragment ( requested Permissions . capture ()) Ċ // ĠĠĠ ĠassertEquals ( 1 , Ġrequested Permissions . value . size . to Long ()) Ċ // ĠĠĠ ĠassertEquals ( Manifest . permission . READ _ PHONE _ STATE , Ġrequested Permissions . value [ 0 ]) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġeach Subscription _ se veral Permissions _ one Denied () Ġ{ Ċ // ĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() Ċ // ĠĠĠ Ġval Ġpermissions Ġ= ĠarrayOf ( Manifest . permission . READ _ PHONE _ STATE , ĠManifest . permission . CAMERA ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( Matchers . any Var arg < String >() )). willReturn ( false ) Ċ // ĠĠĠ Ġval Ġresult Ġ= Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED , ĠPackage Manager . PERMISSION _ DEN IED ) Ċ // Ċ // ĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure Each (* permissions )). subscribe ( sub ) Ċ // ĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( permissions , Ġresult ) Ċ // Ċ // ĠĠĠ Ġsub . assert No Errors () Ċ // ĠĠĠ Ġsub . assert Terminated () Ċ // ĠĠĠ Ġsub . assert Values ( Permission ( permission . names [ 0 ], Ġtrue ), ĠPermission ( permission . names [ 1 ], Ġfalse )) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġeach Subscription Combined _ se veral Permissions _ one Denied () Ġ{ Ċ // ĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() Ċ // ĠĠĠ Ġval Ġpermissions Ġ= ĠarrayOf ( Manifest . permission . READ _ PHONE _ STATE , ĠManifest . permission . CAMERA ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( Matchers . any Var arg < String >() )). willReturn ( false ) Ċ // ĠĠĠ Ġval Ġresult Ġ= Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED , ĠPackage Manager . PERMISSION _ DEN IED ) Ċ // Ċ // ĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure Each Combined (* permissions )). subscribe ( sub ) Ċ // ĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( permissions , Ġresult ) Ċ // Ċ // ĠĠĠ Ġsub . assert No Errors () Ċ // ĠĠĠ Ġsub . assert Terminated () Ċ // ĠĠĠ Ġsub . assert Values ( Permission ( permission . names [ 0 ] Ġ+ Ġ", Ġ" Ġ+ Ġpermissions [ 1 ], Ġfalse )) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġeach Subscription _ se veral Permissions _ one Rev oked () Ġ{ Ċ // ĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() Ċ // ĠĠĠ Ġval Ġpermissions Ġ= ĠarrayOf ( Manifest . permission . READ _ PHONE _ STATE , ĠManifest . permission . CAMERA ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( Matchers . any Var arg < String >() )). willReturn ( false ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Rev oked ( Manifest . permission . CAMERA )). willReturn ( true ) Ċ // Ċ // ĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure Each (* permissions )). subscribe ( sub ) Ċ // ĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( Ċ // ĠĠĠĠĠĠĠ ĠarrayOf ( Manifest . permission . READ _ PHONE _ STATE ), Ċ // ĠĠĠĠĠĠĠ Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED )) Ċ // Ċ // ĠĠĠ Ġsub . assert No Errors () Ċ // ĠĠĠ Ġsub . assert Terminated () Ċ // ĠĠĠ Ġsub . assert Values ( Permission ( permission . names [ 0 ], Ġtrue ), ĠPermission ( permission . names [ 1 ], Ġfalse )) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġeach Subscription Combined _ se veral Permissions _ one Rev oked () Ġ{ Ċ // ĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() Ċ // ĠĠĠ Ġval Ġpermissions Ġ= ĠarrayOf ( Manifest . permission . READ _ PHONE _ STATE , ĠManifest . permission . CAMERA ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( Matchers . any Var arg < String >() )). willReturn ( false ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Rev oked ( Manifest . permission . CAMERA )). willReturn ( true ) Ċ // Ċ // ĠĠĠ Ġtrigger (). compose ( m Rx Permissions !!. ensure Each Combined (* permissions )). subscribe ( sub ) Ċ // ĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( Ċ // ĠĠĠĠĠĠĠ ĠarrayOf ( Manifest . permission . READ _ PHONE _ STATE ), Ċ // ĠĠĠĠĠĠĠ Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED )) Ċ // Ċ // ĠĠĠ Ġsub . assert No Errors () Ċ // ĠĠĠ Ġsub . assert Terminated () Ċ // ĠĠĠ Ġsub . assert Values ( Permission ( permission . names [ 0 ] Ġ+ Ġ", Ġ" Ġ+ Ġpermissions [ 1 ], Ġfalse )) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġsubscription _ trigger _ gr anted () Ġ{ Ċ // ĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Boolean >() Ċ // ĠĠĠ Ġval Ġpermission Ġ= ĠPermission ( Manifest . permission . READ _ PHONE _ STATE ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( permission )). willReturn ( false ) Ċ // ĠĠĠ Ġval Ġresult Ġ= Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED ) Ċ // ĠĠĠ Ġval Ġtrigger Ġ= ĠPublish Subject . create < Any >() Ċ // Ċ // ĠĠĠ Ġtrigger . compose ( m Rx Permissions !!. ensure ( permission )). subscribe ( sub ) Ċ // ĠĠĠ Ġtrigger . onNext ( 1 ) Ċ // ĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( array Of ( permission . name ), Ġresult ) Ċ // Ċ // ĠĠĠ Ġsub . assert No Errors () Ċ // ĠĠĠ Ġsub . assertNot Terminated () Ċ // ĠĠĠ Ġsub . assert Value ( true ) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġeach Subscription _ trigger _ gr anted () Ġ{ Ċ // ĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() Ċ // ĠĠĠ Ġval Ġpermission Ġ= ĠPermission ( Manifest . permission . READ _ PHONE _ STATE ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( permission )). willReturn ( false ) Ċ // ĠĠĠ Ġval Ġresult Ġ= Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED ) Ċ // ĠĠĠ Ġval Ġtrigger Ġ= ĠPublish Subject . create < Any >() Ċ // Ċ // ĠĠĠ Ġtrigger . compose ( m Rx Permissions !!. ensure Each ( permission )). subscribe ( sub ) Ċ // ĠĠĠ Ġtrigger . onNext ( 1 ) Ċ // ĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( array Of ( permission . name ), Ġresult ) Ċ // Ċ // ĠĠĠ Ġsub . assert No Errors () Ċ // ĠĠĠ Ġsub . assertNot Terminated () Ċ // ĠĠĠ Ġsub . assert Value ( Permission ( permission . name , Ġtrue )) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġeach Subscription Combined _ trigger _ gr anted () Ġ{ Ċ // ĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Permission >() Ċ // ĠĠĠ Ġval Ġpermission Ġ= ĠPermission ( Manifest . permission . READ _ PHONE _ STATE ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted ( permission )). willReturn ( false ) Ċ // ĠĠĠ Ġval Ġresult Ġ= Ġint ArrayOf ( PackageManager . PERMISSION _ GRAN TED ) Ċ // ĠĠĠ Ġval Ġtrigger Ġ= ĠPublish Subject . create < Any >() Ċ // Ċ // ĠĠĠ Ġtrigger . compose ( m Rx Permissions !!. ensure Each Combined ( permission )). subscribe ( sub ) Ċ // ĠĠĠ Ġtrigger . onNext ( 1 ) Ċ // ĠĠĠ Ġm Rx Permissions !!. on Request Permissions Result ( array Of ( permission . name ), Ġresult ) Ċ // Ċ // ĠĠĠ Ġsub . assert No Errors () Ċ // ĠĠĠ Ġsub . assertNot Terminated () Ċ // ĠĠĠ Ġsub . assert Value ( Permission ( permission . name , Ġtrue )) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġshould Show Request Permission R ationale _ all Denied _ all R ationale () Ġ{ Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Mar shm allow ). willReturn ( true ) Ċ // ĠĠĠ Ġval Ġactivity Ġ= Ġmock ( Activity :: class . java ) Ċ // ĠĠĠ Ġgiven ( activity . should Show Request Permission R ationale ( any String ())). willReturn ( true ) Ċ // Ċ // ĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Boolean >() Ċ // ĠĠĠ Ġm Rx Permissions !!. should Show Request Permission R ationale ( activity , Ġ" p 1 ", Ġ" p 2 ") Ċ // ĠĠĠĠĠĠĠ Ġ. subscribe ( sub ) Ċ // Ċ // ĠĠĠ Ġsub . assert Complete () Ċ // ĠĠĠ Ġsub . assert No Errors () Ċ // ĠĠĠ Ġsub . assert Value ( true ) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġshould Show Request Permission R ationale _ all Denied _ one R ationale () Ġ{ Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Mar shm allow ). willReturn ( true ) Ċ // ĠĠĠ Ġval Ġactivity Ġ= Ġmock ( Activity :: class . java ) Ċ // ĠĠĠ Ġgiven ( activity . should Show Request Permission R ationale (" p 1 ")). willReturn ( true ) Ċ // Ċ // ĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Boolean >() Ċ // ĠĠĠ Ġm Rx Permissions !!. should Show Request Permission R ationale ( activity , Ġ" p 1 ", Ġ" p 2 ") Ċ // ĠĠĠĠĠĠĠ Ġ. subscribe ( sub ) Ċ // Ċ // ĠĠĠ Ġsub . assert Complete () Ċ // ĠĠĠ Ġsub . assert No Errors () Ċ // ĠĠĠ Ġsub . assert Value ( false ) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġshould Show Request Permission R ationale _ all Denied _ no R ationale () Ġ{ Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Mar shm allow ). willReturn ( true ) Ċ // ĠĠĠ Ġval Ġactivity Ġ= Ġmock ( Activity :: class . java ) Ċ // Ċ // ĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Boolean >() Ċ // ĠĠĠ Ġm Rx Permissions !!. should Show Request Permission R ationale ( activity , Ġ" p 1 ", Ġ" p 2 ") Ċ // ĠĠĠĠĠĠĠ Ġ. subscribe ( sub ) Ċ // Ċ // ĠĠĠ Ġsub . assert Complete () Ċ // ĠĠĠ Ġsub . assert No Errors () Ċ // ĠĠĠ Ġsub . assert Value ( false ) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġshould Show Request Permission R ationale _ one Denied R ationale () Ġ{ Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Mar shm allow ). willReturn ( true ) Ċ // ĠĠĠ Ġval Ġactivity Ġ= Ġmock ( Activity :: class . java ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted (" p 1 ")). willReturn ( true ) Ċ // ĠĠĠ Ġgiven ( activity . should Show Request Permission R ationale (" p 2 ")). willReturn ( true ) Ċ // Ċ // ĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Boolean >() Ċ // ĠĠĠ Ġm Rx Permissions !!. should Show Request Permission R ationale ( activity , Ġ" p 1 ", Ġ" p 2 ") Ċ // ĠĠĠĠĠĠĠ Ġ. subscribe ( sub ) Ċ // Ċ // ĠĠĠ Ġsub . assert Complete () Ċ // ĠĠĠ Ġsub . assert No Errors () Ċ // ĠĠĠ Ġsub . assert Value ( true ) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġshould Show Request Permission R ationale _ one Denied Not R ationale () Ġ{ Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Mar shm allow ). willReturn ( true ) Ċ // ĠĠĠ Ġval Ġactivity Ġ= Ġmock ( Activity :: class . java ) Ċ // ĠĠĠ Ġgiven ( m Rx Permissions !!. is Granted (" p 2 ")). willReturn ( true ) Ċ // Ċ // ĠĠĠ Ġval Ġsub Ġ= ĠTest Observer < Boolean >() Ċ // ĠĠĠ Ġm Rx Permissions !!. should Show Request Permission R ationale ( activity , Ġ" p 1 ", Ġ" p 2 ") Ċ // ĠĠĠĠĠĠĠ Ġ. subscribe ( sub ) Ċ // Ċ // ĠĠĠ Ġsub . assert Complete () Ċ // ĠĠĠ Ġsub . assert No Errors () Ċ // ĠĠĠ Ġsub . assert Value ( false ) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġfun Ġis Granted _ pre Mar shm allow () Ġ{ Ċ // ĠĠĠ Ġ// Ġun mock Ġis Granted Ċ // ĠĠĠ Ġdo Call Real Method (). given < Rx Permissions >( m Rx Permissions ). is Granted ( any String ()) Ċ // ĠĠĠ Ġdo Return ( false ). given < Rx Permissions >( m Rx Permissions ). is Mar shm allow Ċ // Ċ // ĠĠĠ Ġval Ġgranted Ġ= Ġm Rx Permissions !!. is Granted (" p ") Ċ // Ċ // ĠĠĠ ĠassertTrue ( gr anted ) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġis Granted _ gr anted () Ġ{ Ċ // ĠĠĠ Ġ// Ġun mock Ġis Granted Ċ // ĠĠĠ Ġdo Call Real Method (). given < Rx Permissions >( m Rx Permissions ). is Granted ( any String ()) Ċ // ĠĠĠ Ġdo Return ( true ). given < Rx Permissions >( m Rx Permissions ). is Mar shm allow Ċ // ĠĠĠ Ġgiven ( m Activity !!. check Self Permission (" p ")). willReturn ( PackageManager . PERMISSION _ GRAN TED ) Ċ // Ċ // ĠĠĠ Ġval Ġgranted Ġ= Ġm Rx Permissions !!. is Granted (" p ") Ċ // Ċ // ĠĠĠ ĠassertTrue ( gr anted ) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġis Granted _ den ied () Ġ{ Ċ // ĠĠĠ Ġ// Ġun mock Ġis Granted Ċ // ĠĠĠ Ġdo Call Real Method (). given < Rx Permissions >( m Rx Permissions ). is Granted ( any String ()) Ċ // ĠĠĠ Ġdo Return ( true ). given < Rx Permissions >( m Rx Permissions ). is Mar shm allow Ċ // ĠĠĠ Ġgiven ( m Activity !!. check Self Permission (" p ")). willReturn ( PackageManager . PERMISSION _ DEN IED ) Ċ // Ċ // ĠĠĠ Ġval Ġgranted Ġ= Ġm Rx Permissions !!. is Granted (" p ") Ċ // Ċ // ĠĠĠ ĠassertFalse ( gr anted ) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġfun Ġis Rev oked _ pre Mar shm allow () Ġ{ Ċ // ĠĠĠ Ġ// Ġun mock Ġis Rev oked Ċ // ĠĠĠ Ġdo Call Real Method (). given < Rx Permissions >( m Rx Permissions ). is Rev oked ( any String ()) Ċ // ĠĠĠ Ġdo Return ( false ). given < Rx Permissions >( m Rx Permissions ). is Mar shm allow Ċ // Ċ // ĠĠĠ Ġval Ġrev oked Ġ= Ġm Rx Permissions !!. is Rev oked (" p ") Ċ // Ċ // ĠĠĠ ĠassertFalse ( rev oked ) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġis Rev oked _ true () Ġ{ Ċ // ĠĠĠ Ġ// Ġun mock Ġis Rev oked Ċ // ĠĠĠ Ġdo Call Real Method (). given < Rx Permissions >( m Rx Permissions ). is Rev oked ( any String ()) Ċ // ĠĠĠ Ġdo Return ( true ). given < Rx Permissions >( m Rx Permissions ). is Mar shm allow Ċ // ĠĠĠ Ġval Ġpm Ġ= Ġmock ( PackageManager :: class . java ) Ċ // ĠĠĠ Ġgiven ( m Activity !!. package Manager ). willReturn ( pm ) Ċ // ĠĠĠ Ġgiven ( pm . is Permission Rev oked By Policy ( eq (" p "), Ġany String ())). willReturn ( true ) Ċ // Ċ // ĠĠĠ Ġval Ġrev oked Ġ= Ġm Rx Permissions !!. is Rev oked (" p ") Ċ // Ċ // ĠĠĠ ĠassertTrue ( rev oked ) Ċ // Ġ Ġ} Ċ // Ċ // Ġ Ġ@ Test Ċ // Ġ Ġ@ Target Api ( Build . VERSION _ CODES . M ) Ċ // Ġ Ġfun Ġis Granted _ false () Ġ{ Ċ // ĠĠĠ Ġ// Ġun mock Ġis Rev oked Ċ // ĠĠĠ Ġdo Call Real Method (). given < Rx Permissions >( m Rx Permissions ). is Rev oked ( any String ()) Ċ // ĠĠĠ Ġdo Return ( true ). given < Rx Permissions >( m Rx Permissions ). is Mar shm allow Ċ // ĠĠĠ Ġval Ġpm Ġ= Ġmock ( PackageManager :: class . java ) Ċ // ĠĠĠ Ġgiven ( m Activity !!. package Manager ). willReturn ( pm ) Ċ // ĠĠĠ Ġgiven ( pm . is Permission Rev oked By Policy ( eq (" p "), Ġany String ())). willReturn ( false ) Ċ // Ċ // ĠĠĠ Ġval Ġrev oked Ġ= Ġm Rx Permissions !!. is Rev oked (" p ") Ċ // Ċ // ĠĠĠ ĠassertFalse ( rev oked ) Ċ // Ġ Ġ} Ċ } Ċ