/* Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 2 1 Ġ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 Ġapp . cash . zi pline Ċ Ċ import Ġapp . cash . zi pline . internal . console Name Ċ import Ġapp . cash . zi pline . internal . event Loop Name Ċ import Ġapp . cash . zi pline . internal . js Platform Name Ċ import Ġapp . cash . zi pline . testing . Echo Request Ċ import Ġapp . cash . zi pline . testing . Echo Response Ċ import Ġapp . cash . zi pline . testing . Echo Service Ċ import Ġapp . cash . zi pline . testing . hello Service Ċ import Ġapp . cash . zi pline . testing . js Sus pending Echo Service Ċ import Ġapp . cash . zi pline . testing . prepare Sus pending Jvm B rid ges Ċ import Ġapp . cash . zi pline . testing . yo Service Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġkotlinx . coroutines . test . Test Coroutine Dispatcher Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ Ċ @ Opt In ( Experimental Cor outines Api :: class ) Ċ class ĠZ i pline Test Ġ{ ĊĠ Ġprivate Ġval Ġdispatcher Ġ= ĠTest Coroutine Dispatcher () ĊĠ Ġprivate Ġval Ġz i pline Ġ= ĠZ i pline . create ( dispatcher ) ĊĊĠ Ġ@ Before Ġfun ĠsetUp (): ĠUnit Ġ= Ġrun Blocking ( dispatcher ) Ġ{ ĊĠĠĠ Ġz i pline . load Testing Js () ĊĠ Ġ} ĊĊĠ Ġ@ After Ġfun ĠtearDown (): ĠUnit Ġ= Ġrun Blocking ( dispatcher ) Ġ{ ĊĠĠĠ Ġz i pline . close () ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġcannot Get Or Set Service After Close (): ĠUnit Ġ= Ġrun Blocking ( dispatcher ) Ġ{ ĊĠĠĠ Ġz i pline . close () ĊĠĠĠ ĠassertThat ( assert Throws < IllegalStateException > Ġ{ ĊĠĠĠĠĠ Ġz i pline . get < Echo Service >(" hello Service ") ĊĠĠĠ Ġ}) ĊĠĠĠ ĠassertThat ( assert Throws < IllegalStateException > Ġ{ ĊĠĠĠĠĠ Ġz i pline . set < Echo Service >(" sup Service ", ĠJ vm Echo Service (" sup ")) ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġcall Service After Close Fails Grace fully (): ĠUnit Ġ= Ġrun Blocking ( dispatcher ) Ġ{ ĊĠĠĠ Ġz i pline . quick Js . evaluate (" testing . app . cash . zi pline . testing . prepare Js B rid ges () ") ĊĠĠĠ Ġval Ġservice Ġ= Ġz i pline . hello Service ĊĊĠĠĠ Ġz i pline . close () ĊĠĠĠ ĠassertThat ( assert Throws < IllegalStateException > Ġ{ ĊĠĠĠĠĠ Ġservice . echo ( Echo Request (" J ake ")) ĊĠĠĠ Ġ}). has Message That (). isEqualTo (" Zi pline Ġclosed ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġj vm Call Js Service (): ĠUnit Ġ= Ġrun Blocking ( dispatcher ) Ġ{ ĊĠĠĠ Ġz i pline . quick Js . evaluate (" testing . app . cash . zi pline . testing . prepare Js B rid ges () ") ĊĊĠĠĠ ĠassertThat ( zi pline . hello Service . echo ( Echo Request (" J ake "))) ĊĠĠĠĠĠ Ġ. isEqualTo ( Echo Response (" hello Ġfrom ĠJavaScript , ĠJ ake ")) ĊĠĠĠ ĠassertThat ( zi pline . yo Service . echo ( Echo Request (" K evin "))) ĊĠĠĠĠĠ Ġ. isEqualTo ( Echo Response (" yo Ġfrom ĠJavaScript , ĠKevin ")) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġjs Call Jvm Service (): ĠUnit Ġ= Ġrun Blocking ( dispatcher ) Ġ{ ĊĠĠĠ Ġz i pline . set < Echo Service >(" sup Service ", ĠJ vm Echo Service (" sup ")) ĊĊĠĠĠ ĠassertThat ( zi pline . quick Js . evaluate (" testing . app . cash . zi pline . testing . call Sup Service (' hom ie ') ")) ĊĠĠĠĠĠ Ġ. isEqualTo (" JavaScript Ġreceived Ġ' sup Ġfrom Ġthe ĠJVM , Ġhom ie ' Ġfrom Ġthe ĠJVM ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġj vm Call Js Service That Throws (): ĠUnit Ġ= Ġrun Blocking ( dispatcher ) Ġ{ ĊĠĠĠ Ġz i pline . quick Js . evaluate (" testing . app . cash . zi pline . testing . prepare Throw ing Js B rid ges () ") ĊĊĠĠĠ ĠassertThat ( assert Throws < Exception > Ġ{ ĊĠĠĠĠĠ Ġz i pline . hello Service . echo ( Echo Request (" J ake ")) ĊĠĠĠ Ġ}). has Message That (). contains (" boom !") Ġ// Ġ' IllegalStateException ' Ġprefix Ġlost Ġwhen Ġwe Ġmin ify ĠJS . ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġjs Call Jvm Service That Throws (): ĠUnit Ġ= Ġrun Blocking ( dispatcher ) Ġ{ ĊĠĠĠ Ġz i pline . set < Echo Service >(" sup Service ", ĠJ vm Throw ing Echo Service ()) ĊĊĠĠĠ ĠassertThat ( assert Throws < Quick Js Exception > Ġ{ ĊĠĠĠĠĠ Ġz i pline . quick Js . evaluate (" testing . app . cash . zi pline . testing . call Sup Service (' hom ie ') ") ĊĠĠĠ Ġ}). has Message That (). contains (" java . lang . IllegalStateException : Ġbo om !") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġsus pending Jvm Call Js Service (): ĠUnit Ġ= Ġrun Blocking ( dispatcher ) Ġ{ ĊĠĠĠ Ġz i pline . quick Js . evaluate (" testing . app . cash . zi pline . testing . prepare Sus pending Js B rid ges () ") ĊĊĠĠĠ ĠassertThat ( zi pline . js Sus pending Echo Service . sus pending Echo ( Echo Request (" J ake "))) ĊĠĠĠĠĠ Ġ. isEqualTo ( Echo Response (" hello Ġfrom Ġsus pending ĠJavaScript , ĠJ ake ")) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġsus pending Js Call Jvm Service (): ĠUnit Ġ= Ġrun Blocking ( dispatcher ) Ġ{ ĊĠĠĠ Ġprepare Sus pending Jvm B rid ges ( zi pline ) ĊĊĠĠĠ Ġz i pline . quick Js . evaluate (" testing . app . cash . zi pline . testing . call Sus pending Echo Service (' E ric ') ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġservice Names And Client Names (): ĠUnit Ġ= Ġrun Blocking ( dispatcher ) Ġ{ ĊĠĠĠ ĠassertThat ( zi pline . service Names ). contains Exactly ( ĊĠĠĠĠĠ Ġevent Loop Name , ĊĠĠĠĠĠ Ġconsole Name , ĊĠĠĠ Ġ) ĊĠĠĠ ĠassertThat ( zi pline . client Names ). contains Exactly ( ĊĠĠĠĠĠ Ġjs Platform Name , ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġz i pline . quick Js . evaluate (" testing . app . cash . zi pline . testing . prepare Js B rid ges () ") ĊĠĠĠ ĠassertThat ( zi pline . service Names ). contains Exactly ( ĊĠĠĠĠĠ Ġevent Loop Name , ĊĠĠĠĠĠ Ġconsole Name , ĊĠĠĠ Ġ) ĊĠĠĠ ĠassertThat ( zi pline . client Names ). contains Exactly ( ĊĠĠĠĠĠ Ġjs Platform Name , ĊĠĠĠĠĠ Ġ" hello Service ", ĊĠĠĠĠĠ Ġ" yo Service ", ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġz i pline . set < Echo Service >(" sup Service ", ĠJ vm Echo Service (" sup ")) ĊĠĠĠ ĠassertThat ( zi pline . service Names ). contains Exactly ( ĊĠĠĠĠĠ Ġevent Loop Name , ĊĠĠĠĠĠ Ġconsole Name , ĊĠĠĠĠĠ Ġ" sup Service ", ĊĠĠĠ Ġ) ĊĠĠĠ ĠassertThat ( zi pline . client Names ). contains Exactly ( ĊĠĠĠĠĠ Ġjs Platform Name , ĊĠĠĠĠĠ Ġ" hello Service ", ĊĠĠĠĠĠ Ġ" yo Service ", ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġclass ĠJ vm Echo Service ( private Ġval Ġg reeting : ĠString ) Ġ: ĠEcho Service Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġecho ( request : ĠEcho Request ): ĠEcho Response Ġ{ ĊĠĠĠĠĠ Ġreturn ĠEcho Response ("$ greeting Ġfrom Ġthe ĠJVM , Ġ${ request . message }") ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġclass ĠJ vm Throw ing Echo Service Ġ: ĠEcho Service Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġecho ( request : ĠEcho Request ): ĠEcho Response Ġ{ ĊĠĠĠĠĠ Ġthrow ĠIllegalStateException (" boom !") ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ