/* Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 2 1 ĠThe ĠAndroid ĠOpen ĠSource ĠProject Ċ Ġ* Ċ Ġ* Ġ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 Ġcom . android . build . at tribution Ċ Ċ import Ġcom . android . build . at tribution . data . Gradle Plugins Data Ċ import Ġcom . android . utils . FileUtils Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġcom . intellij . openapi . util . Pair Ċ import Ġcom . intellij . test Framework . Application Rule Ċ import Ġcom . intellij . util . download . File Downloader Ċ import Ġcom . intellij . util . download . impl . Download able File Description Impl Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . rules . Temporary Folder Ċ import Ġorg . mockito . Argument Matchers Ċ import Ġorg . mockito . Mockito Ċ import Ġjava . io . File Ċ import Ġjava . io . IOException Ċ Ċ class ĠKnown Gradle Plugins ServiceImpl Test Ġ{ ĊĠ Ġ@ get : Rule ĊĠ Ġval Ġapplication Rule Ġ= ĠApplication Rule () ĊĊĠ Ġ@ get : Rule ĊĠ Ġval Ġtemporary Folder Ġ= ĠTemporary Folder () ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Local Gradle Plugins Service Par ses File Correct ly () Ġ{ ĊĠĠĠ Ġval Ġdata Ġ= ĠLocal Known Gradle Plugins ServiceImpl (). gradle Plugins Data ĊĊĠĠĠ ĠassertThat ( data ). isNot EqualTo ( Gradle Plugins Data . empty Data ) ĊĠĠĠ ĠassertThat ( data . plugins Info ). has Size ( 2 5 ) ĊĠĠĠ ĠassertThat ( data . plugins Info . filter Ġ{ Ġit . configuration Caching Compatible From Ġ== Ġnull Ġ}). has Size ( 3 ) ĊĠĠĠ ĠassertThat ( data . plugins Info . filter Ġ{ Ġit . plugin Artifact Ġ== Ġnull Ġ}). isEmpty () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Gets Downloaded File () Ġ{ ĊĠĠĠ Ġval Ġfile Content Ġ= Ġ""" Ċ { ĊĠ Ġ" plugins Info ": Ġ[ ĊĠĠĠ Ġ{ ĊĠĠĠĠĠ Ġ" plugin Class Prefixes ": Ġ[ ĊĠĠĠĠĠĠĠ Ġ" my . plugin . plugin A ", ĊĠĠĠĠĠĠĠ Ġ" my . plugin . plugin B " ĊĠĠĠĠĠ Ġ], ĊĠĠĠĠĠ Ġ" name ": Ġ" My Plugin ", ĊĠĠĠĠĠ Ġ" plugin Description ": Ġ" Fake Ġtest Ġplugin Ġdescription .< br /> ", ĊĠĠĠĠĠ Ġ" plugin Contact Instructions ": Ġ"< a Ġhref =' link To Plugin Repo '> Plugin Ġrepository </ a >", ĊĠĠĠĠĠ Ġ" plugin Artifact ": Ġ" org . my : gradle - plugin ", ĊĠĠĠĠĠ Ġ" configuration Caching Compatible From ": Ġ" 1 . 0 . 0 " ĊĠĠĠ Ġ} ĊĠ Ġ] Ċ } ĊĠĠĠ Ġ""" . trim Indent () ĊĠĠĠ Ġval Ġoutput Dir Ġ= Ġtemporary Folder . new Folder () ĊĠĠĠ Ġval ĠfileName Ġ= Ġ" plugins _ data . json " ĊĠĠĠ Ġval Ġdistribution File Ġ= ĠFileUtils . join ( output Dir , ĠfileName ) ĊĠĠĠ Ġval Ġlocal Cache Ġ= ĠFileUtils . join ( output Dir , Ġ" cache ") ĊĊĠĠĠ Ġdistribution File . parent File . mkdir s () ĊĠĠĠ Ġdistribution File . write Text ( file Content ) ĊĊĠĠĠ Ġval Ġdistribution Url Ġ= Ġdistribution File . to URI (). to URL () ĊĠĠĠ Ġval Ġdownload able File Description Ġ= ĠDownload able File Description Impl ( distribution Url . toString (), ĠfileName , Ġ" json ") ĊĊĠĠĠ Ġval Ġdown loader Ġ= ĠMockito . mock ( File Downloader :: class . java ) ĊĠĠĠ ĠMockito .` when `( downloader . download ( Argument Matchers . any ( File :: class . java ))) ĊĠĠĠĠĠ Ġ. thenReturn ( listOf ( Pair ( distribution File , Ġdownload able File Description ))) ĊĊĠĠĠ Ġval Ġservice Ġ= ĠKnown Gradle Plugins ServiceImpl ( downloader , Ġlocal Cache ) ĊĠĠĠ Ġservice . refresh S ynchronously () ĊĠĠĠ ĠassertThat ( service . gradle Plugins Data ). isNot EqualTo ( Gradle Plugins Data . empty Data ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Download Failure () Ġ{ ĊĠĠĠ Ġval Ġoutput Dir Ġ= Ġtemporary Folder . new Folder () ĊĠĠĠ Ġval Ġlocal Cache Ġ= ĠFileUtils . join ( output Dir , Ġ" cache ") ĊĠĠĠ Ġval Ġdown loader Ġ= ĠMockito . mock ( File Downloader :: class . java ) ĊĠĠĠ ĠMockito .` when `( downloader . download ( Argument Matchers . any ( File :: class . java ))) ĊĠĠĠĠĠ Ġ. then Throw ( IOException ()) ĊĊĠĠĠ Ġval Ġservice Ġ= ĠKnown Gradle Plugins ServiceImpl ( downloader , Ġlocal Cache ) ĊĠĠĠ Ġservice . refresh S ynchronously () ĊĠĠĠ ĠassertThat ( service . gradle Plugins Data ). isNot EqualTo ( Gradle Plugins Data . empty Data ) ĊĠ Ġ} Ċ Ċ /* ĊĠ ĠTODO Ġ( b / 1 7 3 7 8 4 1 6 1 ): Ġadd Ġtests : ĊĠĠĠĠĠ Ġnormal Ġ- Ġdownloaded Ġfrom Ġurl Ġ( mock Ġis Ġtriggered ), Ġcopied Ġto Ġtemp ĊĠĠĠĠĠ Ġtest Ġsecond Ġrequest Ġin Ġa Ġrow Ġdoesn 't Ġtry Ġto Ġdownload ĊĠĠĠĠĠ Ġtest Ġfailed Ġrequest Ġ=> Ġtries Ġto Ġload Ġprevious Ġdownload ĊĠĠĠĠĠ Ġ( if Ġpossible Ġand Ġhave Ġtime ) Ġtest Ġlong Ġasync Ġthen Ġsync Ġ=> Ġsync Ġwaits Ġfor Ġasync Ġto Ġfinish Ċ */ Ċ }