Android Open Source - libraryofalexandria Art Work Presenter Tests






From Project

Back to project page libraryofalexandria.

License

The source code is released under:

Apache License

If you think the Android project libraryofalexandria 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 alexandria.israelferrer.com.libraryofalexandria;
/*from w  ww  . ja  va 2  s.  c  om*/
import junit.framework.TestCase;

import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;

import java.util.List;

import static alexandria.israelferrer.com.libraryofalexandria.ArtWorkListActivityTests.ARTWORKS;
import static org.mockito.ArgumentCaptor.*;
import static org.mockito.Mockito.only;
import static org.mockito.Mockito.verify;

public class ArtWorkPresenterTests extends TestCase {
    private Display display;
    private Model model;
    private Presenter presenter;

    @Override
    public void setUp() throws Exception {
        super.setUp();
        display = Mockito.mock(Display.class);
        model = Mockito.mock(Model.class);
        presenter = new ArtWorkListPresenter(display, model);
    }

    public void testOnCreate_success() throws Exception {
        presenter.onCreate();
        Callback callback = getCallback();
        callback.success(ARTWORKS);
        verify(display, only()).setAdapter(ARTWORKS);
    }

    public void testOnCreate_failure() throws Exception {
        presenter.onCreate();
        Callback callback = getCallback();
        callback.failure(new Exception());
        verify(display, only()).showError();
    }

    private Callback<List<ArtWork>> getCallback() {
        ArgumentCaptor<Callback> callbackCatcher = forClass(Callback.class);
        verify(model, only()).getArtWorks(callbackCatcher.capture());
        return callbackCatcher.getValue();
    }
}




Java Source Code List

alexandria.israelferrer.com.libraryofalexandria.ArtWorkListActivityTests.java
alexandria.israelferrer.com.libraryofalexandria.ArtWorkListActivity.java
alexandria.israelferrer.com.libraryofalexandria.ArtWorkListPresenter.java
alexandria.israelferrer.com.libraryofalexandria.ArtWorkModelTests.java
alexandria.israelferrer.com.libraryofalexandria.ArtWorkModel.java
alexandria.israelferrer.com.libraryofalexandria.ArtWorkPersistence.java
alexandria.israelferrer.com.libraryofalexandria.ArtWorkPresenterTests.java
alexandria.israelferrer.com.libraryofalexandria.ArtWorkServiceImpl.java
alexandria.israelferrer.com.libraryofalexandria.ArtWorkService.java
alexandria.israelferrer.com.libraryofalexandria.ArtWork.java
alexandria.israelferrer.com.libraryofalexandria.Callback.java
alexandria.israelferrer.com.libraryofalexandria.Display.java
alexandria.israelferrer.com.libraryofalexandria.ItemView.java
alexandria.israelferrer.com.libraryofalexandria.Model.java
alexandria.israelferrer.com.libraryofalexandria.Presenter.java