mirror of
https://github.com/zhigang1992/AndroidVideoCache.git
synced 2026-03-06 22:32:57 +08:00
📦 2.6.2: use slf4j for logging
This commit is contained in:
@@ -36,7 +36,7 @@ repositories {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
compile 'com.danikula:videocache:2.6.1'
|
||||
compile 'com.danikula:videocache:2.6.2'
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -23,13 +23,14 @@ sourceCompatibility = '1.7'
|
||||
|
||||
dependencies {
|
||||
compile 'com.google.android:android:1.6_r2'
|
||||
compile 'org.slf4j:slf4j-android:1.7.21'
|
||||
}
|
||||
|
||||
publish {
|
||||
userOrg = 'alexeydanilov'
|
||||
groupId = 'com.danikula'
|
||||
artifactId = 'videocache'
|
||||
publishVersion = '2.6.1'
|
||||
publishVersion = '2.6.2'
|
||||
description = 'Cache support for android VideoView'
|
||||
website = 'https://github.com/danikula/AndroidVideoCache'
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.danikula.videocache;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
|
||||
import com.danikula.videocache.file.DiskUsage;
|
||||
import com.danikula.videocache.file.FileNameGenerator;
|
||||
@@ -12,6 +11,9 @@ import com.danikula.videocache.file.TotalSizeLruDiskUsage;
|
||||
import com.danikula.videocache.sourcestorage.SourceInfoStorage;
|
||||
import com.danikula.videocache.sourcestorage.SourceInfoStorageFactory;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@@ -33,7 +35,6 @@ import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static com.danikula.videocache.Preconditions.checkAllNotNull;
|
||||
import static com.danikula.videocache.Preconditions.checkNotNull;
|
||||
import static com.danikula.videocache.ProxyCacheUtils.LOG_TAG;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
|
||||
/**
|
||||
@@ -57,6 +58,8 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
*/
|
||||
public class HttpProxyCacheServer {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger("HttpProxyCacheServer");
|
||||
|
||||
private static final String PROXY_HOST = "127.0.0.1";
|
||||
private static final String PING_REQUEST = "ping";
|
||||
private static final String PING_RESPONSE = "ping ok";
|
||||
@@ -84,7 +87,7 @@ public class HttpProxyCacheServer {
|
||||
this.waitConnectionThread = new Thread(new WaitRequestsRunnable(startSignal));
|
||||
this.waitConnectionThread.start();
|
||||
startSignal.await(); // freeze thread, wait for server starts
|
||||
Log.i(LOG_TAG, "Proxy cache server started. Ping it...");
|
||||
LOG.info("Proxy cache server started. Ping it...");
|
||||
makeSureServerWorks();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
socketProcessor.shutdown();
|
||||
@@ -105,12 +108,12 @@ public class HttpProxyCacheServer {
|
||||
}
|
||||
SystemClock.sleep(delay);
|
||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||
Log.e(LOG_TAG, "Error pinging server [attempt: " + pingAttempts + ", timeout: " + delay + "]. ", e);
|
||||
LOG.error("Error pinging server [attempt: " + pingAttempts + ", timeout: " + delay + "]. ", e);
|
||||
}
|
||||
pingAttempts++;
|
||||
delay *= 2;
|
||||
}
|
||||
Log.e(LOG_TAG, "Shutdown server… Error pinging server [attempts: " + pingAttempts + ", max timeout: " + delay / 2 + "]. " +
|
||||
LOG.error("Shutdown server… Error pinging server [attempts: " + pingAttempts + ", max timeout: " + delay / 2 + "]. " +
|
||||
"If you see this message, please, email me danikula@gmail.com");
|
||||
shutdown();
|
||||
}
|
||||
@@ -124,10 +127,10 @@ public class HttpProxyCacheServer {
|
||||
byte[] response = new byte[expectedResponse.length];
|
||||
source.read(response);
|
||||
boolean pingOk = Arrays.equals(expectedResponse, response);
|
||||
Log.d(LOG_TAG, "Ping response: `" + new String(response) + "`, pinged? " + pingOk);
|
||||
LOG.info("Ping response: `" + new String(response) + "`, pinged? " + pingOk);
|
||||
return pingOk;
|
||||
} catch (ProxyCacheException e) {
|
||||
Log.e(LOG_TAG, "Error reading ping response", e);
|
||||
LOG.error("Error reading ping response", e);
|
||||
return false;
|
||||
} finally {
|
||||
source.close();
|
||||
@@ -136,7 +139,7 @@ public class HttpProxyCacheServer {
|
||||
|
||||
public String getProxyUrl(String url) {
|
||||
if (!pinged) {
|
||||
Log.e(LOG_TAG, "Proxy server isn't pinged. Caching doesn't work. If you see this message, please, email me danikula@gmail.com");
|
||||
LOG.error("Proxy server isn't pinged. Caching doesn't work. If you see this message, please, email me danikula@gmail.com");
|
||||
}
|
||||
return pinged ? appendToProxyUrl(url) : url;
|
||||
}
|
||||
@@ -151,7 +154,7 @@ public class HttpProxyCacheServer {
|
||||
try {
|
||||
getClients(url).registerCacheListener(cacheListener);
|
||||
} catch (ProxyCacheException e) {
|
||||
Log.d(LOG_TAG, "Error registering cache listener", e);
|
||||
LOG.warn("Error registering cache listener", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,7 +165,7 @@ public class HttpProxyCacheServer {
|
||||
try {
|
||||
getClients(url).unregisterCacheListener(cacheListener);
|
||||
} catch (ProxyCacheException e) {
|
||||
Log.d(LOG_TAG, "Error registering cache listener", e);
|
||||
LOG.warn("Error registering cache listener", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,7 +194,7 @@ public class HttpProxyCacheServer {
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
Log.i(LOG_TAG, "Shutdown proxy server");
|
||||
LOG.info("Shutdown proxy server");
|
||||
|
||||
shutdownClients();
|
||||
|
||||
@@ -220,7 +223,7 @@ public class HttpProxyCacheServer {
|
||||
try {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
Socket socket = serverSocket.accept();
|
||||
Log.d(LOG_TAG, "Accept new socket " + socket);
|
||||
LOG.debug("Accept new socket " + socket);
|
||||
socketProcessor.submit(new SocketProcessorRunnable(socket));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@@ -231,7 +234,7 @@ public class HttpProxyCacheServer {
|
||||
private void processSocket(Socket socket) {
|
||||
try {
|
||||
GetRequest request = GetRequest.read(socket.getInputStream());
|
||||
Log.i(LOG_TAG, "Request to cache proxy:" + request);
|
||||
LOG.debug("Request to cache proxy:" + request);
|
||||
String url = ProxyCacheUtils.decode(request.uri);
|
||||
if (PING_REQUEST.equals(url)) {
|
||||
responseToPing(socket);
|
||||
@@ -242,12 +245,12 @@ public class HttpProxyCacheServer {
|
||||
} catch (SocketException e) {
|
||||
// There is no way to determine that client closed connection http://stackoverflow.com/a/10241044/999458
|
||||
// So just to prevent log flooding don't log stacktrace
|
||||
Log.d(LOG_TAG, "Closing socket… Socket is closed by client.");
|
||||
LOG.debug("Closing socket… Socket is closed by client.");
|
||||
} catch (ProxyCacheException | IOException e) {
|
||||
onError(new ProxyCacheException("Error processing request", e));
|
||||
} finally {
|
||||
releaseSocket(socket);
|
||||
Log.d(LOG_TAG, "Opened connections: " + getClientsCount());
|
||||
LOG.debug("Opened connections: " + getClientsCount());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,7 +295,7 @@ public class HttpProxyCacheServer {
|
||||
} catch (SocketException e) {
|
||||
// There is no way to determine that client closed connection http://stackoverflow.com/a/10241044/999458
|
||||
// So just to prevent log flooding don't log stacktrace
|
||||
Log.d(LOG_TAG, "Releasing input stream… Socket is closed by client.");
|
||||
LOG.debug("Releasing input stream… Socket is closed by client.");
|
||||
} catch (IOException e) {
|
||||
onError(new ProxyCacheException("Error closing socket input stream", e));
|
||||
}
|
||||
@@ -319,7 +322,7 @@ public class HttpProxyCacheServer {
|
||||
}
|
||||
|
||||
private void onError(Throwable e) {
|
||||
Log.e(LOG_TAG, "HttpProxyCacheServer error", e);
|
||||
LOG.error("HttpProxyCacheServer error", e);
|
||||
}
|
||||
|
||||
private final class WaitRequestsRunnable implements Runnable {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.danikula.videocache;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.danikula.videocache.sourcestorage.SourceInfoStorage;
|
||||
import com.danikula.videocache.sourcestorage.SourceInfoStorageFactory;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -15,7 +17,6 @@ import java.net.URL;
|
||||
|
||||
import static com.danikula.videocache.Preconditions.checkNotNull;
|
||||
import static com.danikula.videocache.ProxyCacheUtils.DEFAULT_BUFFER_SIZE;
|
||||
import static com.danikula.videocache.ProxyCacheUtils.LOG_TAG;
|
||||
import static java.net.HttpURLConnection.HTTP_MOVED_PERM;
|
||||
import static java.net.HttpURLConnection.HTTP_MOVED_TEMP;
|
||||
import static java.net.HttpURLConnection.HTTP_OK;
|
||||
@@ -29,6 +30,8 @@ import static java.net.HttpURLConnection.HTTP_SEE_OTHER;
|
||||
*/
|
||||
public class HttpUrlSource implements Source {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger("HttpUrlSource");
|
||||
|
||||
private static final int MAX_REDIRECTS = 5;
|
||||
private final SourceInfoStorage sourceInfoStorage;
|
||||
private SourceInfo sourceInfo;
|
||||
@@ -108,7 +111,7 @@ public class HttpUrlSource implements Source {
|
||||
}
|
||||
|
||||
private void fetchContentInfo() throws ProxyCacheException {
|
||||
Log.d(LOG_TAG, "Read content info from " + sourceInfo.url);
|
||||
LOG.debug("Read content info from " + sourceInfo.url);
|
||||
HttpURLConnection urlConnection = null;
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
@@ -118,9 +121,9 @@ public class HttpUrlSource implements Source {
|
||||
inputStream = urlConnection.getInputStream();
|
||||
this.sourceInfo = new SourceInfo(sourceInfo.url, length, mime);
|
||||
this.sourceInfoStorage.put(sourceInfo.url, sourceInfo);
|
||||
Log.i(LOG_TAG, "Source info fetched: " + sourceInfo);
|
||||
LOG.debug("Source info fetched: " + sourceInfo);
|
||||
} catch (IOException e) {
|
||||
Log.e(LOG_TAG, "Error fetching info from " + sourceInfo.url, e);
|
||||
LOG.error("Error fetching info from " + sourceInfo.url, e);
|
||||
} finally {
|
||||
ProxyCacheUtils.close(inputStream);
|
||||
if (urlConnection != null) {
|
||||
@@ -135,7 +138,7 @@ public class HttpUrlSource implements Source {
|
||||
int redirectCount = 0;
|
||||
String url = this.sourceInfo.url;
|
||||
do {
|
||||
Log.d(LOG_TAG, "Open connection " + (offset > 0 ? " with offset " + offset : "") + " to " + url);
|
||||
LOG.debug("Open connection " + (offset > 0 ? " with offset " + offset : "") + " to " + url);
|
||||
connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
if (offset > 0) {
|
||||
connection.setRequestProperty("Range", "bytes=" + offset + "-");
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.danikula.videocache;
|
||||
|
||||
import android.util.Log;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static com.danikula.videocache.Preconditions.checkNotNull;
|
||||
import static com.danikula.videocache.ProxyCacheUtils.LOG_TAG;
|
||||
|
||||
/**
|
||||
* Proxy for {@link Source} with caching support ({@link Cache}).
|
||||
@@ -18,6 +18,7 @@ import static com.danikula.videocache.ProxyCacheUtils.LOG_TAG;
|
||||
*/
|
||||
class ProxyCache {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger("ProxyCache");
|
||||
private static final int MAX_READ_SOURCE_ATTEMPTS = 1;
|
||||
|
||||
private final Source source;
|
||||
@@ -61,7 +62,7 @@ class ProxyCache {
|
||||
|
||||
public void shutdown() {
|
||||
synchronized (stopLock) {
|
||||
Log.d(LOG_TAG, "Shutdown proxy for " + source);
|
||||
LOG.debug("Shutdown proxy for " + source);
|
||||
try {
|
||||
stopped = true;
|
||||
if (sourceReaderThread != null) {
|
||||
@@ -173,9 +174,9 @@ class ProxyCache {
|
||||
protected final void onError(final Throwable e) {
|
||||
boolean interruption = e instanceof InterruptedProxyCacheException;
|
||||
if (interruption) {
|
||||
Log.d(LOG_TAG, "ProxyCache is interrupted");
|
||||
LOG.debug("ProxyCache is interrupted");
|
||||
} else {
|
||||
Log.e(LOG_TAG, "ProxyCache error", e);
|
||||
LOG.error("ProxyCache error", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.danikula.videocache;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@@ -23,7 +25,7 @@ import static com.danikula.videocache.Preconditions.checkNotNull;
|
||||
*/
|
||||
public class ProxyCacheUtils {
|
||||
|
||||
static final String LOG_TAG = "ProxyCache";
|
||||
private static final Logger LOG = LoggerFactory.getLogger("ProxyCacheUtils");
|
||||
static final int DEFAULT_BUFFER_SIZE = 8 * 1024;
|
||||
static final int MAX_ARRAY_PREVIEW = 16;
|
||||
|
||||
@@ -70,7 +72,7 @@ public class ProxyCacheUtils {
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(LOG_TAG, "Error closing resource", e);
|
||||
LOG.error("Error closing resource", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@ package com.danikula.videocache;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static android.os.Environment.MEDIA_MOUNTED;
|
||||
import static com.danikula.videocache.ProxyCacheUtils.LOG_TAG;
|
||||
|
||||
/**
|
||||
* Provides application storage paths
|
||||
@@ -19,6 +20,7 @@ import static com.danikula.videocache.ProxyCacheUtils.LOG_TAG;
|
||||
*/
|
||||
final class StorageUtils {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger("StorageUtils");
|
||||
private static final String INDIVIDUAL_DIR_NAME = "video-cache";
|
||||
|
||||
/**
|
||||
@@ -61,7 +63,7 @@ final class StorageUtils {
|
||||
}
|
||||
if (appCacheDir == null) {
|
||||
String cacheDirPath = "/data/data/" + context.getPackageName() + "/cache/";
|
||||
Log.w(LOG_TAG, "Can't define system cache directory! '" + cacheDirPath + "%s' will be used.");
|
||||
LOG.warn("Can't define system cache directory! '" + cacheDirPath + "%s' will be used.");
|
||||
appCacheDir = new File(cacheDirPath);
|
||||
}
|
||||
return appCacheDir;
|
||||
@@ -72,7 +74,7 @@ final class StorageUtils {
|
||||
File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache");
|
||||
if (!appCacheDir.exists()) {
|
||||
if (!appCacheDir.mkdirs()) {
|
||||
Log.w(LOG_TAG, "Unable to create external cache directory");
|
||||
LOG.warn("Unable to create external cache directory");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.danikula.videocache.file;
|
||||
|
||||
import android.util.Log;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -16,7 +17,7 @@ import java.util.concurrent.Executors;
|
||||
*/
|
||||
abstract class LruDiskUsage implements DiskUsage {
|
||||
|
||||
private static final String LOG_TAG = "ProxyCache";
|
||||
private static final Logger LOG = LoggerFactory.getLogger("LruDiskUsage");
|
||||
private final ExecutorService workerThread = Executors.newSingleThreadExecutor();
|
||||
|
||||
@Override
|
||||
@@ -43,9 +44,9 @@ abstract class LruDiskUsage implements DiskUsage {
|
||||
if (deleted) {
|
||||
totalCount--;
|
||||
totalSize -= fileSize;
|
||||
Log.i(LOG_TAG, "Cache file " + file + " is deleted because it exceeds cache limit");
|
||||
LOG.info("Cache file " + file + " is deleted because it exceeds cache limit");
|
||||
} else {
|
||||
Log.e(LOG_TAG, "Error deleting file " + file + " for trimming cache");
|
||||
LOG.error("Error deleting file " + file + " for trimming cache");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ dependencies {
|
||||
// compile project(':library')
|
||||
compile 'com.android.support:support-v4:23.1.0'
|
||||
compile 'org.androidannotations:androidannotations-api:3.3.2'
|
||||
compile 'com.danikula:videocache:2.6.1'
|
||||
compile 'com.danikula:videocache:2.6.2'
|
||||
compile 'com.viewpagerindicator:library:2.4.2-SNAPSHOT@aar'
|
||||
apt 'org.androidannotations:androidannotations:3.3.2'
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ android {
|
||||
|
||||
dependencies {
|
||||
compile project(':library')
|
||||
|
||||
testCompile 'org.slf4j:slf4j-simple:1.7.21'
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile 'org.robolectric:robolectric:3.1'
|
||||
testCompile 'com.squareup:fest-android:1.0.0'
|
||||
|
||||
17
test/src/test/java/com/danikula/videocache/BaseTest.java
Normal file
17
test/src/test/java/com/danikula/videocache/BaseTest.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.danikula.videocache;
|
||||
|
||||
import com.danikula.videocache.test.BuildConfig;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricGradleTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricGradleTestRunner.class)
|
||||
@Config(constants = BuildConfig.class)
|
||||
public abstract class BaseTest {
|
||||
|
||||
static {
|
||||
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "trace");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,12 +2,8 @@ package com.danikula.videocache;
|
||||
|
||||
import com.danikula.videocache.file.FileNameGenerator;
|
||||
import com.danikula.videocache.file.Md5FileNameGenerator;
|
||||
import com.danikula.videocache.test.BuildConfig;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricGradleTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -19,9 +15,7 @@ import static org.fest.assertions.api.Assertions.fail;
|
||||
*
|
||||
* @author Alexey Danilov (danikula@gmail.com).
|
||||
*/
|
||||
@RunWith(RobolectricGradleTestRunner.class)
|
||||
@Config(constants = BuildConfig.class)
|
||||
public class FileNameGeneratorTest {
|
||||
public class FileNameGeneratorTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
public void testMd5SimpleName() throws Exception {
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
package com.danikula.videocache;
|
||||
|
||||
import com.danikula.videocache.test.BuildConfig;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricGradleTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
@@ -16,9 +11,7 @@ import static org.fest.assertions.api.Assertions.fail;
|
||||
/**
|
||||
* @author Alexey Danilov (danikula@gmail.com).
|
||||
*/
|
||||
@RunWith(RobolectricGradleTestRunner.class)
|
||||
@Config(constants = BuildConfig.class)
|
||||
public class GetRequestTest {
|
||||
public class GetRequestTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
public void testPartialHttpGet() throws Exception {
|
||||
|
||||
@@ -7,14 +7,10 @@ import com.danikula.videocache.file.FileNameGenerator;
|
||||
import com.danikula.videocache.file.Md5FileNameGenerator;
|
||||
import com.danikula.videocache.support.ProxyCacheTestUtils;
|
||||
import com.danikula.videocache.support.Response;
|
||||
import com.danikula.videocache.test.BuildConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricGradleTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -40,9 +36,7 @@ import static org.fest.assertions.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Alexey Danilov (danikula@gmail.com).
|
||||
*/
|
||||
@RunWith(RobolectricGradleTestRunner.class)
|
||||
@Config(constants = BuildConfig.class)
|
||||
public class HttpProxyCacheServerTest {
|
||||
public class HttpProxyCacheServerTest extends BaseTest {
|
||||
|
||||
private File cacheFolder;
|
||||
|
||||
|
||||
@@ -6,14 +6,10 @@ import com.danikula.videocache.sourcestorage.SourceInfoStorage;
|
||||
import com.danikula.videocache.sourcestorage.SourceInfoStorageFactory;
|
||||
import com.danikula.videocache.support.ProxyCacheTestUtils;
|
||||
import com.danikula.videocache.support.Response;
|
||||
import com.danikula.videocache.test.BuildConfig;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.robolectric.RobolectricGradleTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@@ -49,9 +45,7 @@ import static org.mockito.Mockito.when;
|
||||
*
|
||||
* @author Alexey Danilov (danikula@gmail.com).
|
||||
*/
|
||||
@RunWith(RobolectricGradleTestRunner.class)
|
||||
@Config(constants = BuildConfig.class)
|
||||
public class HttpProxyCacheTest {
|
||||
public class HttpProxyCacheTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
public void testProcessRequestNoCache() throws Exception {
|
||||
|
||||
@@ -3,14 +3,10 @@ package com.danikula.videocache;
|
||||
import com.danikula.videocache.sourcestorage.SourceInfoStorage;
|
||||
import com.danikula.videocache.sourcestorage.SourceInfoStorageFactory;
|
||||
import com.danikula.videocache.support.ProxyCacheTestUtils;
|
||||
import com.danikula.videocache.test.BuildConfig;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.robolectric.RobolectricGradleTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Arrays;
|
||||
@@ -33,9 +29,7 @@ import static org.mockito.Matchers.any;
|
||||
/**
|
||||
* @author Alexey Danilov (danikula@gmail.com).
|
||||
*/
|
||||
@RunWith(RobolectricGradleTestRunner.class)
|
||||
@Config(constants = BuildConfig.class)
|
||||
public class HttpUrlSourceTest {
|
||||
public class HttpUrlSourceTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
public void testHttpUrlSourceRange() throws Exception {
|
||||
|
||||
@@ -3,12 +3,8 @@ package com.danikula.videocache;
|
||||
import com.danikula.android.garden.io.IoUtils;
|
||||
import com.danikula.videocache.file.FileCache;
|
||||
import com.danikula.videocache.support.ProxyCacheTestUtils;
|
||||
import com.danikula.videocache.test.BuildConfig;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricGradleTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
@@ -28,9 +24,7 @@ import static org.fest.assertions.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Alexey Danilov (danikula@gmail.com).
|
||||
*/
|
||||
@RunWith(RobolectricGradleTestRunner.class)
|
||||
@Config(constants = BuildConfig.class)
|
||||
public class ProxyCacheTest {
|
||||
public class ProxyCacheTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
public void testNoCache() throws Exception {
|
||||
@@ -102,7 +96,6 @@ public class ProxyCacheTest {
|
||||
assertThat(readData).isEqualTo(sourceData);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadEnd() throws Exception {
|
||||
int capacity = 5323;
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package com.danikula.videocache.file;
|
||||
|
||||
import com.danikula.videocache.BaseTest;
|
||||
import com.danikula.videocache.support.ProxyCacheTestUtils;
|
||||
import com.danikula.videocache.test.BuildConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricGradleTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -21,9 +18,7 @@ import static org.fest.assertions.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Alexey Danilov (danikula@gmail.com).
|
||||
*/
|
||||
@RunWith(RobolectricGradleTestRunner.class)
|
||||
@Config(constants = BuildConfig.class)
|
||||
public class DiskUsageTest {
|
||||
public class DiskUsageTest extends BaseTest {
|
||||
|
||||
private File cacheFolder;
|
||||
|
||||
|
||||
@@ -2,16 +2,13 @@ package com.danikula.videocache.file;
|
||||
|
||||
import com.danikula.android.garden.io.Files;
|
||||
import com.danikula.android.garden.io.IoUtils;
|
||||
import com.danikula.videocache.BaseTest;
|
||||
import com.danikula.videocache.Cache;
|
||||
import com.danikula.videocache.ProxyCacheException;
|
||||
import com.danikula.videocache.test.BuildConfig;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricGradleTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
@@ -27,9 +24,7 @@ import static org.fest.assertions.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Alexey Danilov (danikula@gmail.com).
|
||||
*/
|
||||
@RunWith(RobolectricGradleTestRunner.class)
|
||||
@Config(constants = BuildConfig.class)
|
||||
public class FileCacheTest {
|
||||
public class FileCacheTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
public void testWriteReadDiscCache() throws Exception {
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package com.danikula.videocache.file;
|
||||
|
||||
import com.danikula.videocache.BaseTest;
|
||||
import com.danikula.videocache.support.ProxyCacheTestUtils;
|
||||
import com.danikula.videocache.test.BuildConfig;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricGradleTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -17,9 +14,7 @@ import static org.fest.assertions.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Alexey Danilov (danikula@gmail.com).
|
||||
*/
|
||||
@RunWith(RobolectricGradleTestRunner.class)
|
||||
@Config(constants = BuildConfig.class)
|
||||
public class FilesTest {
|
||||
public class FilesTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
public void testModify() throws Exception {
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package com.danikula.videocache.sourcestorage;
|
||||
|
||||
import com.danikula.videocache.BaseTest;
|
||||
import com.danikula.videocache.SourceInfo;
|
||||
import com.danikula.videocache.test.BuildConfig;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricGradleTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.fest.assertions.api.Assertions.fail;
|
||||
@@ -19,9 +16,7 @@ import static org.fest.assertions.api.Assertions.fail;
|
||||
*
|
||||
* @author Alexey Danilov (danikula@gmail.com).
|
||||
*/
|
||||
@RunWith(RobolectricGradleTestRunner.class)
|
||||
@Config(constants = BuildConfig.class)
|
||||
public class SourceInfoStorageTest {
|
||||
public class SourceInfoStorageTest extends BaseTest {
|
||||
|
||||
private SourceInfoStorage storage;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user