package Ġcom . stripe . android . model Ċ Ċ import Ġcom . stripe . android . model . Card Test . Companion . JSON _ CARD _ USD Ċ import Ġkotlin . test . Test Ċ import Ġkotlin . test . assertEquals Ċ import Ġkotlin . test . assertFalse Ċ import Ġkotlin . test . assertNotNull Ċ import Ġkotlin . test . assertNull Ċ import Ġkotlin . test . assertTrue Ċ import Ġorg . json . JSONException Ċ import Ġorg . json . JSONObject Ċ Ċ /** Ċ Ġ* ĠTest Ġclass Ġfor Ġ[ Customer ] Ġmodel Ġobject . Ċ Ġ*/ Ċ class ĠCustomer Test Ġ{ ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfrom String _ when String IsNull _ returns Null () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertNull ( Customer . fromString ( null )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfrom Json _ when Not AC ustom er _ returns Null () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertNull ( Customer . fromJson ( NON _ CUSTOMER _ OBJECT )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfrom Json _ when Customer _ returns Expected Customer () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcustomer Ġ= ĠCustomer Fixtures . CUSTOMER ĊĠĠĠĠĠĠĠ ĠassertNotNull ( customer ) ĊĠĠĠĠĠĠĠ ĠassertEquals (" cus _ AQ s H pv Kf Kw J Dr F ", Ġcustomer . id ) ĊĠĠĠĠĠĠĠ ĠassertEquals (" abc 1 2 3 ", Ġcustomer . default Source ) ĊĠĠĠĠĠĠĠ ĠassertNull ( customer . shipping Information ) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( customer . sources ) ĊĠĠĠĠĠĠĠ ĠassertEquals ("/ v 1 / customers / cus _ AQ s H pv Kf Kw J Dr F / sources ", Ġcustomer . url ) ĊĠĠĠĠĠĠĠ ĠassertFalse ( customer . hasMore ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 0 , Ġcustomer . total Count ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( JSONException :: class ) ĊĠĠĠ Ġfun Ġfrom Json _ when Customer Has Apple Pay _ returns Customer Without Apple Pay Sources () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcustomer Ġ= ĠCustomer . fromString ( create Test Customer Object With Apple Pay Source ()) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( customer ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġcustomer . sources . size ) ĊĠĠĠĠĠĠĠ Ġ// ĠNote Ġthat Ġfiltering Ġthe Ġapple _ pay Ġsources Ġintention ally Ġdoes Ġnot Ġchange Ġthe Ġtotal ĊĠĠĠĠĠĠĠ Ġ// Ġcount Ġvalue . ĊĠĠĠĠĠĠĠ ĠassertEquals ( 5 , Ġcustomer . total Count ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfrom Json _ creates Same Object () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġexpected Customer Ġ= ĠCustomer . fromJson ( Customer Fixtures . CUSTOMER _ JSON ) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( expected Customer ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġexpected Customer , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠCustomer . fromJson ( Customer Fixtures . CUSTOMER _ JSON ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Throws ( JSONException :: class ) ĊĠĠĠ Ġprivate Ġfun Ġcreate Test Customer Object With Apple Pay Source (): ĠString Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġraw Json Customer Ġ= ĠCustomer Fixtures . CUSTOMER _ JSON ĊĠĠĠĠĠĠĠ Ġval Ġsources Object Ġ= Ġraw Json Customer . getJSONObject (" sources ") ĊĠĠĠĠĠĠĠ Ġval Ġsources Array Ġ= Ġsources Object . get JSONArray (" data ") ĊĊĠĠĠĠĠĠĠ Ġsources Object . put (" total _ count ", Ġ 5 ) ĊĠĠĠĠĠĠĠ Ġsources Array . put ( Source Fixtures . APPLE _ PAY ) ĊĊĠĠĠĠĠĠĠ Ġval Ġmanip ulated Card Ġ= ĠJSONObject ( JSON _ CARD _ USD . toString ()) ĊĠĠĠĠĠĠĠ Ġmanip ulated Card . put (" id ", Ġ" card _ id 5 5 5 5 5 ") ĊĠĠĠĠĠĠĠ Ġmanip ulated Card . put (" token ization _ method ", Ġ" apple _ pay ") ĊĊĠĠĠĠĠĠĠ Ġ// ĠNote Ġthat Ġwe Ġdon 't Ġyet Ġexplicitly Ġsupport Ġbitcoin Ġsources , Ġbut Ġthis Ġdata Ġis ĊĠĠĠĠĠĠĠ Ġ// Ġconvenient Ġfor Ġthe Ġtest Ġbecause Ġit Ġis Ġnot Ġan Ġapple Ġpay Ġsource . ĊĠĠĠĠĠĠĠ Ġsources Array . put ( Source Test . EXAMPLE _ JSON _ SOURCE _ WITHOUT _ NULL S ) ĊĠĠĠĠĠĠĠ Ġsources Array . put ( Source Fixtures . AL IP AY _ JSON ) ĊĠĠĠĠĠĠĠ Ġsources Array . put ( JSONObject ( JSON _ CARD _ USD . toString ())) ĊĠĠĠĠĠĠĠ Ġsources Array . put ( manip ulated Card ) ĊĠĠĠĠĠĠĠ Ġsources Object . put (" data ", Ġsources Array ) ĊĊĠĠĠĠĠĠĠ Ġraw Json Customer . put (" sources ", Ġsources Object ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠVerify ĠJSON Ġmanipulation ĊĠĠĠĠĠĠĠ ĠassertTrue ( raw Json Customer . has (" sources ")) ĊĠĠĠĠĠĠĠ ĠassertTrue ( raw Json Customer . getJSONObject (" sources "). has (" data ")) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 5 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġraw Json Customer . getJSONObject (" sources "). get JSONArray (" data "). length ()) ĊĊĠĠĠĠĠĠĠ Ġreturn Ġraw Json Customer . toString () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠNON _ CUSTOMER _ OBJECT Ġ= ĠJSONObject ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ""" ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" object ": Ġ" not _ a _ customer ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" has _ more ": Ġfalse , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" total _ count ": Ġ 2 2 , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" url ": Ġ" http :// google . com " ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ""" . trim Indent () ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} Ċ } Ċ