Remove duplication of various TestUtil
methods
In most cases, the places that were trying to avoid a transitive dependency on `lib-exoplayer` when this duplication was introduced [1] are already depending on it again, except for `lib-container` where the dep is added in this change. In general it seems fine for the tests of module A to depend (transitively or directly) on module B even where the prod code of module A **does not** depend on module B. [1] <unknown commit> PiperOrigin-RevId: 561660371
This commit is contained in:
parent
6ecd3e9c2d
commit
8af11a980a
@ -19,6 +19,7 @@ import static androidx.media3.common.C.PLAYREADY_UUID;
|
||||
import static androidx.media3.common.C.UUID_NIL;
|
||||
import static androidx.media3.common.C.WIDEVINE_UUID;
|
||||
import static androidx.media3.common.MimeTypes.VIDEO_MP4;
|
||||
import static androidx.media3.test.utils.TestUtil.buildTestData;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.os.Parcel;
|
||||
@ -26,7 +27,6 @@ import androidx.media3.common.DrmInitData.SchemeData;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@ -130,12 +130,4 @@ public class DrmInitDataTest {
|
||||
}
|
||||
return schemeDatas;
|
||||
}
|
||||
|
||||
/** Generates an array of random bytes with the specified length. */
|
||||
// TODO(internal b/161804035): Use TestUtils when it's available in a dependency we can use here.
|
||||
private static byte[] buildTestData(int length, int seed) {
|
||||
byte[] source = new byte[length];
|
||||
new Random(seed).nextBytes(source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package androidx.media3.common;
|
||||
import static androidx.media3.common.C.WIDEVINE_UUID;
|
||||
import static androidx.media3.common.MimeTypes.VIDEO_MP4;
|
||||
import static androidx.media3.common.MimeTypes.VIDEO_WEBM;
|
||||
import static androidx.media3.test.utils.TestUtil.buildTestData;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.os.Bundle;
|
||||
@ -25,7 +26,6 @@ import androidx.media3.test.utils.FakeMetadataEntry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@ -115,12 +115,4 @@ public final class FormatTest {
|
||||
.setTileCountVertical(40)
|
||||
.build();
|
||||
}
|
||||
|
||||
/** Generates an array of random bytes with the specified length. */
|
||||
// TODO(internal b/161804035): Use TestUtils when it's available in a dependency we can use here.
|
||||
private static byte[] buildTestData(int length, int seed) {
|
||||
byte[] source = new byte[length];
|
||||
new Random(seed).nextBytes(source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package androidx.media3.common.util;
|
||||
|
||||
import static androidx.media3.test.utils.TestUtil.createByteArray;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
@ -370,15 +371,4 @@ public final class ParsableBitArrayTest {
|
||||
output.setPosition(0);
|
||||
assertThat(output.readBits(32)).isEqualTo(0x80000001);
|
||||
}
|
||||
|
||||
/** Converts an array of integers in the range [0, 255] into an equivalent byte array. */
|
||||
// TODO(internal b/161804035): Use TestUtils when it's available in a dependency we can use here.
|
||||
private static byte[] createByteArray(int... bytes) {
|
||||
byte[] byteArray = new byte[bytes.length];
|
||||
for (int i = 0; i < byteArray.length; i++) {
|
||||
Assertions.checkState(0x00 <= bytes[i] && bytes[i] <= 0xFF);
|
||||
byteArray[i] = (byte) bytes[i];
|
||||
}
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,9 @@ import static androidx.media3.common.util.Util.minValue;
|
||||
import static androidx.media3.common.util.Util.parseXsDateTime;
|
||||
import static androidx.media3.common.util.Util.parseXsDuration;
|
||||
import static androidx.media3.common.util.Util.unescapeFileName;
|
||||
import static androidx.media3.test.utils.TestUtil.buildTestData;
|
||||
import static androidx.media3.test.utils.TestUtil.buildTestString;
|
||||
import static androidx.media3.test.utils.TestUtil.createByteArray;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
@ -41,7 +44,6 @@ import android.os.HandlerThread;
|
||||
import android.os.Looper;
|
||||
import android.util.SparseLongArray;
|
||||
import androidx.media3.common.C;
|
||||
import androidx.media3.test.utils.TestUtil;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
@ -996,7 +998,7 @@ public class UtilTest {
|
||||
|
||||
@Test
|
||||
public void gzip_resultInflatesBackToOriginalValue() throws Exception {
|
||||
byte[] input = TestUtil.buildTestData(20);
|
||||
byte[] input = buildTestData(20);
|
||||
|
||||
byte[] deflated = gzip(input);
|
||||
|
||||
@ -1514,39 +1516,4 @@ public class UtilTest {
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {}
|
||||
};
|
||||
}
|
||||
|
||||
/** Generates an array of random bytes with the specified length. */
|
||||
private static byte[] buildTestData(int length, int seed) {
|
||||
byte[] source = new byte[length];
|
||||
new Random(seed).nextBytes(source);
|
||||
return source;
|
||||
}
|
||||
|
||||
/** Equivalent to {@code buildTestData(length, length)}. */
|
||||
// TODO(internal b/161804035): Use TestUtils when it's available in a dependency we can use here.
|
||||
private static byte[] buildTestData(int length) {
|
||||
return buildTestData(length, length);
|
||||
}
|
||||
|
||||
/** Generates a random string with the specified maximum length. */
|
||||
// TODO(internal b/161804035): Use TestUtils when it's available in a dependency we can use here.
|
||||
private static String buildTestString(int maximumLength, Random random) {
|
||||
int length = random.nextInt(maximumLength);
|
||||
StringBuilder builder = new StringBuilder(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
builder.append((char) random.nextInt());
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/** Converts an array of integers in the range [0, 255] into an equivalent byte array. */
|
||||
// TODO(internal b/161804035): Use TestUtils when it's available in a dependency we can use here.
|
||||
private static byte[] createByteArray(int... bytes) {
|
||||
byte[] byteArray = new byte[bytes.length];
|
||||
for (int i = 0; i < byteArray.length; i++) {
|
||||
Assertions.checkState(0x00 <= bytes[i] && bytes[i] <= 0xFF);
|
||||
byteArray[i] = (byte) bytes[i];
|
||||
}
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,8 @@ dependencies {
|
||||
testImplementation 'com.google.truth:truth:' + truthVersion
|
||||
testImplementation 'junit:junit:' + junitVersion
|
||||
testImplementation 'org.robolectric:robolectric:' + robolectricVersion
|
||||
testImplementation project(modulePrefix + 'test-utils')
|
||||
|
||||
}
|
||||
|
||||
ext {
|
||||
|
@ -15,9 +15,9 @@
|
||||
*/
|
||||
package androidx.media3.container;
|
||||
|
||||
import static androidx.media3.test.utils.TestUtil.createByteArray;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import androidx.media3.common.util.Assertions;
|
||||
import androidx.media3.common.util.Util;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import java.nio.ByteBuffer;
|
||||
@ -273,15 +273,4 @@ public final class NalUnitUtilTest {
|
||||
NalUnitUtil.discardToSps(buffer);
|
||||
assertThat(Arrays.copyOf(buffer.array(), buffer.position())).isEqualTo(expectedOutputBitstream);
|
||||
}
|
||||
|
||||
/** Converts an array of integers in the range [0, 255] into an equivalent byte array. */
|
||||
// TODO(internal b/161804035): Use TestUtils when it's available in a dependency we can use here.
|
||||
private static byte[] createByteArray(int... bytes) {
|
||||
byte[] byteArray = new byte[bytes.length];
|
||||
for (int i = 0; i < byteArray.length; i++) {
|
||||
Assertions.checkState(0x00 <= bytes[i] && bytes[i] <= 0xFF);
|
||||
byteArray[i] = (byte) bytes[i];
|
||||
}
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,10 @@
|
||||
*/
|
||||
package androidx.media3.container;
|
||||
|
||||
import static androidx.media3.test.utils.TestUtil.createByteArray;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import androidx.media3.common.util.Assertions;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -120,15 +120,4 @@ public final class ParsableNalUnitBitArrayTest {
|
||||
assertThat(array.canReadBits(24)).isTrue();
|
||||
assertThat(array.canReadBits(25)).isFalse();
|
||||
}
|
||||
|
||||
/** Converts an array of integers in the range [0, 255] into an equivalent byte array. */
|
||||
// TODO(internal b/161804035): Use TestUtils when it's available in a dependency we can use here.
|
||||
private static byte[] createByteArray(int... bytes) {
|
||||
byte[] byteArray = new byte[bytes.length];
|
||||
for (int i = 0; i < byteArray.length; i++) {
|
||||
Assertions.checkState(0x00 <= bytes[i] && bytes[i] <= 0xFF);
|
||||
byteArray[i] = (byte) bytes[i];
|
||||
}
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
|
@ -15,16 +15,16 @@
|
||||
*/
|
||||
package androidx.media3.extractor.metadata.emsg;
|
||||
|
||||
import static androidx.media3.test.utils.TestUtil.createByteArray;
|
||||
import static androidx.media3.test.utils.TestUtil.createMetadataInputBuffer;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
import androidx.media3.common.Metadata;
|
||||
import androidx.media3.common.util.Assertions;
|
||||
import androidx.media3.common.util.Util;
|
||||
import androidx.media3.extractor.metadata.MetadataInputBuffer;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import java.nio.ByteBuffer;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@ -81,27 +81,4 @@ public final class EventMessageDecoderTest {
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> decoder.decode(buffer));
|
||||
}
|
||||
|
||||
/** Converts an array of integers in the range [0, 255] into an equivalent byte array. */
|
||||
// TODO(internal b/161804035): Use TestUtils when it's available in a dependency we can use here.
|
||||
private static byte[] createByteArray(int... bytes) {
|
||||
byte[] byteArray = new byte[bytes.length];
|
||||
for (int i = 0; i < byteArray.length; i++) {
|
||||
Assertions.checkState(0x00 <= bytes[i] && bytes[i] <= 0xFF);
|
||||
byteArray[i] = (byte) bytes[i];
|
||||
}
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link MetadataInputBuffer} and copy {@code data} into the backing {@link
|
||||
* ByteBuffer}.
|
||||
*/
|
||||
// TODO(internal b/161804035): Use TestUtils when it's available in a dependency we can use here.
|
||||
private static MetadataInputBuffer createMetadataInputBuffer(byte[] data) {
|
||||
MetadataInputBuffer buffer = new MetadataInputBuffer();
|
||||
buffer.data = ByteBuffer.allocate(data.length).put(data);
|
||||
buffer.data.flip();
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
@ -15,17 +15,17 @@
|
||||
*/
|
||||
package androidx.media3.extractor.metadata.emsg;
|
||||
|
||||
import static androidx.media3.test.utils.TestUtil.createByteArray;
|
||||
import static androidx.media3.test.utils.TestUtil.createMetadataInputBuffer;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import androidx.media3.common.C;
|
||||
import androidx.media3.common.Metadata;
|
||||
import androidx.media3.common.util.Assertions;
|
||||
import androidx.media3.common.util.ParsableByteArray;
|
||||
import androidx.media3.extractor.metadata.MetadataInputBuffer;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@ -91,27 +91,4 @@ public final class EventMessageEncoderTest {
|
||||
|
||||
assertThat(decodedMessage).isEqualTo(originalMessage);
|
||||
}
|
||||
|
||||
/** Converts an array of integers in the range [0, 255] into an equivalent byte array. */
|
||||
// TODO(internal b/161804035): Move to a single file.
|
||||
private static byte[] createByteArray(int... bytes) {
|
||||
byte[] byteArray = new byte[bytes.length];
|
||||
for (int i = 0; i < byteArray.length; i++) {
|
||||
Assertions.checkState(0x00 <= bytes[i] && bytes[i] <= 0xFF);
|
||||
byteArray[i] = (byte) bytes[i];
|
||||
}
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link MetadataInputBuffer} and copy {@code data} into the backing {@link
|
||||
* ByteBuffer}.
|
||||
*/
|
||||
// TODO(internal b/161804035): Use TestUtils when it's available in a dependency we can use here.
|
||||
private static MetadataInputBuffer createMetadataInputBuffer(byte[] data) {
|
||||
MetadataInputBuffer buffer = new MetadataInputBuffer();
|
||||
buffer.data = ByteBuffer.allocate(data.length).put(data);
|
||||
buffer.data.flip();
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package androidx.media3.extractor.metadata.id3;
|
||||
|
||||
import static androidx.media3.test.utils.TestUtil.createByteArray;
|
||||
import static androidx.media3.test.utils.TestUtil.createMetadataInputBuffer;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
@ -24,7 +26,6 @@ import androidx.media3.common.util.Util;
|
||||
import androidx.media3.extractor.metadata.MetadataInputBuffer;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import com.google.common.base.Charsets;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -543,27 +544,4 @@ public final class Id3DecoderTest {
|
||||
this.frameData = frameData;
|
||||
}
|
||||
}
|
||||
|
||||
/** Converts an array of integers in the range [0, 255] into an equivalent byte array. */
|
||||
// TODO(internal b/161804035): Move to a single file.
|
||||
private static byte[] createByteArray(int... bytes) {
|
||||
byte[] byteArray = new byte[bytes.length];
|
||||
for (int i = 0; i < byteArray.length; i++) {
|
||||
Assertions.checkState(0x00 <= bytes[i] && bytes[i] <= 0xFF);
|
||||
byteArray[i] = (byte) bytes[i];
|
||||
}
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link MetadataInputBuffer} and copy {@code data} into the backing {@link
|
||||
* ByteBuffer}.
|
||||
*/
|
||||
// TODO(internal b/161804035): Use TestUtils when it's available in a dependency we can use here.
|
||||
private static MetadataInputBuffer createMetadataInputBuffer(byte[] data) {
|
||||
MetadataInputBuffer buffer = new MetadataInputBuffer();
|
||||
buffer.data = ByteBuffer.allocate(data.length).put(data);
|
||||
buffer.data.flip();
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user