RendererManager { public RendererLibrary getRendererForDisplayer(DisplayerSettings target) { if (!StringUtils.isBlank(target.getRenderer())) { RendererLibrary targetRenderer = _getRendererByUUID(target.getRenderer()); if (targetRenderer != null) return targetRenderer; } List<RendererLibrary> renderersSupported = getRenderersForType(target.getType(), target.getSubtype()); RendererLibrary defaultRenderer = getDefaultRenderer(target.getType()); for (RendererLibrary rendererLibrary : renderersSupported) { if (defaultRenderer != null && rendererLibrary.equals(defaultRenderer)) { return defaultRenderer; } } if (!renderersSupported.isEmpty()) return renderersSupported.get(0); throw new RuntimeException(i18n.renderermanager_renderer_not_available(target.getType().name())); } RendererManager(); @Inject  RendererManager(SyncBeanManager beanManager, Caller<RendererSettingsService> rendererSettingsService); List<RendererLibrary> getRenderers(); RendererLibrary getDefaultRenderer(DisplayerType displayerType); void setDefaultRenderer(DisplayerType displayerType, String rendererName); List<RendererLibrary> getRenderersForType(DisplayerType displayerType); List<RendererLibrary> getRenderersForType(DisplayerType type, DisplayerSubType subType); RendererLibrary getRendererByUUID(String renderer); RendererLibrary getRendererByName(String renderer); RendererLibrary getRendererForType(DisplayerType displayerType); RendererLibrary getRendererForDisplayer(DisplayerSettings target); boolean isTypeSupported(DisplayerType type);  }
@Test public void rendererByDisplayerTest() { DisplayerSettings settings = mock(DisplayerSettings.class); when(settings.getRenderer()).thenReturn(REND1_UUID); when(settings.getType()).thenReturn(BARCHART); when(settings.getSubtype()).thenReturn(BAR); RendererLibrary lib = rendererManager.getRendererForDisplayer(settings); assertNotNull(lib); assertEquals(REND1_UUID, lib.getUUID()); }
@Test public void rendererByDisplayerWithoutUUIDTest() { DisplayerSettings settings = mock(DisplayerSettings.class); when(settings.getType()).thenReturn(BARCHART); when(settings.getSubtype()).thenReturn(BAR); RendererLibrary lib = rendererManager.getRendererForDisplayer(settings); assertNotNull(lib); assertEquals(DEFAULT_REND_FOR_BARCHART_UUID, lib.getUUID()); }
@Test(expected=RuntimeException.class) public void rendererByDisplayerTypeNotSupportedTest() { DisplayerSettings settings = mock(DisplayerSettings.class); when(settings.getType()).thenReturn(MAP); when(settings.getSubtype()).thenReturn(MAP_MARKERS); rendererManager.getRendererForDisplayer(settings); }