/* Ċ Ġ* Ġ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 Ċ Ġ* Ċ Ġ* Ġhttps :// 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 Ġcom . squareup . kotlin po et Ċ Ċ import Ġcom . google . common . io . Byte Streams Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġjava . net . URI Ċ import Ġjava . nio . charset . StandardCharsets . UTF _ 8 Ċ import Ġjavax . tools . Java FileObject . Kind Ċ import Ġkotlin . test . Test Ċ Ċ class ĠFile Reading Test Ġ{ ĊĠ Ġ@ Test Ġfun Ġjava FileObject Uri () Ġ{ ĊĠĠĠ Ġval Ġtype Ġ= ĠType Spec . class Builder (" Test "). build () ĊĠĠĠ ĠassertThat ( File Spec . get ("", Ġtype ). to Java FileObject (). to Uri ()) ĊĠĠĠĠĠ Ġ. isEqualTo ( URI . create (" Test . kt ")) ĊĠĠĠ ĠassertThat ( File Spec . get (" foo ", Ġtype ). to Java FileObject (). to Uri ()) ĊĠĠĠĠĠ Ġ. isEqualTo ( URI . create (" foo / Test . kt ")) ĊĠĠĠ ĠassertThat ( File Spec . get (" com . example ", Ġtype ). to Java FileObject (). to Uri ()) ĊĠĠĠĠĠ Ġ. isEqualTo ( URI . create (" com / example / Test . kt ")) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġjava FileObject Kind () Ġ{ ĊĠĠĠ Ġval Ġsource Ġ= ĠFile Spec . get ("", ĠType Spec . class Builder (" Test "). build ()) ĊĠĠĠ ĠassertThat ( source . to Java FileObject (). kind ). isEqualTo ( Kind . SOURCE ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġjava FileObject Character Content () Ġ{ ĊĠĠĠ Ġval Ġtype Ġ= ĠType Spec . class Builder (" Test ") ĊĠĠĠĠĠ Ġ. add K doc (" Pi \ u 0 0 f 1 ata \ u 0 0 a 1 ") ĊĠĠĠĠĠ Ġ. addFunction ( Fun Spec . builder (" foo Bar "). build ()) ĊĠĠĠĠĠ Ġ. build () ĊĠĠĠ Ġval Ġsource Ġ= ĠFile Spec . get (" foo ", Ġtype ) ĊĠĠĠ Ġval Ġjava FileObject Ġ= Ġsource . to Java FileObject () ĊĊĠĠĠ Ġ// ĠWe Ġcan Ġnever Ġhave Ġencoding Ġissues Ġ( everything Ġis Ġin Ġprocess ) ĊĠĠĠ ĠassertThat ( java FileObject . get Char Content ( true )). isEqualTo ( source . toString ()) ĊĠĠĠ ĠassertThat ( java FileObject . get Char Content ( false )). isEqualTo ( source . toString ()) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġjava FileObject InputStream Is Utf 8 () Ġ{ ĊĠĠĠ Ġval Ġsource Ġ= ĠFile Spec . builder (" foo ", Ġ" Test ") ĊĠĠĠĠĠ Ġ. add Type ( Type Spec . class Builder (" Test "). build ()) ĊĠĠĠĠĠ Ġ. add Comment (" Pi \ u 0 0 f 1 ata \ u 0 0 a 1 ") ĊĠĠĠĠĠ Ġ. build () ĊĠĠĠ Ġval Ġbytes Ġ= ĠByte Streams . toByteArray ( source . to Java FileObject (). open InputStream ()) ĊĊĠĠĠ Ġ// ĠKotlin Po et Ġalways Ġuses ĠUTF - 8 . ĊĠĠĠ ĠassertThat ( bytes ). isEqualTo ( source . toString (). toByteArray ( UTF _ 8 )) ĊĠ Ġ} Ċ } Ċ