Skip to content

Commit

Permalink
Check bundles in MediaItem to verify keys are skipped
Browse files Browse the repository at this point in the history
Added another check in each of these tests to make sure we don't add keys to bundle for fields with default values.

Also fixed comments of similar changes in `AdPlaybackStateTest` and `MediaMetadataTest`.

PiperOrigin-RevId: 499463581
  • Loading branch information
rohitjoins authored and marcbaechinger committed Jan 4, 2023
1 parent d449142 commit 0512164
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,12 @@ public void adPlaybackStateWithNoAds_toBundleSkipsDefaultValues_fromBundleRestor

Bundle adPlaybackStateWithNoAdsBundle = adPlaybackStateWithNoAds.toBundle();

// check Bundle created above, contains no keys.
// Check that default values are skipped when bundling.
assertThat(adPlaybackStateWithNoAdsBundle.keySet()).isEmpty();

AdPlaybackState adPlaybackStateWithNoAdsFromBundle =
AdPlaybackState.CREATOR.fromBundle(adPlaybackStateWithNoAdsBundle);

// check object retrieved from adPlaybackStateWithNoAdsBundle is equal to AdPlaybackState.NONE
assertThat(adPlaybackStateWithNoAdsFromBundle.adsId).isEqualTo(adPlaybackStateWithNoAds.adsId);
assertThat(adPlaybackStateWithNoAdsFromBundle.adGroupCount)
.isEqualTo(adPlaybackStateWithNoAds.adGroupCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,18 @@ public void createDefaultClippingConfigurationInstance_checksDefaultValues() {
}

@Test
public void createDefaultClippingConfigurationInstance_roundTripViaBundle_yieldsEqualInstance() {
public void
createDefaultClippingConfigurationInstance_toBundleSkipsDefaultValues_fromBundleRestoresThem() {
MediaItem.ClippingConfiguration clippingConfiguration =
new MediaItem.ClippingConfiguration.Builder().build();

Bundle clippingConfigurationBundle = clippingConfiguration.toBundle();

// Check that default values are skipped when bundling.
assertThat(clippingConfigurationBundle.keySet()).isEmpty();

MediaItem.ClippingConfiguration clippingConfigurationFromBundle =
MediaItem.ClippingConfiguration.CREATOR.fromBundle(clippingConfiguration.toBundle());
MediaItem.ClippingConfiguration.CREATOR.fromBundle(clippingConfigurationBundle);

assertThat(clippingConfigurationFromBundle).isEqualTo(clippingConfiguration);
}
Expand Down Expand Up @@ -558,12 +564,18 @@ public void createDefaultLiveConfigurationInstance_checksDefaultValues() {
}

@Test
public void createDefaultLiveConfigurationInstance_roundTripViaBundle_yieldsEqualInstance() {
public void
createDefaultLiveConfigurationInstance_toBundleSkipsDefaultValues_fromBundleRestoresThem() {
MediaItem.LiveConfiguration liveConfiguration =
new MediaItem.LiveConfiguration.Builder().build();

Bundle liveConfigurationBundle = liveConfiguration.toBundle();

// Check that default values are skipped when bundling.
assertThat(liveConfigurationBundle.keySet()).isEmpty();

MediaItem.LiveConfiguration liveConfigurationFromBundle =
MediaItem.LiveConfiguration.CREATOR.fromBundle(liveConfiguration.toBundle());
MediaItem.LiveConfiguration.CREATOR.fromBundle(liveConfigurationBundle);

assertThat(liveConfigurationFromBundle).isEqualTo(liveConfiguration);
}
Expand Down Expand Up @@ -832,9 +844,14 @@ public void createDefaultMediaItemInstance_checksDefaultValues() {
}

@Test
public void createDefaultMediaItemInstance_roundTripViaBundle_yieldsEqualInstance() {
public void createDefaultMediaItemInstance_toBundleSkipsDefaultValues_fromBundleRestoresThem() {
MediaItem mediaItem = new MediaItem.Builder().build();

Bundle mediaItemBundle = mediaItem.toBundle();

// Check that default values are skipped when bundling.
assertThat(mediaItemBundle.keySet()).isEmpty();

MediaItem mediaItemFromBundle = MediaItem.CREATOR.fromBundle(mediaItem.toBundle());

assertThat(mediaItemFromBundle).isEqualTo(mediaItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,11 @@ public void toBundleSkipsDefaultValues_fromBundleRestoresThem() {

Bundle mediaMetadataBundle = mediaMetadata.toBundle();

// check Bundle created above, contains no keys.
// Check that default values are skipped when bundling.
assertThat(mediaMetadataBundle.keySet()).isEmpty();

MediaMetadata mediaMetadataFromBundle = MediaMetadata.CREATOR.fromBundle(mediaMetadataBundle);

// check object retrieved from mediaMetadataBundle is equal to mediaMetadata.
assertThat(mediaMetadataFromBundle).isEqualTo(mediaMetadata);
// Extras is not implemented in MediaMetadata.equals(Object o).
assertThat(mediaMetadataFromBundle.extras).isNull();
Expand Down

0 comments on commit 0512164

Please sign in to comment.