PostViewModel extends ViewModel { public Post getPost() { Post post = new Post(name.get(), content.get(), category.get(), HttpUrl.parse(inReplyTo.get())); if (!this.photo.get().equals("")) { post.setPhoto(this.photo.get()); } if (!this.likeOf.get().equals("")) { post.setLikeOf(HttpUrl.parse(likeOf.get())); } if (!this.bookmarkOf.get().equals("")) { post.setBookmarkOf(HttpUrl.parse(bookmarkOf.get())); } if (!this.postStatus.get().equals("")) { post.setPostStatus((postStatus.get())); } int id = this.checkedVisibility.get(); switch (id) { case R.id.radioButtonPublic: this.visibility.set("public"); break; case R.id.radioButtonUnlisted: this.visibility.set("unlisted"); break; case R.id.radioButtonProtected: this.visibility.set("protected"); break; case R.id.radioButtonPrivate: this.visibility.set("private"); break; } if (!this.visibility.get().equals("")) { post.setVisibility((visibility.get())); } return post; } PostViewModel(); void clear(); void findReplyTo(String urlOrNote); void findLikeOf(String urlOrNote); void findBookmarkOf(String urlOrNote); void setPhoto(String url); Post getPost(); @BindingAdapter("android:visibility") static void setVisibility(View view, Boolean value); final ObservableField<String> name; final ObservableField<String> content; final ObservableField<String> category; final ObservableField<String> inReplyTo; final ObservableField<String> photo; final ObservableField<String> likeOf; final ObservableField<String> bookmarkOf; final ObservableField<String> postStatus; final ObservableField<String> visibility; final ObservableInt checkedVisibility; }
@Test public void postStatusNotSet() { PostViewModel postModel = new PostViewModel(); Post post = postModel.getPost(); assertFalse(post.hasPostStatus()); }
@Test public void postStatusSetToDraft() { PostViewModel postModel = new PostViewModel(); postModel.postStatus.set("draft"); Post post = postModel.getPost(); assertEquals("draft", post.getPostStatus()); }