package Ġio . me how . labor atory . inspector Ċ Ċ import Ġapp . cash . tur bine . test Ċ import Ġio . kot est . core . spec . style . Describe Spec Ċ import Ġio . kot est . matchers . collections . should Contain Exactly Ċ import Ġio . kot est . matchers . collections . should Not Contain Ċ import Ġio . me how . labor atory . Feature Ċ import Ġio . me how . labor atory . Feature Factory Ċ import Ġio . me how . labor atory . L abor atory Ċ import Ġio . me how . labor atory . inspector . L abor atory Activity . Configuration Ċ import Ġkotlinx . coroutines . flow . first Ċ import Ġkotlinx . coroutines . flow . map Ċ Ċ class ĠViewModel Spec Ġ: ĠDescribe Spec ({ ĊĠ Ġdescribe (" view Ġmodel ") Ġ{ ĊĠĠĠ Ġit (" filters Ġempty Ġfeature Ġgroups ") Ġ{ ĊĠĠĠĠĠ Ġval ĠviewModel Ġ= ĠFeatures ViewModel ( ĊĠĠĠĠĠĠĠĠĠ ĠConfiguration ( L abor atory . in Memory (), Ġmap Of (" Local " Ġto ĠNo Source Feature Factory )) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġval Ġfeature Names Ġ= ĠviewModel . observe Feature Groups (" Local "). first (). map ( Feature Group :: name ) ĊĊĠĠĠĠĠ Ġfeature Names Ġshould Not Contain Ġ" Empty " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġit (" orders Ġfeature Ġgroups Ġby Ġname ") Ġ{ ĊĠĠĠĠĠ Ġval ĠviewModel Ġ= ĠFeatures ViewModel ( ĊĠĠĠĠĠĠĠĠĠ ĠConfiguration ( L abor atory . in Memory (), Ġmap Of (" Local " Ġto ĠNo Source Feature Factory )) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġval Ġfeature Names Ġ= ĠviewModel . observe Feature Groups (" Local "). first (). map ( Feature Group :: name ) ĊĊĠĠĠĠĠ Ġfeature Names Ġshould Contain Exactly ĠlistOf (" First ", Ġ" Second ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġit (" does Ġnot Ġorder Ġfeature Ġvalues ") Ġ{ ĊĠĠĠĠĠ Ġval ĠviewModel Ġ= ĠFeatures ViewModel ( ĊĠĠĠĠĠĠĠĠĠ ĠConfiguration ( L abor atory . in Memory (), Ġmap Of (" Local " Ġto ĠNo Source Feature Factory )) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġval Ġfeatures Ġ= ĠviewModel . observe Feature Groups (" Local "). first () ĊĠĠĠĠĠĠĠĠĠ Ġ. map ( Feature Group :: models ) ĊĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġmodels Ġ-> Ġmodels . map ( Feature Model :: feature ) Ġ} ĊĊĠĠĠĠĠ Ġfeatures [ 0 ] Ġshould Contain Exactly ĠlistOf ( First . C , ĠFirst . B , ĠFirst . A ) ĊĠĠĠĠĠ Ġfeatures [ 1 ] Ġshould Contain Exactly ĠlistOf ( Second . B , ĠSecond . C , ĠSecond . A ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġit (" marks Ġfirst Ġfeature Ġas Ġselected Ġby Ġdefault ") Ġ{ ĊĠĠĠĠĠ Ġval ĠviewModel Ġ= ĠFeatures ViewModel ( ĊĠĠĠĠĠĠĠĠĠ ĠConfiguration ( L abor atory . in Memory (), Ġmap Of (" Local " Ġto ĠNo Source Feature Factory )) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ ĠviewModel . observe Selected Features (" Local "). first () Ġshould Contain Exactly ĠlistOf ( First . C , ĠSecond . B ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġit (" marks Ġsaved Ġfeature Ġas Ġselected ") Ġ{ ĊĠĠĠĠĠ Ġval Ġlabor atory Ġ= ĠLaboratory . in Memory (). apply Ġ{ ĊĠĠĠĠĠĠĠ Ġset Feature ( First . A ) ĊĠĠĠĠĠĠĠ Ġset Feature ( Second . C ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġval ĠviewModel Ġ= ĠFeatures ViewModel ( ĊĠĠĠĠĠĠĠĠĠ ĠConfiguration ( labor atory , Ġmap Of (" Local " Ġto ĠNo Source Feature Factory )) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ ĠviewModel . observe Selected Features (" Local "). first () Ġshould Contain Exactly ĠlistOf ( First . A , ĠSecond . C ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġit (" select s Ġfeatures ") Ġ{ ĊĠĠĠĠĠ Ġval ĠviewModel Ġ= ĠFeatures ViewModel ( ĊĠĠĠĠĠĠĠĠĠ ĠConfiguration ( L abor atory . in Memory (), Ġmap Of (" Local " Ġto ĠNo Source Feature Factory )) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ ĠviewModel . select Feature ( First . B ) ĊĠĠĠĠĠ ĠviewModel . select Feature ( Second . A ) ĊĊĠĠĠĠĠ ĠviewModel . observe Selected Features (" Local "). first () Ġshould Contain Exactly ĠlistOf ( First . B , ĠSecond . A ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġit (" ob serves Ġfeature Ġchanges ") Ġ{ ĊĠĠĠĠĠ Ġval ĠviewModel Ġ= ĠFeatures ViewModel ( ĊĠĠĠĠĠĠĠĠĠ ĠConfiguration ( L abor atory . in Memory (), Ġmap Of (" Local " Ġto ĠNo Source Feature Factory )) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ ĠviewModel . observe Selected Features (" Local "). test Ġ{ ĊĠĠĠĠĠĠĠ Ġexpect Item () Ġshould Contain Exactly ĠlistOf ( First . C , ĠSecond . B ) ĊĊĠĠĠĠĠĠĠ ĠviewModel . select Feature ( First . B ) ĊĠĠĠĠĠĠĠ Ġexpect Item () Ġshould Contain Exactly ĠlistOf ( First . B , ĠSecond . B ) ĊĊĠĠĠĠĠĠĠ ĠviewModel . select Feature ( Second . C ) ĊĠĠĠĠĠĠĠ Ġexpect Item () Ġshould Contain Exactly ĠlistOf ( First . B , ĠSecond . C ) ĊĊĠĠĠĠĠĠĠ Ġcancel () ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġit (" resets Ġall Ġfeatures Ġto Ġtheir Ġdefault Ġvalues ") Ġ{ ĊĠĠĠĠĠ Ġval ĠviewModel Ġ= ĠFeatures ViewModel ( ĊĠĠĠĠĠĠĠĠĠ ĠConfiguration ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠLaboratory . in Memory (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġmap Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" First " Ġto Ġobject Ġ: ĠFeature Factory Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ@ Suppress (" UN CHECK ED _ CAST ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcreate () Ġ= Ġset Of ( Empty :: class . java , ĠFirst :: class . java ) Ġas ĠSet < Class < Feature <* >>> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Second " Ġto Ġobject Ġ: ĠFeature Factory Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ@ Suppress (" UN CHECK ED _ CAST ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcreate () Ġ= Ġset Of ( Second :: class . java ) Ġas ĠSet < Class < Feature <* >>> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ ĠviewModel . select Feature ( First . B ) ĊĠĠĠĠĠ ĠviewModel . select Feature ( Second . C ) ĊĊĠĠĠĠĠ ĠviewModel . reset All Features () ĊĊĠĠĠĠĠ ĠviewModel . observe Selected Features (" First "). first () Ġshould Contain Exactly ĠlistOf ( First . C ) ĊĠĠĠĠĠ ĠviewModel . observe Selected Features (" Second "). first () Ġshould Contain Exactly ĠlistOf ( Second . B ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġit (" resets Ġfeature Ġand Ġsources Ġto Ġtheir Ġdefault Ġvalues ") Ġ{ ĊĠĠĠĠĠ Ġval ĠviewModel Ġ= ĠFeatures ViewModel ( ĊĠĠĠĠĠĠĠĠĠ ĠConfiguration ( L abor atory . in Memory (), Ġmap Of (" Local " Ġto ĠS ourced Feature Factory )) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ ĠviewModel . select Feature ( S ourced . B ) ĊĠĠĠĠĠ ĠviewModel . select Feature ( S ourced . Source . Remote ) ĊĊĠĠĠĠĠ ĠviewModel . reset All Features () ĊĊĠĠĠĠĠ ĠviewModel . observe Selected Features And Sources (" Local "). first () Ġshould Contain Exactly ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠ ĠS ourced . A Ġto ĠS ourced . Source . Local , ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġit (" ob serves Ġsource Ġchanges ") Ġ{ ĊĠĠĠĠĠ Ġval ĠviewModel Ġ= ĠFeatures ViewModel ( ĊĠĠĠĠĠĠĠĠĠ ĠConfiguration ( L abor atory . in Memory (), Ġmap Of (" Local " Ġto ĠAll Feature Factory )) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ ĠviewModel . observe Selected Features And Sources (" Local "). test Ġ{ ĊĠĠĠĠĠĠĠ Ġexpect Item () Ġshould Contain Exactly ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠFirst . C Ġto Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSecond . B Ġto Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠS ourced . A Ġto ĠS ourced . Source . Local ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ ĠviewModel . select Feature ( S ourced . Source . Remote ) ĊĊĠĠĠĠĠĠĠ Ġexpect Item () Ġshould Contain Exactly ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠFirst . C Ġto Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSecond . B Ġto Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠS ourced . A Ġto ĠS ourced . Source . Remote ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ }) Ċ Ċ internal Ġfun ĠFeatures ViewModel . observe Selected Features And Sources ( ĊĠ Ġsection : ĠString , Ċ ) Ġ= Ġobserve Feature Groups ( section ). map Ġ{ Ġgroups Ġ-> ĊĠ Ġgroups . map Ġ{ Ġgroup Ġ-> ĊĠĠĠ Ġval Ġfeature Ġ= Ġgroup . models . single ( Feature Model :: isSelected ). feature ĊĠĠĠ Ġval Ġsource Ġ= Ġgroup . sources . single OrNull ( Feature Model :: isSelected )?. feature ĊĠĠĠ Ġfeature Ġto Ġsource ĊĠ Ġ} Ċ } Ċ Ċ internal Ġfun ĠFeatures ViewModel . observe Selected Features ( ĊĠ Ġsection : ĠString , Ċ ) Ġ= Ġobserve Selected Features And Sources ( section ). map Ġ{ Ġpairs Ġ-> ĊĠ Ġpairs . map Ġ{ Ġ( feature , Ġ_) Ġ-> Ġfeature Ġ} Ċ } Ċ Ċ private Ġobject ĠNo Source Feature Factory Ġ: ĠFeature Factory Ġ{ ĊĠ Ġoverride Ġfun Ġcreate (): ĠSet < Class < Feature <* >>> Ġ{ ĊĠĠĠ Ġ@ Suppress (" UN CHECK ED _ CAST ") ĊĠĠĠ Ġreturn Ġset Of ( Second :: class . java , ĠFirst :: class . java , ĠEmpty :: class . java ) Ġas ĠSet < Class < Feature <* >>> ĊĠ Ġ} Ċ } Ċ Ċ private Ġobject ĠS ourced Feature Factory Ġ: ĠFeature Factory Ġ{ ĊĠ Ġoverride Ġfun Ġcreate (): ĠSet < Class < Feature <* >>> Ġ{ ĊĠĠĠ Ġ@ Suppress (" UN CHECK ED _ CAST ") ĊĠĠĠ Ġreturn Ġset Of ( S ourced :: class . java ) Ġas ĠSet < Class < Feature <* >>> ĊĠ Ġ} Ċ } Ċ Ċ private Ġobject ĠAll Feature Factory Ġ: ĠFeature Factory Ġ{ ĊĠ Ġoverride Ġfun Ġcreate (): ĠSet < Class < Feature <* >>> Ġ{ ĊĠĠĠ Ġreturn ĠNo Source Feature Factory . create () Ġ+ ĠS ourced Feature Factory . create () ĊĠ Ġ} Ċ } Ċ Ċ private Ġenum Ġclass ĠFirst ( override Ġval Ġis DefaultValue : ĠBoolean Ġ= Ġfalse ) Ġ: ĠFeature < First > Ġ{ ĊĠ ĠC , ĊĠ ĠB , ĊĠ ĠA , ĊĠ Ġ; Ċ } Ċ Ċ private Ġenum Ġclass ĠSecond ( override Ġval Ġis DefaultValue : ĠBoolean Ġ= Ġfalse ) Ġ: ĠFeature < Second > Ġ{ ĊĠ ĠB , ĊĠ ĠC , ĊĠ ĠA , ĊĠ Ġ; Ċ } Ċ Ċ private Ġenum Ġclass ĠEmpty Ġ: ĠFeature < Empty > Ċ Ċ private Ġenum Ġclass ĠS ourced ( override Ġval Ġis DefaultValue : ĠBoolean Ġ= Ġfalse ) Ġ: ĠFeature < S ourced > Ġ{ ĊĠ ĠA , ĊĠ ĠB , ĊĠ ĠC , ĊĠ Ġ; ĊĊĠ Ġ@ Suppress (" UN CHECK ED _ CAST ") ĊĠ Ġoverride Ġval Ġs ourced With Ġ= ĠSource :: class . java Ġas ĠClass < Feature <* >> ĊĊĠ Ġenum Ġclass ĠSource ( override Ġval Ġis DefaultValue : ĠBoolean Ġ= Ġfalse ) Ġ: ĠFeature < Source > Ġ{ ĊĠĠĠ ĠLocal , ĊĠĠĠ ĠRemote , ĊĠĠĠ Ġ; ĊĠ Ġ} Ċ } Ċ