Fix downcasting in DownloadAction.Serializers
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=165699826
This commit is contained in:
parent
1e4f899548
commit
a1add8f9e6
@ -16,7 +16,6 @@
|
|||||||
package com.google.android.exoplayer2.offline;
|
package com.google.android.exoplayer2.offline;
|
||||||
|
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import com.google.android.exoplayer2.offline.DownloadAction.Serializer;
|
|
||||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||||
import com.google.android.exoplayer2.upstream.DummyDataSource;
|
import com.google.android.exoplayer2.upstream.DummyDataSource;
|
||||||
import com.google.android.exoplayer2.upstream.cache.Cache;
|
import com.google.android.exoplayer2.upstream.cache.Cache;
|
||||||
@ -101,24 +100,22 @@ public class ProgressiveDownloadActionTest extends InstrumentationTestCase {
|
|||||||
|
|
||||||
public void testSerializerGetType() throws Exception {
|
public void testSerializerGetType() throws Exception {
|
||||||
ProgressiveDownloadAction action = new ProgressiveDownloadAction("uri", null, false);
|
ProgressiveDownloadAction action = new ProgressiveDownloadAction("uri", null, false);
|
||||||
Serializer serializer = action.getSerializer();
|
assertNotNull(action.getType());
|
||||||
assertNotNull(serializer.getType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSerializerWriteRead() throws Exception {
|
public void testSerializerWriteRead() throws Exception {
|
||||||
doTestSerializationRoundtrip(new ProgressiveDownloadAction("uri1", null, false));
|
doTestSerializationRoundTrip(new ProgressiveDownloadAction("uri1", null, false));
|
||||||
doTestSerializationRoundtrip(new ProgressiveDownloadAction("uri2", "key", true));
|
doTestSerializationRoundTrip(new ProgressiveDownloadAction("uri2", "key", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTestSerializationRoundtrip(ProgressiveDownloadAction action1) throws IOException {
|
private void doTestSerializationRoundTrip(ProgressiveDownloadAction action1) throws IOException {
|
||||||
Serializer serializer = action1.getSerializer();
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
DataOutputStream output = new DataOutputStream(out);
|
DataOutputStream output = new DataOutputStream(out);
|
||||||
serializer.writeToStream(output, action1);
|
action1.writeToStream(output);
|
||||||
|
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
DataInputStream input = new DataInputStream(in);
|
DataInputStream input = new DataInputStream(in);
|
||||||
DownloadAction action2 = serializer.readFromStream(input);
|
DownloadAction action2 = ProgressiveDownloadAction.DESERIALIZER.readFromStream(input);
|
||||||
|
|
||||||
assertEquals(action1, action2);
|
assertEquals(action1, action2);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user