Skip to content

Commit

Permalink
Make setters of TestResource.Builder accept a value.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 347388172
  • Loading branch information
christosts committed Dec 17, 2020
1 parent 401634a commit e18892c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected ImmutableList<TestResource> getTestResources() throws Exception {
.setName("simple (pipe=true)")
.setUri(TestContentProvider.buildUri(DATA_PATH, /* pipeMode= */ true))
.setExpectedBytes(completeData)
.resolvesToUnknownLength()
.setResolvesToUnknownLength(true)
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected ImmutableList<TestResource> getTestResources() {
.setName("local-udp-unicast-socket")
.setUri(Uri.parse("udp://localhost:" + findFreeUdpPort()))
.setExpectedBytes(data)
.resolvesToUnknownLength()
.setResolvesToUnknownLength(true)
.setEndOfInputExpected(false)
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void unboundedDataSpec_readEverything() throws Exception {
? Util.readToEnd(dataSource)
: Util.readExactly(dataSource, resource.getExpectedBytes().length);

assertThat(length).isEqualTo(resource.getExpectedLength());
assertThat(length).isEqualTo(resource.getExpectedResolvedLength());
assertThat(data).isEqualTo(resource.getExpectedBytes());
} finally {
dataSource.close();
Expand Down Expand Up @@ -127,19 +127,19 @@ public static final class TestResource {
@Nullable private final String name;
private final Uri uri;
private final byte[] expectedBytes;
private final boolean resolvesToKnownLength;
private final boolean resolvesToUnknownLength;
private final boolean endOfInputExpected;

private TestResource(
@Nullable String name,
Uri uri,
byte[] expectedBytes,
boolean resolvesToKnownLength,
boolean resolvesToUnknownLength,
boolean endOfInputExpected) {
this.name = name;
this.uri = uri;
this.expectedBytes = expectedBytes;
this.resolvesToKnownLength = resolvesToKnownLength;
this.resolvesToUnknownLength = resolvesToUnknownLength;
this.endOfInputExpected = endOfInputExpected;
}

Expand All @@ -160,13 +160,13 @@ public byte[] getExpectedBytes() {
}

/**
* Returns the expected length of this resource.
* Returns the expected resolved length of this resource.
*
* <p>This is either {@link #getExpectedBytes() getExpectedBytes().length} or {@link
* C#LENGTH_UNSET}.
*/
public long getExpectedLength() {
return resolvesToKnownLength ? expectedBytes.length : C.LENGTH_UNSET;
public long getExpectedResolvedLength() {
return resolvesToUnknownLength ? C.LENGTH_UNSET : expectedBytes.length;
}

/**
Expand All @@ -182,12 +182,11 @@ public static final class Builder {
private @MonotonicNonNull String name;
private @MonotonicNonNull Uri uri;
private byte @MonotonicNonNull [] expectedBytes;
private boolean resolvesToKnownLength;
private boolean resolvesToUnknownLength;
private boolean endOfInputExpected;

/** Construct a new instance. */
public Builder() {
this.resolvesToKnownLength = true;
this.endOfInputExpected = true;
}

Expand All @@ -212,12 +211,12 @@ public Builder setExpectedBytes(byte[] expectedBytes) {
}

/**
* Calling this method indicates it's expected that {@link DataSource#open(DataSpec)} will
* return {@link C#LENGTH_UNSET} when passed the URI of this resource and a {@link DataSpec}
* with {@code length == C.LENGTH_UNSET}.
* Sets whether {@link DataSource#open(DataSpec)} is expected to return {@link C#LENGTH_UNSET}
* when passed the URI of this resource and a {@link DataSpec} with {@code length ==
* C.LENGTH_UNSET}.
*/
public Builder resolvesToUnknownLength() {
this.resolvesToKnownLength = false;
public Builder setResolvesToUnknownLength(boolean value) {
this.resolvesToUnknownLength = value;
return this;
}

Expand All @@ -235,7 +234,7 @@ public TestResource build() {
name,
checkNotNull(uri),
checkNotNull(expectedBytes),
resolvesToKnownLength,
resolvesToUnknownLength,
endOfInputExpected);
}
}
Expand Down

0 comments on commit e18892c

Please sign in to comment.