package Ġcom . gmail . h ame dv ak hide . simp ler oom test . view model Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġcom . gmail . h ame dv ak hide . simp ler oom test . Main Coroutine Rule Ċ import Ġcom . gmail . h ame dv ak hide . simp ler oom test . data . Note Ċ import Ġcom . gmail . h ame dv ak hide . simp ler oom test . get Or Await Value Test Ċ import Ġcom . gmail . h ame dv ak hide . simp ler oom test . repositories . Fake Notes Repository Ċ import Ġcom . gmail . h ame dv ak hide . simp ler oom test . util . Status Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test ĊĊ Ċ @ Experimental Cor outines Api Ċ class ĠNote ViewModel Test Ġ{ ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġinstant Task Executor Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġ/// Ġrule Ġto Ġrun Ġcoroutine Ġon Ġunit Ġtest ĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġmain Coroutine Rule Ġ= ĠMain Coroutine Rule () ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠNote ViewModel ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup (){ ĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠNote ViewModel ( Fake Notes Repository ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` insert Ġnew Ġnote Ġwith Ġempty Ġfields Ġreturn Ġerror ` (){ ĊĠĠĠĠĠĠĠ ĠviewModel . insert Note (" Ġ"," ") ĊĠĠĠĠĠĠĠ Ġval Ġstatus Ġ= ĠviewModel . insert Note Status . get Or Await Value Test () ĊĠĠĠĠĠĠĠ ĠassertThat ( status . getContent IfNot Handled ()?. status ). isEqualTo ( Status . ERROR ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` insert Ġvalid Ġnote Ġreturn Ġsuccessful ` (){ ĊĠĠĠĠĠĠĠ ĠviewModel . insert Note (" test ", Ġ" test ") ĊĠĠĠĠĠĠĠ Ġval Ġstatus Ġ= ĠviewModel . insert Note Status . get Or Await Value Test () ĊĠĠĠĠĠĠĠ ĠassertThat ( status . getContent IfNot Handled ()?. status ). isEqualTo ( Status . SUCCESS ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` delete Ġnote Ġis Ġsuccessful ` (){ ĊĠĠĠĠĠĠĠ Ġval Ġnote Ġ= ĠNote (" test "," test ", 1 ) ĊĠĠĠĠĠĠĠ ĠviewModel . insert Note Into Db ( note ) ĊĠĠĠĠĠĠĠ ĠviewModel . delete Note ( note ) ĊĊĠĠĠĠĠĠĠ Ġval Ġlist Ġ= ĠviewModel . notes List . get Or Await Value Test () ĊĠĠĠĠĠĠĠ ĠassertThat ( list ). isEmpty () ĊĊĠĠĠ Ġ} Ċ }