Move TestUtil.createTempFolder and TestUtil.recursiveDelete to Util class
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=150190520
This commit is contained in:
parent
d6db5066cd
commit
f092c4446f
@ -20,9 +20,9 @@ import android.test.InstrumentationTestCase;
|
|||||||
import android.test.MoreAsserts;
|
import android.test.MoreAsserts;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.testutil.FakeDataSource;
|
import com.google.android.exoplayer2.testutil.FakeDataSource;
|
||||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
|
||||||
import com.google.android.exoplayer2.upstream.DataSpec;
|
import com.google.android.exoplayer2.upstream.DataSpec;
|
||||||
import com.google.android.exoplayer2.upstream.FileDataSource;
|
import com.google.android.exoplayer2.upstream.FileDataSource;
|
||||||
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -42,13 +42,13 @@ public class CacheDataSourceTest extends InstrumentationTestCase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
cacheDir = TestUtil.createTempFolder(getInstrumentation().getContext());
|
cacheDir = Util.createTempDirectory(getInstrumentation().getContext(), "ExoPlayerTest");
|
||||||
simpleCache = new SimpleCache(cacheDir, new NoOpCacheEvictor());
|
simpleCache = new SimpleCache(cacheDir, new NoOpCacheEvictor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
TestUtil.recursiveDelete(cacheDir);
|
Util.recursiveDelete(cacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMaxCacheFileSize() throws Exception {
|
public void testMaxCacheFileSize() throws Exception {
|
||||||
|
@ -4,7 +4,7 @@ import android.test.InstrumentationTestCase;
|
|||||||
import android.test.MoreAsserts;
|
import android.test.MoreAsserts;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -36,13 +36,13 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
cacheDir = TestUtil.createTempFolder(getInstrumentation().getContext());
|
cacheDir = Util.createTempDirectory(getInstrumentation().getContext(), "ExoPlayerTest");
|
||||||
index = new CachedContentIndex(cacheDir);
|
index = new CachedContentIndex(cacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
TestUtil.recursiveDelete(cacheDir);
|
Util.recursiveDelete(cacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddGetRemove() throws Exception {
|
public void testAddGetRemove() throws Exception {
|
||||||
|
@ -18,6 +18,7 @@ package com.google.android.exoplayer2.upstream.cache;
|
|||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import com.google.android.exoplayer2.extractor.ChunkIndex;
|
import com.google.android.exoplayer2.extractor.ChunkIndex;
|
||||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||||
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@ -49,13 +50,13 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
|
|||||||
|
|
||||||
tracker = new CachedRegionTracker(cache, CACHE_KEY, CHUNK_INDEX);
|
tracker = new CachedRegionTracker(cache, CACHE_KEY, CHUNK_INDEX);
|
||||||
|
|
||||||
cacheDir = TestUtil.createTempFolder(getInstrumentation().getContext());
|
cacheDir = Util.createTempDirectory(getInstrumentation().getContext(), "ExoPlayerTest");
|
||||||
index = new CachedContentIndex(cacheDir);
|
index = new CachedContentIndex(cacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
TestUtil.recursiveDelete(cacheDir);
|
Util.recursiveDelete(cacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetRegion_noSpansInCache() {
|
public void testGetRegion_noSpansInCache() {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package com.google.android.exoplayer2.upstream.cache;
|
package com.google.android.exoplayer2.upstream.cache;
|
||||||
|
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -48,13 +48,13 @@ public class SimpleCacheSpanTest extends InstrumentationTestCase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
cacheDir = TestUtil.createTempFolder(getInstrumentation().getContext());
|
cacheDir = Util.createTempDirectory(getInstrumentation().getContext(), "ExoPlayerTest");
|
||||||
index = new CachedContentIndex(cacheDir);
|
index = new CachedContentIndex(cacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
TestUtil.recursiveDelete(cacheDir);
|
Util.recursiveDelete(cacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCacheFile() throws Exception {
|
public void testCacheFile() throws Exception {
|
||||||
|
@ -18,7 +18,6 @@ package com.google.android.exoplayer2.upstream.cache;
|
|||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import android.test.MoreAsserts;
|
import android.test.MoreAsserts;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@ -39,12 +38,12 @@ public class SimpleCacheTest extends InstrumentationTestCase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
this.cacheDir = TestUtil.createTempFolder(getInstrumentation().getContext());
|
cacheDir = Util.createTempDirectory(getInstrumentation().getContext(), "ExoPlayerTest");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
TestUtil.recursiveDelete(cacheDir);
|
Util.recursiveDelete(cacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCommittingOneFile() throws Exception {
|
public void testCommittingOneFile() throws Exception {
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package com.google.android.exoplayer2.util;
|
package com.google.android.exoplayer2.util;
|
||||||
|
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -34,14 +33,14 @@ public class AtomicFileTest extends InstrumentationTestCase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
tempFolder = TestUtil.createTempFolder(getInstrumentation().getContext());
|
tempFolder = Util.createTempDirectory(getInstrumentation().getContext(), "ExoPlayerTest");
|
||||||
file = new File(tempFolder, "atomicFile");
|
file = new File(tempFolder, "atomicFile");
|
||||||
atomicFile = new AtomicFile(file);
|
atomicFile = new AtomicFile(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
TestUtil.recursiveDelete(tempFolder);
|
Util.recursiveDelete(tempFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDelete() throws Exception {
|
public void testDelete() throws Exception {
|
||||||
|
@ -36,6 +36,7 @@ import com.google.android.exoplayer2.upstream.DataSource;
|
|||||||
import com.google.android.exoplayer2.upstream.DataSpec;
|
import com.google.android.exoplayer2.upstream.DataSpec;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@ -946,6 +947,24 @@ public final class Util {
|
|||||||
throw (T) t;
|
throw (T) t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Recursively deletes a directory and its content. */
|
||||||
|
public static void recursiveDelete(File fileOrDirectory) {
|
||||||
|
if (fileOrDirectory.isDirectory()) {
|
||||||
|
for (File child : fileOrDirectory.listFiles()) {
|
||||||
|
recursiveDelete(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fileOrDirectory.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates an empty directory in the directory returned by {@link Context#getCacheDir()}. */
|
||||||
|
public static File createTempDirectory(Context context, String prefix) throws IOException {
|
||||||
|
File tempFile = File.createTempFile(prefix, null, context.getCacheDir());
|
||||||
|
tempFile.delete(); // Delete the temp file.
|
||||||
|
tempFile.mkdir(); // Create a directory with the same name.
|
||||||
|
return tempFile;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the result of updating a CRC with the specified bytes in a "most significant bit first"
|
* Returns the result of updating a CRC with the specified bytes in a "most significant bit first"
|
||||||
* order.
|
* order.
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
package com.google.android.exoplayer2.testutil;
|
package com.google.android.exoplayer2.testutil;
|
||||||
|
|
||||||
import android.app.Instrumentation;
|
import android.app.Instrumentation;
|
||||||
import android.content.Context;
|
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.extractor.Extractor;
|
import com.google.android.exoplayer2.extractor.Extractor;
|
||||||
@ -25,7 +24,6 @@ import com.google.android.exoplayer2.extractor.SeekMap;
|
|||||||
import com.google.android.exoplayer2.testutil.FakeExtractorInput.SimulatedIOException;
|
import com.google.android.exoplayer2.testutil.FakeExtractorInput.SimulatedIOException;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -375,21 +373,4 @@ public class TestUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void recursiveDelete(File fileOrDirectory) {
|
|
||||||
if (fileOrDirectory.isDirectory()) {
|
|
||||||
for (File child : fileOrDirectory.listFiles()) {
|
|
||||||
recursiveDelete(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fileOrDirectory.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates an empty folder in the application specific cache directory. */
|
|
||||||
public static File createTempFolder(Context context) throws IOException {
|
|
||||||
File tempFolder = File.createTempFile("ExoPlayerTest", null, context.getCacheDir());
|
|
||||||
Assert.assertTrue(tempFolder.delete());
|
|
||||||
Assert.assertTrue(tempFolder.mkdir());
|
|
||||||
return tempFolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user