package Ġcom . air bnb . mv rx . navigation Ċ Ċ import Ġandroidx . lifecycle . Lifecycle Ċ import Ġorg . junit . Assert . assertFalse Ċ import Ġorg . junit . Assert . assertTrue Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . junit . runners . JUnit 4 Ċ import Ġjava . lang . IllegalStateException ĊĊĊ Ċ @ RunWith ( JUnit 4 :: class ) Ċ class ĠNavigation Lifecycle Aware Lazy Test Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġowner : ĠNav Test Lifecycle Owner ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlazy Prop : Ġnavigation Lifecycle Aware Lazy < String > ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġowner Ġ= ĠNav Test Lifecycle Owner () ĊĠĠĠĠĠĠĠ Ġlazy Prop Ġ= Ġnavigation Lifecycle Aware Lazy ( owner ) Ġ{ Ġ" Hello ĠWorld " Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Not Initialized Before On Create () Ġ{ ĊĠĠĠĠĠĠĠ Ġowner . lifecycle . currentState Ġ= ĠLifecycle . State . INITIAL IZED ĊĠĠĠĠĠĠĠ ĠassertFalse ( lazy Prop . isInitialized ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Not Initialized After On Create () Ġ{ ĊĠĠĠĠĠĠĠ Ġowner . lifecycle . currentState Ġ= ĠLifecycle . State . INITIAL IZED ĊĠĠĠĠĠĠĠ Ġowner . lifecycle . handle Lifecycle Event ( Lifecycle . Event . ON _ CREATE ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( lazy Prop . isInitialized ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Initialized If Already Started () Ġ{ ĊĠĠĠĠĠĠĠ Ġowner . lifecycle . currentState Ġ= ĠLifecycle . State . STARTED ĊĠĠĠĠĠĠĠ Ġlazy Prop Ġ= Ġnavigation Lifecycle Aware Lazy ( owner ) Ġ{ Ġ" Hello ĠWorld " Ġ} ĊĠĠĠĠĠĠĠ ĠassertTrue ( lazy Prop . isInitialized ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Not Initialized If Error Is Thrown () Ġ{ ĊĠĠĠĠĠĠĠ Ġowner . lifecycle . currentState Ġ= ĠLifecycle . State . STARTED ĊĠĠĠĠĠĠĠ Ġlazy Prop Ġ= Ġnavigation Lifecycle Aware Lazy ( owner ) Ġ{ Ġthrow ĠIllegalStateException () Ġ} ĊĠĠĠĠĠĠĠ ĠassertFalse ( lazy Prop . isInitialized ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Initialized After On Create Throws But On Start Suc ceeds () Ġ{ ĊĠĠĠĠĠĠĠ Ġowner . lifecycle . currentState Ġ= ĠLifecycle . State . CREATED ĊĠĠĠĠĠĠĠ Ġlazy Prop Ġ= Ġnavigation Lifecycle Aware Lazy ( owner ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif ( owner . lifecycle . currentState Ġ== ĠLifecycle . State . CREATED ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠIllegalStateException () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Hello ĠWorld " ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġowner . lifecycle . currentState Ġ= ĠLifecycle . State . STARTED ĊĠĠĠĠĠĠĠ Ġlazy Prop . lifecycle Observer . onStart ( owner ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( lazy Prop . isInitialized ()) ĊĠĠĠ Ġ} Ċ } ĊĊ