### Question:
ViewAddOnFactories { public ViewAddOn createViewAddOn(Object view) { Class<?> viewClass = view.getClass(); ViewAddOnFactory factory = findMostSuitable(viewClass); if (factory == null) { throw new RuntimeException("no ViewAddOn registered for " + viewClass.getName()); } return factory.create(view); } ViewAddOnFactories(Map<Class<?>, ViewAddOnFactory> mappings); ViewAddOn createViewAddOn(Object view);  }### Answer:
@Test(expected=RuntimeException.class) public void givenViewWithoutViewAddOnFactory_whenCreateViewAddOn_thenThrowError() { Map<Class<?>, ViewAddOnFactory> emptyMappings = Collections.emptyMap(); ViewAddOnFactories factories = new ViewAddOnFactories(emptyMappings); factories.createViewAddOn(view); }
@Test public void givenViewWithViewAddOnFactory_whenCreateViewAddOn_thenReturnInstance() { ViewAddOnFactory factory = mock(ViewAddOnFactory.class); ViewAddOn viewAddOn = mock(ViewAddOn.class); when(factory.create(view)).thenReturn(viewAddOn); Map<Class<?>, ViewAddOnFactory> mappings = Maps.newHashMap(); mappings.put(view.getClass(), factory); ViewAddOnFactories factories = new ViewAddOnFactories(mappings); ViewAddOn actual = factories.createViewAddOn(view); assertThat(actual, is(viewAddOn)); }