/* Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 1 7 ĠThe ĠAndroid ĠOpen ĠSource ĠProject Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġandroidx . room . integration . kot lint est app . test Ċ Ċ import Ġandroid . database . sqlite . SQLite Constraint Exception Ċ import Ġandroidx . arch . core . executor . Arch Task Executor Ċ import Ġandroidx . room . integration . kot lint est app . vo . Author Ċ import Ġandroidx . room . integration . kot lint est app . vo . Book Ċ import Ġandroidx . room . integration . kot lint est app . vo . Book With Publisher Ċ import Ġandroidx . room . integration . kot lint est app . vo . Lang Ċ import Ġandroidx . room . integration . kot lint est app . vo . Publisher Ċ import Ġandroidx . test . filters . Medium Test Ċ import Ġandroidx . test . filters . Sdk Suppress Ċ import Ġcom . google . common . base . Optional Ċ import Ġio . reactivex . Flow able Ċ import Ġio . reactivex . schedul ers . Schedulers Ċ import Ġio . reactivex . subscribers . Test Subscriber Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġorg . hamcrest . Core Matchers Ċ import Ġorg . hamcrest . Core Matchers .` is ` Ċ import Ġorg . hamcrest . Core Matchers . equalTo Ċ import Ġorg . hamcrest . Core Matchers . instance Of Ċ import Ġorg . hamcrest . Core Matchers . notNull Value Ċ import Ġorg . hamcrest . Matcher Assert . assertThat Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Assert . assertNotNull Ċ import Ġorg . junit . Assert . assertNull Ċ import Ġorg . junit . Assert . fail Ċ import Ġorg . junit . Test Ċ import Ġjava . util . Date Ċ Ċ @ Medium Test Ċ class ĠBooks Dao Test Ġ: ĠTest Database Test () Ġ{ ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbook ById () Ġ{ ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Authors ( TestUtil . AUTHOR _ 1 ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Publish ers ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Books ( TestUtil . BOOK _ 1 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( books Dao . get Book ( TestUtil . BOOK _ 1 . book Id ), Ġ` is `< Book >( TestUtil . BOOK _ 1 )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Sdk Suppress ( min Sdk Version Ġ= Ġ 2 4 ) ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbook ById Java Optional () Ġ{ ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Authors ( TestUtil . AUTHOR _ 1 ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Publish ers ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Books ( TestUtil . BOOK _ 1 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Dao . get Book Java Optional ( TestUtil . BOOK _ 1 . book Id ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` is `< java . util . Optional < Book >>( java . util . Optional . of ( TestUtil . BOOK _ 1 )) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Sdk Suppress ( min Sdk Version Ġ= Ġ 2 4 ) ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbook ById Java Optional Empty () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Dao . get Book Java Optional ( TestUtil . BOOK _ 1 . book Id ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` is `< java . util . Optional < Book >>( java . util . Optional . empty ()) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbook ById List enable Future () Ġ{ ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Authors ( TestUtil . AUTHOR _ 1 ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Publish ers ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Books ( TestUtil . BOOK _ 1 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Dao . get Book List enable Future ( TestUtil . BOOK _ 1 . book Id ). get (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` is `< Book >( TestUtil . BOOK _ 1 ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbook ById Optional () Ġ{ ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Authors ( TestUtil . AUTHOR _ 1 ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Publish ers ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Books ( TestUtil . BOOK _ 1 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Dao . get Book Optional ( TestUtil . BOOK _ 1 . book Id ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` is `< Optional < Book >>( Optional . of ( TestUtil . BOOK _ 1 )) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbook ById Optional List enable Future () Ġ{ ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Authors ( TestUtil . AUTHOR _ 1 ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Publish ers ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Books ( TestUtil . BOOK _ 1 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Dao . get Book Optional List enable Future ( TestUtil . BOOK _ 1 . book Id ). get (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` is `< Optional < Book >>( Optional . of ( TestUtil . BOOK _ 1 )) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbook ById Optional List enable Future Absent () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Dao . get Book Optional List enable Future ( TestUtil . BOOK _ 1 . book Id ). get (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` is `< Optional < Book >>( Optional . abs ent ()) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbook ById Optional Absent () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Dao . get Book Optional ( TestUtil . BOOK _ 1 . book Id ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` is `< Optional < Book >>( Optional . abs ent ()) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbook ById Optional Flow able () Ġ{ ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Authors ( TestUtil . AUTHOR _ 1 ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Publish ers ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Books ( TestUtil . BOOK _ 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġsubscriber Ġ= ĠTest Subscriber < Optional < Book >>() ĊĠĠĠĠĠĠĠ Ġval Ġflow able : ĠFlow able < Optional < Book >> Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Dao . get Book Optional Flow able ( TestUtil . BOOK _ 1 . book Id ) ĊĠĠĠĠĠĠĠ Ġflow able . observe On ( Schedulers . from ( Arch Task Executor . get MainThread Executor ())) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe With ( subscriber ) ĊĠĠĠĠĠĠĠ Ġdrain () ĊĠĠĠĠĠĠĠ ĠassertThat ( subscriber . values (). size , Ġ` is `( 1 )) ĊĠĠĠĠĠĠĠ ĠassertThat ( subscriber . values ()[ 0 ], Ġ` is `( Optional . of ( TestUtil . BOOK _ 1 ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbook ById Optional Flow able Absent () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsubscriber Ġ= ĠTest Subscriber < Optional < Book >>() ĊĠĠĠĠĠĠĠ Ġval Ġflow able : ĠFlow able < Optional < Book >> Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Dao . get Book Optional Flow able ( TestUtil . BOOK _ 1 . book Id ) ĊĠĠĠĠĠĠĠ Ġflow able . observe On ( Schedulers . from ( Arch Task Executor . get MainThread Executor ())) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe With ( subscriber ) ĊĠĠĠĠĠĠĠ Ġdrain () ĊĠĠĠĠĠĠĠ ĠassertThat ( subscriber . values (). size , Ġ` is `( 1 )) ĊĠĠĠĠĠĠĠ ĠassertThat ( subscriber . values ()[ 0 ], Ġ` is `( Optional . abs ent ())) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbook With Publisher () Ġ{ ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Authors ( TestUtil . AUTHOR _ 1 ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Publish ers ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Books ( TestUtil . BOOK _ 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġexpected Ġ= ĠBook With Publisher ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTest Util . BOOK _ 1 . book Id , ĠTest Util . BOOK _ 1 . title , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTest Util . PUBL IS HER ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġexpected List Ġ= ĠArrayList < Book With Publisher >() ĊĠĠĠĠĠĠĠ Ġexpected List . add ( expected ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdatabase . books Dao (). get Books With Publisher (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` is `< List < Book With Publisher >>( expected List ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbook With Publisher List enable Future () Ġ{ ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Authors ( TestUtil . AUTHOR _ 1 ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Publish ers ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Books ( TestUtil . BOOK _ 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġexpected Ġ= ĠBook With Publisher ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTest Util . BOOK _ 1 . book Id , ĠTest Util . BOOK _ 1 . title , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTest Util . PUBL IS HER ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġexpected List Ġ= ĠArrayList < Book With Publisher >() ĊĠĠĠĠĠĠĠ Ġexpected List . add ( expected ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdatabase . books Dao (). get Books With Publisher List enable Future (). get (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` is `< List < Book With Publisher >>( expected List ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġupdate Book With Null Title () Ġ{ ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Publish ers ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Books ( TestUtil . BOOK _ 1 ) ĊĊĠĠĠĠĠĠĠ Ġvar Ġthrowable : ĠThrowable ? Ġ= Ġnull ĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Dao . update Book Title ( TestUtil . BOOK _ 1 . book Id , Ġnull ) ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( t : ĠThrowable ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrowable Ġ= Ġt ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠassertNotNull ( throwable ) ĊĠĠĠĠĠĠĠ ĠassertThat < Throwable >( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrowable , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinstance Of < Throwable >( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSQLite Constraint Exception :: class ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. java ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġpublisher With Books () Ġ{ ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Authors ( TestUtil . AUTHOR _ 1 ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Publish ers ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Books ( TestUtil . BOOK _ 1 , ĠTest Util . BOOK _ 2 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Publisher With Books Ġ= Ġbooks Dao . get Publisher With Books ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTest Util . PUBL IS HER . publisher Id ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( actual Publisher With Books . publisher , Ġ` is `< Publisher >( TestUtil . PUBL IS HER )) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual Publisher With Books . books ?. size , Ġ` is `( 2 )) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual Publisher With Books . books ?. get ( 0 ), Ġ` is `< Book >( TestUtil . BOOK _ 1 )) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual Publisher With Books . books ?. get ( 1 ), Ġ` is `< Book >( TestUtil . BOOK _ 2 )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġ// Ġb / 6 8 0 7 7 5 0 6 ĊĠĠĠ Ġfun Ġpublisher With Book Sales () Ġ{ ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Authors ( TestUtil . AUTHOR _ 1 ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Publish ers ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Books ( TestUtil . BOOK _ 1 , ĠTest Util . BOOK _ 2 ) ĊĠĠĠĠĠĠĠ Ġval Ġactual Publisher With Books Ġ= Ġbooks Dao . get Publisher With Book Sales ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTest Util . PUBL IS HER . publisher Id ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( actual Publisher With Books . publisher , Ġ` is `< Publisher >( TestUtil . PUBL IS HER )) ĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactual Publisher With Books . sales , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` is `( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Util . BOOK _ 1 . sales Cnt , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Util . BOOK _ 2 . sales Cnt ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġinsert Author With All Fields () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġauthor Ġ= ĠAuthor (" id ", Ġ" name ", ĠDate (), ĠArrayList ()) ĊĠĠĠĠĠĠĠ Ġdatabase . books Dao (). add Authors ( author ) ĊĊĠĠĠĠĠĠĠ Ġval Ġauthor Db Ġ= Ġdatabase . books Dao (). get Author ( author . author Id ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( author Db , ĠCore Matchers .` is `< Author >( author )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġinsert In Inherited Dao () Ġ{ ĊĠĠĠĠĠĠĠ Ġdatabase . derived Dao (). insert ( TestUtil . AUTHOR _ 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġauthor Ġ= Ġdatabase . derived Dao (). get Author ( TestUtil . AUTHOR _ 1 . author Id ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( author , ĠCore Matchers .` is `< Author >( TestUtil . AUTHOR _ 1 )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfind Books In Multi Line Query () Ġ{ ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Publish ers ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Books ( TestUtil . BOOK _ 1 ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Books ( TestUtil . BOOK _ 2 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġbooks Ġ= Ġdatabase . books Dao (). get Books Multi Line Query ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġarray ListOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Util . BOOK _ 1 . book Id , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Util . BOOK _ 2 . book Id ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ ĠassertThat ( books , Ġ` is `( listOf ( TestUtil . BOOK _ 2 , ĠTest Util . BOOK _ 1 ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfind Books By Language () Ġ{ ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Publish ers ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ Ġval Ġbook 1 Ġ= ĠTest Util . BOOK _ 1 . copy ( languages Ġ= Ġset Of ( Lang . TR )) ĊĠĠĠĠĠĠĠ Ġval Ġbook 2 Ġ= ĠTest Util . BOOK _ 2 . copy ( languages Ġ= Ġset Of ( Lang . ES , ĠLang . TR )) ĊĠĠĠĠĠĠĠ Ġval Ġbook 3 Ġ= ĠTest Util . BOOK _ 3 . copy ( languages Ġ= Ġset Of ( Lang . EN )) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Books ( book 1 , Ġbook 2 , Ġbook 3 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Dao . findBy Languages ( set Of ( Lang . EN , ĠLang . TR )), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` is `( listOf ( book 1 , Ġbook 2 , Ġbook 3 )) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Dao . findBy Languages ( set Of ( Lang . TR )), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` is `( listOf ( book 1 , Ġbook 2 )) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Dao . findBy Languages ( set Of ( Lang . ES )), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` is `( listOf ( book 2 )) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Dao . findBy Languages ( set Of ( Lang . EN )), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` is `( listOf ( book 3 )) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġinsert Var arg In Inherited Dao () Ġ{ ĊĠĠĠĠĠĠĠ Ġdatabase . derived Dao (). insert All Arg ( TestUtil . AUTHOR _ 1 , ĠTest Util . AUTHOR _ 2 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġauthor Ġ= Ġdatabase . derived Dao (). get Author ( TestUtil . AUTHOR _ 1 . author Id ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( author , ĠCore Matchers .` is `< Author >( TestUtil . AUTHOR _ 1 )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġinsert List In Inherited Dao () Ġ{ ĊĠĠĠĠĠĠĠ Ġdatabase . derived Dao (). insert All ( listOf ( TestUtil . AUTHOR _ 1 )) ĊĊĠĠĠĠĠĠĠ Ġval Ġauthor Ġ= Ġdatabase . derived Dao (). get Author ( TestUtil . AUTHOR _ 1 . author Id ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( author , ĠCore Matchers .` is `< Author >( TestUtil . AUTHOR _ 1 )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdelete And Add Publisher () Ġ{ ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Publish ers ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . get Publish ers (). run Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( this . size , Ġ` is `( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( this . first (), Ġ` is `( equalTo ( TestUtil . PUBL IS HER ))) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġbooks Dao . delete And Add Publisher ( TestUtil . PUBL IS HER , ĠTest Util . PUBL IS HER 2 ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . get Publish ers (). run Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( this . size , Ġ` is `( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( this . first (), Ġ` is `( equalTo ( TestUtil . PUBL IS HER 2 ))) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdelete And Add Publisher _ failure () Ġ{ ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Publish ers ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . get Publish ers (). run Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( this . size , Ġ` is `( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( this . first (), Ġ` is `( equalTo ( TestUtil . PUBL IS HER ))) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġvar Ġthrowable : ĠThrowable ? Ġ= Ġnull ĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Dao . delete And Add Publisher ( TestUtil . PUBL IS HER , ĠTest Util . PUBL IS HER 2 , Ġtrue ) ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( e : ĠRuntimeException ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrowable Ġ= Ġe ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠassertThat ( throwable , Ġ` is `( notNull Value ())) ĊĠĠĠĠĠĠĠ Ġbooks Dao . get Publish ers (). run Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( this . size , Ġ` is `( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( this . first (), Ġ` is `( equalTo ( TestUtil . PUBL IS HER ))) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdelete Books With Zero Sales () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbooks Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTest Util . BOOK _ 1 . copy ( sales Cnt Ġ= Ġ 0 ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTest Util . BOOK _ 2 . copy ( sales Cnt Ġ= Ġ 0 ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Publish ers ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ Ġbooks Dao . add Books (* books . to Typed Array ()) ĊĊĠĠĠĠĠĠĠ Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( books Dao . delete Books With Zero Sales (), Ġ` is `( equalTo ( books ))) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( books Dao . get Books Suspend (), Ġ` is `( equalTo ( emptyList ()))) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġadd Author Publisher Books _ failure () Ġ{ ĊĠĠĠĠĠĠĠ Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Dao . add Author Publisher Books ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġauthor Ġ= ĠTest Util . AUTHOR _ 1 , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpublisher Ġ= ĠTest Util . PUBL IS HER , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġbooks Ġ= ĠarrayOf ( TestUtil . BOOK _ 1 , ĠTest Util . BOOK _ 1 ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfail (" add Author Publisher Books Ġshould Ġhave Ġfailed ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( ex : ĠSQLite Constraint Exception ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġignored Ġon Ġpurpose ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( books Dao . get Books Suspend (). isEmpty (), Ġ` is `( true )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġkotlin Default Function () Ġ{ ĊĠĠĠĠĠĠĠ Ġbooks Dao . add And Remove Publisher ( TestUtil . PUBL IS HER ) ĊĠĠĠĠĠĠĠ ĠassertNull ( books Dao . get Publisher ( TestUtil . PUBL IS HER . publisher Id )) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ("", Ġbooks Dao . concrete Function ()) ĊĠĠĠĠĠĠĠ ĠassertEquals (" 1 Ġ- Ġhello ", Ġbooks Dao . concrete Function With Params ( 1 , Ġ" hello ")) ĊĊĠĠĠĠĠĠĠ Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ("", Ġbooks Dao . concrete Suspend Function ()) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals (" 2 Ġ- Ġhi ", Ġbooks Dao . concrete Suspend Function With Params ( 2 , Ġ" hi ")) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ