/* Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 1 5 ĠSquare , ĠInc . Ċ Ġ* Ċ Ġ* Ġ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 Ġokhttp 3 Ċ Ċ import Ġjava . text . ParseException Ċ import Ġjava . text . SimpleDateFormat Ċ import Ġjava . util . Arrays Ċ import Ġjava . util . Date Ċ import Ġokhttp 3 . Cookie . Companion . parse Ċ import Ġokhttp 3 . Cookie . Companion . parse All Ċ import Ġokhttp 3 . Http Url . Companion . to Http Url Ċ import Ġokhttp 3 . internal . UTC Ċ import Ġokhttp 3 . internal . http . MAX _ DATE Ċ import Ġokhttp 3 . internal . parse Cookie Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Assertions . fail Ċ import Ġorg . junit . jupiter . api . Test Ċ Ċ class ĠCookie Test Ġ{ ĊĠ Ġval Ġurl Ġ= Ġ" https :// example . com / ". to Http Url () ĊĊĠ Ġ@ Test Ġfun Ġsimple Cookie () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= Ġparse ( url , Ġ" SID = 3 1 d 4 d 9 6 e 4 0 7 aad 4 2 ") ĊĠĠĠ ĠassertThat ( cookie . toString ()). isEqualTo (" SID = 3 1 d 4 d 9 6 e 4 0 7 aad 4 2 ; Ġpath =/ ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġno Equals Sign () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" foo ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" foo ; ĠPath =/ ")). isNull () ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġempty Name () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ"= b ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" Ġ= b ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url , Ġ"\ r \ t Ġ\ n = b ")). isNull () ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġspace In Name () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a Ġb = cd ") !!. name ). isEqualTo (" a Ġb ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġspace In Value () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" ab = c Ġd ") !!. value ). isEqualTo (" c Ġd ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġtrim Leading And Trailing Whitespace FromName () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" Ġa = b ") !!. name ). isEqualTo (" a ") ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a Ġ= b ") !!. name ). isEqualTo (" a ") ĊĠĠĠ ĠassertThat ( parse ( url , Ġ"\ r \ t Ġ\ na \ n \ t Ġ\ n = b ") !!. name ). isEqualTo (" a ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġempty Value () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a =") !!. value ). isEqualTo ("") ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = Ġ") !!. value ). isEqualTo ("") ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a =\ r \ t Ġ\ n ") !!. value ). isEqualTo ("") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġtrim Leading And Trailing Whitespace From Value () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = Ġ") !!. value ). isEqualTo ("") ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = Ġb ") !!. value ). isEqualTo (" b ") ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b Ġ") !!. value ). isEqualTo (" b ") ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a =\ r \ t Ġ\ nb \ n \ t Ġ\ n ") !!. value ). isEqualTo (" b ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġinvalid Characters () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a \ u 0 0 0 0 b = cd ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" ab = c \ u 0 0 0 0 d ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a \ u 0 0 0 1 b = cd ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" ab = c \ u 0 0 0 1 d ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a \ u 0 0 0 9 b = cd ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" ab = c \ u 0 0 0 9 d ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a \ u 0 0 1 fb = cd ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" ab = c \ u 0 0 1 fd ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a \ u 0 0 7 fb = cd ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" ab = c \ u 0 0 7 fd ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a \ u 0 0 8 0 b = cd ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" ab = c \ u 0 0 8 0 d ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a \ u 0 0 ffb = cd ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" ab = c \ u 0 0 ffd ")). isNull () ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġmax Age () Ġ{ ĊĠĠĠ ĠassertThat ( parse Cookie ( 5 0 0 0 0 L , Ġurl , Ġ" a = b ; ĠMax - Age = 1 ") !!. expires At ). isEqualTo ( 5 1 0 0 0 L ) ĊĠĠĠ ĠassertThat ( parse Cookie ( 5 0 0 0 0 L , Ġurl , Ġ" a = b ; ĠMax - Age = 9 2 2 3 3 7 2 0 3 6 8 5 4 7 2 4 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠĠĠ ĠassertThat ( parse Cookie ( 5 0 0 0 0 L , Ġurl , Ġ" a = b ; ĠMax - Age = 9 2 2 3 3 7 2 0 3 6 8 5 4 7 2 5 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠĠĠ ĠassertThat ( parse Cookie ( 5 0 0 0 0 L , Ġurl , Ġ" a = b ; ĠMax - Age = 9 2 2 3 3 7 2 0 3 6 8 5 4 7 2 6 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠĠĠ ĠassertThat ( parse Cookie ( 9 2 2 3 3 7 2 0 3 6 8 5 4 7 7 3 8 0 7 L , Ġurl , Ġ" a = b ; ĠMax - Age = 1 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠĠĠ ĠassertThat ( parse Cookie ( 9 2 2 3 3 7 2 0 3 6 8 5 4 7 7 3 8 0 7 L , Ġurl , Ġ" a = b ; ĠMax - Age = 2 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠĠĠ ĠassertThat ( parse Cookie ( 9 2 2 3 3 7 2 0 3 6 8 5 4 7 7 3 8 0 7 L , Ġurl , Ġ" a = b ; ĠMax - Age = 3 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠĠĠ ĠassertThat ( parse Cookie ( 5 0 0 0 0 L , Ġurl , Ġ" a = b ; ĠMax - Age = 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġmax Age Non Positive () Ġ{ ĊĠĠĠ ĠassertThat ( parse Cookie ( 5 0 0 0 0 L , Ġurl , Ġ" a = b ; ĠMax - Age =- 1 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( Long . MIN _ VALUE ) ĊĠĠĠ ĠassertThat ( parse Cookie ( 5 0 0 0 0 L , Ġurl , Ġ" a = b ; ĠMax - Age = 0 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( Long . MIN _ VALUE ) ĊĠĠĠ ĠassertThat ( parse Cookie ( 5 0 0 0 0 L , Ġurl , Ġ" a = b ; ĠMax - Age =- 9 2 2 3 3 7 2 0 3 6 8 5 4 7 7 5 8 0 8 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( Long . MIN _ VALUE ) ĊĠĠĠ ĠassertThat ( parse Cookie ( 5 0 0 0 0 L , Ġurl , Ġ" a = b ; ĠMax - Age =- 9 2 2 3 3 7 2 0 3 6 8 5 4 7 7 5 8 0 9 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( Long . MIN _ VALUE ) ĊĠĠĠ ĠassertThat ( parse Cookie ( 5 0 0 0 0 L , Ġurl , Ġ" a = b ; ĠMax - Age =- 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( Long . MIN _ VALUE ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġdomain And Path () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= Ġparse ( url , Ġ" SID = 3 1 d 4 d 9 6 e 4 0 7 aad 4 2 ; ĠPath =/ ; ĠDomain = example . com ") ĊĠĠĠ ĠassertThat ( cookie !!. domain ). isEqualTo (" example . com ") ĊĠĠĠ ĠassertThat ( cookie . path ). isEqualTo ("/") ĊĠĠĠ ĠassertThat ( cookie . host Only ). isFalse ĊĠĠĠ ĠassertThat ( cookie . toString ()). isEqualTo (" SID = 3 1 d 4 d 9 6 e 4 0 7 aad 4 2 ; Ġdomain = example . com ; Ġpath =/ ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġsecure And Http Only () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= Ġparse ( url , Ġ" SID = 3 1 d 4 d 9 6 e 4 0 7 aad 4 2 ; ĠPath =/ ; ĠSecure ; ĠHttp Only ") ĊĠĠĠ ĠassertThat ( cookie !!. secure ). isTrue ĊĠĠĠ ĠassertThat ( cookie . http Only ). isTrue ĊĠĠĠ ĠassertThat ( cookie . toString ()). isEqualTo (" SID = 3 1 d 4 d 9 6 e 4 0 7 aad 4 2 ; Ġpath =/ ; Ġsecure ; Ġhttp only ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġexpires Date () Ġ{ ĊĠĠĠ ĠassertThat ( Date ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 0 ĠGMT ") !!. expires At )) ĊĠĠĠĠĠ Ġ. isEqualTo ( date (" 1 9 7 0 - 0 1 - 0 1 T 0 0 : 0 0 : 0 0 . 0 0 0 + 0 0 0 0 ")) ĊĠĠĠ ĠassertThat ( Date ( parse ( url , Ġ" a = b ; ĠExp ires = Wed , Ġ 0 9 ĠJun Ġ 2 0 2 1 Ġ 1 0 : 1 8 : 1 4 ĠGMT ") !!. expires At )) ĊĠĠĠĠĠ Ġ. isEqualTo ( date (" 2 0 2 1 - 0 6 - 0 9 T 1 0 : 1 8 : 1 4 . 0 0 0 + 0 0 0 0 ")) ĊĠĠĠ ĠassertThat ( Date ( parse ( url , Ġ" a = b ; ĠExp ires = Sun , Ġ 0 6 ĠNov Ġ 1 9 9 4 Ġ 0 8 : 4 9 : 3 7 ĠGMT ") !!. expires At )) ĊĠĠĠĠĠ Ġ. isEqualTo ( date (" 1 9 9 4 - 1 1 - 0 6 T 0 8 : 4 9 : 3 7 . 0 0 0 + 0 0 0 0 ")) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġawk ward Dates () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠJan Ġ 7 0 Ġ 0 0 : 0 0 : 0 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( 0 L ) ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠJanuary Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( 0 L ) ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠJan uce m ber Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( 0 L ) ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 1 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( 0 L ) ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 0 : 0 0 : 0 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( 0 L ) ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 : 0 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( 0 L ) ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( 0 L ) ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = 0 0 : 0 0 : 0 0 ĠThu , Ġ 0 1 ĠJan Ġ 1 9 7 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( 0 L ) ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = 0 0 : 0 0 : 0 0 Ġ 1 9 7 0 ĠJan Ġ 0 1 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( 0 L ) ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = 0 0 : 0 0 : 0 0 Ġ 1 9 7 0 ĠJan Ġ 1 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( 0 L ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġinvalid Year () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠJan Ġ 1 6 0 0 Ġ 0 0 : 0 0 : 0 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠJan Ġ 1 9 9 9 9 Ġ 0 0 : 0 0 : 0 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠJan Ġ 0 0 : 0 0 : 0 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġinvalid Month () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠFoo Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠFoo cember Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġinvalid Day OfMonth () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 3 2 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġinvalid Hour () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 2 4 : 0 0 : 0 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġinvalid Minute () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 6 0 : 0 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġinvalid Second () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 6 0 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( MAX _ DATE ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġdomain Matches () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= Ġparse ( url , Ġ" a = b ; Ġdomain = example . com ") ĊĠĠĠ ĠassertThat ( cookie !!. matches (" http :// example . com ". to Http Url ())). isTrue ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// www . example . com ". to Http Url ())). isTrue ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// square . com ". to Http Url ())). isFalse ĊĠ Ġ} ĊĊĠ Ġ/** ĠIf Ġno Ġdomain Ġis Ġpresent , Ġmatch Ġonly Ġthe Ġorigin Ġdomain . Ġ Ġ*/ ĊĠ Ġ@ Test Ġfun Ġdomain Matches No Domain () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= Ġparse ( url , Ġ" a = b ") ĊĠĠĠ ĠassertThat ( cookie !!. matches (" http :// example . com ". to Http Url ())). isTrue ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// www . example . com ". to Http Url ())). isFalse ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// square . com ". to Http Url ())). isFalse ĊĠ Ġ} ĊĊĠ Ġ/** ĠIgnore Ġan Ġoptional Ġleading Ġ`. ` Ġin Ġthe Ġdomain . Ġ Ġ*/ ĊĠ Ġ@ Test Ġfun Ġdomain Matches Ig no res Leading Dot () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= Ġparse ( url , Ġ" a = b ; Ġdomain =. example . com ") ĊĠĠĠ ĠassertThat ( cookie !!. matches (" http :// example . com ". to Http Url ())). isTrue ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// www . example . com ". to Http Url ())). isTrue ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// square . com ". to Http Url ())). isFalse ĊĠ Ġ} ĊĊĠ Ġ/** ĠIgnore Ġthe Ġentire Ġattribute Ġif Ġthe Ġdomain Ġends Ġwith Ġ`. `. Ġ Ġ*/ ĊĠ Ġ@ Test Ġfun Ġdomain Ignored With Trailing Dot () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= Ġparse ( url , Ġ" a = b ; Ġdomain = example . com .") ĊĠĠĠ ĠassertThat ( cookie !!. matches (" http :// example . com ". to Http Url ())). isTrue ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// www . example . com ". to Http Url ())). isFalse ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// square . com ". to Http Url ())). isFalse ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġid n Domain Matches () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= Ġparse (" http :// âĺ ĥ . net / ". to Http Url (), Ġ" a = b ; Ġdomain = âĺ ĥ . net ") ĊĠĠĠ ĠassertThat ( cookie !!. matches (" http :// âĺ ĥ . net / ". to Http Url ())). isTrue ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// xn -- n 3 h . net / ". to Http Url ())). isTrue ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// www . âĺ ĥ . net / ". to Http Url ())). isTrue ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// www . xn -- n 3 h . net / ". to Http Url ())). isTrue ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġp un y code Domain Matches () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= Ġparse (" http :// xn -- n 3 h . net / ". to Http Url (), Ġ" a = b ; Ġdomain = xn -- n 3 h . net ") ĊĠĠĠ ĠassertThat ( cookie !!. matches (" http :// âĺ ĥ . net / ". to Http Url ())). isTrue ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// xn -- n 3 h . net / ". to Http Url ())). isTrue ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// www . âĺ ĥ . net / ". to Http Url ())). isTrue ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// www . xn -- n 3 h . net / ". to Http Url ())). isTrue ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġdomain Matches IpAddress () Ġ{ ĊĠĠĠ Ġval Ġurl With Ip Ġ= Ġ" http :// 1 2 3 . 4 5 . 2 3 4 . 5 6 / ". to Http Url () ĊĠĠĠ ĠassertThat ( parse ( url With Ip , Ġ" a = b ; Ġdomain = 2 3 4 . 5 6 ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( url With Ip , Ġ" a = b ; Ġdomain = 1 2 3 . 4 5 . 2 3 4 . 5 6 ") !!. domain ). isEqualTo (" 1 2 3 . 4 5 . 2 3 4 . 5 6 ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġdomain Matches Ipv 6 Address () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= Ġparse (" http :// [ :: 1 ]/ ". to Http Url (), Ġ" a = b ; Ġdomain = :: 1 ") ĊĠĠĠ ĠassertThat ( cookie !!. domain ). isEqualTo (" :: 1 ") ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// [ :: 1 ]/ ". to Http Url ())). isTrue ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġdomain Matches Ipv 6 Address With Compression () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= Ġparse (" http :// [ 0 0 0 1 : 0 0 0 0 :: ]/ ". to Http Url (), Ġ" a = b ; Ġdomain = 0 0 0 1 : 0 0 0 0 :: ") ĊĠĠĠ ĠassertThat ( cookie !!. domain ). isEqualTo (" 1 :: ") ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// [ 1 :: ]/ ". to Http Url ())). isTrue ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġdomain Matches Ipv 6 Address With Ipv 4 Suffix () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= Ġparse ( ĊĠĠĠĠĠ Ġ" http :// [ :: 1 : ffff : ffff ]/ ". to Http Url (), Ġ" a = b ; Ġdomain = :: 1 : 2 5 5 . 2 5 5 . 2 5 5 . 2 5 5 " ĊĠĠĠ Ġ) ĊĠĠĠ ĠassertThat ( cookie !!. domain ). isEqualTo (" :: 1 : ffff : ffff ") ĊĠĠĠ ĠassertThat ( cookie . matches (" http :// [ :: 1 : ffff : ffff ]/ ". to Http Url ())). isTrue ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġipv 6 Address Does nt Match () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= Ġparse (" http :// [ :: 1 ]/ ". to Http Url (), Ġ" a = b ; Ġdomain = :: 2 ") ĊĠĠĠ ĠassertThat ( cookie ). isNull () ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġipv 6 Address Malformed () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= Ġparse (" http :// [ :: 1 ]/ ". to Http Url (), Ġ" a = b ; Ġdomain = :: 2 :: 2 ") ĊĠĠĠ ĠassertThat ( cookie !!. domain ). isEqualTo (" :: 1 ") ĊĠ Ġ} ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠThese Ġpublic Ġsuffix es Ġwere Ġselected Ġby Ġinspect ing Ġthe Ġpublic suffix . org Ġlist . ĠIt 's Ġpossible Ġthey ĊĠĠ Ġ* Ġmay Ġchange Ġin Ġthe Ġfuture . ĠIf Ġthis Ġtest Ġbegins Ġto Ġfail , Ġplease Ġdouble Ġcheck Ġthey Ġare Ġstill ĊĠĠ Ġ* Ġpresent Ġin Ġthe Ġpublic Ġsuffix Ġlist . ĊĠĠ Ġ*/ ĊĠ Ġ@ Test Ġfun Ġdomain Is Public Suffix () Ġ{ ĊĠĠĠ Ġval Ġascii Ġ= Ġ" https :// foo 1 . foo . bar . el b . amazonaws . com ". to Http Url () ĊĠĠĠ ĠassertThat ( parse ( ascii , Ġ" a = b ; Ġdomain = foo . bar . el b . amazonaws . com ")). isNotNull ĊĠĠĠ ĠassertThat ( parse ( ascii , Ġ" a = b ; Ġdomain = bar . el b . amazonaws . com ")). isNull () ĊĠĠĠ ĠassertThat ( parse ( ascii , Ġ" a = b ; Ġdomain = com ")). isNull () ĊĠĠĠ Ġval Ġunicode Ġ= Ġ" https :// éķ· . éķ· . éķ· å´ İ . jp ". to Http Url () ĊĠĠĠ ĠassertThat ( parse ( unicode , Ġ" a = b ; Ġdomain = éķ· . éķ· å´ İ . jp ")). isNotNull ĊĠĠĠ ĠassertThat ( parse ( unicode , Ġ" a = b ; Ġdomain = éķ· å´ İ . jp ")). isNull () ĊĠĠĠ Ġval Ġp un y code Ġ= Ġ" https :// xn -- ue 5 a . xn -- ue 5 a . xn -- 8 ltr 6 2 k . jp ". to Http Url () ĊĠĠĠ ĠassertThat ( parse ( pun y code , Ġ" a = b ; Ġdomain = xn -- ue 5 a . xn -- 8 ltr 6 2 k . jp ")). isNotNull ĊĠĠĠ ĠassertThat ( parse ( pun y code , Ġ" a = b ; Ġdomain = xn -- 8 ltr 6 2 k . jp ")). isNull () ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġhost Only () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ") !!. host Only ). isTrue ĊĠĠĠ ĠassertThat ( ĊĠĠĠĠĠ Ġparse ( url , Ġ" a = b ; Ġdomain = example . com ") !!. host Only ĊĠĠĠ Ġ). isFalse ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġdefault Path () Ġ{ ĊĠĠĠ ĠassertThat ( parse (" http :// example . com / foo / bar ". to Http Url (), Ġ" a = b ") !!. path ). isEqualTo ("/ foo ") ĊĠĠĠ ĠassertThat ( parse (" http :// example . com / foo / ". to Http Url (), Ġ" a = b ") !!. path ). isEqualTo ("/ foo ") ĊĠĠĠ ĠassertThat ( parse (" http :// example . com / foo ". to Http Url (), Ġ" a = b ") !!. path ). isEqualTo ("/") ĊĠĠĠ ĠassertThat ( parse (" http :// example . com / ". to Http Url (), Ġ" a = b ") !!. path ). isEqualTo ("/") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġdefault Path Is Used If Path Does nt Have Leading Slash () Ġ{ ĊĠĠĠ ĠassertThat ( parse (" http :// example . com / foo / bar ". to Http Url (), Ġ" a = b ; Ġpath = qu ux ") !!. path ĊĠĠĠ Ġ). isEqualTo ("/ foo ") ĊĠĠĠ ĠassertThat ( parse (" http :// example . com / foo / bar ". to Http Url (), Ġ" a = b ; Ġpath =") !!. path ) ĊĠĠĠĠĠ Ġ. isEqualTo ("/ foo ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġpath Attribute Does nt Need To Match () Ġ{ ĊĠĠĠ ĠassertThat ( parse (" http :// example . com / ". to Http Url (), Ġ" a = b ; Ġpath =/ qu ux ") !!. path ) ĊĠĠĠĠĠ Ġ. isEqualTo ("/ qu ux ") ĊĠĠĠ ĠassertThat ( parse (" http :// example . com / foo / bar ". to Http Url (), Ġ" a = b ; Ġpath =/ qu ux ") !!. path ) ĊĠĠĠĠĠ Ġ. isEqualTo ("/ qu ux ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġhttp Only () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ") !!. http Only ). isFalse ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠHttp Only ") !!. http Only ). isTrue ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġsecure () Ġ{ ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ") !!. secure ). isFalse ĊĠĠĠ ĠassertThat ( parse ( url , Ġ" a = b ; ĠSecure ") !!. secure ). isTrue ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġmax Age T akes Pre cedence Over Expires () Ġ{ ĊĠĠĠ Ġ// ĠMax - Age Ġ= Ġ 1 , ĠExp ires Ġ= Ġ 2 . ĠIn Ġeither Ġorder . ĊĠĠĠ ĠassertThat ( parse Cookie ( 0 L , Ġurl , Ġ" a = b ; ĠMax - Age = 1 ; ĠExp ires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 2 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( 1 0 0 0 L ) ĊĠĠĠ ĠassertThat ( parse Cookie ( 0 L , Ġurl , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 2 ĠGMT ; ĠMax - Age = 1 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( 1 0 0 0 L ) ĊĠĠĠ Ġ// ĠMax - Age Ġ= Ġ 2 , ĠExp ires Ġ= Ġ 1 . ĠIn Ġeither Ġorder . ĊĠĠĠ ĠassertThat ( parse Cookie ( 0 L , Ġurl , Ġ" a = b ; ĠMax - Age = 2 ; ĠExp ires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 1 ĠGMT ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( 2 0 0 0 L ) ĊĠĠĠ ĠassertThat ( parse Cookie ( 0 L , Ġurl , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 1 ĠGMT ; ĠMax - Age = 2 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( 2 0 0 0 L ) ĊĠ Ġ} ĊĊĠ Ġ/** ĠIf Ġa Ġcookie Ġincorrectly Ġdefines Ġmultiple Ġ' Max - Age ' Ġattributes , Ġthe Ġlast Ġone Ġdefined Ġwins . Ġ Ġ*/ ĊĠ Ġ@ Test Ġfun Ġlast Max Age W ins () Ġ{ ĊĠĠĠ ĠassertThat ( parse Cookie ( 0 L , Ġurl , Ġ" a = b ; ĠMax - Age = 2 ; ĠMax - Age = 4 ; ĠMax - Age = 1 ; ĠMax - Age = 3 ") !!. expires At ) ĊĠĠĠĠĠ Ġ. isEqualTo ( 3 0 0 0 L ) ĊĠ Ġ} ĊĊĠ Ġ/** ĠIf Ġa Ġcookie Ġincorrectly Ġdefines Ġmultiple Ġ' Expires ' Ġattributes , Ġthe Ġlast Ġone Ġdefined Ġwins . Ġ Ġ*/ ĊĠ Ġ@ Test Ġfun Ġlast Expires At W ins () Ġ{ ĊĠĠĠ ĠassertThat ( ĊĠĠĠĠĠ Ġparse Cookie ( ĊĠĠĠĠĠĠĠĠ 0 L , Ġurl , Ġ" a = b ; Ġ" ĊĠĠĠĠĠĠĠ Ġ+ Ġ" Expires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 2 ĠGMT ; Ġ" ĊĠĠĠĠĠĠĠ Ġ+ Ġ" Expires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 4 ĠGMT ; Ġ" ĊĠĠĠĠĠĠĠ Ġ+ Ġ" Expires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 1 ĠGMT ; Ġ" ĊĠĠĠĠĠĠĠ Ġ+ Ġ" Expires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 3 ĠGMT " ĊĠĠĠĠĠ Ġ) !!. expires At ĊĠĠĠ Ġ). isEqualTo ( 3 0 0 0 L ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġmax Age Or Expires M akes Cookie Persistent () Ġ{ ĊĠĠĠ ĠassertThat ( parse Cookie ( 0 L , Ġurl , Ġ" a = b ") !!. persistent ). isFalse ĊĠĠĠ ĠassertThat ( parse Cookie ( 0 L , Ġurl , Ġ" a = b ; ĠMax - Age = 1 ") !!. persistent ). isTrue ĊĠĠĠ ĠassertThat ( parse Cookie ( 0 L , Ġurl , Ġ" a = b ; ĠExp ires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 1 ĠGMT ") !!. persistent ) ĊĠĠĠĠĠ Ġ. isTrue ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġparse All () Ġ{ ĊĠĠĠ Ġval Ġheaders Ġ= ĠHeaders . Builder () ĊĠĠĠĠĠ Ġ. add (" Set - Cookie : Ġa = b ") ĊĠĠĠĠĠ Ġ. add (" Set - Cookie : Ġc = d ") ĊĠĠĠĠĠ Ġ. build () ĊĠĠĠ Ġval Ġcookies Ġ= Ġparse All ( url , Ġheaders ) ĊĠĠĠ ĠassertThat ( cookies . size ). isEqualTo ( 2 ) ĊĠĠĠ ĠassertThat ( cookies [ 0 ]. toString ()). isEqualTo (" a = b ; Ġpath =/ ") ĊĠĠĠ ĠassertThat ( cookies [ 1 ]. toString ()). isEqualTo (" c = d ; Ġpath =/ ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġbuilder () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= ĠCookie . Builder () ĊĠĠĠĠĠ Ġ. name (" a ") ĊĠĠĠĠĠ Ġ. value (" b ") ĊĠĠĠĠĠ Ġ. domain (" example . com ") ĊĠĠĠĠĠ Ġ. build () ĊĠĠĠ ĠassertThat ( cookie . name ). isEqualTo (" a ") ĊĠĠĠ ĠassertThat ( cookie . value ). isEqualTo (" b ") ĊĠĠĠ ĠassertThat ( cookie . expires At ). isEqualTo ( MAX _ DATE ) ĊĠĠĠ ĠassertThat ( cookie . domain ). isEqualTo (" example . com ") ĊĠĠĠ ĠassertThat ( cookie . path ). isEqualTo ("/") ĊĠĠĠ ĠassertThat ( cookie . secure ). isFalse ĊĠĠĠ ĠassertThat ( cookie . http Only ). isFalse ĊĠĠĠ ĠassertThat ( cookie . persistent ). isFalse ĊĠĠĠ ĠassertThat ( cookie . host Only ). isFalse ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun ĠnewBuilder () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= Ġparse Cookie ( 0 L , Ġurl , Ġ" c = d ; ĠMax - Age = 1 ") !!. newBuilder () ĊĠĠĠĠĠ Ġ. name (" a ") ĊĠĠĠĠĠ Ġ. value (" b ") ĊĠĠĠĠĠ Ġ. domain (" example . com ") ĊĠĠĠĠĠ Ġ. expires At ( MAX _ DATE ) ĊĠĠĠĠĠ Ġ. build () ĊĠĠĠ ĠassertThat ( cookie . name ). isEqualTo (" a ") ĊĠĠĠ ĠassertThat ( cookie . value ). isEqualTo (" b ") ĊĠĠĠ ĠassertThat ( cookie . expires At ). isEqualTo ( MAX _ DATE ) ĊĠĠĠ ĠassertThat ( cookie . domain ). isEqualTo (" example . com ") ĊĠĠĠ ĠassertThat ( cookie . path ). isEqualTo ("/") ĊĠĠĠ ĠassertThat ( cookie . secure ). isFalse ĊĠĠĠ ĠassertThat ( cookie . http Only ). isFalse ĊĠĠĠ Ġ// Ġcan 't Ġbe Ġunset ĊĠĠĠ ĠassertThat ( cookie . persistent ). isTrue ĊĠĠĠ ĠassertThat ( cookie . host Only ). isFalse ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġbuilder Name Validation () Ġ{ ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ ĠCookie . Builder (). name (" Ġa Ġ") ĊĠĠĠĠĠ Ġfail < Any >() ĊĠĠĠ Ġ} Ġcatch Ġ( expected : ĠIllegalArgumentException ) Ġ{ ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġbuilder Value Validation () Ġ{ ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ ĠCookie . Builder (). value (" Ġb Ġ") ĊĠĠĠĠĠ Ġfail < Any >() ĊĠĠĠ Ġ} Ġcatch Ġ( expected : ĠIllegalArgumentException ) Ġ{ ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġbuilder Clamp s Max Date () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= ĠCookie . Builder () ĊĠĠĠĠĠ Ġ. name (" a ") ĊĠĠĠĠĠ Ġ. value (" b ") ĊĠĠĠĠĠ Ġ. host Only Domain (" example . com ") ĊĠĠĠĠĠ Ġ. expires At ( Long . MAX _ VALUE ) ĊĠĠĠĠĠ Ġ. build () ĊĠĠĠ ĠassertThat ( cookie . toString ()). isEqualTo (" a = b ; Ġexpires = Fri , Ġ 3 1 ĠDec Ġ 9 9 9 9 Ġ 2 3 : 5 9 : 5 9 ĠGMT ; Ġpath =/ ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġbuilder Expires At () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= ĠCookie . Builder () ĊĠĠĠĠĠ Ġ. name (" a ") ĊĠĠĠĠĠ Ġ. value (" b ") ĊĠĠĠĠĠ Ġ. host Only Domain (" example . com ") ĊĠĠĠĠĠ Ġ. expires At ( date (" 1 9 7 0 - 0 1 - 0 1 T 0 0 : 0 0 : 0 1 . 0 0 0 + 0 0 0 0 "). time ) ĊĠĠĠĠĠ Ġ. build () ĊĠĠĠ ĠassertThat ( cookie . toString ()). isEqualTo (" a = b ; Ġexpires = Thu , Ġ 0 1 ĠJan Ġ 1 9 7 0 Ġ 0 0 : 0 0 : 0 1 ĠGMT ; Ġpath =/ ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġbuilder Clamp s Min Date () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= ĠCookie . Builder () ĊĠĠĠĠĠ Ġ. name (" a ") ĊĠĠĠĠĠ Ġ. value (" b ") ĊĠĠĠĠĠ Ġ. host Only Domain (" example . com ") ĊĠĠĠĠĠ Ġ. expires At ( date (" 1 9 7 0 - 0 1 - 0 1 T 0 0 : 0 0 : 0 0 . 0 0 0 + 0 0 0 0 "). time ) ĊĠĠĠĠĠ Ġ. build () ĊĠĠĠ ĠassertThat ( cookie . toString ()). isEqualTo (" a = b ; Ġmax - age = 0 ; Ġpath =/ ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġbuilder Domain Validation () Ġ{ ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ ĠCookie . Builder (). host Only Domain (" a / b ") ĊĠĠĠĠĠ Ġfail < Any >() ĊĠĠĠ Ġ} Ġcatch Ġ( expected : ĠIllegalArgumentException ) Ġ{ ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġbuilder Domain () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= ĠCookie . Builder () ĊĠĠĠĠĠ Ġ. name (" a ") ĊĠĠĠĠĠ Ġ. value (" b ") ĊĠĠĠĠĠ Ġ. host Only Domain (" squareup . com ") ĊĠĠĠĠĠ Ġ. build () ĊĠĠĠ ĠassertThat ( cookie . domain ). isEqualTo (" squareup . com ") ĊĠĠĠ ĠassertThat ( cookie . host Only ). isTrue ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġbuilder Path () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= ĠCookie . Builder () ĊĠĠĠĠĠ Ġ. name (" a ") ĊĠĠĠĠĠ Ġ. value (" b ") ĊĠĠĠĠĠ Ġ. host Only Domain (" example . com ") ĊĠĠĠĠĠ Ġ. path ("/ foo ") ĊĠĠĠĠĠ Ġ. build () ĊĠĠĠ ĠassertThat ( cookie . path ). isEqualTo ("/ foo ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġbuilder Path Validation () Ġ{ ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ ĠCookie . Builder (). path (" foo ") ĊĠĠĠĠĠ Ġfail < Any >() ĊĠĠĠ Ġ} Ġcatch Ġ( expected : ĠIllegalArgumentException ) Ġ{ ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġbuilder Secure () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= ĠCookie . Builder () ĊĠĠĠĠĠ Ġ. name (" a ") ĊĠĠĠĠĠ Ġ. value (" b ") ĊĠĠĠĠĠ Ġ. host Only Domain (" example . com ") ĊĠĠĠĠĠ Ġ. secure () ĊĠĠĠĠĠ Ġ. build () ĊĠĠĠ ĠassertThat ( cookie . secure ). isTrue ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġbuilder Http Only () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= ĠCookie . Builder () ĊĠĠĠĠĠ Ġ. name (" a ") ĊĠĠĠĠĠ Ġ. value (" b ") ĊĠĠĠĠĠ Ġ. host Only Domain (" example . com ") ĊĠĠĠĠĠ Ġ. http Only () ĊĠĠĠĠĠ Ġ. build () ĊĠĠĠ ĠassertThat ( cookie . http Only ). isTrue ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġbuilder Ipv 6 () Ġ{ ĊĠĠĠ Ġval Ġcookie Ġ= ĠCookie . Builder () ĊĠĠĠĠĠ Ġ. name (" a ") ĊĠĠĠĠĠ Ġ. value (" b ") ĊĠĠĠĠĠ Ġ. domain (" 0 : 0 : 0 : 0 : 0 : 0 : 0 : 1 ") ĊĠĠĠĠĠ Ġ. build () ĊĠĠĠ ĠassertThat ( cookie . domain ). isEqualTo (" :: 1 ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġequals And HashCode () Ġ{ ĊĠĠĠ Ġval Ġcookie Strings Ġ= ĠArrays . asList ( ĊĠĠĠĠĠ Ġ" a = b ; ĠPath =/ c ; ĠDomain = example . com ; ĠMax - Age = 5 ; ĠSecure ; ĠHttp Only ", ĊĠĠĠĠĠ Ġ" a = Ġ; ĠPath =/ c ; ĠDomain = example . com ; ĠMax - Age = 5 ; ĠSecure ; ĠHttp Only ", ĊĠĠĠĠĠ Ġ" a = b ; ĠĠĠĠĠĠĠĠĠ ĠDomain = example . com ; ĠMax - Age = 5 ; ĠSecure ; ĠHttp Only ", ĊĠĠĠĠĠ Ġ" a = b ; ĠPath =/ c ; ĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠMax - Age = 5 ; ĠSecure ; ĠHttp Only ", ĊĠĠĠĠĠ Ġ" a = b ; ĠPath =/ c ; ĠDomain = example . com ; ĠĠĠĠĠĠĠĠĠĠĠ ĠSecure ; ĠHttp Only ", ĊĠĠĠĠĠ Ġ" a = b ; ĠPath =/ c ; ĠDomain = example . com ; ĠMax - Age = 5 ; ĠĠĠĠĠĠĠĠ ĠHttp Only ", ĊĠĠĠĠĠ Ġ" a = b ; ĠPath =/ c ; ĠDomain = example . com ; ĠMax - Age = 5 ; ĠSecure ; ĠĠĠĠĠĠĠĠ Ġ" ĊĠĠĠ Ġ) ĊĠĠĠ Ġfor Ġ( string A Ġin Ġcookie Strings ) Ġ{ ĊĠĠĠĠĠ Ġval Ġcookie A Ġ= Ġparse Cookie ( 0 , Ġurl , Ġstring A !! ) ĊĠĠĠĠĠ Ġfor Ġ( string B Ġin Ġcookie Strings ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcookie B Ġ= Ġparse Cookie ( 0 , Ġurl , Ġstring B !! ) ĊĠĠĠĠĠĠĠ Ġif Ġ( string A Ġ== Ġstring B ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( cookie B . hashCode ()). isEqualTo ( cookie A . hashCode ()) ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( cookie B ). isEqualTo ( cookie A ) ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( cookie B . hashCode ()). isNot EqualTo ( cookie A . hashCode (). to Long ()) ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( cookie B ). isNot EqualTo ( cookie A ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ ĠassertThat ( cookie A ). isNot EqualTo ( null ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Throws ( ParseException :: class ) Ġprivate Ġfun Ġdate ( s : ĠString ): ĠDate Ġ{ ĊĠĠĠ Ġval Ġformat Ġ= ĠSimpleDateFormat (" yyyy - MM - dd ' T ' HH : mm : ss . SS SZ ") ĊĠĠĠ Ġformat . time Zone Ġ= ĠUTC ĊĠĠĠ Ġreturn Ġformat . parse ( s ) ĊĠ Ġ} Ċ } Ċ