Movie implements Parcelable { public static String getFormattedUserRating(double userRating) { double rounded = round(userRating, 2); String formatted; if (rounded == (long) rounded) { formatted = String.format(Locale.getDefault(), "%d", (long) rounded); } else { formatted = String.format("%s", rounded); } return formatted.concat(USER_RATING_APPEND); } Movie(String title, String posterImageUrl, String backdropImageUrl, String synopsis,
            double userRating, Date releaseDate); protected  Movie(Parcel in); @BindingAdapter({"posterImageUrl"}) static void loadPosterImage(ImageView view, String imageUrl); @BindingAdapter({"backdropImageUrl"}) static void loadBackdropImage(ImageView view, String imageUrl); @BindingAdapter({"userRating"}) static void loadUserRating(TextView view, double userRating); static String getFormattedUserRating(double userRating); @BindingAdapter({"releaseDate"}) static void loadReleaseDate(TextView view, Date releaseDate); static String getFormattedReleaseDate(Date releaseDate); String getTitle(); String getPosterImageUrl(); String getBackdropImageUrl(); String getSynopsis(); double getUserRating(); Date getReleaseDate(); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); static final Parcelable.Creator<Movie> CREATOR; static final String USER_RATING_APPEND; static final double POSTER_IMAGE_ASPECT_RATIO; static final double BACKDROP_IMAGE_ASPECT_RATIO; static final DateFormat DATE_FORMAT; }
@Test public void testGetFormattedUserRating() throws Exception { assertEquals("10".concat(Movie.USER_RATING_APPEND), Movie.getFormattedUserRating(9.999999)); assertNotEquals("1".concat(Movie.USER_RATING_APPEND), Movie.getFormattedUserRating(0.99)); assertEquals("1".concat(Movie.USER_RATING_APPEND), Movie.getFormattedUserRating(0.999)); assertEquals("9.45".concat(Movie.USER_RATING_APPEND), Movie.getFormattedUserRating(9.450001)); assertEquals("0".concat(Movie.USER_RATING_APPEND), Movie.getFormattedUserRating(0.0000000001)); assertEquals("8.46".concat(Movie.USER_RATING_APPEND), Movie.getFormattedUserRating(8.455)); }