@Test public void shouldCacheChildViewWhichWasRequestedPreviously() { val parent = givenParentView(); val cachedChildren = new SparseArray<View>(); val viewCache = new ViewCache(parent, cachedChildren); val firstTime = viewCache.getView(1); then(parent).should().findViewById(1); assertThat(firstTime, is(notNullValue())); assertThat(cachedChildren.size(), is(1)); val secondTime = viewCache.getView(1); then(parent).shouldHaveNoMoreInteractions(); assertThat(secondTime, is(notNullValue())); assertThat(cachedChildren.size(), is(1)); }
public View getView(final int id) { return getView(id, View.class); }
ViewCache { public View getView(final int id) { return getView(id, View.class); } }
ViewCache { public View getView(final int id) { return getView(id, View.class); } ViewCache(@NonNull final View parent);   ViewCache(final View parent, final SparseArray<View> cachedChildren); }
ViewCache { public View getView(final int id) { return getView(id, View.class); } ViewCache(@NonNull final View parent);   ViewCache(final View parent, final SparseArray<View> cachedChildren); View getView(final int id); TextView getTextView(final int id); ImageView getImageView(final int id); CheckBox getCheckBox(final int id); RadioButton getRadioButton(final int id); }
ViewCache { public View getView(final int id) { return getView(id, View.class); } ViewCache(@NonNull final View parent);   ViewCache(final View parent, final SparseArray<View> cachedChildren); View getView(final int id); TextView getTextView(final int id); ImageView getImageView(final int id); CheckBox getCheckBox(final int id); RadioButton getRadioButton(final int id);  }