Enable nullness checker for Muxer module androidTest library

PiperOrigin-RevId: 538742957
This commit is contained in:
sheenachhabra 2023-06-08 11:03:09 +00:00 committed by Tofunmi Adigun-Hameed
parent 0c924fcb40
commit 2753fb0e3e

View File

@ -15,6 +15,8 @@
*/ */
package androidx.media3.muxer; package androidx.media3.muxer;
import static androidx.media3.common.util.Assertions.checkNotNull;
import android.content.Context; import android.content.Context;
import android.media.MediaCodec; import android.media.MediaCodec;
import android.media.MediaExtractor; import android.media.MediaExtractor;
@ -30,6 +32,7 @@ import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
@ -53,26 +56,23 @@ public class Mp4MuxerEndToEndTest {
return ImmutableList.of(H264_MP4, H265_HDR10_MP4, H265_WITH_METADATA_TRACK_MP4, AV1_MP4); return ImmutableList.of(H264_MP4, H265_HDR10_MP4, H265_WITH_METADATA_TRACK_MP4, AV1_MP4);
} }
@Parameter public String inputFile; @Parameter public @MonotonicNonNull String inputFile;
@Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder(); @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();
private static final String MP4_FILE_ASSET_DIRECTORY = "media/mp4/"; private static final String MP4_FILE_ASSET_DIRECTORY = "media/mp4/";
private final Context context = ApplicationProvider.getApplicationContext();
private Context context; private @MonotonicNonNull String outputPath;
private String outputPath; private @MonotonicNonNull FileOutputStream outputStream;
private FileOutputStream outputStream;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
context = ApplicationProvider.getApplicationContext();
outputPath = temporaryFolder.newFile("muxeroutput.mp4").getPath(); outputPath = temporaryFolder.newFile("muxeroutput.mp4").getPath();
outputStream = new FileOutputStream(outputPath); outputStream = new FileOutputStream(outputPath);
} }
@After @After
public void tearDown() throws IOException { public void tearDown() throws IOException {
outputStream.close(); checkNotNull(outputStream).close();
} }
@Test @Test
@ -80,9 +80,9 @@ public class Mp4MuxerEndToEndTest {
Mp4Muxer mp4Muxer = null; Mp4Muxer mp4Muxer = null;
try { try {
mp4Muxer = new Mp4Muxer.Builder(outputStream).build(); mp4Muxer = new Mp4Muxer.Builder(checkNotNull(outputStream)).build();
mp4Muxer.setModificationTime(/* timestampMs= */ 500_000_000L); mp4Muxer.setModificationTime(/* timestampMs= */ 500_000_000L);
feedInputDataToMuxer(mp4Muxer, inputFile); feedInputDataToMuxer(mp4Muxer, checkNotNull(inputFile));
} finally { } finally {
if (mp4Muxer != null) { if (mp4Muxer != null) {
mp4Muxer.close(); mp4Muxer.close();
@ -90,14 +90,14 @@ public class Mp4MuxerEndToEndTest {
} }
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath(new Mp4Extractor(), outputPath); TestUtil.extractAllSamplesFromFilePath(new Mp4Extractor(), checkNotNull(outputPath));
DumpFileAsserts.assertOutput( DumpFileAsserts.assertOutput(
context, fakeExtractorOutput, AndroidMuxerTestUtil.getExpectedDumpFilePath(inputFile)); context, fakeExtractorOutput, AndroidMuxerTestUtil.getExpectedDumpFilePath(inputFile));
} }
@Test @Test
public void createMp4File_muxerNotClosed_createsPartiallyWrittenValidFile() throws IOException { public void createMp4File_muxerNotClosed_createsPartiallyWrittenValidFile() throws IOException {
Mp4Muxer mp4Muxer = new Mp4Muxer.Builder(outputStream).build(); Mp4Muxer mp4Muxer = new Mp4Muxer.Builder(checkNotNull(outputStream)).build();
mp4Muxer.setModificationTime(/* timestampMs= */ 500_000_000L); mp4Muxer.setModificationTime(/* timestampMs= */ 500_000_000L);
feedInputDataToMuxer(mp4Muxer, H265_HDR10_MP4); feedInputDataToMuxer(mp4Muxer, H265_HDR10_MP4);
@ -107,7 +107,7 @@ public class Mp4MuxerEndToEndTest {
// Video sample written = 94 out of 127. // Video sample written = 94 out of 127.
// Output is still a valid MP4 file. // Output is still a valid MP4 file.
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath(new Mp4Extractor(), outputPath); TestUtil.extractAllSamplesFromFilePath(new Mp4Extractor(), checkNotNull(outputPath));
DumpFileAsserts.assertOutput( DumpFileAsserts.assertOutput(
context, context,
fakeExtractorOutput, fakeExtractorOutput,