Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 committed Sep 13, 2015
1 parent e1903c2 commit bdefdb0
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@
<orderEntry type="library" exported="" name="play-services-base-7.5.0" level="project" />
<orderEntry type="library" exported="" name="glide-3.6.1" level="project" />
<orderEntry type="library" exported="" name="customtabs-23.0.1" level="project" />
<orderEntry type="library" exported="" name="retrofit-1.9.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" name="retrofit-1.9.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" name="palette-v7-23.0.1" level="project" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.mgaetan89.showsrage.adapter;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class ComingEpisodesPagerAdapter_EmptyTest {
private ComingEpisodesPagerAdapter adapter;

public ComingEpisodesPagerAdapter_EmptyTest() {
}

@Before
public void before() {
this.adapter = new ComingEpisodesPagerAdapter(null, null, null);
}

@Test
public void getCount() {
assertThat(this.adapter.getCount()).isEqualTo(0);
}

@After
public void after() {
this.adapter = null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.mgaetan89.showsrage.adapter;

import android.support.v4.app.Fragment;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

public class EpisodePagerAdapter_EmptyTest {
private EpisodePagerAdapter adapter;

@Before
public void before() {
this.adapter = new EpisodePagerAdapter(null, mock(Fragment.class), null);
}

@Test
public void getCount() {
assertThat(this.adapter.getCount()).isEqualTo(0);
}

@After
public void after() {
this.adapter = null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.mgaetan89.showsrage.adapter;

import android.content.res.Resources;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;

import com.mgaetan89.showsrage.EmptyFragmentHostCallback;
import com.mgaetan89.showsrage.R;
import com.mgaetan89.showsrage.fragment.ShowOverviewFragment;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.lang.reflect.Field;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ShowPagerAdapter_EmptyTest {
private ShowPagerAdapter adapter;

@Before
public void before() {
FragmentActivity activity = mock(FragmentActivity.class);
when(activity.getResources()).thenReturn(mock(Resources.class));

Fragment fragment = mock(Fragment.class);

try {
Field fragmentHostField = Fragment.class.getDeclaredField("mHost");
fragmentHostField.setAccessible(true);
fragmentHostField.set(fragment, new EmptyFragmentHostCallback(activity));
} catch (IllegalAccessException ignored) {
} catch (NoSuchFieldException ignored) {
}

when(fragment.getString(R.string.show)).thenReturn("Show");

this.adapter = new ShowPagerAdapter(null, fragment, null);
}

@Test
public void getCount() {
assertThat(this.adapter.getCount()).isEqualTo(1);
}

@Test
public void getItem() {
Fragment fragment = this.adapter.getItem(0);
assertThat(fragment).isInstanceOf(ShowOverviewFragment.class);
assertThat(fragment.getArguments()).isNull();
}

@Test
public void getPageTitle() {
assertThat(this.adapter.getPageTitle(0)).isEqualTo("Show");
}

@After
public void after() {
this.adapter = null;
}
}

0 comments on commit bdefdb0

Please sign in to comment.