MediaMetadataRetriever:setDataSource(string)
с пустой строкой должно выдать IllegalArgumentException () .Тем не менее, он не выдает никаких исключений, если он запускается из моего робоэлектрического теста.
Тестовый класс:
@RunWith(RobolectricTestRunner::class)
class MyActivityTest {
private val context: Context = ApplicationProvider.getApplicationContext()
@get:Rule
val exception = ExpectedException.none()
@Test
fun test_GivenFilePathEmpty_ButNoException() {
// no exception is expected
// Given
val filePath = ""
// val filePath = null // This should also throw Exception
// When
val controller = Robolectric.buildActivity(
MyActivity::class.java
).setup()
// Then
assertNotNull(controller.visible())
}
MyActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mediaMetadataRetriever = new MediaMetadataRetriever();
filePath = ""
mediaMetadataRetriever.setDataSource(filePath);
}
MediaMetadataRetriever.java из AOSP:
public void setDataSource(String path) throws IllegalArgumentException {
if (path == null) {
throw new IllegalArgumentException();
}
try (FileInputStream is = new FileInputStream(path)) {
FileDescriptor fd = is.getFD();
setDataSource(fd, 0, 0x7ffffffffffffffL);
} catch (FileNotFoundException fileEx) {
throw new IllegalArgumentException();
} catch (IOException ioEx) {
throw new IllegalArgumentException();
}
}
Это потому, что robolectric не может определить файловую систему?Или это потому, что API-интерфейсы AOSP на самом деле не вызываются из RobolectricTestRunner?