package Ġcall ceptor . com . call ceptor Ċ Ċ import Ġandroid . arch . persistence . room . Room Ċ import Ġandroid . support . test . Instrumentation Registry Ċ import Ġandroid . support . test . runner . Android JUnit 4 Ċ import Ġcall ceptor . com . call ceptor . data . db . Call ceptor DAO Ċ import Ġcall ceptor . com . call ceptor . data . db . Call ceptor Database Ċ import Ġcall ceptor . com . call ceptor . data . models . Call Ċ import Ġcall ceptor . com . call ceptor . data . models . Message Ċ import Ġcall ceptor . com . call ceptor . utils . App Constants . Companion . PAGE _ ENTR IES Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ Ċ /** Ċ Ġ* ĠCreated Ġby ĠTom Ġon Ġ 2 8 . 8 . 2 0 1 8 .. Ċ Ġ*/ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠCall ceptor DAO Test Ġ{ ĊĊĠĠĠ Ġlateinit Ġvar Ġcall ceptor DAO : ĠCall ceptor DAO ĊĠĠĠ Ġlateinit Ġvar Ġdatabase : ĠCall ceptor Database ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcontext Ġ= ĠInstrument ation Registry . getTarget Context () ĊĠĠĠĠĠĠĠ Ġdatabase Ġ= ĠRoom . in Memory Database Builder ( context , ĠCall ceptor Database :: class . java ). build () ĊĠĠĠĠĠĠĠ Ġcall ceptor DAO Ġ= Ġdatabase . get Call ceptor Dao () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠĠĠĠĠ Ġdatabase . close () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Save Get Delete Calls () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcalls Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCall (" 1 2 . 1 2 . 2 0 1 8 .", Ġ 1 , Ġ" 1 2 ", Ġ"+ 3 8 5 9 1 1 2 3 4 5 6 7 8 ", Ġ" https :// cdn . pix ab ay . com / photo / 2 0 1 3 / 0 4 / 0 6 / 1 1 / 5 0 / image - editing - 1 0 1 0 4 0 _ 9 6 0 _ 7 2 0 . jpg ", Ġ" User ", Ġ 1 5 3 5 5 2 7 9 0 2 0 3 2 ," 1 "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCall (" 1 2 . 1 1 . 2 0 1 8 .", Ġ 4 , Ġ" 5 ", Ġ"+ 3 8 5 9 1 1 6 4 2 7 5 8 2 ", Ġ" https :// cdn . pix ab ay . com / photo / 2 0 1 3 / 0 4 / 0 6 / 1 1 / 5 0 / image - editing - 1 0 1 0 4 0 _ 9 6 0 _ 7 2 0 . jpg ", Ġ" User 2 ", Ġ 1 5 3 5 5 2 7 9 0 2 0 3 3 , Ġ" 3 "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCall (" 1 . 1 . 2 0 1 8 .", Ġ 3 , Ġ" 3 ", Ġ"+ 3 8 5 9 1 1 2 3 4 3 2 4 5 ", Ġ" https :// cdn . pix ab ay . com / photo / 2 0 1 3 / 0 4 / 0 6 / 1 1 / 5 0 / image - editing - 1 0 1 0 4 0 _ 9 6 0 _ 7 2 0 . jpg ", Ġ" User 3 ", Ġ 1 5 3 5 5 2 7 9 0 2 0 3 4 ," 5 ")) ĊĊĊĠĠĠĠĠĠĠ Ġval Ġcalls 2 Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCall (" 5 . 5 . 2 0 1 8 .", Ġ 5 , Ġ" 1 ", Ġ"+ 3 8 5 9 1 1 2 3 4 5 6 7 8 ", Ġ" https :// cdn . pix ab ay . com / photo / 2 0 1 3 / 0 4 / 0 6 / 1 1 / 5 0 / image - editing - 1 0 1 0 4 0 _ 9 6 0 _ 7 2 0 . jpg ", Ġ" User 4 ", Ġ 1 5 3 5 5 2 7 9 0 2 0 3 5 ," 1 "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCall (" 6 . 6 . 2 0 1 8 .", Ġ 1 , Ġ" 1 5 ", Ġ"+ 3 8 5 9 1 1 6 4 2 7 5 8 2 ", Ġ" https :// cdn . pix ab ay . com / photo / 2 0 1 3 / 0 4 / 0 6 / 1 1 / 5 0 / image - editing - 1 0 1 0 4 0 _ 9 6 0 _ 7 2 0 . jpg ", Ġ" User 5 ", Ġ 1 5 3 5 5 2 7 9 0 2 0 3 6 ," 3 "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCall (" 1 . 1 2 . 2 0 1 8 .", Ġ 6 , Ġ" 1 3 ", Ġ"+ 3 8 5 9 1 1 2 3 4 3 2 4 5 ", Ġ" https :// cdn . pix ab ay . com / photo / 2 0 1 3 / 0 4 / 0 6 / 1 1 / 5 0 / image - editing - 1 0 1 0 4 0 _ 9 6 0 _ 7 2 0 . jpg ", Ġ" User 6 ", Ġ 1 5 3 5 5 2 7 9 0 2 0 3 7 ," 5 ")) ĊĊĠĠĠĠĠĠĠ Ġval Ġsingle Call Ġ= ĠCall (" 1 1 . 6 . 2 0 1 8 .", Ġ 4 , Ġ" 5 ", Ġ"+ 3 8 5 9 3 8 6 4 2 7 5 8 2 ", Ġ" https :// cdn . pix ab ay . com / photo / 2 0 1 3 / 0 4 / 0 6 / 1 1 / 5 0 / image - editing - 1 0 1 0 4 0 _ 9 6 0 _ 7 2 0 . jpg ", Ġ" J ake ĠWh art on ", Ġ 1 5 3 5 5 2 7 9 0 2 0 3 8 ," 6 ") ĊĊĊĠĠĠĠĠĠĠ Ġcall ceptor DAO . save Incoming Calls ( ArrayList ( calls )) ĊĠĠĠĠĠĠĠ Ġcall ceptor DAO . save Incoming Call ( single Call ) ĊĠĠĠĠĠĠĠ Ġcall ceptor DAO . save Incoming Calls ( ArrayList ( calls 2 )) ĊĊĠĠĠĠĠĠĠ Ġval Ġget Results Ġ= Ġcall ceptor DAO . get Calls ( 0 , ĠPAGE _ ENTR IES ) ĊĊĠĠĠĠĠĠĠ Ġval Ġexpected Result Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCall (" 1 1 . 6 . 2 0 1 8 .", Ġ 4 , Ġ" 5 ", Ġ"+ 3 8 5 9 3 8 6 4 2 7 5 8 2 ", Ġ" https :// cdn . pix ab ay . com / photo / 2 0 1 3 / 0 4 / 0 6 / 1 1 / 5 0 / image - editing - 1 0 1 0 4 0 _ 9 6 0 _ 7 2 0 . jpg ", Ġ" J ake ĠWh art on ", Ġ 1 5 3 5 5 2 7 9 0 2 0 3 8 ," 6 "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCall (" 1 . 1 2 . 2 0 1 8 .", Ġ 6 , Ġ" 1 3 ", Ġ"+ 3 8 5 9 1 1 2 3 4 3 2 4 5 ", Ġ" https :// cdn . pix ab ay . com / photo / 2 0 1 3 / 0 4 / 0 6 / 1 1 / 5 0 / image - editing - 1 0 1 0 4 0 _ 9 6 0 _ 7 2 0 . jpg ", Ġ" User 6 ", Ġ 1 5 3 5 5 2 7 9 0 2 0 3 7 ," 5 "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCall (" 6 . 6 . 2 0 1 8 .", Ġ 1 , Ġ" 1 5 ", Ġ"+ 3 8 5 9 1 1 6 4 2 7 5 8 2 ", Ġ" https :// cdn . pix ab ay . com / photo / 2 0 1 3 / 0 4 / 0 6 / 1 1 / 5 0 / image - editing - 1 0 1 0 4 0 _ 9 6 0 _ 7 2 0 . jpg ", Ġ" User 5 ", Ġ 1 5 3 5 5 2 7 9 0 2 0 3 6 ," 3 "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCall (" 5 . 5 . 2 0 1 8 .", Ġ 5 , Ġ" 1 ", Ġ"+ 3 8 5 9 1 1 2 3 4 5 6 7 8 ", Ġ" https :// cdn . pix ab ay . com / photo / 2 0 1 3 / 0 4 / 0 6 / 1 1 / 5 0 / image - editing - 1 0 1 0 4 0 _ 9 6 0 _ 7 2 0 . jpg ", Ġ" User 4 ", Ġ 1 5 3 5 5 2 7 9 0 2 0 3 5 ," 1 "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCall (" 1 . 1 . 2 0 1 8 .", Ġ 3 , Ġ" 3 ", Ġ"+ 3 8 5 9 1 1 2 3 4 3 2 4 5 ", Ġ" https :// cdn . pix ab ay . com / photo / 2 0 1 3 / 0 4 / 0 6 / 1 1 / 5 0 / image - editing - 1 0 1 0 4 0 _ 9 6 0 _ 7 2 0 . jpg ", Ġ" User 3 ", Ġ 1 5 3 5 5 2 7 9 0 2 0 3 4 ," 5 "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCall (" 1 2 . 1 1 . 2 0 1 8 .", Ġ 4 , Ġ" 5 ", Ġ"+ 3 8 5 9 1 1 6 4 2 7 5 8 2 ", Ġ" https :// cdn . pix ab ay . com / photo / 2 0 1 3 / 0 4 / 0 6 / 1 1 / 5 0 / image - editing - 1 0 1 0 4 0 _ 9 6 0 _ 7 2 0 . jpg ", Ġ" User 2 ", Ġ 1 5 3 5 5 2 7 9 0 2 0 3 3 ," 3 "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCall (" 1 2 . 1 2 . 2 0 1 8 .", Ġ 1 , Ġ" 1 2 ", Ġ"+ 3 8 5 9 1 1 2 3 4 5 6 7 8 ", Ġ" https :// cdn . pix ab ay . com / photo / 2 0 1 3 / 0 4 / 0 6 / 1 1 / 5 0 / image - editing - 1 0 1 0 4 0 _ 9 6 0 _ 7 2 0 . jpg ", Ġ" User ", Ġ 1 5 3 5 5 2 7 9 0 2 0 3 2 ," 1 ")) ĊĊĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( get Results [ 0 ]. timestamp , Ġexpected Result [ 0 ]. timestamp ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( get Results [ 6 ]. timestamp , Ġexpected Result [ 6 ]. timestamp ) ĊĊĠĠĠĠĠĠĠ Ġval Ġget Deleted Rows Ġ= Ġcall ceptor DAO . delete Calls () ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( 7 , Ġget Deleted Rows ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Save Get Delete Messages () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmessages Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠMessage (" 1 2 . 1 2 . 2 0 1 8 .", Ġ"+ 3 8 5 9 1 1 2 3 4 5 6 7 8 ", Ġ" Incoming ĠSMS Ġmessage Ġ 1 ", Ġ" User ", Ġ" 1 5 3 5 5 2 7 9 0 2 0 3 2 "," 1 "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠMessage (" 1 2 . 1 1 . 2 0 1 8 .", Ġ"+ 3 8 5 9 1 1 6 4 2 7 5 8 2 ", Ġ" Incoming ĠSMS Ġmessage Ġ 2 ", Ġ" User 2 ", Ġ" 1 5 3 5 5 2 7 9 0 2 0 3 3 "," 3 "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠMessage (" 1 . 1 . 2 0 1 8 .", Ġ"+ 3 8 5 9 1 1 2 3 4 3 2 4 5 ", Ġ" Incoming ĠSMS Ġmessage Ġ 3 ", Ġ" User 3 ", Ġ" 1 5 3 5 5 2 7 9 0 2 0 3 4 "," 5 ")) ĊĊĊĠĠĠĠĠĠĠ Ġval Ġmessages 2 Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠMessage (" 5 . 5 . 2 0 1 8 .", Ġ"+ 3 8 5 9 1 1 2 3 4 5 6 7 8 ", Ġ" Incoming ĠSMS Ġmessage Ġ 4 ", Ġ" User 4 ", Ġ" 1 5 3 5 5 2 7 9 0 2 0 3 5 "," 1 "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠMessage (" 6 . 6 . 2 0 1 8 .", Ġ"+ 3 8 5 9 1 1 6 4 2 7 5 8 2 ", Ġ" Incoming ĠSMS Ġmessage Ġ 5 ", Ġ" User 5 ", Ġ" 1 5 3 5 5 2 7 9 0 2 0 3 6 "," 3 "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠMessage (" 1 . 1 2 . 2 0 1 8 .", Ġ"+ 3 8 5 9 1 1 2 3 4 3 2 4 5 ", Ġ" Incoming ĠSMS Ġmessage Ġ 6 ", Ġ" User 6 ", Ġ" 1 5 3 5 5 2 7 9 0 2 0 3 7 "," 5 ")) ĊĊĠĠĠĠĠĠĠ Ġval Ġsingle Message Ġ= ĠMessage (" 1 1 . 6 . 2 0 1 8 .", Ġ"+ 3 8 5 9 3 8 6 4 2 7 5 8 2 ", Ġ" Incoming ĠSMS Ġmessage Ġ 7 ", Ġ" J ake ĠWh art on ", Ġ" 1 5 3 5 5 2 7 9 0 2 0 3 8 "," 6 ") ĊĊĊĠĠĠĠĠĠĠ Ġcall ceptor DAO . save Incoming Messages ( ArrayList ( messages )) ĊĠĠĠĠĠĠĠ Ġcall ceptor DAO . save Incoming Message ( single Message ) ĊĠĠĠĠĠĠĠ Ġcall ceptor DAO . save Incoming Messages ( ArrayList ( messages 2 )) ĊĊĠĠĠĠĠĠĠ Ġval Ġget Results Ġ= Ġcall ceptor DAO . get Messages ( 0 , ĠPAGE _ ENTR IES ) ĊĊĠĠĠĠĠĠĠ Ġval Ġexpected Result Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠMessage (" 1 1 . 6 . 2 0 1 8 .", Ġ"+ 3 8 5 9 3 8 6 4 2 7 5 8 2 ", Ġ" Incoming ĠSMS Ġmessage Ġ 7 ", Ġ" J ake ĠWh art on ", Ġ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8 ", Ġ" Incoming ĠSMS Ġmessage Ġ 1 ", Ġ" User ", Ġ" 1 5 3 5 5 2 7 9 0 2 0 3 2 "," 1 ")) ĊĊĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( get Results [ 0 ]. timestamp , Ġexpected Result [ 0 ]. timestamp ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( get Results [ 6 ]. timestamp , Ġexpected Result [ 6 ]. timestamp ) ĊĊĠĠĠĠĠĠĠ Ġval Ġget Deleted Rows Ġ= Ġcall ceptor DAO . delete Messages () ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( 7 , Ġget Deleted Rows ) ĊĠĠĠ Ġ} Ċ Ċ }