From 1687f1653eadc4eb22177f029d27b5179c2cbf5e Mon Sep 17 00:00:00 2001 From: eguven Date: Mon, 22 May 2017 01:40:15 -0700 Subject: [PATCH] Make the error messages the first parameter in Assertions methods to match JUnit methods Reverse parameter order creates a slight confusion. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=156712385 --- .../exoplayer2/demo/SampleChooserActivity.java | 16 ++++++++-------- .../exoplayer2/extractor/mp4/AtomParsers.java | 16 ++++++++-------- .../extractor/mp4/FragmentedMp4Extractor.java | 2 +- .../exoplayer2/extractor/ts/SeiReader.java | 6 +++--- .../source/ConcatenatingMediaSource.java | 4 ++-- .../exoplayer2/source/LoopingMediaSource.java | 4 ++-- .../android/exoplayer2/util/Assertions.java | 16 ++++++++-------- .../android/exoplayer2/util/LibraryLoader.java | 2 +- .../android/exoplayer2/video/DummySurface.java | 14 +++++++------- 9 files changed, 40 insertions(+), 40 deletions(-) diff --git a/demo/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java b/demo/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java index 87b8e92e83..ed9dd63a45 100644 --- a/demo/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java +++ b/demo/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java @@ -200,17 +200,17 @@ public class SampleChooserActivity extends Activity { extension = reader.nextString(); break; case "drm_scheme": - Assertions.checkState(!insidePlaylist, "Invalid attribute on nested item: drm_scheme"); + Assertions.checkState("Invalid attribute on nested item: drm_scheme", !insidePlaylist); drmUuid = getDrmUuid(reader.nextString()); break; case "drm_license_url": - Assertions.checkState(!insidePlaylist, - "Invalid attribute on nested item: drm_license_url"); + Assertions.checkState("Invalid attribute on nested item: drm_license_url", + !insidePlaylist); drmLicenseUrl = reader.nextString(); break; case "drm_key_request_properties": - Assertions.checkState(!insidePlaylist, - "Invalid attribute on nested item: drm_key_request_properties"); + Assertions.checkState("Invalid attribute on nested item: drm_key_request_properties", + !insidePlaylist); ArrayList drmKeyRequestPropertiesList = new ArrayList<>(); reader.beginObject(); while (reader.hasNext()) { @@ -221,12 +221,12 @@ public class SampleChooserActivity extends Activity { drmKeyRequestProperties = drmKeyRequestPropertiesList.toArray(new String[0]); break; case "prefer_extension_decoders": - Assertions.checkState(!insidePlaylist, - "Invalid attribute on nested item: prefer_extension_decoders"); + Assertions.checkState("Invalid attribute on nested item: prefer_extension_decoders", + !insidePlaylist); preferExtensionDecoders = reader.nextBoolean(); break; case "playlist": - Assertions.checkState(!insidePlaylist, "Invalid nesting of playlists"); + Assertions.checkState("Invalid nesting of playlists", !insidePlaylist); playlistSamples = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/extractor/mp4/AtomParsers.java b/library/core/src/main/java/com/google/android/exoplayer2/extractor/mp4/AtomParsers.java index 474ba65d86..229cf8fcbd 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/extractor/mp4/AtomParsers.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/extractor/mp4/AtomParsers.java @@ -593,7 +593,7 @@ import java.util.List; for (int i = 0; i < numberOfEntries; i++) { int childStartPosition = stsd.getPosition(); int childAtomSize = stsd.readInt(); - Assertions.checkArgument(childAtomSize > 0, "childAtomSize should be positive"); + Assertions.checkArgument("childAtomSize should be positive", childAtomSize > 0); int childAtomType = stsd.readInt(); if (childAtomType == Atom.TYPE_avc1 || childAtomType == Atom.TYPE_avc3 || childAtomType == Atom.TYPE_encv || childAtomType == Atom.TYPE_mp4v @@ -693,7 +693,7 @@ import java.util.List; // Handle optional terminating four zero bytes in MOV files. break; } - Assertions.checkArgument(childAtomSize > 0, "childAtomSize should be positive"); + Assertions.checkArgument("childAtomSize should be positive", childAtomSize > 0); int childAtomType = parent.readInt(); if (childAtomType == Atom.TYPE_avcC) { Assertions.checkState(mimeType == null); @@ -877,7 +877,7 @@ import java.util.List; while (childPosition - position < size) { parent.setPosition(childPosition); int childAtomSize = parent.readInt(); - Assertions.checkArgument(childAtomSize > 0, "childAtomSize should be positive"); + Assertions.checkArgument("childAtomSize should be positive", childAtomSize > 0); int childAtomType = parent.readInt(); if (childAtomType == Atom.TYPE_esds || (isQuickTime && childAtomType == Atom.TYPE_wave)) { int esdsAtomPosition = childAtomType == Atom.TYPE_esds ? childPosition @@ -936,7 +936,7 @@ import java.util.List; while (childAtomPosition - position < size) { parent.setPosition(childAtomPosition); int childAtomSize = parent.readInt(); - Assertions.checkArgument(childAtomSize > 0, "childAtomSize should be positive"); + Assertions.checkArgument("childAtomSize should be positive", childAtomSize > 0); int childType = parent.readInt(); if (childType == Atom.TYPE_esds) { return childAtomPosition; @@ -1032,7 +1032,7 @@ import java.util.List; while (childPosition - position < size) { parent.setPosition(childPosition); int childAtomSize = parent.readInt(); - Assertions.checkArgument(childAtomSize > 0, "childAtomSize should be positive"); + Assertions.checkArgument("childAtomSize should be positive", childAtomSize > 0); int childAtomType = parent.readInt(); if (childAtomType == Atom.TYPE_sinf) { Pair result = parseSinfFromParent(parent, childPosition, @@ -1071,8 +1071,8 @@ import java.util.List; } if (isCencScheme) { - Assertions.checkArgument(dataFormat != null, "frma atom is mandatory"); - Assertions.checkArgument(trackEncryptionBox != null, "schi->tenc atom is mandatory"); + Assertions.checkArgument("frma atom is mandatory", dataFormat != null); + Assertions.checkArgument("schi->tenc atom is mandatory", trackEncryptionBox != null); return Pair.create(dataFormat, trackEncryptionBox); } else { return null; @@ -1157,7 +1157,7 @@ import java.util.List; length = chunkOffsets.readUnsignedIntToInt(); stsc.setPosition(Atom.FULL_HEADER_SIZE); remainingSamplesPerChunkChanges = stsc.readUnsignedIntToInt(); - Assertions.checkState(stsc.readInt() == 1, "first_chunk must be 1"); + Assertions.checkState("first_chunk must be 1", stsc.readInt() == 1); index = C.INDEX_UNSET; } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/extractor/mp4/FragmentedMp4Extractor.java b/library/core/src/main/java/com/google/android/exoplayer2/extractor/mp4/FragmentedMp4Extractor.java index fe1d4b04af..1a40310146 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/extractor/mp4/FragmentedMp4Extractor.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/extractor/mp4/FragmentedMp4Extractor.java @@ -388,7 +388,7 @@ public final class FragmentedMp4Extractor implements Extractor { } private void onMoovContainerAtomRead(ContainerAtom moov) throws ParserException { - Assertions.checkState(sideloadedTrack == null, "Unexpected moov box."); + Assertions.checkState("Unexpected moov box.", sideloadedTrack == null); DrmInitData drmInitData = getDrmInitDataFromAtoms(moov.leafChildren); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/extractor/ts/SeiReader.java b/library/core/src/main/java/com/google/android/exoplayer2/extractor/ts/SeiReader.java index 1e5d480ea1..5fa33b31e8 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/extractor/ts/SeiReader.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/extractor/ts/SeiReader.java @@ -48,9 +48,9 @@ import java.util.List; TrackOutput output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_TEXT); Format channelFormat = closedCaptionFormats.get(i); String channelMimeType = channelFormat.sampleMimeType; - Assertions.checkArgument(MimeTypes.APPLICATION_CEA608.equals(channelMimeType) - || MimeTypes.APPLICATION_CEA708.equals(channelMimeType), - "Invalid closed caption mime type provided: " + channelMimeType); + Assertions.checkArgument("Invalid closed caption mime type provided: " + channelMimeType, + MimeTypes.APPLICATION_CEA608.equals(channelMimeType) + || MimeTypes.APPLICATION_CEA708.equals(channelMimeType)); output.format(Format.createTextSampleFormat(idGenerator.getFormatId(), channelMimeType, null, Format.NO_VALUE, channelFormat.selectionFlags, channelFormat.language, channelFormat.accessibilityChannel, null)); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/ConcatenatingMediaSource.java b/library/core/src/main/java/com/google/android/exoplayer2/source/ConcatenatingMediaSource.java index 2299e757d7..c9ffa9251f 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/ConcatenatingMediaSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/ConcatenatingMediaSource.java @@ -170,8 +170,8 @@ public final class ConcatenatingMediaSource implements MediaSource { for (int i = 0; i < timelines.length; i++) { Timeline timeline = timelines[i]; periodCount += timeline.getPeriodCount(); - Assertions.checkState(periodCount <= Integer.MAX_VALUE, - "ConcatenatingMediaSource children contain too many periods"); + Assertions.checkState("ConcatenatingMediaSource children contain too many periods", + periodCount <= Integer.MAX_VALUE); sourcePeriodOffsets[i] = (int) periodCount; windowCount += timeline.getWindowCount(); sourceWindowOffsets[i] = windowCount; diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/LoopingMediaSource.java b/library/core/src/main/java/com/google/android/exoplayer2/source/LoopingMediaSource.java index 0e1e7d9033..fed05d1bc9 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/LoopingMediaSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/LoopingMediaSource.java @@ -102,8 +102,8 @@ public final class LoopingMediaSource implements MediaSource { childPeriodCount = childTimeline.getPeriodCount(); childWindowCount = childTimeline.getWindowCount(); this.loopCount = loopCount; - Assertions.checkState(loopCount <= Integer.MAX_VALUE / childPeriodCount, - "LoopingMediaSource contains too many periods"); + Assertions.checkState("LoopingMediaSource contains too many periods", + loopCount <= Integer.MAX_VALUE / childPeriodCount); } @Override diff --git a/library/core/src/main/java/com/google/android/exoplayer2/util/Assertions.java b/library/core/src/main/java/com/google/android/exoplayer2/util/Assertions.java index aee46eea0e..afee5ee725 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/util/Assertions.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/util/Assertions.java @@ -41,12 +41,12 @@ public final class Assertions { /** * Throws {@link IllegalArgumentException} if {@code expression} evaluates to false. * - * @param expression The expression to evaluate. * @param errorMessage The exception message if an exception is thrown. The message is converted * to a {@link String} using {@link String#valueOf(Object)}. + * @param expression The expression to evaluate. * @throws IllegalArgumentException If {@code expression} is false. */ - public static void checkArgument(boolean expression, Object errorMessage) { + public static void checkArgument(Object errorMessage, boolean expression) { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && !expression) { throw new IllegalArgumentException(String.valueOf(errorMessage)); } @@ -83,12 +83,12 @@ public final class Assertions { /** * Throws {@link IllegalStateException} if {@code expression} evaluates to false. * - * @param expression The expression to evaluate. * @param errorMessage The exception message if an exception is thrown. The message is converted * to a {@link String} using {@link String#valueOf(Object)}. + * @param expression The expression to evaluate. * @throws IllegalStateException If {@code expression} is false. */ - public static void checkState(boolean expression, Object errorMessage) { + public static void checkState(Object errorMessage, boolean expression) { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && !expression) { throw new IllegalStateException(String.valueOf(errorMessage)); } @@ -113,13 +113,13 @@ public final class Assertions { * Throws {@link NullPointerException} if {@code reference} is null. * * @param The type of the reference. - * @param reference The reference. * @param errorMessage The exception message to use if the check fails. The message is converted * to a string using {@link String#valueOf(Object)}. + * @param reference The reference. * @return The non-null reference that was validated. * @throws NullPointerException If {@code reference} is null. */ - public static T checkNotNull(T reference, Object errorMessage) { + public static T checkNotNull(Object errorMessage, T reference) { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && reference == null) { throw new NullPointerException(String.valueOf(errorMessage)); } @@ -143,13 +143,13 @@ public final class Assertions { /** * Throws {@link IllegalArgumentException} if {@code string} is null or zero length. * - * @param string The string to check. * @param errorMessage The exception message to use if the check fails. The message is converted * to a string using {@link String#valueOf(Object)}. + * @param string The string to check. * @return The non-null, non-empty string that was validated. * @throws IllegalArgumentException If {@code string} is null or 0-length. */ - public static String checkNotEmpty(String string, Object errorMessage) { + public static String checkNotEmpty(Object errorMessage, String string) { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && TextUtils.isEmpty(string)) { throw new IllegalArgumentException(String.valueOf(errorMessage)); } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/util/LibraryLoader.java b/library/core/src/main/java/com/google/android/exoplayer2/util/LibraryLoader.java index c12bae0a07..f90817f062 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/util/LibraryLoader.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/util/LibraryLoader.java @@ -36,7 +36,7 @@ public final class LibraryLoader { * {@link #isAvailable()}. */ public synchronized void setLibraries(String... libraries) { - Assertions.checkState(!loadAttempted, "Cannot set libraries after loading"); + Assertions.checkState("Cannot set libraries after loading", !loadAttempted); nativeLibraries = libraries; } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/video/DummySurface.java b/library/core/src/main/java/com/google/android/exoplayer2/video/DummySurface.java index 5298c82f61..2c99a6bad4 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/video/DummySurface.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/video/DummySurface.java @@ -226,11 +226,11 @@ public final class DummySurface extends Surface { private void initInternal(boolean secure) { EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); - Assertions.checkState(display != null, "eglGetDisplay failed"); + Assertions.checkState("eglGetDisplay failed", display != null); int[] version = new int[2]; boolean eglInitialized = eglInitialize(display, version, 0, version, 1); - Assertions.checkState(eglInitialized, "eglInitialize failed"); + Assertions.checkState("eglInitialize failed", eglInitialized); int[] eglAttributes = new int[] { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, @@ -247,8 +247,8 @@ public final class DummySurface extends Surface { int[] numConfigs = new int[1]; boolean eglChooseConfigSuccess = eglChooseConfig(display, eglAttributes, 0, configs, 0, 1, numConfigs, 0); - Assertions.checkState(eglChooseConfigSuccess && numConfigs[0] > 0 && configs[0] != null, - "eglChooseConfig failed"); + Assertions.checkState("eglChooseConfig failed", + eglChooseConfigSuccess && numConfigs[0] > 0 && configs[0] != null); EGLConfig config = configs[0]; int[] glAttributes; @@ -264,7 +264,7 @@ public final class DummySurface extends Surface { } EGLContext context = eglCreateContext(display, config, android.opengl.EGL14.EGL_NO_CONTEXT, glAttributes, 0); - Assertions.checkState(context != null, "eglCreateContext failed"); + Assertions.checkState("eglCreateContext failed", context != null); int[] pbufferAttributes; if (secure) { @@ -280,10 +280,10 @@ public final class DummySurface extends Surface { EGL_NONE}; } EGLSurface pbuffer = eglCreatePbufferSurface(display, config, pbufferAttributes, 0); - Assertions.checkState(pbuffer != null, "eglCreatePbufferSurface failed"); + Assertions.checkState("eglCreatePbufferSurface failed", pbuffer != null); boolean eglMadeCurrent = eglMakeCurrent(display, pbuffer, pbuffer, context); - Assertions.checkState(eglMadeCurrent, "eglMakeCurrent failed"); + Assertions.checkState("eglMakeCurrent failed", eglMadeCurrent); glGenTextures(1, textureIdHolder, 0); surfaceTexture = new SurfaceTexture(textureIdHolder[0]);