package Ġwatch . craft . storage Ċ Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġorg . junit . jupiter . api . Assertions . assertArrayEquals Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . assert Throws Ċ import Ġorg . junit . jupiter . api . io . TempDir Ċ import Ġjava . nio . file . Path Ċ Ċ class ĠLocal Object Store Test Ġ{ ĊĠ Ġ@ Test ĊĠ Ġfun Ġ` writes Ġdata Ġto Ġfilesystem Ġif Ġnot Ġalready Ġpresent ` (@ TempDir Ġtemp Dir : ĠPath ) Ġ{ ĊĠĠĠ Ġval Ġstore Ġ= ĠLocal Object Store ( temp Dir . to File ()) ĊĊĠĠĠ Ġrun Blocking Ġ{ Ġstore . write ( N ICE _ KEY , ĠN ICE _ DATA ) Ġ} ĊĊĠĠĠ Ġassert ArrayEquals ( N ICE _ DATA , Ġtemp Dir . resolve ( N ICE _ KEY ). to File (). read Bytes ()) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` throws Ġand Ġdoesn 't Ġoverwrite Ġif Ġfile Ġalready Ġpresent ` (@ TempDir Ġtemp Dir : ĠPath ) Ġ{ ĊĠĠĠ Ġtemp Dir . resolve ( N ICE _ KEY ). to File (). write Bytes ( N ICE _ DATA ) ĊĠĠĠ Ġval Ġstore Ġ= ĠLocal Object Store ( temp Dir . to File ()) ĊĊĠĠĠ ĠassertThrows < File Exists Exception > Ġ{ ĊĠĠĠĠĠ Ġrun Blocking Ġ{ Ġstore . write ( N ICE _ KEY , ĠOTHER _ DATA ) Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġassert ArrayEquals ( N ICE _ DATA , Ġtemp Dir . resolve ( N ICE _ KEY ). to File (). read Bytes ()) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` reads Ġdata Ġfrom Ġfilesystem Ġif Ġpresent ` (@ TempDir Ġtemp Dir : ĠPath ) Ġ{ ĊĠĠĠ Ġtemp Dir . resolve ( N ICE _ KEY ). to File (). write Bytes ( N ICE _ DATA ) ĊĠĠĠ Ġval Ġstore Ġ= ĠLocal Object Store ( temp Dir . to File ()) ĊĊĠĠĠ Ġassert ArrayEquals ( N ICE _ DATA , Ġrun Blocking Ġ{ Ġstore . read ( N ICE _ KEY ) Ġ}) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` throws Ġif Ġfile Ġnot Ġpresent ` (@ TempDir Ġtemp Dir : ĠPath ) Ġ{ ĊĠĠĠ Ġval Ġstore Ġ= ĠLocal Object Store ( temp Dir . to File ()) ĊĊĠĠĠ ĠassertThrows < File Does nt Exist Exception > Ġ{ ĊĠĠĠĠĠ Ġrun Blocking Ġ{ Ġstore . read ( N ICE _ KEY ) Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġprivate Ġconst Ġval ĠN ICE _ KEY Ġ= Ġ" foo " ĊĠĠĠ Ġprivate Ġval ĠN ICE _ DATA Ġ= Ġbyte ArrayOf ( 1 , Ġ 2 , Ġ 3 , Ġ 4 ) ĊĠĠĠ Ġprivate Ġval ĠOTHER _ DATA Ġ= Ġbyte ArrayOf ( 5 , Ġ 6 , Ġ 7 , Ġ 8 ) ĊĠ Ġ} Ċ } Ċ