From fc3ce9f55111b48d0f0ecbed61d5687faef47dde Mon Sep 17 00:00:00 2001 From: Christopher Eby Date: Tue, 4 Oct 2011 00:29:21 -0500 Subject: [PATCH] Use JUnit assert rather than assert keyword These are turned on by default and can be compiled out entirely for release mode --- proguard.config | 4 ++++ src/org/kreed/vanilla/LibraryActivity.java | 3 ++- src/org/kreed/vanilla/MediaButtonHandler.java | 8 ++++---- src/org/kreed/vanilla/MediaUtils.java | 5 +++-- src/org/kreed/vanilla/SongTimeline.java | 16 ++++++++-------- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/proguard.config b/proguard.config index 3af62544..551b9211 100644 --- a/proguard.config +++ b/proguard.config @@ -51,3 +51,7 @@ -assumenosideeffects class java.lang.String { public *** format(...); } + +-assumenosideeffects class junit.framework.Assert { + ; +} diff --git a/src/org/kreed/vanilla/LibraryActivity.java b/src/org/kreed/vanilla/LibraryActivity.java index 1a40cdc8..4cdce8fe 100644 --- a/src/org/kreed/vanilla/LibraryActivity.java +++ b/src/org/kreed/vanilla/LibraryActivity.java @@ -53,6 +53,7 @@ import android.widget.ListView; import android.widget.TabWidget; import android.widget.TextView; import android.widget.Toast; +import junit.framework.Assert; /** * The library activity where songs to play can be selected from the library. @@ -411,7 +412,7 @@ public class LibraryActivity extends PlaybackActivity implements AdapterView.OnI if (i == 1) { // generate the artist limiter (we need to query the artist id) MediaAdapter.Limiter limiter = mSongAdapter.getLimiter(); - assert(limiter.type == MediaUtils.TYPE_ALBUM); + Assert.assertEquals(MediaUtils.TYPE_ALBUM, limiter.type); ContentResolver resolver = getContentResolver(); Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; diff --git a/src/org/kreed/vanilla/MediaButtonHandler.java b/src/org/kreed/vanilla/MediaButtonHandler.java index 32b77d01..4de22f6b 100644 --- a/src/org/kreed/vanilla/MediaButtonHandler.java +++ b/src/org/kreed/vanilla/MediaButtonHandler.java @@ -22,9 +22,6 @@ package org.kreed.vanilla; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -34,6 +31,9 @@ import android.os.SystemClock; import android.telephony.TelephonyManager; import android.util.Log; import android.view.KeyEvent; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import junit.framework.Assert; /** * Handle a provided MediaButton event and take the appropriate action in @@ -225,7 +225,7 @@ public class MediaButtonHandler { */ public void registerMediaButton() { - assert(mUseControls == 1); + Assert.assertEquals(mUseControls, 1); if (mRegisterMediaButtonEventReceiver != null) { try { mRegisterMediaButtonEventReceiver.invoke(mAudioManager, mButtonReceiver); diff --git a/src/org/kreed/vanilla/MediaUtils.java b/src/org/kreed/vanilla/MediaUtils.java index ca9b0403..593cb7e5 100644 --- a/src/org/kreed/vanilla/MediaUtils.java +++ b/src/org/kreed/vanilla/MediaUtils.java @@ -30,6 +30,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Random; +import junit.framework.Assert; public class MediaUtils { /** @@ -253,7 +254,7 @@ public class MediaUtils { */ public static void shuffle(Song[] list, int end) { - assert(end <= list.length && end >= 0); + Assert.assertTrue(end <= list.length && end >= 0); Random random = getRandom(); for (int i = end; --i != -1; ) { int j = random.nextInt(i + 1); @@ -457,7 +458,7 @@ public class MediaUtils { int count = cursor.getCount(); if (count > 0) { - assert(count <= RANDOM_POPULATE_SIZE); + Assert.assertTrue(count <= RANDOM_POPULATE_SIZE); for (int i = 0; i != count; ++i) { cursor.moveToNext(); diff --git a/src/org/kreed/vanilla/SongTimeline.java b/src/org/kreed/vanilla/SongTimeline.java index 2b8fc953..a275a442 100644 --- a/src/org/kreed/vanilla/SongTimeline.java +++ b/src/org/kreed/vanilla/SongTimeline.java @@ -22,6 +22,11 @@ package org.kreed.vanilla; +import android.content.ContentResolver; +import android.content.Context; +import android.database.Cursor; +import android.net.Uri; +import android.provider.MediaStore; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.EOFException; @@ -31,12 +36,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.ListIterator; - -import android.content.ContentResolver; -import android.content.Context; -import android.database.Cursor; -import android.net.Uri; -import android.provider.MediaStore; +import junit.framework.Assert; /** * Represents a series of songs that can be moved through backward or forward. @@ -379,7 +379,7 @@ public final class SongTimeline { */ public Song getSong(int delta) { - assert(delta >= -1 && delta <= 1); + Assert.assertTrue(delta >= -1 && delta <= 1); ArrayList timeline = mSongs; Song song = null; @@ -435,7 +435,7 @@ public final class SongTimeline { */ public Song shiftCurrentSong(int delta) { - assert(delta >= -1 && delta <= 1); + Assert.assertTrue(delta >= -1 && delta <= 1); synchronized (this) { int pos = mCurrentPos + delta;