// Path: test/src/test/java/com/danikula/videocache/BaseTest.java
// @RunWith(RobolectricTestRunner.class)
// @Config(constants = BuildConfig.class)
// public abstract class BaseTest {
// 
//     static {
//         System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "trace");
//     }
// 
// }
// 
// Path: library/src/main/java/com/danikula/videocache/Cache.java
// public interface Cache {
// 
//     long available() throws ProxyCacheException;
// 
//     int read(byte[] buffer, long offset, int length) throws ProxyCacheException;
// 
//     void append(byte[] data, int length) throws ProxyCacheException;
// 
//     void close() throws ProxyCacheException;
// 
//     void complete() throws ProxyCacheException;
// 
//     boolean isCompleted();
// }
// 
// Path: library/src/main/java/com/danikula/videocache/ProxyCacheException.java
// public class ProxyCacheException extends Exception {
// 
//     private static final String LIBRARY_VERSION = ". Version: " + BuildConfig.VERSION_NAME;
// 
//     public ProxyCacheException(String message) {
//         super(message + LIBRARY_VERSION);
//     }
// 
//     public ProxyCacheException(String message, Throwable cause) {
//         super(message + LIBRARY_VERSION, cause);
//     }
// 
//     public ProxyCacheException(Throwable cause) {
//         super("No explanation error" + LIBRARY_VERSION, cause);
//     }
// }
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static final String ASSETS_DATA_NAME = "android.jpg";
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static byte[] generate(int capacity) {
//     Random random = new Random(System.currentTimeMillis());
//     byte[] result = new byte[capacity];
//     random.nextBytes(result);
//     return result;
// }
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static byte[] getFileContent(File file) throws IOException {
//     return Files.asByteSource(file).read();
// }
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static File getTempFile(File file) {
//     return new File(file.getParentFile(), file.getName() + ".download");
// }
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static byte[] loadAssetFile(String name) throws IOException {
//     InputStream in = RuntimeEnvironment.application.getResources().getAssets().open(name);
//     ByteArrayOutputStream out = new ByteArrayOutputStream();
//     IoUtils.copy(in, out);
//     IoUtils.closeSilently(in);
//     IoUtils.closeSilently(out);
//     return out.toByteArray();
// }
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static File newCacheFile() {
//     return new File(RuntimeEnvironment.application.getCacheDir(), UUID.randomUUID().toString());
// }


import com.danikula.android.garden.io.Files;
import com.danikula.videocache.BaseTest;
import com.danikula.videocache.Cache;
import com.danikula.videocache.ProxyCacheException;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import static com.danikula.videocache.support.ProxyCacheTestUtils.ASSETS_DATA_NAME;
import static com.danikula.videocache.support.ProxyCacheTestUtils.generate;
import static com.danikula.videocache.support.ProxyCacheTestUtils.getFileContent;
import static com.danikula.videocache.support.ProxyCacheTestUtils.getTempFile;
import static com.danikula.videocache.support.ProxyCacheTestUtils.loadAssetFile;
import static com.danikula.videocache.support.ProxyCacheTestUtils.newCacheFile;
import static com.google.common.io.Files.write;
import static org.fest.assertions.api.Assertions.assertThat;
        fileCache.complete();
        fileCache.append(generate(20), 10);
        Assert.fail();
    }

    @Test
    public void testAppendDiscCache() throws Exception {
        File file = newCacheFile();
        Cache fileCache = new FileCache(file);

        int firstPortionLength = 10000;
        byte[] firstDataPortion = generate(firstPortionLength);
        fileCache.append(firstDataPortion, firstDataPortion.length);

        int secondPortionLength = 30000;
        byte[] secondDataPortion = generate(secondPortionLength * 2);
        fileCache.append(secondDataPortion, secondPortionLength);

        byte[] wroteSecondPortion = Arrays.copyOfRange(secondDataPortion, 0, secondPortionLength);
        byte[] readData = new byte[secondPortionLength];
        fileCache.read(readData, firstPortionLength, secondPortionLength);
        assertThat(readData).isEqualTo(wroteSecondPortion);

        readData = new byte[(int)fileCache.available()];
        fileCache.read(readData, 0, readData.length);
        byte[] fileContent = getFileContent(getTempFile(file));
        assertThat(readData).isEqualTo(fileContent);
    }

    @Test
// Path: test/src/test/java/com/danikula/videocache/BaseTest.java
// @RunWith(RobolectricTestRunner.class)
// @Config(constants = BuildConfig.class)
// public abstract class BaseTest {
// 
//     static {
//         System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "trace");
//     }
// 
// }
// 
// Path: library/src/main/java/com/danikula/videocache/Cache.java
// public interface Cache {
// 
//     long available() throws ProxyCacheException;
// 
//     int read(byte[] buffer, long offset, int length) throws ProxyCacheException;
// 
//     void append(byte[] data, int length) throws ProxyCacheException;
// 
//     void close() throws ProxyCacheException;
// 
//     void complete() throws ProxyCacheException;
// 
//     boolean isCompleted();
// }
// 
// Path: library/src/main/java/com/danikula/videocache/ProxyCacheException.java
// public class ProxyCacheException extends Exception {
// 
//     private static final String LIBRARY_VERSION = ". Version: " + BuildConfig.VERSION_NAME;
// 
//     public ProxyCacheException(String message) {
//         super(message + LIBRARY_VERSION);
//     }
// 
//     public ProxyCacheException(String message, Throwable cause) {
//         super(message + LIBRARY_VERSION, cause);
//     }
// 
//     public ProxyCacheException(Throwable cause) {
//         super("No explanation error" + LIBRARY_VERSION, cause);
//     }
// }
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static final String ASSETS_DATA_NAME = "android.jpg";
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static byte[] generate(int capacity) {
//     Random random = new Random(System.currentTimeMillis());
//     byte[] result = new byte[capacity];
//     random.nextBytes(result);
//     return result;
// }
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static byte[] getFileContent(File file) throws IOException {
//     return Files.asByteSource(file).read();
// }
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static File getTempFile(File file) {
//     return new File(file.getParentFile(), file.getName() + ".download");
// }
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static byte[] loadAssetFile(String name) throws IOException {
//     InputStream in = RuntimeEnvironment.application.getResources().getAssets().open(name);
//     ByteArrayOutputStream out = new ByteArrayOutputStream();
//     IoUtils.copy(in, out);
//     IoUtils.closeSilently(in);
//     IoUtils.closeSilently(out);
//     return out.toByteArray();
// }
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static File newCacheFile() {
//     return new File(RuntimeEnvironment.application.getCacheDir(), UUID.randomUUID().toString());
// }


// Path: test/src/test/java/com/danikula/videocache/file/FileCacheTest.java
import com.danikula.android.garden.io.Files;
import com.danikula.videocache.BaseTest;
import com.danikula.videocache.Cache;
import com.danikula.videocache.ProxyCacheException;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import static com.danikula.videocache.support.ProxyCacheTestUtils.ASSETS_DATA_NAME;
import static com.danikula.videocache.support.ProxyCacheTestUtils.generate;
import static com.danikula.videocache.support.ProxyCacheTestUtils.getFileContent;
import static com.danikula.videocache.support.ProxyCacheTestUtils.getTempFile;
import static com.danikula.videocache.support.ProxyCacheTestUtils.loadAssetFile;
import static com.danikula.videocache.support.ProxyCacheTestUtils.newCacheFile;
import static com.google.common.io.Files.write;
import static org.fest.assertions.api.Assertions.assertThat;

        fileCache.complete();
        fileCache.append(generate(20), 10);
        Assert.fail();
    }

    @Test
    public void testAppendDiscCache() throws Exception {
        File file = newCacheFile();
        Cache fileCache = new FileCache(file);

        int firstPortionLength = 10000;
        byte[] firstDataPortion = generate(firstPortionLength);
        fileCache.append(firstDataPortion, firstDataPortion.length);

        int secondPortionLength = 30000;
        byte[] secondDataPortion = generate(secondPortionLength * 2);
        fileCache.append(secondDataPortion, secondPortionLength);

        byte[] wroteSecondPortion = Arrays.copyOfRange(secondDataPortion, 0, secondPortionLength);
        byte[] readData = new byte[secondPortionLength];
        fileCache.read(readData, firstPortionLength, secondPortionLength);
        assertThat(readData).isEqualTo(wroteSecondPortion);

        readData = new byte[(int)fileCache.available()];
        fileCache.read(readData, 0, readData.length);
        byte[] fileContent = getFileContent(getTempFile(file));
        assertThat(readData).isEqualTo(fileContent);
    }

    @Test
    public void testIsFileCacheCompleted() throws Exception {