Commit e991a801 by tonihei Committed by Oliver Woodman

Use Truth instead of framework asserts in all tests.

This achieves two things:
1. All our tests use the same type of assertions.
2. The tests currently run as instrumentation test can be moved to
   Robolectric without changing the assertions.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=182910542
parent aa1b41bf
Showing with 916 additions and 774 deletions
......@@ -15,8 +15,7 @@
*/
package com.google.android.exoplayer2.ext.cronet;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
......@@ -53,13 +52,13 @@ public final class ByteArrayUploadDataProviderTest {
@Test
public void testGetLength() {
assertEquals(TEST_DATA.length, byteArrayUploadDataProvider.getLength());
assertThat(byteArrayUploadDataProvider.getLength()).isEqualTo(TEST_DATA.length);
}
@Test
public void testReadFullBuffer() throws IOException {
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
assertArrayEquals(TEST_DATA, byteBuffer.array());
assertThat(byteBuffer.array()).isEqualTo(TEST_DATA);
}
@Test
......@@ -69,12 +68,12 @@ public final class ByteArrayUploadDataProviderTest {
byteBuffer = ByteBuffer.allocate(TEST_DATA.length / 2);
// Read half of the data.
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
assertArrayEquals(firstHalf, byteBuffer.array());
assertThat(byteBuffer.array()).isEqualTo(firstHalf);
// Read the second half of the data.
byteBuffer.rewind();
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
assertArrayEquals(secondHalf, byteBuffer.array());
assertThat(byteBuffer.array()).isEqualTo(secondHalf);
verify(mockUploadDataSink, times(2)).onReadSucceeded(false);
}
......@@ -82,13 +81,13 @@ public final class ByteArrayUploadDataProviderTest {
public void testRewind() throws IOException {
// Read all the data.
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
assertArrayEquals(TEST_DATA, byteBuffer.array());
assertThat(byteBuffer.array()).isEqualTo(TEST_DATA);
// Rewind and make sure it can be read again.
byteBuffer.clear();
byteArrayUploadDataProvider.rewind(mockUploadDataSink);
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
assertArrayEquals(TEST_DATA, byteBuffer.array());
assertThat(byteBuffer.array()).isEqualTo(TEST_DATA);
verify(mockUploadDataSink).onRewindSucceeded();
}
......
......@@ -32,6 +32,7 @@ android {
dependencies {
compile project(modulePrefix + 'library-core')
androidTestCompile 'com.google.truth:truth:' + truthVersion
}
ext {
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.ext.vp9;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.net.Uri;
import android.os.Looper;
......@@ -73,8 +75,8 @@ public class VpxPlaybackTest extends InstrumentationTestCase {
playUri(INVALID_BITSTREAM_URI);
fail();
} catch (Exception e) {
assertNotNull(e.getCause());
assertTrue(e.getCause() instanceof VpxDecoderException);
assertThat(e.getCause()).isNotNull();
assertThat(e.getCause()).isInstanceOf(VpxDecoderException.class);
}
}
......
......@@ -46,6 +46,7 @@ dependencies {
compile 'com.android.support:support-annotations:' + supportLibraryVersion
androidTestCompile 'com.google.dexmaker:dexmaker:' + dexmakerVersion
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:' + dexmakerVersion
androidTestCompile 'com.google.truth:truth:' + truthVersion
androidTestCompile 'org.mockito:mockito-core:' + mockitoVersion
testCompile 'com.google.truth:truth:' + truthVersion
testCompile 'junit:junit:' + junitVersion
......
......@@ -15,11 +15,11 @@
*/
package com.google.android.exoplayer2.drm;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
import android.test.InstrumentationTestCase;
import android.test.MoreAsserts;
import android.util.Pair;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.drm.DrmInitData.SchemeData;
......@@ -86,7 +86,7 @@ public class OfflineLicenseHelperTest extends InstrumentationTestCase {
byte[] offlineLicenseKeySetId = offlineLicenseHelper.downloadLicense(newDrmInitData());
assertNull(offlineLicenseKeySetId);
assertThat(offlineLicenseKeySetId).isNull();
}
public void testDownloadLicenseDoesNotFailIfDurationNotAvailable() throws Exception {
......@@ -94,7 +94,7 @@ public class OfflineLicenseHelperTest extends InstrumentationTestCase {
byte[] offlineLicenseKeySetId = offlineLicenseHelper.downloadLicense(newDrmInitData());
assertNotNull(offlineLicenseKeySetId);
assertThat(offlineLicenseKeySetId).isNotNull();
}
public void testGetLicenseDurationRemainingSec() throws Exception {
......@@ -108,8 +108,8 @@ public class OfflineLicenseHelperTest extends InstrumentationTestCase {
Pair<Long, Long> licenseDurationRemainingSec = offlineLicenseHelper
.getLicenseDurationRemainingSec(offlineLicenseKeySetId);
assertEquals(licenseDuration, (long) licenseDurationRemainingSec.first);
assertEquals(playbackDuration, (long) licenseDurationRemainingSec.second);
assertThat(licenseDurationRemainingSec.first).isEqualTo(licenseDuration);
assertThat(licenseDurationRemainingSec.second).isEqualTo(playbackDuration);
}
public void testGetLicenseDurationRemainingSecExpiredLicense() throws Exception {
......@@ -123,8 +123,8 @@ public class OfflineLicenseHelperTest extends InstrumentationTestCase {
Pair<Long, Long> licenseDurationRemainingSec = offlineLicenseHelper
.getLicenseDurationRemainingSec(offlineLicenseKeySetId);
assertEquals(licenseDuration, (long) licenseDurationRemainingSec.first);
assertEquals(playbackDuration, (long) licenseDurationRemainingSec.second);
assertThat(licenseDurationRemainingSec.first).isEqualTo(licenseDuration);
assertThat(licenseDurationRemainingSec.second).isEqualTo(playbackDuration);
}
private void setDefaultStubKeySetId()
......@@ -139,8 +139,8 @@ public class OfflineLicenseHelperTest extends InstrumentationTestCase {
private static void assertOfflineLicenseKeySetIdEqual(
byte[] expectedKeySetId, byte[] actualKeySetId) throws Exception {
assertNotNull(actualKeySetId);
MoreAsserts.assertEquals(expectedKeySetId, actualKeySetId);
assertThat(actualKeySetId).isNotNull();
assertThat(actualKeySetId).isEqualTo(expectedKeySetId);
}
private void setStubLicenseAndPlaybackDurationValues(long licenseDuration,
......
......@@ -15,6 +15,9 @@
*/
package com.google.android.exoplayer2.extractor.ogg;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
import com.google.android.exoplayer2.util.ParsableByteArray;
......@@ -60,28 +63,33 @@ public final class DefaultOggSeekerTest extends TestCase {
}
// Test granule 0 from file start
assertEquals(0, seekTo(input, oggSeeker, 0, 0));
assertEquals(0, input.getPosition());
assertThat(seekTo(input, oggSeeker, 0, 0)).isEqualTo(0);
assertThat(input.getPosition()).isEqualTo(0);
// Test granule 0 from file end
assertEquals(0, seekTo(input, oggSeeker, 0, testFile.data.length - 1));
assertEquals(0, input.getPosition());
assertThat(seekTo(input, oggSeeker, 0, testFile.data.length - 1)).isEqualTo(0);
assertThat(input.getPosition()).isEqualTo(0);
{ // Test last granule
long currentGranule = seekTo(input, oggSeeker, testFile.lastGranule, 0);
long position = testFile.data.length;
assertTrue((testFile.lastGranule > currentGranule && position > input.getPosition())
|| (testFile.lastGranule == currentGranule && position == input.getPosition()));
assertThat(
(testFile.lastGranule > currentGranule && position > input.getPosition())
|| (testFile.lastGranule == currentGranule && position == input.getPosition()))
.isTrue();
}
{ // Test exact granule
input.setPosition(testFile.data.length / 2);
oggSeeker.skipToNextPage(input);
assertTrue(pageHeader.populate(input, true));
assertThat(pageHeader.populate(input, true)).isTrue();
long position = input.getPosition() + pageHeader.headerSize + pageHeader.bodySize;
long currentGranule = seekTo(input, oggSeeker, pageHeader.granulePosition, 0);
assertTrue((pageHeader.granulePosition > currentGranule && position > input.getPosition())
|| (pageHeader.granulePosition == currentGranule && position == input.getPosition()));
assertThat(
(pageHeader.granulePosition > currentGranule && position > input.getPosition())
|| (pageHeader.granulePosition == currentGranule
&& position == input.getPosition()))
.isTrue();
}
for (int i = 0; i < 100; i += 1) {
......@@ -91,16 +99,17 @@ public final class DefaultOggSeekerTest extends TestCase {
long currentGranule = seekTo(input, oggSeeker, targetGranule, initialPosition);
long currentPosition = input.getPosition();
assertTrue("getNextSeekPosition() didn't leave input on a page start.",
pageHeader.populate(input, true));
assertWithMessage("getNextSeekPosition() didn't leave input on a page start.")
.that(pageHeader.populate(input, true))
.isTrue();
if (currentGranule == 0) {
assertEquals(0, currentPosition);
assertThat(currentPosition).isEqualTo(0);
} else {
int previousPageStart = testFile.findPreviousPageStart(currentPosition);
input.setPosition(previousPageStart);
assertTrue(pageHeader.populate(input, true));
assertEquals(pageHeader.granulePosition, currentGranule);
assertThat(pageHeader.populate(input, true)).isTrue();
assertThat(currentGranule).isEqualTo(pageHeader.granulePosition);
}
input.setPosition((int) currentPosition);
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.extractor.ogg;
import static com.google.common.truth.Truth.assertThat;
import android.test.InstrumentationTestCase;
import com.google.android.exoplayer2.extractor.Extractor;
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
......@@ -56,44 +58,47 @@ public final class OggExtractorTest extends InstrumentationTestCase {
}
public void testSniffVorbis() throws Exception {
byte[] data = TestUtil.joinByteArrays(
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
TestUtil.createByteArray(7), // Laces
new byte[] {0x01, 'v', 'o', 'r', 'b', 'i', 's'});
assertTrue(sniff(data));
byte[] data =
TestUtil.joinByteArrays(
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
TestUtil.createByteArray(7), // Laces
new byte[] {0x01, 'v', 'o', 'r', 'b', 'i', 's'});
assertThat(sniff(data)).isTrue();
}
public void testSniffFlac() throws Exception {
byte[] data = TestUtil.joinByteArrays(
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
TestUtil.createByteArray(5), // Laces
new byte[] {0x7F, 'F', 'L', 'A', 'C'});
assertTrue(sniff(data));
byte[] data =
TestUtil.joinByteArrays(
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
TestUtil.createByteArray(5), // Laces
new byte[] {0x7F, 'F', 'L', 'A', 'C'});
assertThat(sniff(data)).isTrue();
}
public void testSniffFailsOpusFile() throws Exception {
byte[] data = TestUtil.joinByteArrays(
OggTestData.buildOggHeader(0x02, 0, 1000, 0x00),
new byte[] {'O', 'p', 'u', 's'});
assertFalse(sniff(data));
byte[] data =
TestUtil.joinByteArrays(
OggTestData.buildOggHeader(0x02, 0, 1000, 0x00), new byte[] {'O', 'p', 'u', 's'});
assertThat(sniff(data)).isFalse();
}
public void testSniffFailsInvalidOggHeader() throws Exception {
byte[] data = OggTestData.buildOggHeader(0x00, 0, 1000, 0x00);
assertFalse(sniff(data));
assertThat(sniff(data)).isFalse();
}
public void testSniffInvalidHeader() throws Exception {
byte[] data = TestUtil.joinByteArrays(
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
TestUtil.createByteArray(7), // Laces
new byte[] {0x7F, 'X', 'o', 'r', 'b', 'i', 's'});
assertFalse(sniff(data));
byte[] data =
TestUtil.joinByteArrays(
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
TestUtil.createByteArray(7), // Laces
new byte[] {0x7F, 'X', 'o', 'r', 'b', 'i', 's'});
assertThat(sniff(data)).isFalse();
}
public void testSniffFailsEOF() throws Exception {
byte[] data = OggTestData.buildOggHeader(0x02, 0, 1000, 0x00);
assertFalse(sniff(data));
assertThat(sniff(data)).isFalse();
}
private boolean sniff(byte[] data) throws InterruptedException, IOException {
......
......@@ -15,8 +15,9 @@
*/
package com.google.android.exoplayer2.extractor.ogg;
import static com.google.common.truth.Truth.assertThat;
import android.test.InstrumentationTestCase;
import android.test.MoreAsserts;
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
import com.google.android.exoplayer2.testutil.OggTestData;
import com.google.android.exoplayer2.testutil.TestUtil;
......@@ -48,56 +49,58 @@ public final class OggPacketTest extends InstrumentationTestCase {
byte[] thirdPacket = TestUtil.buildTestData(256, random);
byte[] fourthPacket = TestUtil.buildTestData(271, random);
FakeExtractorInput input = OggTestData.createInput(
TestUtil.joinByteArrays(
// First page with a single packet.
OggTestData.buildOggHeader(0x02, 0, 1000, 0x01),
TestUtil.createByteArray(0x08), // Laces
firstPacket,
// Second page with a single packet.
OggTestData.buildOggHeader(0x00, 16, 1001, 0x02),
TestUtil.createByteArray(0xFF, 0x11), // Laces
secondPacket,
// Third page with zero packets.
OggTestData.buildOggHeader(0x00, 16, 1002, 0x00),
// Fourth page with two packets.
OggTestData.buildOggHeader(0x04, 128, 1003, 0x04),
TestUtil.createByteArray(0xFF, 0x01, 0xFF, 0x10), // Laces
thirdPacket,
fourthPacket), true);
FakeExtractorInput input =
OggTestData.createInput(
TestUtil.joinByteArrays(
// First page with a single packet.
OggTestData.buildOggHeader(0x02, 0, 1000, 0x01),
TestUtil.createByteArray(0x08), // Laces
firstPacket,
// Second page with a single packet.
OggTestData.buildOggHeader(0x00, 16, 1001, 0x02),
TestUtil.createByteArray(0xFF, 0x11), // Laces
secondPacket,
// Third page with zero packets.
OggTestData.buildOggHeader(0x00, 16, 1002, 0x00),
// Fourth page with two packets.
OggTestData.buildOggHeader(0x04, 128, 1003, 0x04),
TestUtil.createByteArray(0xFF, 0x01, 0xFF, 0x10), // Laces
thirdPacket,
fourthPacket),
true);
assertReadPacket(input, firstPacket);
assertTrue((oggPacket.getPageHeader().type & 0x02) == 0x02);
assertFalse((oggPacket.getPageHeader().type & 0x04) == 0x04);
assertEquals(0x02, oggPacket.getPageHeader().type);
assertEquals(27 + 1, oggPacket.getPageHeader().headerSize);
assertEquals(8, oggPacket.getPageHeader().bodySize);
assertEquals(0x00, oggPacket.getPageHeader().revision);
assertEquals(1, oggPacket.getPageHeader().pageSegmentCount);
assertEquals(1000, oggPacket.getPageHeader().pageSequenceNumber);
assertEquals(4096, oggPacket.getPageHeader().streamSerialNumber);
assertEquals(0, oggPacket.getPageHeader().granulePosition);
assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isTrue();
assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isFalse();
assertThat(oggPacket.getPageHeader().type).isEqualTo(0x02);
assertThat(oggPacket.getPageHeader().headerSize).isEqualTo(27 + 1);
assertThat(oggPacket.getPageHeader().bodySize).isEqualTo(8);
assertThat(oggPacket.getPageHeader().revision).isEqualTo(0x00);
assertThat(oggPacket.getPageHeader().pageSegmentCount).isEqualTo(1);
assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1000);
assertThat(oggPacket.getPageHeader().streamSerialNumber).isEqualTo(4096);
assertThat(oggPacket.getPageHeader().granulePosition).isEqualTo(0);
assertReadPacket(input, secondPacket);
assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02);
assertFalse((oggPacket.getPageHeader().type & 0x04) == 0x04);
assertEquals(0, oggPacket.getPageHeader().type);
assertEquals(27 + 2, oggPacket.getPageHeader().headerSize);
assertEquals(255 + 17, oggPacket.getPageHeader().bodySize);
assertEquals(2, oggPacket.getPageHeader().pageSegmentCount);
assertEquals(1001, oggPacket.getPageHeader().pageSequenceNumber);
assertEquals(16, oggPacket.getPageHeader().granulePosition);
assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse();
assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isFalse();
assertThat(oggPacket.getPageHeader().type).isEqualTo(0);
assertThat(oggPacket.getPageHeader().headerSize).isEqualTo(27 + 2);
assertThat(oggPacket.getPageHeader().bodySize).isEqualTo(255 + 17);
assertThat(oggPacket.getPageHeader().pageSegmentCount).isEqualTo(2);
assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1001);
assertThat(oggPacket.getPageHeader().granulePosition).isEqualTo(16);
assertReadPacket(input, thirdPacket);
assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02);
assertTrue((oggPacket.getPageHeader().type & 0x04) == 0x04);
assertEquals(4, oggPacket.getPageHeader().type);
assertEquals(27 + 4, oggPacket.getPageHeader().headerSize);
assertEquals(255 + 1 + 255 + 16, oggPacket.getPageHeader().bodySize);
assertEquals(4, oggPacket.getPageHeader().pageSegmentCount);
assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse();
assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isTrue();
assertThat(oggPacket.getPageHeader().type).isEqualTo(4);
assertThat(oggPacket.getPageHeader().headerSize).isEqualTo(27 + 4);
assertThat(oggPacket.getPageHeader().bodySize).isEqualTo(255 + 1 + 255 + 16);
assertThat(oggPacket.getPageHeader().pageSegmentCount).isEqualTo(4);
// Page 1002 is empty, so current page is 1003.
assertEquals(1003, oggPacket.getPageHeader().pageSequenceNumber);
assertEquals(128, oggPacket.getPageHeader().granulePosition);
assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1003);
assertThat(oggPacket.getPageHeader().granulePosition).isEqualTo(128);
assertReadPacket(input, fourthPacket);
......@@ -135,9 +138,9 @@ public final class OggPacketTest extends InstrumentationTestCase {
Arrays.copyOfRange(firstPacket, 510, 510 + 8)), true);
assertReadPacket(input, firstPacket);
assertTrue((oggPacket.getPageHeader().type & 0x04) == 0x04);
assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02);
assertEquals(1001, oggPacket.getPageHeader().pageSequenceNumber);
assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isTrue();
assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse();
assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1001);
assertReadEof(input);
}
......@@ -165,9 +168,9 @@ public final class OggPacketTest extends InstrumentationTestCase {
Arrays.copyOfRange(firstPacket, 510 + 255 + 255, 510 + 255 + 255 + 8)), true);
assertReadPacket(input, firstPacket);
assertTrue((oggPacket.getPageHeader().type & 0x04) == 0x04);
assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02);
assertEquals(1003, oggPacket.getPageHeader().pageSequenceNumber);
assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isTrue();
assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse();
assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1003);
assertReadEof(input);
}
......@@ -218,19 +221,19 @@ public final class OggPacketTest extends InstrumentationTestCase {
while (readPacket(input)) {
packetCounter++;
}
assertEquals(277, packetCounter);
assertThat(packetCounter).isEqualTo(277);
}
private void assertReadPacket(FakeExtractorInput extractorInput, byte[] expected)
throws IOException, InterruptedException {
assertTrue(readPacket(extractorInput));
assertThat(readPacket(extractorInput)).isTrue();
ParsableByteArray payload = oggPacket.getPayload();
MoreAsserts.assertEquals(expected, Arrays.copyOf(payload.data, payload.limit()));
assertThat(Arrays.copyOf(payload.data, payload.limit())).isEqualTo(expected);
}
private void assertReadEof(FakeExtractorInput extractorInput)
throws IOException, InterruptedException {
assertFalse(readPacket(extractorInput));
assertThat(readPacket(extractorInput)).isFalse();
}
private boolean readPacket(FakeExtractorInput input)
......
......@@ -15,11 +15,12 @@
*/
package com.google.android.exoplayer2.extractor.ogg;
import static org.junit.Assert.fail;
import com.google.android.exoplayer2.testutil.OggTestData;
import com.google.android.exoplayer2.testutil.TestUtil;
import java.util.ArrayList;
import java.util.Random;
import junit.framework.Assert;
/**
* Generates test data.
......@@ -119,7 +120,7 @@ import junit.framework.Assert;
return i;
}
}
Assert.fail();
fail();
return -1;
}
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.extractor.ts;
import static com.google.common.truth.Truth.assertThat;
import android.test.InstrumentationTestCase;
import android.util.SparseArray;
import com.google.android.exoplayer2.C;
......@@ -92,12 +94,11 @@ public final class TsExtractorTest extends InstrumentationTestCase {
readResult = tsExtractor.read(input, seekPositionHolder);
}
CustomEsReader reader = factory.esReader;
assertEquals(2, reader.packetsRead);
assertThat(reader.packetsRead).isEqualTo(2);
TrackOutput trackOutput = reader.getTrackOutput();
assertTrue(trackOutput == output.trackOutputs.get(257 /* PID of audio track. */));
assertEquals(
Format.createTextSampleFormat("1/257", "mime", null, 0, 0, "und", null, 0),
((FakeTrackOutput) trackOutput).format);
assertThat(trackOutput == output.trackOutputs.get(257 /* PID of audio track. */)).isTrue();
assertThat(((FakeTrackOutput) trackOutput).format)
.isEqualTo(Format.createTextSampleFormat("1/257", "mime", null, 0, 0, "und", null, 0));
}
public void testCustomInitialSectionReader() throws Exception {
......@@ -115,7 +116,7 @@ public final class TsExtractorTest extends InstrumentationTestCase {
while (readResult != Extractor.RESULT_END_OF_INPUT) {
readResult = tsExtractor.read(input, seekPositionHolder);
}
assertEquals(1, factory.sdtReader.consumedSdts);
assertThat(factory.sdtReader.consumedSdts).isEqualTo(1);
}
private static void writeJunkData(ByteArrayOutputStream out, int length) {
......@@ -145,7 +146,7 @@ public final class TsExtractorTest extends InstrumentationTestCase {
@Override
public SparseArray<TsPayloadReader> createInitialPayloadReaders() {
if (provideSdtReader) {
assertNull(sdtReader);
assertThat(sdtReader).isNull();
SparseArray<TsPayloadReader> mapping = new SparseArray<>();
sdtReader = new SdtSectionReader();
mapping.put(17, new SectionReader(sdtReader));
......@@ -226,21 +227,21 @@ public final class TsExtractorTest extends InstrumentationTestCase {
// original_network_id(16), reserved_future_use(8)
sectionData.skipBytes(11);
// Start of the service loop.
assertEquals(0x5566 /* arbitrary service id */, sectionData.readUnsignedShort());
assertThat(sectionData.readUnsignedShort()).isEqualTo(0x5566 /* arbitrary service id */);
// reserved_future_use(6), EIT_schedule_flag(1), EIT_present_following_flag(1)
sectionData.skipBytes(1);
// Assert there is only one service.
// Remove running_status(3), free_CA_mode(1) from the descriptors_loop_length with the mask.
assertEquals(sectionData.readUnsignedShort() & 0xFFF, sectionData.bytesLeft());
assertThat(sectionData.readUnsignedShort() & 0xFFF).isEqualTo(sectionData.bytesLeft());
while (sectionData.bytesLeft() > 0) {
int descriptorTag = sectionData.readUnsignedByte();
int descriptorLength = sectionData.readUnsignedByte();
if (descriptorTag == 72 /* service descriptor */) {
assertEquals(1, sectionData.readUnsignedByte()); // Service type: Digital TV.
assertThat(sectionData.readUnsignedByte()).isEqualTo(1); // Service type: Digital TV.
int serviceProviderNameLength = sectionData.readUnsignedByte();
assertEquals("Some provider", sectionData.readString(serviceProviderNameLength));
assertThat(sectionData.readString(serviceProviderNameLength)).isEqualTo("Some provider");
int serviceNameLength = sectionData.readUnsignedByte();
assertEquals("Some Channel", sectionData.readString(serviceNameLength));
assertThat(sectionData.readString(serviceNameLength)).isEqualTo("Some Channel");
} else {
sectionData.skipBytes(descriptorLength);
}
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.source;
import static com.google.common.truth.Truth.assertThat;
import android.test.InstrumentationTestCase;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Player;
......@@ -52,10 +54,12 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
Timeline clippedTimeline = getClippedTimeline(timeline, 0, TEST_PERIOD_DURATION_US);
assertEquals(1, clippedTimeline.getWindowCount());
assertEquals(1, clippedTimeline.getPeriodCount());
assertEquals(TEST_PERIOD_DURATION_US, clippedTimeline.getWindow(0, window).getDurationUs());
assertEquals(TEST_PERIOD_DURATION_US, clippedTimeline.getPeriod(0, period).getDurationUs());
assertThat(clippedTimeline.getWindowCount()).isEqualTo(1);
assertThat(clippedTimeline.getPeriodCount()).isEqualTo(1);
assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
.isEqualTo(TEST_PERIOD_DURATION_US);
assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
.isEqualTo(TEST_PERIOD_DURATION_US);
}
public void testClippingUnseekableWindowThrows() throws IOException {
......@@ -68,7 +72,7 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
getClippedTimeline(timeline, 1, TEST_PERIOD_DURATION_US);
fail("Expected clipping to fail.");
} catch (IllegalClippingException e) {
assertEquals(IllegalClippingException.REASON_NOT_SEEKABLE_TO_START, e.reason);
assertThat(e.reason).isEqualTo(IllegalClippingException.REASON_NOT_SEEKABLE_TO_START);
}
}
......@@ -77,10 +81,10 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US,
TEST_PERIOD_DURATION_US);
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US,
clippedTimeline.getWindow(0, window).getDurationUs());
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US,
clippedTimeline.getPeriod(0, period).getDurationUs());
assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
}
public void testClippingEnd() throws IOException {
......@@ -88,10 +92,10 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
Timeline clippedTimeline = getClippedTimeline(timeline, 0,
TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US,
clippedTimeline.getWindow(0, window).getDurationUs());
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US,
clippedTimeline.getPeriod(0, period).getDurationUs());
assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
}
public void testClippingStartAndEndInitial() throws IOException {
......@@ -103,10 +107,10 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US,
TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 2);
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3,
clippedTimeline.getWindow(0, window).getDurationUs());
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3,
clippedTimeline.getPeriod(0, period).getDurationUs());
assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3);
assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3);
}
public void testClippingStartAndEnd() throws IOException {
......@@ -114,10 +118,10 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US,
TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 2);
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3,
clippedTimeline.getWindow(0, window).getDurationUs());
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3,
clippedTimeline.getPeriod(0, period).getDurationUs());
assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3);
assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3);
}
public void testWindowAndPeriodIndices() throws IOException {
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.source;
import static com.google.common.truth.Truth.assertThat;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline;
......@@ -77,8 +79,9 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
}
public void testMultipleMediaSources() throws IOException {
Timeline[] timelines = { createFakeTimeline(3, 111), createFakeTimeline(1, 222),
createFakeTimeline(3, 333) };
Timeline[] timelines = {
createFakeTimeline(3, 111), createFakeTimeline(1, 222), createFakeTimeline(3, 333)
};
Timeline timeline = getConcatenatedTimeline(false, timelines);
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
TimelineAsserts.assertPeriodCounts(timeline, 3, 1, 3);
......@@ -98,10 +101,10 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
C.INDEX_UNSET, 0, 1);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 2, 0, 1);
assertEquals(0, timeline.getFirstWindowIndex(false));
assertEquals(2, timeline.getLastWindowIndex(false));
assertEquals(2, timeline.getFirstWindowIndex(true));
assertEquals(0, timeline.getLastWindowIndex(true));
assertThat(timeline.getFirstWindowIndex(false)).isEqualTo(0);
assertThat(timeline.getLastWindowIndex(false)).isEqualTo(2);
assertThat(timeline.getFirstWindowIndex(true)).isEqualTo(2);
assertThat(timeline.getLastWindowIndex(true)).isEqualTo(0);
timeline = getConcatenatedTimeline(true, timelines);
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
......@@ -117,8 +120,8 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
1, 2, C.INDEX_UNSET);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, shuffled, 1, 2, 0);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, shuffled, 1, 2, 0);
assertEquals(0, timeline.getFirstWindowIndex(shuffled));
assertEquals(2, timeline.getLastWindowIndex(shuffled));
assertThat(timeline.getFirstWindowIndex(shuffled)).isEqualTo(0);
assertThat(timeline.getLastWindowIndex(shuffled)).isEqualTo(2);
}
}
......@@ -152,9 +155,16 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
public void testEmptyTimelineMediaSources() throws IOException {
// Empty timelines in the front, back, and the middle (single and multiple in a row).
Timeline[] timelines = { Timeline.EMPTY, createFakeTimeline(1, 111), Timeline.EMPTY,
Timeline.EMPTY, createFakeTimeline(2, 222), Timeline.EMPTY, createFakeTimeline(3, 333),
Timeline.EMPTY };
Timeline[] timelines = {
Timeline.EMPTY,
createFakeTimeline(1, 111),
Timeline.EMPTY,
Timeline.EMPTY,
createFakeTimeline(2, 222),
Timeline.EMPTY,
createFakeTimeline(3, 333),
Timeline.EMPTY
};
Timeline timeline = getConcatenatedTimeline(false, timelines);
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
TimelineAsserts.assertPeriodCounts(timeline, 1, 2, 3);
......@@ -174,10 +184,10 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
C.INDEX_UNSET, 0, 1);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 2, 0, 1);
assertEquals(0, timeline.getFirstWindowIndex(false));
assertEquals(2, timeline.getLastWindowIndex(false));
assertEquals(2, timeline.getFirstWindowIndex(true));
assertEquals(0, timeline.getLastWindowIndex(true));
assertThat(timeline.getFirstWindowIndex(false)).isEqualTo(0);
assertThat(timeline.getLastWindowIndex(false)).isEqualTo(2);
assertThat(timeline.getFirstWindowIndex(true)).isEqualTo(2);
assertThat(timeline.getLastWindowIndex(true)).isEqualTo(0);
timeline = getConcatenatedTimeline(true, timelines);
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
......@@ -193,8 +203,8 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
1, 2, C.INDEX_UNSET);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, shuffled, 1, 2, 0);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, shuffled, 1, 2, 0);
assertEquals(0, timeline.getFirstWindowIndex(shuffled));
assertEquals(2, timeline.getLastWindowIndex(shuffled));
assertThat(timeline.getFirstWindowIndex(shuffled)).isEqualTo(0);
assertThat(timeline.getLastWindowIndex(shuffled)).isEqualTo(2);
}
}
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.source;
import static com.google.common.truth.Truth.assertThat;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.MergingMediaSource.IllegalMergeException;
......@@ -53,7 +55,7 @@ public class MergingMediaSourceTest extends TestCase {
testMergingMediaSourcePrepare(firstTimeline, secondTimeline);
fail("Expected merging to fail.");
} catch (IllegalMergeException e) {
assertEquals(IllegalMergeException.REASON_PERIOD_COUNT_MISMATCH, e.reason);
assertThat(e.reason).isEqualTo(IllegalMergeException.REASON_PERIOD_COUNT_MISMATCH);
}
}
......@@ -71,7 +73,7 @@ public class MergingMediaSourceTest extends TestCase {
try {
Timeline timeline = testRunner.prepareSource();
// The merged timeline should always be the one from the first child.
assertEquals(timelines[0], timeline);
assertThat(timeline).isEqualTo(timelines[0]);
} finally {
testRunner.release();
}
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.text.ssa;
import static com.google.common.truth.Truth.assertThat;
import android.test.InstrumentationTestCase;
import com.google.android.exoplayer2.testutil.TestUtil;
import java.io.IOException;
......@@ -38,8 +40,8 @@ public final class SsaDecoderTest extends InstrumentationTestCase {
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), EMPTY);
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertEquals(0, subtitle.getEventTimeCount());
assertTrue(subtitle.getCues(0).isEmpty());
assertThat(subtitle.getEventTimeCount()).isEqualTo(0);
assertThat(subtitle.getCues(0).isEmpty()).isTrue();
}
public void testDecodeTypical() throws IOException {
......@@ -47,7 +49,7 @@ public final class SsaDecoderTest extends InstrumentationTestCase {
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL);
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertEquals(6, subtitle.getEventTimeCount());
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
assertTypicalCue1(subtitle, 0);
assertTypicalCue2(subtitle, 2);
assertTypicalCue3(subtitle, 4);
......@@ -63,7 +65,7 @@ public final class SsaDecoderTest extends InstrumentationTestCase {
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_DIALOGUE_ONLY);
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertEquals(6, subtitle.getEventTimeCount());
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
assertTypicalCue1(subtitle, 0);
assertTypicalCue2(subtitle, 2);
assertTypicalCue3(subtitle, 4);
......@@ -75,7 +77,7 @@ public final class SsaDecoderTest extends InstrumentationTestCase {
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), INVALID_TIMECODES);
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertEquals(2, subtitle.getEventTimeCount());
assertThat(subtitle.getEventTimeCount()).isEqualTo(2);
assertTypicalCue3(subtitle, 0);
}
......@@ -84,40 +86,40 @@ public final class SsaDecoderTest extends InstrumentationTestCase {
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_END_TIMECODES);
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertEquals(3, subtitle.getEventTimeCount());
assertThat(subtitle.getEventTimeCount()).isEqualTo(3);
assertEquals(0, subtitle.getEventTime(0));
assertEquals("This is the first subtitle.",
subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString());
assertThat(subtitle.getEventTime(0)).isEqualTo(0);
assertThat(subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString())
.isEqualTo("This is the first subtitle.");
assertEquals(2340000, subtitle.getEventTime(1));
assertEquals("This is the second subtitle \nwith a newline \nand another.",
subtitle.getCues(subtitle.getEventTime(1)).get(0).text.toString());
assertThat(subtitle.getEventTime(1)).isEqualTo(2340000);
assertThat(subtitle.getCues(subtitle.getEventTime(1)).get(0).text.toString())
.isEqualTo("This is the second subtitle \nwith a newline \nand another.");
assertEquals(4560000, subtitle.getEventTime(2));
assertEquals("This is the third subtitle, with a comma.",
subtitle.getCues(subtitle.getEventTime(2)).get(0).text.toString());
assertThat(subtitle.getEventTime(2)).isEqualTo(4560000);
assertThat(subtitle.getCues(subtitle.getEventTime(2)).get(0).text.toString())
.isEqualTo("This is the third subtitle, with a comma.");
}
private static void assertTypicalCue1(SsaSubtitle subtitle, int eventIndex) {
assertEquals(0, subtitle.getEventTime(eventIndex));
assertEquals("This is the first subtitle.",
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
assertEquals(1230000, subtitle.getEventTime(eventIndex + 1));
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(0);
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
.isEqualTo("This is the first subtitle.");
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(1230000);
}
private static void assertTypicalCue2(SsaSubtitle subtitle, int eventIndex) {
assertEquals(2340000, subtitle.getEventTime(eventIndex));
assertEquals("This is the second subtitle \nwith a newline \nand another.",
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
assertEquals(3450000, subtitle.getEventTime(eventIndex + 1));
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(2340000);
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
.isEqualTo("This is the second subtitle \nwith a newline \nand another.");
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(3450000);
}
private static void assertTypicalCue3(SsaSubtitle subtitle, int eventIndex) {
assertEquals(4560000, subtitle.getEventTime(eventIndex));
assertEquals("This is the third subtitle, with a comma.",
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
assertEquals(8900000, subtitle.getEventTime(eventIndex + 1));
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(4560000);
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
.isEqualTo("This is the third subtitle, with a comma.");
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(8900000);
}
}
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.text.subrip;
import static com.google.common.truth.Truth.assertThat;
import android.test.InstrumentationTestCase;
import com.google.android.exoplayer2.testutil.TestUtil;
import java.io.IOException;
......@@ -39,8 +41,8 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), EMPTY_FILE);
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertEquals(0, subtitle.getEventTimeCount());
assertTrue(subtitle.getCues(0).isEmpty());
assertThat(subtitle.getEventTimeCount()).isEqualTo(0);
assertThat(subtitle.getCues(0).isEmpty()).isTrue();
}
public void testDecodeTypical() throws IOException {
......@@ -48,7 +50,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_FILE);
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertEquals(6, subtitle.getEventTimeCount());
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
assertTypicalCue1(subtitle, 0);
assertTypicalCue2(subtitle, 2);
assertTypicalCue3(subtitle, 4);
......@@ -59,7 +61,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_WITH_BYTE_ORDER_MARK);
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertEquals(6, subtitle.getEventTimeCount());
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
assertTypicalCue1(subtitle, 0);
assertTypicalCue2(subtitle, 2);
assertTypicalCue3(subtitle, 4);
......@@ -70,7 +72,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_EXTRA_BLANK_LINE);
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertEquals(6, subtitle.getEventTimeCount());
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
assertTypicalCue1(subtitle, 0);
assertTypicalCue2(subtitle, 2);
assertTypicalCue3(subtitle, 4);
......@@ -82,7 +84,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_MISSING_TIMECODE);
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertEquals(4, subtitle.getEventTimeCount());
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
assertTypicalCue1(subtitle, 0);
assertTypicalCue3(subtitle, 2);
}
......@@ -93,7 +95,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_MISSING_SEQUENCE);
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertEquals(4, subtitle.getEventTimeCount());
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
assertTypicalCue1(subtitle, 0);
assertTypicalCue3(subtitle, 2);
}
......@@ -104,7 +106,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_NEGATIVE_TIMESTAMPS);
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertEquals(2, subtitle.getEventTimeCount());
assertThat(subtitle.getEventTimeCount()).isEqualTo(2);
assertTypicalCue3(subtitle, 0);
}
......@@ -114,7 +116,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_UNEXPECTED_END);
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertEquals(4, subtitle.getEventTimeCount());
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
assertTypicalCue1(subtitle, 0);
assertTypicalCue2(subtitle, 2);
}
......@@ -124,40 +126,40 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_END_TIMECODES_FILE);
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertEquals(3, subtitle.getEventTimeCount());
assertThat(subtitle.getEventTimeCount()).isEqualTo(3);
assertEquals(0, subtitle.getEventTime(0));
assertEquals("SubRip doesn't technically allow missing end timecodes.",
subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString());
assertThat(subtitle.getEventTime(0)).isEqualTo(0);
assertThat(subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString())
.isEqualTo("SubRip doesn't technically allow missing end timecodes.");
assertEquals(2345000, subtitle.getEventTime(1));
assertEquals("We interpret it to mean that a subtitle extends to the start of the next one.",
subtitle.getCues(subtitle.getEventTime(1)).get(0).text.toString());
assertThat(subtitle.getEventTime(1)).isEqualTo(2345000);
assertThat(subtitle.getCues(subtitle.getEventTime(1)).get(0).text.toString())
.isEqualTo("We interpret it to mean that a subtitle extends to the start of the next one.");
assertEquals(3456000, subtitle.getEventTime(2));
assertEquals("Or to the end of the media.",
subtitle.getCues(subtitle.getEventTime(2)).get(0).text.toString());
assertThat(subtitle.getEventTime(2)).isEqualTo(3456000);
assertThat(subtitle.getCues(subtitle.getEventTime(2)).get(0).text.toString())
.isEqualTo("Or to the end of the media.");
}
private static void assertTypicalCue1(SubripSubtitle subtitle, int eventIndex) {
assertEquals(0, subtitle.getEventTime(eventIndex));
assertEquals("This is the first subtitle.",
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
assertEquals(1234000, subtitle.getEventTime(eventIndex + 1));
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(0);
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
.isEqualTo("This is the first subtitle.");
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(1234000);
}
private static void assertTypicalCue2(SubripSubtitle subtitle, int eventIndex) {
assertEquals(2345000, subtitle.getEventTime(eventIndex));
assertEquals("This is the second subtitle.\nSecond subtitle with second line.",
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
assertEquals(3456000, subtitle.getEventTime(eventIndex + 1));
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(2345000);
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
.isEqualTo("This is the second subtitle.\nSecond subtitle with second line.");
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(3456000);
}
private static void assertTypicalCue3(SubripSubtitle subtitle, int eventIndex) {
assertEquals(4567000, subtitle.getEventTime(eventIndex));
assertEquals("This is the third subtitle.",
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
assertEquals(8901000, subtitle.getEventTime(eventIndex + 1));
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(4567000);
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
.isEqualTo("This is the third subtitle.");
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(8901000);
}
}
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.upstream;
import static com.google.common.truth.Truth.assertThat;
import android.app.Instrumentation;
import android.content.ContentProvider;
import android.content.ContentResolver;
......@@ -75,7 +77,7 @@ public final class ContentDataSourceTest extends InstrumentationTestCase {
fail();
} catch (ContentDataSource.ContentDataSourceException e) {
// Expected.
assertTrue(e.getCause() instanceof FileNotFoundException);
assertThat(e.getCause()).isInstanceOf(FileNotFoundException.class);
} finally {
dataSource.close();
}
......
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.upstream.cache;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.when;
......@@ -67,8 +68,8 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
}
public void testGetRegion_noSpansInCache() {
assertEquals(CachedRegionTracker.NOT_CACHED, tracker.getRegionEndTimeMs(100));
assertEquals(CachedRegionTracker.NOT_CACHED, tracker.getRegionEndTimeMs(150));
assertThat(tracker.getRegionEndTimeMs(100)).isEqualTo(CachedRegionTracker.NOT_CACHED);
assertThat(tracker.getRegionEndTimeMs(150)).isEqualTo(CachedRegionTracker.NOT_CACHED);
}
public void testGetRegion_fullyCached() throws Exception {
......@@ -76,8 +77,8 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
cache,
newCacheSpan(100, 100));
assertEquals(CachedRegionTracker.CACHED_TO_END, tracker.getRegionEndTimeMs(101));
assertEquals(CachedRegionTracker.CACHED_TO_END, tracker.getRegionEndTimeMs(121));
assertThat(tracker.getRegionEndTimeMs(101)).isEqualTo(CachedRegionTracker.CACHED_TO_END);
assertThat(tracker.getRegionEndTimeMs(121)).isEqualTo(CachedRegionTracker.CACHED_TO_END);
}
public void testGetRegion_partiallyCached() throws Exception {
......@@ -85,8 +86,8 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
cache,
newCacheSpan(100, 40));
assertEquals(200, tracker.getRegionEndTimeMs(101));
assertEquals(200, tracker.getRegionEndTimeMs(121));
assertThat(tracker.getRegionEndTimeMs(101)).isEqualTo(200);
assertThat(tracker.getRegionEndTimeMs(121)).isEqualTo(200);
}
public void testGetRegion_multipleSpanAddsJoinedCorrectly() throws Exception {
......@@ -97,8 +98,8 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
cache,
newCacheSpan(120, 20));
assertEquals(200, tracker.getRegionEndTimeMs(101));
assertEquals(200, tracker.getRegionEndTimeMs(121));
assertThat(tracker.getRegionEndTimeMs(101)).isEqualTo(200);
assertThat(tracker.getRegionEndTimeMs(121)).isEqualTo(200);
}
public void testGetRegion_fullyCachedThenPartiallyRemoved() throws Exception {
......@@ -112,10 +113,10 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
cache,
newCacheSpan(140, 40));
assertEquals(200, tracker.getRegionEndTimeMs(101));
assertEquals(200, tracker.getRegionEndTimeMs(121));
assertThat(tracker.getRegionEndTimeMs(101)).isEqualTo(200);
assertThat(tracker.getRegionEndTimeMs(121)).isEqualTo(200);
assertEquals(CachedRegionTracker.CACHED_TO_END, tracker.getRegionEndTimeMs(181));
assertThat(tracker.getRegionEndTimeMs(181)).isEqualTo(CachedRegionTracker.CACHED_TO_END);
}
public void testGetRegion_subchunkEstimation() throws Exception {
......@@ -123,8 +124,8 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
cache,
newCacheSpan(100, 10));
assertEquals(50, tracker.getRegionEndTimeMs(101));
assertEquals(CachedRegionTracker.NOT_CACHED, tracker.getRegionEndTimeMs(111));
assertThat(tracker.getRegionEndTimeMs(101)).isEqualTo(50);
assertThat(tracker.getRegionEndTimeMs(111)).isEqualTo(CachedRegionTracker.NOT_CACHED);
}
private CacheSpan newCacheSpan(int position, int length) throws IOException {
......
......@@ -15,6 +15,9 @@
*/
package com.google.android.exoplayer2.upstream.cache;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import android.test.InstrumentationTestCase;
import com.google.android.exoplayer2.util.Util;
import java.io.File;
......@@ -88,39 +91,39 @@ public class SimpleCacheSpanTest extends InstrumentationTestCase {
for (File file : cacheDir.listFiles()) {
SimpleCacheSpan cacheEntry = SimpleCacheSpan.createCacheEntry(file, index);
if (file.equals(wrongEscapedV2file)) {
assertNull(cacheEntry);
assertThat(cacheEntry).isNull();
} else {
assertNotNull(cacheEntry);
assertThat(cacheEntry).isNotNull();
}
}
assertTrue(v3file.exists());
assertFalse(v2file.exists());
assertTrue(wrongEscapedV2file.exists());
assertFalse(v1File.exists());
assertThat(v3file.exists()).isTrue();
assertThat(v2file.exists()).isFalse();
assertThat(wrongEscapedV2file.exists()).isTrue();
assertThat(v1File.exists()).isFalse();
File[] files = cacheDir.listFiles();
assertEquals(4, files.length);
assertThat(files).hasLength(4);
Set<String> keys = index.getKeys();
assertEquals("There should be only one key for all files.", 1, keys.size());
assertTrue(keys.contains(key));
assertWithMessage("There should be only one key for all files.").that(keys).hasSize(1);
assertThat(keys).contains(key);
TreeSet<SimpleCacheSpan> spans = index.get(key).getSpans();
assertTrue("upgradeOldFiles() shouldn't add any spans.", spans.isEmpty());
assertWithMessage("upgradeOldFiles() shouldn't add any spans.").that(spans.isEmpty()).isTrue();
HashMap<Long, Long> cachedPositions = new HashMap<>();
for (File file : files) {
SimpleCacheSpan cacheSpan = SimpleCacheSpan.createCacheEntry(file, index);
if (cacheSpan != null) {
assertEquals(key, cacheSpan.key);
assertThat(cacheSpan.key).isEqualTo(key);
cachedPositions.put(cacheSpan.position, cacheSpan.lastAccessTimestamp);
}
}
assertEquals(1, (long) cachedPositions.get((long) 0));
assertEquals(2, (long) cachedPositions.get((long) 1));
assertEquals(6, (long) cachedPositions.get((long) 5));
assertThat(cachedPositions.get((long) 0)).isEqualTo(1);
assertThat(cachedPositions.get((long) 1)).isEqualTo(2);
assertThat(cachedPositions.get((long) 5)).isEqualTo(6);
}
private static void createTestFile(File file, int length) throws IOException {
......@@ -143,14 +146,14 @@ public class SimpleCacheSpanTest extends InstrumentationTestCase {
File cacheFile = createCacheSpanFile(cacheDir, id, offset, 1, lastAccessTimestamp);
SimpleCacheSpan cacheSpan = SimpleCacheSpan.createCacheEntry(cacheFile, index);
String message = cacheFile.toString();
assertNotNull(message, cacheSpan);
assertEquals(message, cacheDir, cacheFile.getParentFile());
assertEquals(message, key, cacheSpan.key);
assertEquals(message, offset, cacheSpan.position);
assertEquals(message, 1, cacheSpan.length);
assertTrue(message, cacheSpan.isCached);
assertEquals(message, cacheFile, cacheSpan.file);
assertEquals(message, lastAccessTimestamp, cacheSpan.lastAccessTimestamp);
assertWithMessage(message).that(cacheSpan).isNotNull();
assertWithMessage(message).that(cacheFile.getParentFile()).isEqualTo(cacheDir);
assertWithMessage(message).that(cacheSpan.key).isEqualTo(key);
assertWithMessage(message).that(cacheSpan.position).isEqualTo(offset);
assertWithMessage(message).that(cacheSpan.length).isEqualTo(1);
assertWithMessage(message).that(cacheSpan.isCached).isTrue();
assertWithMessage(message).that(cacheSpan.file).isEqualTo(cacheFile);
assertWithMessage(message).that(cacheSpan.lastAccessTimestamp).isEqualTo(lastAccessTimestamp);
}
private void assertNullCacheSpan(File parent, String key, long offset,
......@@ -158,7 +161,7 @@ public class SimpleCacheSpanTest extends InstrumentationTestCase {
File cacheFile = SimpleCacheSpan.getCacheFile(parent, index.assignIdForKey(key), offset,
lastAccessTimestamp);
CacheSpan cacheSpan = SimpleCacheSpan.createCacheEntry(cacheFile, index);
assertNull(cacheFile.toString(), cacheSpan);
assertWithMessage(cacheFile.toString()).that(cacheSpan).isNull();
}
}
......@@ -142,10 +142,7 @@ public class DefaultEbmlReaderTest {
// Check that we really did get to the end of input.
assertThat(input.readFully(new byte[1], 0, 1, true)).isFalse();
assertThat(output.events).hasSize(expectedEvents.size());
for (int i = 0; i < expectedEvents.size(); i++) {
assertThat(output.events.get(i)).isEqualTo(expectedEvents.get(i));
}
assertThat(output.events).containsExactlyElementsIn(expectedEvents).inOrder();
}
/**
......
......@@ -83,11 +83,9 @@ public class SimpleCacheTest {
addCache(simpleCache, KEY_1, 0, 15);
Set<String> cachedKeys = simpleCache.getKeys();
assertThat(cachedKeys).hasSize(1);
assertThat(cachedKeys.contains(KEY_1)).isTrue();
assertThat(cachedKeys).containsExactly(KEY_1);
cachedSpans = simpleCache.getCachedSpans(KEY_1);
assertThat(cachedSpans).hasSize(1);
assertThat(cachedSpans.contains(cacheSpan1)).isTrue();
assertThat(cachedSpans).contains(cacheSpan1);
assertThat(simpleCache.getCacheSpace()).isEqualTo(15);
simpleCache.releaseHoleSpan(cacheSpan1);
......
......@@ -17,7 +17,7 @@ package com.google.android.exoplayer2.util;
import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.Charset.forName;
import static junit.framework.TestCase.fail;
import static org.junit.Assert.fail;
import java.nio.ByteBuffer;
import java.util.Arrays;
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.source.dash;
import static com.google.common.truth.Truth.assertThat;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.drm.DrmInitData;
......@@ -36,25 +38,25 @@ public final class DashUtilTest extends TestCase {
public void testLoadDrmInitDataFromManifest() throws Exception {
Period period = newPeriod(newAdaptationSets(newRepresentations(newDrmInitData())));
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
assertEquals(newDrmInitData(), drmInitData);
assertThat(drmInitData).isEqualTo(newDrmInitData());
}
public void testLoadDrmInitDataMissing() throws Exception {
Period period = newPeriod(newAdaptationSets(newRepresentations(null /* no init data */)));
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
assertNull(drmInitData);
assertThat(drmInitData).isNull();
}
public void testLoadDrmInitDataNoRepresentations() throws Exception {
Period period = newPeriod(newAdaptationSets(/* no representation */));
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
assertNull(drmInitData);
assertThat(drmInitData).isNull();
}
public void testLoadDrmInitDataNoAdaptationSets() throws Exception {
Period period = newPeriod(/* no adaptation set */);
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
assertNull(drmInitData);
assertThat(drmInitData).isNull();
}
private static Period newPeriod(AdaptationSet... adaptationSets) {
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.source.dash.manifest;
import static com.google.common.truth.Truth.assertThat;
import android.net.Uri;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase;
......@@ -129,33 +131,35 @@ public class DashManifestTest extends TestCase {
}
private static void assertManifestEquals(DashManifest expected, DashManifest actual) {
assertEquals(expected.availabilityStartTimeMs, actual.availabilityStartTimeMs);
assertEquals(expected.durationMs, actual.durationMs);
assertEquals(expected.minBufferTimeMs, actual.minBufferTimeMs);
assertEquals(expected.dynamic, actual.dynamic);
assertEquals(expected.minUpdatePeriodMs, actual.minUpdatePeriodMs);
assertEquals(expected.timeShiftBufferDepthMs, actual.timeShiftBufferDepthMs);
assertEquals(expected.suggestedPresentationDelayMs, actual.suggestedPresentationDelayMs);
assertEquals(expected.publishTimeMs, actual.publishTimeMs);
assertEquals(expected.utcTiming, actual.utcTiming);
assertEquals(expected.location, actual.location);
assertEquals(expected.getPeriodCount(), actual.getPeriodCount());
assertThat(actual.availabilityStartTimeMs).isEqualTo(expected.availabilityStartTimeMs);
assertThat(actual.durationMs).isEqualTo(expected.durationMs);
assertThat(actual.minBufferTimeMs).isEqualTo(expected.minBufferTimeMs);
assertThat(actual.dynamic).isEqualTo(expected.dynamic);
assertThat(actual.minUpdatePeriodMs).isEqualTo(expected.minUpdatePeriodMs);
assertThat(actual.timeShiftBufferDepthMs).isEqualTo(expected.timeShiftBufferDepthMs);
assertThat(actual.suggestedPresentationDelayMs)
.isEqualTo(expected.suggestedPresentationDelayMs);
assertThat(actual.publishTimeMs).isEqualTo(expected.publishTimeMs);
assertThat(actual.utcTiming).isEqualTo(expected.utcTiming);
assertThat(actual.location).isEqualTo(expected.location);
assertThat(actual.getPeriodCount()).isEqualTo(expected.getPeriodCount());
for (int i = 0; i < expected.getPeriodCount(); i++) {
Period expectedPeriod = expected.getPeriod(i);
Period actualPeriod = actual.getPeriod(i);
assertEquals(expectedPeriod.id, actualPeriod.id);
assertEquals(expectedPeriod.startMs, actualPeriod.startMs);
assertThat(actualPeriod.id).isEqualTo(expectedPeriod.id);
assertThat(actualPeriod.startMs).isEqualTo(expectedPeriod.startMs);
List<AdaptationSet> expectedAdaptationSets = expectedPeriod.adaptationSets;
List<AdaptationSet> actualAdaptationSets = actualPeriod.adaptationSets;
assertEquals(expectedAdaptationSets.size(), actualAdaptationSets.size());
assertThat(actualAdaptationSets).hasSize(expectedAdaptationSets.size());
for (int j = 0; j < expectedAdaptationSets.size(); j++) {
AdaptationSet expectedAdaptationSet = expectedAdaptationSets.get(j);
AdaptationSet actualAdaptationSet = actualAdaptationSets.get(j);
assertEquals(expectedAdaptationSet.id, actualAdaptationSet.id);
assertEquals(expectedAdaptationSet.type, actualAdaptationSet.type);
assertEquals(expectedAdaptationSet.accessibilityDescriptors,
actualAdaptationSet.accessibilityDescriptors);
assertEquals(expectedAdaptationSet.representations, actualAdaptationSet.representations);
assertThat(actualAdaptationSet.id).isEqualTo(expectedAdaptationSet.id);
assertThat(actualAdaptationSet.type).isEqualTo(expectedAdaptationSet.type);
assertThat(actualAdaptationSet.accessibilityDescriptors)
.isEqualTo(expectedAdaptationSet.accessibilityDescriptors);
assertThat(actualAdaptationSet.representations)
.isEqualTo(expectedAdaptationSet.representations);
}
}
}
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.source.dash.manifest;
import static com.google.common.truth.Truth.assertThat;
import com.google.android.exoplayer2.C;
import junit.framework.TestCase;
......@@ -72,16 +74,16 @@ public class RangedUriTest extends TestCase {
private void assertMerge(RangedUri rangeA, RangedUri rangeB, RangedUri expected, String baseUrl) {
RangedUri merged = rangeA.attemptMerge(rangeB, baseUrl);
assertEquals(expected, merged);
assertThat(merged).isEqualTo(expected);
merged = rangeB.attemptMerge(rangeA, baseUrl);
assertEquals(expected, merged);
assertThat(merged).isEqualTo(expected);
}
private void assertNonMerge(RangedUri rangeA, RangedUri rangeB, String baseUrl) {
RangedUri merged = rangeA.attemptMerge(rangeB, baseUrl);
assertNull(merged);
assertThat(merged).isNull();
merged = rangeB.attemptMerge(rangeA, baseUrl);
assertNull(merged);
assertThat(merged).isNull();
}
}
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.source.dash.manifest;
import static com.google.common.truth.Truth.assertThat;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase;
import com.google.android.exoplayer2.util.MimeTypes;
......@@ -32,13 +34,13 @@ public class RepresentationTest extends TestCase {
MimeTypes.VIDEO_H264, 2500000, 1920, 1080, Format.NO_VALUE, null, 0);
Representation representation = Representation.newInstance("test_stream_1", 3, format, uri,
base);
assertEquals("test_stream_1.0.3", representation.getCacheKey());
assertThat(representation.getCacheKey()).isEqualTo("test_stream_1.0.3");
format = Format.createVideoContainerFormat("150", MimeTypes.APPLICATION_MP4, null,
MimeTypes.VIDEO_H264, 2500000, 1920, 1080, Format.NO_VALUE, null, 0);
representation = Representation.newInstance("test_stream_1", Representation.REVISION_ID_DEFAULT,
format, uri, base);
assertEquals("test_stream_1.150.-1", representation.getCacheKey());
assertThat(representation.getCacheKey()).isEqualTo("test_stream_1.150.-1");
}
}
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.source.dash.manifest;
import static com.google.common.truth.Truth.assertThat;
import junit.framework.TestCase;
/**
......@@ -26,31 +28,31 @@ public class UrlTemplateTest extends TestCase {
String template = "QualityLevels($Bandwidth$)/Fragments(video=$Time$,format=mpd-time-csf)";
UrlTemplate urlTemplate = UrlTemplate.compile(template);
String url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
assertEquals("QualityLevels(650000)/Fragments(video=5000,format=mpd-time-csf)", url);
assertThat(url).isEqualTo("QualityLevels(650000)/Fragments(video=5000,format=mpd-time-csf)");
template = "$RepresentationID$/$Number$";
urlTemplate = UrlTemplate.compile(template);
url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
assertEquals("abc1/10", url);
assertThat(url).isEqualTo("abc1/10");
template = "chunk_ctvideo_cfm4s_rid$RepresentationID$_cn$Number$_w2073857842_mpd.m4s";
urlTemplate = UrlTemplate.compile(template);
url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
assertEquals("chunk_ctvideo_cfm4s_ridabc1_cn10_w2073857842_mpd.m4s", url);
assertThat(url).isEqualTo("chunk_ctvideo_cfm4s_ridabc1_cn10_w2073857842_mpd.m4s");
}
public void testFull() {
String template = "$Bandwidth$_a_$RepresentationID$_b_$Time$_c_$Number$";
UrlTemplate urlTemplate = UrlTemplate.compile(template);
String url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
assertEquals("650000_a_abc1_b_5000_c_10", url);
assertThat(url).isEqualTo("650000_a_abc1_b_5000_c_10");
}
public void testFullWithDollarEscaping() {
String template = "$$$Bandwidth$$$_a$$_$RepresentationID$_b_$Time$_c_$Number$$$";
UrlTemplate urlTemplate = UrlTemplate.compile(template);
String url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
assertEquals("$650000$_a$_abc1_b_5000_c_10$", url);
assertThat(url).isEqualTo("$650000$_a$_abc1_b_5000_c_10$");
}
public void testInvalidSubstitution() {
......
......@@ -21,6 +21,9 @@ import static com.google.android.exoplayer2.source.dash.offline.DashDownloadTest
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertCacheEmpty;
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertCachedData;
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertDataCached;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import android.test.InstrumentationTestCase;
import com.google.android.exoplayer2.C;
......@@ -73,7 +76,7 @@ public class DashDownloaderTest extends InstrumentationTestCase {
DashManifest manifest = dashDownloader.getManifest();
assertNotNull(manifest);
assertThat(manifest).isNotNull();
assertCachedData(cache, fakeDataSet);
}
......@@ -101,7 +104,7 @@ public class DashDownloaderTest extends InstrumentationTestCase {
// on the second try it downloads the rest of the data
DashManifest manifest = dashDownloader.getManifest();
assertNotNull(manifest);
assertThat(manifest).isNotNull();
assertCachedData(cache, fakeDataSet);
}
......@@ -203,8 +206,8 @@ public class DashDownloaderTest extends InstrumentationTestCase {
.setRandomData("text_segment_2", 2)
.setRandomData("text_segment_3", 3);
FakeDataSource fakeDataSource = new FakeDataSource(fakeDataSet);
Factory factory = Mockito.mock(Factory.class);
Mockito.when(factory.createDataSource()).thenReturn(fakeDataSource);
Factory factory = mock(Factory.class);
when(factory.createDataSource()).thenReturn(fakeDataSource);
DashDownloader dashDownloader = new DashDownloader(TEST_MPD_URI,
new DownloaderConstructorHelper(cache, factory));
......@@ -213,15 +216,15 @@ public class DashDownloaderTest extends InstrumentationTestCase {
dashDownloader.download(null);
DataSpec[] openedDataSpecs = fakeDataSource.getAndClearOpenedDataSpecs();
assertEquals(8, openedDataSpecs.length);
assertEquals(TEST_MPD_URI, openedDataSpecs[0].uri);
assertEquals("audio_init_data", openedDataSpecs[1].uri.getPath());
assertEquals("audio_segment_1", openedDataSpecs[2].uri.getPath());
assertEquals("text_segment_1", openedDataSpecs[3].uri.getPath());
assertEquals("audio_segment_2", openedDataSpecs[4].uri.getPath());
assertEquals("text_segment_2", openedDataSpecs[5].uri.getPath());
assertEquals("audio_segment_3", openedDataSpecs[6].uri.getPath());
assertEquals("text_segment_3", openedDataSpecs[7].uri.getPath());
assertThat(openedDataSpecs.length).isEqualTo(8);
assertThat(openedDataSpecs[0].uri).isEqualTo(TEST_MPD_URI);
assertThat(openedDataSpecs[1].uri.getPath()).isEqualTo("audio_init_data");
assertThat(openedDataSpecs[2].uri.getPath()).isEqualTo("audio_segment_1");
assertThat(openedDataSpecs[3].uri.getPath()).isEqualTo("text_segment_1");
assertThat(openedDataSpecs[4].uri.getPath()).isEqualTo("audio_segment_2");
assertThat(openedDataSpecs[5].uri.getPath()).isEqualTo("text_segment_2");
assertThat(openedDataSpecs[6].uri.getPath()).isEqualTo("audio_segment_3");
assertThat(openedDataSpecs[7].uri.getPath()).isEqualTo("text_segment_3");
}
public void testProgressiveDownloadSeparatePeriods() throws Exception {
......@@ -235,8 +238,8 @@ public class DashDownloaderTest extends InstrumentationTestCase {
.setRandomData("period_2_segment_2", 2)
.setRandomData("period_2_segment_3", 3);
FakeDataSource fakeDataSource = new FakeDataSource(fakeDataSet);
Factory factory = Mockito.mock(Factory.class);
Mockito.when(factory.createDataSource()).thenReturn(fakeDataSource);
Factory factory = mock(Factory.class);
when(factory.createDataSource()).thenReturn(fakeDataSource);
DashDownloader dashDownloader = new DashDownloader(TEST_MPD_URI,
new DownloaderConstructorHelper(cache, factory));
......@@ -245,15 +248,15 @@ public class DashDownloaderTest extends InstrumentationTestCase {
dashDownloader.download(null);
DataSpec[] openedDataSpecs = fakeDataSource.getAndClearOpenedDataSpecs();
assertEquals(8, openedDataSpecs.length);
assertEquals(TEST_MPD_URI, openedDataSpecs[0].uri);
assertEquals("audio_init_data", openedDataSpecs[1].uri.getPath());
assertEquals("audio_segment_1", openedDataSpecs[2].uri.getPath());
assertEquals("audio_segment_2", openedDataSpecs[3].uri.getPath());
assertEquals("audio_segment_3", openedDataSpecs[4].uri.getPath());
assertEquals("period_2_segment_1", openedDataSpecs[5].uri.getPath());
assertEquals("period_2_segment_2", openedDataSpecs[6].uri.getPath());
assertEquals("period_2_segment_3", openedDataSpecs[7].uri.getPath());
assertThat(openedDataSpecs.length).isEqualTo(8);
assertThat(openedDataSpecs[0].uri).isEqualTo(TEST_MPD_URI);
assertThat(openedDataSpecs[1].uri.getPath()).isEqualTo("audio_init_data");
assertThat(openedDataSpecs[2].uri.getPath()).isEqualTo("audio_segment_1");
assertThat(openedDataSpecs[3].uri.getPath()).isEqualTo("audio_segment_2");
assertThat(openedDataSpecs[4].uri.getPath()).isEqualTo("audio_segment_3");
assertThat(openedDataSpecs[5].uri.getPath()).isEqualTo("period_2_segment_1");
assertThat(openedDataSpecs[6].uri.getPath()).isEqualTo("period_2_segment_2");
assertThat(openedDataSpecs[7].uri.getPath()).isEqualTo("period_2_segment_3");
}
public void testDownloadRepresentationFailure() throws Exception {
......@@ -400,9 +403,9 @@ public class DashDownloaderTest extends InstrumentationTestCase {
private static void assertCounters(DashDownloader dashDownloader, int totalSegments,
int downloadedSegments, int downloadedBytes) {
assertEquals(totalSegments, dashDownloader.getTotalSegments());
assertEquals(downloadedSegments, dashDownloader.getDownloadedSegments());
assertEquals(downloadedBytes, dashDownloader.getDownloadedBytes());
assertThat(dashDownloader.getTotalSegments()).isEqualTo(totalSegments);
assertThat(dashDownloader.getDownloadedSegments()).isEqualTo(downloadedSegments);
assertThat(dashDownloader.getDownloadedBytes()).isEqualTo(downloadedBytes);
}
}
......@@ -30,6 +30,7 @@ import static com.google.android.exoplayer2.source.hls.offline.HlsDownloadTestDa
import static com.google.android.exoplayer2.source.hls.offline.HlsDownloadTestData.MEDIA_PLAYLIST_DATA;
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertCacheEmpty;
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertCachedData;
import static com.google.common.truth.Truth.assertThat;
import android.net.Uri;
import android.test.InstrumentationTestCase;
......@@ -78,7 +79,7 @@ public class HlsDownloaderTest extends InstrumentationTestCase {
public void testDownloadManifest() throws Exception {
HlsMasterPlaylist manifest = hlsDownloader.getManifest();
assertNotNull(manifest);
assertThat(manifest).isNotNull();
assertCachedData(cache, fakeDataSet, MASTER_PLAYLIST_URI);
}
......@@ -97,9 +98,10 @@ public class HlsDownloaderTest extends InstrumentationTestCase {
hlsDownloader.selectRepresentations(new String[] {MEDIA_PLAYLIST_1_URI});
hlsDownloader.download(null);
assertEquals(4, hlsDownloader.getTotalSegments());
assertEquals(4, hlsDownloader.getDownloadedSegments());
assertEquals(MEDIA_PLAYLIST_DATA.length + 10 + 11 + 12, hlsDownloader.getDownloadedBytes());
assertThat(hlsDownloader.getTotalSegments()).isEqualTo(4);
assertThat(hlsDownloader.getDownloadedSegments()).isEqualTo(4);
assertThat(hlsDownloader.getDownloadedBytes())
.isEqualTo(MEDIA_PLAYLIST_DATA.length + 10 + 11 + 12);
}
public void testInitStatus() throws Exception {
......@@ -111,9 +113,10 @@ public class HlsDownloaderTest extends InstrumentationTestCase {
newHlsDownloader.selectRepresentations(new String[] {MEDIA_PLAYLIST_1_URI});
newHlsDownloader.init();
assertEquals(4, newHlsDownloader.getTotalSegments());
assertEquals(4, newHlsDownloader.getDownloadedSegments());
assertEquals(MEDIA_PLAYLIST_DATA.length + 10 + 11 + 12, newHlsDownloader.getDownloadedBytes());
assertThat(newHlsDownloader.getTotalSegments()).isEqualTo(4);
assertThat(newHlsDownloader.getDownloadedSegments()).isEqualTo(4);
assertThat(newHlsDownloader.getDownloadedBytes())
.isEqualTo(MEDIA_PLAYLIST_DATA.length + 10 + 11 + 12);
}
public void testDownloadRepresentation() throws Exception {
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.source.hls.playlist;
import static com.google.common.truth.Truth.assertThat;
import android.net.Uri;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
......@@ -23,7 +25,6 @@ import com.google.android.exoplayer2.util.MimeTypes;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.List;
import junit.framework.TestCase;
......@@ -89,43 +90,43 @@ public class HlsMasterPlaylistParserTest extends TestCase {
+ "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"aud2\",LANGUAGE=\"en\",NAME=\"English\","
+ "AUTOSELECT=YES,DEFAULT=YES,CHANNELS=\"6\",URI=\"a2/prog_index.m3u8\"\n";
public void testParseMasterPlaylist() throws IOException{
public void testParseMasterPlaylist() throws IOException {
HlsMasterPlaylist masterPlaylist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_SIMPLE);
List<HlsMasterPlaylist.HlsUrl> variants = masterPlaylist.variants;
assertEquals(5, variants.size());
assertNull(masterPlaylist.muxedCaptionFormats);
assertEquals(1280000, variants.get(0).format.bitrate);
assertEquals("mp4a.40.2,avc1.66.30", variants.get(0).format.codecs);
assertEquals(304, variants.get(0).format.width);
assertEquals(128, variants.get(0).format.height);
assertEquals("http://example.com/low.m3u8", variants.get(0).url);
assertEquals(1280000, variants.get(1).format.bitrate);
assertEquals("mp4a.40.2 , avc1.66.30 ", variants.get(1).format.codecs);
assertEquals("http://example.com/spaces_in_codecs.m3u8", variants.get(1).url);
assertEquals(2560000, variants.get(2).format.bitrate);
assertNull(variants.get(2).format.codecs);
assertEquals(384, variants.get(2).format.width);
assertEquals(160, variants.get(2).format.height);
assertEquals(25.0f, variants.get(2).format.frameRate);
assertEquals("http://example.com/mid.m3u8", variants.get(2).url);
assertEquals(7680000, variants.get(3).format.bitrate);
assertNull(variants.get(3).format.codecs);
assertEquals(Format.NO_VALUE, variants.get(3).format.width);
assertEquals(Format.NO_VALUE, variants.get(3).format.height);
assertEquals(29.997f, variants.get(3).format.frameRate);
assertEquals("http://example.com/hi.m3u8", variants.get(3).url);
assertEquals(65000, variants.get(4).format.bitrate);
assertEquals("mp4a.40.5", variants.get(4).format.codecs);
assertEquals(Format.NO_VALUE, variants.get(4).format.width);
assertEquals(Format.NO_VALUE, variants.get(4).format.height);
assertEquals((float) Format.NO_VALUE, variants.get(4).format.frameRate);
assertEquals("http://example.com/audio-only.m3u8", variants.get(4).url);
assertThat(variants).hasSize(5);
assertThat(masterPlaylist.muxedCaptionFormats).isNull();
assertThat(variants.get(0).format.bitrate).isEqualTo(1280000);
assertThat(variants.get(0).format.codecs).isEqualTo("mp4a.40.2,avc1.66.30");
assertThat(variants.get(0).format.width).isEqualTo(304);
assertThat(variants.get(0).format.height).isEqualTo(128);
assertThat(variants.get(0).url).isEqualTo("http://example.com/low.m3u8");
assertThat(variants.get(1).format.bitrate).isEqualTo(1280000);
assertThat(variants.get(1).format.codecs).isEqualTo("mp4a.40.2 , avc1.66.30 ");
assertThat(variants.get(1).url).isEqualTo("http://example.com/spaces_in_codecs.m3u8");
assertThat(variants.get(2).format.bitrate).isEqualTo(2560000);
assertThat(variants.get(2).format.codecs).isNull();
assertThat(variants.get(2).format.width).isEqualTo(384);
assertThat(variants.get(2).format.height).isEqualTo(160);
assertThat(variants.get(2).format.frameRate).isEqualTo(25.0f);
assertThat(variants.get(2).url).isEqualTo("http://example.com/mid.m3u8");
assertThat(variants.get(3).format.bitrate).isEqualTo(7680000);
assertThat(variants.get(3).format.codecs).isNull();
assertThat(variants.get(3).format.width).isEqualTo(Format.NO_VALUE);
assertThat(variants.get(3).format.height).isEqualTo(Format.NO_VALUE);
assertThat(variants.get(3).format.frameRate).isEqualTo(29.997f);
assertThat(variants.get(3).url).isEqualTo("http://example.com/hi.m3u8");
assertThat(variants.get(4).format.bitrate).isEqualTo(65000);
assertThat(variants.get(4).format.codecs).isEqualTo("mp4a.40.5");
assertThat(variants.get(4).format.width).isEqualTo(Format.NO_VALUE);
assertThat(variants.get(4).format.height).isEqualTo(Format.NO_VALUE);
assertThat(variants.get(4).format.frameRate).isEqualTo((float) Format.NO_VALUE);
assertThat(variants.get(4).url).isEqualTo("http://example.com/audio-only.m3u8");
}
public void testMasterPlaylistWithBandwdithAverage() throws IOException {
......@@ -134,8 +135,8 @@ public class HlsMasterPlaylistParserTest extends TestCase {
List<HlsMasterPlaylist.HlsUrl> variants = masterPlaylist.variants;
assertEquals(1280000, variants.get(0).format.bitrate);
assertEquals(1270000, variants.get(1).format.bitrate);
assertThat(variants.get(0).format.bitrate).isEqualTo(1280000);
assertThat(variants.get(1).format.bitrate).isEqualTo(1270000);
}
public void testPlaylistWithInvalidHeader() throws IOException {
......@@ -149,28 +150,28 @@ public class HlsMasterPlaylistParserTest extends TestCase {
public void testPlaylistWithClosedCaption() throws IOException {
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITH_CC);
assertEquals(1, playlist.muxedCaptionFormats.size());
assertThat(playlist.muxedCaptionFormats).hasSize(1);
Format closedCaptionFormat = playlist.muxedCaptionFormats.get(0);
assertEquals(MimeTypes.APPLICATION_CEA708, closedCaptionFormat.sampleMimeType);
assertEquals(4, closedCaptionFormat.accessibilityChannel);
assertEquals("es", closedCaptionFormat.language);
assertThat(closedCaptionFormat.sampleMimeType).isEqualTo(MimeTypes.APPLICATION_CEA708);
assertThat(closedCaptionFormat.accessibilityChannel).isEqualTo(4);
assertThat(closedCaptionFormat.language).isEqualTo("es");
}
public void testPlaylistWithoutClosedCaptions() throws IOException {
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITHOUT_CC);
assertEquals(Collections.emptyList(), playlist.muxedCaptionFormats);
assertThat(playlist.muxedCaptionFormats).isEmpty();
}
public void testCodecPropagation() throws IOException {
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITH_AUDIO_MEDIA_TAG);
Format firstAudioFormat = playlist.audios.get(0).format;
assertEquals("mp4a.40.2", firstAudioFormat.codecs);
assertEquals(MimeTypes.AUDIO_AAC, firstAudioFormat.sampleMimeType);
assertThat(firstAudioFormat.codecs).isEqualTo("mp4a.40.2");
assertThat(firstAudioFormat.sampleMimeType).isEqualTo(MimeTypes.AUDIO_AAC);
Format secondAudioFormat = playlist.audios.get(1).format;
assertEquals("ac-3", secondAudioFormat.codecs);
assertEquals(MimeTypes.AUDIO_AC3, secondAudioFormat.sampleMimeType);
assertThat(secondAudioFormat.codecs).isEqualTo("ac-3");
assertThat(secondAudioFormat.sampleMimeType).isEqualTo(MimeTypes.AUDIO_AC3);
}
private static HlsMasterPlaylist parseMasterPlaylist(String uri, String playlistString)
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.source.hls.playlist;
import static com.google.common.truth.Truth.assertThat;
import android.net.Uri;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment;
......@@ -69,67 +71,71 @@ public class HlsMediaPlaylistParserTest extends TestCase {
playlistString.getBytes(Charset.forName(C.UTF8_NAME)));
try {
HlsPlaylist playlist = new HlsPlaylistParser().parse(playlistUri, inputStream);
assertNotNull(playlist);
assertThat(playlist).isNotNull();
HlsMediaPlaylist mediaPlaylist = (HlsMediaPlaylist) playlist;
assertEquals(HlsMediaPlaylist.PLAYLIST_TYPE_VOD, mediaPlaylist.playlistType);
assertEquals(mediaPlaylist.durationUs - 25000000, mediaPlaylist.startOffsetUs);
assertThat(mediaPlaylist.playlistType).isEqualTo(HlsMediaPlaylist.PLAYLIST_TYPE_VOD);
assertThat(mediaPlaylist.startOffsetUs).isEqualTo(mediaPlaylist.durationUs - 25000000);
assertEquals(2679, mediaPlaylist.mediaSequence);
assertEquals(3, mediaPlaylist.version);
assertTrue(mediaPlaylist.hasEndTag);
assertThat(mediaPlaylist.mediaSequence).isEqualTo(2679);
assertThat(mediaPlaylist.version).isEqualTo(3);
assertThat(mediaPlaylist.hasEndTag).isTrue();
List<Segment> segments = mediaPlaylist.segments;
assertNotNull(segments);
assertEquals(5, segments.size());
assertThat(segments).isNotNull();
assertThat(segments).hasSize(5);
Segment segment = segments.get(0);
assertEquals(4, mediaPlaylist.discontinuitySequence + segment.relativeDiscontinuitySequence);
assertEquals(7975000, segment.durationUs);
assertNull(segment.fullSegmentEncryptionKeyUri);
assertNull(segment.encryptionIV);
assertEquals(51370, segment.byterangeLength);
assertEquals(0, segment.byterangeOffset);
assertEquals("https://priv.example.com/fileSequence2679.ts", segment.url);
assertThat(mediaPlaylist.discontinuitySequence + segment.relativeDiscontinuitySequence)
.isEqualTo(4);
assertThat(segment.durationUs).isEqualTo(7975000);
assertThat(segment.fullSegmentEncryptionKeyUri).isNull();
assertThat(segment.encryptionIV).isNull();
assertThat(segment.byterangeLength).isEqualTo(51370);
assertThat(segment.byterangeOffset).isEqualTo(0);
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2679.ts");
segment = segments.get(1);
assertEquals(0, segment.relativeDiscontinuitySequence);
assertEquals(7975000, segment.durationUs);
assertEquals("https://priv.example.com/key.php?r=2680", segment.fullSegmentEncryptionKeyUri);
assertEquals("0x1566B", segment.encryptionIV);
assertEquals(51501, segment.byterangeLength);
assertEquals(2147483648L, segment.byterangeOffset);
assertEquals("https://priv.example.com/fileSequence2680.ts", segment.url);
assertThat(segment.relativeDiscontinuitySequence).isEqualTo(0);
assertThat(segment.durationUs).isEqualTo(7975000);
assertThat(segment.fullSegmentEncryptionKeyUri)
.isEqualTo("https://priv.example.com/key.php?r=2680");
assertThat(segment.encryptionIV).isEqualTo("0x1566B");
assertThat(segment.byterangeLength).isEqualTo(51501);
assertThat(segment.byterangeOffset).isEqualTo(2147483648L);
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2680.ts");
segment = segments.get(2);
assertEquals(0, segment.relativeDiscontinuitySequence);
assertEquals(7941000, segment.durationUs);
assertNull(segment.fullSegmentEncryptionKeyUri);
assertEquals(null, segment.encryptionIV);
assertEquals(51501, segment.byterangeLength);
assertEquals(2147535149L, segment.byterangeOffset);
assertEquals("https://priv.example.com/fileSequence2681.ts", segment.url);
assertThat(segment.relativeDiscontinuitySequence).isEqualTo(0);
assertThat(segment.durationUs).isEqualTo(7941000);
assertThat(segment.fullSegmentEncryptionKeyUri).isNull();
assertThat(segment.encryptionIV).isEqualTo(null);
assertThat(segment.byterangeLength).isEqualTo(51501);
assertThat(segment.byterangeOffset).isEqualTo(2147535149L);
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2681.ts");
segment = segments.get(3);
assertEquals(1, segment.relativeDiscontinuitySequence);
assertEquals(7975000, segment.durationUs);
assertEquals("https://priv.example.com/key.php?r=2682", segment.fullSegmentEncryptionKeyUri);
assertThat(segment.relativeDiscontinuitySequence).isEqualTo(1);
assertThat(segment.durationUs).isEqualTo(7975000);
assertThat(segment.fullSegmentEncryptionKeyUri)
.isEqualTo("https://priv.example.com/key.php?r=2682");
// 0xA7A == 2682.
assertNotNull(segment.encryptionIV);
assertEquals("A7A", segment.encryptionIV.toUpperCase(Locale.getDefault()));
assertEquals(51740, segment.byterangeLength);
assertEquals(2147586650L, segment.byterangeOffset);
assertEquals("https://priv.example.com/fileSequence2682.ts", segment.url);
assertThat(segment.encryptionIV).isNotNull();
assertThat(segment.encryptionIV.toUpperCase(Locale.getDefault())).isEqualTo("A7A");
assertThat(segment.byterangeLength).isEqualTo(51740);
assertThat(segment.byterangeOffset).isEqualTo(2147586650L);
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2682.ts");
segment = segments.get(4);
assertEquals(1, segment.relativeDiscontinuitySequence);
assertEquals(7975000, segment.durationUs);
assertEquals("https://priv.example.com/key.php?r=2682", segment.fullSegmentEncryptionKeyUri);
assertThat(segment.relativeDiscontinuitySequence).isEqualTo(1);
assertThat(segment.durationUs).isEqualTo(7975000);
assertThat(segment.fullSegmentEncryptionKeyUri)
.isEqualTo("https://priv.example.com/key.php?r=2682");
// 0xA7B == 2683.
assertNotNull(segment.encryptionIV);
assertEquals("A7B", segment.encryptionIV.toUpperCase(Locale.getDefault()));
assertEquals(C.LENGTH_UNSET, segment.byterangeLength);
assertEquals(0, segment.byterangeOffset);
assertEquals("https://priv.example.com/fileSequence2683.ts", segment.url);
assertThat(segment.encryptionIV).isNotNull();
assertThat(segment.encryptionIV.toUpperCase(Locale.getDefault())).isEqualTo("A7B");
assertThat(segment.byterangeLength).isEqualTo(C.LENGTH_UNSET);
assertThat(segment.byterangeOffset).isEqualTo(0);
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2683.ts");
} catch (IOException exception) {
fail(exception.getMessage());
}
......
......@@ -15,7 +15,8 @@
*/
package com.google.android.exoplayer2.source.smoothstreaming.manifest;
import android.test.MoreAsserts;
import static com.google.common.truth.Truth.assertThat;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.ProtectionElement;
......@@ -75,28 +76,28 @@ public class SsManifestTest extends TestCase {
}
private static void assertManifestEquals(SsManifest expected, SsManifest actual) {
assertEquals(expected.durationUs, actual.durationUs);
assertEquals(expected.dvrWindowLengthUs, actual.dvrWindowLengthUs);
assertEquals(expected.isLive, actual.isLive);
assertEquals(expected.lookAheadCount, actual.lookAheadCount);
assertEquals(expected.majorVersion, actual.majorVersion);
assertEquals(expected.minorVersion, actual.minorVersion);
assertEquals(expected.protectionElement.uuid, actual.protectionElement.uuid);
assertEquals(expected.protectionElement, actual.protectionElement);
assertThat(actual.durationUs).isEqualTo(expected.durationUs);
assertThat(actual.dvrWindowLengthUs).isEqualTo(expected.dvrWindowLengthUs);
assertThat(actual.isLive).isEqualTo(expected.isLive);
assertThat(actual.lookAheadCount).isEqualTo(expected.lookAheadCount);
assertThat(actual.majorVersion).isEqualTo(expected.majorVersion);
assertThat(actual.minorVersion).isEqualTo(expected.minorVersion);
assertThat(actual.protectionElement.uuid).isEqualTo(expected.protectionElement.uuid);
assertThat(actual.protectionElement).isEqualTo(expected.protectionElement);
for (int i = 0; i < expected.streamElements.length; i++) {
StreamElement expectedStreamElement = expected.streamElements[i];
StreamElement actualStreamElement = actual.streamElements[i];
assertEquals(expectedStreamElement.chunkCount, actualStreamElement.chunkCount);
assertEquals(expectedStreamElement.displayHeight, actualStreamElement.displayHeight);
assertEquals(expectedStreamElement.displayWidth, actualStreamElement.displayWidth);
assertEquals(expectedStreamElement.language, actualStreamElement.language);
assertEquals(expectedStreamElement.maxHeight, actualStreamElement.maxHeight);
assertEquals(expectedStreamElement.maxWidth, actualStreamElement.maxWidth);
assertEquals(expectedStreamElement.name, actualStreamElement.name);
assertEquals(expectedStreamElement.subType, actualStreamElement.subType);
assertEquals(expectedStreamElement.timescale, actualStreamElement.timescale);
assertEquals(expectedStreamElement.type, actualStreamElement.type);
MoreAsserts.assertEquals(expectedStreamElement.formats, actualStreamElement.formats);
assertThat(actualStreamElement.chunkCount).isEqualTo(expectedStreamElement.chunkCount);
assertThat(actualStreamElement.displayHeight).isEqualTo(expectedStreamElement.displayHeight);
assertThat(actualStreamElement.displayWidth).isEqualTo(expectedStreamElement.displayWidth);
assertThat(actualStreamElement.language).isEqualTo(expectedStreamElement.language);
assertThat(actualStreamElement.maxHeight).isEqualTo(expectedStreamElement.maxHeight);
assertThat(actualStreamElement.maxWidth).isEqualTo(expectedStreamElement.maxWidth);
assertThat(actualStreamElement.name).isEqualTo(expectedStreamElement.name);
assertThat(actualStreamElement.subType).isEqualTo(expectedStreamElement.subType);
assertThat(actualStreamElement.timescale).isEqualTo(expectedStreamElement.timescale);
assertThat(actualStreamElement.type).isEqualTo(expectedStreamElement.type);
assertThat(actualStreamElement.formats).isEqualTo(expectedStreamElement.formats);
}
}
......
......@@ -15,6 +15,9 @@
*/
package com.google.android.exoplayer2.playbacktests.gts;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import android.net.Uri;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
......@@ -89,15 +92,16 @@ public final class DashDownloadTest extends ActivityInstrumentationTestCase2<Hos
// Download representations
DashDownloader dashDownloader = downloadContent(false, Float.NaN);
assertEquals(cache.getCacheSpace() - manifestLength, dashDownloader.getDownloadedBytes());
assertThat(dashDownloader.getDownloadedBytes())
.isEqualTo(cache.getCacheSpace() - manifestLength);
testRunner.setStreamName("test_h264_fixed_download").
setDataSourceFactory(newOfflineCacheDataSourceFactory()).run();
dashDownloader.remove();
assertEquals("There should be no content left.", 0, cache.getKeys().size());
assertEquals("There should be no content left.", 0, cache.getCacheSpace());
assertWithMessage("There should be no content left.").that(cache.getKeys().size()).isEqualTo(0);
assertWithMessage("There should be no content left.").that(cache.getCacheSpace()).isEqualTo(0);
}
public void testPartialDownload() throws Exception {
......@@ -114,7 +118,7 @@ public final class DashDownloadTest extends ActivityInstrumentationTestCase2<Hos
// Make sure it doesn't download any data
dashDownloader = downloadContent(true, Float.NaN);
assertEquals(downloadedBytes, dashDownloader.getDownloadedBytes());
assertThat(dashDownloader.getDownloadedBytes()).isEqualTo(downloadedBytes);
testRunner.setStreamName("test_h264_fixed_partial_download")
.setDataSourceFactory(newOfflineCacheDataSourceFactory()).run();
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.playbacktests.gts;
import static com.google.common.truth.Truth.assertThat;
import android.test.ActivityInstrumentationTestCase2;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.Player;
......@@ -603,8 +605,8 @@ public final class DashStreamingTest extends ActivityInstrumentationTestCase2<Ho
return;
}
MediaCodecInfo decoderInfo = MediaCodecUtil.getDecoderInfo(MimeTypes.VIDEO_H264, false);
assertNotNull(decoderInfo);
assertTrue(Util.SDK_INT < 21 || decoderInfo.adaptive);
assertThat(decoderInfo).isNotNull();
assertThat(Util.SDK_INT < 21 || decoderInfo.adaptive).isTrue();
}
public void testDecoderInfoH265V24() throws DecoderQueryException {
......@@ -612,7 +614,7 @@ public final class DashStreamingTest extends ActivityInstrumentationTestCase2<Ho
// Pass.
return;
}
assertTrue(MediaCodecUtil.getDecoderInfo(MimeTypes.VIDEO_H265, false).adaptive);
assertThat(MediaCodecUtil.getDecoderInfo(MimeTypes.VIDEO_H265, false).adaptive).isTrue();
}
public void testDecoderInfoVP9V24() throws DecoderQueryException {
......@@ -620,7 +622,7 @@ public final class DashStreamingTest extends ActivityInstrumentationTestCase2<Ho
// Pass.
return;
}
assertTrue(MediaCodecUtil.getDecoderInfo(MimeTypes.VIDEO_VP9, false).adaptive);
assertThat(MediaCodecUtil.getDecoderInfo(MimeTypes.VIDEO_VP9, false).adaptive).isTrue();
}
// Internal.
......
......@@ -64,7 +64,6 @@ import com.google.android.exoplayer2.util.Util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import junit.framework.AssertionFailedError;
/** {@link DashHostedTest} builder. */
public final class DashTestRunner {
......@@ -362,7 +361,7 @@ public final class DashTestRunner {
// Assert that consecutive dropped frames were within limit.
DecoderCountersUtil.assertConsecutiveDroppedBufferLimit(tag + VIDEO_TAG_SUFFIX,
videoCounters, MAX_CONSECUTIVE_DROPPED_VIDEO_FRAMES);
} catch (AssertionFailedError e) {
} catch (AssertionError e) {
if (trackSelector.includedAdditionalVideoFormats) {
// Retry limiting to CDD mandated formats (b/28220076).
Log.e(tag, "Too many dropped or consecutive dropped frames.", e);
......
......@@ -15,6 +15,9 @@
*/
package com.google.android.exoplayer2.playbacktests.gts;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import android.media.MediaDrm.MediaDrmStateException;
import android.net.Uri;
import android.test.ActivityInstrumentationTestCase2;
......@@ -33,7 +36,6 @@ import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException;
import junit.framework.Assert;
/**
* Tests Widevine encrypted DASH playbacks using offline keys.
......@@ -98,7 +100,7 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa
// Renew license after playback should still work
offlineLicenseKeySetId = offlineLicenseHelper.renewLicense(offlineLicenseKeySetId);
Assert.assertNotNull(offlineLicenseKeySetId);
assertThat(offlineLicenseKeySetId).isNotNull();
}
public void testWidevineOfflineReleasedLicenseV22() throws Throwable {
......@@ -136,8 +138,10 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa
// Wait until the license expires
long licenseDuration =
offlineLicenseHelper.getLicenseDurationRemainingSec(offlineLicenseKeySetId).first;
assertTrue("License duration should be less than 30 sec. "
+ "Server settings might have changed.", licenseDuration < 30);
assertWithMessage(
"License duration should be less than 30 sec. " + "Server settings might have changed.")
.that(licenseDuration < 30)
.isTrue();
while (licenseDuration > 0) {
synchronized (this) {
wait(licenseDuration * 1000 + 2000);
......@@ -145,7 +149,9 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa
long previousDuration = licenseDuration;
licenseDuration =
offlineLicenseHelper.getLicenseDurationRemainingSec(offlineLicenseKeySetId).first;
assertTrue("License duration should be decreasing.", previousDuration > licenseDuration);
assertWithMessage("License duration should be decreasing.")
.that(previousDuration > licenseDuration)
.isTrue();
}
// DefaultDrmSessionManager should renew the license and stream play fine
......@@ -162,8 +168,10 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa
Pair<Long, Long> licenseDurationRemainingSec =
offlineLicenseHelper.getLicenseDurationRemainingSec(offlineLicenseKeySetId);
long licenseDuration = licenseDurationRemainingSec.first;
assertTrue("License duration should be less than 30 sec. "
+ "Server settings might have changed.", licenseDuration < 30);
assertWithMessage(
"License duration should be less than 30 sec. " + "Server settings might have changed.")
.that(licenseDuration < 30)
.isTrue();
ActionSchedule schedule = new ActionSchedule.Builder(TAG)
.waitForPlaybackState(Player.STATE_READY)
.delay(3000).pause().delay(licenseDuration * 1000 + 2000).play().build();
......@@ -178,8 +186,8 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa
Uri.parse(DashTestData.WIDEVINE_H264_MANIFEST));
DrmInitData drmInitData = DashUtil.loadDrmInitData(dataSource, dashManifest.getPeriod(0));
offlineLicenseKeySetId = offlineLicenseHelper.downloadLicense(drmInitData);
Assert.assertNotNull(offlineLicenseKeySetId);
Assert.assertTrue(offlineLicenseKeySetId.length > 0);
assertThat(offlineLicenseKeySetId).isNotNull();
assertThat(offlineLicenseKeySetId.length).isGreaterThan(0);
testRunner.setOfflineLicenseKeySetId(offlineLicenseKeySetId);
}
......
......@@ -27,4 +27,5 @@ android {
dependencies {
compile project(modulePrefix + 'library-core')
compile 'org.mockito:mockito-core:' + mockitoVersion
compile 'com.google.truth:truth:' + truthVersion
}
......@@ -15,11 +15,10 @@
*/
package com.google.android.exoplayer2.testutil;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import android.net.Uri;
import android.test.MoreAsserts;
import com.google.android.exoplayer2.testutil.FakeDataSet.FakeData;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DataSpec;
......@@ -76,7 +75,7 @@ public final class CacheAsserts {
assertDataCached(cache, uri, data);
totalLength += data.length;
}
assertEquals(totalLength, cache.getCacheSpace());
assertThat(cache.getCacheSpace()).isEqualTo(totalLength);
}
/**
......@@ -112,8 +111,9 @@ public final class CacheAsserts {
dataSource.open(dataSpec);
try {
byte[] bytes = TestUtil.readToEnd(dataSource);
MoreAsserts.assertEquals(
"Cached data doesn't match expected for '" + dataSpec.uri + "',", expected, bytes);
assertWithMessage("Cached data doesn't match expected for '" + dataSpec.uri + "',")
.that(bytes)
.isEqualTo(expected);
} finally {
dataSource.close();
}
......@@ -122,15 +122,15 @@ public final class CacheAsserts {
/** Asserts that there is no cache content for the given {@code uriStrings}. */
public static void assertDataNotCached(Cache cache, String... uriStrings) {
for (String uriString : uriStrings) {
assertTrue(
"There is cached data for '" + uriString + "',",
cache.getCachedSpans(CacheUtil.generateKey(Uri.parse(uriString))).isEmpty());
assertWithMessage("There is cached data for '" + uriString + "',")
.that(cache.getCachedSpans(CacheUtil.generateKey(Uri.parse(uriString))).isEmpty())
.isTrue();
}
}
/** Asserts that the cache is empty. */
public static void assertCacheEmpty(Cache cache) {
assertEquals(0, cache.getCacheSpace());
assertThat(cache.getCacheSpace()).isEqualTo(0);
}
private CacheAsserts() {}
......
......@@ -15,8 +15,9 @@
*/
package com.google.android.exoplayer2.testutil;
import static com.google.common.truth.Truth.assertWithMessage;
import com.google.android.exoplayer2.decoder.DecoderCounters;
import junit.framework.TestCase;
/**
* Assertions for {@link DecoderCounters}.
......@@ -41,30 +42,60 @@ public final class DecoderCountersUtil {
int expected) {
counters.ensureUpdated();
int actual = counters.skippedOutputBufferCount;
TestCase.assertEquals("Codec(" + name + ") skipped " + actual + " buffers. Expected "
+ expected + ".", expected, actual);
assertWithMessage(
"Codec(" + name + ") skipped " + actual + " buffers. Expected " + expected + ".")
.that(actual)
.isEqualTo(expected);
}
public static void assertTotalBufferCount(String name, DecoderCounters counters, int minCount,
int maxCount) {
int actual = getTotalBufferCount(counters);
TestCase.assertTrue("Codec(" + name + ") output " + actual + " buffers. Expected in range ["
+ minCount + ", " + maxCount + "].", minCount <= actual && actual <= maxCount);
assertWithMessage(
"Codec("
+ name
+ ") output "
+ actual
+ " buffers. Expected in range ["
+ minCount
+ ", "
+ maxCount
+ "].")
.that(minCount <= actual && actual <= maxCount)
.isTrue();
}
public static void assertDroppedBufferLimit(String name, DecoderCounters counters, int limit) {
counters.ensureUpdated();
int actual = counters.droppedBufferCount;
TestCase.assertTrue("Codec(" + name + ") was late decoding: " + actual + " buffers. "
+ "Limit: " + limit + ".", actual <= limit);
assertWithMessage(
"Codec("
+ name
+ ") was late decoding: "
+ actual
+ " buffers. "
+ "Limit: "
+ limit
+ ".")
.that(actual)
.isAtMost(limit);
}
public static void assertConsecutiveDroppedBufferLimit(String name, DecoderCounters counters,
int limit) {
counters.ensureUpdated();
int actual = counters.maxConsecutiveDroppedBufferCount;
TestCase.assertTrue("Codec(" + name + ") was late decoding: " + actual
+ " buffers consecutively. " + "Limit: " + limit + ".", actual <= limit);
assertWithMessage(
"Codec("
+ name
+ ") was late decoding: "
+ actual
+ " buffers consecutively. "
+ "Limit: "
+ limit
+ ".")
.that(actual)
.isAtMost(limit);
}
}
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.testutil;
import static com.google.common.truth.Truth.assertWithMessage;
import android.os.ConditionVariable;
import android.os.Looper;
import android.os.SystemClock;
......@@ -46,7 +48,6 @@ import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.util.HandlerWrapper;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoRendererEventListener;
import junit.framework.Assert;
/**
* A {@link HostedTest} for {@link ExoPlayer} playback tests.
......@@ -219,9 +220,12 @@ public abstract class ExoHostedTest extends Player.DefaultEventListener implemen
// Assert that the playback spanned the correct duration of time.
long minAllowedActualPlayingTimeMs = playingTimeToAssertMs - MAX_PLAYING_TIME_DISCREPANCY_MS;
long maxAllowedActualPlayingTimeMs = playingTimeToAssertMs + MAX_PLAYING_TIME_DISCREPANCY_MS;
Assert.assertTrue("Total playing time: " + totalPlayingTimeMs + ". Expected: "
+ playingTimeToAssertMs, minAllowedActualPlayingTimeMs <= totalPlayingTimeMs
&& totalPlayingTimeMs <= maxAllowedActualPlayingTimeMs);
assertWithMessage(
"Total playing time: " + totalPlayingTimeMs + ". Expected: " + playingTimeToAssertMs)
.that(
minAllowedActualPlayingTimeMs <= totalPlayingTimeMs
&& totalPlayingTimeMs <= maxAllowedActualPlayingTimeMs)
.isTrue();
}
// Make any additional assertions.
assertPassed(audioDecoderCounters, videoDecoderCounters);
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.testutil;
import static com.google.common.truth.Truth.assertThat;
import android.os.HandlerThread;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.DefaultLoadControl;
......@@ -22,7 +24,6 @@ import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.LoadControl;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Player.DiscontinuityReason;
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.RenderersFactory;
import com.google.android.exoplayer2.SimpleExoPlayer;
......@@ -41,10 +42,10 @@ import com.google.android.exoplayer2.util.HandlerWrapper;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.video.VideoRendererEventListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import junit.framework.Assert;
/**
* Helper class to run an ExoPlayer test.
......@@ -97,7 +98,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
* @return This builder.
*/
public Builder setTimeline(Timeline timeline) {
Assert.assertNull(mediaSource);
assertThat(mediaSource).isNull();
this.timeline = timeline;
return this;
}
......@@ -111,7 +112,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
* @return This builder.
*/
public Builder setManifest(Object manifest) {
Assert.assertNull(mediaSource);
assertThat(mediaSource).isNull();
this.manifest = manifest;
return this;
}
......@@ -127,8 +128,8 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
* @return This builder.
*/
public Builder setMediaSource(MediaSource mediaSource) {
Assert.assertNull(timeline);
Assert.assertNull(manifest);
assertThat(timeline).isNull();
assertThat(manifest).isNull();
this.mediaSource = mediaSource;
return this;
}
......@@ -182,7 +183,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
* @return This builder.
*/
public Builder setRenderers(Renderer... renderers) {
Assert.assertNull(renderersFactory);
assertThat(renderersFactory).isNull();
this.renderers = renderers;
return this;
}
......@@ -196,7 +197,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
* @return This builder.
*/
public Builder setRenderersFactory(RenderersFactory renderersFactory) {
Assert.assertNull(renderers);
assertThat(renderers).isNull();
this.renderersFactory = renderersFactory;
return this;
}
......@@ -478,10 +479,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
* @param timelines A list of expected {@link Timeline}s.
*/
public void assertTimelinesEqual(Timeline... timelines) {
Assert.assertEquals(timelines.length, this.timelines.size());
for (int i = 0; i < timelines.length; i++) {
Assert.assertEquals(timelines[i], this.timelines.get(i));
}
assertThat(this.timelines).containsExactlyElementsIn(Arrays.asList(timelines)).inOrder();
}
/**
......@@ -492,22 +490,16 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
* @param manifests A list of expected manifests.
*/
public void assertManifestsEqual(Object... manifests) {
Assert.assertEquals(manifests.length, this.manifests.size());
for (int i = 0; i < manifests.length; i++) {
Assert.assertEquals(manifests[i], this.manifests.get(i));
}
assertThat(this.manifests).containsExactlyElementsIn(Arrays.asList(manifests)).inOrder();
}
/**
* Asserts that the timeline change reasons reported by
* {@link Player.EventListener#onTimelineChanged(Timeline, Object, int)} are equal to the provided
* Asserts that the timeline change reasons reported by {@link
* Player.EventListener#onTimelineChanged(Timeline, Object, int)} are equal to the provided
* timeline change reasons.
*/
public void assertTimelineChangeReasonsEqual(@Player.TimelineChangeReason int... reasons) {
Assert.assertEquals(reasons.length, timelineChangeReasons.size());
for (int i = 0; i < reasons.length; i++) {
Assert.assertEquals(reasons[i], (int) timelineChangeReasons.get(i));
}
public void assertTimelineChangeReasonsEqual(Integer... reasons) {
assertThat(timelineChangeReasons).containsExactlyElementsIn(Arrays.asList(reasons)).inOrder();
}
/**
......@@ -518,28 +510,26 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
* @param trackGroupArray The expected {@link TrackGroupArray}.
*/
public void assertTrackGroupsEqual(TrackGroupArray trackGroupArray) {
Assert.assertEquals(trackGroupArray, this.trackGroups);
assertThat(this.trackGroups).isEqualTo(trackGroupArray);
}
/**
* Asserts that {@link Player.EventListener#onPositionDiscontinuity(int)} was not called.
*/
public void assertNoPositionDiscontinuities() {
Assert.assertTrue(discontinuityReasons.isEmpty());
assertThat(discontinuityReasons).isEmpty();
}
/**
* Asserts that the discontinuity reasons reported by
* {@link Player.EventListener#onPositionDiscontinuity(int)} are equal to the provided values.
* Asserts that the discontinuity reasons reported by {@link
* Player.EventListener#onPositionDiscontinuity(int)} are equal to the provided values.
*
* @param discontinuityReasons The expected discontinuity reasons.
*/
public void assertPositionDiscontinuityReasonsEqual(
@DiscontinuityReason int... discontinuityReasons) {
Assert.assertEquals(discontinuityReasons.length, this.discontinuityReasons.size());
for (int i = 0; i < discontinuityReasons.length; i++) {
Assert.assertEquals(discontinuityReasons[i], (int) this.discontinuityReasons.get(i));
}
public void assertPositionDiscontinuityReasonsEqual(Integer... discontinuityReasons) {
assertThat(this.discontinuityReasons)
.containsExactlyElementsIn(Arrays.asList(discontinuityReasons))
.inOrder();
}
/**
......@@ -550,11 +540,10 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
*
* @param periodIndices A list of expected period indices.
*/
public void assertPlayedPeriodIndices(int... periodIndices) {
Assert.assertEquals(periodIndices.length, this.periodIndices.size());
for (int i = 0; i < periodIndices.length; i++) {
Assert.assertEquals(periodIndices[i], (int) this.periodIndices.get(i));
}
public void assertPlayedPeriodIndices(Integer... periodIndices) {
assertThat(this.periodIndices)
.containsExactlyElementsIn(Arrays.asList(periodIndices))
.inOrder();
}
// Private implementation details.
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.testutil;
import static com.google.common.truth.Truth.assertThat;
import android.app.Instrumentation;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.extractor.Extractor;
......@@ -26,7 +28,6 @@ import com.google.android.exoplayer2.testutil.FakeExtractorInput.SimulatedIOExce
import com.google.android.exoplayer2.util.Assertions;
import java.io.IOException;
import java.util.Arrays;
import junit.framework.Assert;
/**
* Assertion methods for {@link Extractor}.
......@@ -126,7 +127,7 @@ public final class ExtractorAsserts {
.setSimulatePartialReads(simulatePartialReads).build();
if (sniffFirst) {
Assert.assertTrue(TestUtil.sniffTestData(extractor, input));
assertThat(TestUtil.sniffTestData(extractor, input)).isTrue();
input.resetPeekPosition();
}
......
......@@ -15,12 +15,13 @@
*/
package com.google.android.exoplayer2.testutil;
import static com.google.common.truth.Truth.assertThat;
import android.util.SparseBooleanArray;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.extractor.ExtractorInput;
import java.io.EOFException;
import java.io.IOException;
import junit.framework.Assert;
/**
* A fake {@link ExtractorInput} capable of simulating various scenarios.
......@@ -84,7 +85,7 @@ public final class FakeExtractorInput implements ExtractorInput {
* @param position The position to set.
*/
public void setPosition(int position) {
Assert.assertTrue(0 <= position && position <= data.length);
assertThat(0 <= position && position <= data.length).isTrue();
readPosition = position;
peekPosition = position;
}
......@@ -180,7 +181,7 @@ public final class FakeExtractorInput implements ExtractorInput {
@Override
public <E extends Throwable> void setRetryPosition(long position, E e) throws E {
Assert.assertTrue(position >= 0);
assertThat(position >= 0).isTrue();
readPosition = (int) position;
throw e;
}
......
......@@ -15,6 +15,9 @@
*/
package com.google.android.exoplayer2.testutil;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import android.app.Instrumentation;
import android.util.SparseArray;
import com.google.android.exoplayer2.extractor.ExtractorOutput;
......@@ -22,7 +25,6 @@ import com.google.android.exoplayer2.extractor.SeekMap;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import junit.framework.Assert;
/**
* A fake {@link ExtractorOutput}.
......@@ -50,7 +52,7 @@ public final class FakeExtractorOutput implements ExtractorOutput, Dumper.Dumpab
public FakeTrackOutput track(int id, int type) {
FakeTrackOutput output = trackOutputs.get(id);
if (output == null) {
Assert.assertFalse(tracksEnded);
assertThat(tracksEnded).isFalse();
numberOfTracks++;
output = new FakeTrackOutput();
trackOutputs.put(id, output);
......@@ -69,19 +71,19 @@ public final class FakeExtractorOutput implements ExtractorOutput, Dumper.Dumpab
}
public void assertEquals(FakeExtractorOutput expected) {
Assert.assertEquals(expected.numberOfTracks, numberOfTracks);
Assert.assertEquals(expected.tracksEnded, tracksEnded);
assertThat(numberOfTracks).isEqualTo(expected.numberOfTracks);
assertThat(tracksEnded).isEqualTo(expected.tracksEnded);
if (expected.seekMap == null) {
Assert.assertNull(seekMap);
assertThat(seekMap).isNull();
} else {
// TODO: Bulk up this check if possible.
Assert.assertNotNull(seekMap);
Assert.assertEquals(expected.seekMap.getClass(), seekMap.getClass());
Assert.assertEquals(expected.seekMap.isSeekable(), seekMap.isSeekable());
Assert.assertEquals(expected.seekMap.getSeekPoints(0), seekMap.getSeekPoints(0));
assertThat(seekMap).isNotNull();
assertThat(seekMap.getClass()).isEqualTo(expected.seekMap.getClass());
assertThat(seekMap.isSeekable()).isEqualTo(expected.seekMap.isSeekable());
assertThat(seekMap.getSeekPoints(0)).isEqualTo(expected.seekMap.getSeekPoints(0));
}
for (int i = 0; i < numberOfTracks; i++) {
Assert.assertEquals(expected.trackOutputs.keyAt(i), trackOutputs.keyAt(i));
assertThat(trackOutputs.keyAt(i)).isEqualTo(expected.trackOutputs.keyAt(i));
trackOutputs.valueAt(i).assertEquals(expected.trackOutputs.valueAt(i));
}
}
......@@ -107,7 +109,7 @@ public final class FakeExtractorOutput implements ExtractorOutput, Dumper.Dumpab
out.close();
} else {
String expected = TestUtil.getString(instrumentation, dumpFile);
Assert.assertEquals(dumpFile, expected, actual);
assertWithMessage(dumpFile).that(actual).isEqualTo(expected);
}
}
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.testutil;
import static com.google.common.truth.Truth.assertThat;
import android.os.Handler;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.C;
......@@ -25,7 +27,6 @@ import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import java.io.IOException;
import junit.framework.Assert;
/**
* Fake {@link MediaPeriod} that provides tracks from the given {@link TrackGroupArray}. Selecting
......@@ -119,14 +120,14 @@ public class FakeMediaPeriod implements MediaPeriod {
@Override
public TrackGroupArray getTrackGroups() {
Assert.assertTrue(prepared);
assertThat(prepared).isTrue();
return trackGroupArray;
}
@Override
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags,
SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
Assert.assertTrue(prepared);
assertThat(prepared).isTrue();
int rendererCount = selections.length;
for (int i = 0; i < rendererCount; i++) {
if (streams[i] != null && (selections[i] == null || !mayRetainStreamFlags[i])) {
......@@ -134,12 +135,12 @@ public class FakeMediaPeriod implements MediaPeriod {
}
if (streams[i] == null && selections[i] != null) {
TrackSelection selection = selections[i];
Assert.assertTrue(1 <= selection.length());
assertThat(selection.length()).isAtLeast(1);
TrackGroup trackGroup = selection.getTrackGroup();
Assert.assertTrue(trackGroupArray.indexOf(trackGroup) != C.INDEX_UNSET);
assertThat(trackGroupArray.indexOf(trackGroup) != C.INDEX_UNSET).isTrue();
int indexInTrackGroup = selection.getIndexInTrackGroup(selection.getSelectedIndex());
Assert.assertTrue(0 <= indexInTrackGroup);
Assert.assertTrue(indexInTrackGroup < trackGroup.length);
assertThat(indexInTrackGroup).isAtLeast(0);
assertThat(indexInTrackGroup).isLessThan(trackGroup.length);
streams[i] = createSampleStream(selection);
streamResetFlags[i] = true;
}
......@@ -159,7 +160,7 @@ public class FakeMediaPeriod implements MediaPeriod {
@Override
public long readDiscontinuity() {
Assert.assertTrue(prepared);
assertThat(prepared).isTrue();
long positionDiscontinuityUs = this.discontinuityPositionUs;
this.discontinuityPositionUs = C.TIME_UNSET;
return positionDiscontinuityUs;
......@@ -167,13 +168,13 @@ public class FakeMediaPeriod implements MediaPeriod {
@Override
public long getBufferedPositionUs() {
Assert.assertTrue(prepared);
assertThat(prepared).isTrue();
return C.TIME_END_OF_SOURCE;
}
@Override
public long seekToUs(long positionUs) {
Assert.assertTrue(prepared);
assertThat(prepared).isTrue();
return positionUs + seekOffsetUs;
}
......@@ -184,13 +185,13 @@ public class FakeMediaPeriod implements MediaPeriod {
@Override
public long getNextLoadPositionUs() {
Assert.assertTrue(prepared);
assertThat(prepared).isTrue();
return C.TIME_END_OF_SOURCE;
}
@Override
public boolean continueLoading(long positionUs) {
Assert.assertTrue(prepared);
assertThat(prepared).isTrue();
return false;
}
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.testutil;
import static com.google.common.truth.Truth.assertThat;
import android.os.Handler;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.ExoPlayer;
......@@ -28,7 +30,6 @@ import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.util.Assertions;
import java.io.IOException;
import java.util.ArrayList;
import junit.framework.Assert;
/**
* Fake {@link MediaSource} that provides a given timeline. Creating the period will return a
......@@ -75,7 +76,7 @@ public class FakeMediaSource implements MediaSource {
@Override
public synchronized void prepareSource(
ExoPlayer player, boolean isTopLevelSource, Listener listener) {
Assert.assertFalse(preparedSource);
assertThat(preparedSource).isFalse();
preparedSource = true;
this.listener = listener;
sourceInfoRefreshHandler = new Handler();
......@@ -86,13 +87,13 @@ public class FakeMediaSource implements MediaSource {
@Override
public void maybeThrowSourceInfoRefreshError() throws IOException {
Assert.assertTrue(preparedSource);
assertThat(preparedSource).isTrue();
}
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
Assert.assertTrue(preparedSource);
Assert.assertFalse(releasedSource);
assertThat(preparedSource).isTrue();
assertThat(releasedSource).isFalse();
Assertions.checkIndex(id.periodIndex, 0, timeline.getPeriodCount());
FakeMediaPeriod mediaPeriod = createFakeMediaPeriod(id, trackGroupArray, allocator);
activeMediaPeriods.add(mediaPeriod);
......@@ -102,18 +103,18 @@ public class FakeMediaSource implements MediaSource {
@Override
public void releasePeriod(MediaPeriod mediaPeriod) {
Assert.assertTrue(preparedSource);
Assert.assertFalse(releasedSource);
assertThat(preparedSource).isTrue();
assertThat(releasedSource).isFalse();
FakeMediaPeriod fakeMediaPeriod = (FakeMediaPeriod) mediaPeriod;
Assert.assertTrue(activeMediaPeriods.remove(fakeMediaPeriod));
assertThat(activeMediaPeriods.remove(fakeMediaPeriod)).isTrue();
fakeMediaPeriod.release();
}
@Override
public void releaseSource() {
Assert.assertTrue(preparedSource);
Assert.assertFalse(releasedSource);
Assert.assertTrue(activeMediaPeriods.isEmpty());
assertThat(preparedSource).isTrue();
assertThat(releasedSource).isFalse();
assertThat(activeMediaPeriods.isEmpty()).isTrue();
releasedSource = true;
}
......@@ -127,8 +128,8 @@ public class FakeMediaSource implements MediaSource {
new Runnable() {
@Override
public void run() {
Assert.assertFalse(releasedSource);
Assert.assertTrue(preparedSource);
assertThat(releasedSource).isFalse();
assertThat(preparedSource).isTrue();
timeline = newTimeline;
manifest = newManifest;
listener.onSourceInfoRefreshed(FakeMediaSource.this, timeline, manifest);
......@@ -144,14 +145,14 @@ public class FakeMediaSource implements MediaSource {
* Assert that the source and all periods have been released.
*/
public void assertReleased() {
Assert.assertTrue(releasedSource || !preparedSource);
assertThat(releasedSource || !preparedSource).isTrue();
}
/**
* Assert that a media period for the given id has been created.
*/
public void assertMediaPeriodCreated(MediaPeriodId mediaPeriodId) {
Assert.assertTrue(createdMediaPeriods.contains(mediaPeriodId));
assertThat(createdMediaPeriods).contains(mediaPeriodId);
}
protected FakeMediaPeriod createFakeMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray,
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.testutil;
import static com.google.common.truth.Truth.assertThat;
import com.google.android.exoplayer2.BaseRenderer;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException;
......@@ -26,7 +28,6 @@ import com.google.android.exoplayer2.util.MimeTypes;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import junit.framework.Assert;
/**
* Fake {@link Renderer} that supports any format with the matching MIME type. The renderer
......@@ -65,7 +66,7 @@ public class FakeRenderer extends BaseRenderer {
buffer.data = null;
if (result == C.RESULT_FORMAT_READ) {
formatReadCount++;
Assert.assertTrue(expectedFormats.contains(formatHolder.format));
assertThat(expectedFormats).contains(formatHolder.format);
} else if (result == C.RESULT_BUFFER_READ) {
bufferReadCount++;
if (buffer.isEndOfStream()) {
......
......@@ -15,7 +15,8 @@
*/
package com.google.android.exoplayer2.testutil;
import android.test.MoreAsserts;
import static com.google.common.truth.Truth.assertThat;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.extractor.ExtractorInput;
......@@ -25,7 +26,6 @@ import java.io.EOFException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import junit.framework.Assert;
/**
* A fake {@link TrackOutput}.
......@@ -98,15 +98,15 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
}
public void assertSampleCount(int count) {
Assert.assertEquals(count, sampleTimesUs.size());
assertThat(sampleTimesUs).hasSize(count);
}
public void assertSample(int index, byte[] data, long timeUs, int flags, CryptoData cryptoData) {
byte[] actualData = getSampleData(index);
MoreAsserts.assertEquals(data, actualData);
Assert.assertEquals(timeUs, (long) sampleTimesUs.get(index));
Assert.assertEquals(flags, (int) sampleFlags.get(index));
Assert.assertEquals(cryptoData, cryptoDatas.get(index));
assertThat(actualData).isEqualTo(data);
assertThat(sampleTimesUs.get(index)).isEqualTo(timeUs);
assertThat(sampleFlags.get(index)).isEqualTo(flags);
assertThat(cryptoDatas.get(index)).isEqualTo(cryptoData);
}
public byte[] getSampleData(int index) {
......@@ -115,18 +115,18 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
}
public void assertEquals(FakeTrackOutput expected) {
Assert.assertEquals(expected.format, format);
Assert.assertEquals(expected.sampleTimesUs.size(), sampleTimesUs.size());
MoreAsserts.assertEquals(expected.sampleData, sampleData);
assertThat(format).isEqualTo(expected.format);
assertThat(sampleTimesUs).hasSize(expected.sampleTimesUs.size());
assertThat(sampleData).isEqualTo(expected.sampleData);
for (int i = 0; i < sampleTimesUs.size(); i++) {
Assert.assertEquals(expected.sampleTimesUs.get(i), sampleTimesUs.get(i));
Assert.assertEquals(expected.sampleFlags.get(i), sampleFlags.get(i));
Assert.assertEquals(expected.sampleStartOffsets.get(i), sampleStartOffsets.get(i));
Assert.assertEquals(expected.sampleEndOffsets.get(i), sampleEndOffsets.get(i));
assertThat(sampleTimesUs.get(i)).isEqualTo(expected.sampleTimesUs.get(i));
assertThat(sampleFlags.get(i)).isEqualTo(expected.sampleFlags.get(i));
assertThat(sampleStartOffsets.get(i)).isEqualTo(expected.sampleStartOffsets.get(i));
assertThat(sampleEndOffsets.get(i)).isEqualTo(expected.sampleEndOffsets.get(i));
if (expected.cryptoDatas.get(i) == null) {
Assert.assertNull(cryptoDatas.get(i));
assertThat(cryptoDatas.get(i)).isNull();
} else {
Assert.assertEquals(expected.cryptoDatas.get(i), cryptoDatas.get(i));
assertThat(cryptoDatas.get(i)).isEqualTo(expected.cryptoDatas.get(i));
}
}
}
......
......@@ -15,13 +15,14 @@
*/
package com.google.android.exoplayer2.testutil;
import static com.google.common.truth.Truth.assertThat;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.chunk.MediaChunk;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import java.util.List;
import junit.framework.Assert;
/**
* A fake {@link TrackSelection} that only returns 1 fixed track, and allows querying the number
......@@ -42,7 +43,7 @@ public final class FakeTrackSelection implements TrackSelection {
@Override
public void enable() {
// assert that track selection is in disabled state before this call.
Assert.assertFalse(isEnabled);
assertThat(isEnabled).isFalse();
enableCount++;
isEnabled = true;
}
......@@ -50,7 +51,7 @@ public final class FakeTrackSelection implements TrackSelection {
@Override
public void disable() {
// assert that track selection is in enabled state before this call.
Assert.assertTrue(isEnabled);
assertThat(isEnabled).isTrue();
releaseCount++;
isEnabled = false;
}
......@@ -77,7 +78,7 @@ public final class FakeTrackSelection implements TrackSelection {
@Override
public int indexOf(Format format) {
Assert.assertTrue(isEnabled);
assertThat(isEnabled).isTrue();
return 0;
}
......@@ -119,18 +120,18 @@ public final class FakeTrackSelection implements TrackSelection {
@Override
public void updateSelectedTrack(long playbackPositionUs, long bufferedDurationUs,
long availableDurationUs) {
Assert.assertTrue(isEnabled);
assertThat(isEnabled).isTrue();
}
@Override
public int evaluateQueueSize(long playbackPositionUs, List<? extends MediaChunk> queue) {
Assert.assertTrue(isEnabled);
assertThat(isEnabled).isTrue();
return 0;
}
@Override
public boolean blacklist(int index, long blacklistDurationMs) {
Assert.assertTrue(isEnabled);
assertThat(isEnabled).isTrue();
return false;
}
......
......@@ -15,7 +15,7 @@
*/
package com.google.android.exoplayer2.testutil;
import static junit.framework.Assert.fail;
import static org.junit.Assert.fail;
import android.app.Activity;
import android.content.Context;
......
......@@ -15,9 +15,8 @@
*/
package com.google.android.exoplayer2.testutil;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
import android.os.ConditionVariable;
import android.os.Handler;
......@@ -90,7 +89,7 @@ public class MediaSourceTestRunner {
}
}
});
assertTrue(finishedCondition.block(TIMEOUT_MS));
assertThat(finishedCondition.block(TIMEOUT_MS)).isTrue();
if (throwable[0] != null) {
Util.sneakyThrow(throwable[0]);
}
......@@ -138,7 +137,7 @@ public class MediaSourceTestRunner {
holder[0] = mediaSource.createPeriod(periodId, allocator);
}
});
assertNotNull(holder[0]);
assertThat(holder[0]).isNotNull();
return holder[0];
}
......@@ -201,7 +200,7 @@ public class MediaSourceTestRunner {
* runner was created if neither method has been called).
*/
public void assertNoTimelineChange() {
assertTrue(timelines.isEmpty());
assertThat(timelines.isEmpty()).isTrue();
}
/**
......@@ -224,7 +223,7 @@ public class MediaSourceTestRunner {
public Timeline assertTimelineChangeBlocking() {
try {
timeline = timelines.poll(TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertNotNull(timeline); // Null indicates the poll timed out.
assertThat(timeline).isNotNull(); // Null indicates the poll timed out.
assertNoTimelineChange();
return timeline;
} catch (InterruptedException e) {
......@@ -254,12 +253,12 @@ public class MediaSourceTestRunner {
private void assertPrepareAndReleasePeriod(MediaPeriodId mediaPeriodId) {
MediaPeriod mediaPeriod = createPeriod(mediaPeriodId);
ConditionVariable preparedCondition = preparePeriod(mediaPeriod, 0);
assertTrue(preparedCondition.block(TIMEOUT_MS));
assertThat(preparedCondition.block(TIMEOUT_MS)).isTrue();
// MediaSource is supposed to support multiple calls to createPeriod with the same id without an
// intervening call to releasePeriod.
MediaPeriod secondMediaPeriod = createPeriod(mediaPeriodId);
ConditionVariable secondPreparedCondition = preparePeriod(secondMediaPeriod, 0);
assertTrue(secondPreparedCondition.block(TIMEOUT_MS));
assertThat(secondPreparedCondition.block(TIMEOUT_MS)).isTrue();
// Release the periods.
releasePeriod(mediaPeriod);
releasePeriod(secondMediaPeriod);
......
......@@ -15,9 +15,11 @@
*/
package com.google.android.exoplayer2.testutil;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
import android.app.Instrumentation;
import android.content.Context;
import android.test.MoreAsserts;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.extractor.Extractor;
import com.google.android.exoplayer2.testutil.FakeExtractorInput.SimulatedIOException;
......@@ -29,7 +31,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Random;
import junit.framework.Assert;
/**
* Utility methods for tests.
......@@ -71,7 +72,7 @@ public class TestUtil {
while (position < length) {
int bytesRead = dataSource.read(data, position, data.length - position);
if (bytesRead == C.RESULT_END_OF_INPUT) {
Assert.fail("Not enough data could be read: " + position + " < " + length);
fail("Not enough data could be read: " + position + " < " + length);
} else {
position += bytesRead;
}
......@@ -164,13 +165,14 @@ public class TestUtil {
* data length. If false then it's asserted that {@link C#LENGTH_UNSET} is returned.
* @throws IOException If an error occurs reading fom the {@link DataSource}.
*/
public static void assertDataSourceContent(DataSource dataSource, DataSpec dataSpec,
byte[] expectedData, boolean expectKnownLength) throws IOException {
public static void assertDataSourceContent(
DataSource dataSource, DataSpec dataSpec, byte[] expectedData, boolean expectKnownLength)
throws IOException {
try {
long length = dataSource.open(dataSpec);
Assert.assertEquals(expectKnownLength ? expectedData.length : C.LENGTH_UNSET, length);
byte[] readData = TestUtil.readToEnd(dataSource);
MoreAsserts.assertEquals(expectedData, readData);
assertThat(length).isEqualTo(expectKnownLength ? expectedData.length : C.LENGTH_UNSET);
byte[] readData = readToEnd(dataSource);
assertThat(readData).isEqualTo(expectedData);
} finally {
dataSource.close();
}
......
......@@ -15,7 +15,8 @@
*/
package com.google.android.exoplayer2.testutil;
import static junit.framework.Assert.assertEquals;
import static com.google.common.truth.Truth.assertThat;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline;
......@@ -27,6 +28,10 @@ import com.google.android.exoplayer2.Timeline.Window;
*/
public final class TimelineAsserts {
private static final int[] REPEAT_MODES = {
Player.REPEAT_MODE_OFF, Player.REPEAT_MODE_ONE, Player.REPEAT_MODE_ALL
};
private TimelineAsserts() {}
/**
......@@ -36,8 +41,8 @@ public final class TimelineAsserts {
assertWindowIds(timeline);
assertPeriodCounts(timeline);
for (boolean shuffled : new boolean[] {false, true}) {
assertEquals(C.INDEX_UNSET, timeline.getFirstWindowIndex(shuffled));
assertEquals(C.INDEX_UNSET, timeline.getLastWindowIndex(shuffled));
assertThat(timeline.getFirstWindowIndex(shuffled)).isEqualTo(C.INDEX_UNSET);
assertThat(timeline.getLastWindowIndex(shuffled)).isEqualTo(C.INDEX_UNSET);
}
}
......@@ -49,11 +54,11 @@ public final class TimelineAsserts {
*/
public static void assertWindowIds(Timeline timeline, Object... expectedWindowIds) {
Window window = new Window();
assertEquals(expectedWindowIds.length, timeline.getWindowCount());
assertThat(timeline.getWindowCount()).isEqualTo(expectedWindowIds.length);
for (int i = 0; i < timeline.getWindowCount(); i++) {
timeline.getWindow(i, window, true);
if (expectedWindowIds[i] != null) {
assertEquals(expectedWindowIds[i], window.id);
assertThat(window.id).isEqualTo(expectedWindowIds[i]);
}
}
}
......@@ -65,7 +70,7 @@ public final class TimelineAsserts {
Window window = new Window();
for (int i = 0; i < timeline.getWindowCount(); i++) {
timeline.getWindow(i, window, true);
assertEquals(windowIsDynamic[i], window.isDynamic);
assertThat(window.isDynamic).isEqualTo(windowIsDynamic[i]);
}
}
......@@ -77,8 +82,8 @@ public final class TimelineAsserts {
@Player.RepeatMode int repeatMode, boolean shuffleModeEnabled,
int... expectedPreviousWindowIndices) {
for (int i = 0; i < timeline.getWindowCount(); i++) {
assertEquals(expectedPreviousWindowIndices[i],
timeline.getPreviousWindowIndex(i, repeatMode, shuffleModeEnabled));
assertThat(timeline.getPreviousWindowIndex(i, repeatMode, shuffleModeEnabled))
.isEqualTo(expectedPreviousWindowIndices[i]);
}
}
......@@ -89,8 +94,8 @@ public final class TimelineAsserts {
public static void assertNextWindowIndices(Timeline timeline, @Player.RepeatMode int repeatMode,
boolean shuffleModeEnabled, int... expectedNextWindowIndices) {
for (int i = 0; i < timeline.getWindowCount(); i++) {
assertEquals(expectedNextWindowIndices[i],
timeline.getNextWindowIndex(i, repeatMode, shuffleModeEnabled));
assertThat(timeline.getNextWindowIndex(i, repeatMode, shuffleModeEnabled))
.isEqualTo(expectedNextWindowIndices[i]);
}
}
......@@ -106,14 +111,14 @@ public final class TimelineAsserts {
for (int i = 0; i < windowCount; i++) {
accumulatedPeriodCounts[i + 1] = accumulatedPeriodCounts[i] + expectedPeriodCounts[i];
}
assertEquals(accumulatedPeriodCounts[accumulatedPeriodCounts.length - 1],
timeline.getPeriodCount());
assertThat(timeline.getPeriodCount())
.isEqualTo(accumulatedPeriodCounts[accumulatedPeriodCounts.length - 1]);
Window window = new Window();
Period period = new Period();
for (int i = 0; i < windowCount; i++) {
timeline.getWindow(i, window, true);
assertEquals(accumulatedPeriodCounts[i], window.firstPeriodIndex);
assertEquals(accumulatedPeriodCounts[i + 1] - 1, window.lastPeriodIndex);
assertThat(window.firstPeriodIndex).isEqualTo(accumulatedPeriodCounts[i]);
assertThat(window.lastPeriodIndex).isEqualTo(accumulatedPeriodCounts[i + 1] - 1);
}
int expectedWindowIndex = 0;
for (int i = 0; i < timeline.getPeriodCount(); i++) {
......@@ -121,18 +126,18 @@ public final class TimelineAsserts {
while (i >= accumulatedPeriodCounts[expectedWindowIndex + 1]) {
expectedWindowIndex++;
}
assertEquals(expectedWindowIndex, period.windowIndex);
assertEquals(i, timeline.getIndexOfPeriod(period.uid));
for (@Player.RepeatMode int repeatMode
: new int[] {Player.REPEAT_MODE_OFF, Player.REPEAT_MODE_ONE, Player.REPEAT_MODE_ALL}) {
assertThat(period.windowIndex).isEqualTo(expectedWindowIndex);
assertThat(timeline.getIndexOfPeriod(period.uid)).isEqualTo(i);
for (int repeatMode : REPEAT_MODES) {
if (i < accumulatedPeriodCounts[expectedWindowIndex + 1] - 1) {
assertEquals(i + 1, timeline.getNextPeriodIndex(i, period, window, repeatMode, false));
assertThat(timeline.getNextPeriodIndex(i, period, window, repeatMode, false))
.isEqualTo(i + 1);
} else {
int nextWindow = timeline.getNextWindowIndex(expectedWindowIndex, repeatMode, false);
int nextPeriod = nextWindow == C.INDEX_UNSET ? C.INDEX_UNSET
: accumulatedPeriodCounts[nextWindow];
assertEquals(nextPeriod, timeline.getNextPeriodIndex(i, period, window, repeatMode,
false));
assertThat(timeline.getNextPeriodIndex(i, period, window, repeatMode, false))
.isEqualTo(nextPeriod);
}
}
}
......@@ -145,7 +150,7 @@ public final class TimelineAsserts {
Period period = new Period();
for (int i = 0; i < timeline.getPeriodCount(); i++) {
timeline.getPeriod(i, period);
assertEquals(expectedAdGroupCounts[i], period.getAdGroupCount());
assertThat(period.getAdGroupCount()).isEqualTo(expectedAdGroupCounts[i]);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment