Move tests relying on unreleased robolectric changes
#cherrypick PiperOrigin-RevId: 679589647
This commit is contained in:
parent
c6434a8276
commit
287f353c87
@ -16,8 +16,6 @@
|
|||||||
package androidx.media3.session;
|
package androidx.media3.session;
|
||||||
|
|
||||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||||
import static androidx.media3.session.DefaultMediaNotificationProvider.DEFAULT_CHANNEL_ID;
|
|
||||||
import static androidx.media3.session.DefaultMediaNotificationProvider.DEFAULT_NOTIFICATION_ID;
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
@ -30,8 +28,6 @@ import static org.mockito.Mockito.when;
|
|||||||
import static org.robolectric.Shadows.shadowOf;
|
import static org.robolectric.Shadows.shadowOf;
|
||||||
|
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationChannel;
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@ -61,9 +57,7 @@ import org.mockito.InOrder;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.robolectric.Robolectric;
|
import org.robolectric.Robolectric;
|
||||||
import org.robolectric.Shadows;
|
|
||||||
import org.robolectric.shadows.ShadowLooper;
|
import org.robolectric.shadows.ShadowLooper;
|
||||||
import org.robolectric.shadows.ShadowNotificationManager;
|
|
||||||
|
|
||||||
/** Tests for {@link DefaultMediaNotificationProvider}. */
|
/** Tests for {@link DefaultMediaNotificationProvider}. */
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@ -977,76 +971,6 @@ public class DefaultMediaNotificationProviderTest {
|
|||||||
.isEqualTo(context.getString(R.string.media3_controls_play_description));
|
.isEqualTo(context.getString(R.string.media3_controls_play_description));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void provider_idsNotSpecified_usesDefaultIds() {
|
|
||||||
Context context = ApplicationProvider.getApplicationContext();
|
|
||||||
DefaultMediaNotificationProvider defaultMediaNotificationProvider =
|
|
||||||
new DefaultMediaNotificationProvider.Builder(context).build();
|
|
||||||
BitmapLoader mockBitmapLoader = mock(BitmapLoader.class);
|
|
||||||
when(mockBitmapLoader.loadBitmapFromMetadata(any())).thenReturn(null);
|
|
||||||
Player player = new TestExoPlayerBuilder(context).build();
|
|
||||||
MediaSession mediaSession =
|
|
||||||
new MediaSession.Builder(context, player).setBitmapLoader(mockBitmapLoader).build();
|
|
||||||
DefaultActionFactory defaultActionFactory =
|
|
||||||
new DefaultActionFactory(Robolectric.setupService(TestService.class));
|
|
||||||
|
|
||||||
MediaNotification notification =
|
|
||||||
defaultMediaNotificationProvider.createNotification(
|
|
||||||
mediaSession,
|
|
||||||
ImmutableList.of(),
|
|
||||||
defaultActionFactory,
|
|
||||||
mock(MediaNotification.Provider.Callback.class));
|
|
||||||
mediaSession.release();
|
|
||||||
player.release();
|
|
||||||
|
|
||||||
assertThat(notification.notificationId).isEqualTo(DEFAULT_NOTIFICATION_ID);
|
|
||||||
assertThat(notification.notification.getChannelId()).isEqualTo(DEFAULT_CHANNEL_ID);
|
|
||||||
ShadowNotificationManager shadowNotificationManager =
|
|
||||||
Shadows.shadowOf(
|
|
||||||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE));
|
|
||||||
assertHasNotificationChannel(
|
|
||||||
shadowNotificationManager.getNotificationChannels(),
|
|
||||||
/* channelId= */ DEFAULT_CHANNEL_ID,
|
|
||||||
/* channelName= */ context.getString(R.string.default_notification_channel_name));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void provider_withCustomIds_notificationsUseCustomIds() {
|
|
||||||
Context context = ApplicationProvider.getApplicationContext();
|
|
||||||
DefaultMediaNotificationProvider defaultMediaNotificationProvider =
|
|
||||||
new DefaultMediaNotificationProvider.Builder(context)
|
|
||||||
.setNotificationId(/* notificationId= */ 2)
|
|
||||||
.setChannelId(/* channelId= */ "customChannelId")
|
|
||||||
.setChannelName(/* channelNameResourceId= */ R.string.media3_controls_play_description)
|
|
||||||
.build();
|
|
||||||
BitmapLoader mockBitmapLoader = mock(BitmapLoader.class);
|
|
||||||
when(mockBitmapLoader.loadBitmapFromMetadata(any())).thenReturn(null);
|
|
||||||
Player player = new TestExoPlayerBuilder(context).build();
|
|
||||||
MediaSession mediaSession =
|
|
||||||
new MediaSession.Builder(context, player).setBitmapLoader(mockBitmapLoader).build();
|
|
||||||
DefaultActionFactory defaultActionFactory =
|
|
||||||
new DefaultActionFactory(Robolectric.setupService(TestService.class));
|
|
||||||
|
|
||||||
MediaNotification notification =
|
|
||||||
defaultMediaNotificationProvider.createNotification(
|
|
||||||
mediaSession,
|
|
||||||
ImmutableList.of(),
|
|
||||||
defaultActionFactory,
|
|
||||||
mock(MediaNotification.Provider.Callback.class));
|
|
||||||
mediaSession.release();
|
|
||||||
player.release();
|
|
||||||
|
|
||||||
assertThat(notification.notificationId).isEqualTo(2);
|
|
||||||
assertThat(notification.notification.getChannelId()).isEqualTo("customChannelId");
|
|
||||||
ShadowNotificationManager shadowNotificationManager =
|
|
||||||
Shadows.shadowOf(
|
|
||||||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE));
|
|
||||||
assertHasNotificationChannel(
|
|
||||||
shadowNotificationManager.getNotificationChannels(),
|
|
||||||
/* channelId= */ "customChannelId",
|
|
||||||
/* channelName= */ context.getString(R.string.media3_controls_play_description));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void provider_withCustomNotificationIdProvider_notificationsUseCustomId() {
|
public void provider_withCustomNotificationIdProvider_notificationsUseCustomId() {
|
||||||
Context context = ApplicationProvider.getApplicationContext();
|
Context context = ApplicationProvider.getApplicationContext();
|
||||||
@ -1200,43 +1124,6 @@ public class DefaultMediaNotificationProviderTest {
|
|||||||
assertThat(NotificationCompat.getContentTitle(notification.notification)).isNull();
|
assertThat(NotificationCompat.getContentTitle(notification.notification)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link DefaultMediaNotificationProvider} is designed to be extendable. Public constructor
|
|
||||||
* should not be removed.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void createsProviderUsingConstructor_idsNotSpecified_usesDefaultIds() {
|
|
||||||
Context context = ApplicationProvider.getApplicationContext();
|
|
||||||
DefaultMediaNotificationProvider defaultMediaNotificationProvider =
|
|
||||||
new DefaultMediaNotificationProvider(context);
|
|
||||||
BitmapLoader mockBitmapLoader = mock(BitmapLoader.class);
|
|
||||||
when(mockBitmapLoader.loadBitmapFromMetadata(any())).thenReturn(null);
|
|
||||||
Player player = new TestExoPlayerBuilder(context).build();
|
|
||||||
MediaSession mediaSession =
|
|
||||||
new MediaSession.Builder(context, player).setBitmapLoader(mockBitmapLoader).build();
|
|
||||||
DefaultActionFactory defaultActionFactory =
|
|
||||||
new DefaultActionFactory(Robolectric.setupService(TestService.class));
|
|
||||||
|
|
||||||
MediaNotification notification =
|
|
||||||
defaultMediaNotificationProvider.createNotification(
|
|
||||||
mediaSession,
|
|
||||||
/* customLayout= */ ImmutableList.of(),
|
|
||||||
defaultActionFactory,
|
|
||||||
/* onNotificationChangedCallback= */ mock(MediaNotification.Provider.Callback.class));
|
|
||||||
mediaSession.release();
|
|
||||||
player.release();
|
|
||||||
|
|
||||||
assertThat(notification.notificationId).isEqualTo(DEFAULT_NOTIFICATION_ID);
|
|
||||||
assertThat(notification.notification.getChannelId()).isEqualTo(DEFAULT_CHANNEL_ID);
|
|
||||||
ShadowNotificationManager shadowNotificationManager =
|
|
||||||
Shadows.shadowOf(
|
|
||||||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE));
|
|
||||||
assertHasNotificationChannel(
|
|
||||||
shadowNotificationManager.getNotificationChannels(),
|
|
||||||
/* channelId= */ DEFAULT_CHANNEL_ID,
|
|
||||||
/* channelName= */ context.getString(R.string.default_notification_channel_name));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extends {@link DefaultMediaNotificationProvider} and overrides all known protected methods. If
|
* Extends {@link DefaultMediaNotificationProvider} and overrides all known protected methods. If
|
||||||
* by accident we change the signature of the class in a way that affects inheritance, this test
|
* by accident we change the signature of the class in a way that affects inheritance, this test
|
||||||
@ -1279,22 +1166,6 @@ public class DefaultMediaNotificationProviderTest {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertHasNotificationChannel(
|
|
||||||
List<NotificationChannel> notificationChannels, String channelId, String channelName) {
|
|
||||||
boolean found = false;
|
|
||||||
for (NotificationChannel notificationChannel : notificationChannels) {
|
|
||||||
found =
|
|
||||||
notificationChannel.getId().equals(channelId)
|
|
||||||
// NotificationChannel.getName() is CharSequence. Use String#contentEquals instead
|
|
||||||
// because CharSequence.equals() has undefined behavior.
|
|
||||||
&& channelName.contentEquals(notificationChannel.getName());
|
|
||||||
if (found) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assertThat(found).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Player createPlayerWithMetadata(MediaMetadata mediaMetadata) {
|
private Player createPlayerWithMetadata(MediaMetadata mediaMetadata) {
|
||||||
return createPlayerWithMetadata(mediaMetadata, /* isMetadataCommandAvailable= */ true);
|
return createPlayerWithMetadata(mediaMetadata, /* isMetadataCommandAvailable= */ true);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user