/* Ċ Ġ* Ġ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 . ui builder . handlers Ċ Ċ import Ġcom . android . Sdk Constants .* Ċ import Ġcom . android . resources . ResourceType Ċ import Ġcom . android . tools . idea . common . api . Insert Type Ċ import Ġcom . android . tools . idea . ui builder . Layout TestCase Ċ import Ġcom . android . tools . idea . ui builder . scene . Sync Layout lib Scene Manager Ċ import Ġcom . android . tools . idea . ui builder . surface . Nl Design Surface Ċ import Ġcom . intellij . openapi . command . Write Command Action Ċ import Ġcom . intellij . openapi . file Editor . File Editor Manager Ċ import Ġcom . intellij . psi . XmlElement Factory Ċ import Ġorg . jetbrains . android . Android TestCase Ċ import Ġorg . mockito . Mockito .` when ` Ċ import Ġorg . mockito . Mockito . mock Ċ import Ġjava . util .* Ċ Ċ class ĠFragment Handler Test Ġ: ĠLayout TestCase () Ġ{ ĊĠ Ġfun Ġtest Activate Nav Fragment () Ġ{ ĊĠĠĠ Ġmy Fixture . add File To Project (" res / navigation / nav . xml ", Ġ"< navigation /> ") ĊĠĠĠ Ġval Ġmodel Ġ= Ġmodel ( ĊĠĠĠĠĠ Ġ" model . xml ", ĊĠĠĠĠĠ Ġcomponent (" LinearLayout ") ĊĠĠĠĠĠĠĠ Ġ. id ("@ + id / outer ") ĊĠĠĠĠĠĠĠ Ġ. with Bounds ( 0 , Ġ 0 , Ġ 1 0 0 , Ġ 1 0 0 ) ĊĠĠĠĠĠĠĠ Ġ. children ( ĊĠĠĠĠĠĠĠĠĠ Ġcomponent (" fragment ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. id ("@ + id / nav host ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Attribute ( AUTO _ URI , ĠATTR _ NAV _ GRAPH , Ġ"@ navigation / nav ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Bounds ( 0 , Ġ 0 , Ġ 1 0 0 , Ġ 5 0 ), ĊĠĠĠĠĠĠĠĠĠ Ġcomponent (" fragment ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. id ("@ + id / regular ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Bounds ( 0 , Ġ 5 0 , Ġ 1 0 0 , Ġ 5 0 ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ). build () ĊĊĠĠĠ Ġval Ġsurface Ġ= ĠN l Design Surface . build ( project , Ġproject ) ĊĠĠĠ Ġsurface . model Ġ= Ġmodel ĊĠĠĠ Ġval Ġeditor Manager Ġ= ĠFile Editor Manager . getInstance ( project ) ĊĊĠĠĠ Ġsurface . notify Component Activate ( model . find (" regular ") !! , Ġ 1 0 , Ġ 6 0 ) ĊĠĠĠ ĠAndroid TestCase . assert Empty ( editor Manager . open Files ) ĊĊĠĠĠ Ġsurface . notify Component Activate ( model . find (" nav host ") !! , Ġ 1 0 , Ġ 1 0 ) ĊĠĠĠ ĠAndroid TestCase . assertEquals (" nav . xml ", Ġeditor Manager . open Files [ 0 ]. name ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Create Nav Host () Ġ{ ĊĠĠĠ Ġval Ġmodel Ġ= Ġmodel ( ĊĠĠĠĠĠĠĠ Ġ" model . xml ", ĊĠĠĠĠĠĠĠ Ġcomponent (" LinearLayout ") ĊĠĠĠĠĠĠĠĠĠ Ġ. id ("@ + id / outer ") ĊĠĠĠĠĠĠĠĠĠ Ġ. with Bounds ( 0 , Ġ 0 , Ġ 1 0 0 , Ġ 1 0 0 )) ĊĠĠĠĠĠ Ġ. build () ĊĊĠĠĠ Ġval Ġtag Ġ= ĠXml Element Factory . getInstance ( getProject ()). create Tag FromText ( ĊĠĠĠĠĠĠĠ Ġ" ĠĠĠ Ġ< fragment \ n " Ġ+ ĊĠĠĠĠĠĠĠ Ġ" ĠĠĠĠĠĠĠ Ġandroid : id =\" @ + id / fragment \"\ n " Ġ+ ĊĠĠĠĠĠĠĠ Ġ" ĠĠĠĠĠĠĠ Ġandroid : name =\" android x . navigation . fragment . Nav Host Fragment \"\ n /> "); ĊĠĠĠ Ġval Ġeditor Ġ= Ġmock ( View Editor Impl :: class . java ) ĊĠĠĠ Ġ` when `( editor . display Resource Input (" Navigation ĠGraph s ", ĠEnum Set . of ( ResourceType . NAV IG ATION ))). thenReturn ("@ navigation / test Nav ") ĊĠĠĠ Ġ( model . surface . scene Manager Ġas ĠSync Layout lib Scene Manager ). set Custom View Editor ( editor ) ĊĠĠĠ ĠWrite Command Action . run Write Command Action ( ĊĠĠĠĠĠĠĠ Ġmodel . project , Ġnull , Ġnull , ĊĠĠĠĠĠĠĠ ĠRunnable Ġ{ Ġmodel . create Component ( model . surface , Ġtag , Ġmodel . find (" outer "), Ġnull , ĠInsert Type . CREATE ) Ġ}, ĊĠĠĠĠĠĠĠ Ġmodel . file ĊĠĠĠ Ġ) ĊĠĠĠ Ġval Ġnew Fragment Ġ= Ġmodel . find (" fragment ") !! ĊĠĠĠ ĠassertEquals ("@ navigation / test Nav ", Ġnew Fragment . getAttribute ( AUTO _ URI , ĠATTR _ NAV _ GRAPH )) ĊĠĠĠ ĠassertEquals (" true ", Ġnew Fragment . getAttribute ( AUTO _ URI , ĠATTR _ DEFAULT _ NAV _ HOST )) ĊĠ Ġ} Ċ }