method2testcases
stringlengths
118
3.08k
### Question: ControlPointControlImpl extends AbstractCanvasHandlerRegistrationControl<AbstractCanvasHandler> implements ControlPointControl<AbstractCanvasHandler> { @Override public void updateControlPoints(final Edge candidate, final ControlPoint[] controlPoints) { execute(canvasCommandFactory.updateControlPointPosition(candidate, controlPoints)); } @Inject ControlPointControlImpl(final CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory, final Event<CanvasSelectionEvent> selectionEvent); @Override void register(final Element element); @Override void addControlPoint(final Edge candidate, final ControlPoint controlPoint, final int index); @Override void updateControlPoints(final Edge candidate, final ControlPoint[] controlPoints); @Override void deleteControlPoint(final Edge candidate, final int index); @Override void setCommandManagerProvider(final CommandManagerProvider<AbstractCanvasHandler> provider); }### Answer: @Test public void testStunnerControlPointsAcceptorMove() { ControlPointControl control = mock(ControlPointControl.class); ControlPointControlImpl.StunnerControlPointsAcceptor acceptor = createStunnerControlPointsAcceptor(control); Point2DArray locationArray = new Point2DArray(new com.ait.lienzo.client.core.types.Point2D(0, 0), new com.ait.lienzo.client.core.types.Point2D(5, 5), new com.ait.lienzo.client.core.types.Point2D(10, 10)); final boolean moveResult = acceptor.move(connector, locationArray); assertTrue(moveResult); ArgumentCaptor<ControlPoint[]> controlPointsExpected = ArgumentCaptor.forClass(ControlPoint[].class); verify(control, times(1)).updateControlPoints(eq(edge), controlPointsExpected.capture()); ControlPoint[] cps = controlPointsExpected.getValue(); assertNotNull(cps); assertEquals(1, cps.length); assertEquals(ControlPoint.build(5, 5), cps[0]); }
### Question: LocationControlImpl extends AbstractCanvasHandlerRegistrationControl<AbstractCanvasHandler> implements LocationControl<AbstractCanvasHandler, Element>, CanvasControl.SessionAware<EditorSession> { @SuppressWarnings("unchecked") private static void ensureDragConstraints(final AbstractCanvas<?> canvas, final ShapeView shapeView) { final Bounds bounds = canvas.getView().getPanel().getLocationConstraints(); ShapeUtils.enforceLocationConstraints(shapeView, bounds); } protected LocationControlImpl(); @Inject LocationControlImpl(final CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory, final Event<ShapeLocationsChangedEvent> shapeLocationsChangedEvent, final Event<CanvasSelectionEvent> selectionEvent); Collection<String> getSelectedIDs(); @Override void bind(final EditorSession session); void handleArrowKeys(final Key... keys); @Override void setCommandManagerProvider(final CommandManagerProvider<AbstractCanvasHandler> provider); @Override @SuppressWarnings("unchecked") void register(final Element element); @Override @SuppressWarnings("unchecked") CommandResult<CanvasViolation> move(final Element[] elements, final Point2D[] locations); }### Answer: @Test public void testEnsureDragConstraints() throws Exception { tested.init(canvasHandler); Bounds bounds = Bounds.create(0d, 0d, 600d, 600d); when(canvasPanel.getLocationConstraints()).thenReturn(bounds); tested.register(element); verify(shapeView, times(1)).setDragBounds(eq(bounds)); }
### Question: DockingAcceptorControlImpl extends AbstractAcceptorControl implements DockingAcceptorControl<AbstractCanvasHandler> { @Override public boolean allow(final Node parent, final Node child) { return evaluate(parent, child, command -> getCommandManager().allow(getCanvasHandler(), command)); } @Inject DockingAcceptorControlImpl(final CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory); @Override boolean allow(final Node parent, final Node child); @Override boolean accept(final Node parent, final Node child); }### Answer: @Test public void testAllow() { tested.init(canvasHandler); final boolean allow = tested.allow(source, docked); assertTrue(allow); verify(commandManager, times(1)).allow(eq(canvasHandler), eq(updateDockNodeCommand)); assertEquals(source, updateDockNodeCommand.getParent()); assertEquals(docked, updateDockNodeCommand.getCandidate()); } @Test public void testAllowNoParent() { tested.init(canvasHandler); final boolean allow = tested.allow(null, docked); assertFalse(allow); verify(commandManager, times(0)).allow(any(AbstractCanvasHandler.class), any(UpdateDockNodeCommand.class)); }
### Question: DockingAcceptorControlImpl extends AbstractAcceptorControl implements DockingAcceptorControl<AbstractCanvasHandler> { @Override public boolean accept(final Node parent, final Node child) { return evaluate(parent, child, command -> getCommandManager().execute(getCanvasHandler(), command)); } @Inject DockingAcceptorControlImpl(final CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory); @Override boolean allow(final Node parent, final Node child); @Override boolean accept(final Node parent, final Node child); }### Answer: @Test public void testAccept() { tested.init(canvasHandler); final boolean accept = tested.accept(source, docked); assertTrue(accept); verify(commandManager, times(1)).execute(eq(canvasHandler), eq(updateDockNodeCommand)); assertEquals(source, updateDockNodeCommand.getParent()); assertEquals(docked, updateDockNodeCommand.getCandidate()); } @Test public void testAceeptNoParent() { tested.init(canvasHandler); final boolean accept = tested.accept(null, docked); assertFalse(accept); verify(commandManager, times(0)).execute(any(AbstractCanvasHandler.class), any(UpdateDockNodeCommand.class)); }
### Question: PreviewDiagramScreen { void showPreview(final ClientSession session) { if (Objects.isNull(session)) { return; } if (session instanceof AbstractSession) { if (Objects.nonNull(previewWidget)) { closePreview(); } previewWidget = sessionPreviews.get(); previewWidget.open((AbstractSession) session, PREVIEW_WIDTH, PREVIEW_HEIGHT, new SessionViewer.SessionViewerCallback<Diagram>() { @Override public void afterCanvasInitialized() { } @Override public void onSuccess() { view.setPreviewWidget(previewWidget.getView()); } @Override public void onError(final ClientRuntimeError error) { LOGGER.log(Level.SEVERE, error.getMessage()); } }); } } protected PreviewDiagramScreen(); @Inject PreviewDiagramScreen(final SessionManager clientSessionManager, final @Any @DMNEditor ManagedInstance<SessionDiagramPreview<AbstractSession>> sessionPreviews, final View view, final DMNDiagramsSession session); @OnStartup @SuppressWarnings("unused") void onStartup(final PlaceRequest placeRequest); @OnOpen @SuppressWarnings("unused") void onOpen(); @OnClose @SuppressWarnings("unused") void onClose(); @WorkbenchPartTitle @SuppressWarnings("unused") String getTitle(); @WorkbenchPartView @SuppressWarnings("unused") IsWidget getWidget(); @WorkbenchContextId @SuppressWarnings("unused") String getMyContextRef(); static final String SCREEN_ID; }### Answer: @Test @SuppressWarnings("unchecked") public void testShowPreview() { tested.showPreview(session); verify(sessionPreview).open(eq(session), anyInt(), anyInt(), sessionViewerCallbackArgumentCaptor.capture()); final SessionViewer.SessionViewerCallback sessionViewerCallback = sessionViewerCallbackArgumentCaptor.getValue(); sessionViewerCallback.onSuccess(); verify(sessionPreview, never()).clear(); verify(view).setPreviewWidget(previewWidget); }
### Question: LienzoMediatorsControl extends AbstractCanvasControl<C> implements MediatorsControl<C> { @Override public MediatorsControl<C> setMinScale(final double minScale) { mediators.setMinScale(minScale); return this; } @Inject LienzoMediatorsControl(final LienzoPanelMediators mediators); @Override MediatorsControl<C> setMinScale(final double minScale); @Override MediatorsControl<C> setMaxScale(final double maxScale); @Override MediatorsControl<C> setZoomFactor(final double factor); @Override MediatorsControl<C> scale(final double factor); @Override MediatorsControl<C> scale(final double sx, final double sy); @Override MediatorsControl<C> translate(final double tx, final double ty); }### Answer: @Test public void testSetMinScale() { tested.setMinScale(0.4d); verify(mediators, times(1)).setMinScale(eq(0.4d)); }
### Question: LienzoMediatorsControl extends AbstractCanvasControl<C> implements MediatorsControl<C> { @Override public MediatorsControl<C> setMaxScale(final double maxScale) { mediators.setMaxScale(maxScale); return this; } @Inject LienzoMediatorsControl(final LienzoPanelMediators mediators); @Override MediatorsControl<C> setMinScale(final double minScale); @Override MediatorsControl<C> setMaxScale(final double maxScale); @Override MediatorsControl<C> setZoomFactor(final double factor); @Override MediatorsControl<C> scale(final double factor); @Override MediatorsControl<C> scale(final double sx, final double sy); @Override MediatorsControl<C> translate(final double tx, final double ty); }### Answer: @Test public void testSetMaxScale() { tested.setMaxScale(0.4d); verify(mediators, times(1)).setMaxScale(eq(0.4d)); }
### Question: LienzoMediatorsControl extends AbstractCanvasControl<C> implements MediatorsControl<C> { @Override public MediatorsControl<C> setZoomFactor(final double factor) { mediators.setZoomFactor(factor); return this; } @Inject LienzoMediatorsControl(final LienzoPanelMediators mediators); @Override MediatorsControl<C> setMinScale(final double minScale); @Override MediatorsControl<C> setMaxScale(final double maxScale); @Override MediatorsControl<C> setZoomFactor(final double factor); @Override MediatorsControl<C> scale(final double factor); @Override MediatorsControl<C> scale(final double sx, final double sy); @Override MediatorsControl<C> translate(final double tx, final double ty); }### Answer: @Test public void testSetZoomFactor() { tested.setZoomFactor(0.4d); verify(mediators, times(1)).setZoomFactor(eq(0.4d)); }
### Question: LienzoMediatorsControl extends AbstractCanvasControl<C> implements MediatorsControl<C> { @Override public MediatorsControl<C> scale(final double factor) { getLayer().scale(factor); return this; } @Inject LienzoMediatorsControl(final LienzoPanelMediators mediators); @Override MediatorsControl<C> setMinScale(final double minScale); @Override MediatorsControl<C> setMaxScale(final double maxScale); @Override MediatorsControl<C> setZoomFactor(final double factor); @Override MediatorsControl<C> scale(final double factor); @Override MediatorsControl<C> scale(final double sx, final double sy); @Override MediatorsControl<C> translate(final double tx, final double ty); }### Answer: @Test public void testScale() { tested.scale(0.2d, 0.4d); verify(layer, times(1)).scale(0.2d, 0.4d); tested.scale(0.5d); verify(layer, times(1)).scale(0.5d); }
### Question: LienzoMediatorsControl extends AbstractCanvasControl<C> implements MediatorsControl<C> { @Override public MediatorsControl<C> translate(final double tx, final double ty) { getLayer().translate(tx, ty); return this; } @Inject LienzoMediatorsControl(final LienzoPanelMediators mediators); @Override MediatorsControl<C> setMinScale(final double minScale); @Override MediatorsControl<C> setMaxScale(final double maxScale); @Override MediatorsControl<C> setZoomFactor(final double factor); @Override MediatorsControl<C> scale(final double factor); @Override MediatorsControl<C> scale(final double sx, final double sy); @Override MediatorsControl<C> translate(final double tx, final double ty); }### Answer: @Test public void testTranslate() { tested.translate(0.2d, 0.4d); verify(layer, times(1)).translate(0.2d, 0.4d); }
### Question: LienzoMediatorsControl extends AbstractCanvasControl<C> implements MediatorsControl<C> { void onCanvasFocusedEvent(final @Observes CanvasFocusedEvent focusedEvent) { if (null != canvas && canvas.equals(focusedEvent.getCanvas())) { mediators.enable(); } } @Inject LienzoMediatorsControl(final LienzoPanelMediators mediators); @Override MediatorsControl<C> setMinScale(final double minScale); @Override MediatorsControl<C> setMaxScale(final double maxScale); @Override MediatorsControl<C> setZoomFactor(final double factor); @Override MediatorsControl<C> scale(final double factor); @Override MediatorsControl<C> scale(final double sx, final double sy); @Override MediatorsControl<C> translate(final double tx, final double ty); }### Answer: @Test public void testOnCanvasFocusedEvent() { CanvasFocusedEvent event = new CanvasFocusedEvent(canvas); tested.onCanvasFocusedEvent(event); verify(mediators, times(1)).enable(); verify(mediators, never()).disable(); }
### Question: LienzoMediatorsControl extends AbstractCanvasControl<C> implements MediatorsControl<C> { void onCanvasLostFocusEvent(final @Observes CanvasLostFocusEvent lostFocusEvent) { if (null != canvas && canvas.equals(lostFocusEvent.getCanvas())) { mediators.disable(); } } @Inject LienzoMediatorsControl(final LienzoPanelMediators mediators); @Override MediatorsControl<C> setMinScale(final double minScale); @Override MediatorsControl<C> setMaxScale(final double maxScale); @Override MediatorsControl<C> setZoomFactor(final double factor); @Override MediatorsControl<C> scale(final double factor); @Override MediatorsControl<C> scale(final double sx, final double sy); @Override MediatorsControl<C> translate(final double tx, final double ty); }### Answer: @Test public void testOnCanvasLostFocusEvent() { CanvasLostFocusEvent event = new CanvasLostFocusEvent(canvas); tested.onCanvasLostFocusEvent(event); verify(mediators, times(1)).disable(); verify(mediators, never()).enable(); }
### Question: LienzoMultipleSelectionControl extends AbstractSelectionControl<H> { @Override protected void onSelect(final Collection<String> uuids) { super.onSelect(uuids); final Collection<ShapeView> shapeViews = uuids.stream() .map(uuid -> getCanvasHandler().getCanvas().getShape(uuid)) .filter(Objects::nonNull) .map(org.kie.workbench.common.stunner.core.client.shape.Shape::getShapeView) .collect(Collectors.toList()); shapeViews.stream() .filter(view -> view instanceof WiresShapeView) .forEach(view -> getSelectionManager().getSelectedItems().add((WiresShape) view)); shapeViews.stream() .filter(view -> view instanceof WiresConnectorView) .forEach(view -> getSelectionManager().getSelectedItems().add((WiresConnector) view)); } @Inject LienzoMultipleSelectionControl(final Event<CanvasSelectionEvent> canvasSelectionEvent, final Event<CanvasClearSelectionEvent> clearSelectionEvent); LienzoMultipleSelectionControl(final MapSelectionControl<H> selectionControl, final Event<CanvasSelectionEvent> canvasSelectionEvent, final Event<CanvasClearSelectionEvent> clearSelectionEvent, final CursoredSelectionShapeProvider selectionShapeProvider); }### Answer: @Test public void testOnSelectEvent() { final SelectionManager.SelectedItems selectedItems = mock(SelectionManager.SelectedItems.class); when(selectionManager.getSelectedItems()).thenReturn(selectedItems); tested.init(canvasHandler); tested.register(element); tested.onSelect(Collections.singletonList(ELEMENT_UUID)); verify(selectedItems, times(1)).add(eq(shapeView)); verify(selectionControl, never()).clearSelection(); }
### Question: LienzoMultipleSelectionControl extends AbstractSelectionControl<H> { @Override protected void onClearSelection() { super.onClearSelection(); if (Objects.nonNull(getSelectionControl().getCanvasHandler())) { getSelectionManager().clearSelection(); } } @Inject LienzoMultipleSelectionControl(final Event<CanvasSelectionEvent> canvasSelectionEvent, final Event<CanvasClearSelectionEvent> clearSelectionEvent); LienzoMultipleSelectionControl(final MapSelectionControl<H> selectionControl, final Event<CanvasSelectionEvent> canvasSelectionEvent, final Event<CanvasClearSelectionEvent> clearSelectionEvent, final CursoredSelectionShapeProvider selectionShapeProvider); }### Answer: @Test public void testOnClearSelectionEvent() { tested.init(canvasHandler); tested.onClearSelection(); verify(selectionControl, never()).clearSelection(); verify(selectionManager, times(1)).clearSelection(); }
### Question: LienzoMultipleSelectionControl extends AbstractSelectionControl<H> { @Override protected void onDestroy() { getSelectionManager().destroy(); selectionShapeProvider.destroy(); super.onDestroy(); } @Inject LienzoMultipleSelectionControl(final Event<CanvasSelectionEvent> canvasSelectionEvent, final Event<CanvasClearSelectionEvent> clearSelectionEvent); LienzoMultipleSelectionControl(final MapSelectionControl<H> selectionControl, final Event<CanvasSelectionEvent> canvasSelectionEvent, final Event<CanvasClearSelectionEvent> clearSelectionEvent, final CursoredSelectionShapeProvider selectionShapeProvider); }### Answer: @Test public void testDestroy() { tested.destroy(); verify(tested).onDestroy(); verify(selectionManager).destroy(); verify(selectionShapeProvider).destroy(); }
### Question: ContainmentAcceptorControlImpl extends AbstractAcceptorControl implements ContainmentAcceptorControl<AbstractCanvasHandler> { @Override public boolean allow(final Element parent, final Node[] children) { return evaluate(parent, children, command -> getCommandManager().allow(getCanvasHandler(), command), true); } @Inject ContainmentAcceptorControlImpl(final CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory, final CanvasHighlight canvasHighlight); @Override boolean allow(final Element parent, final Node[] children); @Override boolean accept(final Element parent, final Node[] children); }### Answer: @Test public void testAllow() { tested.init(canvasHandler); final boolean allow = tested.allow(parent, new Node[]{candidate}); assertTrue(allow); verify(commandManager, times(1)).allow(eq(canvasHandler), eq(updateChildrenCommand)); assertEquals(parent, updateChildrenCommand.getParent()); assertEquals(candidate, updateChildrenCommand.getCandidates().iterator().next()); verify(highlight, times(1)).unhighLight(); }
### Question: ContainmentAcceptorControlImpl extends AbstractAcceptorControl implements ContainmentAcceptorControl<AbstractCanvasHandler> { @Override public boolean accept(final Element parent, final Node[] children) { return evaluate(parent, children, command -> getCommandManager().execute(getCanvasHandler(), command), false); } @Inject ContainmentAcceptorControlImpl(final CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory, final CanvasHighlight canvasHighlight); @Override boolean allow(final Element parent, final Node[] children); @Override boolean accept(final Element parent, final Node[] children); }### Answer: @Test public void testAccept() { tested.init(canvasHandler); final boolean accept = tested.accept(parent, new Node[]{candidate}); assertTrue(accept); verify(commandManager, times(1)).execute(eq(canvasHandler), eq(updateChildrenCommand)); assertEquals(parent, updateChildrenCommand.getParent()); assertEquals(candidate, updateChildrenCommand.getCandidates().iterator().next()); verify(highlight, times(1)).unhighLight(); }
### Question: ResizeControlImpl extends AbstractCanvasHandlerRegistrationControl<AbstractCanvasHandler> implements ResizeControl<AbstractCanvasHandler, Element> { @Override @SuppressWarnings("unchecked") public void register(final Element element) { if (checkNotRegistered(element)) { final Canvas<?> canvas = canvasHandler.getCanvas(); final Shape<?> shape = canvas.getShape(element.getUUID()); if (supportsResize(shape)) { registerResizeHandlers(element, shape); } } } protected ResizeControlImpl(); @Inject ResizeControlImpl(final CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory); @Override @SuppressWarnings("unchecked") void register(final Element element); @Override @SuppressWarnings("unchecked") CommandResult<CanvasViolation> resize(final Element element, final double width, final double height); @Override void setCommandManagerProvider(final RequiresCommandManager.CommandManagerProvider<AbstractCanvasHandler> provider); }### Answer: @Test public void testRegister() { tested.init(canvasHandler); assertFalse(tested.isRegistered(element)); tested.register(element); verify(shapeView, times(1)).supports(eq(ViewEventType.RESIZE)); verify(shapeView, times(1)).addHandler(eq(ViewEventType.RESIZE), any(ResizeHandler.class)); assertTrue(tested.isRegistered(element)); } @Test @SuppressWarnings("unchecked") public void testDeregister() { tested.init(canvasHandler); tested.register(element); tested.deregister(element); verify(shapeView, times(1)).removeHandler(any(ViewHandler.class)); assertFalse(tested.isRegistered(element)); }
### Question: ResizeControlImpl extends AbstractCanvasHandlerRegistrationControl<AbstractCanvasHandler> implements ResizeControl<AbstractCanvasHandler, Element> { @Override @SuppressWarnings("unchecked") public CommandResult<CanvasViolation> resize(final Element element, final double width, final double height) { return doResize(element, width, height); } protected ResizeControlImpl(); @Inject ResizeControlImpl(final CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory); @Override @SuppressWarnings("unchecked") void register(final Element element); @Override @SuppressWarnings("unchecked") CommandResult<CanvasViolation> resize(final Element element, final double width, final double height); @Override void setCommandManagerProvider(final RequiresCommandManager.CommandManagerProvider<AbstractCanvasHandler> provider); }### Answer: @Test @SuppressWarnings("unchecked") public void testResize() { tested.init(canvasHandler); assertFalse(tested.isRegistered(element)); tested.register(element); verify(shapeView, times(1)).supports(eq(ViewEventType.RESIZE)); ArgumentCaptor<ResizeHandler> resizeHandlerArgumentCaptor = ArgumentCaptor.forClass(ResizeHandler.class); verify(shapeView, times(1)).addHandler(eq(ViewEventType.RESIZE), resizeHandlerArgumentCaptor.capture()); final CanvasCommand expectedCommand = mock(CanvasCommand.class); doAnswer(invocationOnMock -> expectedCommand).when(canvasCommandFactory).resize(eq(element), any(BoundingBox.class)); ResizeHandler resizeHandler = resizeHandlerArgumentCaptor.getValue(); double x = 121.45d; double y = 23.456d; double width = 100d; double height = 200d; ResizeEvent event = new ResizeEvent(x, y, x, y, width, height); resizeHandler.end(event); ArgumentCaptor<CanvasCommand> commandArgumentCaptor = ArgumentCaptor.forClass(CanvasCommand.class); verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture()); CanvasCommand command = commandArgumentCaptor.getValue(); assertNotNull(command); assertEquals(expectedCommand, command); }
### Question: ResizeControlImpl extends AbstractCanvasHandlerRegistrationControl<AbstractCanvasHandler> implements ResizeControl<AbstractCanvasHandler, Element> { @SuppressWarnings("unchecked") protected void onCanvasSelectionEvent(@Observes CanvasSelectionEvent event) { checkNotNull("event", event); if (event.getIdentifiers().size() == 1) { final String uuid = event.getIdentifiers().iterator().next(); if (isSameCanvas(event) && isRegistered(uuid)) { hideALLCPs(); final HasControlPoints<?> hasControlPoints = getControlPointsInstance(uuid); if (!hasControlPoints.areControlsVisible()) { showCPs(hasControlPoints); } } } else if (event.getIdentifiers().size() > 1){ hideALLCPs(); } } protected ResizeControlImpl(); @Inject ResizeControlImpl(final CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory); @Override @SuppressWarnings("unchecked") void register(final Element element); @Override @SuppressWarnings("unchecked") CommandResult<CanvasViolation> resize(final Element element, final double width, final double height); @Override void setCommandManagerProvider(final RequiresCommandManager.CommandManagerProvider<AbstractCanvasHandler> provider); }### Answer: @Test public void testOnCanvasSelectionEvent() { tested.onCanvasSelectionEvent(elementsSelectedEvent); verify(elementsSelectedEvent, times(2)).getIdentifiers(); }
### Question: LienzoSelectionControl extends AbstractSelectionControl<H> { Map<String, ViewHandler<?>> getHandlers() { return handlers; } @Inject LienzoSelectionControl(final Event<CanvasSelectionEvent> canvasSelectionEvent, final Event<CanvasClearSelectionEvent> clearSelectionEvent); LienzoSelectionControl(final MapSelectionControl<H> selectionControl, final Event<CanvasSelectionEvent> canvasSelectionEvent, final Event<CanvasClearSelectionEvent> clearSelectionEvent); }### Answer: @Test public void testRegisterAndClick() { tested.init(canvasHandler); tested.register(element); verify(selectionControl, times(1)).register(eq(element)); ArgumentCaptor<MouseClickHandler> clickHandlerCaptor = ArgumentCaptor.forClass(MouseClickHandler.class); verify(shapeViewHandlers, times(1)).supports(eq(ViewEventType.MOUSE_CLICK)); verify(shapeViewHandlers, times(1)).addHandler(eq(ViewEventType.MOUSE_CLICK), clickHandlerCaptor.capture()); final MouseClickHandler clickHandler = clickHandlerCaptor.getValue(); assertEquals(clickHandler, tested.getHandlers().get(ELEMENT_UUID)); MouseClickEvent event = mock(MouseClickEvent.class); when(event.isButtonLeft()).thenReturn(true); clickHandler.handle(event); verify(selectionControl, times(1)).select(eq(element.getUUID())); }
### Question: LienzoSelectionControl extends AbstractSelectionControl<H> { void singleSelect(final Element element) { if (!getSelectedItems().isEmpty()) { clearSelection(); } select(element.getUUID()); } @Inject LienzoSelectionControl(final Event<CanvasSelectionEvent> canvasSelectionEvent, final Event<CanvasClearSelectionEvent> clearSelectionEvent); LienzoSelectionControl(final MapSelectionControl<H> selectionControl, final Event<CanvasSelectionEvent> canvasSelectionEvent, final Event<CanvasClearSelectionEvent> clearSelectionEvent); }### Answer: @Test public void testSelectionIsSingle() { when(selectionControl.getSelectedItems()).thenReturn(Collections.singletonList(ELEMENT_UUID)); tested.init(canvasHandler); tested.register(element); tested.singleSelect(element); verify(selectionControl, times(1)).clearSelection(); verify(selectionControl, times(1)).select(eq(element.getUUID())); } @Test public void testClearSelection() { tested.init(canvasHandler); tested.register(element); tested.singleSelect(element); tested.clearSelection(); verify(selectionControl, times(1)).clearSelection(); }
### Question: LienzoSelectionControl extends AbstractSelectionControl<H> { protected void deregister(final String uuid) { final Shape shape = getSelectionControl().getCanvas().getShape(uuid); final ViewHandler<?> handler = handlers.get(uuid); doDeregisterHandler(shape, handler); } @Inject LienzoSelectionControl(final Event<CanvasSelectionEvent> canvasSelectionEvent, final Event<CanvasClearSelectionEvent> clearSelectionEvent); LienzoSelectionControl(final MapSelectionControl<H> selectionControl, final Event<CanvasSelectionEvent> canvasSelectionEvent, final Event<CanvasClearSelectionEvent> clearSelectionEvent); }### Answer: @Test @SuppressWarnings("unchecked") public void testDeregister() { tested.init(canvasHandler); tested.register(element); tested.deregister(element); verify(selectionControl, times(1)).deregister(eq(element)); verify(shapeViewHandlers, times(1)).removeHandler(any(ViewHandler.class)); assertTrue(tested.getHandlers().isEmpty()); }
### Question: LienzoCanvas extends AbstractCanvas<V> { public AbstractCanvas<V> initialize(final CanvasPanel panel, final CanvasSettings settings) { eventHandlerManager = new ViewEventHandlerManager(getView().getLayer().getLienzoLayer(), SUPPORTED_EVENT_TYPES); return initialize(panel, settings, eventHandlerManager); } protected LienzoCanvas(final Event<CanvasClearEvent> canvasClearEvent, final Event<CanvasShapeAddedEvent> canvasShapeAddedEvent, final Event<CanvasShapeRemovedEvent> canvasShapeRemovedEvent, final Event<CanvasDrawnEvent> canvasDrawnEvent, final Event<CanvasFocusedEvent> canvasFocusedEvent); AbstractCanvas<V> initialize(final CanvasPanel panel, final CanvasSettings settings); @Override Optional<Shape> getShapeAt(final double x, final double y); @Override void onAfterDraw(final Command callback); @Override void focus(); @Override boolean supports(final ViewEventType type); @Override AbstractCanvas<V> addHandler(final ViewEventType type, final ViewHandler<? extends ViewEvent> eventHandler); @Override AbstractCanvas<V> removeHandler(final ViewHandler<? extends ViewEvent> eventHandler); @Override AbstractCanvas<V> enableHandlers(); @Override AbstractCanvas<V> disableHandlers(); @Override Shape<?> getAttachableShape(); @Override void destroy(); }### Answer: @Test public void testInitialize() { CanvasPanel panel = mock(CanvasPanel.class); CanvasSettings settings = mock(CanvasSettings.class); when(settings.isHiDPIEnabled()).thenReturn(true); assertEquals(tested, tested.initialize(panel, settings)); assertTrue(LienzoCore.get().isHidpiEnabled()); assertNotNull(tested.getEventHandlerManager()); verify(view, times(1)).initialize(eq(panel), eq(settings)); }
### Question: LienzoCanvas extends AbstractCanvas<V> { @Override public void onAfterDraw(final Command callback) { getView().getLayer().onAfterDraw(callback); } protected LienzoCanvas(final Event<CanvasClearEvent> canvasClearEvent, final Event<CanvasShapeAddedEvent> canvasShapeAddedEvent, final Event<CanvasShapeRemovedEvent> canvasShapeRemovedEvent, final Event<CanvasDrawnEvent> canvasDrawnEvent, final Event<CanvasFocusedEvent> canvasFocusedEvent); AbstractCanvas<V> initialize(final CanvasPanel panel, final CanvasSettings settings); @Override Optional<Shape> getShapeAt(final double x, final double y); @Override void onAfterDraw(final Command callback); @Override void focus(); @Override boolean supports(final ViewEventType type); @Override AbstractCanvas<V> addHandler(final ViewEventType type, final ViewHandler<? extends ViewEvent> eventHandler); @Override AbstractCanvas<V> removeHandler(final ViewHandler<? extends ViewEvent> eventHandler); @Override AbstractCanvas<V> enableHandlers(); @Override AbstractCanvas<V> disableHandlers(); @Override Shape<?> getAttachableShape(); @Override void destroy(); }### Answer: @Test public void testOnAfterDraw() { Command callback = mock(Command.class); tested.onAfterDraw(callback); verify(lienzoLayer, times(1)).onAfterDraw(eq(callback)); }
### Question: LienzoCanvas extends AbstractCanvas<V> { @Override public void focus() { getView().getLienzoPanel().focus(); } protected LienzoCanvas(final Event<CanvasClearEvent> canvasClearEvent, final Event<CanvasShapeAddedEvent> canvasShapeAddedEvent, final Event<CanvasShapeRemovedEvent> canvasShapeRemovedEvent, final Event<CanvasDrawnEvent> canvasDrawnEvent, final Event<CanvasFocusedEvent> canvasFocusedEvent); AbstractCanvas<V> initialize(final CanvasPanel panel, final CanvasSettings settings); @Override Optional<Shape> getShapeAt(final double x, final double y); @Override void onAfterDraw(final Command callback); @Override void focus(); @Override boolean supports(final ViewEventType type); @Override AbstractCanvas<V> addHandler(final ViewEventType type, final ViewHandler<? extends ViewEvent> eventHandler); @Override AbstractCanvas<V> removeHandler(final ViewHandler<? extends ViewEvent> eventHandler); @Override AbstractCanvas<V> enableHandlers(); @Override AbstractCanvas<V> disableHandlers(); @Override Shape<?> getAttachableShape(); @Override void destroy(); }### Answer: @Test public void testFocus() { LienzoPanel panel = mock(LienzoPanel.class); when(view.getLienzoPanel()).thenReturn(panel); tested.focus(); verify(panel, times(1)).focus(); }
### Question: LienzoCanvas extends AbstractCanvas<V> { @Override public void destroy() { if (null != eventHandlerManager) { eventHandlerManager.destroy(); eventHandlerManager = null; } super.destroy(); } protected LienzoCanvas(final Event<CanvasClearEvent> canvasClearEvent, final Event<CanvasShapeAddedEvent> canvasShapeAddedEvent, final Event<CanvasShapeRemovedEvent> canvasShapeRemovedEvent, final Event<CanvasDrawnEvent> canvasDrawnEvent, final Event<CanvasFocusedEvent> canvasFocusedEvent); AbstractCanvas<V> initialize(final CanvasPanel panel, final CanvasSettings settings); @Override Optional<Shape> getShapeAt(final double x, final double y); @Override void onAfterDraw(final Command callback); @Override void focus(); @Override boolean supports(final ViewEventType type); @Override AbstractCanvas<V> addHandler(final ViewEventType type, final ViewHandler<? extends ViewEvent> eventHandler); @Override AbstractCanvas<V> removeHandler(final ViewHandler<? extends ViewEvent> eventHandler); @Override AbstractCanvas<V> enableHandlers(); @Override AbstractCanvas<V> disableHandlers(); @Override Shape<?> getAttachableShape(); @Override void destroy(); }### Answer: @Test public void testDestroy() { CanvasPanel panel = mock(CanvasPanel.class); CanvasSettings settings = mock(CanvasSettings.class); ViewEventHandlerManager eventHandler = mock(ViewEventHandlerManager.class); tested.initialize(panel, settings, eventHandler); tested.destroy(); verify(eventHandler, times(1)).destroy(); verify(view, times(1)).destroy(); }
### Question: LienzoCanvasCommandFactory extends DefaultCanvasCommandFactory { @Override public CanvasCommand<AbstractCanvasHandler> resize(final Element<? extends View<?>> element, final BoundingBox boundingBox) { return new LienzoResizeNodeCommand(element, boundingBox); } protected LienzoCanvasCommandFactory(); @Inject LienzoCanvasCommandFactory(final @Any ManagedInstance<ChildrenTraverseProcessor> childrenTraverseProcessors, final @Any ManagedInstance<ViewTraverseProcessor> viewTraverseProcessors); @Override CanvasCommand<AbstractCanvasHandler> resize(final Element<? extends View<?>> element, final BoundingBox boundingBox); }### Answer: @Test @SuppressWarnings("unchecked") public void testCreateResizeCommand() { Element element = mock(Element.class); BoundingBox boundingBox = new BoundingBox(0, 0, 1, 2); final CanvasCommand<AbstractCanvasHandler> command = tested.resize(element, boundingBox); assertNotNull(command); assertTrue(command instanceof LienzoResizeNodeCommand); LienzoResizeNodeCommand lienzoCommand = (LienzoResizeNodeCommand) command; assertEquals(element, lienzoCommand.getCandidate()); assertEquals(boundingBox, lienzoCommand.getBoundingBox()); }
### Question: WiresCanvasView extends LienzoCanvasView<WiresLayer> { public void use(final WiresManager wiresManager) { layer.use(wiresManager); } @Inject WiresCanvasView(final WiresLayer layer); void use(final WiresManager wiresManager); @Override LienzoCanvasView<WiresLayer> add(final ShapeView<?> shape); LienzoCanvasView addRoot(final ShapeView<?> shape); @Override LienzoCanvasView<WiresLayer> delete(final ShapeView<?> shape); LienzoCanvasView deleteRoot(final ShapeView<?> shape); @Override LienzoCanvasView addChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView deleteChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView dock(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView undock(final ShapeView<?> childParent, final ShapeView<?> child); @Override WiresLayer getLayer(); }### Answer: @Test public void testUseWiresManager() { WiresManager wiresManager = mock(WiresManager.class); tested.use(wiresManager); verify(wiresLayer, times(1)).use(eq(wiresManager)); }
### Question: WiresCanvasView extends LienzoCanvasView<WiresLayer> { @Override public LienzoCanvasView<WiresLayer> add(final ShapeView<?> shape) { if (WiresUtils.isWiresShape(shape)) { layer.add((WiresShape) shape); } else if (WiresUtils.isWiresConnector(shape)) { layer.add((WiresConnector) shape); } else { return super.add(shape); } return this; } @Inject WiresCanvasView(final WiresLayer layer); void use(final WiresManager wiresManager); @Override LienzoCanvasView<WiresLayer> add(final ShapeView<?> shape); LienzoCanvasView addRoot(final ShapeView<?> shape); @Override LienzoCanvasView<WiresLayer> delete(final ShapeView<?> shape); LienzoCanvasView deleteRoot(final ShapeView<?> shape); @Override LienzoCanvasView addChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView deleteChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView dock(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView undock(final ShapeView<?> childParent, final ShapeView<?> child); @Override WiresLayer getLayer(); }### Answer: @Test public void testAdd() { WiresShapeView shapeView = new WiresShapeView(new MultiPath().rect(0, 0, 50, 50)); tested.add(shapeView); verify(wiresLayer, times(1)).add(eq(shapeView)); }
### Question: WiresCanvasView extends LienzoCanvasView<WiresLayer> { @Override public LienzoCanvasView<WiresLayer> delete(final ShapeView<?> shape) { if (WiresUtils.isWiresShape(shape)) { layer.delete((WiresShape) shape); } else if (WiresUtils.isWiresConnector(shape)) { layer.delete((WiresConnector) shape); } else { return super.delete(shape); } return this; } @Inject WiresCanvasView(final WiresLayer layer); void use(final WiresManager wiresManager); @Override LienzoCanvasView<WiresLayer> add(final ShapeView<?> shape); LienzoCanvasView addRoot(final ShapeView<?> shape); @Override LienzoCanvasView<WiresLayer> delete(final ShapeView<?> shape); LienzoCanvasView deleteRoot(final ShapeView<?> shape); @Override LienzoCanvasView addChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView deleteChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView dock(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView undock(final ShapeView<?> childParent, final ShapeView<?> child); @Override WiresLayer getLayer(); }### Answer: @Test public void testDelete() { WiresShapeView shapeView = new WiresShapeView(new MultiPath().rect(0, 0, 50, 50)); tested.delete(shapeView); verify(wiresLayer, times(1)).delete(eq(shapeView)); }
### Question: WiresCanvasView extends LienzoCanvasView<WiresLayer> { public LienzoCanvasView addRoot(final ShapeView<?> shape) { if (WiresUtils.isWiresShape(shape)) { layer.add(((WiresShape) shape).getGroup()); } else if (WiresUtils.isWiresConnector(shape)) { layer.add(((WiresConnector) shape).getGroup()); } else { return super.add(shape); } return this; } @Inject WiresCanvasView(final WiresLayer layer); void use(final WiresManager wiresManager); @Override LienzoCanvasView<WiresLayer> add(final ShapeView<?> shape); LienzoCanvasView addRoot(final ShapeView<?> shape); @Override LienzoCanvasView<WiresLayer> delete(final ShapeView<?> shape); LienzoCanvasView deleteRoot(final ShapeView<?> shape); @Override LienzoCanvasView addChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView deleteChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView dock(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView undock(final ShapeView<?> childParent, final ShapeView<?> child); @Override WiresLayer getLayer(); }### Answer: @Test public void testAddRoot() { WiresShapeView shapeView = new WiresShapeView(new MultiPath().rect(0, 0, 50, 50)); tested.addRoot(shapeView); verify(wiresLayer, times(1)).add(eq(shapeView.getGroup())); }
### Question: WiresCanvasView extends LienzoCanvasView<WiresLayer> { public LienzoCanvasView deleteRoot(final ShapeView<?> shape) { if (WiresUtils.isWiresShape(shape)) { layer.delete(((WiresShape) shape).getGroup()); } else if (WiresUtils.isWiresConnector(shape)) { layer.delete(((WiresConnector) shape).getGroup()); } else { return super.delete(shape); } return this; } @Inject WiresCanvasView(final WiresLayer layer); void use(final WiresManager wiresManager); @Override LienzoCanvasView<WiresLayer> add(final ShapeView<?> shape); LienzoCanvasView addRoot(final ShapeView<?> shape); @Override LienzoCanvasView<WiresLayer> delete(final ShapeView<?> shape); LienzoCanvasView deleteRoot(final ShapeView<?> shape); @Override LienzoCanvasView addChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView deleteChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView dock(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView undock(final ShapeView<?> childParent, final ShapeView<?> child); @Override WiresLayer getLayer(); }### Answer: @Test public void testDeleteRoot() { WiresShapeView shapeView = new WiresShapeView(new MultiPath().rect(0, 0, 50, 50)); tested.deleteRoot(shapeView); verify(wiresLayer, times(1)).delete(eq(shapeView.getGroup())); }
### Question: WiresCanvasView extends LienzoCanvasView<WiresLayer> { @Override public LienzoCanvasView addChild(final ShapeView<?> parent, final ShapeView<?> child) { final WiresContainer parentShape = (WiresContainer) parent; final WiresShape childShape = (WiresShape) child; layer.addChild(parentShape, childShape); childShape.shapeMoved(); return this; } @Inject WiresCanvasView(final WiresLayer layer); void use(final WiresManager wiresManager); @Override LienzoCanvasView<WiresLayer> add(final ShapeView<?> shape); LienzoCanvasView addRoot(final ShapeView<?> shape); @Override LienzoCanvasView<WiresLayer> delete(final ShapeView<?> shape); LienzoCanvasView deleteRoot(final ShapeView<?> shape); @Override LienzoCanvasView addChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView deleteChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView dock(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView undock(final ShapeView<?> childParent, final ShapeView<?> child); @Override WiresLayer getLayer(); }### Answer: @Test public void testAddChild() { WiresShapeView parent = new WiresShapeView(new MultiPath().rect(0, 0, 50, 50)); WiresShapeView child = new WiresShapeView(new MultiPath().rect(0, 0, 50, 50)); tested.addChild(parent, child); verify(wiresLayer, times(1)).addChild(eq(parent), eq(child)); }
### Question: WiresCanvasView extends LienzoCanvasView<WiresLayer> { @Override public LienzoCanvasView deleteChild(final ShapeView<?> parent, final ShapeView<?> child) { final WiresContainer parentShape = (WiresContainer) parent; final WiresShape childShape = (WiresShape) child; layer.deleteChild(parentShape, childShape); childShape.shapeMoved(); return this; } @Inject WiresCanvasView(final WiresLayer layer); void use(final WiresManager wiresManager); @Override LienzoCanvasView<WiresLayer> add(final ShapeView<?> shape); LienzoCanvasView addRoot(final ShapeView<?> shape); @Override LienzoCanvasView<WiresLayer> delete(final ShapeView<?> shape); LienzoCanvasView deleteRoot(final ShapeView<?> shape); @Override LienzoCanvasView addChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView deleteChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView dock(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView undock(final ShapeView<?> childParent, final ShapeView<?> child); @Override WiresLayer getLayer(); }### Answer: @Test public void testDeleteChild() { WiresShapeView parent = new WiresShapeView(new MultiPath().rect(0, 0, 50, 50)); WiresShapeView child = new WiresShapeView(new MultiPath().rect(0, 0, 50, 50)); tested.deleteChild(parent, child); verify(wiresLayer, times(1)).deleteChild(eq(parent), eq(child)); }
### Question: WiresCanvasView extends LienzoCanvasView<WiresLayer> { @Override public LienzoCanvasView dock(final ShapeView<?> parent, final ShapeView<?> child) { final WiresContainer parentShape = (WiresContainer) parent; final WiresShape childShape = (WiresShape) child; layer.dock(parentShape, childShape); childShape.shapeMoved(); return this; } @Inject WiresCanvasView(final WiresLayer layer); void use(final WiresManager wiresManager); @Override LienzoCanvasView<WiresLayer> add(final ShapeView<?> shape); LienzoCanvasView addRoot(final ShapeView<?> shape); @Override LienzoCanvasView<WiresLayer> delete(final ShapeView<?> shape); LienzoCanvasView deleteRoot(final ShapeView<?> shape); @Override LienzoCanvasView addChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView deleteChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView dock(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView undock(final ShapeView<?> childParent, final ShapeView<?> child); @Override WiresLayer getLayer(); }### Answer: @Test public void testDock() { WiresShapeView parent = new WiresShapeView(new MultiPath().rect(0, 0, 50, 50)); WiresShapeView child = new WiresShapeView(new MultiPath().rect(0, 0, 50, 50)); tested.dock(parent, child); verify(wiresLayer, times(1)).dock(eq(parent), eq(child)); }
### Question: WiresCanvasView extends LienzoCanvasView<WiresLayer> { @Override public LienzoCanvasView undock(final ShapeView<?> childParent, final ShapeView<?> child) { final WiresShape childShape = (WiresShape) child; layer.undock(childShape); childShape.shapeMoved(); return this; } @Inject WiresCanvasView(final WiresLayer layer); void use(final WiresManager wiresManager); @Override LienzoCanvasView<WiresLayer> add(final ShapeView<?> shape); LienzoCanvasView addRoot(final ShapeView<?> shape); @Override LienzoCanvasView<WiresLayer> delete(final ShapeView<?> shape); LienzoCanvasView deleteRoot(final ShapeView<?> shape); @Override LienzoCanvasView addChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView deleteChild(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView dock(final ShapeView<?> parent, final ShapeView<?> child); @Override LienzoCanvasView undock(final ShapeView<?> childParent, final ShapeView<?> child); @Override WiresLayer getLayer(); }### Answer: @Test public void testUnDock() { WiresShapeView parent = new WiresShapeView(new MultiPath().rect(0, 0, 50, 50)); WiresShapeView child = new WiresShapeView(new MultiPath().rect(0, 0, 50, 50)); tested.undock(parent, child); verify(wiresLayer, times(1)).undock(eq(child)); }
### Question: WiresCanvas extends LienzoCanvas<WiresCanvasView> { @Override public WiresCanvasView getView() { return view; } @Inject WiresCanvas(final Event<CanvasClearEvent> canvasClearEvent, final Event<CanvasShapeAddedEvent> canvasShapeAddedEvent, final Event<CanvasShapeRemovedEvent> canvasShapeRemovedEvent, final Event<CanvasDrawnEvent> canvasDrawnEvent, final Event<CanvasFocusedEvent> canvasFocusedEvent, final @Default WiresManagerFactory wiresManagerFactory, final WiresCanvasView view); @Override AbstractCanvas<WiresCanvasView> initialize(final CanvasPanel panel, final CanvasSettings settings); @Override WiresCanvasView getView(); WiresManager getWiresManager(); static final String WIRES_CANVAS_GROUP_ID; }### Answer: @Test public void testGetView() { assertEquals(view, tested.getView()); }
### Question: WiresCanvas extends LienzoCanvas<WiresCanvasView> { @Override protected void addChild(final Shape shape) { getView().addRoot(shape.getShapeView()); } @Inject WiresCanvas(final Event<CanvasClearEvent> canvasClearEvent, final Event<CanvasShapeAddedEvent> canvasShapeAddedEvent, final Event<CanvasShapeRemovedEvent> canvasShapeRemovedEvent, final Event<CanvasDrawnEvent> canvasDrawnEvent, final Event<CanvasFocusedEvent> canvasFocusedEvent, final @Default WiresManagerFactory wiresManagerFactory, final WiresCanvasView view); @Override AbstractCanvas<WiresCanvasView> initialize(final CanvasPanel panel, final CanvasSettings settings); @Override WiresCanvasView getView(); WiresManager getWiresManager(); static final String WIRES_CANVAS_GROUP_ID; }### Answer: @Test public void testAddChild() { Shape shape = mock(Shape.class); ShapeView shapeView = mock(ShapeView.class); when(shape.getShapeView()).thenReturn(shapeView); tested.addChild(shape); verify(view, times(1)).addRoot(eq(shapeView)); }
### Question: WiresCanvas extends LienzoCanvas<WiresCanvasView> { @Override protected void deleteChild(final Shape shape) { getView().deleteRoot(shape.getShapeView()); } @Inject WiresCanvas(final Event<CanvasClearEvent> canvasClearEvent, final Event<CanvasShapeAddedEvent> canvasShapeAddedEvent, final Event<CanvasShapeRemovedEvent> canvasShapeRemovedEvent, final Event<CanvasDrawnEvent> canvasDrawnEvent, final Event<CanvasFocusedEvent> canvasFocusedEvent, final @Default WiresManagerFactory wiresManagerFactory, final WiresCanvasView view); @Override AbstractCanvas<WiresCanvasView> initialize(final CanvasPanel panel, final CanvasSettings settings); @Override WiresCanvasView getView(); WiresManager getWiresManager(); static final String WIRES_CANVAS_GROUP_ID; }### Answer: @Test public void testDeleteChild() { Shape shape = mock(Shape.class); ShapeView shapeView = mock(ShapeView.class); when(shape.getShapeView()).thenReturn(shapeView); tested.deleteChild(shape); verify(view, times(1)).deleteRoot(eq(shapeView)); }
### Question: WiresLayer extends LienzoLayer { public LienzoLayer add(final WiresShape wiresShape) { if (contains(wiresShape)) { LOGGER.log(Level.WARNING, "Cannot add a WiresShape into the WiresLayer twice!"); } else { wiresManager.register(wiresShape); wiresManager.getMagnetManager().createMagnets(wiresShape, MAGNET_CARDINALS); WiresUtils.assertShapeGroup(wiresShape.getGroup(), WiresCanvas.WIRES_CANVAS_GROUP_ID); } return this; } WiresLayer use(final WiresManager wiresManager); LienzoLayer add(final WiresShape wiresShape); LienzoLayer add(final WiresConnector wiresConnector); LienzoLayer delete(final WiresShape wiresShape); LienzoLayer delete(final WiresConnector wiresConnector); WiresLayer addChild(final WiresContainer parent, final WiresShape child); WiresLayer deleteChild(final WiresContainer parent, final WiresShape child); WiresLayer dock(final WiresContainer parent, final WiresShape child); WiresLayer undock(final WiresShape child); WiresManager getWiresManager(); @Override void destroy(); }### Answer: @Test public void testAddShape() { tested.add(shape); verify(wiresManager, times(1)).register(eq(shape)); verify(magnetManager, times(1)).createMagnets(eq(shape), eq(WiresLayer.MAGNET_CARDINALS)); } @Test public void testAddShapeTwice() { when(wiresManager.getShape(eq(SHAPE_UUID))).thenReturn(shape); tested.add(shape); verify(wiresManager, never()).register(eq(shape)); verify(magnetManager, never()).createMagnets(eq(shape), eq(WiresLayer.MAGNET_CARDINALS)); } @Test public void testAddconnector() { tested.add(connector); verify(wiresManager, times(1)).register(eq(connector)); }
### Question: WiresLayer extends LienzoLayer { public LienzoLayer delete(final WiresShape wiresShape) { wiresManager.deregister(wiresShape); return this; } WiresLayer use(final WiresManager wiresManager); LienzoLayer add(final WiresShape wiresShape); LienzoLayer add(final WiresConnector wiresConnector); LienzoLayer delete(final WiresShape wiresShape); LienzoLayer delete(final WiresConnector wiresConnector); WiresLayer addChild(final WiresContainer parent, final WiresShape child); WiresLayer deleteChild(final WiresContainer parent, final WiresShape child); WiresLayer dock(final WiresContainer parent, final WiresShape child); WiresLayer undock(final WiresShape child); WiresManager getWiresManager(); @Override void destroy(); }### Answer: @Test public void testDeleteShape() { tested.delete(shape); verify(wiresManager, times(1)).deregister(eq(shape)); } @Test public void testDeleteConnector() { tested.delete(connector); verify(wiresManager, times(1)).deregister(eq(connector)); }
### Question: WiresLayer extends LienzoLayer { public WiresLayer addChild(final WiresContainer parent, final WiresShape child) { parent.add(child); return this; } WiresLayer use(final WiresManager wiresManager); LienzoLayer add(final WiresShape wiresShape); LienzoLayer add(final WiresConnector wiresConnector); LienzoLayer delete(final WiresShape wiresShape); LienzoLayer delete(final WiresConnector wiresConnector); WiresLayer addChild(final WiresContainer parent, final WiresShape child); WiresLayer deleteChild(final WiresContainer parent, final WiresShape child); WiresLayer dock(final WiresContainer parent, final WiresShape child); WiresLayer undock(final WiresShape child); WiresManager getWiresManager(); @Override void destroy(); }### Answer: @Test public void testAddChild() { WiresShape parent = mock(WiresShape.class); tested.addChild(parent, shape); verify(parent, times(1)).add(eq(shape)); }
### Question: WiresLayer extends LienzoLayer { public WiresLayer deleteChild(final WiresContainer parent, final WiresShape child) { parent.remove(child); return this; } WiresLayer use(final WiresManager wiresManager); LienzoLayer add(final WiresShape wiresShape); LienzoLayer add(final WiresConnector wiresConnector); LienzoLayer delete(final WiresShape wiresShape); LienzoLayer delete(final WiresConnector wiresConnector); WiresLayer addChild(final WiresContainer parent, final WiresShape child); WiresLayer deleteChild(final WiresContainer parent, final WiresShape child); WiresLayer dock(final WiresContainer parent, final WiresShape child); WiresLayer undock(final WiresShape child); WiresManager getWiresManager(); @Override void destroy(); }### Answer: @Test public void testDeleteChild() { WiresShape parent = mock(WiresShape.class); tested.deleteChild(parent, shape); verify(parent, times(1)).remove(eq(shape)); }
### Question: WiresLayer extends LienzoLayer { public WiresLayer undock(final WiresShape child) { child.getControl().getDockingControl().undock(); return this; } WiresLayer use(final WiresManager wiresManager); LienzoLayer add(final WiresShape wiresShape); LienzoLayer add(final WiresConnector wiresConnector); LienzoLayer delete(final WiresShape wiresShape); LienzoLayer delete(final WiresConnector wiresConnector); WiresLayer addChild(final WiresContainer parent, final WiresShape child); WiresLayer deleteChild(final WiresContainer parent, final WiresShape child); WiresLayer dock(final WiresContainer parent, final WiresShape child); WiresLayer undock(final WiresShape child); WiresManager getWiresManager(); @Override void destroy(); }### Answer: @Test public void testUnDock() { WiresShape child = mock(WiresShape.class); WiresShapeControl control = mock(WiresShapeControl.class); WiresDockingControl dockingControl = mock(WiresDockingControl.class); when(control.getDockingControl()).thenReturn(dockingControl); when(child.getControl()).thenReturn(control); tested.undock(child); verify(dockingControl, times(1)).undock(); }
### Question: WiresUtils { public static boolean isWiresLayer(final WiresContainer wiresShape) { return null != wiresShape && wiresShape instanceof WiresLayer; } static Point2D getAbsolute(final IDrawable<?> shape); static Node getNode(final AbstractCanvasHandler canvasHandler, final WiresContainer shape); static Node getNode(final AbstractCanvasHandler canvasHandler, final WiresMagnet magnet); static Edge getEdge(final AbstractCanvasHandler canvasHandler, final WiresConnector connector); static boolean isWiresShape(final ShapeView<?> shapeView); static boolean isWiresContainer(final ShapeView<?> shapeView); static boolean isWiresConnector(final ShapeView<?> shapeView); static boolean isWiresShape(final WiresContainer wiresShape); static boolean isWiresLayer(final WiresContainer wiresShape); static void assertShapeUUID(final IDrawable<?> shape, final String uuid); static String getShapeUUID(final IDrawable<?> shape); static void assertShapeGroup(final IDrawable<?> shape, final String group); static String getShapeGroup(final IDrawable<?> shape); }### Answer: @Test public void isWiresLayerWhenWiresLayer() { final Layer l = new Layer(); final WiresLayer wl = new WiresLayer(l); assertTrue(WiresUtils.isWiresLayer(wl)); } @Test public void isWiresLayerWhenWiresShape() { final WiresShape ws = new WiresShape(new MultiPath()); assertFalse(WiresUtils.isWiresLayer(ws)); }
### Question: WiresUtils { public static boolean isWiresShape(final ShapeView<?> shapeView) { return shapeView instanceof WiresShape; } static Point2D getAbsolute(final IDrawable<?> shape); static Node getNode(final AbstractCanvasHandler canvasHandler, final WiresContainer shape); static Node getNode(final AbstractCanvasHandler canvasHandler, final WiresMagnet magnet); static Edge getEdge(final AbstractCanvasHandler canvasHandler, final WiresConnector connector); static boolean isWiresShape(final ShapeView<?> shapeView); static boolean isWiresContainer(final ShapeView<?> shapeView); static boolean isWiresConnector(final ShapeView<?> shapeView); static boolean isWiresShape(final WiresContainer wiresShape); static boolean isWiresLayer(final WiresContainer wiresShape); static void assertShapeUUID(final IDrawable<?> shape, final String uuid); static String getShapeUUID(final IDrawable<?> shape); static void assertShapeGroup(final IDrawable<?> shape, final String group); static String getShapeGroup(final IDrawable<?> shape); }### Answer: @Test public void isWiresShapeWhenWiresContainer() { final WiresContainer wc = new WiresContainer(new Group()); assertFalse(WiresUtils.isWiresShape(wc)); } @Test public void isWiresShapeWhenWiresLayer() { final Layer l = new Layer(); final WiresLayer wl = new WiresLayer(l); assertTrue(WiresUtils.isWiresShape(wl)); } @Test public void isWiresShapeWhenUnregisteredWiresShape() { final WiresShape ws = new WiresShape(new MultiPath()); assertFalse(WiresUtils.isWiresShape(ws)); }
### Question: LiteralExpressionPropertyConverter { public static JSITLiteralExpression dmnFromWB(final IsLiteralExpression wb) { if (Objects.isNull(wb)) { return null; } final JSITLiteralExpression result = LITERAL_EXPRESSION_PROVIDER.make(); result.setId(wb.getId().getValue()); final String description = wb.getDescription().getValue(); if (StringUtils.nonEmpty(description)) { result.setDescription(description); } if (wb instanceof LiteralExpression) { final String expressionLanguage = ((LiteralExpression) wb).getExpressionLanguage().getValue(); if (StringUtils.nonEmpty(expressionLanguage)) { result.setExpressionLanguage(expressionLanguage); } } QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef); result.setText(wb.getText().getValue()); final JSITImportedValues importedValues = ImportedValuesConverter.dmnFromWB(wb.getImportedValues()); if (Objects.nonNull(importedValues)) { result.setImportedValues(importedValues); } return result; } static LiteralExpression wbFromDMN(final JSITLiteralExpression dmn); static JSITLiteralExpression dmnFromWB(final IsLiteralExpression wb); }### Answer: @Test public void testDMNFromWB() { when(wb.getId()).thenReturn(new Id(UUID)); when(wb.getDescription()).thenReturn(new Description(DESCRIPTION)); when(wb.getTypeRef()).thenReturn(new QName(KIE.getUri(), TYPE_REF, KIE.getPrefix())); when(wb.getText()).thenReturn(new Text(TEXT)); when(wb.getExpressionLanguage()).thenReturn(new ExpressionLanguage(EXPRESSION_LANGUAGE)); final JSITLiteralExpression result = LiteralExpressionPropertyConverter.dmnFromWB(wb); verify(result).setId(UUID); verify(result).setDescription(DESCRIPTION); verify(result).setTypeRef("{" + KIE.getUri() + "}" + TYPE_REF); verify(result).setText(TEXT); verify(result).setExpressionLanguage(EXPRESSION_LANGUAGE); }
### Question: OutputClauseLiteralExpressionPropertyConverter { public static OutputClauseLiteralExpression wbFromDMN(final JSITLiteralExpression dmn) { if (Objects.isNull(dmn)) { return new OutputClauseLiteralExpression(); } final Id id = IdPropertyConverter.wbFromDMN(dmn.getId()); final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription()); final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef()); final Text text = new Text(dmn.getText()); final ImportedValues importedValues = ImportedValuesConverter.wbFromDMN(dmn.getImportedValues()); final OutputClauseLiteralExpression result = new OutputClauseLiteralExpression(id, description, typeRef, text, importedValues); if (Objects.nonNull(importedValues)) { importedValues.setParent(result); } return result; } static OutputClauseLiteralExpression wbFromDMN(final JSITLiteralExpression dmn); static JSITLiteralExpression dmnFromWB(final OutputClauseLiteralExpression wb); }### Answer: @Test public void testWBFromDMNWhenNull() { final OutputClauseLiteralExpression wb = OutputClauseLiteralExpressionPropertyConverter.wbFromDMN(null); assertThat(wb).isNotNull(); } @Test public void testWBFromDMNWhenNonNull() { when(jsitLiteralExpression.getText()).thenReturn(TEXT); final OutputClauseLiteralExpression wb = OutputClauseLiteralExpressionPropertyConverter.wbFromDMN(jsitLiteralExpression); assertThat(wb).isNotNull(); assertThat(wb.getText().getValue()).isEqualTo(TEXT); }
### Question: OutputClauseLiteralExpressionPropertyConverter { public static JSITLiteralExpression dmnFromWB(final OutputClauseLiteralExpression wb) { if (Objects.isNull(wb)) { return null; } else if (Objects.isNull(wb.getText())) { return null; } else if (StringUtils.isEmpty(wb.getText().getValue())) { return null; } return LiteralExpressionPropertyConverter.dmnFromWB(wb); } static OutputClauseLiteralExpression wbFromDMN(final JSITLiteralExpression dmn); static JSITLiteralExpression dmnFromWB(final OutputClauseLiteralExpression wb); }### Answer: @Test public void testDMNFromWBWhenNull() { final JSITLiteralExpression dmn = OutputClauseLiteralExpressionPropertyConverter.dmnFromWB(null); assertThat(dmn).isNull(); } @Test public void testDMNFromWBWhenTextIsNull() { final OutputClauseLiteralExpression wb = new OutputClauseLiteralExpression(); wb.setText(null); final JSITLiteralExpression dmn = OutputClauseLiteralExpressionPropertyConverter.dmnFromWB(wb); assertThat(dmn).isNull(); } @Test public void testDMNFromWBWhenNonNullWithEmptyString() { final OutputClauseLiteralExpression wb = new OutputClauseLiteralExpression(); wb.getText().setValue(""); final JSITLiteralExpression dmn = OutputClauseLiteralExpressionPropertyConverter.dmnFromWB(wb); assertThat(dmn).isNull(); } @Test public void testDMNFromWBWhenNonNullWithNonEmptyString() { final OutputClauseLiteralExpression wb = new OutputClauseLiteralExpression(); wb.getText().setValue(TEXT); final JSITLiteralExpression dmn = OutputClauseLiteralExpressionPropertyConverter.dmnFromWB(wb); assertThat(dmn).isNotNull(); verify(jsitLiteralExpression).setText(TEXT); }
### Question: LienzoCanvasExport implements CanvasExport<AbstractCanvasHandler> { private static LienzoLayer getLayer(final AbstractCanvasHandler canvasHandler) { return ((WiresCanvas) canvasHandler.getCanvas()).getView().getLayer(); } LienzoCanvasExport(); LienzoCanvasExport(final BoundsProvider boundsProvider); @Override IContext2D toContext2D(final AbstractCanvasHandler canvasHandler, final CanvasExportSettings settings); @Override String toImageData(final AbstractCanvasHandler canvasHandler, final CanvasURLExportSettings settings); static final String BG_COLOR; static final int PADDING; }### Answer: @Test public void testWiresLayerBoundsProvider() { layer = new Layer(); when(lienzoLayer.getLienzoLayer()).thenReturn(layer); WiresManager wiresManager = WiresManager.get(layer); com.ait.lienzo.client.core.shape.wires.WiresLayer wiresLayer = wiresManager.getLayer(); wiresLayer.add(new WiresShape(new MultiPath().rect(0, 0, 50, 50)).setLocation(new Point2D(12, 44))); wiresLayer.add(new WiresShape(new MultiPath().rect(0, 0, 100, 150)).setLocation(new Point2D(1, 3))); LienzoCanvasExport.WiresLayerBoundsProvider provider = new LienzoCanvasExport.WiresLayerBoundsProvider(); int[] size0 = provider.compute(lienzoLayer, CanvasExportSettings.build()); assertEquals(0, size0[0]); assertEquals(0, size0[1]); assertEquals(151, size0[2]); assertEquals(203, size0[3]); }
### Question: CanvasBoundsIndexerImpl implements CanvasBoundsIndexer<AbstractCanvasHandler> { @Override public void destroy() { this.canvasHandler = null; } BoundsIndexer<AbstractCanvasHandler, Node<View<?>, Edge>> build(final AbstractCanvasHandler context); @Override @SuppressWarnings("unchecked") Node<View<?>, Edge> getAt(final double x, final double y); @Override @SuppressWarnings("unchecked") Node<View<?>, Edge> getAt(final double x, final double y, final double width, final double height, final Element parentNode); @Override double[] getTrimmedBounds(); @Override void destroy(); }### Answer: @Test public void testDestroy() { canvasBoundsIndexerImpl.destroy(); assertNull(canvasBoundsIndexerImpl.canvasHandler); }
### Question: LienzoCanvasView extends AbstractCanvasView<LienzoCanvasView> { @Override public LienzoCanvasView<L> add(final ShapeView<?> shape) { getLayer().add((IPrimitive<?>) shape); return this; } LienzoCanvasView(); LienzoCanvasView(final BiFunction<Integer, Integer, IPrimitive<?>> decoratorFactory); abstract L getLayer(); @Override LienzoCanvasView<L> add(final ShapeView<?> shape); @Override LienzoCanvasView<L> delete(final ShapeView<?> shape); @Override LienzoCanvasView<L> setGrid(final CanvasGrid grid); LienzoCanvasView<L> setDecoratorFactory(final BiFunction<Integer, Integer, IPrimitive<?>> decoratorFatory); @Override LienzoCanvasView<L> clear(); @Override Transform getTransform(); LienzoPanel getLienzoPanel(); }### Answer: @Test public void testInitialize() { assertEquals(tested, tested.initialize(panel, settings)); verify(panel, times(1)).show(eq(lienzoLayer)); verify(panelStyle, times(1)).setBackgroundColor(eq(LienzoCanvasView.BG_COLOR)); verify(topLayer, times(1)).add(eq(decorator)); }
### Question: LienzoCanvasView extends AbstractCanvasView<LienzoCanvasView> { @Override public LienzoCanvasView<L> setGrid(final CanvasGrid grid) { if (null != grid) { GridLayer gridLayer = LienzoGridLayerBuilder.getLienzoGridFor(grid); getLienzoPanel().setBackgroundLayer(gridLayer); } else { getLienzoPanel().setBackgroundLayer(null); } return this; } LienzoCanvasView(); LienzoCanvasView(final BiFunction<Integer, Integer, IPrimitive<?>> decoratorFactory); abstract L getLayer(); @Override LienzoCanvasView<L> add(final ShapeView<?> shape); @Override LienzoCanvasView<L> delete(final ShapeView<?> shape); @Override LienzoCanvasView<L> setGrid(final CanvasGrid grid); LienzoCanvasView<L> setDecoratorFactory(final BiFunction<Integer, Integer, IPrimitive<?>> decoratorFatory); @Override LienzoCanvasView<L> clear(); @Override Transform getTransform(); LienzoPanel getLienzoPanel(); }### Answer: @Test public void testSetGrid() { tested.initialize(panel, settings); tested.setGrid(CanvasGrid.DEFAULT_GRID); verify(panel, times(1)).setBackgroundLayer(any(Layer.class)); } @Test public void testRemoveGrid() { tested.initialize(panel, settings); tested.setGrid(null); verify(panel, times(1)).setBackgroundLayer(eq(null)); }
### Question: LienzoCanvasView extends AbstractCanvasView<LienzoCanvasView> { @Override public LienzoCanvasView<L> clear() { getLayer().clear(); return this; } LienzoCanvasView(); LienzoCanvasView(final BiFunction<Integer, Integer, IPrimitive<?>> decoratorFactory); abstract L getLayer(); @Override LienzoCanvasView<L> add(final ShapeView<?> shape); @Override LienzoCanvasView<L> delete(final ShapeView<?> shape); @Override LienzoCanvasView<L> setGrid(final CanvasGrid grid); LienzoCanvasView<L> setDecoratorFactory(final BiFunction<Integer, Integer, IPrimitive<?>> decoratorFatory); @Override LienzoCanvasView<L> clear(); @Override Transform getTransform(); LienzoPanel getLienzoPanel(); }### Answer: @Test public void testClear() { tested.clear(); verify(lienzoLayer, times(1)).clear(); }
### Question: LienzoCanvasView extends AbstractCanvasView<LienzoCanvasView> { @Override public Transform getTransform() { return getLayer().getTransform(); } LienzoCanvasView(); LienzoCanvasView(final BiFunction<Integer, Integer, IPrimitive<?>> decoratorFactory); abstract L getLayer(); @Override LienzoCanvasView<L> add(final ShapeView<?> shape); @Override LienzoCanvasView<L> delete(final ShapeView<?> shape); @Override LienzoCanvasView<L> setGrid(final CanvasGrid grid); LienzoCanvasView<L> setDecoratorFactory(final BiFunction<Integer, Integer, IPrimitive<?>> decoratorFatory); @Override LienzoCanvasView<L> clear(); @Override Transform getTransform(); LienzoPanel getLienzoPanel(); }### Answer: @Test public void testTransform() { Transform transform = mock(Transform.class); when(lienzoLayer.getTransform()).thenReturn(transform); assertEquals(transform, tested.getTransform()); }
### Question: CommandManagerImpl implements CommandManager<C, V>, HasCommandListener<CommandListener<C, V>> { @Override public CommandResult<V> allow(final C context, final Command<C, V> command) { Objects.requireNonNull(command, "command"); logCommand("ALLOW", command); final CommandResult<V> result = command.allow(context); if (null != listener) { listener.onAllow(context, command, result); } logResult(result); return result; } CommandManagerImpl(); @Override CommandResult<V> allow(final C context, final Command<C, V> command); @Override CommandResult<V> execute(final C context, final Command<C, V> command); @Override CommandResult<V> undo(final C context, final Command<C, V> command); @Override void setCommandListener(final CommandListener<C, V> listener); }### Answer: @Test public void allowTest() { commandManager.allow(null, command); verify(commandListener, times(1)).onAllow(any(), any(), any()); }
### Question: CommandManagerImpl implements CommandManager<C, V>, HasCommandListener<CommandListener<C, V>> { @Override public CommandResult<V> execute(final C context, final Command<C, V> command) { Objects.requireNonNull(command, "command"); logCommand("EXECUTE", command); final CommandResult<V> result = command.execute(context); if (null != listener) { listener.onExecute(context, command, result); } logResult(result); return result; } CommandManagerImpl(); @Override CommandResult<V> allow(final C context, final Command<C, V> command); @Override CommandResult<V> execute(final C context, final Command<C, V> command); @Override CommandResult<V> undo(final C context, final Command<C, V> command); @Override void setCommandListener(final CommandListener<C, V> listener); }### Answer: @Test public void executeTest() { commandManager.execute(null, command); verify(commandListener, times(1)).onExecute(any(), any(), any()); }
### Question: CommandManagerImpl implements CommandManager<C, V>, HasCommandListener<CommandListener<C, V>> { @Override public CommandResult<V> undo(final C context, final Command<C, V> command) { logCommand("UNDO", command); final CommandResult<V> result = command.undo(context); if (null != listener) { listener.onUndo(context, command, result); } logResult(result); return result; } CommandManagerImpl(); @Override CommandResult<V> allow(final C context, final Command<C, V> command); @Override CommandResult<V> execute(final C context, final Command<C, V> command); @Override CommandResult<V> undo(final C context, final Command<C, V> command); @Override void setCommandListener(final CommandListener<C, V> listener); }### Answer: @Test public void undoTest() { commandManager.undo(null, command); verify(commandListener, times(1)).onUndo(any(), any(), any()); }
### Question: PrimitiveUtilities { public static String getClassNameForPrimitiveType(final String type) { if (BYTE.equals(type)) { return Byte.class.getName(); } if (SHORT.equals(type)) { return Short.class.getName(); } if (INT.equals(type)) { return Integer.class.getName(); } if (LONG.equals(type)) { return Long.class.getName(); } if (FLOAT.equals(type)) { return Float.class.getName(); } if (DOUBLE.equals(type)) { return Double.class.getName(); } if (CHAR.equals(type)) { return Character.class.getName(); } if (BOOLEAN.equals(type)) { return Boolean.class.getName(); } return null; } static String getClassNameForPrimitiveType(final String type); static final String BYTE; static final String SHORT; static final String INT; static final String LONG; static final String FLOAT; static final String DOUBLE; static final String CHAR; static final String BOOLEAN; }### Answer: @Test public void testGetClassNameForPrimitiveType() { assertThat(PrimitiveUtilities.getClassNameForPrimitiveType(PrimitiveUtilities.BYTE)).isEqualTo(Byte.class.getName()); assertThat(PrimitiveUtilities.getClassNameForPrimitiveType(PrimitiveUtilities.SHORT)).isEqualTo(Short.class.getName()); assertThat(PrimitiveUtilities.getClassNameForPrimitiveType(PrimitiveUtilities.INT)).isEqualTo(Integer.class.getName()); assertThat(PrimitiveUtilities.getClassNameForPrimitiveType(PrimitiveUtilities.LONG)).isEqualTo(Long.class.getName()); assertThat(PrimitiveUtilities.getClassNameForPrimitiveType(PrimitiveUtilities.FLOAT)).isEqualTo(Float.class.getName()); assertThat(PrimitiveUtilities.getClassNameForPrimitiveType(PrimitiveUtilities.DOUBLE)).isEqualTo(Double.class.getName()); assertThat(PrimitiveUtilities.getClassNameForPrimitiveType(PrimitiveUtilities.CHAR)).isEqualTo(Character.class.getName()); assertThat(PrimitiveUtilities.getClassNameForPrimitiveType(PrimitiveUtilities.BOOLEAN)).isEqualTo(Boolean.class.getName()); assertThat(PrimitiveUtilities.getClassNameForPrimitiveType("")).isNull(); assertThat(PrimitiveUtilities.getClassNameForPrimitiveType(null)).isNull(); assertThat(PrimitiveUtilities.getClassNameForPrimitiveType("Unknown")).isNull(); }
### Question: ClassFieldInspector { public Map<String, FieldInfo> getFieldTypesFieldInfo() { return this.fieldTypesFieldInfo; } ClassFieldInspector(final Class<?> clazz); Set<String> getFieldNames(); Map<String, FieldInfo> getFieldTypesFieldInfo(); }### Answer: @Test public void testGetFieldTypesInfo() { Map<String, FieldInfo> result = bean1Inspector.getFieldTypesFieldInfo(); assertEquals(bean1Fields, result); result = bean2Inspector.getFieldTypesFieldInfo(); assertEquals(bean2Fields, result); }
### Question: ClassFactBuilder extends BaseFactBuilder { @Override public void build(final ModuleDataModelOracleImpl oracle) { super.build(oracle); oracle.addModuleMethodInformation(methodInformation); oracle.addModuleFieldParametersType(fieldParametersType); oracle.addModuleSuperTypes(buildSuperTypes()); oracle.addModuleTypeAnnotations(buildTypeAnnotations()); oracle.addModuleTypeFieldsAnnotations(buildTypeFieldsAnnotations()); } ClassFactBuilder(final ModuleDataModelOracleBuilder builder, final Class<?> clazz, final boolean isEvent, final Function<String, TypeSource> typeSourceResolver); ClassFactBuilder(final ModuleDataModelOracleBuilder builder, final Map<String, FactBuilder> discoveredFieldFactBuilders, final Class<?> clazz, final boolean isEvent, final Function<String, TypeSource> typeSourceResolver); @Override void build(final ModuleDataModelOracleImpl oracle); @Override void addInternalBuilders(Map<String, FactBuilder> builders); }### Answer: @Test public void testSuperTypes() throws Exception { final ModuleDataModelOracleBuilder builder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()); final ModuleDataModelOracleImpl oracle = new ModuleDataModelOracleImpl(); final ClassFactBuilder cb = new ClassFactBuilder(builder, PapaSmurf.class, false, type -> TypeSource.JAVA_PROJECT); cb.build(oracle); assertEquals(2, oracle.getModuleSuperTypes().get(PapaSmurf.class.getName()).size()); }
### Question: DMNIncludedNodeFactory { QName createTypeRef(final String modelName, final QName qName) { return new QName(qName.getNamespaceURI(), modelName + "." + qName.getLocalPart(), qName.getPrefix()); } DMNIncludedNode makeDMNIncludeNode(final String path, final IncludedModel includeModel, final DRGElement drgElement); }### Answer: @Test public void testCreateTypeRef() { final DMNIncludedNodeFactory factory = new DMNIncludedNodeFactory(); final QName qname = mock(QName.class); final String modelName = "modelName"; final String namespaceUri = "uri"; final String prefix = "prefix"; final String localPart = "localPart"; when(qname.getNamespaceURI()).thenReturn(namespaceUri); when(qname.getPrefix()).thenReturn(prefix); when(qname.getLocalPart()).thenReturn(localPart); final QName typeRef = factory.createTypeRef(modelName, qname); assertEquals(namespaceUri, typeRef.getNamespaceURI()); assertEquals(modelName + "." + localPart, typeRef.getLocalPart()); assertEquals(prefix, typeRef.getPrefix()); }
### Question: PackageNameValidator implements FileNameValidator { @Override public boolean isValid(final String value) { if (value == null) { return false; } final Map<String, Boolean> results = evaluateIdentifiers(value.split("\\.", -1)); return !results.containsValue(Boolean.FALSE); } @Override int getPriority(); @Override boolean accept(final String fileName); @Override boolean accept(final Path path); @Override boolean isValid(final String value); }### Answer: @Test public void isValid() { assertEquals(valid, VALIDATOR.isValid(input)); }
### Question: DefaultGenericKieValidator implements GenericValidator { public List<ValidationMessage> validate(final Path path, final String content) { return validatorBuildService.validate(path, content) .stream() .filter(fromValidatedPath(path)) .collect(Collectors.toList()); } DefaultGenericKieValidator(); @Inject DefaultGenericKieValidator(final ValidatorBuildService validatorBuildService); List<ValidationMessage> validate(final Path path, final String content); List<ValidationMessage> validate(final Path path); }### Answer: @Test public void testWorks() throws Exception { final Path path = resourcePath("/GuvnorM2RepoDependencyExample1/src/main/resources/rule2.drl"); final URL urlToValidate = this.getClass().getResource("/GuvnorM2RepoDependencyExample1/src/main/resources/rule2.drl"); final List<ValidationMessage> errors = validator.validate(path, Resources.toString(urlToValidate, Charset.forName("UTF-8"))); assertTrue(errors.isEmpty()); } @Test public void validatingAnAlreadyInvalidAssetShouldReportErrors() throws Exception { final Path path = resourcePath("/BuilderExampleBrokenSyntax/src/main/resources/rule1.drl"); final URL urlToValidate = this.getClass().getResource("/BuilderExampleBrokenSyntax/src/main/resources/rule1.drl"); final List<ValidationMessage> errors1 = validator.validate(path, Resources.toString(urlToValidate, Charset.forName("UTF-8"))); final List<ValidationMessage> errors2 = validator.validate(path, Resources.toString(urlToValidate, Charset.forName("UTF-8"))); assertFalse(errors1.isEmpty()); assertFalse(errors2.isEmpty()); assertEquals(errors1.size(), errors2.size()); }
### Question: DMNIncludedNodeFactory { Name createName(final DRGElement drgElement, final String modelName) { return new Name(modelName + "." + drgElement.getName().getValue()); } DMNIncludedNode makeDMNIncludeNode(final String path, final IncludedModel includeModel, final DRGElement drgElement); }### Answer: @Test public void testCreateName() { final DMNIncludedNodeFactory factory = new DMNIncludedNodeFactory(); final DRGElement drgElement = mock(DRGElement.class); final String theName = "the name"; final Name name = new Name(theName); final String modelName = "modelName"; when(drgElement.getName()).thenReturn(name); final Name createdName = factory.createName(drgElement, modelName); assertEquals(modelName + "." + theName, createdName.getValue()); }
### Question: DependencyServiceImpl implements DependencyService { @Override public Set<String> loadPackageNames(final GAV gav) { final Artifact artifact = getMavenRepository().resolveArtifact(gav.toString()); if (artifact != null) { return stripPackageNamesFromJar(artifact.getFile()); } else { return new HashSet<>(); } } DependencyServiceImpl(); @Override Collection<Dependency> loadDependencies(final Collection<GAV> gavs); @Override Collection<Dependency> loadDependencies(final GAV gav); @Override Set<String> loadPackageNames(final GAV gav); @Override EnhancedDependencies loadEnhancedDependencies(final Collection<Dependency> dependencies); }### Answer: @Test public void testListPackages() throws Exception { Set<String> junitPackages = service.loadPackageNames( new GAV( "junit", "junit", "4.11" ) ); Set<String> hamcrestPackages = service.loadPackageNames( new GAV( "org.hamcrest", "hamcrest-core", "1.3" ) ); assertTrue( junitPackages.contains( "org.junit.rules" ) ); assertTrue( junitPackages.contains( "org.junit.matchers" ) ); assertFalse( junitPackages.contains( "org.hamcrest" ) ); assertFalse( junitPackages.contains( "org.hamcrest.core" ) ); assertTrue( hamcrestPackages.contains( "org.hamcrest" ) ); assertTrue( hamcrestPackages.contains( "org.hamcrest.core" ) ); assertFalse( hamcrestPackages.contains( "org.junit.rules" ) ); assertFalse( hamcrestPackages.contains( "org.junit.matchers" ) ); } @Test public void testFillDependenciesWithPackageNames() throws Exception { final Set<String> packageNames = service.loadPackageNames( new GAV( "junit", "junit", "4.11" ) ); assertEquals( 2, packageNames.size() ); assertTrue( packageNames.contains( "org.junit.rules" ) ); assertTrue( packageNames.contains( "org.junit.matchers" ) ); }
### Question: PackageNameWhiteListSaver implements SupportsUpdate<WhiteList> { @Override public Path save( final Path path, final WhiteList content, final Metadata metadata, final String comment ) { try { ioService.write( Paths.convert( path ), toString( content ), metadataService.setUpAttributes( path, metadata ), commentedOptionFactory.makeCommentedOption( comment ) ); return path; } catch ( Exception e ) { throw ExceptionUtilities.handleException( e ); } } PackageNameWhiteListSaver(); @Inject PackageNameWhiteListSaver( final @Named( "ioStrategy" ) IOService ioService, final MetadataServerSideService metadataService, final CommentedOptionFactory commentedOptionFactory ); @Override Path save( final Path path, final WhiteList content, final Metadata metadata, final String comment ); }### Answer: @Test public void testSave() throws Exception { final Path path = testFileSystem.createTempFile( "whitelist" ); final WhiteList whiteList = new WhiteList(); whiteList.add( "org.drools" ); whiteList.add( "org.guvnor" ); final Metadata metadata = new Metadata(); final String comment = "comment"; final HashMap<String, Object> attributes = new HashMap<String, Object>(); when( metadataService.setUpAttributes( path, metadata ) ).thenReturn( attributes ); final CommentedOption commentedOption = mock( CommentedOption.class ); when( commentedOptionFactory.makeCommentedOption( "comment" ) ).thenReturn( commentedOption ); saver.save( path, whiteList, metadata, comment ); ArgumentCaptor<String> whiteListTextArgumentCaptor = ArgumentCaptor.forClass( String.class ); verify( ioService ).write( any( org.uberfire.java.nio.file.Path.class ), whiteListTextArgumentCaptor.capture(), eq( attributes ), eq( commentedOption ) ); final String whiteListAsText = whiteListTextArgumentCaptor.getValue(); assertTrue( whiteListAsText.contains( "org.drools" ) ); assertTrue( whiteListAsText.contains( "org.guvnor" ) ); }
### Question: PackageNameWhiteListServiceImpl implements PackageNameWhiteListService { @Override public Path save(final Path path, final WhiteList content, final Metadata metadata, final String comment) { return saver.save(path, content, metadata, comment); } PackageNameWhiteListServiceImpl(); @Inject PackageNameWhiteListServiceImpl(final @Named("ioStrategy") IOService ioService, final KieModuleService moduleService, final PackageNameWhiteListLoader loader, final PackageNameWhiteListSaver saver); void createModuleWhiteList(final Path packageNamesWhiteListPath, final String initialContent); @Override WhiteList filterPackageNames(final Module module, final Collection<String> packageNames); @Override WhiteList load(final Path packageNamesWhiteListPath); @Override Path save(final Path path, final WhiteList content, final Metadata metadata, final String comment); }### Answer: @Test public void testSave() throws Exception { final PackageNameWhiteListService service = makeService(""); final Path path = mock(Path.class); final WhiteList whiteList = new WhiteList(); final Metadata metadata = new Metadata(); final String comment = "comment"; service.save(path, whiteList, metadata, comment); verify(saver).save(path, whiteList, metadata, comment); }
### Question: SessionServiceImpl implements SessionService { @Override public KieSession newKieSession(KieModule project, String ksessionName) { final KieContainer kieContainer = getKieContainer(project); if (kieContainer == null) { return null; } return kieContainer.newKieSession(ksessionName); } SessionServiceImpl(); @Inject SessionServiceImpl(final BuildInfoService buildInfoService); @Override KieSession newKieSession(KieModule project, String ksessionName); @Override KieSession newDefaultKieSessionWithPseudoClock(final KieModule project); }### Answer: @Test public void newDefaultKieSession() { final KieSession kSession = mock(KieSession.class); doReturn(kSession).when(kieContainer).newKieSession(eq("ksessionName")); final KieSession resultKSession = sessionService.newKieSession(kieModule, "ksessionName"); verify(builder).build(); assertEquals(resultKSession, kSession); }
### Question: SessionServiceImpl implements SessionService { @Override public KieSession newDefaultKieSessionWithPseudoClock(final KieModule project) { final KieContainer kieContainer = getKieContainer(project); if (kieContainer == null) { return null; } final SessionConfiguration conf = SessionConfiguration.newInstance(); conf.setClockType(ClockType.PSEUDO_CLOCK); return kieContainer.getKieBase().newKieSession(conf, null); } SessionServiceImpl(); @Inject SessionServiceImpl(final BuildInfoService buildInfoService); @Override KieSession newKieSession(KieModule project, String ksessionName); @Override KieSession newDefaultKieSessionWithPseudoClock(final KieModule project); }### Answer: @Test public void newDefaultKieSessionWithPseudoClock() { final KieBase kBase = mock(KieBase.class); final KieSession kSession = mock(KieSession.class); doReturn(kBase).when(kieContainer).getKieBase(); doReturn(kSession).when(kBase).newKieSession(sessionConfigurationArgumentCaptor.capture(), eq(null)); final KieSession resultKSession = sessionService.newDefaultKieSessionWithPseudoClock(kieModule); final SessionConfiguration sessionConfiguration = sessionConfigurationArgumentCaptor.getValue(); verify(builder).build(); assertEquals(ClockType.PSEUDO_CLOCK, sessionConfiguration.getClockType()); assertEquals(resultKSession, kSession); } @Test public void manageFailureToLoadABuilder() { when(buildInfoService.getBuildInfo(any())).thenReturn(null); assertThatThrownBy(() -> sessionService.newDefaultKieSessionWithPseudoClock(kieModule)) .isInstanceOf(IllegalStateException.class) .hasMessage("Failed to clone Builder."); }
### Question: KieService { public T loadContent(Path path) { try { final org.uberfire.java.nio.file.Path ioPath = Paths.convert(path); if (pathResolver.isDotFile(ioPath)) { org.uberfire.java.nio.file.Path ioPrincipleFilePath = pathResolver.resolveMainFilePath(ioPath); if (!ioService.exists(ioPrincipleFilePath)) { ioPrincipleFilePath = ioPath; } final Path principleFilePath = Paths.convert(ioPrincipleFilePath); return constructContent(principleFilePath, overviewLoader.loadOverview(principleFilePath)); } else { return constructContent(path, overviewLoader.loadOverview(path)); } } catch (Exception e) { throw ExceptionUtilities.handleException(e); } } T loadContent(Path path); String getSource(final Path path); }### Answer: @Test public void testBasic() throws Exception { TestModel testModel = kieService.loadContent(Paths.convert(mainFilePath)); assertNotNull(testModel); assertMetadataRequestedForMainFile(); } @Test public void testProjectName() throws Exception { final KieModule module = mock(KieModule.class); doReturn(module).when(moduleService).resolveModule(any(Path.class)); final WorkspaceProject project = mock(WorkspaceProject.class); doReturn("test name").when(project).getName(); doReturn(project).when(projectService).resolveProject(any(Path.class)); final TestModel testModel = kieService.loadContent(Paths.convert(mainFilePath)); assertEquals("test name", testModel.overview.getProjectName()); } @Test public void testPathPointsToDotFile() throws Exception { TestModel testModel = kieService.loadContent(Paths.convert(dotFilePath)); assertNotNull(testModel); assertMetadataRequestedForMainFile(); } @Test public void testPathPointsToOrphanDotFile() throws Exception { TestModel testModel = kieService.loadContent(Paths.convert(orphanDotFilePath)); assertNotNull(testModel); assertMetadataRequestedForOrphanFile(); }
### Question: AbstractInvalidateDMOPackageCacheDeleteHelper implements DeleteHelper { @Override public boolean supports( final Path path ) { return resourceType.accept( path ); } AbstractInvalidateDMOPackageCacheDeleteHelper( final T resourceType, final Event<InvalidateDMOPackageCacheEvent> invalidateDMOPackageCache ); @Override boolean supports( final Path path ); @Override void postProcess( final Path path ); }### Answer: @Test public void checkMatchesResourceType() { final Path path = mock(Path.class); when(path.getFileName()).thenReturn("file." + resourceType.getSuffix()); assertTrue(helper.supports(path)); } @Test public void checkDoesNotMatchOtherResourceTypes() { final Path path = mock(Path.class); when(path.getFileName()).thenReturn("file.smurf"); assertFalse(helper.supports(path)); }
### Question: AbstractInvalidateDMOPackageCacheDeleteHelper implements DeleteHelper { @Override public void postProcess( final Path path ) { if ( supports( path ) ) { invalidateDMOPackageCache.fire( new InvalidateDMOPackageCacheEvent( path ) ); } } AbstractInvalidateDMOPackageCacheDeleteHelper( final T resourceType, final Event<InvalidateDMOPackageCacheEvent> invalidateDMOPackageCache ); @Override boolean supports( final Path path ); @Override void postProcess( final Path path ); }### Answer: @Test public void checkEventFiredWhenMatchesResourceType() { final Path path = mock(Path.class); when(path.getFileName()).thenReturn("file." + resourceType.getSuffix()); helper.postProcess(path); verify(invalidateDMOPackageCache, times(1)).fire(any(InvalidateDMOPackageCacheEvent.class)); } @Test public void checkEventNotFiredWhenNotMatchOtherResourceTypes() { final Path path = mock(Path.class); when(path.getFileName()).thenReturn("file.smurf"); helper.postProcess(path); verify(invalidateDMOPackageCache, never()).fire(any(InvalidateDMOPackageCacheEvent.class)); }
### Question: KModuleContentHandler { public String toString(KModuleModel model) { return createXStream().toXML(model); } KModuleModel toModel(String xml); String toString(KModuleModel model); }### Answer: @Test public void testMarshallingOfDefaultDroolsNameSpace() throws Exception { final KModuleContentHandler kModuleContentHandler = new KModuleContentHandler(); final String kmodule = kModuleContentHandler.toString(new KModuleModel()); assertNotNull(kmodule); assertTrue(kmodule.contains("xmlns=\"http: }
### Question: SourceServicesImpl implements SourceServices { @Override public boolean hasServiceFor( final Path path ) { try { final SourceService sourceService = getMatchingSourceService( path ); return sourceService != null; } catch ( Exception e ) { throw ExceptionUtilities.handleException( e ); } } SourceServicesImpl(); @Inject SourceServicesImpl( @Any Instance<SourceService<?>> sourceServiceList ); @Override boolean hasServiceFor( final Path path ); @Override SourceService getServiceFor( final Path path ); }### Answer: @Test public void testSomethingSimple() throws Exception { addToList(getSourceService(".drl")); assertTrue(new SourceServicesImpl(instance).hasServiceFor(makePath("myFile", ".drl"))); } @Test public void testMissing() throws Exception { addToList(getSourceService(".notHere")); assertFalse(new SourceServicesImpl(instance).hasServiceFor(makePath("myFile", ".drl"))); }
### Question: SourceServicesImpl implements SourceServices { @Override public SourceService getServiceFor( final Path path ) { try { final SourceService sourceService = getMatchingSourceService( path ); if ( sourceService == null ) { throw new IllegalArgumentException( "No SourceService found for '" + path + "'." ); } return sourceService; } catch ( Exception e ) { throw ExceptionUtilities.handleException( e ); } } SourceServicesImpl(); @Inject SourceServicesImpl( @Any Instance<SourceService<?>> sourceServiceList ); @Override boolean hasServiceFor( final Path path ); @Override SourceService getServiceFor( final Path path ); }### Answer: @Test public void testShorter() throws Exception { SourceService DRL = getSourceService(".drl"); SourceService modelDRL = getSourceService(".model.drl"); addToList(DRL, modelDRL); assertEquals(DRL, new SourceServicesImpl(instance).getServiceFor(makePath("myFile", ".drl"))); sourceServices.clear(); addToList(modelDRL, DRL); assertEquals(DRL, new SourceServicesImpl(instance).getServiceFor(makePath("myFile", ".drl"))); } @Test public void testLonger() throws Exception { SourceService DRL = getSourceService(".drl"); SourceService modelDRL = getSourceService(".model.drl"); addToList(DRL, modelDRL); assertEquals(modelDRL, new SourceServicesImpl(instance).getServiceFor(makePath("myFile", ".model.drl"))); sourceServices.clear(); addToList(modelDRL, DRL); assertEquals(modelDRL, new SourceServicesImpl(instance).getServiceFor(makePath("myFile", ".model.drl"))); }
### Question: BuildInfoService { public BuildInfo getBuildInfo(final Module module) { final Builder[] result = {builderCache.getBuilder(module)}; if (result[0] == null || !result[0].isBuilt()) { ((BuildServiceImpl) buildService).build(module, builder -> result[0] = builder); } return new BuildInfoImpl(result[0]); } BuildInfoService(); @Inject BuildInfoService(BuildService buildService, LRUBuilderCache builderCache); BuildInfo getBuildInfo(final Module module); }### Answer: @Test public void testGetBuildInfoWhenModuleIsBuilt() { when(cache.getBuilder(module)).thenReturn(builder); when(builder.isBuilt()).thenReturn(true); BuildInfo expectedBuildInfo = new BuildInfoImpl(builder); BuildInfo result = buildInfoService.getBuildInfo(module); assertEquals(expectedBuildInfo, result); verify(cache, times(1)).getBuilder(module); verify(buildService, never()).build(eq(module), any(Consumer.class)); }
### Question: BuildServiceHelper { public BuildResults localBuild(Module module) { final BuildResults[] result = new BuildResults[1]; invokeLocalBuildPipeLine(module, localBinaryConfig -> { result[0] = localBinaryConfig.getBuildResults(); }); return result[0]; } BuildServiceHelper(); @Inject BuildServiceHelper(BuildPipelineInvoker buildPipelineInvoker, DeploymentVerifier deploymentVerifier); BuildResults localBuild(Module module); void localBuild(Module module, Consumer<LocalBinaryConfig> consumer); IncrementalBuildResults localBuild(Module module, LocalBuildConfig.BuildType buildType, Path resource); IncrementalBuildResults localBuild(Module module, Map<Path, Collection<ResourceChange>> resourceChanges); BuildResults localBuildAndDeploy(final Module module, final DeploymentMode mode, final boolean suppressHandlers); }### Answer: @Test public void testLocalBuild() { prepareLocalFullBuild(); when(localBinaryConfig.getBuildResults()).thenReturn(buildResults); BuildResults result = serviceHelper.localBuild(module); assertEquals(buildResults, result); verify(pipelineInvoker, times(1)).invokeLocalBuildPipeLine(eq(expectedRequest), any(Consumer.class)); }
### Question: BuildServiceHelper { public BuildResults localBuildAndDeploy(final Module module, final DeploymentMode mode, final boolean suppressHandlers) { final BuildResults[] result = new BuildResults[1]; invokeLocalBuildPipeLine(module, suppressHandlers, mode, localBinaryConfig -> { result[0] = localBinaryConfig.getBuildResults(); }); return result[0]; } BuildServiceHelper(); @Inject BuildServiceHelper(BuildPipelineInvoker buildPipelineInvoker, DeploymentVerifier deploymentVerifier); BuildResults localBuild(Module module); void localBuild(Module module, Consumer<LocalBinaryConfig> consumer); IncrementalBuildResults localBuild(Module module, LocalBuildConfig.BuildType buildType, Path resource); IncrementalBuildResults localBuild(Module module, Map<Path, Collection<ResourceChange>> resourceChanges); BuildResults localBuildAndDeploy(final Module module, final DeploymentMode mode, final boolean suppressHandlers); }### Answer: @Test public void testLocalBuildAndDeployForced() { prepareBuildAndDeploy(module, LocalBuildConfig.DeploymentType.FORCED, false); BuildResults result = serviceHelper.localBuildAndDeploy(module, DeploymentMode.FORCED, false); verifyBuildAndDeploy(result); } @Test public void testLocalBuildAndDeployValidated() { prepareBuildAndDeploy(module, LocalBuildConfig.DeploymentType.VALIDATED, false); BuildResults result = serviceHelper.localBuildAndDeploy(module, DeploymentMode.VALIDATED, false); verifyBuildAndDeploy(result); }
### Question: BuildServiceImpl implements BuildService { @Override public BuildResults build(final Module module) { return buildServiceHelper.localBuild(module); } BuildServiceImpl(); @Inject BuildServiceImpl(final KieModuleService moduleService, final BuildServiceHelper buildServiceHelper, final LRUBuilderCache cache); @Override BuildResults build(final Module module); void build(final Module module, final Consumer<Builder> consumer); @Override BuildResults buildAndDeploy(final Module module); @Override BuildResults buildAndDeploy(final Module module, final DeploymentMode mode); @Override BuildResults buildAndDeploy(final Module module, final boolean suppressHandlers); @Override BuildResults buildAndDeploy(final Module module, final boolean suppressHandlers, final DeploymentMode mode); @Override boolean isBuilt(final Module module); @Override IncrementalBuildResults addPackageResource(final Path resource); @Override IncrementalBuildResults deletePackageResource(final Path resource); @Override IncrementalBuildResults updatePackageResource(final Path resource); @Override IncrementalBuildResults applyBatchResourceChanges(final Module module, final Map<Path, Collection<ResourceChange>> changes); }### Answer: @Test public void testBuild() { when(buildServiceHelper.localBuild(module)).thenReturn(buildResults); BuildResults result = buildService.build(module); assertEquals(buildResults, result); } @Test public void testBuildWithConsumer() { when(localBinaryConfig.getBuilder()).thenReturn(builder); doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock invocation) { Consumer consumer = (Consumer) invocation.getArguments()[1]; consumer.accept(localBinaryConfig); return null; } }).when(buildServiceHelper).localBuild(eq(module), any(Consumer.class)); buildService.build(module, new Consumer<Builder>() { @Override public void accept(Builder result) { assertEquals(builder, result); } }); verify(buildServiceHelper, times(1)).localBuild(eq(module), any(Consumer.class)); }
### Question: BuildServiceImpl implements BuildService { @Override public boolean isBuilt(final Module module) { final Builder builder = cache.assertBuilder(module); return builder.isBuilt(); } BuildServiceImpl(); @Inject BuildServiceImpl(final KieModuleService moduleService, final BuildServiceHelper buildServiceHelper, final LRUBuilderCache cache); @Override BuildResults build(final Module module); void build(final Module module, final Consumer<Builder> consumer); @Override BuildResults buildAndDeploy(final Module module); @Override BuildResults buildAndDeploy(final Module module, final DeploymentMode mode); @Override BuildResults buildAndDeploy(final Module module, final boolean suppressHandlers); @Override BuildResults buildAndDeploy(final Module module, final boolean suppressHandlers, final DeploymentMode mode); @Override boolean isBuilt(final Module module); @Override IncrementalBuildResults addPackageResource(final Path resource); @Override IncrementalBuildResults deletePackageResource(final Path resource); @Override IncrementalBuildResults updatePackageResource(final Path resource); @Override IncrementalBuildResults applyBatchResourceChanges(final Module module, final Map<Path, Collection<ResourceChange>> changes); }### Answer: @Test public void testIsBuiltTrue() { when(cache.assertBuilder(module)).thenReturn(builder); when(builder.isBuilt()).thenReturn(true); assertTrue(buildService.isBuilt(module)); } @Test public void testIsBuiltFalse() { when(cache.assertBuilder(module)).thenReturn(builder); when(builder.isBuilt()).thenReturn(false); assertFalse(buildService.isBuilt(module)); }
### Question: BuildServiceImpl implements BuildService { @Override public IncrementalBuildResults addPackageResource(final Path resource) { return buildIncrementally(resource, LocalBuildConfig.BuildType.INCREMENTAL_ADD_RESOURCE); } BuildServiceImpl(); @Inject BuildServiceImpl(final KieModuleService moduleService, final BuildServiceHelper buildServiceHelper, final LRUBuilderCache cache); @Override BuildResults build(final Module module); void build(final Module module, final Consumer<Builder> consumer); @Override BuildResults buildAndDeploy(final Module module); @Override BuildResults buildAndDeploy(final Module module, final DeploymentMode mode); @Override BuildResults buildAndDeploy(final Module module, final boolean suppressHandlers); @Override BuildResults buildAndDeploy(final Module module, final boolean suppressHandlers, final DeploymentMode mode); @Override boolean isBuilt(final Module module); @Override IncrementalBuildResults addPackageResource(final Path resource); @Override IncrementalBuildResults deletePackageResource(final Path resource); @Override IncrementalBuildResults updatePackageResource(final Path resource); @Override IncrementalBuildResults applyBatchResourceChanges(final Module module, final Map<Path, Collection<ResourceChange>> changes); }### Answer: @Test public void testAddPackageResource() { prepareIncrementalBuild(path, LocalBuildConfig.BuildType.INCREMENTAL_ADD_RESOURCE); IncrementalBuildResults result = buildService.addPackageResource(path); assertEquals(incrementalBuildResults, result); verifyIncrementalBuild(path, LocalBuildConfig.BuildType.INCREMENTAL_ADD_RESOURCE); }
### Question: BuildServiceImpl implements BuildService { @Override public IncrementalBuildResults deletePackageResource(final Path resource) { return buildIncrementally(resource, LocalBuildConfig.BuildType.INCREMENTAL_DELETE_RESOURCE); } BuildServiceImpl(); @Inject BuildServiceImpl(final KieModuleService moduleService, final BuildServiceHelper buildServiceHelper, final LRUBuilderCache cache); @Override BuildResults build(final Module module); void build(final Module module, final Consumer<Builder> consumer); @Override BuildResults buildAndDeploy(final Module module); @Override BuildResults buildAndDeploy(final Module module, final DeploymentMode mode); @Override BuildResults buildAndDeploy(final Module module, final boolean suppressHandlers); @Override BuildResults buildAndDeploy(final Module module, final boolean suppressHandlers, final DeploymentMode mode); @Override boolean isBuilt(final Module module); @Override IncrementalBuildResults addPackageResource(final Path resource); @Override IncrementalBuildResults deletePackageResource(final Path resource); @Override IncrementalBuildResults updatePackageResource(final Path resource); @Override IncrementalBuildResults applyBatchResourceChanges(final Module module, final Map<Path, Collection<ResourceChange>> changes); }### Answer: @Test public void testDeletePackageResource() { prepareIncrementalBuild(path, LocalBuildConfig.BuildType.INCREMENTAL_DELETE_RESOURCE); IncrementalBuildResults result = buildService.deletePackageResource(path); assertEquals(incrementalBuildResults, result); verifyIncrementalBuild(path, LocalBuildConfig.BuildType.INCREMENTAL_DELETE_RESOURCE); }
### Question: BuildServiceImpl implements BuildService { @Override public IncrementalBuildResults updatePackageResource(final Path resource) { return buildIncrementally(resource, LocalBuildConfig.BuildType.INCREMENTAL_UPDATE_RESOURCE); } BuildServiceImpl(); @Inject BuildServiceImpl(final KieModuleService moduleService, final BuildServiceHelper buildServiceHelper, final LRUBuilderCache cache); @Override BuildResults build(final Module module); void build(final Module module, final Consumer<Builder> consumer); @Override BuildResults buildAndDeploy(final Module module); @Override BuildResults buildAndDeploy(final Module module, final DeploymentMode mode); @Override BuildResults buildAndDeploy(final Module module, final boolean suppressHandlers); @Override BuildResults buildAndDeploy(final Module module, final boolean suppressHandlers, final DeploymentMode mode); @Override boolean isBuilt(final Module module); @Override IncrementalBuildResults addPackageResource(final Path resource); @Override IncrementalBuildResults deletePackageResource(final Path resource); @Override IncrementalBuildResults updatePackageResource(final Path resource); @Override IncrementalBuildResults applyBatchResourceChanges(final Module module, final Map<Path, Collection<ResourceChange>> changes); }### Answer: @Test public void testUpdatePackageResource() { prepareIncrementalBuild(path, LocalBuildConfig.BuildType.INCREMENTAL_UPDATE_RESOURCE); IncrementalBuildResults result = buildService.updatePackageResource(path); assertEquals(incrementalBuildResults, result); verifyIncrementalBuild(path, LocalBuildConfig.BuildType.INCREMENTAL_UPDATE_RESOURCE); }
### Question: BuildServiceImpl implements BuildService { @Override public IncrementalBuildResults applyBatchResourceChanges(final Module module, final Map<Path, Collection<ResourceChange>> changes) { if (module == null) { return new IncrementalBuildResults(); } return buildServiceHelper.localBuild(module, changes); } BuildServiceImpl(); @Inject BuildServiceImpl(final KieModuleService moduleService, final BuildServiceHelper buildServiceHelper, final LRUBuilderCache cache); @Override BuildResults build(final Module module); void build(final Module module, final Consumer<Builder> consumer); @Override BuildResults buildAndDeploy(final Module module); @Override BuildResults buildAndDeploy(final Module module, final DeploymentMode mode); @Override BuildResults buildAndDeploy(final Module module, final boolean suppressHandlers); @Override BuildResults buildAndDeploy(final Module module, final boolean suppressHandlers, final DeploymentMode mode); @Override boolean isBuilt(final Module module); @Override IncrementalBuildResults addPackageResource(final Path resource); @Override IncrementalBuildResults deletePackageResource(final Path resource); @Override IncrementalBuildResults updatePackageResource(final Path resource); @Override IncrementalBuildResults applyBatchResourceChanges(final Module module, final Map<Path, Collection<ResourceChange>> changes); }### Answer: @Test public void testApplyBatchResourceChanges() { when(buildServiceHelper.localBuild(module, resourceChanges)).thenReturn(incrementalBuildResults); IncrementalBuildResults result = buildService.applyBatchResourceChanges(module, resourceChanges); assertEquals(incrementalBuildResults, result); verify(buildServiceHelper, times(1)).localBuild(module, resourceChanges); }
### Question: ClassVerifier { private void verifyClass(final String packageName, final String className) { try { final Class clazz = kieModuleMetaData.getClass(packageName, className); if (clazz != null) { if (TypeSource.JAVA_DEPENDENCY == typeSourceResolver.getTypeSource(clazz)) { verifyExternalClass(clazz); } } else { logger.warn(MessageFormat.format(ERROR_EXTERNAL_CLASS_VERIFICATION, toFQCN(packageName, className))); } } catch (Throwable e) { final String msg = MessageFormat.format(ERROR_EXTERNAL_CLASS_VERIFICATION, toFQCN(packageName, className), e.getMessage()); logger.warn(msg); logger.debug("This state is usually encountered when the Project references a class not on the classpath; e.g. in a Maven 'provided' scope or 'optional' dependency.", e); buildMessages.add(makeWarningMessage(msg)); } } ClassVerifier(final KieModuleMetaData kieModuleMetaData, final TypeSourceResolver typeSourceResolver); List<BuildMessage> verify(WhiteList whiteList); }### Answer: @Test public void testVerifyClass(){ WhiteList whiteList = new WhiteList(); whiteList.add("org.kie.workbench.common.services.backend.builder"); ClassVerifier classVerifier = new ClassVerifier(kieModuleMetaData, typeSourceResolver); List<BuildMessage> messages = classVerifier.verify(whiteList); assertEquals(messages.size(), 1); assertEquals("Verification of class org.kie.workbench.common.services.backend.builder.SomeClass failed and will not be available for authoring.\n" + "Underlying system error is: The access to the class is not allowed. Please check the necessary external dependencies for this project are configured correctly.", messages.get(0).getText()); }
### Question: ObservableProjectImportsFile implements ResourceChangeObservableFile { @Override public boolean accept(final Path path) { final String fileName = path.getFileName(); return fileName.equals(FILENAME); } @Override boolean accept(final Path path); }### Answer: @Test public void testAcceptWithoutProjectImportsFile() { doReturn("Cheese.txt").when(path).getFileName(); assertFalse(observer.accept(path)); } @Test public void testAcceptWithProjectImportsFile() { doReturn(ObservableProjectImportsFile.FILENAME).when(path).getFileName(); assertTrue(observer.accept(path)); }
### Question: ObservableKModuleFile implements ResourceChangeObservableFile { @Override public boolean accept(final Path path) { final String fileName = path.getFileName(); return fileName.equals(FILENAME); } @Override boolean accept(final Path path); }### Answer: @Test public void testAcceptWithoutKModuleFile() { doReturn("Cheese.txt").when(path).getFileName(); assertFalse(observer.accept(path)); } @Test public void testAcceptWithKModuleFile() { doReturn(ObservableKModuleFile.FILENAME).when(path).getFileName(); assertTrue(observer.accept(path)); }
### Question: LRUBuilderCache extends LRUCache<Module, Builder> { protected static String validateCacheSize(final String value) { if (value == null || value.length() == 0 || !value.matches("^[0-9]*$")) { logger.error("Illeagal Argument : Property {} should be a positive integer", BUILDER_CACHE_SIZE); return DEFAULT_BUILDER_CACHE_SIZE; } return value; } LRUBuilderCache(); @Inject LRUBuilderCache(final @Named("ioStrategy") IOService ioService, final KieModuleService moduleService, final ProjectImportsService importsService, final @Any Instance<BuildValidationHelper> buildValidationHelperBeans, final @Named("LRUModuleDependenciesClassLoaderCache") LRUModuleDependenciesClassLoaderCache dependenciesClassLoaderCache, final @Named("LRUPomModelCache") LRUPomModelCache pomModelCache, final PackageNameWhiteListService packageNameWhiteListService, final @JavaSourceFilter Instance<Predicate<String>> classFilterBeans); @PostConstruct void loadInstances(); @PreDestroy void destroyInstances(); void invalidateProjectCache(@Observes final InvalidateDMOModuleCacheEvent event); Builder assertBuilder(POM pom); Builder assertBuilder(final Module module); Builder getBuilder(final Module module); }### Answer: @Test public void testValidateCacheSize() { assertEquals(LRUBuilderCache.validateCacheSize("10"), "10"); assertEquals(LRUBuilderCache.validateCacheSize("-10"), LRUBuilderCache.DEFAULT_BUILDER_CACHE_SIZE); assertEquals(LRUBuilderCache.validateCacheSize(""), LRUBuilderCache.DEFAULT_BUILDER_CACHE_SIZE); assertEquals(LRUBuilderCache.validateCacheSize("ab"), LRUBuilderCache.DEFAULT_BUILDER_CACHE_SIZE); assertEquals(LRUBuilderCache.validateCacheSize(null), LRUBuilderCache.DEFAULT_BUILDER_CACHE_SIZE); }
### Question: BuildHelper { public BuildResult build(final Module module) { try { cache.invalidateCache(module); Builder builder = cache.assertBuilder(module); final BuildResults results = builder.build(); BuildMessage infoMsg = new BuildMessage(); infoMsg.setLevel(Level.INFO); infoMsg.setText(buildResultMessage(module, results).toString()); results.addBuildMessage(0, infoMsg); return new BuildResult(builder, results); } catch (Exception e) { logger.error(e.getMessage(), e); return new BuildResult(null, buildExceptionResults(e, module.getPom().getGav())); } } BuildHelper(); @Inject BuildHelper(final POMService pomService, final ExtendedM2RepoService m2RepoService, final KieModuleService moduleService, final DeploymentVerifier deploymentVerifier, final LRUBuilderCache cache, final Instance<PostBuildHandler> handlers, final Instance<User> identity); BuildResult build(final Module module); IncrementalBuildResults addPackageResource(final Path resource); IncrementalBuildResults deletePackageResource(final Path resource); IncrementalBuildResults updatePackageResource(final Path resource); IncrementalBuildResults applyBatchResourceChanges(final Module module, final Map<Path, Collection<ResourceChange>> changes); BuildResults buildExceptionResults(Exception e, GAV gav); BuildResults buildAndDeploy(final Module module); BuildResults buildAndDeploy(final Module module, final DeploymentMode mode); BuildResults buildAndDeploy(final Module module, final boolean suppressHandlers); BuildResults buildAndDeploy(final Module module, final boolean suppressHandlers, final DeploymentMode mode); }### Answer: @Test public void testBuildThatDoesNotUpdateTheCache() throws Exception { final Path path = path(); buildHelper.build(moduleService.resolveModule(path)); assertTrue(cachedFileSystemDoesNotChange()); }
### Question: ObservablePackageNamesWhiteListFile implements ResourceChangeObservableFile { @Override public boolean accept(final Path path) { final String fileName = path.getFileName(); return fileName.equals(FILENAME); } @Override boolean accept(final Path path); }### Answer: @Test public void testAcceptWithoutPNWLFile() { doReturn("Cheese.txt").when(path).getFileName(); assertFalse(observer.accept(path)); } @Test public void testAcceptWithPNWLFile() { doReturn(ObservablePackageNamesWhiteListFile.FILENAME).when(path).getFileName(); assertTrue(observer.accept(path)); }
### Question: DeploymentVerifier { public void verifyWithException(final Module module, DeploymentMode deploymentMode) { if (DeploymentMode.VALIDATED.equals(deploymentMode)) { final GAV gav = module.getPom().getGav(); if (gav.isSnapshot()) { return; } final ModuleRepositories projectRepositories = moduleRepositoriesService.load(((KieModule) module).getRepositoriesPath()); final Set<MavenRepositoryMetadata> repositories = repositoryResolver.getRepositoriesResolvingArtifact(gav, module, projectRepositories.filterByIncluded()); if (repositories.size() > 0) { throw new GAVAlreadyExistsException(gav, repositories); } } } DeploymentVerifier(); @Inject DeploymentVerifier(final ModuleRepositoryResolver repositoryResolver, final ModuleRepositoriesService moduleRepositoriesService); void verifyWithException(final Module module, DeploymentMode deploymentMode); }### Answer: @Test public void testVerifyAlreadyDeployedValidatedNonSNAPSHOT() { prepareProjectIsDeployed(true); when(gav.isSnapshot()).thenReturn(false); try { deploymentVerifier.verifyWithException(module, DeploymentMode.VALIDATED); } catch (Exception e) { exception = e; } assertNotNull(exception); assertTrue(exception instanceof GAVAlreadyExistsException); assertEquals(gav, ((GAVAlreadyExistsException) exception).getGAV()); assertEquals(repositories, ((GAVAlreadyExistsException) exception).getRepositories()); }
### Question: LRUPomModelCache extends LRUCache<Module, PomModel> { public void invalidateProjectCache(@Observes final InvalidateDMOModuleCacheEvent event) { PortablePreconditions.checkNotNull("event", event); final Path resourcePath = event.getResourcePath(); final KieModule module = moduleService.resolveModule(resourcePath); if (module != null) { invalidateCache(module); } } LRUPomModelCache(); @Inject LRUPomModelCache(final KieModuleService moduleService); void invalidateProjectCache(@Observes final InvalidateDMOModuleCacheEvent event); }### Answer: @Test public void testCacheIsInvalidatedWhenResourceThatMapsToProject() { final InvalidateDMOModuleCacheEvent event = new InvalidateDMOModuleCacheEvent(sessionInfo, module, resourcePath); doReturn(module).when(moduleService).resolveModule(resourcePath); cache.invalidateProjectCache(event); verify(cache).invalidateCache(eq(module)); verify(cache, never()).invalidateCache(eq(otherModule)); }
### Question: MessageConverter { static BuildMessage convertMessage(final Message message, Handles handles) { final BuildMessage m = new BuildMessage(); switch (message.getLevel()) { case ERROR: m.setLevel(Level.ERROR); break; case WARNING: m.setLevel(Level.WARNING); break; case INFO: m.setLevel(Level.INFO); break; } m.setId(message.getId()); m.setLine(message.getLine()); m.setPath(convertPath(message.getPath(), handles)); m.setColumn(message.getColumn()); m.setText(convertMessageText(message)); return m; } }### Answer: @Test public void checkMessageWithKieBase() { final MessageImpl m = new MessageImpl(ID, Message.Level.ERROR, FILE, TEXT); m.setKieBaseName(KIE_BASE_NAME); final BuildMessage bm = MessageConverter.convertMessage(m, handles); assertConversion(bm, () -> "[KBase: " + KIE_BASE_NAME + "]: " + TEXT); } @Test public void checkMessageWithoutKieBase() { final Message m = new MessageImpl(ID, Message.Level.ERROR, FILE, TEXT); final BuildMessage bm = MessageConverter.convertMessage(m, handles); assertConversion(bm, () -> TEXT); }
### Question: LocalSourceConfigExecutor implements FunctionConfigExecutor< LocalSourceConfig, Source > { @Override public Optional< Source > apply( LocalSourceConfig localSourceConfig ) { Path path = Paths.get( URI.create( localSourceConfig.getRootPath() ) ); return Optional.of( new LocalSource( path ) ); } LocalSourceConfigExecutor( ); @Override Optional< Source > apply( LocalSourceConfig localSourceConfig ); @Override Class< ? extends Config > executeFor( ); @Override String outputId( ); }### Answer: @Test public void testApply( ) { when( sourceConfig.getRootPath( ) ).thenReturn( ROOT_PATH_URI ); Optional< Source > result = executor.apply( sourceConfig ); assertTrue( result.isPresent( ) ); assertEquals( ROOT_PATH, result.get( ).getPath( ) ); }
### Question: LocalModuleConfigExecutor implements BiFunctionConfigExecutor<Source, LocalProjectConfig, ProjectConfig> { @Override public Optional<ProjectConfig> apply(Source source, LocalProjectConfig localProjectConfig) { Module module = moduleService.resolveModule(Paths.convert(source.getPath().resolve("pom.xml"))); return Optional.of(new LocalModuleImpl(module)); } LocalModuleConfigExecutor(); @Inject LocalModuleConfigExecutor(final KieModuleService moduleService); @Override Optional<ProjectConfig> apply(Source source, LocalProjectConfig localProjectConfig); @Override Class<? extends Config> executeFor(); @Override String outputId(); }### Answer: @Test public void testApply() { Path pomPath = Paths.convert(POM_PATH); when(sourceConfig.getPath()).thenReturn(ROOT_PATH); when(moduleService.resolveModule(pomPath)).thenReturn(module); Optional<ProjectConfig> result = executor.apply(sourceConfig, projectConfig); assertTrue(result.isPresent()); assertEquals(module, ((LocalModule) result.get()).getModule()); }
### Question: LocalBuildConfigExecutor implements BiFunctionConfigExecutor<LocalModule, LocalBuildConfig, BuildConfig> { @Override public Optional<BuildConfig> apply(LocalModule localModule, LocalBuildConfig localBuildConfig) { Optional<BuildConfig> result = Optional.empty(); LocalBuildConfig.BuildType buildType = decodeBuildType(localBuildConfig.getBuildType()); switch (buildType) { case FULL_BUILD: result = Optional.of(new LocalBuildConfigInternal(localModule.getModule())); break; case INCREMENTAL_ADD_RESOURCE: case INCREMENTAL_DELETE_RESOURCE: case INCREMENTAL_UPDATE_RESOURCE: result = Optional.of(new LocalBuildConfigInternal(localModule.getModule(), buildType, decodePath(localBuildConfig.getResource()))); break; case INCREMENTAL_BATCH_CHANGES: result = Optional.of(new LocalBuildConfigInternal(localModule.getModule(), getResourceChanges(localBuildConfig.getResourceChanges()))); break; case FULL_BUILD_AND_DEPLOY: result = Optional.of(new LocalBuildConfigInternal(localModule.getModule(), decodeDeploymentType(localBuildConfig.getDeploymentType()), decodeSuppressHandlers(localBuildConfig.getSuppressHandlers()))); } return result; } LocalBuildConfigExecutor(); @Override Optional<BuildConfig> apply(LocalModule localModule, LocalBuildConfig localBuildConfig); @Override Class<? extends Config> executeFor(); @Override String outputId(); }### Answer: @Test public void testApplyForModuleFullBuild() { when(localModule.getModule()).thenReturn(project); when(buildConfig.getBuildType()).thenReturn(LocalBuildConfig.BuildType.FULL_BUILD.name()); Optional<BuildConfig> result = executor.apply(localModule, buildConfig); assertTrue(result.isPresent()); assertEquals(LocalBuildConfig.BuildType.FULL_BUILD, ((LocalBuildConfigInternal) result.get()).getBuildType()); assertEquals(project, ((LocalBuildConfigInternal) result.get()).getModule()); }
### Question: JavaFileProjectResourcePathResolver implements ModuleResourcePathResolver { @Override public boolean accept(String resourceType) { return "java".equals(resourceType); } JavaFileProjectResourcePathResolver(); @Override int getPriority(); @Override boolean accept(String resourceType); @Override Path resolveDefaultPath(Package pkg); }### Answer: @Test public void testAcceptJavaFile() { assertTrue( resolver.accept( "java" ) ); } @Test public void testDenyNonJavaFile() { assertFalse( resolver.accept( "txt" ) ); assertFalse( resolver.accept( null ) ); assertFalse( resolver.accept( "" ) ); }
### Question: JavaFileProjectResourcePathResolver implements ModuleResourcePathResolver { @Override public Path resolveDefaultPath(Package pkg) { return pkg.getPackageMainSrcPath(); } JavaFileProjectResourcePathResolver(); @Override int getPriority(); @Override boolean accept(String resourceType); @Override Path resolveDefaultPath(Package pkg); }### Answer: @Test public void testResolveByDefaultPath() { assertEquals( packageMainSrcPath, resolver.resolveDefaultPath( pkg ) ); verify( pkg, times( 1 ) ).getPackageMainSrcPath(); }