package Ġcom . j sh v arts . lex ies ample . presentation . note detail Ċ Ċ import Ġandroid . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġandroid . arch . lifecycle . Observer Ċ import Ġcom . j sh v arts . lex ies ample . domain . Note Ċ import Ġcom . j sh v arts . lex ies ample . domain . Note Detail UseCase Ċ import Ġcom . j sh v arts . lex ies ample . presentation . Rx Test Scheduler Rule Ċ import Ġcom . n ha ar man . mockito _ kotlin . mock Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify No More Interactions Ċ import Ġcom . n ha ar man . mockito _ kotlin . wh enever Ċ import Ġio . reactivex . Single Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ Ċ private Ġconst Ġval ĠNOTE _ ID Ġ= Ġ 1 L Ċ private Ġconst Ġval ĠNOTE _ TEXT Ġ= Ġ" dummy Ġtext " Ċ Ċ class ĠNote Detail ViewModel Test Ġ{ ĊĠĠĠ Ġ@ get : Rule Ġval Ġinstant Executor Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġ@ get : Rule Ġval Ġtest Scheduler Rule Ġ= ĠRx Test Scheduler Rule () ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġtest Subject : ĠNote Detail ViewModel ĊĊĠĠĠ Ġprivate Ġval Ġidle State Ġ= ĠState ( is Idle Ġ= Ġtrue ) ĊĊĠĠĠ Ġprivate Ġval Ġnote Detail UseCase Ġ= Ġmock < Note Detail UseCase >() ĊĊĠĠĠ Ġprivate Ġval Ġobserver Ġ= Ġmock < Observer < State >>() ĊĊĠĠĠ Ġ@ Before Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġtest Subject Ġ= ĠNote Detail ViewModel ( idle State , Ġnote Detail UseCase ) ĊĠĠĠĠĠĠĠ Ġtest Subject . observable State . observe Fore ver ( observer ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` Given Ġnote Ġsuccessfully Ġloaded , Ġwhen Ġaction ĠLoad Note Detail Ġis Ġreceived , Ġthen ĠState Ġcontains Ġnote `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠG IV EN ĊĠĠĠĠĠĠĠ Ġval Ġnote Ġ= ĠNote ( NOTE _ ID , ĠNOTE _ TEXT ) ĊĠĠĠĠĠĠĠ Ġval Ġsuccess State Ġ= ĠState ( note ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( note Detail UseCase . findById ( NOTE _ ID )). thenReturn ( Single . just ( note )) ĊĊĠĠĠĠĠĠĠ Ġ// ĠWHEN ĊĠĠĠĠĠĠĠ Ġtest Subject . dispatch ( Action . Load Note Detail ( NOTE _ ID )) ĊĠĠĠĠĠĠĠ Ġtest Scheduler Rule . trigger Actions () ĊĊĠĠĠĠĠĠĠ Ġ// ĠTHEN ĊĠĠĠĠĠĠĠ Ġverify ( observer ). on Changed ( success State ) ĊĠĠĠĠĠĠĠ Ġverify No More Interactions ( observer ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` Given Ġnote Ġfailed Ġto Ġload , Ġwhen Ġaction ĠLoad Note Detail Ġis Ġreceived , Ġthen ĠState Ġcontains Ġerror `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠG IV EN ĊĠĠĠĠĠĠĠ Ġval Ġerror State Ġ= ĠState ( isError Ġ= Ġtrue ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( note Detail UseCase . findById ( NOTE _ ID )). thenReturn ( Single . error ( RuntimeException ())) ĊĊĠĠĠĠĠĠĠ Ġ// ĠWHEN ĊĠĠĠĠĠĠĠ Ġtest Subject . dispatch ( Action . Load Note Detail ( NOTE _ ID )) ĊĠĠĠĠĠĠĠ Ġtest Scheduler Rule . trigger Actions () ĊĊĠĠĠĠĠĠĠ Ġ// ĠTHEN ĊĠĠĠĠĠĠĠ Ġverify ( observer ). on Changed ( error State ) ĊĠĠĠĠĠĠĠ Ġverify No More Interactions ( observer ) ĊĠĠĠ Ġ} Ċ }