Commit b77cc7c6 by Karol Wrótniak

Introduced failing unit test for ContentDataSource

parent 8af77acb
......@@ -24,6 +24,9 @@
android:allowBackup="false"
tools:ignore="MissingApplicationIcon,HardcodedDebugMode">
<uses-library android:name="android.test.runner"/>
<provider
android:authorities="exoplayer"
android:name="com.google.android.exoplayer2.upstream.TestDataProvider"/>
</application>
<instrumentation
......
package com.google.android.exoplayer2.upstream;
import android.content.Context;
import android.net.Uri;
import android.test.InstrumentationTestCase;
public class AndroidDataSourceTest extends InstrumentationTestCase {
private static final long SAMPLE_MP4_BYTES = 101597;
private static final String SAMPLE_MP4_PATH = "/mp4/sample.mp4";
public void testAssetDataSource() throws Exception {
final Context context = getInstrumentation().getContext();
AssetDataSource dataSource = new AssetDataSource(context);
Uri assetUri = Uri.parse("file:///android_asset" + SAMPLE_MP4_PATH);
DataSpec dataSpec = new DataSpec(assetUri);
long sourceLengthBytes = dataSource.open(dataSpec);
assertEquals(SAMPLE_MP4_BYTES, sourceLengthBytes);
}
public void testContentDataSource() throws Exception {
Context context = getInstrumentation().getContext();
ContentDataSource dataSource = new ContentDataSource(context);
Uri contentUri = Uri.parse("content://exoplayer" + SAMPLE_MP4_PATH);
DataSpec dataSpec = new DataSpec(contentUri);
long sourceLengthBytes = dataSource.open(dataSpec);
assertEquals(SAMPLE_MP4_BYTES, sourceLengthBytes);
}
}
package com.google.android.exoplayer2.upstream;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.io.FileNotFoundException;
import java.io.IOException;
import static junit.framework.Assert.assertNotNull;
public class TestDataProvider extends ContentProvider {
@Override
public boolean onCreate() {
return true;
}
@Nullable
@Override
public Cursor query(@NonNull final Uri uri, @Nullable final String[] projection, @Nullable final String selection, @Nullable final String[] selectionArgs, @Nullable final String sortOrder) {
throw new UnsupportedOperationException("Not implemented");
}
@Nullable
@Override
public AssetFileDescriptor openAssetFile(@NonNull final Uri uri, @NonNull final String mode) throws FileNotFoundException {
try {
Context context = getContext();
assertNotNull(context);
return context.getAssets().openFd(uri.getPath().replaceFirst("/", ""));
} catch (IOException e) {
FileNotFoundException exception = new FileNotFoundException(e.getMessage());
exception.initCause(e);
throw exception;
}
}
@Nullable
@Override
public String getType(@NonNull final Uri uri) {
throw new UnsupportedOperationException("Not implemented");
}
@Nullable
@Override
public Uri insert(@NonNull final Uri uri, @Nullable final ContentValues values) {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public int delete(@NonNull final Uri uri, @Nullable final String selection, @Nullable final String[] selectionArgs) {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public int update(@NonNull final Uri uri, @Nullable final ContentValues values, @Nullable final String selection, @Nullable final String[] selectionArgs) {
throw new UnsupportedOperationException("Not implemented");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment