/* Ċ Ġ* ĠCopyright Ġ 2 0 1 9 Ġ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 Ġandroidx . navigation . safe . args . generator Ċ Ċ import Ġandroidx . navigation . safe . args . generator . kotlin . Kotlin Code File Ċ import Ġandroidx . navigation . safe . args . generator . kotlin . Kotlin Nav Writer Ċ import Ġandroidx . navigation . safe . args . generator . kotlin . to Code File Ċ import Ġandroidx . navigation . safe . args . generator . models . Action Ċ import Ġandroidx . navigation . safe . args . generator . models . Argument Ċ import Ġandroidx . navigation . safe . args . generator . models . Destination Ċ import Ġandroidx . navigation . safe . args . generator . models . Res Reference Ċ import Ġcom . google . common . truth . String Subject Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġcom . squareup . jav ap o et . ClassName Ċ import Ġcom . squareup . kotlin po et . File Spec Ċ import Ġcom . squareup . kotlin po et . Type Spec Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . junit . runners . JUnit 4 Ċ Ċ @ RunWith ( JUnit 4 :: class ) Ċ class ĠKotlin Nav Writer Test Ġ{ ĊĠĠĠ Ġprivate Ġfun Ġgenerate Directions Code File ( ĊĠĠĠĠĠĠĠ Ġdestination : ĠDestination , ĊĠĠĠĠĠĠĠ Ġparent Directions FileList : ĠList < Kotlin Code File >, ĊĠĠĠĠĠĠĠ Ġuse Android X : ĠBoolean ĊĠĠĠ Ġ) Ġ= ĠKotlin Nav Writer ( use Android X ). generate Directions Code File ( ĊĠĠĠĠĠĠĠ Ġdestination , ĊĠĠĠĠĠĠĠ Ġparent Directions FileList ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġprivate Ġfun Ġgenerate Direction sType Spec ( action : ĠAction , Ġuse Android X : ĠBoolean ) Ġ= ĊĠĠĠĠĠĠĠ ĠKotlin Nav Writer ( use Android X ). generate Direction Type Spec ( action ) ĊĊĠĠĠ Ġprivate Ġfun Ġgenerate Args Code File ( ĊĠĠĠĠĠĠĠ Ġdestination : ĠDestination , ĊĠĠĠĠĠĠĠ Ġuse Android X : ĠBoolean ĊĠĠĠ Ġ) Ġ= ĠKotlin Nav Writer ( use Android X ). generate Args Code File ( destination ) ĊĊĠĠĠ Ġprivate Ġfun Ġid ( id : ĠString ) Ġ= ĠRes Reference (" a . b ", Ġ" id ", Ġid ) ĊĊĠĠĠ Ġprivate Ġfun Ġwrapped Inner Class ( spec : ĠType Spec ): ĠKotlin Code File Ġ= ĊĠĠĠĠĠĠĠ ĠFile Spec . builder (" a . b ", Ġ" B oring Wrapper ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Type ( spec ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. to Code File () ĊĊĠĠĠ Ġprivate Ġfun ĠString Subject . par ses As ( full ClassName : ĠString ) Ġ= ĊĠĠĠĠĠĠĠ Ġthis . isEqualTo ( load Source String ( full ClassName , Ġ" expected / kotlin _ nav _ writer _ test ", Ġ" kt ")) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Direction Class Generation () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġaction Ġ= ĠAction ( id (" next "), Ġid (" dest A "), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠArgument (" main ", ĠString Type ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠArgument (" main Int ", ĠInt Type ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠArgument (" optional ", ĠString Type , ĠString Value (" bl a ")), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠArgument (" optional Int ", ĠInt Type , ĠInt Value (" 2 3 9 ")), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠArgument ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" optional Parcelable ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠObjectType (" android . content . pm . Activity Info "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠNull Value , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠArgument ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" parcel able ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠObjectType (" android . content . pm . Activity Info ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠArgument ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" inner Data ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠObjectType (" android . content . pm . Activity Info \$ Window Layout ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ))) ĊĠĠĠĠĠĠĠ Ġval Ġactual Ġ= Ġgenerate Direction sType Spec ( action , Ġfalse ) ĊĠĠĠĠĠĠĠ ĠassertThat ( wrapped Inner Class ( actual ). toString ()). par ses As (" a . b . Next ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Directions Class Generation () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnext Action Ġ= ĠAction ( id (" next "), Ġid (" dest A "), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠArgument (" main ", ĠString Type ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠArgument (" optional ", ĠString Type , ĠString Value (" bl a ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ)) ĊĊĠĠĠĠĠĠĠ Ġval Ġprev Action Ġ= ĠAction ( id (" previous "), Ġid (" dest B "), Ġempty List ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġdest Ġ= ĠDestination ( null , ĠClass Name . get (" a . b ", Ġ" Main Fragment "), Ġ" fragment ", ĠlistOf (), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( prev Action , Ġnext Action )) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Ġ= Ġgenerate Directions Code File ( dest , Ġempty List (), Ġfalse ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . toString ()). par ses As (" a . b . Main Fragment Directions ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Directions Class Generation _ with Keyword Id () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġfun Action Ġ= ĠAction ( Res Reference (" fun . is . in ", Ġ" id ", Ġ" next "), Ġid (" dest A "), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġdest Ġ= ĠDestination ( null , ĠClass Name . get (" a . b ", Ġ" Fun Fragment "), Ġ" fragment ", ĠlistOf (), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( fun Action )) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Ġ= Ġgenerate Directions Code File ( dest , Ġempty List (), Ġfalse ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . toString ()). par ses As (" a . b . Fun Fragment Directions ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Directions Class Generation _ long Package () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġfun Action Ġ= ĠAction ( Res Reference (" a . b . second really really really really " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" really really really really really really really really really really really really " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" long package ", Ġ" id ", Ġ" next "), Ġid (" dest A "), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġdest Ġ= ĠDestination ( null , ĠClass Name . get (" a . b . really really really really " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" really really really really really really really really really really really really " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" long package ", Ġ" Long Package Fragment "), Ġ" fragment ", ĠlistOf (), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( fun Action )) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Ġ= Ġgenerate Directions Code File ( dest , Ġempty List (), Ġfalse ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . toString ()). par ses As (" a . b . really really really really really " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" really really really really really really really really really really really " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" long package . Long Package Fragment Directions ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Arguments Class Generation () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdest Ġ= ĠDestination ( null , ĠClass Name . get (" a . b ", Ġ" Main Fragment "), Ġ" fragment ", ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠArgument (" main ", ĠString Type ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠArgument (" optional ", ĠInt Type , ĠInt Value ("- 1 ")), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠArgument (" reference ", ĠReference Type , ĠReference Value ( Res Reference (" a . b ", Ġ" drawable ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" background ")) ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠArgument (" reference Zero DefaultValue ", ĠReference Type , ĠInt Value (" 0 ")), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠArgument (" float Arg ", ĠFloat Type , ĠFloat Value (" 1 ")), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠArgument (" float Array Arg ", ĠFloat ArrayType ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠArgument (" object Array Arg ", ĠObject ArrayType (" android . content . pm . Activity Info ")), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠArgument (" bool Arg ", ĠBool Type , ĠBoolean Value (" true ")), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠArgument ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" optional Parcelable ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠObjectType (" android . content . pm . Activity Info "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠNull Value , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠArgument ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" enum Arg ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠObjectType (" java . nio . file . Access Mode "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠEnum Value ( ObjectType (" java . nio . file . Access Mode "), Ġ" READ "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfalse ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ)), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Ġ= Ġgenerate Args Code File ( dest , Ġfalse ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . toString ()). par ses As (" a . b . Main Fragment Args ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Argument Class Generation _ long Argument Name () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdest Ġ= ĠDestination ( null , ĠClass Name . get (" a . b ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" Re ally Re ally Re ally Re ally Re ally Re ally Re ally Re ally Re ally Re ally Re ally Re ally Re ally Re ally " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Long Name Fragment "), Ġ" fragment ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf (), ĠlistOf ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Ġ= Ġgenerate Args Code File ( dest , Ġfalse ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . toString ()). par ses As (" a . b . Re ally Re ally Re ally Re ally Re ally " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Re ally Re ally Re ally Re ally Re ally Re ally Re ally Re ally Re ally Long Name Main Fragment Args ") ĊĠĠĠ Ġ} Ċ }