package Ġtest helpers . extensions Ċ Ċ import Ġcom . google . gson . Gson Ċ import Ġcom . google . gson . Gson Builder Ċ import Ġcom . google . gson . JsonObject Ċ import Ġio . kot est . assertions . assertion Counter Ċ import Ġio . kot est . assertions . collect OrThrow Ċ import Ġio . kot est . assertions . eq . eq Ċ import Ġio . kot est . assertions . error Collector Ċ import Ġokhttp 3 . mock webserver . Mock Response Ċ Ċ fun ĠString . to Comparable Json () Ġ= Ġtry Ġ{ ĊĠĠĠ ĠGson (). fromJson ( this , ĠJsonObject :: class . java ). toString () Ċ } Ġcatch Ġ( e : ĠException ) Ġ{ ĊĠĠĠ Ġthrow ĠIllegalArgumentException ("' $ this ' Ġwasn 't Ġvalid ĠJSON ") Ċ } Ċ Ċ fun ĠString . to Comparable Json Pretty (): ĠString Ġ= Ġtry Ġ{ ĊĠĠĠ Ġval Ġgson Ġ= ĠGson Builder (). set Pretty Print ing (). create () ĊĠĠĠ Ġval Ġobj Ġ= Ġgson . fromJson ( this , ĠJsonObject :: class . java ) ĊĠĠĠ Ġgson . toJson ( obj ) Ċ } Ġcatch Ġ( e : ĠException ) Ġ{ ĊĠĠĠ Ġthrow ĠIllegalArgumentException ("' $ this ' Ġwasn 't Ġvalid ĠJSON ") Ċ } Ċ Ċ @ Suppress (" UN CHECK ED _ CAST ") Ċ infix Ġfun ĠString . should Match Json ( expected : ĠString ) Ġ{ ĊĠĠĠ Ġval Ġactual Pretty Ġ= Ġthis . to Comparable Json Pretty () ĊĠĠĠ Ġval Ġexpected Pretty Ġ= Ġexpected . to Comparable Json Pretty () ĊĊĠĠĠ Ġassertion Counter . inc () ĊĠĠĠ Ġeq ( actual Pretty , Ġexpected Pretty )?. let ( error Collector :: collect OrThrow ) Ċ } Ċ Ċ fun ĠString . toJson Response (): ĠMock Response Ġ= ĠMock Response (). set Body ( this . to Comparable Json ()) Ċ