/* Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 1 8 Ġ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 . tools . idea . gradle . dsl . model . ext Ċ Ċ import Ġcom . android . tools . idea . gradle . dsl . Test FileName Impl . PROPERTY _ UTIL _ WRITE _ BACK _ ELEMENT _ WITH _ TRIM MED _ NAME Ċ import Ġcom . android . tools . idea . gradle . dsl . api . ext . PropertyType Ċ import Ġcom . android . tools . idea . gradle . dsl . model . android . Product Flavor Model Impl Ċ import Ġcom . android . tools . idea . gradle . dsl . model . ext . transforms . Transform TestCase Ċ import Ġcom . android . tools . idea . gradle . dsl . parser . External Name Info . External Name Syntax . ASSIGN MENT Ċ import Ġcom . android . tools . idea . gradle . dsl . parser . elements . Gradle Dsl Literal Ċ import Ġcom . android . tools . idea . gradle . dsl . parser . elements . Gradle Dsl MethodCall Ċ import Ġcom . android . tools . idea . gradle . dsl . parser . elements . Gradle Name Element Ċ import Ġorg . hamcrest . Core Matchers . equalTo Ċ import Ġorg . hamcrest . Matcher Assert . assertThat Ċ import Ġorg . junit . Test ĊĊ Ċ class ĠProperty Util Test Ġ: ĠTransform TestCase () Ġ{ ĊĠ Ġprivate Ġval ĠfieldName Ġ= ĠGradle Name Element . create (" store File ") ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet File Value From Single Arg Constructor () Ġ{ ĊĠĠĠ Ġval Ġmethod Ġ= ĠGradle Dsl MethodCall ( gradle Dsl File , Ġnull , ĠfieldName , Ġtrue , ĠProperty Util . FILE _ CON STRUCTOR _ NAME ) ĊĠĠĠ Ġval Ġarg Ġ= ĠGradle Dsl Literal ( gradle Dsl File , ĠGradle Name Element . create (" 0 ")) ĊĠĠĠ Ġarg . setValue (" path / to / some / file ") ĊĠĠĠ Ġmethod . add Parsed Expression ( arg ) ĊĠĠĠ ĠassertThat ( Property Util . getFile Value ( method ), ĠequalTo (" path / to / some / file ")) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet File Value From Empty Arg Constructor () Ġ{ ĊĠĠĠ Ġval Ġmethod Ġ= ĠGradle Dsl MethodCall ( gradle Dsl File , Ġnull , ĠfieldName , Ġtrue , ĠProperty Util . FILE _ CON STRUCTOR _ NAME ) ĊĠĠĠ ĠassertNull ( Property Util . getFile Value ( method )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet File Value From Multi Arg Constructor () Ġ{ ĊĠĠĠ Ġval Ġmethod Ġ= ĠGradle Dsl MethodCall ( gradle Dsl File , Ġnull , ĠfieldName , Ġtrue , ĠProperty Util . FILE _ CON STRUCTOR _ NAME ) ĊĠĠĠ Ġval Ġarg Ġ= ĠGradle Dsl Literal ( gradle Dsl File , ĠGradle Name Element . create (" 0 ")) ĊĠĠĠ Ġarg . setValue (" path / to / some / file ") ĊĠĠĠ Ġval Ġother Arg Ġ= ĠGradle Dsl Literal ( gradle Dsl File , ĠGradle Name Element . create (" 1 ")) ĊĠĠĠ Ġother Arg . setValue (" file . txt ") ĊĠĠĠ Ġmethod . add Parsed Expression ( arg ) ĊĠĠĠ Ġmethod . add Parsed Expression ( other Arg ) ĊĠĠĠ ĠassertThat ( Property Util . getFile Value ( method ), ĠequalTo (" path / to / some / file / file . txt ")) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet File Value From Single Arg MethodCall () Ġ{ ĊĠĠĠ Ġval Ġmethod Ġ= ĠGradle Dsl MethodCall ( gradle Dsl File , Ġnull , ĠfieldName , Ġfalse , ĠProperty Util . FILE _ METHOD _ NAME ) ĊĠĠĠ Ġval Ġarg Ġ= ĠGradle Dsl Literal ( gradle Dsl File , ĠGradle Name Element . create (" 0 ")) ĊĠĠĠ Ġarg . setValue (" path / to / some / file ") ĊĠĠĠ Ġmethod . add Parsed Expression ( arg ) ĊĠĠĠ ĠassertThat ( Property Util . getFile Value ( method ), ĠequalTo (" path / to / some / file ")) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet File Value From Empty Arg MethodCall () Ġ{ ĊĠĠĠ Ġval Ġmethod Ġ= ĠGradle Dsl MethodCall ( gradle Dsl File , Ġnull , ĠfieldName , Ġfalse , ĠProperty Util . FILE _ METHOD _ NAME ) ĊĠĠĠ ĠassertNull ( Property Util . getFile Value ( method )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet File Value From Multi Arg MethodCall () Ġ{ ĊĠĠĠ Ġval Ġmethod Ġ= ĠGradle Dsl MethodCall ( gradle Dsl File , Ġnull , ĠfieldName , Ġfalse , ĠProperty Util . FILE _ METHOD _ NAME ) ĊĠĠĠ Ġval Ġarg Ġ= ĠGradle Dsl Literal ( gradle Dsl File , ĠGradle Name Element . create (" 0 ")) ĊĠĠĠ Ġarg . setValue (" path / to / some / file ") ĊĠĠĠ Ġval Ġother Arg Ġ= ĠGradle Dsl Literal ( gradle Dsl File , ĠGradle Name Element . create (" 1 ")) ĊĠĠĠ Ġother Arg . setValue (" file . txt ") ĊĠĠĠ Ġmethod . add Parsed Expression ( arg ) ĊĠĠĠ Ġmethod . add Parsed Expression ( other Arg ) ĊĠĠĠ ĠassertThat ( Property Util . getFile Value ( method ), ĠequalTo (" path / to / some / file / file . txt ")) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Wrong MethodName Gets Null () Ġ{ ĊĠĠĠ Ġval Ġmethod Ġ= ĠGradle Dsl MethodCall ( gradle Dsl File , Ġnull , ĠfieldName , Ġfalse , Ġ" some Random MethodName ") ĊĠĠĠ Ġval Ġarg Ġ= ĠGradle Dsl Literal ( gradle Dsl File , ĠGradle Name Element . create (" 0 ")) ĊĠĠĠ Ġarg . setValue (" path / to / some / file ") ĊĠĠĠ Ġval Ġother Arg Ġ= ĠGradle Dsl Literal ( gradle Dsl File , ĠGradle Name Element . create (" 1 ")) ĊĠĠĠ Ġother Arg . setValue (" file . txt ") ĊĠĠĠ Ġmethod . add Parsed Expression ( arg ) ĊĠĠĠ Ġmethod . add Parsed Expression ( other Arg ) ĊĠĠĠ ĠassertNull ( Property Util . getFile Value ( method )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Write Back Element With Trim med Name () Ġ{ ĊĠĠĠ Ġval Ġliteral Ġ= Ġcreate Literal ( name Ġ= Ġ" android . default Config . application Id ") ĊĠĠĠ Ġval Ġbuild Model Ġ= Ġgradle Build Model ĊĠĠĠ Ġval Ġdefault Config Block Ġ= Ġ( build Model . android (). default Config () Ġas ĠProduct Flavor Model Impl ). dsl Element () ĊĠĠĠ Ġliteral . elementType Ġ= ĠProperty Type . REG ULAR ĊĠĠĠ Ġif Ġ(! is Gro ovy ) Ġ{ ĊĠĠĠĠĠ Ġliteral . external Syntax Ġ= ĠASS IGN MENT ĊĠĠĠ Ġ} ĊĠĠĠ Ġdefault Config Block . set New Element ( literal ) ĊĠĠĠ Ġliteral . setValue (" hello ") ĊĊĠĠĠ Ġapply Changes And Re parse ( build Model ) ĊĠĠĠ Ġverify File Contents ( my Build File , ĠPROPERTY _ UTIL _ WRITE _ BACK _ ELEMENT _ WITH _ TRIM MED _ NAME ); ĊĊĠĠĠ Ġval Ġapplication Id Ġ= Ġbuild Model . android (). default Config (). application Id () ĊĠĠĠ Ġif Ġ( is Gro ovy ) Ġ{ ĊĠĠĠĠĠ ĠassertThat ( application Id . psi Element !!. parent !!. text , ĠequalTo (" application Id Ġ' hello ' ")) ĊĠĠĠ Ġ} ĊĠĠĠ Ġelse Ġ{ ĊĠĠĠĠĠ ĠassertThat ( application Id . psi Element !!. parent !!. text , ĠequalTo (" application Id Ġ= Ġ\" hello \"" )) ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ }