### Question:
ViewTagsBasedViewAddOns implements ViewAddOns { @Override public ViewAddOn getMostSuitable(Object view) { if(supportsViewTag(view)) { return retrieveFromViewTag((View)view); } else { return viewAddOnFactories.createViewAddOn(view); } } ViewTagsBasedViewAddOns(ViewAddOnFactories viewAddOnFactories, ViewTags<ViewAddOn> viewTags); @Override ViewAddOn getMostSuitable(Object view);  }### Answer:
@Test public void givenViewAddOnNotSetOnTag_whenGetMostSuitable_thenReturnNewViewAddOn() { View view = mock(View.class); ViewAddOn newViewAddOn = mock(ViewAddOn.class); when(factories.createViewAddOn(view)).thenReturn(newViewAddOn); ViewTag<ViewAddOn> viewTag = viewTagHasValue(false); ViewTags<ViewAddOn> viewTags = viewTagsFor(view, viewTag); ViewTagsBasedViewAddOns viewAddOns = new ViewTagsBasedViewAddOns(factories, viewTags); ViewAddOn actual = viewAddOns.getMostSuitable(view); assertThat(actual, is(newViewAddOn)); }
@Test public void givenViewAddOnSetOnTag_whenGetMostSuitable_thenReturnOldViewAddOn() { View view = mock(View.class); ViewAddOn oldViewAddOn = mock(ViewAddOn.class); ViewTag<ViewAddOn> viewTag = viewTagHasValue(true); when(viewTag.get()).thenReturn(oldViewAddOn); ViewTags<ViewAddOn> viewTags = viewTagsFor(view, viewTag); ViewTagsBasedViewAddOns viewAddOns = new ViewTagsBasedViewAddOns(factories, viewTags); ViewAddOn actual = viewAddOns.getMostSuitable(view); assertThat(actual, is(oldViewAddOn)); }
@Test public void givenViewNotSupportTag_whenGetMostSuitable_thenReturnNewViewAddOn() { Object viewNotSupportTag = mock(Object.class); ViewAddOn newViewAddOn = mock(ViewAddOn.class); when(factories.createViewAddOn(viewNotSupportTag)).thenReturn(newViewAddOn); ViewTagsBasedViewAddOns viewAddOns = new ViewTagsBasedViewAddOns(factories, null); ViewAddOn actual = viewAddOns.getMostSuitable(viewNotSupportTag); assertThat(actual, is(newViewAddOn)); }