BPIViewHolder extends RecyclerView.ViewHolder { public void bind(BPI item) { if (date != null) { date.setText(simpleDateFormat.format(item.getDate())); } SpannableStringBuilder closeText = new SpannableStringBuilder(String.format("$%.2f", item.getClose())); if (largeCloseTextSize) { closeText.setSpan(new RelativeSizeSpan(0.4f), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } close.setText(closeText); int changeTextColorRes = R.color.textColorSecondary; String changeText = ""; String changeArrow = ""; if (item.getChange() != null) { changeText = String.format("%.2f%%", item.getChange() * 100); if (item.getChange() > 0) { changeArrow = " ▲"; changeTextColorRes = R.color.bpiChangeIncrease; } else if (item.getChange() < 0) { changeArrow = " ▼"; changeTextColorRes = R.color.bpiChangeDecrease; } } change.setText(changeText + changeArrow); change.setTextColor(change.getResources().getColor(changeTextColorRes)); } BPIViewHolder(View itemView, SimpleDateFormat simpleDateFormat); void bind(BPI item);  }
@Test public void bind_increase() { BPI bpi = new BPI(new Date(System.currentTimeMillis()), 225.25f, 0.0124f); viewHolder.bind(bpi); if (viewHolder.date != null) { ANDROID.assertThat(viewHolder.date).hasTextString(simpleDateFormat.format(bpi.getDate())); } ANDROID.assertThat(viewHolder.close).hasTextString("$" + bpi.getClose()); ANDROID.assertThat(viewHolder.change).hasTextString((bpi.getChange() * 100) + "% ▲"); ANDROID.assertThat(viewHolder.change).hasCurrentTextColor(getColor(R.color.bpiChangeIncrease)); }
@Test public void bind_decrease() { BPI bpi = new BPI(new Date(System.currentTimeMillis()), 225.25f, - 0.0124f); viewHolder.bind(bpi); if (viewHolder.date != null) { ANDROID.assertThat(viewHolder.date).hasTextString(simpleDateFormat.format(bpi.getDate())); } ANDROID.assertThat(viewHolder.close).hasTextString("$" + bpi.getClose()); ANDROID.assertThat(viewHolder.change).hasTextString((bpi.getChange() * 100) + "% ▼"); ANDROID.assertThat(viewHolder.change).hasCurrentTextColor(getColor(R.color.bpiChangeDecrease)); }
@Test public void bind_noChange() { BPI bpi = new BPI(new Date(System.currentTimeMillis()), 225.25f); viewHolder.bind(bpi); if (viewHolder.date != null) { ANDROID.assertThat(viewHolder.date).hasTextString(simpleDateFormat.format(bpi.getDate())); } ANDROID.assertThat(viewHolder.close).hasTextString("$" + bpi.getClose()); ANDROID.assertThat(viewHolder.change).hasTextString(""); }