/* Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 2 0 Ġ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 . compare Ċ Ċ import Ġokhttp 3 . mock webserver . Mock Response Ċ import Ġokhttp 3 . mock webserver . Mock WebServer Ċ import Ġorg . apache . hc . client 5 . http . classic . methods . HttpGet Ċ import Ġorg . apache . hc . client 5 . http . impl . classic . HttpClient s Ċ import Ġorg . apache . hc . core 5 . http . io . entity . Entity Utils Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ Ċ /** Ċ Ġ* ĠApache ĠHttpClient Ġ 5 . x . Ċ Ġ* Ċ Ġ* Ġhttps :// hc . apache . org / http components - client - 5 . 0 . x / index . html Ċ Ġ*/ Ċ class ĠApache HttpClient Test Ġ{ ĊĠ Ġ@ Jvm Field Ġ@ Rule Ġval Ġserver Ġ= ĠMock WebServer () ĊĊĠ Ġprivate Ġval ĠhttpClient Ġ= ĠHttpClient s . create Default () ĊĊĠ Ġ@ After Ġfun ĠtearDown () Ġ{ ĊĠĠĠ ĠhttpClient . close () ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġget () Ġ{ ĊĠĠĠ Ġserver . enqueue ( Mock Response () ĊĠĠĠĠĠĠĠ Ġ. set Body (" hello , ĠApache ĠHttpClient Ġ 5 . x ")) ĊĊĠĠĠ Ġval Ġrequest Ġ= ĠHttp Get ( server . url ("/ "). to Uri ()) ĊĠĠĠ Ġrequest . add Header (" Accept ", Ġ" text / plain ") ĊĊĠĠĠ ĠhttpClient . execute ( request ). use Ġ{ Ġresponse Ġ-> ĊĠĠĠĠĠ ĠassertThat ( response . code ). isEqualTo ( 2 0 0 ) ĊĠĠĠĠĠ ĠassertThat ( Entity Utils . toString ( response . entity )). isEqualTo (" hello , ĠApache ĠHttpClient Ġ 5 . x ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġrecorded Ġ= Ġserver . take Request () ĊĠĠĠ ĠassertThat ( re corded . getHeader (" Accept ")). isEqualTo (" text / plain ") ĊĠĠĠ ĠassertThat ( re corded . getHeader (" Accept - Encoding ")). isEqualTo (" gzip , Ġx - gzip , Ġdef late ") ĊĠĠĠ ĠassertThat ( re corded . getHeader (" Connection ")). isEqualTo (" keep - alive ") ĊĠĠĠ ĠassertThat ( re corded . getHeader (" User - Agent ")). startsWith (" Apache - HttpClient / 5 . 0 ") ĊĠ Ġ} Ċ } Ċ