package Ġcom . github . ptr te ix e ira . cookbook . data Ċ Ċ import Ġcom . github . ptr te ix e ira . cookbook . core . Recipe E gg Ċ import Ġcom . github . ptr te ix e ira . cookbook . core . User Ċ import Ġcook book . server . src . test . kotlin . data . j db i Ċ import Ġcook book . server . src . test . kotlin . data . migrate Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Before All Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . slf 4 j . LoggerFactory Ċ Ċ class ĠRecipe Data Test Ġ{ ĊĠĠĠ Ġprivate Ġval ĠID Ġ= Ġ 0 ĊĠĠĠ Ġprivate Ġval ĠUSER Ġ= ĠUser (" test - user ") ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġit Returns Missing Recipes As Absent () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġrecipe Dao . get Recipe ( USER , ĠID ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. isEmpty () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġwhen No Recipes It Returns Empty List () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġrecipe Dao . get Recipes ( USER ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( result ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. isEmpty () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġit Allow s Recipes ToBe Created () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġid Ġ= Ġrecipe Dao . create Recipe Keys ( USER , Ġsample Recipe E gg ) ĊĠĠĠĠĠĠĠ Ġval Ġrecipe Ġ= Ġrecipe Dao . get Recipe ( USER , Ġid ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. get () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( recipe ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. isEqualTo ( sample Recipe E gg . to Recipe ( id , ĠUSER )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġwhen Recipes Added Return edList Contains Recipes () Ġ{ ĊĠĠĠĠĠĠĠ Ġrecipe Dao . create Recipe Keys ( USER , Ġsample Recipe E gg ) ĊĠĠĠĠĠĠĠ Ġval Ġall Recipes Ġ= Ġrecipe Dao . get Recipes ( USER ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( all Recipes ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. has Size ( 1 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. extract ing < String > Ġ{ Ġit . name Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contains Exactly ( sample Recipe E gg . name ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġit Allow s Recipes ToBe Deleted () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġid Ġ= Ġrecipe Dao . create Recipe Keys ( USER , Ġsample Recipe E gg ) ĊĊĠĠĠĠĠĠĠ Ġrecipe Dao . delete Recipe ( USER , Ġid ) ĊĊĠĠĠĠĠĠĠ Ġval Ġget Result Ġ= Ġrecipe Dao . get Recipe ( USER , Ġid ) ĊĠĠĠĠĠĠĠ ĠassertThat ( getResult ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. isEmpty () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġit Allow s Recipes ToBe Updated () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġid Ġ= Ġrecipe Dao . create Recipe Keys ( USER , Ġsample Recipe E gg ) ĊĠĠĠĠĠĠĠ Ġval Ġnew Ing redients Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" Eg gs ", Ġ" White ĠS ugar ", Ġ" B rown ĠS ugar ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" B utter ", Ġ" F lour ", Ġ" Cho colate ĠCh ips " ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġupdated Ġ= Ġsample Recipe E gg . copy ( ingredients Ġ= Ġnew Ing redients ) ĊĠĠĠĠĠĠĠ Ġrecipe Dao . patch Recipe Keys ( USER , Ġid , Ġupdated ) ĊĠĠĠĠĠĠĠ Ġval Ġget Result Ġ= Ġrecipe Dao . get Recipe ( USER , Ġid ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( getResult ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contains ( updated . to Recipe ( id , ĠUSER )) ĊĠĠĠĠĠĠĠ ĠassertThat ( getResult . get (). ingredients ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contains Exactly In Any Order (* new Ing redients . to Typed Array ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġit Only Lists Recipes For The Given User () Ġ{ ĊĠĠĠĠĠĠĠ Ġrecipe Dao . create Recipe Keys ( User (" user - 1 "), Ġsample Recipe E gg ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( recipe Dao . get Recipes ( User (" user - 2 "))) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. isEmpty () ĊĠĠĠĠĠĠĠ ĠassertThat ( recipe Dao . get Recipes ( User (" user - 1 "))) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. isNotEmpty () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġit For bids Access To Another Users Recipes () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġid Ġ= Ġrecipe Dao . create Recipe Keys ( User (" user - 1 "), Ġsample Recipe E gg ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( recipe Dao . get Recipe ( User (" user - 2 "), Ġid )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. isEmpty () ĊĠĠĠĠĠĠĠ ĠassertThat ( recipe Dao . get Recipe ( User (" user - 1 "), Ġid )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. isNotEmpty () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġit For bids Updates To Another Users Recipes () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġid Ġ= Ġrecipe Dao . create Recipe Keys ( User (" user - 1 "), Ġsample Recipe E gg ) ĊĊĠĠĠĠĠĠĠ Ġrecipe Dao . delete Recipe ( User (" user - 2 "), Ġid ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( recipe Dao . get Recipe ( User (" user - 1 "), Ġid )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. isNotEmpty () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun Ġtruncate Table () Ġ{ ĊĠĠĠĠĠĠĠ Ġdb i . with Handle < Unit , ĠNothing > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġit . create Update (" DELETE ĠFROM ĠRE CIP ES ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. execute () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġlogger Ġ= ĠLoggerFactory . getLogger ( Recipe Data Test :: class . java ) ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġdb i Ġ= Ġj db i () ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġrecipe Dao Ġ= Ġdb i . on Demand < Recipe Data >( Recipe Data :: class . java ) ĊĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġsample Recipe E gg Ġ= ĠRecipe E gg ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġname Ġ= Ġ" Cho colate ĠCh ip ĠCookies ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġingredients Ġ= ĠlistOf (" Cho colate ", Ġ" Chips ", Ġ" Cookies "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinstructions Ġ= Ġ" Mix ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsummary Ġ= Ġ" They Ġwere Ġinvent ed Ġright Ġhere Ġin ĠMass ach uset ts , Ġyou Ġknow ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdescription Ġ= Ġ" They 're Ġcho colate Ġchip Ġcookies . ĠW add ya Ġwant ?" ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġ@ Before All ĊĠĠĠĠĠĠĠ Ġ@ Jvm Static ĊĠĠĠĠĠĠĠ Ġfun Ġmigrate () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlogger . info (" Running Ġmigrations Ġbefore ĠDao Test ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmigrate ( db i ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ