1 package android.media; 2 3 import static com.google.common.truth.Truth.assertThat; 4 5 import android.os.Build; 6 import androidx.test.ext.junit.runners.AndroidJUnit4; 7 import org.junit.Test; 8 import org.junit.runner.RunWith; 9 10 /** Compatibility test for {@link android.media.MediaPlayer} */ 11 @RunWith(AndroidJUnit4.class) 12 public class MediaPlayerTest { 13 14 /** 15 * Checks that a MediaPlayer in the IDLE state does not throw an exception when calling {@link 16 * MediaPlayer#getCurrentPosition()}. 17 */ 18 @Test newMediaPlayer_getCurrentPosition_doesNotThrow()19 public void newMediaPlayer_getCurrentPosition_doesNotThrow() { 20 MediaPlayer mediaPlayer = new MediaPlayer(); 21 int currentPosition = mediaPlayer.getCurrentPosition(); 22 // currentPosition appears to be inconsistent garbage when run on emulators for SDKs < 30 23 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { 24 assertThat(currentPosition).isEqualTo(0); 25 } 26 } 27 } 28