package Ġeu . kan ade . t ach iy omi . data . database Ċ Ċ import Ġandroid . os . Build Ċ import Ġeu . kan ade . t ach iy omi . Build Config Ċ import Ġeu . kan ade . t ach iy omi . Custom Ro bo lectric Gradle TestRunner Ċ import Ġeu . kan ade . t ach iy omi . data . database . models . Category Impl Ċ import Ġeu . kan ade . t ach iy omi . data . database . models . M anga Ċ import Ġeu . kan ade . t ach iy omi . data . database . models . M anga Category Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . ro bo lectric . Runtime Environment Ċ import Ġorg . ro bo lectric . annotation . Config Ċ Ċ @ Config ( constants Ġ= ĠBuild Config :: class , Ġsdk Ġ= Ġ[ Build . VERSION _ CODES . LO L LI POP ]) Ċ @ RunWith ( Custom Ro bo lectric Gradle TestRunner :: class ) Ċ class ĠCategory Test Ġ{ ĊĊĠĠĠ Ġlateinit Ġvar Ġdb : ĠDatabase Helper ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġapp Ġ= ĠRuntime Environment . application ĊĠĠĠĠĠĠĠ Ġdb Ġ= ĠDatabase Helper ( app ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠCreate Ġ 5 Ġm anga ĊĠĠĠĠĠĠĠ Ġcreate M anga (" a ") ĊĠĠĠĠĠĠĠ Ġcreate M anga (" b ") ĊĠĠĠĠĠĠĠ Ġcreate M anga (" c ") ĊĠĠĠĠĠĠĠ Ġcreate M anga (" d ") ĊĠĠĠĠĠĠĠ Ġcreate M anga (" e ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Has Categories () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠCreate Ġ 2 Ġcategories ĊĠĠĠĠĠĠĠ Ġcreate Category (" Reading ") ĊĠĠĠĠĠĠĠ Ġcreate Category (" Hold ") ĊĊĠĠĠĠĠĠĠ Ġval Ġcategories Ġ= Ġdb . getC ategories (). execute As Blocking () ĊĠĠĠĠĠĠĠ ĠassertThat ( categories ). has Size ( 2 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Has Library M ang as () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġm ang as Ġ= Ġdb . get Library M ang as (). execute As Blocking () ĊĠĠĠĠĠĠĠ ĠassertThat ( m ang as ). has Size ( 5 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Has Correct F avorites () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġm Ġ= ĠM anga . create ( 0 ) ĊĠĠĠĠĠĠĠ Ġm . title Ġ= Ġ" title " ĊĠĠĠĠĠĠĠ Ġm . author Ġ= Ġ"" ĊĠĠĠĠĠĠĠ Ġm . artist Ġ= Ġ"" ĊĠĠĠĠĠĠĠ Ġm . thumbnail _ url Ġ= Ġ"" ĊĠĠĠĠĠĠĠ Ġm . genre Ġ= Ġ" a Ġlist Ġof Ġgen res " ĊĠĠĠĠĠĠĠ Ġm . description Ġ= Ġ" long Ġdescription " ĊĠĠĠĠĠĠĠ Ġm . url Ġ= Ġ" url Ġto Ġm anga " ĊĠĠĠĠĠĠĠ Ġm . favorite Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġdb . insert M anga ( m ). execute As Blocking () ĊĠĠĠĠĠĠĠ Ġval Ġm ang as Ġ= Ġdb . get Library M ang as (). execute As Blocking () ĊĠĠĠĠĠĠĠ ĠassertThat ( m ang as ). has Size ( 5 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest M anga In Category () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠCreate Ġ 2 Ġcategories ĊĠĠĠĠĠĠĠ Ġcreate Category (" Reading ") ĊĠĠĠĠĠĠĠ Ġcreate Category (" Hold ") ĊĊĠĠĠĠĠĠĠ Ġ// ĠIt Ġshould Ġnot Ġhave Ġ 0 Ġas Ġid ĊĠĠĠĠĠĠĠ Ġval Ġc Ġ= Ġdb . getC ategories (). execute As Blocking ()[ 0 ] ĊĠĠĠĠĠĠĠ ĠassertThat ( c . id ). isNot Zero ĊĊĠĠĠĠĠĠĠ Ġ// ĠAdd Ġa Ġm anga Ġto Ġa Ġcategory ĊĠĠĠĠĠĠĠ Ġval Ġm Ġ= Ġdb . get Library M ang as (). execute As Blocking ()[ 0 ] ĊĠĠĠĠĠĠĠ Ġval Ġmc Ġ= ĠM anga Category . create ( m , Ġc ) ĊĠĠĠĠĠĠĠ Ġdb . insert M anga Category ( mc ). execute As Blocking () ĊĊĠĠĠĠĠĠĠ Ġ// ĠGet Ġm ang as Ġfrom Ġlibrary Ġand Ġassert Ġm anga Ġcategory Ġis Ġthe Ġsame ĊĠĠĠĠĠĠĠ Ġval Ġm ang as Ġ= Ġdb . get Library M ang as (). execute As Blocking () ĊĠĠĠĠĠĠĠ Ġfor Ġ( manga Ġin Ġm ang as ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( manga . id Ġ== Ġm . id ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( manga . category ). isEqualTo ( c . id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate M anga ( title : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġm Ġ= ĠM anga . create ( 0 ) ĊĠĠĠĠĠĠĠ Ġm . title Ġ= Ġtitle ĊĠĠĠĠĠĠĠ Ġm . author Ġ= Ġ"" ĊĠĠĠĠĠĠĠ Ġm . artist Ġ= Ġ"" ĊĠĠĠĠĠĠĠ Ġm . thumbnail _ url Ġ= Ġ"" ĊĠĠĠĠĠĠĠ Ġm . genre Ġ= Ġ" a Ġlist Ġof Ġgen res " ĊĠĠĠĠĠĠĠ Ġm . description Ġ= Ġ" long Ġdescription " ĊĠĠĠĠĠĠĠ Ġm . url Ġ= Ġ" url Ġto Ġm anga " ĊĠĠĠĠĠĠĠ Ġm . favorite Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġdb . insert M anga ( m ). execute As Blocking () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Category ( name : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġc Ġ= ĠCategory Impl () ĊĠĠĠĠĠĠĠ Ġc . name Ġ= Ġname ĊĠĠĠĠĠĠĠ Ġdb . insert Category ( c ). execute As Blocking () ĊĠĠĠ Ġ} Ċ } Ċ