@@ -0,0 +1,3475 @@
+/*%0A * Copyright 2016 Martin Kamp Jensen%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.github.mkjensen.dml.ondemand;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertNotNull;%0Aimport static org.mockito.Matchers.isA;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.powermock.api.mockito.PowerMockito.mock;%0Aimport static org.powermock.api.mockito.PowerMockito.spy;%0Aimport static org.powermock.api.mockito.PowerMockito.when;%0Aimport static org.powermock.api.support.membermodification.MemberMatcher.field;%0A%0Aimport android.app.Activity;%0Aimport android.graphics.drawable.Drawable;%0Aimport android.support.v17.leanback.widget.ImageCardView;%0Aimport android.support.v17.leanback.widget.Presenter.ViewHolder;%0Aimport android.view.View;%0Aimport android.view.ViewGroup;%0Aimport android.widget.FrameLayout;%0A%0Aimport com.github.mkjensen.dml.PowerMockRobolectricTest;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.powermock.core.classloader.annotations.PrepareForTest;%0Aimport org.robolectric.Robolectric;%0A%0A/**%0A * Tests for %7B@link VideoPresenter%7D.%0A */%0A@PrepareForTest(Video.class)%0Apublic class VideoPresenterTest extends PowerMockRobolectricTest %7B%0A%0A  private VideoPresenter videoPresenter;%0A%0A  @Before%0A  public void before() %7B%0A    videoPresenter = new VideoPresenter();%0A  %7D%0A%0A  @Test%0A  public void onCreateViewHolder_shouldCreateView() %7B%0A%0A    // When%0A    ViewHolder viewHolder = createViewHolder();%0A%0A    // Then%0A    assertNotNull(viewHolder.view);%0A    assertEquals(ImageCardView.class, viewHolder.view.getClass());%0A  %7D%0A%0A  @Test%0A  public void onBindViewHolder_shouldSetImageAndTitleOfView() throws IllegalAccessException %7B%0A%0A    // Given%0A    ViewHolder viewHolder = createViewHolder();%0A    ImageCardView viewMock = (ImageCardView) spy(viewHolder.view);%0A    setViewHolderView(viewHolder, viewMock);%0A    Video videoMock = mock(Video.class);%0A    String title = %22title%22;%0A    when(videoMock.getTitle()).thenReturn(title);%0A%0A    // When%0A    videoPresenter.onBindViewHolder(viewHolder, videoMock);%0A%0A    // Then%0A    verify(viewMock).setMainImage(isA(Drawable.class));%0A    assertEquals(title, viewMock.getTitleText());%0A  %7D%0A%0A  @Test%0A  public void onUnbindViewHolder_shouldUnsetViewMainImage() throws IllegalAccessException %7B%0A%0A    // Given%0A    ViewHolder viewHolderMock = mock(ViewHolder.class);%0A    ImageCardView viewMock = mock(ImageCardView.class);%0A    setViewHolderView(viewHolderMock, viewMock);%0A%0A    // When%0A    videoPresenter.onUnbindViewHolder(viewHolderMock);%0A%0A    // Then%0A    verify(viewMock).setMainImage(null);%0A  %7D%0A%0A  private ViewHolder createViewHolder() %7B%0A    Activity activity = Robolectric.buildActivity(Activity.class).create().get();%0A    ViewGroup layout = new FrameLayout(activity);%0A    return videoPresenter.onCreateViewHolder(layout);%0A  %7D%0A%0A  private void setViewHolderView(ViewHolder viewHolder, View view) throws IllegalAccessException %7B%0A    field(ViewHolder.class, %22view%22).set(viewHolder, view);%0A  %7D%0A%7D%0A

Add tests for VideoPresenter