use of org.robolectric.shadows.util.DataSource in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testSetDataSource_withUri.
@Test
public void testSetDataSource_withUri() throws IOException {
Uri uri = Uri.parse("file:/test");
DataSource ds = toDataSource(ApplicationProvider.getApplicationContext(), uri);
ShadowMediaPlayer.addMediaInfo(ds, info);
mediaPlayer.setDataSource(ApplicationProvider.getApplicationContext(), uri);
assertWithMessage("sourceUri").that(shadowMediaPlayer.getSourceUri()).isSameInstanceAs(uri);
assertWithMessage("dataSource").that(shadowMediaPlayer.getDataSource()).isEqualTo(ds);
}
use of org.robolectric.shadows.util.DataSource in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testSetDataSourceFD.
@Test
public void testSetDataSourceFD() throws IOException {
File tmpFile = File.createTempFile("MediaPlayerTest", null);
try {
tmpFile.deleteOnExit();
FileInputStream is = new FileInputStream(tmpFile);
try {
FileDescriptor fd = is.getFD();
DataSource ds = toDataSource(fd, 23, 524);
ShadowMediaPlayer.addMediaInfo(ds, info);
mediaPlayer.setDataSource(fd, 23, 524);
assertWithMessage("sourceUri").that(shadowMediaPlayer.getSourceUri()).isNull();
assertWithMessage("dataSource").that(shadowMediaPlayer.getDataSource()).isEqualTo(ds);
} finally {
is.close();
}
} finally {
tmpFile.delete();
}
}
use of org.robolectric.shadows.util.DataSource in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testSetDataSourceString.
@Test
public void testSetDataSourceString() throws IOException {
DataSource ds = toDataSource("dummy");
ShadowMediaPlayer.addMediaInfo(ds, info);
mediaPlayer.setDataSource("dummy");
assertWithMessage("dataSource").that(shadowMediaPlayer.getDataSource()).isEqualTo(ds);
}
use of org.robolectric.shadows.util.DataSource in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testResetStaticState.
@Test
public void testResetStaticState() {
ShadowMediaPlayer.CreateListener createListener = Mockito.mock(ShadowMediaPlayer.CreateListener.class);
ShadowMediaPlayer.setCreateListener(createListener);
assertWithMessage("createListener").that(ShadowMediaPlayer.createListener).isSameInstanceAs(createListener);
DataSource dummy = toDataSource("stuff");
IOException e = new IOException();
addException(dummy, e);
try {
shadowMediaPlayer.setState(IDLE);
shadowMediaPlayer.setDataSource(dummy);
fail("Expected exception thrown");
} catch (IOException e2) {
assertWithMessage("thrown exception").that(e2).isSameInstanceAs(e);
}
// Check that the mediaInfo was cleared
shadowMediaPlayer.doSetDataSource(defaultSource);
assertWithMessage("mediaInfo:before").that(shadowMediaPlayer.getMediaInfo()).isNotNull();
ShadowMediaPlayer.resetStaticState();
// Check that the listener was cleared.
assertWithMessage("createListener").that(ShadowMediaPlayer.createListener).isNull();
// Check that the mediaInfo was cleared.
try {
shadowMediaPlayer.doSetDataSource(defaultSource);
fail("Expected exception thrown");
} catch (IllegalArgumentException ie) {
// We expect this if the static state has been cleared.
}
// Check that the exception was cleared.
try {
shadowMediaPlayer.setState(IDLE);
ShadowMediaPlayer.addMediaInfo(dummy, info);
shadowMediaPlayer.setDataSource(dummy);
} catch (IOException e2) {
fail("Exception was not cleared by resetStaticState() for <" + dummy + ">" + e2);
}
}
use of org.robolectric.shadows.util.DataSource in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testSetDataSourceExceptionWithWrongExceptionTypeAsserts.
@Test
public void testSetDataSourceExceptionWithWrongExceptionTypeAsserts() {
boolean fail = false;
Map<DataSource, Exception> exceptions = ReflectionHelpers.getStaticField(ShadowMediaPlayer.class, "exceptions");
DataSource ds = toDataSource("dummy");
// just a convenient, non-RuntimeException in java.lang
Exception e = new CloneNotSupportedException();
exceptions.put(ds, e);
try {
shadowMediaPlayer.setDataSource(ds);
fail = true;
} catch (AssertionError a) {
} catch (IOException ioe) {
fail("Got exception <" + ioe + ">; expecting assertion");
}
if (fail) {
fail("setDataSource() should assert with non-IOException,non-RuntimeException");
}
}
Aggregations