package org.spout.downpour;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.ByteBuffer;

import org.junit.Assert;
import org.junit.Test;

public class TestDownpourCache {
	public static final String TEST_URL = "http://get.spout.org/about.yml";
	
	@Test
	public void testCache() throws MalformedURLException, NoCacheException, IOException {
		DownpourCache cache = new DownpourCache(new File("cachedb"));
		InputStream in = cache.get(new URL(TEST_URL));
		ByteBuffer onlineTest = readFrom(in);
		cache.setOfflineMode(true);
		in = cache.get(new URL(TEST_URL));
		ByteBuffer offlineTest = readFrom(in);
		
		Assert.assertEquals("The offline copy doesn't match the online copy", onlineTest, offlineTest);
	}
	
	public ByteBuffer readFrom(InputStream in) throws IOException {
		ByteBuffer buffer = ByteBuffer.allocate(1024);
		int data;
		while ((data = in.read()) != -1) {
			if (!buffer.hasRemaining()) {
				ByteBuffer replace = ByteBuffer.allocate(buffer.capacity() + 1024);
				replace.put(buffer.array());
				buffer = replace;
			}
			buffer.put((byte) data);
		}
		in.close();
		return buffer;
	}
}

@@ -439,16 +439,149 @@
 ption %7B%0A
+%09%09File cacheDb = new File(%22cachedb%22);%0A%09%09if (cacheDb.exists()) %7B%0A%09%09%09for (File file:cacheDb.listFiles()) %7B%0A%09%09%09%09file.delete();%0A%09%09%09%7D%0A%09%09%7D%0A
 %09%09Downpo
@@ -614,35 +614,23 @@
 urCache(
-new File(%22
 cache
-db%22)
+Db
 );%0A%09%09Inp
@@ -662,32 +662,71 @@
 ew URL(TEST_URL)
+, DownpourCache.DEFAULT_CONNECTOR, true
 );%0A%09%09ByteBuffer 

Fix test