package Ġcom . br aint re ep ay ments . api Ċ Ċ import Ġandroidx . fragment . app . Fragment Activity Ċ import Ġcom . google . android . gms . common . api . ApiException Ċ import Ġcom . google . android . gms . common . api . Status Ċ import Ġcom . google . android . gms . tasks . Tasks Ċ import Ġcom . google . android . gms . wallet . Is Ready To Pay Request Ċ import Ġcom . google . android . gms . wallet . Payments Client Ċ import Ġcom . google . android . gms . wallet . Wallet Ċ import Ġcom . google . android . gms . wallet . Wallet Constants Ċ import Ġio . mock k . every Ċ import Ġio . mock k . mock k Ċ import Ġio . mock k . mock k Static Ċ import Ġio . mock k . slot Ċ import Ġjunit . framework . TestCase .* Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . ro bo lectric . Ro bo lectric TestRunner Ċ import Ġjava . util . concurrent . Count DownLatch Ċ Ċ @ RunWith ( Ro bo lectric TestRunner :: class ) Ċ class ĠGoogle Pay Internal Client UnitTest Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġactivity : ĠFragment Activity ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġis Ready To Pay Callback : ĠGoogle Pay Is Ready To Pay Callback ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġpayments Client : ĠPay ments Client ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġis Ready To Pay Request : ĠIs Ready To Pay Request ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠbeforeEach () Ġ{ ĊĠĠĠĠĠĠĠ Ġmock k Static ( Wallet :: class ) ĊĠĠĠĠĠĠĠ Ġactivity Ġ= Ġmock k ( relax ed Ġ= Ġtrue ) ĊĠĠĠĠĠĠĠ Ġis Ready To Pay Callback Ġ= Ġmock k ( relax ed Ġ= Ġtrue ) ĊĠĠĠĠĠĠĠ Ġpayments Client Ġ= Ġmock k () ĊĠĠĠĠĠĠĠ Ġis Ready To Pay Request Ġ= ĠIs Ready To Pay Request . fromJson ("{} ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` is Ready To Pay Ġrequests ĠTest ĠWallet Ġenvironment Ġwhen Ġconfiguration Ġenvironment Ġis ĠSandbox `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Ġ= ĠConfiguration . fromJson ( Fixtures . CONFIGURATION _ WITH _ GOOGLE _ PAY ) ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġpayments Client . is Ready To Pay ( is Ready To Pay Request ) Ġ} Ġreturns ĠTasks . for Result ( true ) ĊĊĠĠĠĠĠĠĠ Ġval Ġwallet Options Slot Ġ= Ġslot < Wallet . Wallet Options >() ĊĠĠĠĠĠĠĠ Ġevery Ġ{ ĠWallet . get Payments Client ( any (), Ġcapture ( wallet Options Slot )) Ġ} Ġreturns Ġpayments Client ĊĊĠĠĠĠĠĠĠ Ġval Ġsut Ġ= ĠGoogle Pay Internal Client () ĊĠĠĠĠĠĠĠ Ġsut . is Ready To Pay ( activity , Ġconfiguration , Ġis Ready To Pay Request , Ġis Ready To Pay Callback ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( Wallet Constants . ENVIRONMENT _ TEST , Ġwallet Options Slot . captured . environment ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` is Ready To Pay Ġrequests ĠProduction ĠWallet Ġenvironment Ġwhen Ġconfiguration Ġenvironment Ġis ĠProduction `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Ġ= ĠConfiguration . fromJson ( Fixtures . CONFIGURATION _ WITH _ GOOGLE _ PAY _ PRO DU CTION ) ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġpayments Client . is Ready To Pay ( is Ready To Pay Request ) Ġ} Ġreturns ĠTasks . for Result ( true ) ĊĊĠĠĠĠĠĠĠ Ġval Ġwallet Options Slot Ġ= Ġslot < Wallet . Wallet Options >() ĊĠĠĠĠĠĠĠ Ġevery Ġ{ ĠWallet . get Payments Client ( any (), Ġcapture ( wallet Options Slot )) Ġ} Ġreturns Ġpayments Client ĊĊĠĠĠĠĠĠĠ Ġval Ġsut Ġ= ĠGoogle Pay Internal Client () ĊĠĠĠĠĠĠĠ Ġsut . is Ready To Pay ( activity , Ġconfiguration , Ġis Ready To Pay Request , Ġis Ready To Pay Callback ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( Wallet Constants . ENVIRONMENT _ PRO DU CTION , Ġwallet Options Slot . captured . environment ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` is Ready To Pay Ġforwards Ġsuccess Ġresult Ġto Ġcallback `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcount DownLatch Ġ= ĠCount DownLatch ( 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Ġ= ĠConfiguration . fromJson ( Fixtures . CONFIGURATION _ WITH _ GOOGLE _ PAY ) ĊĠĠĠĠĠĠĠ Ġevery Ġ{ ĠWallet . get Payments Client ( any (), Ġany ()) Ġ} Ġreturns Ġpayments Client ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġpayments Client . is Ready To Pay ( is Ready To Pay Request ) Ġ} Ġanswers Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTasks . for Result ( true ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġsut Ġ= ĠGoogle Pay Internal Client () ĊĠĠĠĠĠĠĠ Ġsut . is Ready To Pay ( activity , Ġconfiguration , Ġis Ready To Pay Request ) Ġ{ Ġis Ready To Pay , Ġerror Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertTrue ( is Ready To Pay ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertNull ( error ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcount DownLatch . count Down () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġcount DownLatch . await () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` is Ready To Pay Ġforwards Ġfailure Ġresult Ġto Ġcallback `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcount DownLatch Ġ= ĠCount DownLatch ( 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Ġ= ĠConfiguration . fromJson ( Fixtures . CONFIGURATION _ WITH _ GOOGLE _ PAY ) ĊĠĠĠĠĠĠĠ Ġevery Ġ{ ĠWallet . get Payments Client ( any (), Ġany ()) Ġ} Ġreturns Ġpayments Client ĊĊĠĠĠĠĠĠĠ Ġval Ġexpected Error Ġ= ĠApiException ( Status . RESULT _ INTERNAL _ ERROR ) ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġpayments Client . is Ready To Pay ( is Ready To Pay Request ) Ġ} Ġanswers Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTasks . for Exception ( expected Error ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġsut Ġ= ĠGoogle Pay Internal Client () ĊĠĠĠĠĠĠĠ Ġsut . is Ready To Pay ( activity , Ġconfiguration , Ġis Ready To Pay Request ) Ġ{ Ġis Ready To Pay , Ġerror Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertFalse ( is Ready To Pay ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertSame ( expected Error , Ġerror ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcount DownLatch . count Down () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġcount DownLatch . await () ĊĠĠĠ Ġ} Ċ }