package Ġorg . http 4 k . lens Ċ Ċ import Ġcom . nat pr y ce . ham k rest . assertion . assertThat Ċ import Ġcom . nat pr y ce . ham k rest . equalTo Ċ import Ġcom . nat pr y ce . ham k rest . throws Ċ import Ġorg . http 4 k . core . Method Ċ import Ġorg . http 4 k . core . Method . GET Ċ import Ġorg . http 4 k . core . Request Ċ import Ġorg . http 4 k . core . Uri Ċ import Ġorg . http 4 k . core . with Ċ import Ġorg . junit . Test Ċ import Ġjava . time . LocalDate Ċ import Ġjava . time . LocalDateTime Ċ import Ġjava . time . Zone Id Ċ import Ġjava . time . Z onedDateTime Ċ import Ġjava . util .* Ċ Ċ class ĠPath Test Ġ{ ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` fixed Ġvalue Ġpresent `() Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( Path . fixed (" hello ") (" hello "), ĠequalTo (" hello ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` fixed Ġvalue Ġmismatch `() Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ({ Ġ( Path . fixed (" hello ")) (" world ") Ġ}, Ġthrows ( lens Failure With ( overall Type Ġ= ĠFailure . Type . Invalid ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` fixed ĠtoString `() Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( Path . fixed (" hello "). toString (), ĠequalTo (" hello ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` value Ġpresent `() Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( Path . of (" hello ") (" world "), ĠequalTo (" world ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( Path . map Ġ{ Ġit . length Ġ}. of (" hello ") (" world "), ĠequalTo ( 5 )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` value Ġpresent Ġin Ġrequest Ġwhen Ġit Ġhas Ġbeen Ġpre - parsed `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtarget Ġ= ĠRequest ( Method . GET , Ġ"/ some / world "). header (" x - uri - template ", Ġ"/ some /{ hello }") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( Path . of (" hello ")( target ), ĠequalTo (" world ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( Path . of (" hello "). extract ( target ), ĠequalTo (" world ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( Path . map Ġ{ Ġit . length Ġ}. of (" hello ")( target ), ĠequalTo ( 5 )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` invalid Ġvalue `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpath Ġ= ĠPath . map ( String :: toInt ). of (" hello ") ĊĠĠĠĠĠĠĠ ĠassertThat ({ Ġpath (" world ") Ġ}, Ġthrows ( lens Failure With ( Invalid ( path . meta ), Ġoverall Type Ġ= ĠFailure . Type . Invalid ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` can Ġcreate Ġa Ġcustom Ġtype Ġand Ġget Ġit `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpath Ġ= ĠPath . map (:: My Custom Body Type ). of (" bob ") ĊĠĠĠĠĠĠĠ ĠassertThat ( path (" hello Ġworld ! "), ĠequalTo ( My Custom Body Type (" hello Ġworld ! "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` sets Ġvalue Ġon Ġrequest Ġuri Ġwith Ġproper Ġencoding `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpath Param Ġ= ĠPath . string (). of (" bob ") ĊĠĠĠĠĠĠĠ Ġval Ġupdated Ġ= ĠRequest ( GET , ĠUri . of (" http :// bob . com / first /{ bob }/ second ")). with ( path Param Ġof Ġ" 1 2 3 Ġ 4 5 6 ") ĊĠĠĠĠĠĠĠ ĠassertThat ( updated , ĠequalTo ( Request ( GET , Ġ" http :// bob . com / first / 1 2 3 + 4 5 6 / second "))) ĊĠĠĠĠĠĠĠ ĠassertThat ( path Param (" 1 2 3 + 4 5 6 "), ĠequalTo (" 1 2 3 Ġ 4 5 6 ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` toString Ġis Ġok `() Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( Path . of (" hello "). toString (), ĠequalTo ("{ hello } ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` int `() Ġ= Ġcheck Contract ( Path . int (), Ġ" 1 2 3 ", Ġ 1 2 3 ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` long `() Ġ= Ġcheck Contract ( Path . long (), Ġ" 1 2 3 ", Ġ 1 2 3 ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` float `() Ġ= Ġcheck Contract ( Path . float (), Ġ" 1 2 3 . 0 ", Ġ 1 2 3 f ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` double `() Ġ= Ġcheck Contract ( Path . double (), Ġ" 1 2 3 . 0 ", Ġ 1 2 3 . 0 ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` local Ġdate `() Ġ= Ġcheck Contract ( Path . local Date (), Ġ" 2 0 0 1 - 0 1 - 0 1 ", ĠLocalDate . of ( 2 0 0 1 , Ġ 1 , Ġ 1 )) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` uuid `() Ġ= Ġcheck Contract ( Path . uuid (), Ġ" f 5 fc 0 a 3 f - ecb 5 - 4 ab 3 - bc 7 5 - 1 8 5 1 6 5 dc 4 8 4 4 ", ĠUUID . fromString (" f 5 fc 0 a 3 f - ecb 5 - 4 ab 3 - bc 7 5 - 1 8 5 1 6 5 dc 4 8 4 4 ")) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` regex `() Ġ= Ġcheck Contract ( Path . regex (" v (\\ d + )", Ġ 1 ), Ġ" v 1 2 3 ", Ġ" 1 2 3 ") ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` boolean `() Ġ{ ĊĠĠĠĠĠĠĠ Ġcheck Contract ( Path . boolean (), Ġ" true ", Ġtrue ) ĊĠĠĠĠĠĠĠ Ġcheck Contract ( Path . boolean (), Ġ" false ", Ġfalse ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` datetime `() Ġ= Ġcheck Contract ( Path . dateTime (), Ġ" 2 0 0 1 - 0 1 - 0 1 T 0 2 : 0 3 : 0 4 ", ĠLocalDateTime . of ( 2 0 0 1 , Ġ 1 , Ġ 1 , Ġ 2 , Ġ 3 , Ġ 4 )) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` zon ed Ġdatetime `() Ġ= Ġcheck Contract ( Path . zon ed DateTime (), Ġ" 1 9 7 0 - 0 1 - 0 1 T 0 0 : 0 0 : 0 0 Z [ UTC ]", ĠZ onedDateTime . of ( 1 9 7 0 , Ġ 1 , Ġ 1 , Ġ 0 , Ġ 0 , Ġ 0 , Ġ 0 , ĠZone Id . of (" UTC "))) ĊĊĠĠĠ Ġprivate Ġfun Ġ< T > Ġcheck Contract ( Path : ĠPath Lens Spec < T >, Ġvalue AsString : ĠString , Ġt Value : ĠT ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrequired Lens Ġ= ĠPath . of (" hello ") ĊĠĠĠĠĠĠĠ ĠassertThat ( required Lens ( value AsString ), ĠequalTo ( t Value )) ĊĠĠĠĠĠĠĠ ĠassertThat ({ Ġrequired Lens (" hello ") Ġ}, Ġthrows ( lens Failure With ( Invalid ( required Lens . meta ), Ġoverall Type Ġ= ĠFailure . Type . Invalid ))) ĊĠĠĠ Ġ} Ċ }