### Question:
SerializableTile { public byte[] getTileData() { return (tData == null)? new byte[0] : tData; } SerializableTile(File sTileFile);  SerializableTile(byte[] tileBytes, String etag); static String bytesToHex(byte[] bytes); byte[] getTileData(); void setTileData(byte[] tileData); void clearHeaders(); Map<String, String> getHeaders(); void setHeaders(Map<String, String> h); boolean saveFile(File aFile); boolean saveFile(); boolean fromFile(File file); long getCacheControl(); String getHeader(String k); void setHeader(String k, String v); String getEtag(); static final long CACHE_TILE_MS; }### Answer:
@Test public void testLoadTileMissingFile() throws IOException { File temp = File.createTempFile("temp", ".txt"); String path = temp.getAbsolutePath(); temp.delete(); SerializableTile newTile = new SerializableTile(new File(path)); assertEquals(0, newTile.getTileData().length); }
@Test public void testLoadTileValidHeaderNoData() throws IOException { File temp = File.createTempFile("temp", ".txt"); FileOutputStream fos = new FileOutputStream(temp); byte[] tileData = {(byte) 0xde, (byte) 0xca, (byte) 0xfb, (byte) 0xad}; fos.write(tileData); fos.flush(); fos.close(); assertTrue(temp.exists()); SerializableTile newTile = new SerializableTile(temp); assertEquals(0, newTile.getTileData().length); assertFalse(temp.exists()); }
@Test public void testLoadTileInvalidPayload() throws IOException { File temp = File.createTempFile("temp", ".txt"); FileOutputStream fos = new FileOutputStream(temp); byte[] tileData = {(byte) 0xde, (byte) 0xca, (byte) 0xfb, (byte) 0xad, (byte) 0xaf, (byte) 0xad, (byte) 0xaf, (byte) 0xad, (byte) 0xaf, (byte) 0xad, (byte) 0xaf, (byte) 0xad, (byte) 0xaf, (byte) 0xad }; fos.write(tileData); fos.flush(); fos.close(); assertTrue(temp.exists()); SerializableTile newTile = new SerializableTile(temp); assertEquals(0, newTile.getTileData().length); assertFalse(temp.exists()); }