Android Open Source - filmster Movie List Adapter Spec






From Project

Back to project page filmster.

License

The source code is released under:

Apache License

If you think the Android project filmster listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.doodeec.filmster.MovieList;
/* w  w  w .  java 2  s  . com*/
import android.test.AndroidTestCase;
import android.view.View;
import android.widget.TextView;

import com.doodeec.filmster.Helper;
import com.doodeec.filmster.Mock;
import com.doodeec.filmster.Model.Movie;
import com.doodeec.filmster.R;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Dusan Doodeec Bartos on 1.11.2014.
 *
 * @see com.doodeec.filmster.MovieList.MovieListAdapter
 */
public class MovieListAdapterSpec extends AndroidTestCase {
    private MovieListAdapter mAdapter;

    private Movie firstMovie;
    private Movie secondMovie;
    private Movie thirdMovie;

    public MovieListAdapterSpec() {
        super();
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        JSONObject listDefinition = Mock.REST_MOVIE_LIST();
        JSONArray list = listDefinition.getJSONArray("movies");

        List<Movie> movies = new ArrayList<Movie>();
        firstMovie = new Movie(list.getJSONObject(0));
        secondMovie = new Movie(list.getJSONObject(1));
        thirdMovie = new Movie(list.getJSONObject(2));

        movies.add(firstMovie);
        movies.add(secondMovie);
        movies.add(thirdMovie);

        mAdapter = new MovieListAdapter(movies, null);
    }

    public void testGetView() throws Exception {
        View firstView = mAdapter.getView(0, null, null);

        assertNotNull(firstView);
        assertNotNull(firstView.getTag());
        assertTrue(firstView.getTag() instanceof MovieListItemHolder);

        assertEquals(firstMovie.getTitle(), ((TextView) firstView.findViewById(R.id.movie_title)).getText());
        assertEquals(String.valueOf(firstMovie.getYear()),
                ((TextView) firstView.findViewById(R.id.movie_year)).getText());
        assertEquals(String.format(Helper.getString(R.string.movie_rating), firstMovie.getAudienceRating()),
                ((TextView) firstView.findViewById(R.id.movie_rating)).getText());

        View secondView = mAdapter.getView(1, null, null);

        assertNotNull(secondView);

        assertEquals(secondMovie.getTitle(), ((TextView) secondView.findViewById(R.id.movie_title)).getText());
        assertEquals(String.valueOf(secondMovie.getYear()),
                ((TextView) secondView.findViewById(R.id.movie_year)).getText());
        assertEquals(String.format(Helper.getString(R.string.movie_rating), secondMovie.getAudienceRating()),
                ((TextView) secondView.findViewById(R.id.movie_rating)).getText());

        View thirdView = mAdapter.getView(2, null, null);

        assertNotNull(thirdView);

        assertEquals(thirdMovie.getTitle(), ((TextView) thirdView.findViewById(R.id.movie_title)).getText());
        assertEquals(String.valueOf(thirdMovie.getYear()),
                ((TextView) thirdView.findViewById(R.id.movie_year)).getText());
        assertEquals(String.format(Helper.getString(R.string.movie_rating), thirdMovie.getAudienceRating()),
                ((TextView) thirdView.findViewById(R.id.movie_rating)).getText());
    }

    public void testRecycleView() throws Exception {
        View firstView = mAdapter.getView(0, null, null);
        View secondView = mAdapter.getView(1, firstView, null);

        assertNotNull(secondView);

        assertEquals(secondMovie.getTitle(), ((TextView) secondView.findViewById(R.id.movie_title)).getText());
        assertEquals(String.valueOf(secondMovie.getYear()),
                ((TextView) secondView.findViewById(R.id.movie_year)).getText());
        assertEquals(String.format(Helper.getString(R.string.movie_rating), secondMovie.getAudienceRating()),
                ((TextView) secondView.findViewById(R.id.movie_rating)).getText());
    }

    public void testGetCount() throws Exception {
        assertEquals(3, mAdapter.getCount());
    }

    public void testGetItemId() throws Exception {
        assertEquals(2, mAdapter.getItemId(2));
    }
}




Java Source Code List

com.doodeec.filmster.HelperSpec.java
com.doodeec.filmster.Helper.java
com.doodeec.filmster.ImageCacheSpec.java
com.doodeec.filmster.ImageCache.java
com.doodeec.filmster.MainActivity.java
com.doodeec.filmster.Mock.java
com.doodeec.filmster.ApplicationState.AppStateSpec.java
com.doodeec.filmster.ApplicationState.AppState.java
com.doodeec.filmster.ApplicationState.ConnectionStateChange.java
com.doodeec.filmster.Model.JSONParserSpec.java
com.doodeec.filmster.Model.JSONParser.java
com.doodeec.filmster.Model.MovieDefinitionKeys.java
com.doodeec.filmster.Model.MovieSpec.java
com.doodeec.filmster.Model.Movie.java
com.doodeec.filmster.MovieDetail.MovieDetailFragmentSpec.java
com.doodeec.filmster.MovieDetail.MovieDetailFragment.java
com.doodeec.filmster.MovieList.MovieListActivityInterface.java
com.doodeec.filmster.MovieList.MovieListAdapterSpec.java
com.doodeec.filmster.MovieList.MovieListAdapter.java
com.doodeec.filmster.MovieList.MovieListFragmentSpec.java
com.doodeec.filmster.MovieList.MovieListFragment.java
com.doodeec.filmster.MovieList.MovieListItemHolderSpec.java
com.doodeec.filmster.MovieList.MovieListItemHolder.java
com.doodeec.filmster.Provider.DbHelperSpec.java
com.doodeec.filmster.Provider.DbHelper.java
com.doodeec.filmster.Provider.MovieEntry.java
com.doodeec.filmster.Provider.MovieProviderSpec.java
com.doodeec.filmster.Provider.MovieProvider.java
com.doodeec.filmster.ServerCommunicator.ResourceServiceSpec.java
com.doodeec.filmster.ServerCommunicator.ResourceService.java
com.doodeec.filmster.ServerCommunicator.ResponseListener.BitmapServerResponseListener.java
com.doodeec.filmster.ServerCommunicator.ResponseListener.JSONServerResponseListener.java
com.doodeec.filmster.ServerCommunicator.ResponseListener.ServerResponseListener.java
com.doodeec.filmster.ServerCommunicator.ServerRequest.ErrorResponseSpec.java
com.doodeec.filmster.ServerCommunicator.ServerRequest.ErrorResponse.java
com.doodeec.filmster.ServerCommunicator.ServerRequest.ServerRequestInterface.java
com.doodeec.filmster.ServerCommunicator.ServerRequest.ServerRequestSpec.java
com.doodeec.filmster.ServerCommunicator.ServerRequest.ServerRequest.java