package Ġcom . stripe . android . view Ċ Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . K Argument Captor Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . argument Captor Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . eq Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġcom . stripe . android . Customer Session Ċ import Ġcom . stripe . android . Payment Session Config Ċ import Ġcom . stripe . android . Payment Session Data Ċ import Ġcom . stripe . android . Payment Session Fixtures Ċ import Ġcom . stripe . android . model . Customer Fixtures Ċ import Ġcom . stripe . android . model . Shipping Information Ċ import Ġcom . stripe . android . model . Shipping Method Ċ import Ġkotlin . test . Test Ċ import Ġkotlin . test . assertEquals Ċ import Ġkotlin . test . assertFalse Ċ import Ġkotlin . test . assertNotNull Ċ import Ġkotlin . test . assertTrue Ċ import Ġkotlinx . coroutines . Main Scope Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . ro bo lectric . Ro bo lectric TestRunner Ċ Ċ @ RunWith ( Ro bo lectric TestRunner :: class ) Ċ class ĠPayment Flow ViewModel Test Ġ{ ĊĠĠĠ Ġprivate Ġval Ġcustomer Session : ĠCustomer Session Ġ= Ġmock () ĊĊĠĠĠ Ġprivate Ġval Ġcustomer Retrie val Listener : ĠK Argument Captor < Customer Session . Customer Retrie val Listener > Ġby Ġlazy Ġ{ ĊĠĠĠĠĠĠĠ Ġargument Captor < Customer Session . Customer Retrie val Listener >() ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval ĠviewModel : ĠPayment Flow ViewModel Ġby Ġlazy Ġ{ ĊĠĠĠĠĠĠĠ ĠPayment Flow ViewModel ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcustomer Session Ġ= Ġcustomer Session , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpayment Session Data Ġ= ĠPayment Session Data ( Payment Session Fixtures . CONFIG ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwork Scope Ġ= ĠMain Scope () ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsave Customer Shipping Information _ on Success _ returns Expected Data () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertFalse ( viewModel . is Shipping Info Submitted ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . save Customer Shipping Information ( Shipping Info Fixtures . DEFAULT ) ĊĠĠĠĠĠĠĠ Ġverify ( customer Session ). set Customer Shipping Information ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġeq ( Shipping Info Fixtures . DEFAULT ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcustomer Retrie val Listener . capture () ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġcustomer Retrie val Listener . first Value . on Customer Retrie ved ( Customer Fixtures . CUSTOMER ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Value Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrequire NotNull ( result . value ) Ġas ĠPayment Flow ViewModel . Save Customer Shipping Info Result . Success ĊĠĠĠĠĠĠĠ ĠassertNotNull ( result Value . customer ) ĊĊĠĠĠĠĠĠĠ ĠassertTrue ( viewModel . is Shipping Info Submitted ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġvalidate Shipping Information _ with Valid Shipping Info _ creates Expected Shipping Methods () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= ĠviewModel . validate Shipping Information ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠFake Shipping Information Validator (), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠFake Shipping Methods Factory (), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSh ipping Info Fixtures . DEFAULT ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Value Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrequire NotNull ( result . value ) Ġas ĠPayment Flow ViewModel . Validate Shipping Info Result . Success ĊĠĠĠĠĠĠĠ ĠassertEquals ( SHIP PING _ METHO DS , Ġresult Value . shipping Methods ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( SHIP PING _ METHO DS , ĠviewModel . shipping Methods ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġvalidate Shipping Information _ with Valid Shipping Info And No Shipping Methods Factory _ creates Empty Shipping Methods () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= ĠviewModel . validate Shipping Information ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠFake Shipping Information Validator (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSh ipping Info Fixtures . DEFAULT ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Value Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrequire NotNull ( result . value ) Ġas ĠPayment Flow ViewModel . Validate Shipping Info Result . Success ĊĠĠĠĠĠĠĠ ĠassertTrue ( result Value . shipping Methods . isEmpty ()) ĊĠĠĠĠĠĠĠ ĠassertTrue ( viewModel . shipping Methods . isEmpty ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġvalidate Shipping Information _ with Invalid Valid Shipping Info _ creates Empty Shipping Methods () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= ĠviewModel . validate Shipping Information ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠF ailing Shipping Information Validator (), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠThrow ing Shipping Methods Factory (), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSh ipping Info Fixtures . DEFAULT ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Value Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrequire NotNull ( result . value ) Ġas ĠPayment Flow ViewModel . Validate Shipping Info Result . Error ĊĠĠĠĠĠĠĠ ĠassertEquals ( SHIP PING _ ERROR _ MESSAGE , Ġresult Value . errorMessage ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġclass ĠFake Shipping Information Validator Ġ: ĠPayment Session Config . Shipping Information Validator Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun ĠisValid ( shipping Information : ĠSh ipping Information ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġtrue ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget ErrorMessage ( shipping Information : ĠSh ipping Information ): ĠString Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠIllegalStateException (" Should Ġnot Ġbe Ġcalled Ġbecause Ġshipping Ġinfo Ġis Ġvalid ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġclass ĠFake Shipping Methods Factory Ġ: ĠPayment Session Config . Shipping Methods Factory Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcreate ( shipping Information : ĠSh ipping Information ): ĠList < Shipping Method > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠSH IP PING _ METHO DS ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġclass ĠF ailing Shipping Information Validator Ġ: ĠPayment Session Config . Shipping Information Validator Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun ĠisValid ( shipping Information : ĠSh ipping Information ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġfalse ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget ErrorMessage ( shipping Information : ĠSh ipping Information ): ĠString Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠSH IP PING _ ERROR _ MESSAGE ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġclass ĠThrow ing Shipping Methods Factory Ġ: ĠPayment Session Config . Shipping Methods Factory Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcreate ( shipping Information : ĠSh ipping Information ): ĠList < Shipping Method > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠRuntimeException (" Always Ġthrows Ġan Ġexception ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠSH IP PING _ ERROR _ MESSAGE Ġ= Ġ" Shipping Ġinfo Ġwas Ġinvalid " ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠSH IP PING _ METHO DS Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSh ipping Method (" UP S ĠGround ", Ġ" ups - ground ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ 0 , Ġ" USD ", Ġ" Ar rives Ġin Ġ 3 - 5 Ġdays "), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSh ipping Method (" Fed Ex ", Ġ" fe dex ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ 5 9 9 , Ġ" USD ", Ġ" Ar rives Ġtomorrow ") ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} Ċ } Ċ