use of org.robolectric.shadows.util.DataSource in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testSetDataSourceUri.
@Test
public void testSetDataSourceUri() throws IOException {
Map<String, String> headers = new HashMap<>();
Uri uri = Uri.parse("file:/test");
DataSource ds = toDataSource(RuntimeEnvironment.application, uri, headers);
ShadowMediaPlayer.addMediaInfo(ds, info);
mediaPlayer.setDataSource(RuntimeEnvironment.application, uri, headers);
assertThat(shadowMediaPlayer.getSourceUri()).as("sourceUri").isSameAs(uri);
assertThat(shadowMediaPlayer.getDataSource()).as("dataSource").isEqualTo(ds);
}
use of org.robolectric.shadows.util.DataSource in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testSetDataSourceAssetFileDescriptorDataSource.
@Config(minSdk = N)
@Test
public void testSetDataSourceAssetFileDescriptorDataSource() throws IOException {
Application context = ApplicationProvider.getApplicationContext();
try (AssetFileDescriptor fd = context.getResources().openRawResourceFd(R.drawable.an_image)) {
DataSource ds = toDataSource(fd);
ShadowMediaPlayer.addMediaInfo(ds, info);
mediaPlayer.setDataSource(fd);
assertWithMessage("dataSource").that(shadowMediaPlayer.getDataSource()).isEqualTo(ds);
}
}
use of org.robolectric.shadows.util.DataSource in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testSetDataSourceUsesCustomMediaInfoProvider.
@Test
public void testSetDataSourceUsesCustomMediaInfoProvider() throws Exception {
MediaInfo mediaInfo = new MediaInfo();
ShadowMediaPlayer.setMediaInfoProvider(unused -> mediaInfo);
String path = "data_source_path";
DataSource ds = toDataSource(path);
mediaPlayer.setDataSource(path);
assertWithMessage("dataSource").that(shadowMediaPlayer.getDataSource()).isEqualTo(ds);
assertWithMessage("mediaInfo").that(shadowMediaPlayer.getMediaInfo()).isSameInstanceAs(mediaInfo);
}
use of org.robolectric.shadows.util.DataSource in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testSetDataSourceMediaDataSource.
@Config(minSdk = M)
@Test
public void testSetDataSourceMediaDataSource() {
MediaDataSource mediaDataSource = new MediaDataSource() {
@Override
public void close() {
}
@Override
public int readAt(long position, byte[] buffer, int offset, int size) {
return 0;
}
@Override
public long getSize() {
return 0;
}
};
DataSource ds = toDataSource(mediaDataSource);
ShadowMediaPlayer.addMediaInfo(ds, info);
mediaPlayer.setDataSource(mediaDataSource);
assertWithMessage("dataSource").that(shadowMediaPlayer.getDataSource()).isEqualTo(ds);
}
use of org.robolectric.shadows.util.DataSource in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testSetDataSource_withUriAndHeaders.
@Test
public void testSetDataSource_withUriAndHeaders() throws IOException {
Map<String, String> headers = new HashMap<>();
Uri uri = Uri.parse("file:/test");
DataSource ds = toDataSource(ApplicationProvider.getApplicationContext(), uri, headers);
ShadowMediaPlayer.addMediaInfo(ds, info);
mediaPlayer.setDataSource(ApplicationProvider.getApplicationContext(), uri, headers);
assertWithMessage("sourceUri").that(shadowMediaPlayer.getSourceUri()).isSameInstanceAs(uri);
assertWithMessage("dataSource").that(shadowMediaPlayer.getDataSource()).isEqualTo(ds);
}
Aggregations