/** Ċ * ĠCopyright ĠS or am its u ĠCo ., ĠLtd . ĠAll ĠRights ĠReserved . Ċ * ĠSPDX - License - Identifier : ĠGPL - 3 . 0 Ċ */ Ċ Ċ package Ġjp . co . sor am its u . feature _ project _ impl . data . repository . datasource Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġjp . co . sor am its u . common . data . Preferences Ċ import Ġjp . co . sor am its u . test _ shared . Rx Schedulers Rule Ċ import Ġjunit . framework . Assert . assertEquals Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . rules . Test Rule Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . BDD Mockito . given Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito . verify Ċ import Ġorg . mockito . junit . Mockito JUnit Runner Ċ Ċ @ RunWith ( Mockito JUnit Runner :: class ) Ċ class ĠP refs Project Datasource Test Ġ{ ĊĊĠĠĠ Ġ@ Rule Ġ@ Jvm Field Ġval Ġrule : ĠTest Rule Ġ= ĠInstant Task Executor Rule () ĊĠĠĠ Ġ@ Rule Ġ@ Jvm Field Ġval Ġrx Scheduler Rule Ġ= ĠRx Schedulers Rule () ĊĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġpreferences : ĠPreferences ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġprefs Project Datasource : ĠP refs Project Datasource ĊĊĠĠĠ Ġ@ Before Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġprefs Project Datasource Ġ= ĠP refs Project Datasource ( preferences ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` save Ġvotes Ġcalled `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġkey Votes Ġ= Ġ" key _ votes " ĊĠĠĠĠĠĠĠ Ġval Ġvotes Ġ= Ġ" 1 " ĊĊĠĠĠĠĠĠĠ Ġprefs Project Datasource . save Votes ( votes ) ĊĊĠĠĠĠĠĠĠ Ġverify ( preferences ). putString ( key Votes , Ġvotes ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` retrieve Ġvotes Ġcalled `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġkey Votes Ġ= Ġ" key _ votes " ĊĠĠĠĠĠĠĠ Ġval Ġvotes Ġ= Ġ" 1 " ĊĠĠĠĠĠĠĠ Ġgiven ( preferences . getString ( key Votes )). willReturn ( votes ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( votes , Ġprefs Project Datasource . retrieve Votes ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` save Ġlast Ġreceiver Ġvotes Ġcalled `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġkey Last Votes Ġ= Ġ" key _ projects _ last _ v oted " ĊĠĠĠĠĠĠĠ Ġval Ġvotes Ġ= Ġ" 1 " ĊĊĠĠĠĠĠĠĠ Ġprefs Project Datasource . save Last Received Votes ( votes ) ĊĊĠĠĠĠĠĠĠ Ġverify ( preferences ). putString ( key Last Votes , Ġvotes ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` retrieve Ġlast Ġreceiver Ġvotes Ġcalled `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġkey Last Votes Ġ= Ġ" key _ projects _ last _ v oted " ĊĠĠĠĠĠĠĠ Ġval Ġvotes Ġ= Ġ" 1 " ĊĠĠĠĠĠĠĠ Ġgiven ( preferences . getString ( key Last Votes )). willReturn ( votes ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( votes , Ġprefs Project Datasource . retrieve Last Received Votes ()) ĊĠĠĠ Ġ} Ċ } Ċ