|
22 | 22 | import android.os.Bundle;
|
23 | 23 | import android.os.Looper;
|
24 | 24 | import androidx.media3.common.Player;
|
| 25 | +import androidx.media3.common.Timeline; |
| 26 | +import androidx.media3.test.utils.FakeTimeline; |
25 | 27 | import androidx.test.ext.junit.runners.AndroidJUnit4;
|
26 | 28 | import com.google.common.collect.ImmutableList;
|
27 | 29 | import org.junit.Before;
|
@@ -57,6 +59,52 @@ public void setUp() {
|
57 | 59 | when(player.getApplicationLooper()).thenReturn(Looper.myLooper());
|
58 | 60 | }
|
59 | 61 |
|
| 62 | + @Test |
| 63 | + public void |
| 64 | + getCurrentTimelineWithCommandCheck_withoutCommandGetTimelineAndGetCurrentMediaItem_isEmpty() { |
| 65 | + when(player.isCommandAvailable(Player.COMMAND_GET_TIMELINE)).thenReturn(false); |
| 66 | + when(player.isCommandAvailable(Player.COMMAND_GET_CURRENT_MEDIA_ITEM)).thenReturn(false); |
| 67 | + when(player.getCurrentTimeline()).thenReturn(new FakeTimeline(/* windowCount= */ 3)); |
| 68 | + |
| 69 | + Timeline currentTimeline = playerWrapper.getCurrentTimelineWithCommandCheck(); |
| 70 | + |
| 71 | + assertThat(currentTimeline.isEmpty()).isTrue(); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + public void getCurrentTimelineWithCommandCheck_withoutCommandGetTimelineWhenEmpty_isEmpty() { |
| 76 | + when(player.isCommandAvailable(Player.COMMAND_GET_TIMELINE)).thenReturn(false); |
| 77 | + when(player.isCommandAvailable(Player.COMMAND_GET_CURRENT_MEDIA_ITEM)).thenReturn(true); |
| 78 | + when(player.getCurrentTimeline()).thenReturn(Timeline.EMPTY); |
| 79 | + |
| 80 | + Timeline currentTimeline = playerWrapper.getCurrentTimelineWithCommandCheck(); |
| 81 | + |
| 82 | + assertThat(currentTimeline.isEmpty()).isTrue(); |
| 83 | + } |
| 84 | + |
| 85 | + @Test |
| 86 | + public void |
| 87 | + getCurrentTimelineWithCommandCheck_withoutCommandGetTimelineWhenMultipleItems_hasSingleItemTimeline() { |
| 88 | + when(player.isCommandAvailable(Player.COMMAND_GET_TIMELINE)).thenReturn(false); |
| 89 | + when(player.isCommandAvailable(Player.COMMAND_GET_CURRENT_MEDIA_ITEM)).thenReturn(true); |
| 90 | + when(player.getCurrentTimeline()).thenReturn(new FakeTimeline(/* windowCount= */ 3)); |
| 91 | + |
| 92 | + Timeline currentTimeline = playerWrapper.getCurrentTimelineWithCommandCheck(); |
| 93 | + |
| 94 | + assertThat(currentTimeline.getWindowCount()).isEqualTo(1); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + public void getCurrentTimelineWithCommandCheck_withCommandGetTimeline_returnOriginalTimeline() { |
| 99 | + when(player.isCommandAvailable(Player.COMMAND_GET_TIMELINE)).thenReturn(true); |
| 100 | + when(player.isCommandAvailable(Player.COMMAND_GET_CURRENT_MEDIA_ITEM)).thenReturn(false); |
| 101 | + when(player.getCurrentTimeline()).thenReturn(new FakeTimeline(/* windowCount= */ 3)); |
| 102 | + |
| 103 | + Timeline currentTimeline = playerWrapper.getCurrentTimelineWithCommandCheck(); |
| 104 | + |
| 105 | + assertThat(currentTimeline.getWindowCount()).isEqualTo(3); |
| 106 | + } |
| 107 | + |
60 | 108 | @Test
|
61 | 109 | public void createSessionPositionInfoForBundling() {
|
62 | 110 | int testAdGroupIndex = 12;
|
|
0 commit comments