// Ġ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 Ġcom . android . tools . datastore . database Ċ Ċ import Ġcom . android . tools . datastore . DataStore Database Ċ import Ġcom . android . tools . datastore . Fake Log Service Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġorg . junit . Test Ċ import Ġjava . io . Buffered OutputStream Ċ import Ġjava . io . File Ċ import Ġjava . io . File OutputStream Ċ Ċ class ĠData Store Database Test Ġ{ ĊĊĠ Ġprivate Ġval Ġmy Database File Ġ= ĠFile . create TempFile (" f aked b file ", Ġ" sql ") ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Database Creates DB File () Ġ{ ĊĠĠĠ Ġmy Database File . delete () ĊĠĠĠ Ġval Ġdb Ġ= ĠData Store Database ( my Database File . absolute Path , ĠData Store Database . Characteristic . D UR ABLE , ĠFake Log Service ()) ĊĠĠĠ Ġdb . disconnect () ĊĠĠĠ ĠassertThat ( my Database File . exists ()). isTrue () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Database Deletes Ex is iting File OnLoad () Ġ{ ĊĠĠĠ Ġval ĠoutputStream Ġ= ĠBuffered OutputStream ( File OutputStream ( my Database File )) ĊĠĠĠ ĠoutputStream . write ( ByteArray ( 1 0 2 4 )) ĊĠĠĠ ĠoutputStream . close () ĊĠĠĠ ĠassertThat ( my Database File . length ()). isEqualTo ( 1 0 2 4 ) ĊĠĠĠ Ġval Ġdb Ġ= ĠData Store Database ( my Database File . absolute Path , ĠData Store Database . Characteristic . D UR ABLE , ĠFake Log Service ()) ĊĠĠĠ ĠassertThat ( my Database File . length ()). isEqualTo ( 0 ) ĊĠĠĠ Ġdb . disconnect () ĊĠĠĠ ĠassertThat ( my Database File . exists ()). isTrue () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Connection Is Open () Ġ{ ĊĠĠĠ Ġ// ĠVerify Ġpersistent Ġdatabase ĊĠĠĠ Ġvar Ġdb Ġ= ĠData Store Database ( my Database File . absolute Path , ĠData Store Database . Characteristic . D UR ABLE , ĠFake Log Service ()) ĊĠĠĠ ĠassertThat ( db . connection . is Closed ). isFalse () ĊĠĠĠ ĠassertThat ( db . connection . auto Commit ). isFalse () ĊĠĠĠ ĠassertThat ( db . connection . metaData . url ). matches (" jdbc : sqlite :${ my Database File . absolute Path }") ĊĠĠĠ Ġdb . disconnect () ĊĠĠĠ ĠassertThat ( db . connection . is Closed ). isTrue () ĊĊĠĠĠ Ġ// ĠVerify Ġmemory Ġdatabase . ĊĠĠĠ Ġdb Ġ= ĠData Store Database ( my Database File . absolute Path , ĠData Store Database . Characteristic . PER FORM ANT , ĠFake Log Service ()) ĊĠĠĠ ĠassertThat ( db . connection . is Closed ). isFalse () ĊĠĠĠ ĠassertThat ( db . connection . auto Commit ). isFalse () ĊĠĠĠ ĠassertThat ( db . connection . metaData . url ). matches (" jdbc : sqlite :: memory :") ĊĠĠĠ Ġdb . disconnect () ĊĠĠĠ ĠassertThat ( db . connection . is Closed ). isTrue () ĊĠ Ġ} Ċ } Ċ