@Test @SuppressWarnings("unchecked") public void testHandle() { when(imageProxy.isLoaded()).thenReturn(true); when(icon.getBoundingBox()).thenReturn(new BoundingBox(0d, 0d, ServiceTaskShapeViewHandler.WID_ICON_WIDTH * 2, ServiceTaskShapeViewHandler.WID_ICON_HEIGHT * 2)); tested.handle(task, view); ArgumentCaptor<ImageShapeLoadedHandler> loadedHandlerArgumentCaptor = ArgumentCaptor.forClass(ImageShapeLoadedHandler.class); verify(imageProxy, times(1)).setImageShapeLoadedHandler(loadedHandlerArgumentCaptor.capture()); verify(imageProxy, times(1)).load(eq(WID_ICON_DATA)); ImageShapeLoadedHandler loadedHandler = loadedHandlerArgumentCaptor.getValue(); loadedHandler.onImageShapeLoaded(icon); verify(icon, times(1)).setScale(eq(0.5d), eq(0.5d)); verify(width, times(1)).setValue(WIDTH); verify(height, times(1)).setValue(HEIGHT); } }
@Before @SuppressWarnings("unchecked") public void init() throws Exception { this.task = new ServiceTask(); task.getDimensionsSet().getWidth().setValue(WIDTH); task.getDimensionsSet().getHeight().setValue(HEIGHT); this.task.setName(WID_ID); when(node.getDefinition()).thenReturn(task); when(node.getBounds()).thenReturn(BOUNDS); when(registry.items()).thenReturn(Collections.singleton(DEF)); when(registry.get(eq(WID_ID))).thenReturn(DEF); when(view.getChildren()).thenReturn(Collections.singletonList(imageSvgPrimitive)); when(imageSvgPrimitive.getId()).thenReturn(ServiceTaskShapeViewHandler.WID_ICON_ID); when(imageSvgPrimitive.get()).thenReturn(imagePrimitive); when(imageSvgPrimitive.getPrimitiveId()).thenReturn(ServiceTaskShapeViewHandler.WID_ICON_ID); when(imagePrimitive.getID()).thenReturn(ServiceTaskShapeViewHandler.WID_ICON_ID); when(imagePrimitive.getImageProxy()).thenReturn(imageProxy); this.tested = new ServiceTaskShapeDef(() -> registry, iconDataGlyphGenerator); }
w.setValue(width); if (h != null) { break;
@Override public void handle(final ServiceTask bean, final SVGShapeView<?> view) { // Obtain the work item's icon data url. final String itemIconData = workItemDefinitionRegistry .get() .get(bean.getName()) .getIconDefinition() .getIconData(); final String iconData = null != itemIconData ? itemIconData : WorkItemDefinitionClientUtils.getDefaultIconData(); // Obtain the image element from the svg shape view. final SVGPrimitive svgPrimitive = SVGViewUtils.getPrimitive(view, WID_ICON_ID).get(); // Load the icon data. final Picture icon = (Picture) svgPrimitive.get(); if (hasDataChanged(iconData, icon.getURL())) { forceLoad(icon, iconData, () -> scaleViewIcon(view, icon)); } if (Objects.equals(bean.getDimensionsSet().getHeight().getValue(), 0d) && Objects.equals(bean.getDimensionsSet().getWidth().getValue(), 0d)) { bean.getDimensionsSet().getHeight().setValue(view.getPrimitive().get().getAttributes().getHeight()); bean.getDimensionsSet().getWidth().setValue(view.getPrimitive().get().getAttributes().getWidth()); } }