BaggersListEntryView extends BaseRecyclerViewHolder<BaggersListEntry> { void setTextIfAny(TextView textview, CharSequence text) { if (TextUtils.isEmpty(text)) { textview.setVisibility(View.GONE); } else { textview.setText(text); textview.setVisibility(View.VISIBLE); } } BaggersListEntryView(ViewGroup parent); @Override void bindData(@NonNull BaggersListEntry data); @OnClick(R.id.bagger_entry_invite_button) void onInviteButtonClicked(Button button);  }
@Test public void should_set_textview_visibility_to_gone_if_text_is_null() { TextView tv = new TextView(RuntimeEnvironment.application); tv.setVisibility(View.VISIBLE); view.setTextIfAny(tv, null); assertThat(tv.getVisibility()).isEqualTo(View.GONE); }
@Test public void should_set_textview_visibility_to_gone_if_text_is_empty() { TextView tv = new TextView(RuntimeEnvironment.application); tv.setVisibility(View.VISIBLE); view.setTextIfAny(tv, ""); assertThat(tv.getVisibility()).isEqualTo(View.GONE); }
@Test public void should_set_text_and_textview_visibility_to_visible() { TextView tv = new TextView(RuntimeEnvironment.application); tv.setVisibility(View.GONE); view.setTextIfAny(tv, "Hello!"); assertThat(tv.getVisibility()).isEqualTo(View.VISIBLE); assertThat(tv.getText().toString()).isEqualTo("Hello!"); }