From 44318d87d9dfc3663546dcc93def03d6c7fe0737 Mon Sep 17 00:00:00 2001 From: Alexey Danilov Date: Tue, 27 Sep 2016 16:03:01 +0300 Subject: [PATCH] :package: 2.6.2: use slf4j for logging --- README.md | 2 +- library/build.gradle | 3 +- .../videocache/HttpProxyCacheServer.java | 37 ++++++++++--------- .../danikula/videocache/HttpUrlSource.java | 15 +++++--- .../com/danikula/videocache/ProxyCache.java | 11 +++--- .../danikula/videocache/ProxyCacheUtils.java | 8 ++-- .../com/danikula/videocache/StorageUtils.java | 10 +++-- .../videocache/file/LruDiskUsage.java | 9 +++-- sample/build.gradle | 2 +- test/build.gradle | 2 +- .../com/danikula/videocache/BaseTest.java | 17 +++++++++ .../videocache/FileNameGeneratorTest.java | 8 +--- .../danikula/videocache/GetRequestTest.java | 9 +---- .../videocache/HttpProxyCacheServerTest.java | 8 +--- .../videocache/HttpProxyCacheTest.java | 8 +--- .../videocache/HttpUrlSourceTest.java | 8 +--- .../danikula/videocache/ProxyCacheTest.java | 9 +---- .../videocache/file/DiskUsageTest.java | 9 +---- .../videocache/file/FileCacheTest.java | 9 +---- .../danikula/videocache/file/FilesTest.java | 9 +---- .../sourcestorage/SourceInfoStorageTest.java | 9 +---- 21 files changed, 87 insertions(+), 115 deletions(-) create mode 100644 test/src/test/java/com/danikula/videocache/BaseTest.java diff --git a/README.md b/README.md index 8adf990..c111f68 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ repositories { jcenter() } dependencies { - compile 'com.danikula:videocache:2.6.1' + compile 'com.danikula:videocache:2.6.2' } ``` diff --git a/library/build.gradle b/library/build.gradle index d155c9e..6fd1348 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -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' } diff --git a/library/src/main/java/com/danikula/videocache/HttpProxyCacheServer.java b/library/src/main/java/com/danikula/videocache/HttpProxyCacheServer.java index b09a926..b9e5d0c 100644 --- a/library/src/main/java/com/danikula/videocache/HttpProxyCacheServer.java +++ b/library/src/main/java/com/danikula/videocache/HttpProxyCacheServer.java @@ -2,7 +2,6 @@ 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.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 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 @@ */ 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 @@ private HttpProxyCacheServer(Config config) { 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 @@ private void makeSureServerWorks() { } 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 @@ private boolean pingServer() throws ProxyCacheException { 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 @@ private boolean pingServer() throws ProxyCacheException { 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 void registerCacheListener(CacheListener cacheListener, String url) { 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 void unregisterCacheListener(CacheListener cacheListener, String url) { 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 boolean isCached(String url) { } public void shutdown() { - Log.i(LOG_TAG, "Shutdown proxy server"); + LOG.info("Shutdown proxy server"); shutdownClients(); @@ -220,7 +223,7 @@ private void waitForRequest() { 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 @@ private void waitForRequest() { 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 @@ private void processSocket(Socket socket) { } 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 @@ private void closeSocketInput(Socket socket) { } 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 @@ private void closeSocket(Socket socket) { } private void onError(Throwable e) { - Log.e(LOG_TAG, "HttpProxyCacheServer error", e); + LOG.error("HttpProxyCacheServer error", e); } private final class WaitRequestsRunnable implements Runnable { diff --git a/library/src/main/java/com/danikula/videocache/HttpUrlSource.java b/library/src/main/java/com/danikula/videocache/HttpUrlSource.java index e64d653..9820d65 100644 --- a/library/src/main/java/com/danikula/videocache/HttpUrlSource.java +++ b/library/src/main/java/com/danikula/videocache/HttpUrlSource.java @@ -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 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 @@ */ 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 int read(byte[] buffer) throws ProxyCacheException { } 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 @@ private void fetchContentInfo() throws ProxyCacheException { 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 @@ private HttpURLConnection openConnection(int offset, int timeout) throws IOExcep 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 + "-"); diff --git a/library/src/main/java/com/danikula/videocache/ProxyCache.java b/library/src/main/java/com/danikula/videocache/ProxyCache.java index 5fa4176..e3cf856 100644 --- a/library/src/main/java/com/danikula/videocache/ProxyCache.java +++ b/library/src/main/java/com/danikula/videocache/ProxyCache.java @@ -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 @@ */ 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 @@ private void checkReadSourceErrorsCount() throws ProxyCacheException { 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 @@ private void closeSource() { 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); } } diff --git a/library/src/main/java/com/danikula/videocache/ProxyCacheUtils.java b/library/src/main/java/com/danikula/videocache/ProxyCacheUtils.java index 226fa79..7e26a2b 100644 --- a/library/src/main/java/com/danikula/videocache/ProxyCacheUtils.java +++ b/library/src/main/java/com/danikula/videocache/ProxyCacheUtils.java @@ -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 @@ */ 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 @@ static void close(Closeable closeable) { try { closeable.close(); } catch (IOException e) { - Log.e(LOG_TAG, "Error closing resource", e); + LOG.error("Error closing resource", e); } } } diff --git a/library/src/main/java/com/danikula/videocache/StorageUtils.java b/library/src/main/java/com/danikula/videocache/StorageUtils.java index 3772f29..a4f2dce 100644 --- a/library/src/main/java/com/danikula/videocache/StorageUtils.java +++ b/library/src/main/java/com/danikula/videocache/StorageUtils.java @@ -2,12 +2,13 @@ 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 @@ */ final class StorageUtils { + private static final Logger LOG = LoggerFactory.getLogger("StorageUtils"); private static final String INDIVIDUAL_DIR_NAME = "video-cache"; /** @@ -61,7 +63,7 @@ private static File getCacheDirectory(Context context, boolean preferExternal) { } 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 @@ private static File getExternalCacheDir(Context context) { 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; } } diff --git a/library/src/main/java/com/danikula/videocache/file/LruDiskUsage.java b/library/src/main/java/com/danikula/videocache/file/LruDiskUsage.java index f8925f2..224cd2e 100644 --- a/library/src/main/java/com/danikula/videocache/file/LruDiskUsage.java +++ b/library/src/main/java/com/danikula/videocache/file/LruDiskUsage.java @@ -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 @@ */ 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 @@ private void trim(List files) { 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"); } } } diff --git a/sample/build.gradle b/sample/build.gradle index 49ea658..831ba74 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -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' } diff --git a/test/build.gradle b/test/build.gradle index 12bf4bc..a59f292 100644 --- a/test/build.gradle +++ b/test/build.gradle @@ -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' diff --git a/test/src/test/java/com/danikula/videocache/BaseTest.java b/test/src/test/java/com/danikula/videocache/BaseTest.java new file mode 100644 index 0000000..3ea4983 --- /dev/null +++ b/test/src/test/java/com/danikula/videocache/BaseTest.java @@ -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"); + } + +} diff --git a/test/src/test/java/com/danikula/videocache/FileNameGeneratorTest.java b/test/src/test/java/com/danikula/videocache/FileNameGeneratorTest.java index 08e2dfc..27da9d6 100644 --- a/test/src/test/java/com/danikula/videocache/FileNameGeneratorTest.java +++ b/test/src/test/java/com/danikula/videocache/FileNameGeneratorTest.java @@ -2,12 +2,8 @@ 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 @@ * * @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 { diff --git a/test/src/test/java/com/danikula/videocache/GetRequestTest.java b/test/src/test/java/com/danikula/videocache/GetRequestTest.java index 1f89ba8..0ccd2b8 100644 --- a/test/src/test/java/com/danikula/videocache/GetRequestTest.java +++ b/test/src/test/java/com/danikula/videocache/GetRequestTest.java @@ -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 @@ /** * @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 { diff --git a/test/src/test/java/com/danikula/videocache/HttpProxyCacheServerTest.java b/test/src/test/java/com/danikula/videocache/HttpProxyCacheServerTest.java index 8d7772d..c128ec3 100644 --- a/test/src/test/java/com/danikula/videocache/HttpProxyCacheServerTest.java +++ b/test/src/test/java/com/danikula/videocache/HttpProxyCacheServerTest.java @@ -7,14 +7,10 @@ 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 @@ /** * @author Alexey Danilov (danikula@gmail.com). */ -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class) -public class HttpProxyCacheServerTest { +public class HttpProxyCacheServerTest extends BaseTest { private File cacheFolder; diff --git a/test/src/test/java/com/danikula/videocache/HttpProxyCacheTest.java b/test/src/test/java/com/danikula/videocache/HttpProxyCacheTest.java index df80839..ad4786b 100644 --- a/test/src/test/java/com/danikula/videocache/HttpProxyCacheTest.java +++ b/test/src/test/java/com/danikula/videocache/HttpProxyCacheTest.java @@ -6,14 +6,10 @@ 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 @@ * * @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 { diff --git a/test/src/test/java/com/danikula/videocache/HttpUrlSourceTest.java b/test/src/test/java/com/danikula/videocache/HttpUrlSourceTest.java index 504b302..3b2857c 100644 --- a/test/src/test/java/com/danikula/videocache/HttpUrlSourceTest.java +++ b/test/src/test/java/com/danikula/videocache/HttpUrlSourceTest.java @@ -3,14 +3,10 @@ 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 @@ /** * @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 { diff --git a/test/src/test/java/com/danikula/videocache/ProxyCacheTest.java b/test/src/test/java/com/danikula/videocache/ProxyCacheTest.java index e4fee0d..edb9835 100644 --- a/test/src/test/java/com/danikula/videocache/ProxyCacheTest.java +++ b/test/src/test/java/com/danikula/videocache/ProxyCacheTest.java @@ -3,12 +3,8 @@ 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 @@ /** * @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 void testProxyWithPhlegmaticSource() throws Exception { assertThat(readData).isEqualTo(sourceData); } - @Test public void testReadEnd() throws Exception { int capacity = 5323; diff --git a/test/src/test/java/com/danikula/videocache/file/DiskUsageTest.java b/test/src/test/java/com/danikula/videocache/file/DiskUsageTest.java index 786f157..8fbd2d4 100644 --- a/test/src/test/java/com/danikula/videocache/file/DiskUsageTest.java +++ b/test/src/test/java/com/danikula/videocache/file/DiskUsageTest.java @@ -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 @@ * * @author Alexey Danilov (danikula@gmail.com). */ -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class) -public class DiskUsageTest { +public class DiskUsageTest extends BaseTest { private File cacheFolder; diff --git a/test/src/test/java/com/danikula/videocache/file/FileCacheTest.java b/test/src/test/java/com/danikula/videocache/file/FileCacheTest.java index 01aeaa6..52909fe 100644 --- a/test/src/test/java/com/danikula/videocache/file/FileCacheTest.java +++ b/test/src/test/java/com/danikula/videocache/file/FileCacheTest.java @@ -2,16 +2,13 @@ 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 @@ /** * @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 { diff --git a/test/src/test/java/com/danikula/videocache/file/FilesTest.java b/test/src/test/java/com/danikula/videocache/file/FilesTest.java index fd0fefe..0743389 100644 --- a/test/src/test/java/com/danikula/videocache/file/FilesTest.java +++ b/test/src/test/java/com/danikula/videocache/file/FilesTest.java @@ -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 @@ * * @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 { diff --git a/test/src/test/java/com/danikula/videocache/sourcestorage/SourceInfoStorageTest.java b/test/src/test/java/com/danikula/videocache/sourcestorage/SourceInfoStorageTest.java index 5d0ae56..0362ff1 100644 --- a/test/src/test/java/com/danikula/videocache/sourcestorage/SourceInfoStorageTest.java +++ b/test/src/test/java/com/danikula/videocache/sourcestorage/SourceInfoStorageTest.java @@ -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 @@ * * @author Alexey Danilov (danikula@gmail.com). */ -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class) -public class SourceInfoStorageTest { +public class SourceInfoStorageTest extends BaseTest { private SourceInfoStorage storage;