// ĠCopyright Ġ 2 0 0 0 - 2 0 2 0 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe ĠLICENSE Ġfile . Ċ package Ġcom . intellij . openapi . roots Ċ Ċ import Ġcom . intellij . openapi . module . Module Ċ import Ġcom . intellij . openapi . util . Dis poser Ċ import Ġcom . intellij . test Framework . Application Rule Ċ import Ġcom . intellij . test Framework . Disposable Rule Ċ import Ġcom . intellij . test Framework . rules . Project Model Rule Ċ import Ġcom . intellij . test Framework . rules . Temp Directory Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . jetbrains . j ps . model . module . Unknown Source Root Type Ċ import Ġorg . jetbrains . j ps . model . serialization . J ps Model Serializer Extension Ċ import Ġorg . junit .* Ċ Ċ class ĠCustom Source Root Type Test Ġ{ ĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġ@ Class Rule ĊĠĠĠ Ġval Ġapp Rule Ġ= ĠApplication Rule () ĊĠ Ġ} ĊĊĠ Ġ@ Rule ĊĠ Ġ@ Jvm Field ĊĠ Ġval Ġproject Model Ġ= ĠProject Model Rule () ĊĊĠ Ġ@ Rule ĊĠ Ġ@ Jvm Field ĊĠ Ġval Ġtemp Directory Ġ= ĠTemp Directory () ĊĊĠ Ġ@ Rule ĊĠ Ġ@ Jvm Field ĊĠ Ġval Ġdis posable Ġ= ĠDis posable Rule () ĊĊĠ Ġlateinit Ġvar Ġmodule : ĠModule ĊĊĠ Ġ@ Before ĊĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠ Ġmodule Ġ= Ġproject Model . create Module () ĊĠĠĠ ĠJ ps Model Serializer Extension . get Extensions () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` load Ġun load Ġcustom Ġsource Ġroot `() Ġ{ ĊĠĠĠ Ġval Ġsrc Dir Ġ= Ġproject Model . base Project Dir . new Virtual Directory (" src ") ĊĠĠĠ Ġrun With Registered Extension Ġ{ ĊĠĠĠĠĠ Ġval Ġmodel Ġ= Ġcreate Mod ifiable Model ( module ) ĊĠĠĠĠĠ Ġmodel . add Content Entry ( src Dir ). add Source Folder ( src Dir , ĠTest Custom Source Root Type . INSTANCE , ĠTest Custom Source Root Properties (" hello ")) ĊĠĠĠĠĠ Ġval Ġcommitted Ġ= Ġcommit Mod ifiable Root Model ( model ) ĊĠĠĠĠĠ Ġval Ġsource Folder Ġ= Ġcommitted . content Entries . single (). source Folders . single () ĊĠĠĠĠĠ ĠassertThat ( source Folder . file ). isEqualTo ( src Dir ) ĊĠĠĠĠĠ ĠassertThat ( source Folder . root Type ). isEqualTo ( Test Custom Source Root Type . INSTANCE ) ĊĠĠĠĠĠ ĠassertThat (( source Folder . j ps Element . properties Ġas ĠTest Custom Source Root Properties ). test String ). isEqualTo (" hello ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġsource Folder With Unknown Type Ġ= ĠModule Root Manager . getInstance ( module ). content Entries . single (). source Folders . single () ĊĠĠĠ ĠassertThat ( source Folder With Unknown Type . file ). isEqualTo ( src Dir ) ĊĠĠĠ ĠassertThat ( source Folder With Unknown Type . root Type ). isInstanceOf ( Unknown Source Root Type :: class . java ) ĊĊĠĠĠ ĠTest Custom Root Model Serializer Extension . register Test Custom Source Root Type ( temp Directory . new Directory (), Ġdis posable . dis posable ) ĊĠĠĠ Ġval Ġsource Folder Ġ= ĠModule Root Manager . getInstance ( module ). content Entries . single (). source Folders . single () ĊĠĠĠ ĠassertThat ( source Folder . file ). isEqualTo ( src Dir ) ĊĠĠĠ ĠassertThat ( source Folder . root Type ). isEqualTo ( Test Custom Source Root Type . INSTANCE ) ĊĠĠĠ ĠassertThat (( source Folder . j ps Element . properties Ġas ĠTest Custom Source Root Properties ). test String ). isEqualTo (" hello ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` edit Ġcustom Ġroot Ġproperties `() Ġ{ ĊĠĠĠ ĠAssume . assume True (" Editing Ġof Ġcustom Ġroot Ġproperties Ġisn 't Ġcorrectly Ġimplemented Ġin Ġthe Ġcurrent Ġproject Ġmodel ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠProject Model Rule . is Workspace Model Enabled ) ĊĠĠĠ ĠTest Custom Root Model Serializer Extension . register Test Custom Source Root Type ( temp Directory . new Directory (), Ġdis posable . dis posable ) ĊĠĠĠ Ġval Ġsrc Dir Ġ= Ġproject Model . base Project Dir . new Virtual Directory (" src ") ĊĠĠĠ Ġval Ġcommitted Ġ= Ġrun Ġ{ ĊĠĠĠĠĠ Ġval Ġmodel Ġ= Ġcreate Mod ifiable Model ( module ) ĊĠĠĠĠĠ Ġmodel . add Content Entry ( src Dir ). add Source Folder ( src Dir , ĠTest Custom Source Root Type . INSTANCE , ĠTest Custom Source Root Properties (" foo ")) ĊĠĠĠĠĠ Ġval Ġsource Folder Ġ= Ġmodel . content Entries . single (). source Folders . single () ĊĠĠĠĠĠ ĠassertThat ( source Folder . root Type ). isEqualTo ( Test Custom Source Root Type . INSTANCE ) ĊĠĠĠĠĠ ĠassertThat ( source Folder . custom Root Properties ). isEqualTo (" foo ") ĊĠĠĠĠĠ Ġsource Folder . custom Root Properties Ġ= Ġ" bar " ĊĠĠĠĠĠ ĠassertThat ( model . content Entries . single (). source Folders . single (). custom Root Properties ). isEqualTo (" bar ") ĊĠĠĠĠĠ Ġcommit Mod ifiable Root Model ( model ) ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠassertThat ( committed . content Entries . single (). source Folders . single (). custom Root Properties ). isEqualTo (" bar ") ĊĊĠĠĠ Ġval Ġcommitted 2 Ġ= Ġrun Ġ{ ĊĠĠĠĠĠ Ġval Ġmodel Ġ= Ġcreate Mod ifiable Model ( module ) ĊĠĠĠĠĠ Ġval Ġcontent Entry Ġ= Ġmodel . content Entries . single () ĊĠĠĠĠĠ Ġval Ġsource Folder Ġ= Ġcontent Entry . source Folders . single () ĊĠĠĠĠĠ ĠassertThat ( source Folder . custom Root Properties ). isEqualTo (" bar ") ĊĠĠĠĠĠ Ġsource Folder . custom Root Properties Ġ= Ġ" baz " ĊĠĠĠĠĠ ĠassertThat ( source Folder . custom Root Properties ). isEqualTo (" baz ") ĊĠĠĠĠĠ ĠassertThat ( content Entry . source Folders . single (). custom Root Properties ). isEqualTo (" baz ") ĊĠĠĠĠĠ ĠassertThat ( model . content Entries . single (). source Folders . single (). custom Root Properties ). isEqualTo (" baz ") ĊĠĠĠĠĠ Ġcommit Mod ifiable Root Model ( model ) ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠassertThat ( committed 2 . content Entries . single (). source Folders . single (). custom Root Properties ). isEqualTo (" baz ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` discard Ġchanges Ġin Ġcustom Ġproperties Ġif Ġmodel Ġis Ġdisposed `() Ġ{ ĊĠĠĠ ĠTest Custom Root Model Serializer Extension . register Test Custom Source Root Type ( temp Directory . new Directory (), Ġdis posable . dis posable ) ĊĠĠĠ Ġval Ġsrc Dir Ġ= Ġproject Model . base Project Dir . new Virtual Directory (" src ") ĊĠĠĠ Ġval Ġcommitted Ġ= Ġrun Ġ{ ĊĠĠĠĠĠ Ġval Ġmodel Ġ= Ġcreate Mod ifiable Model ( module ) ĊĠĠĠĠĠ Ġmodel . add Content Entry ( src Dir ). add Source Folder ( src Dir , ĠTest Custom Source Root Type . INSTANCE , ĠTest Custom Source Root Properties (" foo ")) ĊĠĠĠĠĠ Ġcommit Mod ifiable Root Model ( model ) ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠassertThat ( committed . content Entries . single (). source Folders . single (). custom Root Properties ). isEqualTo (" foo ") ĊĊĠĠĠ Ġrun Ġ{ ĊĠĠĠĠĠ Ġval Ġmodel Ġ= Ġcreate Mod ifiable Model ( module ) ĊĠĠĠĠĠ Ġmodel . content Entries . single (). source Folders . single (). custom Root Properties Ġ= Ġ" bar " ĊĠĠĠĠĠ ĠassertThat ( model . content Entries . single (). source Folders . single (). custom Root Properties ). isEqualTo (" bar ") ĊĠĠĠĠĠ Ġmodel . dispose () ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠassertThat ( committed . content Entries . single (). source Folders . single (). custom Root Properties ). isEqualTo (" foo ") ĊĠ Ġ} ĊĊĠ Ġprivate Ġvar ĠSource Folder . custom Root Properties : ĠString ? ĊĠĠĠ Ġget () Ġ= Ġ( j ps Element . properties Ġas ĠTest Custom Source Root Properties ). test String ĊĠĠĠ Ġset ( value ) Ġ{ ĊĠĠĠĠĠ Ġ( j ps Element . properties Ġas ĠTest Custom Source Root Properties ). test String Ġ= Ġvalue ĊĠĠĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġrun With Registered Extension ( action : Ġ() Ġ-> ĠUnit ) Ġ{ ĊĠĠĠ Ġval Ġdis posable Ġ= ĠDis poser . new Disposable () ĊĠĠĠ ĠTest Custom Root Model Serializer Extension . register Test Custom Source Root Type ( temp Directory . new Directory (), Ġdis posable ) ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġaction () ĊĠĠĠ Ġ} ĊĠĠĠ Ġfinally Ġ{ ĊĠĠĠĠĠ ĠDis poser . dispose ( dis posable ) ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ Ċ }