TheMovieDb API – Part 8 – Show me more info!

Sample ui view for movie details

Quickly open android studio! Welcome back to this series on implementing TheMovieDb API. As always remember all the code for this series will be in this GitHub repo today we are setting base to show off movie details!

Let’s begin! First since we are doing test driven development we want to keep our implementation separate, in other words, business logic outside of the UI. Create a MovieDetailsContract interface with the following:

public interface MovieDetailsContract {

    interface View {

        void setMoviePoster(String moviePoster);

        void setMovieBackdropImage(String backdropImage);

        void setTitle(String title);

        void setOverview(String overview);

        void setPopularity(Double popularity);

        void setReleaseDate(String releaseDate);

    interface UserActionsListener {
        void showMovieDetails();

Nothing too fancy here, under the View interface we have the properties we are going to display. You can add as many as you like, remeber API is huge!

Next  let’s create the movie details presenter that will take care of things, in our case it would implement the showMovieDetails() method within the UserActionsListener interface:

public class MovieDetailsPresenter extends BasePresenter
        implements MovieDetailsContract.UserActionsListener {

    private MovieDetailsContract.View movieDetailsView;
    private Movie movie;

    public MovieDetailsPresenter(Movie movie, MovieDetailsContract.View movieDetailsView) { = movie;
        this.movieDetailsView = movieDetailsView;

    public void showMovieDetails() {
        if (IsNotEmpty(movie.backdrop_path)) {
            movieDetailsView.setMovieBackdropImage(Image.BASE_URL + Image.SIZE_W500 + movie.backdrop_path);
        if (IsNotEmpty(movie.poster_path)) {
            movieDetailsView.setMoviePoster(Image.BASE_URL + Image.SIZE_W500 + movie.poster_path);
        movieDetailsView.setPopularity((movie.popularity == null) ? 0 : movie.popularity);
        movieDetailsView.setReleaseDate((String) android.text.format.DateFormat.format("yyyy", movie.release_date));

Once again we are just simply mapping out properties to their respective view contract. Easy right!

Now testing time, I have created MovieDetailsPresenterTests unit test class under my test package and tested out all my methods in the MovieDetailsContract.View interface:

public class MovieDetailsPresenterTests {

    private MovieDetailsPresenter moviesPresenter;

    MovieDetailsContract.View moviesView;

    public void setupNotesPresenter() {
        // Mockito has a very convenient way to inject mocks by using the @Mock annotation. To
        // inject the mocks in the test the initMocks method needs to be called.
        com.jrosa.moviezone.domain.Movie movie = new com.jrosa.moviezone.domain.Movie(); = 12345;
        movie.title = "foo";
        movie.overview = "an awesome foo movie";
        movie.popularity = 10.0;
        movie.backdrop_path = "";
        movie.poster_path = "";

        moviesPresenter = new MovieDetailsPresenter(movie, moviesView);

    public void movieDetailsView_setMoviePoster() {
        //Given the following movie poster
        //image should have being placed

    public void movieDetailsView_setBackdropImage() {
        //Given the following backdrop image
        //image should have being placed

    public void movieDetailsView_setTitle() {
        //Set  title
        moviesView.setTitle("John Doe Adventures");
        //Check that it was successfully set.
        verify(moviesView).setTitle("John Doe Adventures");

    public void movieDetailsView_setOverview() {
        //clear movie list.
        moviesView.setOverview("John Doe Adventures is a cool movie");
        //Check that it was successfully set.
        verify(moviesView).setOverview("John Doe Adventures is a cool movie");

    public void movieDetailsView_setPopularity() {
        //check popularity

    public void movieDetailsView_setReleaseYear() {
        //check popularity

Awesome! For now I’m leaving it there so you can explore the additional properties from a Movie object in API and decide if you want to add more! In the next blog post we will finish up by creating the MovieDetailsFragment, layout and mapped it all out!

Keep practicing,


Please follow and like us:
Joel Sosa

Author: Joel Sosa

Android nanodegree holder | Graduate Student @GeorgiaTech CS Interactive Intelligence | @gdgpuertorico Organizer

1 thought on “TheMovieDb API – Part 8 – Show me more info!”

Comments are closed.