Created
August 27, 2015 10:17
-
-
Save hitherejoe/543368f9326cf79f5193 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(RobolectricTestRunner.class) | |
@Config(constants = BuildConfig.class, sdk = DefaultConfig.EMULATE_SDK, manifest = DefaultConfig.MANIFEST) | |
public class PostViewModelTest { | |
private Context mContext; | |
private PostViewModel mPostViewModel; | |
private Post mPost; | |
@Before | |
public void setUp() { | |
mContext = RuntimeEnvironment.application; | |
mPost = MockModelsUtil.createMockStory(); | |
mPostViewModel = new PostViewModel(mContext, mPost, false); | |
} | |
@Test | |
public void shouldGetPostScore() throws Exception { | |
String postScore = mPost.score + mContext.getResources().getString(R.string.story_points); | |
assertEquals(mPostViewModel.getPostScore(), postScore); | |
} | |
@Test | |
public void shouldGetPostTitle() throws Exception { | |
assertEquals(mPostViewModel.getPostTitle(), mPost.title); | |
} | |
@Test | |
public void shouldGetPostAuthor() throws Exception { | |
String author = mContext.getString(R.string.text_post_author, mPost.by); | |
assertEquals(mPostViewModel.getPostAuthor().toString(), author); | |
} | |
@Test | |
public void shouldGetCommentsVisibility() throws Exception { | |
// Our mock post is of the type story, so this should return gone | |
mPost.kids = null; | |
assertEquals(mPostViewModel.getCommentsVisibility(), View.GONE); | |
mPost.kids = new ArrayList<>(); | |
assertEquals(mPostViewModel.getCommentsVisibility(), View.VISIBLE); | |
mPost.kids = null; | |
mPost.postType = Post.PostType.ASK; | |
assertEquals(mPostViewModel.getCommentsVisibility(), View.VISIBLE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment