use of androidx.media3.common.PercentageRating in project media by androidx.
the class MediaUtilsTest method assertRatingEquals.
void assertRatingEquals(Rating rating, RatingCompat ratingCompat) {
if (rating == null && ratingCompat == null) {
return;
}
assertThat(rating.isRated()).isEqualTo(ratingCompat.isRated());
if (rating instanceof HeartRating) {
assertThat(ratingCompat.getRatingStyle()).isEqualTo(RatingCompat.RATING_HEART);
assertThat(((HeartRating) rating).isHeart()).isEqualTo(ratingCompat.hasHeart());
} else if (rating instanceof ThumbRating) {
assertThat(ratingCompat.getRatingStyle()).isEqualTo(RatingCompat.RATING_THUMB_UP_DOWN);
assertThat(((ThumbRating) rating).isThumbsUp()).isEqualTo(ratingCompat.isThumbUp());
} else if (rating instanceof StarRating) {
StarRating starRating = (StarRating) rating;
switch(starRating.getMaxStars()) {
case 3:
assertThat(ratingCompat.getRatingStyle()).isEqualTo(RatingCompat.RATING_3_STARS);
break;
case 4:
assertThat(ratingCompat.getRatingStyle()).isEqualTo(RatingCompat.RATING_4_STARS);
break;
case 5:
assertThat(ratingCompat.getRatingStyle()).isEqualTo(RatingCompat.RATING_5_STARS);
break;
// fall out
default:
}
assertThat(starRating.getStarRating()).isEqualTo(ratingCompat.getStarRating());
} else if (rating instanceof PercentageRating) {
assertThat(ratingCompat.getRatingStyle()).isEqualTo(RatingCompat.RATING_PERCENTAGE);
assertThat(((PercentageRating) rating).getPercent()).isEqualTo(ratingCompat.getPercentRating());
}
}
Aggregations