mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add tests to DataSourceContractTest asserting uri/response headers.
These values must be null/empty while the source isn't opened. And the Uri must be non-null if the source is open. PiperOrigin-RevId: 362329032
This commit is contained in:
parent
962e686045
commit
4665ac5490
2 changed files with 80 additions and 0 deletions
|
|
@ -59,4 +59,14 @@ public class ByteArrayDataSourceContractTest extends DataSourceContractTest {
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void resourceNotFound_transferListenerCallbacks() {}
|
public void resourceNotFound_transferListenerCallbacks() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void getUri_resourceNotFound_returnsNullIfNotOpened() throws Exception {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void getResponseHeaders_resourceNotFound_isEmptyWhileNotOpen() throws Exception {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -470,6 +470,76 @@ public abstract class DataSourceContractTest {
|
||||||
verifyNoMoreInteractions(listener);
|
verifyNoMoreInteractions(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getUri_returnsNonNullValueOnlyWhileOpen() throws Exception {
|
||||||
|
ImmutableList<TestResource> resources = getTestResources();
|
||||||
|
Assertions.checkArgument(!resources.isEmpty(), "Must provide at least one test resource.");
|
||||||
|
|
||||||
|
for (int i = 0; i < resources.size(); i++) {
|
||||||
|
additionalFailureInfo.setInfo(getFailureLabel(resources, i));
|
||||||
|
TestResource resource = resources.get(i);
|
||||||
|
DataSource dataSource = createDataSource();
|
||||||
|
try {
|
||||||
|
assertThat(dataSource.getUri()).isNull();
|
||||||
|
|
||||||
|
dataSource.open(new DataSpec(resource.getUri()));
|
||||||
|
|
||||||
|
assertThat(dataSource.getUri()).isNotNull();
|
||||||
|
} finally {
|
||||||
|
dataSource.close();
|
||||||
|
}
|
||||||
|
assertThat(dataSource.getUri()).isNull();
|
||||||
|
|
||||||
|
additionalFailureInfo.setInfo(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getUri_resourceNotFound_returnsNullIfNotOpened() throws Exception {
|
||||||
|
DataSource dataSource = createDataSource();
|
||||||
|
|
||||||
|
assertThat(dataSource.getUri()).isNull();
|
||||||
|
|
||||||
|
assertThrows(IOException.class, () -> dataSource.open(new DataSpec(getNotFoundUri())));
|
||||||
|
dataSource.close();
|
||||||
|
|
||||||
|
assertThat(dataSource.getUri()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getResponseHeaders_isEmptyWhileNotOpen() throws Exception {
|
||||||
|
ImmutableList<TestResource> resources = getTestResources();
|
||||||
|
Assertions.checkArgument(!resources.isEmpty(), "Must provide at least one test resource.");
|
||||||
|
|
||||||
|
for (int i = 0; i < resources.size(); i++) {
|
||||||
|
additionalFailureInfo.setInfo(getFailureLabel(resources, i));
|
||||||
|
TestResource resource = resources.get(i);
|
||||||
|
DataSource dataSource = createDataSource();
|
||||||
|
try {
|
||||||
|
assertThat(dataSource.getResponseHeaders()).isEmpty();
|
||||||
|
|
||||||
|
dataSource.open(new DataSpec(resource.getUri()));
|
||||||
|
} finally {
|
||||||
|
dataSource.close();
|
||||||
|
}
|
||||||
|
assertThat(dataSource.getResponseHeaders()).isEmpty();
|
||||||
|
|
||||||
|
additionalFailureInfo.setInfo(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getResponseHeaders_resourceNotFound_isEmptyWhileNotOpen() throws Exception {
|
||||||
|
DataSource dataSource = createDataSource();
|
||||||
|
|
||||||
|
assertThat(dataSource.getResponseHeaders()).isEmpty();
|
||||||
|
|
||||||
|
assertThrows(IOException.class, () -> dataSource.open(new DataSpec(getNotFoundUri())));
|
||||||
|
dataSource.close();
|
||||||
|
|
||||||
|
assertThat(dataSource.getResponseHeaders()).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
/** Build a label to make it clear which resource caused a given test failure. */
|
/** Build a label to make it clear which resource caused a given test failure. */
|
||||||
private static String getFailureLabel(List<TestResource> resources, int i) {
|
private static String getFailureLabel(List<TestResource> resources, int i) {
|
||||||
if (resources.size() == 1) {
|
if (resources.size() == 1) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue