Search in sources :

Example 81 with UiThreadTest

use of androidx.test.annotation.UiThreadTest in project AntennaPod by AntennaPod.

the class PlaybackServiceMediaPlayerTest method testPlayMediaObjectLocalStartNoPrepare.

@Test
@UiThreadTest
public void testPlayMediaObjectLocalStartNoPrepare() throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    CancelablePSMPCallback callback = new CancelablePSMPCallback(new DefaultPSMPCallback() {

        @Override
        public void statusChanged(LocalPSMP.PSMPInfo newInfo) {
            try {
                checkPSMPInfo(newInfo);
                if (newInfo.playerStatus == PlayerStatus.ERROR)
                    throw new IllegalStateException("MediaPlayer error");
                if (countDownLatch.getCount() == 0) {
                    fail();
                } else if (countDownLatch.getCount() == 2) {
                    assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus);
                    countDownLatch.countDown();
                } else {
                    assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus);
                    countDownLatch.countDown();
                }
            } catch (AssertionFailedError e) {
                if (assertionError == null)
                    assertionError = e;
            }
        }
    });
    PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback);
    Playable p = writeTestPlayable(playableFileUrl, PLAYABLE_LOCAL_URL);
    psmp.playMediaObject(p, false, true, false);
    boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    if (assertionError != null)
        throw assertionError;
    assertTrue(res);
    assertSame(PlayerStatus.INITIALIZED, psmp.getPSMPInfo().playerStatus);
    assertTrue(psmp.isStartWhenPrepared());
    callback.cancel();
    psmp.shutdown();
}
Also used : Context(android.content.Context) Playable(de.danoeh.antennapod.model.playback.Playable) LocalPSMP(de.danoeh.antennapod.core.service.playback.LocalPSMP) PlaybackServiceMediaPlayer(de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) AssertionFailedError(junit.framework.AssertionFailedError) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 82 with UiThreadTest

use of androidx.test.annotation.UiThreadTest in project AntennaPod by AntennaPod.

the class PlaybackServiceMediaPlayerTest method testPlayMediaObjectStreamNoStartPrepare.

@Test
@UiThreadTest
public void testPlayMediaObjectStreamNoStartPrepare() throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final CountDownLatch countDownLatch = new CountDownLatch(4);
    CancelablePSMPCallback callback = new CancelablePSMPCallback(new DefaultPSMPCallback() {

        @Override
        public void statusChanged(LocalPSMP.PSMPInfo newInfo) {
            try {
                checkPSMPInfo(newInfo);
                if (newInfo.playerStatus == PlayerStatus.ERROR)
                    throw new IllegalStateException("MediaPlayer error");
                if (countDownLatch.getCount() == 0) {
                    fail();
                } else if (countDownLatch.getCount() == 4) {
                    assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus);
                } else if (countDownLatch.getCount() == 3) {
                    assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus);
                } else if (countDownLatch.getCount() == 2) {
                    assertEquals(PlayerStatus.PREPARING, newInfo.playerStatus);
                } else if (countDownLatch.getCount() == 1) {
                    assertEquals(PlayerStatus.PREPARED, newInfo.playerStatus);
                }
                countDownLatch.countDown();
            } catch (AssertionFailedError e) {
                if (assertionError == null)
                    assertionError = e;
            }
        }
    });
    PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback);
    Playable p = writeTestPlayable(playableFileUrl, null);
    psmp.playMediaObject(p, true, false, true);
    boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    if (assertionError != null)
        throw assertionError;
    assertTrue(res);
    assertSame(PlayerStatus.PREPARED, psmp.getPSMPInfo().playerStatus);
    callback.cancel();
    psmp.shutdown();
}
Also used : Context(android.content.Context) Playable(de.danoeh.antennapod.model.playback.Playable) LocalPSMP(de.danoeh.antennapod.core.service.playback.LocalPSMP) PlaybackServiceMediaPlayer(de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) AssertionFailedError(junit.framework.AssertionFailedError) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 83 with UiThreadTest

use of androidx.test.annotation.UiThreadTest in project AntennaPod by AntennaPod.

the class PlaybackServiceMediaPlayerTest method testPlayMediaObjectLocalNoStartNoPrepare.

@Test
@UiThreadTest
public void testPlayMediaObjectLocalNoStartNoPrepare() throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    CancelablePSMPCallback callback = new CancelablePSMPCallback(new DefaultPSMPCallback() {

        @Override
        public void statusChanged(LocalPSMP.PSMPInfo newInfo) {
            try {
                checkPSMPInfo(newInfo);
                if (newInfo.playerStatus == PlayerStatus.ERROR)
                    throw new IllegalStateException("MediaPlayer error");
                if (countDownLatch.getCount() == 0) {
                    fail();
                } else if (countDownLatch.getCount() == 2) {
                    assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus);
                    countDownLatch.countDown();
                } else {
                    assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus);
                    countDownLatch.countDown();
                }
            } catch (AssertionFailedError e) {
                if (assertionError == null)
                    assertionError = e;
            }
        }
    });
    PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback);
    Playable p = writeTestPlayable(playableFileUrl, PLAYABLE_LOCAL_URL);
    psmp.playMediaObject(p, false, false, false);
    boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    if (assertionError != null)
        throw assertionError;
    assertTrue(res);
    assertSame(PlayerStatus.INITIALIZED, psmp.getPSMPInfo().playerStatus);
    assertFalse(psmp.isStartWhenPrepared());
    callback.cancel();
    psmp.shutdown();
}
Also used : Context(android.content.Context) Playable(de.danoeh.antennapod.model.playback.Playable) LocalPSMP(de.danoeh.antennapod.core.service.playback.LocalPSMP) PlaybackServiceMediaPlayer(de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) AssertionFailedError(junit.framework.AssertionFailedError) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 84 with UiThreadTest

use of androidx.test.annotation.UiThreadTest in project AntennaPod by AntennaPod.

the class PlaybackServiceMediaPlayerTest method testPlayMediaObjectStreamStartNoPrepare.

@Test
@UiThreadTest
public void testPlayMediaObjectStreamStartNoPrepare() throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    CancelablePSMPCallback callback = new CancelablePSMPCallback(new DefaultPSMPCallback() {

        @Override
        public void statusChanged(LocalPSMP.PSMPInfo newInfo) {
            try {
                checkPSMPInfo(newInfo);
                if (newInfo.playerStatus == PlayerStatus.ERROR)
                    throw new IllegalStateException("MediaPlayer error");
                if (countDownLatch.getCount() == 0) {
                    fail();
                } else if (countDownLatch.getCount() == 2) {
                    assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus);
                    countDownLatch.countDown();
                } else {
                    assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus);
                    countDownLatch.countDown();
                }
            } catch (AssertionFailedError e) {
                if (assertionError == null)
                    assertionError = e;
            }
        }
    });
    PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback);
    Playable p = writeTestPlayable(playableFileUrl, null);
    psmp.playMediaObject(p, true, true, false);
    boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    if (assertionError != null)
        throw assertionError;
    assertTrue(res);
    assertSame(PlayerStatus.INITIALIZED, psmp.getPSMPInfo().playerStatus);
    assertTrue(psmp.isStartWhenPrepared());
    callback.cancel();
    psmp.shutdown();
}
Also used : Context(android.content.Context) Playable(de.danoeh.antennapod.model.playback.Playable) LocalPSMP(de.danoeh.antennapod.core.service.playback.LocalPSMP) PlaybackServiceMediaPlayer(de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) AssertionFailedError(junit.framework.AssertionFailedError) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 85 with UiThreadTest

use of androidx.test.annotation.UiThreadTest in project AntennaPod by AntennaPod.

the class PlaybackServiceMediaPlayerTest method testInit.

@Test
@UiThreadTest
public void testInit() {
    final Context c = getInstrumentation().getTargetContext();
    PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, new DefaultPSMPCallback());
    psmp.shutdown();
}
Also used : Context(android.content.Context) LocalPSMP(de.danoeh.antennapod.core.service.playback.LocalPSMP) PlaybackServiceMediaPlayer(de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Aggregations

UiThreadTest (androidx.test.annotation.UiThreadTest)136 Test (org.junit.Test)129 View (android.view.View)41 Unbinder (butterknife.Unbinder)31 Context (android.content.Context)23 AdapterView (android.widget.AdapterView)18 TextView (android.widget.TextView)15 RecordingObserver (com.jakewharton.rxbinding4.RecordingObserver)15 MediumTest (androidx.test.filters.MediumTest)14 Intent (android.content.Intent)10 SubscriptionInfo (android.telephony.SubscriptionInfo)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 LocalPSMP (de.danoeh.antennapod.core.service.playback.LocalPSMP)9 PlaybackServiceMediaPlayer (de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer)9 Slice (androidx.slice.Slice)8 Playable (de.danoeh.antennapod.model.playback.Playable)8 AssertionFailedError (junit.framework.AssertionFailedError)8 Before (org.junit.Before)7 ViewGroup (android.view.ViewGroup)6 FrameLayout (android.widget.FrameLayout)6