method2testcases
stringlengths
118
3.08k
### Question: EditorSessionCommands { public UndoSessionCommand getUndoSessionCommand() { return commands.get(UndoSessionCommand.class); } @Inject EditorSessionCommands(final ManagedClientSessionCommands commands); @PostConstruct void init(); EditorSessionCommands bind(final ClientSession session); ManagedClientSessionCommands getCommands(); VisitGraphSessionCommand getVisitGraphSessionCommand(); SwitchGridSessionCommand getSwitchGridSessionCommand(); ClearSessionCommand getClearSessionCommand(); DeleteSelectionSessionCommand getDeleteSelectionSessionCommand(); UndoSessionCommand getUndoSessionCommand(); RedoSessionCommand getRedoSessionCommand(); ValidateSessionCommand getValidateSessionCommand(); ExportToPngSessionCommand getExportToPngSessionCommand(); ExportToJpgSessionCommand getExportToJpgSessionCommand(); ExportToPdfSessionCommand getExportToPdfSessionCommand(); ExportToSvgSessionCommand getExportToSvgSessionCommand(); ExportToRawFormatSessionCommand getExportToRawFormatSessionCommand(); CopySelectionSessionCommand getCopySelectionSessionCommand(); PasteSelectionSessionCommand getPasteSelectionSessionCommand(); CutSelectionSessionCommand getCutSelectionSessionCommand(); SaveDiagramSessionCommand getSaveDiagramSessionCommand(); S get(final Class<? extends ClientSessionCommand> type); }### Answer: @Test public void testGetUndoSessionCommand() { editorSessionCommands.getUndoSessionCommand(); verify(commands).get(eq(UndoSessionCommand.class)); }
### Question: EditorSessionCommands { public RedoSessionCommand getRedoSessionCommand() { return commands.get(RedoSessionCommand.class); } @Inject EditorSessionCommands(final ManagedClientSessionCommands commands); @PostConstruct void init(); EditorSessionCommands bind(final ClientSession session); ManagedClientSessionCommands getCommands(); VisitGraphSessionCommand getVisitGraphSessionCommand(); SwitchGridSessionCommand getSwitchGridSessionCommand(); ClearSessionCommand getClearSessionCommand(); DeleteSelectionSessionCommand getDeleteSelectionSessionCommand(); UndoSessionCommand getUndoSessionCommand(); RedoSessionCommand getRedoSessionCommand(); ValidateSessionCommand getValidateSessionCommand(); ExportToPngSessionCommand getExportToPngSessionCommand(); ExportToJpgSessionCommand getExportToJpgSessionCommand(); ExportToPdfSessionCommand getExportToPdfSessionCommand(); ExportToSvgSessionCommand getExportToSvgSessionCommand(); ExportToRawFormatSessionCommand getExportToRawFormatSessionCommand(); CopySelectionSessionCommand getCopySelectionSessionCommand(); PasteSelectionSessionCommand getPasteSelectionSessionCommand(); CutSelectionSessionCommand getCutSelectionSessionCommand(); SaveDiagramSessionCommand getSaveDiagramSessionCommand(); S get(final Class<? extends ClientSessionCommand> type); }### Answer: @Test public void testGetRedoSessionCommand() { editorSessionCommands.getRedoSessionCommand(); verify(commands).get(eq(RedoSessionCommand.class)); }
### Question: EditorSessionCommands { public ValidateSessionCommand getValidateSessionCommand() { return commands.get(ValidateSessionCommand.class); } @Inject EditorSessionCommands(final ManagedClientSessionCommands commands); @PostConstruct void init(); EditorSessionCommands bind(final ClientSession session); ManagedClientSessionCommands getCommands(); VisitGraphSessionCommand getVisitGraphSessionCommand(); SwitchGridSessionCommand getSwitchGridSessionCommand(); ClearSessionCommand getClearSessionCommand(); DeleteSelectionSessionCommand getDeleteSelectionSessionCommand(); UndoSessionCommand getUndoSessionCommand(); RedoSessionCommand getRedoSessionCommand(); ValidateSessionCommand getValidateSessionCommand(); ExportToPngSessionCommand getExportToPngSessionCommand(); ExportToJpgSessionCommand getExportToJpgSessionCommand(); ExportToPdfSessionCommand getExportToPdfSessionCommand(); ExportToSvgSessionCommand getExportToSvgSessionCommand(); ExportToRawFormatSessionCommand getExportToRawFormatSessionCommand(); CopySelectionSessionCommand getCopySelectionSessionCommand(); PasteSelectionSessionCommand getPasteSelectionSessionCommand(); CutSelectionSessionCommand getCutSelectionSessionCommand(); SaveDiagramSessionCommand getSaveDiagramSessionCommand(); S get(final Class<? extends ClientSessionCommand> type); }### Answer: @Test public void testGetValidateSessionCommand() { editorSessionCommands.getValidateSessionCommand(); verify(commands).get(eq(ValidateSessionCommand.class)); }
### Question: EditorSessionCommands { public ExportToPngSessionCommand getExportToPngSessionCommand() { return commands.get(ExportToPngSessionCommand.class); } @Inject EditorSessionCommands(final ManagedClientSessionCommands commands); @PostConstruct void init(); EditorSessionCommands bind(final ClientSession session); ManagedClientSessionCommands getCommands(); VisitGraphSessionCommand getVisitGraphSessionCommand(); SwitchGridSessionCommand getSwitchGridSessionCommand(); ClearSessionCommand getClearSessionCommand(); DeleteSelectionSessionCommand getDeleteSelectionSessionCommand(); UndoSessionCommand getUndoSessionCommand(); RedoSessionCommand getRedoSessionCommand(); ValidateSessionCommand getValidateSessionCommand(); ExportToPngSessionCommand getExportToPngSessionCommand(); ExportToJpgSessionCommand getExportToJpgSessionCommand(); ExportToPdfSessionCommand getExportToPdfSessionCommand(); ExportToSvgSessionCommand getExportToSvgSessionCommand(); ExportToRawFormatSessionCommand getExportToRawFormatSessionCommand(); CopySelectionSessionCommand getCopySelectionSessionCommand(); PasteSelectionSessionCommand getPasteSelectionSessionCommand(); CutSelectionSessionCommand getCutSelectionSessionCommand(); SaveDiagramSessionCommand getSaveDiagramSessionCommand(); S get(final Class<? extends ClientSessionCommand> type); }### Answer: @Test public void testGetExportToPngSessionCommand() { editorSessionCommands.getExportToPngSessionCommand(); verify(commands).get(eq(ExportToPngSessionCommand.class)); }
### Question: EditorSessionCommands { public ExportToJpgSessionCommand getExportToJpgSessionCommand() { return commands.get(ExportToJpgSessionCommand.class); } @Inject EditorSessionCommands(final ManagedClientSessionCommands commands); @PostConstruct void init(); EditorSessionCommands bind(final ClientSession session); ManagedClientSessionCommands getCommands(); VisitGraphSessionCommand getVisitGraphSessionCommand(); SwitchGridSessionCommand getSwitchGridSessionCommand(); ClearSessionCommand getClearSessionCommand(); DeleteSelectionSessionCommand getDeleteSelectionSessionCommand(); UndoSessionCommand getUndoSessionCommand(); RedoSessionCommand getRedoSessionCommand(); ValidateSessionCommand getValidateSessionCommand(); ExportToPngSessionCommand getExportToPngSessionCommand(); ExportToJpgSessionCommand getExportToJpgSessionCommand(); ExportToPdfSessionCommand getExportToPdfSessionCommand(); ExportToSvgSessionCommand getExportToSvgSessionCommand(); ExportToRawFormatSessionCommand getExportToRawFormatSessionCommand(); CopySelectionSessionCommand getCopySelectionSessionCommand(); PasteSelectionSessionCommand getPasteSelectionSessionCommand(); CutSelectionSessionCommand getCutSelectionSessionCommand(); SaveDiagramSessionCommand getSaveDiagramSessionCommand(); S get(final Class<? extends ClientSessionCommand> type); }### Answer: @Test public void testGetExportToJpgSessionCommand() { editorSessionCommands.getExportToJpgSessionCommand(); verify(commands).get(eq(ExportToJpgSessionCommand.class)); }
### Question: EditorSessionCommands { public ExportToPdfSessionCommand getExportToPdfSessionCommand() { return commands.get(ExportToPdfSessionCommand.class); } @Inject EditorSessionCommands(final ManagedClientSessionCommands commands); @PostConstruct void init(); EditorSessionCommands bind(final ClientSession session); ManagedClientSessionCommands getCommands(); VisitGraphSessionCommand getVisitGraphSessionCommand(); SwitchGridSessionCommand getSwitchGridSessionCommand(); ClearSessionCommand getClearSessionCommand(); DeleteSelectionSessionCommand getDeleteSelectionSessionCommand(); UndoSessionCommand getUndoSessionCommand(); RedoSessionCommand getRedoSessionCommand(); ValidateSessionCommand getValidateSessionCommand(); ExportToPngSessionCommand getExportToPngSessionCommand(); ExportToJpgSessionCommand getExportToJpgSessionCommand(); ExportToPdfSessionCommand getExportToPdfSessionCommand(); ExportToSvgSessionCommand getExportToSvgSessionCommand(); ExportToRawFormatSessionCommand getExportToRawFormatSessionCommand(); CopySelectionSessionCommand getCopySelectionSessionCommand(); PasteSelectionSessionCommand getPasteSelectionSessionCommand(); CutSelectionSessionCommand getCutSelectionSessionCommand(); SaveDiagramSessionCommand getSaveDiagramSessionCommand(); S get(final Class<? extends ClientSessionCommand> type); }### Answer: @Test public void testGetExportToPdfSessionCommand() { editorSessionCommands.getExportToPdfSessionCommand(); verify(commands).get(eq(ExportToPdfSessionCommand.class)); }
### Question: EditorSessionCommands { public ExportToSvgSessionCommand getExportToSvgSessionCommand() { return commands.get(ExportToSvgSessionCommand.class); } @Inject EditorSessionCommands(final ManagedClientSessionCommands commands); @PostConstruct void init(); EditorSessionCommands bind(final ClientSession session); ManagedClientSessionCommands getCommands(); VisitGraphSessionCommand getVisitGraphSessionCommand(); SwitchGridSessionCommand getSwitchGridSessionCommand(); ClearSessionCommand getClearSessionCommand(); DeleteSelectionSessionCommand getDeleteSelectionSessionCommand(); UndoSessionCommand getUndoSessionCommand(); RedoSessionCommand getRedoSessionCommand(); ValidateSessionCommand getValidateSessionCommand(); ExportToPngSessionCommand getExportToPngSessionCommand(); ExportToJpgSessionCommand getExportToJpgSessionCommand(); ExportToPdfSessionCommand getExportToPdfSessionCommand(); ExportToSvgSessionCommand getExportToSvgSessionCommand(); ExportToRawFormatSessionCommand getExportToRawFormatSessionCommand(); CopySelectionSessionCommand getCopySelectionSessionCommand(); PasteSelectionSessionCommand getPasteSelectionSessionCommand(); CutSelectionSessionCommand getCutSelectionSessionCommand(); SaveDiagramSessionCommand getSaveDiagramSessionCommand(); S get(final Class<? extends ClientSessionCommand> type); }### Answer: @Test public void testGetExportToSvgSessionCommand() { editorSessionCommands.getExportToSvgSessionCommand(); verify(commands).get(eq(ExportToSvgSessionCommand.class)); }
### Question: EditorSessionCommands { public CopySelectionSessionCommand getCopySelectionSessionCommand() { return commands.get(CopySelectionSessionCommand.class); } @Inject EditorSessionCommands(final ManagedClientSessionCommands commands); @PostConstruct void init(); EditorSessionCommands bind(final ClientSession session); ManagedClientSessionCommands getCommands(); VisitGraphSessionCommand getVisitGraphSessionCommand(); SwitchGridSessionCommand getSwitchGridSessionCommand(); ClearSessionCommand getClearSessionCommand(); DeleteSelectionSessionCommand getDeleteSelectionSessionCommand(); UndoSessionCommand getUndoSessionCommand(); RedoSessionCommand getRedoSessionCommand(); ValidateSessionCommand getValidateSessionCommand(); ExportToPngSessionCommand getExportToPngSessionCommand(); ExportToJpgSessionCommand getExportToJpgSessionCommand(); ExportToPdfSessionCommand getExportToPdfSessionCommand(); ExportToSvgSessionCommand getExportToSvgSessionCommand(); ExportToRawFormatSessionCommand getExportToRawFormatSessionCommand(); CopySelectionSessionCommand getCopySelectionSessionCommand(); PasteSelectionSessionCommand getPasteSelectionSessionCommand(); CutSelectionSessionCommand getCutSelectionSessionCommand(); SaveDiagramSessionCommand getSaveDiagramSessionCommand(); S get(final Class<? extends ClientSessionCommand> type); }### Answer: @Test public void testGetCopySelectionSessionCommand() { editorSessionCommands.getCopySelectionSessionCommand(); verify(commands).get(eq(CopySelectionSessionCommand.class)); }
### Question: EditorSessionCommands { public PasteSelectionSessionCommand getPasteSelectionSessionCommand() { return commands.get(PasteSelectionSessionCommand.class); } @Inject EditorSessionCommands(final ManagedClientSessionCommands commands); @PostConstruct void init(); EditorSessionCommands bind(final ClientSession session); ManagedClientSessionCommands getCommands(); VisitGraphSessionCommand getVisitGraphSessionCommand(); SwitchGridSessionCommand getSwitchGridSessionCommand(); ClearSessionCommand getClearSessionCommand(); DeleteSelectionSessionCommand getDeleteSelectionSessionCommand(); UndoSessionCommand getUndoSessionCommand(); RedoSessionCommand getRedoSessionCommand(); ValidateSessionCommand getValidateSessionCommand(); ExportToPngSessionCommand getExportToPngSessionCommand(); ExportToJpgSessionCommand getExportToJpgSessionCommand(); ExportToPdfSessionCommand getExportToPdfSessionCommand(); ExportToSvgSessionCommand getExportToSvgSessionCommand(); ExportToRawFormatSessionCommand getExportToRawFormatSessionCommand(); CopySelectionSessionCommand getCopySelectionSessionCommand(); PasteSelectionSessionCommand getPasteSelectionSessionCommand(); CutSelectionSessionCommand getCutSelectionSessionCommand(); SaveDiagramSessionCommand getSaveDiagramSessionCommand(); S get(final Class<? extends ClientSessionCommand> type); }### Answer: @Test public void testGetPasteSelectionSessionCommand() { editorSessionCommands.getPasteSelectionSessionCommand(); verify(commands).get(eq(PasteSelectionSessionCommand.class)); }
### Question: EditorSessionCommands { public CutSelectionSessionCommand getCutSelectionSessionCommand() { return commands.get(CutSelectionSessionCommand.class); } @Inject EditorSessionCommands(final ManagedClientSessionCommands commands); @PostConstruct void init(); EditorSessionCommands bind(final ClientSession session); ManagedClientSessionCommands getCommands(); VisitGraphSessionCommand getVisitGraphSessionCommand(); SwitchGridSessionCommand getSwitchGridSessionCommand(); ClearSessionCommand getClearSessionCommand(); DeleteSelectionSessionCommand getDeleteSelectionSessionCommand(); UndoSessionCommand getUndoSessionCommand(); RedoSessionCommand getRedoSessionCommand(); ValidateSessionCommand getValidateSessionCommand(); ExportToPngSessionCommand getExportToPngSessionCommand(); ExportToJpgSessionCommand getExportToJpgSessionCommand(); ExportToPdfSessionCommand getExportToPdfSessionCommand(); ExportToSvgSessionCommand getExportToSvgSessionCommand(); ExportToRawFormatSessionCommand getExportToRawFormatSessionCommand(); CopySelectionSessionCommand getCopySelectionSessionCommand(); PasteSelectionSessionCommand getPasteSelectionSessionCommand(); CutSelectionSessionCommand getCutSelectionSessionCommand(); SaveDiagramSessionCommand getSaveDiagramSessionCommand(); S get(final Class<? extends ClientSessionCommand> type); }### Answer: @Test public void testGetCutSelectionSessionCommand() { editorSessionCommands.getCutSelectionSessionCommand(); verify(commands).get(eq(CutSelectionSessionCommand.class)); }
### Question: EditorSessionCommands { public SaveDiagramSessionCommand getSaveDiagramSessionCommand() { return commands.get(SaveDiagramSessionCommand.class); } @Inject EditorSessionCommands(final ManagedClientSessionCommands commands); @PostConstruct void init(); EditorSessionCommands bind(final ClientSession session); ManagedClientSessionCommands getCommands(); VisitGraphSessionCommand getVisitGraphSessionCommand(); SwitchGridSessionCommand getSwitchGridSessionCommand(); ClearSessionCommand getClearSessionCommand(); DeleteSelectionSessionCommand getDeleteSelectionSessionCommand(); UndoSessionCommand getUndoSessionCommand(); RedoSessionCommand getRedoSessionCommand(); ValidateSessionCommand getValidateSessionCommand(); ExportToPngSessionCommand getExportToPngSessionCommand(); ExportToJpgSessionCommand getExportToJpgSessionCommand(); ExportToPdfSessionCommand getExportToPdfSessionCommand(); ExportToSvgSessionCommand getExportToSvgSessionCommand(); ExportToRawFormatSessionCommand getExportToRawFormatSessionCommand(); CopySelectionSessionCommand getCopySelectionSessionCommand(); PasteSelectionSessionCommand getPasteSelectionSessionCommand(); CutSelectionSessionCommand getCutSelectionSessionCommand(); SaveDiagramSessionCommand getSaveDiagramSessionCommand(); S get(final Class<? extends ClientSessionCommand> type); }### Answer: @Test public void testGetSaveDiagramSessionCommand() { editorSessionCommands.getSaveDiagramSessionCommand(); verify(commands).get(eq(SaveDiagramSessionCommand.class)); }
### Question: DiagramEditorScreenViewImpl implements DiagramEditorScreenView, IsElement { @Override public DiagramEditorScreenView setWidget(final IsWidget widget) { widgetPanel.clear(); widgetPanel.add(widget); return this; } @Inject DiagramEditorScreenViewImpl(final @DataField FlowPanel loadingPanel, final @DataField FlowPanel widgetPanel); @Override DiagramEditorScreenView setWidget(final IsWidget widget); @Override DiagramEditorScreenView showLoading(); @Override DiagramEditorScreenView hideLoading(); @Override IsWidget asWidget(); @PreDestroy void destroy(); }### Answer: @Test public void testSetWidget() { tested.setWidget(widget); verify(widgetPanel, times(1)).clear(); verify(widgetPanel, times(1)).add(any(IsWidget.class)); }
### Question: DiagramEditorScreenViewImpl implements DiagramEditorScreenView, IsElement { @Override public DiagramEditorScreenView showLoading() { widgetPanel.setVisible(false); loadingPanel.setVisible(true); return this; } @Inject DiagramEditorScreenViewImpl(final @DataField FlowPanel loadingPanel, final @DataField FlowPanel widgetPanel); @Override DiagramEditorScreenView setWidget(final IsWidget widget); @Override DiagramEditorScreenView showLoading(); @Override DiagramEditorScreenView hideLoading(); @Override IsWidget asWidget(); @PreDestroy void destroy(); }### Answer: @Test public void testShowLoading() { tested.showLoading(); verify(widgetPanel, times(1)).setVisible(eq(false)); verify(loadingPanel, times(1)).setVisible(eq(true)); }
### Question: DiagramEditorScreenViewImpl implements DiagramEditorScreenView, IsElement { @Override public DiagramEditorScreenView hideLoading() { loadingPanel.setVisible(false); widgetPanel.setVisible(true); return this; } @Inject DiagramEditorScreenViewImpl(final @DataField FlowPanel loadingPanel, final @DataField FlowPanel widgetPanel); @Override DiagramEditorScreenView setWidget(final IsWidget widget); @Override DiagramEditorScreenView showLoading(); @Override DiagramEditorScreenView hideLoading(); @Override IsWidget asWidget(); @PreDestroy void destroy(); }### Answer: @Test public void testHideLoading() { tested.hideLoading(); verify(loadingPanel, times(1)).setVisible(eq(false)); verify(widgetPanel, times(1)).setVisible(eq(true)); }
### Question: DiagramEditorView extends BaseEditorViewImpl implements AbstractDiagramEditor.View { @Override public void setWidget(final IsWidget widget) { editorPanel.clear(); editorPanel.add(widget); } protected DiagramEditorView(); @Inject DiagramEditorView(final ResizeFlowPanel editorPanel); @Override void init(final DiagramEditorCore presenter); @Override void onResize(); @Override void setWidget(final IsWidget widget); @PreDestroy void destroy(); }### Answer: @Test public void testSetWidget() { final IsWidget editor = mock(IsWidget.class); tested.setWidget(editor); verify(editorPanel).clear(); verify(editorPanel).add(eq(editor)); }
### Question: DiagramEditorView extends BaseEditorViewImpl implements AbstractDiagramEditor.View { @Override public void onResize() { editorPanel.onResize(); } protected DiagramEditorView(); @Inject DiagramEditorView(final ResizeFlowPanel editorPanel); @Override void init(final DiagramEditorCore presenter); @Override void onResize(); @Override void setWidget(final IsWidget widget); @PreDestroy void destroy(); }### Answer: @Test public void testOnResize() { tested.onResize(); verify(editorPanel).onResize(); }
### Question: DiagramEditorView extends BaseEditorViewImpl implements AbstractDiagramEditor.View { @Override protected void onAttach() { super.onAttach(); if (getElement().getParentElement() != null) { getElement().getParentElement().getStyle().setHeight(100, Style.Unit.PCT); getElement().getParentElement().getStyle().setWidth(100, Style.Unit.PCT); getElement().getParentElement().getStyle().setDisplay(Style.Display.TABLE); } } protected DiagramEditorView(); @Inject DiagramEditorView(final ResizeFlowPanel editorPanel); @Override void init(final DiagramEditorCore presenter); @Override void onResize(); @Override void setWidget(final IsWidget widget); @PreDestroy void destroy(); }### Answer: @Test public void testOnAttach() { testOnAttach(true); testOnAttach(false); }
### Question: ProjectFullProfile extends FullProfile implements ProjectProfile { @Override public String getProjectProfileName() { return Profile.FULL.getName(); } @Override String getProjectProfileName(); }### Answer: @Test public void testProfile() { ProjectFullProfile profile = new ProjectFullProfile(); assertEquals(Profile.FULL.getName(), profile.getProjectProfileName()); assertTrue(profile.definitionAllowedFilter().test("anyBeanTypeAllowed1")); assertTrue(profile.definitionAllowedFilter().test("anyBeanTypeAllowed2")); assertTrue(profile.definitionAllowedFilter().test("anyBeanTypeAllowed3")); assertTrue(profile.definitionAllowedFilter().test("others")); }
### Question: ProjectDiagramResourceServiceImpl implements ProjectDiagramResourceService { @PostConstruct public void init() { saveAndRenameService.init(this); } ProjectDiagramResourceServiceImpl(); @Inject ProjectDiagramResourceServiceImpl(final ProjectDiagramService projectDiagramService, final RenameService renameService, final SaveAndRenameServiceImpl<ProjectDiagramResource, Metadata> saveAndRenameService); @PostConstruct void init(); @Override Path save(final Path path, final ProjectDiagramResource resource, final Metadata metadata, final String comment); @Override Path rename(final Path path, final String newName, final String comment); @Override Path saveAndRename(final Path path, final String newFileName, final Metadata metadata, final ProjectDiagramResource resource, final String comment); }### Answer: @Test public void testInit() { service.init(); verify(saveAndRenameService).init(service); }
### Question: ProjectDiagramResourceServiceImpl implements ProjectDiagramResourceService { @Override public Path rename(final Path path, final String newName, final String comment) { return renameService.rename(path, newName, comment); } ProjectDiagramResourceServiceImpl(); @Inject ProjectDiagramResourceServiceImpl(final ProjectDiagramService projectDiagramService, final RenameService renameService, final SaveAndRenameServiceImpl<ProjectDiagramResource, Metadata> saveAndRenameService); @PostConstruct void init(); @Override Path save(final Path path, final ProjectDiagramResource resource, final Metadata metadata, final String comment); @Override Path rename(final Path path, final String newName, final String comment); @Override Path saveAndRename(final Path path, final String newFileName, final Metadata metadata, final ProjectDiagramResource resource, final String comment); }### Answer: @Test public void testRename() { final Path path = mock(Path.class); final String newName = "newName"; final String comment = "comment"; service.rename(path, newName, comment); verify(renameService).rename(path, newName, comment); }
### Question: ProjectDiagramResourceServiceImpl implements ProjectDiagramResourceService { @Override public Path saveAndRename(final Path path, final String newFileName, final Metadata metadata, final ProjectDiagramResource resource, final String comment) { return saveAndRenameService.saveAndRename(path, newFileName, metadata, resource, comment); } ProjectDiagramResourceServiceImpl(); @Inject ProjectDiagramResourceServiceImpl(final ProjectDiagramService projectDiagramService, final RenameService renameService, final SaveAndRenameServiceImpl<ProjectDiagramResource, Metadata> saveAndRenameService); @PostConstruct void init(); @Override Path save(final Path path, final ProjectDiagramResource resource, final Metadata metadata, final String comment); @Override Path rename(final Path path, final String newName, final String comment); @Override Path saveAndRename(final Path path, final String newFileName, final Metadata metadata, final ProjectDiagramResource resource, final String comment); }### Answer: @Test public void testSaveAndRename() { final Path path = mock(Path.class); final Metadata metadata = mock(Metadata.class); final ProjectDiagramResourceImpl resource = mock(ProjectDiagramResourceImpl.class); final String newName = "newName"; final String comment = "comment"; service.saveAndRename(path, newName, metadata, resource, comment); verify(saveAndRenameService).saveAndRename(path, newName, metadata, resource, comment); }
### Question: ProjectDiagramServiceController extends AbstractVFSDiagramService<ProjectMetadata, ProjectDiagram> { public boolean delete(final Path _path, final String message) { final org.uberfire.java.nio.file.Path path = Paths.convert(_path); return getIoService().deleteIfExists(path, StandardDeleteOption.NON_EMPTY_DIRECTORIES); } ProjectDiagramServiceController(final DefinitionManager definitionManager, final FactoryManager factoryManager, final Instance<DefinitionSetService> definitionSetServiceInstances, final IOService ioService, final BackendRegistryFactory registryFactory, final KieModuleService moduleService, final KieServiceOverviewLoader overviewLoader, final User identity); @Override Path create(final Path path, final String name, final String defSetId); Path create(final Path path, final String name, final String defSetId, final String moduleName, final Package projectPkg, final Optional<String> projectType); @Override ProjectDiagram getDiagramByPath(Path file); Path save(final Path path, final ProjectDiagram diagram, final Map<String, ?> attributes, final OpenOption... comment); Path saveAsXml(final Path path, final String xml, final Map<String, ?> attributes, final OpenOption... comment); boolean delete(final Path _path, final String message); }### Answer: @Test public void testDelete() { Path path = mock(Path.class); when(path.toURI()).thenReturn(FILE_URI); when(metadata.getPath()).thenReturn(path); org.uberfire.java.nio.file.Path expectedNioPath = Paths.convert(path); diagramService.delete(diagram); verify(ioService, times(1)).deleteIfExists(eq(expectedNioPath), any(DeleteOption.class)); }
### Question: DelegateDiagramService implements DiagramService { @Override @SuppressWarnings("unchecked") public Diagram<Graph, Metadata> getDiagramByPath(final Path path) { return convert(projectDiagramService.getDiagramByPath(path)); } @Inject DelegateDiagramService(final ProjectDiagramService projectDiagramService); @Override @SuppressWarnings("unchecked") Diagram<Graph, Metadata> getDiagramByPath(final Path path); @Override boolean accepts(final Path path); @Override Path create(final Path path, final String name, final String defSetId); @Override Metadata saveOrUpdate(final Diagram<Graph, Metadata> diagram); @Override boolean delete(final Diagram<Graph, Metadata> diagram); @Override String getRawContent(final Diagram<Graph, Metadata> diagram); @Override Path saveOrUpdateSvg(final Path diagramPath, final String rawDiagramSvg); }### Answer: @Test public void getDiagramByPath() { Diagram<Graph, Metadata> diagram = delegateDiagramService.getDiagramByPath(path); verify(projectDiagramService).getDiagramByPath(path); assertEqualDiagram(diagram); }
### Question: DelegateDiagramService implements DiagramService { @Override public boolean accepts(final Path path) { return projectDiagramService.accepts(path); } @Inject DelegateDiagramService(final ProjectDiagramService projectDiagramService); @Override @SuppressWarnings("unchecked") Diagram<Graph, Metadata> getDiagramByPath(final Path path); @Override boolean accepts(final Path path); @Override Path create(final Path path, final String name, final String defSetId); @Override Metadata saveOrUpdate(final Diagram<Graph, Metadata> diagram); @Override boolean delete(final Diagram<Graph, Metadata> diagram); @Override String getRawContent(final Diagram<Graph, Metadata> diagram); @Override Path saveOrUpdateSvg(final Path diagramPath, final String rawDiagramSvg); }### Answer: @Test public void accepts() { boolean accepts = delegateDiagramService.accepts(path); verify(projectDiagramService).accepts(path); assertTrue(accepts); }
### Question: DelegateDiagramService implements DiagramService { @Override public Path create(final Path path, final String name, final String defSetId) { return projectDiagramService.create(path, name, defSetId); } @Inject DelegateDiagramService(final ProjectDiagramService projectDiagramService); @Override @SuppressWarnings("unchecked") Diagram<Graph, Metadata> getDiagramByPath(final Path path); @Override boolean accepts(final Path path); @Override Path create(final Path path, final String name, final String defSetId); @Override Metadata saveOrUpdate(final Diagram<Graph, Metadata> diagram); @Override boolean delete(final Diagram<Graph, Metadata> diagram); @Override String getRawContent(final Diagram<Graph, Metadata> diagram); @Override Path saveOrUpdateSvg(final Path diagramPath, final String rawDiagramSvg); }### Answer: @Test public void create() { Path createdPath = delegateDiagramService.create(this.path, NAME, DEF_ID); verify(projectDiagramService).create(this.path, NAME, DEF_ID); assertEquals(createdPath, path); }
### Question: DelegateDiagramService implements DiagramService { @Override public Metadata saveOrUpdate(final Diagram<Graph, Metadata> diagram) { return projectDiagramService.saveOrUpdate(convert(diagram)); } @Inject DelegateDiagramService(final ProjectDiagramService projectDiagramService); @Override @SuppressWarnings("unchecked") Diagram<Graph, Metadata> getDiagramByPath(final Path path); @Override boolean accepts(final Path path); @Override Path create(final Path path, final String name, final String defSetId); @Override Metadata saveOrUpdate(final Diagram<Graph, Metadata> diagram); @Override boolean delete(final Diagram<Graph, Metadata> diagram); @Override String getRawContent(final Diagram<Graph, Metadata> diagram); @Override Path saveOrUpdateSvg(final Path diagramPath, final String rawDiagramSvg); }### Answer: @Test public void saveOrUpdate() { Metadata metadata = delegateDiagramService.saveOrUpdate(diagram); verify(projectDiagramService).saveOrUpdate(projectDiagramArgumentCaptor.capture()); assertEqualDiagram(projectDiagramArgumentCaptor.getValue()); assertEquals(metadata, projectMetadata); }
### Question: DelegateDiagramService implements DiagramService { @Override public boolean delete(final Diagram<Graph, Metadata> diagram) { return projectDiagramService.delete(convert(diagram)); } @Inject DelegateDiagramService(final ProjectDiagramService projectDiagramService); @Override @SuppressWarnings("unchecked") Diagram<Graph, Metadata> getDiagramByPath(final Path path); @Override boolean accepts(final Path path); @Override Path create(final Path path, final String name, final String defSetId); @Override Metadata saveOrUpdate(final Diagram<Graph, Metadata> diagram); @Override boolean delete(final Diagram<Graph, Metadata> diagram); @Override String getRawContent(final Diagram<Graph, Metadata> diagram); @Override Path saveOrUpdateSvg(final Path diagramPath, final String rawDiagramSvg); }### Answer: @Test public void delete() { boolean deleted = delegateDiagramService.delete(diagram); verify(projectDiagramService).delete(projectDiagramArgumentCaptor.capture()); assertEqualDiagram(projectDiagramArgumentCaptor.getValue()); assertTrue(deleted); }
### Question: DelegateDiagramService implements DiagramService { @Override public String getRawContent(final Diagram<Graph, Metadata> diagram) { return projectDiagramService.getRawContent(convert(diagram)); } @Inject DelegateDiagramService(final ProjectDiagramService projectDiagramService); @Override @SuppressWarnings("unchecked") Diagram<Graph, Metadata> getDiagramByPath(final Path path); @Override boolean accepts(final Path path); @Override Path create(final Path path, final String name, final String defSetId); @Override Metadata saveOrUpdate(final Diagram<Graph, Metadata> diagram); @Override boolean delete(final Diagram<Graph, Metadata> diagram); @Override String getRawContent(final Diagram<Graph, Metadata> diagram); @Override Path saveOrUpdateSvg(final Path diagramPath, final String rawDiagramSvg); }### Answer: @Test public void getRawContent() { String rawContent = delegateDiagramService.getRawContent(diagram); verify(projectDiagramService).getRawContent(projectDiagramArgumentCaptor.capture()); assertEquals(rawContent, CONTENT); }
### Question: ProjectValidationServiceImpl implements ProjectValidationService { @Override public Collection<DiagramElementViolation<RuleViolation>> validate(Diagram diagram) { return domainViolations(diagram).stream() .filter(v -> Objects.nonNull(v.getUUID())) .filter(v -> !"null".equals(v.getUUID())) .map(v -> new ElementViolationImpl.Builder().setUuid(v.getUUID()).setDomainViolations(Collections.singletonList(v)).build()) .collect(Collectors.toList()); } protected ProjectValidationServiceImpl(); @Inject ProjectValidationServiceImpl(Instance<DomainValidator> validators); @Override Collection<DiagramElementViolation<RuleViolation>> validate(Diagram diagram); }### Answer: @Test public void validate() { final Collection<DiagramElementViolation<RuleViolation>> violations = validationService.validate(diagram); verify(diagram).getMetadata(); verify(metadata).getDefinitionSetId(); assertEquals(violations.size(), 4); final List<DiagramElementViolation<RuleViolation>> ordered = new ArrayList<>(violations); assertEquals(ordered.get(0).getUUID(), UUID_0); assertEquals(ordered.get(0).getDomainViolations().size(), 1); assertEquals(ordered.get(0).getDomainViolations().iterator().next(), domainViolation); assertEquals(ordered.get(1).getUUID(), UUID_1); assertEquals(ordered.get(1).getDomainViolations().size(), 1); assertEquals(ordered.get(1).getDomainViolations().iterator().next(), domainViolation2); assertEquals(ordered.get(2).getUUID(), UUID_1); assertEquals(ordered.get(2).getDomainViolations().size(), 1); assertEquals(ordered.get(2).getDomainViolations().iterator().next(), domainViolation3); assertEquals(ordered.get(3).getUUID(), UUID_1); assertEquals(ordered.get(3).getDomainViolations().size(), 1); assertEquals(ordered.get(3).getDomainViolations().iterator().next(), domainViolation4); }
### Question: ProjectClientDiagramValidator extends ClientDiagramValidator { @Override public void validate(Diagram diagram, Consumer<Collection<DiagramElementViolation<RuleViolation>>> resultConsumer) { super.validate(diagram, diagramElementViolations -> { final List<DiagramElementViolation<RuleViolation>> violations = (Objects.nonNull(diagramElementViolations) ? new LinkedList<>(diagramElementViolations) : new LinkedList<>()); backendValidation(diagram, backendViolations -> { violations.addAll(backendViolations); resultConsumer.accept(violations); }); }); } protected ProjectClientDiagramValidator(); @Inject ProjectClientDiagramValidator(final DefinitionManager definitionManager, final RuleManager ruleManager, final TreeWalkTraverseProcessor treeWalkTraverseProcessor, final ModelValidator modelValidator, final Caller<ProjectValidationService> validationService, final ManagedInstance<DomainValidator> validators); @Override void validate(Diagram diagram, Consumer<Collection<DiagramElementViolation<RuleViolation>>> resultConsumer); }### Answer: @Test public void validate() { when(diagram.getGraph()).thenReturn(graphTestHandler.graph); clientDiagramValidator.validate(diagram, result -> assertTrue(result.stream().anyMatch(v -> Objects.equals(backendViolation, v)))); verify(validationService).validate(diagram); }
### Question: ProjectMessagesListener { protected void clearMessages(AbstractNotification notification) { final UnpublishMessagesEvent unpublishMessagesEvent = new UnpublishMessagesEvent(); unpublishMessagesEvent.setMessageType(getMessageType(getDiagramPath())); unpublishMessagesEvent.setShowSystemConsole(false); this.unpublishMessagesEvent.fire(unpublishMessagesEvent); } protected ProjectMessagesListener(); @Inject ProjectMessagesListener(final NotificationsObserver notificationsObserver, final Event<PublishMessagesEvent> publishMessagesEvent, final Event<UnpublishMessagesEvent> unpublishMessagesEvent, final SessionManager clientSessionManager); void enable(); static final String MESSAGE_TYPE; }### Answer: @Test public void testClearMessages() { final ArgumentCaptor<UnpublishMessagesEvent> eventCaptor = ArgumentCaptor.forClass(UnpublishMessagesEvent.class); projectMessagesListener.clearMessages(mock(AbstractNotification.class)); verify(unpublishMessagesEvent).fire(eventCaptor.capture()); assertEquals(eventCaptor.getValue().getMessageType(), ProjectMessagesListener.MESSAGE_TYPE + PATH); assertEquals(eventCaptor.getValue().isShowSystemConsole(), false); }
### Question: StunnerDocksHandler extends AbstractWorkbenchDocksHandler { public void onDiagramLoseFocusEvent(final @Observes OnDiagramLoseFocusEvent event) { qualifiers = new Annotation[]{DefinitionManager.DEFAULT_QUALIFIER}; refreshDocks(true, true); } StunnerDocksHandler(); @Inject StunnerDocksHandler(final @Any ManagedInstance<StunnerDockSupplier> dockSuppliers); @Override Collection<UberfireDock> provideDocks(final String perspectiveIdentifier); void onDiagramFocusEvent(final @Observes OnDiagramFocusEvent event); void onDiagramLoseFocusEvent(final @Observes OnDiagramLoseFocusEvent event); void onDiagramEditorMaximized(final @Observes ScreenMaximizedEvent event); }### Answer: @Test public void testOnDiagramLoseFocusEvent() { handler.onDiagramLoseFocusEvent(new OnDiagramLoseFocusEvent()); }
### Question: StunnerDocksHandler extends AbstractWorkbenchDocksHandler { public void onDiagramEditorMaximized(final @Observes ScreenMaximizedEvent event) { if (event.isDiagramScreen()) { refreshDocks(true, false); } } StunnerDocksHandler(); @Inject StunnerDocksHandler(final @Any ManagedInstance<StunnerDockSupplier> dockSuppliers); @Override Collection<UberfireDock> provideDocks(final String perspectiveIdentifier); void onDiagramFocusEvent(final @Observes OnDiagramFocusEvent event); void onDiagramLoseFocusEvent(final @Observes OnDiagramLoseFocusEvent event); void onDiagramEditorMaximized(final @Observes ScreenMaximizedEvent event); }### Answer: @Test public void testOnDiagramEditorMaximized() { handler.onDiagramEditorMaximized(new ScreenMaximizedEvent(true)); assertTrue(handler.shouldRefreshDocks()); assertFalse(handler.shouldDisableDocks()); } @Test public void testOnOtherEditorMaximized() { handler.onDiagramEditorMaximized(new ScreenMaximizedEvent(false)); assertFalse(handler.shouldRefreshDocks()); assertFalse(handler.shouldDisableDocks()); }
### Question: ClientProjectDiagramService extends ClientDiagramServiceImpl<ProjectMetadata, ProjectDiagram, ProjectDiagramService> { public void saveAsXml(final Path path, final String xml, final Metadata metadata, final String comment, final ServiceCallback<String> callback) { diagramServiceCaller.call(v -> callback.onSuccess(xml), (message, throwable) -> { callback.onError(new ClientRuntimeError(throwable)); return false; }).saveAsXml(path, xml, metadata, comment); } protected ClientProjectDiagramService(); @Inject ClientProjectDiagramService(final ShapeManager shapeManager, final SessionManager sessionManager, final Caller<ProjectDiagramService> diagramServiceCaller, final Caller<DiagramLookupService> diagramLookupServiceCaller, final Event<SessionDiagramSavedEvent> saveEvent); void create(final Path path, final String name, final String defSetId, final String projectName, final Package projectPkg, final Optional<String> projectType, final ServiceCallback<Path> callback); void saveOrUpdate(final Path path, final ProjectDiagram diagram, final Metadata metadata, final String comment, final ServiceCallback<ProjectDiagram> callback); void saveAsXml(final Path path, final String xml, final Metadata metadata, final String comment, final ServiceCallback<String> callback); }### Answer: @Test @SuppressWarnings("unchecked") public void testSaveAsXml() { final String xml = "xml"; final String comment = "comment"; final Metadata metadata = mock(Metadata.class); final ServiceCallback<String> callback = mock(ServiceCallback.class); tested.saveAsXml(path, xml, metadata, comment, callback); verify(diagramService, times(1)).saveAsXml(eq(path), eq(xml), eq(metadata), eq(comment)); verify(callback, times(1)).onSuccess(anyString()); verify(callback, times(0)).onError(any(ClientRuntimeError.class)); }
### Question: GridCellTuple implements RequiresResize { @Override public void onResize() { final GridColumn<?> parentColumn = gridWidget.getModel().getColumns().get(columnIndex); parentColumn.setWidth(parentColumn.getWidth()); } GridCellTuple(final int rowIndex, final int columnIndex, final GridWidget gridWidget); int getRowIndex(); void setRowIndex(final int rowIndex); int getColumnIndex(); void setColumnIndex(final int columnIndex); GridWidget getGridWidget(); void proposeContainingColumnWidth(final double proposedWidth, final Function<BaseExpressionGrid, Double> requiredWidthSupplier); @Override void onResize(); }### Answer: @Test public void testOnResizeSetsColumnWidth() { when(gridColumn.getWidth()).thenReturn(100.0); tuple.onResize(); verify(gridColumn).setWidth(100.0); }
### Question: BaseHasDynamicHeightCell extends DMNGridCell<T> implements HasDynamicHeight { @Override public boolean equals(final Object o) { if (this == o) { return true; } if (!(o instanceof BaseHasDynamicHeightCell)) { return false; } if (!super.equals(o)) { return false; } final BaseHasDynamicHeightCell<?> that = (BaseHasDynamicHeightCell<?>) o; return Double.compare(that.lineHeight, lineHeight) == 0 && Double.compare(that.height, height) == 0; } BaseHasDynamicHeightCell(final GridCellValue<T> value, final double lineHeight); @Override double getHeight(); @Override boolean equals(final Object o); @Override int hashCode(); static final double DEFAULT_HEIGHT; }### Answer: @Test public void testEquals() { final CELL sameCell = makeCell(); assertThat(cell).isEqualTo(sameCell); assertThat(cell.hashCode()).isEqualTo(sameCell.hashCode()); }
### Question: ProjectDiagramEditorView extends KieEditorViewImpl implements AbstractProjectDiagramEditor.View { @Override public void setWidget(final IsWidget widget) { editorPanel.clear(); editorPanel.add(widget); } protected ProjectDiagramEditorView(); @Inject ProjectDiagramEditorView(final ResizeFlowPanel editorPanel); @Override void init(final DiagramEditorCore presenter); @Override void onResize(); @Override void setWidget(final IsWidget widget); @PreDestroy void destroy(); }### Answer: @Test public void testSetWidget() { final IsWidget editor = mock(IsWidget.class); tested.setWidget(editor); verify(editorPanel).clear(); verify(editorPanel).add(eq(editor)); }
### Question: ProjectDiagramEditorView extends KieEditorViewImpl implements AbstractProjectDiagramEditor.View { @Override public void onResize() { editorPanel.onResize(); } protected ProjectDiagramEditorView(); @Inject ProjectDiagramEditorView(final ResizeFlowPanel editorPanel); @Override void init(final DiagramEditorCore presenter); @Override void onResize(); @Override void setWidget(final IsWidget widget); @PreDestroy void destroy(); }### Answer: @Test public void testOnResize() { tested.onResize(); verify(editorPanel).onResize(); }
### Question: ProjectDiagramEditorView extends KieEditorViewImpl implements AbstractProjectDiagramEditor.View { @Override protected void onAttach() { super.onAttach(); if (getElement().getParentElement() != null) { getElement().getParentElement().getStyle().setHeight(100, Style.Unit.PCT); getElement().getParentElement().getStyle().setWidth(100, Style.Unit.PCT); getElement().getParentElement().getStyle().setDisplay(Style.Display.TABLE); } } protected ProjectDiagramEditorView(); @Inject ProjectDiagramEditorView(final ResizeFlowPanel editorPanel); @Override void init(final DiagramEditorCore presenter); @Override void onResize(); @Override void setWidget(final IsWidget widget); @PreDestroy void destroy(); }### Answer: @Test public void testOnAttach() { testOnAttach(true); testOnAttach(false); }
### Question: StunnerProjectPreferencesRegistryLoader extends StunnerPreferencesRegistryLoader { @Override public void load(final Metadata metadata, final ParameterizedCommand<StunnerPreferences> loadCompleteCallback, final ParameterizedCommand<Throwable> errorCallback) { super.load(metadata, preferences -> profilePreferencesLoader.load(metadata, profile -> { metadata.setProfileId(profile.getProfileId()); loadCompleteCallback.execute(preferences); }, errorCallback), errorCallback); } @Inject StunnerProjectPreferencesRegistryLoader(final DefinitionUtils definitionUtils, final @Any ManagedInstance<StunnerPreferencesRegistryHolder> preferencesHolders, final StunnerPreferences preferences, final StunnerTextPreferences textPreferences, final StunnerProfilePreferencesLoader profilePreferencesLoader); @Override void load(final Metadata metadata, final ParameterizedCommand<StunnerPreferences> loadCompleteCallback, final ParameterizedCommand<Throwable> errorCallback); }### Answer: @Test @SuppressWarnings("unchecked") public void testLoad() { final ParameterizedCommand<StunnerPreferences> loadCompleteCallback = mock(ParameterizedCommand.class); final ParameterizedCommand<Throwable> errorCallback = mock(ParameterizedCommand.class); final StunnerPreferences pre = mock(StunnerPreferences.class); doAnswer(invocation -> { ((ParameterizedCommand<StunnerPreferences>) invocation.getArguments()[0]).execute(pre); return null; }).when(preferences).load(any(ParameterizedCommand.class), any(ParameterizedCommand.class)); tested.load(metadata, loadCompleteCallback, errorCallback); assertEquals(PROFILE_ID, metadata.getProfileId()); verify(preferencesHolders, times(1)).select(eq(qualifier)); verify(loadCompleteCallback, times(1)).execute(eq(pre)); verify(errorCallback, never()).execute(any(Throwable.class)); verify(preferencesHolder, times(1)).set(eq(pre), eq(StunnerPreferences.class)); verify(preferencesHolder, times(1)).set(eq(textPreferences), eq(StunnerTextPreferences.class)); }
### Question: AbstractDragProxy { MouseMoveHandler getMouseMoveHandler(final int initialX, final int initialY, final int timeout, final Callback callback) { return mouseMoveEvent -> { if (isAttached()) { if (xDiff() == null) { xDiff = initialX - mouseMoveEvent.getX(); } if (yDiff() == null) { yDiff = initialY - mouseMoveEvent.getY(); } final int x = relativeX(getXDiff() + mouseMoveEvent.getX()); final int y = relativeY(getYDiff() + mouseMoveEvent.getY()); setLocation(shapeProxy, x, y); scheduleMove(callback, x, y, timeout); } }; } AbstractDragProxy(final Layer layer, final T shape, final int x, final int y, final int timeout, final Callback callback); void clear(); void destroy(); }### Answer: @Test public void testGetMouseMoveHandler() { final int initialX = 100; final int initialY = 100; final int expectedX = 175; final int expectedY = 175; final MouseMoveHandler handler = abstractDragProxy.getMouseMoveHandler(initialX, initialY, timeout, callback); when(mouseMoveEvent.getX()).thenReturn(150); when(mouseMoveEvent.getY()).thenReturn(150); doReturn(0).when(abstractDragProxy).xDiff(); doReturn(0).when(abstractDragProxy).yDiff(); doReturn(25).when(abstractDragProxy).getXDiff(); doReturn(25).when(abstractDragProxy).getYDiff(); doReturn(true).when(abstractDragProxy).isAttached(); handler.onMouseMove(mouseMoveEvent); verify(abstractDragProxy).setLocation(shapeProxy, expectedX, expectedY); verify(abstractDragProxy).scheduleMove(callback, expectedX, expectedY, timeout); verify(layer, never()).batch(); }
### Question: BaseHasDynamicHeightCell extends DMNGridCell<T> implements HasDynamicHeight { @Override public int hashCode() { return Objects.hash(super.hashCode(), lineHeight, height); } BaseHasDynamicHeightCell(final GridCellValue<T> value, final double lineHeight); @Override double getHeight(); @Override boolean equals(final Object o); @Override int hashCode(); static final double DEFAULT_HEIGHT; }### Answer: @Test public void testEqualsIdentity() { assertThat(cell).isEqualTo(cell); assertThat(cell.hashCode()).isEqualTo(cell.hashCode()); } @Test public void testEqualsDifferentLineHeight() { final CELL differentCell = makeCell(LINE_HEIGHT + 1); assertThat(cell).isNotEqualTo(differentCell); assertThat(cell.hashCode()).isNotEqualTo(differentCell.hashCode()); }
### Question: AbstractDragProxy { MouseUpHandler getMouseUpHandler(final Callback callback) { return mouseUpEvent -> { if (isAttached()) { timer.cancel(); final int x = relativeX(getXDiff() + mouseUpEvent.getX()); final int y = relativeY(getYDiff() + mouseUpEvent.getY()); clear(); callback.onComplete(x, y); } }; } AbstractDragProxy(final Layer layer, final T shape, final int x, final int y, final int timeout, final Callback callback); void clear(); void destroy(); }### Answer: @Test public void testGetMouseUpHandler() { final MouseUpHandler handler = abstractDragProxy.getMouseUpHandler(callback); final int expectedX = 175; final int expectedY = 175; when(mouseUpEvent.getX()).thenReturn(150); when(mouseUpEvent.getY()).thenReturn(150); doReturn(25).when(abstractDragProxy).getXDiff(); doReturn(25).when(abstractDragProxy).getYDiff(); doNothing().when(abstractDragProxy).clear(); doReturn(true).when(abstractDragProxy).isAttached(); handler.onMouseUp(mouseUpEvent); verify(abstractDragProxy).clear(); verify(callback).onComplete(expectedX, expectedY); }
### Question: AbstractDragProxy { int relativeX(final int x) { final Double relativeX = ((x) - getViewportTransform().getTranslateX()) / getViewportTransform().getScaleX(); return relativeX.intValue(); } AbstractDragProxy(final Layer layer, final T shape, final int x, final int y, final int timeout, final Callback callback); void clear(); void destroy(); }### Answer: @Test public void testRelativeX() { final double transformTranslateX = 50d; final double transformScaleX = 1.5d; final int x = 100; final int expectedRelativeX = 33; when(transform.getTranslateX()).thenReturn(transformTranslateX); when(transform.getScaleX()).thenReturn(transformScaleX); final int actualRelativeX = abstractDragProxy.relativeX(x); assertEquals(expectedRelativeX, actualRelativeX); }
### Question: AbstractDragProxy { int relativeY(final int y) { final Double relativeY = ((y) - getViewportTransform().getTranslateY()) / getViewportTransform().getScaleY(); return relativeY.intValue(); } AbstractDragProxy(final Layer layer, final T shape, final int x, final int y, final int timeout, final Callback callback); void clear(); void destroy(); }### Answer: @Test public void testRelativeY() { final double transformTranslateY = 50d; final double transformScaleY = 1.5d; final int y = 100; final int expectedRelativeY = 33; when(transform.getTranslateY()).thenReturn(transformTranslateY); when(transform.getScaleY()).thenReturn(transformScaleY); final int actualRelativeY = abstractDragProxy.relativeY(y); assertEquals(expectedRelativeY, actualRelativeY); }
### Question: Grid implements Iterable<Grid.Point> { public Point findPosition(final Point anchorPoint, final Direction direction) { int width = getWidth(); int height = getHeight(); int x = anchorPoint.getX(); int y = anchorPoint.getY(); switch (direction) { case NORTH: x -= width / 2; y -= height; break; case SOUTH: x -= width / 2; break; case EAST: y -= height / 2; break; case WEST: x -= width; y -= height / 2; break; case NONE: x -= width / 2; y -= height / 2; break; case NORTH_EAST: y -= height; break; case SOUTH_EAST: break; case SOUTH_WEST: x -= width; break; case NORTH_WEST: x -= width; y -= height; break; default: throw new UnsupportedOperationException(); } return new Point(x, y); } Grid(final int padding, final int iconSize, final int rows, final int cols); Point findPosition(final Point anchorPoint, final Direction direction); Point findPosition(final int row, final int col); @Override Iterator<Point> iterator(); int getRows(); int getCols(); int size(); int getWidth(); int getHeight(); }### Answer: @Test public void testFindSimplePosition() { Point p = grid.findPosition(4, 5); assertEquals(160, p.getX()); assertEquals(130, p.getY()); } @Test(expected = IllegalArgumentException.class) public void testFindSimplePositionRowIsTooBig() { grid.findPosition(10000, 5); } @Test(expected = IllegalArgumentException.class) public void testFindSimplePositionColIsTooBig() { grid.findPosition(5, 10000); } @Test(expected = IllegalArgumentException.class) public void testFindSimplePositionNegativeRow() { grid.findPosition(-1, 5); } @Test(expected = IllegalArgumentException.class) public void testFindSimplePositionNegativeCol() { grid.findPosition(5, -1); }
### Question: Grid implements Iterable<Grid.Point> { public int getWidth() { return calculateDistance(getCols()); } Grid(final int padding, final int iconSize, final int rows, final int cols); Point findPosition(final Point anchorPoint, final Direction direction); Point findPosition(final int row, final int col); @Override Iterator<Point> iterator(); int getRows(); int getCols(); int size(); int getWidth(); int getHeight(); }### Answer: @Test public void testGetWidth() { assertEquals(1210, grid.getWidth()); }
### Question: Grid implements Iterable<Grid.Point> { public int getHeight() { return calculateDistance(getRows()); } Grid(final int padding, final int iconSize, final int rows, final int cols); Point findPosition(final Point anchorPoint, final Direction direction); Point findPosition(final int row, final int col); @Override Iterator<Point> iterator(); int getRows(); int getCols(); int size(); int getWidth(); int getHeight(); }### Answer: @Test public void testGetHeight() { assertEquals(910, grid.getHeight()); }
### Question: Grid implements Iterable<Grid.Point> { public int size() { return getRows() * getCols(); } Grid(final int padding, final int iconSize, final int rows, final int cols); Point findPosition(final Point anchorPoint, final Direction direction); Point findPosition(final int row, final int col); @Override Iterator<Point> iterator(); int getRows(); int getCols(); int size(); int getWidth(); int getHeight(); }### Answer: @Test public void testSize() { assertEquals(1200, grid.size()); }
### Question: Grid implements Iterable<Grid.Point> { @Override public Iterator<Point> iterator() { return new GridIterator(this); } Grid(final int padding, final int iconSize, final int rows, final int cols); Point findPosition(final Point anchorPoint, final Direction direction); Point findPosition(final int row, final int col); @Override Iterator<Point> iterator(); int getRows(); int getCols(); int size(); int getWidth(); int getHeight(); }### Answer: @Test public void testIterator() { Iterator iterator = grid.iterator(); int cellCount = 0; while (iterator.hasNext()) { iterator.next(); cellCount++; } assertEquals(grid.size(), cellCount); } @Test(expected = NoSuchElementException.class) public void testIteratorOverflow() { Iterator iterator = grid.iterator(); while (iterator.hasNext()) { iterator.next(); } iterator.next(); } @Test(expected = UnsupportedOperationException.class) public void testIteratorRemoveNotSupported() { grid.iterator().remove(); }
### Question: Decorator extends Group { public IPrimitive<?> build(final IPrimitive<?> item, final double width, final double height) { decorator = createRectangle(width, height); this.add(decorator); this.add(item); decorator.setX(item.getX() - (padding / 4)); decorator.setY(item.getY() - (padding / 4)); decorator.addNodeMouseEnterHandler(nodeMouseEnterEvent -> show(nodeMouseEnterEvent.getMouseEvent().getClientX(), nodeMouseEnterEvent.getMouseEvent().getClientY())); decorator.addNodeMouseExitHandler(nodeMouseExitEvent -> hide()); decorator.addNodeMouseMoveHandler(nodeMouseMoveEvent -> timer.cancel()); item.setDraggable(false); decorator.setDraggable(false).moveToTop(); return this; } Decorator(final ItemCallback callback); Decorator setPadding(final double padding); Decorator setItemCallback(final ItemCallback callback); IPrimitive<?> build(final IPrimitive<?> item, final double width, final double height); Rectangle createRectangle(final double width, final double height); Decorator show(final double x, final double y); Decorator hide(); }### Answer: @Test public void testBuild() { decorator.build(primitive, 5.0, 8.0); verify(decorator).createRectangle(5.0, 8.0); verify(decorator).add(primitive); verify(decorator).add(rectangle); verify(rectangle).addNodeMouseEnterHandler(anyObject()); verify(rectangle).addNodeMouseExitHandler(anyObject()); verify(rectangle).addNodeMouseMoveHandler(anyObject()); verify(rectangle).setDraggable(false); verify(rectangle).moveToTop(); }
### Question: Decorator extends Group { protected void fireHide() { if (null != callback) { callback.onHide(); } } Decorator(final ItemCallback callback); Decorator setPadding(final double padding); Decorator setItemCallback(final ItemCallback callback); IPrimitive<?> build(final IPrimitive<?> item, final double width, final double height); Rectangle createRectangle(final double width, final double height); Decorator show(final double x, final double y); Decorator hide(); }### Answer: @Test public void testFireHide() { decorator.fireHide(); verify(callback).onHide(); }
### Question: Decorator extends Group { protected void fireShow(final double x, final double y) { if (null != callback) { callback.onShow(x, y); } } Decorator(final ItemCallback callback); Decorator setPadding(final double padding); Decorator setItemCallback(final ItemCallback callback); IPrimitive<?> build(final IPrimitive<?> item, final double width, final double height); Rectangle createRectangle(final double width, final double height); Decorator show(final double x, final double y); Decorator hide(); }### Answer: @Test public void testFireShow() { decorator.fireShow(3.0, 5.0); verify(callback).onShow(3.0, 5.0); }
### Question: Decorator extends Group { public Decorator hide() { if (!timer.isRunning()) { decorator.animate(AnimationTweener.LINEAR, AnimationProperties.toPropertyList(AnimationProperty.Properties.STROKE_ALPHA(0)), ANIMATION_DURATION, createHideAnimationCallback()); } return this; } Decorator(final ItemCallback callback); Decorator setPadding(final double padding); Decorator setItemCallback(final ItemCallback callback); IPrimitive<?> build(final IPrimitive<?> item, final double width, final double height); Rectangle createRectangle(final double width, final double height); Decorator show(final double x, final double y); Decorator hide(); }### Answer: @Test public void testHide() { decorator.build(primitive, 6.0, 0.6); doReturn(animationHandle).when((Node) rectangle).animate(anyObject(), anyObject(), anyDouble(), anyObject()); decorator.resetTimer(timer); when(timer.isRunning()).thenReturn(true); decorator.hide(); verify(rectangle, never()).animate(anyObject(), anyObject(), anyDouble(), anyObject()); when(timer.isRunning()).thenReturn(false); decorator.hide(); verify(decorator).createHideAnimationCallback(); verify(rectangle).animate(anyObject(), anyObject(), anyDouble(), anyObject()); }
### Question: Decorator extends Group { protected AnimationCallback createHideAnimationCallback() { return new AnimationCallback() { @Override public void onClose(IAnimation animation, IAnimationHandle handle) { super.onClose(animation, handle); fireHide(); } }; } Decorator(final ItemCallback callback); Decorator setPadding(final double padding); Decorator setItemCallback(final ItemCallback callback); IPrimitive<?> build(final IPrimitive<?> item, final double width, final double height); Rectangle createRectangle(final double width, final double height); Decorator show(final double x, final double y); Decorator hide(); }### Answer: @Test public void testCreateHideAnimationCallback() { decorator.createHideAnimationCallback().onClose(animation, animationHandle); verify(decorator).fireHide(); }
### Question: Decorator extends Group { public Decorator show(final double x, final double y) { if (!timer.isRunning()) { decorator.animate(AnimationTweener.LINEAR, AnimationProperties.toPropertyList(AnimationProperty.Properties.STROKE_ALPHA(1)), ANIMATION_DURATION, createShowAnimationCallback(x, y)); timer.schedule(TIMER_DELAY); } return this; } Decorator(final ItemCallback callback); Decorator setPadding(final double padding); Decorator setItemCallback(final ItemCallback callback); IPrimitive<?> build(final IPrimitive<?> item, final double width, final double height); Rectangle createRectangle(final double width, final double height); Decorator show(final double x, final double y); Decorator hide(); }### Answer: @Test public void testShow() { decorator.build(primitive, 6.0, 0.6); doReturn(animationHandle).when((Node) rectangle).animate(anyObject(), anyObject(), anyDouble(), anyObject()); decorator.resetTimer(timer); when(timer.isRunning()).thenReturn(true); decorator.show(4, 5); verify(rectangle, never()).animate(anyObject(), anyObject(), anyDouble(), anyObject()); when(timer.isRunning()).thenReturn(false); decorator.show(0.1, 0); verify(decorator).createShowAnimationCallback(0.1, 0); verify(rectangle).animate(anyObject(), anyObject(), anyDouble(), anyObject()); verify(timer).schedule(anyInt()); }
### Question: LiteralExpressionGridRow extends BaseGridRow { @Override public double getHeight() { double height = DEFAULT_HEIGHT; for (GridCell<?> cell : this.getCells().values()) { if (cell instanceof HasDynamicHeight) { height = Math.max(((HasDynamicHeight) cell).getHeight(), height); } } return height; } LiteralExpressionGridRow(); @Override double getHeight(); }### Answer: @Test public void testEmptyRow() { final GridRow row = new LiteralExpressionGridRow(); assertThat(row.getHeight()).isEqualTo(DEFAULT_HEIGHT); } @Test public void testGetHeightWithHasDynamicHeightCell() { final GridRow row = spy(new LiteralExpressionGridRow()); final Map<Integer, GridCell> cells = new HashMap<Integer, GridCell>() {{ put(0, new MockHasDynamicHeightCell<>(new BaseGridCellValue<>("cheese"))); put(1, new BaseGridCell<>(new BaseGridCellValue<>("cheese"))); }}; doReturn(cells).when(row).getCells(); assertThat(row.getHeight()).isEqualTo(CELL_HEIGHT); } @Test public void testGetHeightWithoutHasDynamicHeightCell() { final GridRow row = spy(new LiteralExpressionGridRow()); final Map<Integer, GridCell> cells = new HashMap<Integer, GridCell>() {{ put(0, new BaseGridCell<>(new BaseGridCellValue<>("cheese"))); }}; doReturn(cells).when(row).getCells(); assertThat(row.getHeight()).isEqualTo(DEFAULT_HEIGHT); }
### Question: Decorator extends Group { protected AnimationCallback createShowAnimationCallback(final double x, final double y) { return new AnimationCallback() { @Override public void onClose(final IAnimation animation, final IAnimationHandle handle) { super.onClose(animation, handle); fireShow(x, y); } }; } Decorator(final ItemCallback callback); Decorator setPadding(final double padding); Decorator setItemCallback(final ItemCallback callback); IPrimitive<?> build(final IPrimitive<?> item, final double width, final double height); Rectangle createRectangle(final double width, final double height); Decorator show(final double x, final double y); Decorator hide(); }### Answer: @Test public void testCreateShowAnimationCallback() { decorator.createShowAnimationCallback(0.9, 1.1).onClose(animation, animationHandle); verify(decorator).fireShow(0.9, 1.1); }
### Question: FormGenerationServiceImpl implements FormGenerationService { @Override public void generateProcessForm(final Diagram diagram) { doGenerate(diagram, () -> formDefinitionGenerator.generateProcessForm(diagram)); } protected FormGenerationServiceImpl(); @Inject FormGenerationServiceImpl(final Event<FormGeneratedEvent> formGeneratedEvent, final Event<FormGenerationFailureEvent> formGenerationFailureEvent, final FormDefinitionGenerator formDefinitionGenerator); @Override void generateProcessForm(final Diagram diagram); @Override void generateAllForms(final Diagram diagram); @Override void generateSelectedForms(final Diagram diagram, final String[] ids); }### Answer: @Test public void testGenerateProcessForm() { testGenerateProcessForm(false); }
### Question: FormGenerationServiceImpl implements FormGenerationService { @Override public void generateSelectedForms(final Diagram diagram, final String[] ids) { this.doGenerate(diagram, () -> formDefinitionGenerator.generateSelectedForms(diagram, ids)); } protected FormGenerationServiceImpl(); @Inject FormGenerationServiceImpl(final Event<FormGeneratedEvent> formGeneratedEvent, final Event<FormGenerationFailureEvent> formGenerationFailureEvent, final FormDefinitionGenerator formDefinitionGenerator); @Override void generateProcessForm(final Diagram diagram); @Override void generateAllForms(final Diagram diagram); @Override void generateSelectedForms(final Diagram diagram, final String[] ids); }### Answer: @Test public void testGenerateSelectedForms() { testGenerateSelectedForms(false); }
### Question: FormGenerationServiceImpl implements FormGenerationService { @Override public void generateAllForms(final Diagram diagram) { doGenerate(diagram, () -> formDefinitionGenerator.generateAllForms(diagram)); } protected FormGenerationServiceImpl(); @Inject FormGenerationServiceImpl(final Event<FormGeneratedEvent> formGeneratedEvent, final Event<FormGenerationFailureEvent> formGenerationFailureEvent, final FormDefinitionGenerator formDefinitionGenerator); @Override void generateProcessForm(final Diagram diagram); @Override void generateAllForms(final Diagram diagram); @Override void generateSelectedForms(final Diagram diagram, final String[] ids); }### Answer: @Test public void testGenerateAllForms() { testGenerateAllForms(false); }
### Question: FormDefinitionGeneratorImpl implements FormDefinitionGenerator { @Override public void generateProcessForm(Diagram diagram) { try { LOGGER.finest("Generating form for process "); final Definitions definitions = toDefinitions(diagram); final Path path = diagram.getMetadata().getPath(); final BusinessProcessFormModel formModel = bpmnFormModelGenerator.generateProcessFormModel(definitions, path); createFormForModel(formModel, Paths.convert(path)); } catch (Exception ex) { LOGGER.severe("Error generating process form"); throw new RuntimeException(ex); } } @Inject FormDefinitionGeneratorImpl(FormGenerationModelProviders providers, @Named("ioStrategy") final IOService ioService, final BPMNFormModelGenerator bpmnFormModelGenerator, final FormDefinitionSerializer serializer, @Authoring final BPMNFormGeneratorService<Path> bpmnFormGeneratorService); @Override void generateProcessForm(Diagram diagram); @Override void generateSelectedForms(Diagram diagram, String... taskIds); @Override void generateAllForms(Diagram diagram); void createFormForModel(JBPMFormModel formModel, org.uberfire.java.nio.file.Path path); }### Answer: @Test public void testGenerateProcessForm() { generator.generateProcessForm(diagram); verify(generator, times(1)).createFormForModel(formModelArgumentCaptor.capture(), any()); verify(formDefinitionSerializer, times(1)).serialize(formDefinitionArgumentCaptor.capture()); verify(ioService, times(1)).createFile(any()); verify(ioService, times(1)).write(any(), anyString()); JBPMFormModel formModel = formModelArgumentCaptor.getValue(); Assertions.assertThat(formModel) .isNotNull() .isInstanceOf(BusinessProcessFormModel.class); checkProcessFormGenerated((BusinessProcessFormModel) formModel, formDefinitionArgumentCaptor.getValue()); }
### Question: FormGenerationModelProviders { public FormGenerationModelProvider<?> getModelProvider(final Diagram diagram) { for (FormGenerationModelProvider provider : providers) { if (provider.accepts(diagram)) { return provider; } } return null; } protected FormGenerationModelProviders(); @Inject FormGenerationModelProviders(final @Any Instance<FormGenerationModelProvider<?>> providers); FormGenerationModelProviders(final Iterable<FormGenerationModelProvider<?>> providers); FormGenerationModelProvider<?> getModelProvider(final Diagram diagram); }### Answer: @Test public void testGetModelProviders() { assertEquals(provider1, tested.getModelProvider(diagram1)); assertEquals(provider2, tested.getModelProvider(diagram2)); }
### Question: FormGenerationNotifier { public void showNotification(final String message) { messageNotifier.accept(message); } protected FormGenerationNotifier(); @Inject FormGenerationNotifier(ClientTranslationService translationService); FormGenerationNotifier(ClientTranslationService translationService, Consumer<String> messageNotifier, Consumer<String> errorNotifier); void showNotification(final String message); void showError(final String message); }### Answer: @Test public void testShowNotification() { notifier.showNotification(MESSAGE); verify(messageNotification, times(1)).accept(MESSAGE); verify(errorNotification, times(0)).accept(MESSAGE); }
### Question: FormGenerationNotifier { public void showError(final String message) { errorNotifier.accept(message); } protected FormGenerationNotifier(); @Inject FormGenerationNotifier(ClientTranslationService translationService); FormGenerationNotifier(ClientTranslationService translationService, Consumer<String> messageNotifier, Consumer<String> errorNotifier); void showNotification(final String message); void showError(final String message); }### Answer: @Test public void testshowError() { notifier.showError(ERROR); verify(errorNotification, times(1)).accept(ERROR); verify(messageNotification, times(0)).accept(ERROR); }
### Question: FormGenerationToolboxAction implements ToolboxAction<AbstractCanvasHandler> { @Override public String getTitle(final AbstractCanvasHandler canvasHandler, final String uuid) { return translationService.getValue(FormsClientConstants.FormsGenerateTaskForm); } @Inject FormGenerationToolboxAction(final ClientTranslationService translationService, final ClientFormGenerationManager formGenerationManager); @Override Glyph getGlyph(final AbstractCanvasHandler canvasHandler, final String uuid); @Override String getTitle(final AbstractCanvasHandler canvasHandler, final String uuid); @Override @SuppressWarnings("unchecked") ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event); }### Answer: @Test public void testGetTitle() { assertEquals("generateTitle", tested.getTitle(canvasHandler, "uuid")); }
### Question: FormGenerationToolboxAction implements ToolboxAction<AbstractCanvasHandler> { @Override @SuppressWarnings("unchecked") public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) { formGenerationManager.call(service -> service.generateSelectedForms(canvasHandler.getDiagram(), new String[]{uuid})); return this; } @Inject FormGenerationToolboxAction(final ClientTranslationService translationService, final ClientFormGenerationManager formGenerationManager); @Override Glyph getGlyph(final AbstractCanvasHandler canvasHandler, final String uuid); @Override String getTitle(final AbstractCanvasHandler canvasHandler, final String uuid); @Override @SuppressWarnings("unchecked") ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event); }### Answer: @Test @SuppressWarnings("unchecked") public void testOnClick() { final MouseClickEvent event = mock(MouseClickEvent.class); tested.onMouseClick(canvasHandler, "uuid", event); verify(formGenerationManager, times(1)).call(any(Consumer.class)); verify(formGenerationService, times(1)).generateSelectedForms(eq(diagram), eq(new String[]{"uuid"})); }
### Question: FormsCanvasSessionHandler { @SuppressWarnings("unchecked") public boolean executeUpdateDomainObjectProperty(final DomainObject domainObject, final String fieldName, final Object value) { return execute(commandFactory.updateDomainObjectPropertyValue(domainObject, fieldName, value), domainObjectCanvasListener); } @Inject FormsCanvasSessionHandler(final DefinitionManager definitionManager, final CanvasCommandFactory<AbstractCanvasHandler> commandFactory, final SessionCommandManager<AbstractCanvasHandler> sessionCommandManager); FormsCanvasSessionHandler setRenderer(FormRenderer renderer); FormsCanvasSessionHandler bind(final ClientSession session); FormsCanvasSessionHandler unbind(); @PreDestroy void destroy(); void show(); @SuppressWarnings("unchecked") void show(final Command callback); @SuppressWarnings("unchecked") boolean executeUpdateProperty(final Element<? extends Definition<?>> element, final String fieldName, final Object value); @SuppressWarnings("unchecked") boolean executeUpdateDomainObjectProperty(final DomainObject domainObject, final String fieldName, final Object value); ClientSession getSession(); AbstractCanvasHandler getCanvasHandler(); Diagram<?, ?> getDiagram(); RenderMode getSessionRenderMode(); }### Answer: @Test @SuppressWarnings("unchecked") public void testExecuteUpdateDomainObjectProperty() { handler.bind(session); handler.executeUpdateDomainObjectProperty(domainObject, FIELD_NAME, FIELD_VALUE); final InOrder inOrder = inOrder(domainObjectCanvasListener, commandFactory, sessionCommandManager, domainObjectCanvasListener); inOrder.verify(commandFactory).updateDomainObjectPropertyValue(domainObject, FIELD_NAME, FIELD_VALUE); inOrder.verify(domainObjectCanvasListener).startProcessing(); inOrder.verify(sessionCommandManager).execute(abstractCanvasHandler, updateDomainObjectPropertyCommand); inOrder.verify(domainObjectCanvasListener).endProcessing(); }
### Question: FormPropertiesWidget implements IsElement, FormPropertiesWidgetView.Presenter { protected void fireFormsPropertiesOpenedEvent(String uuid, String name) { propertiesOpenedEvent.fire(new FormPropertiesOpened(formSessionHandler.getSession(), uuid, name)); } @Inject FormPropertiesWidget(final FormPropertiesWidgetView view, final DefinitionUtils definitionUtils, final FormsCanvasSessionHandler formSessionHandler, final Event<FormPropertiesOpened> propertiesOpenedEvent, final FormsContainer formsContainer, final FormsFlushManager formsFlushManager, final TranslationService translationService); @PostConstruct @SuppressWarnings("unchecked") void init(); @Override HTMLElement getElement(); @Override HTMLElement getDisplayerElement(); FormsCanvasSessionHandler getFormSessionHandler(); @SuppressWarnings("unchecked") FormPropertiesWidget bind(final ClientSession session); @SuppressWarnings("unchecked") FormPropertiesWidget unbind(); @PreDestroy void destroy(); void show(); @SuppressWarnings("unchecked") void show(final Command callback); void resetLastElementRenderedCache(); boolean areLastPositionsForSameElementSame(final Element element); }### Answer: @Test public void testFireFormsPropertiesOpenedEvent() { tested.fireFormsPropertiesOpenedEvent("", ""); verify(propertiesOpenedEvent, times(1)).fire(formPropertiesOpenedArgumentCaptor.capture()); }
### Question: FormPropertiesWidget implements IsElement, FormPropertiesWidgetView.Presenter { protected static boolean isNode(final Element<? extends Definition<?>> element) { return element instanceof Node; } @Inject FormPropertiesWidget(final FormPropertiesWidgetView view, final DefinitionUtils definitionUtils, final FormsCanvasSessionHandler formSessionHandler, final Event<FormPropertiesOpened> propertiesOpenedEvent, final FormsContainer formsContainer, final FormsFlushManager formsFlushManager, final TranslationService translationService); @PostConstruct @SuppressWarnings("unchecked") void init(); @Override HTMLElement getElement(); @Override HTMLElement getDisplayerElement(); FormsCanvasSessionHandler getFormSessionHandler(); @SuppressWarnings("unchecked") FormPropertiesWidget bind(final ClientSession session); @SuppressWarnings("unchecked") FormPropertiesWidget unbind(); @PreDestroy void destroy(); void show(); @SuppressWarnings("unchecked") void show(final Command callback); void resetLastElementRenderedCache(); boolean areLastPositionsForSameElementSame(final Element element); }### Answer: @Test public void testIsNode() { NodeImpl node = mock(NodeImpl.class); assertTrue(FormPropertiesWidget.isNode(node)); GraphImpl notNode = mock(GraphImpl.class); assertFalse(FormPropertiesWidget.isNode(notNode)); }
### Question: FormPropertiesWidget implements IsElement, FormPropertiesWidgetView.Presenter { protected static boolean isFiltered(final Element<? extends Definition<?>> element) { final Definition content = element.getContent(); if (Objects.isNull(content)) { return false; } final Object definition = content.getDefinition(); return !FormFiltersProviderFactory.getFilterForDefinition(element.getUUID(), definition).isEmpty(); } @Inject FormPropertiesWidget(final FormPropertiesWidgetView view, final DefinitionUtils definitionUtils, final FormsCanvasSessionHandler formSessionHandler, final Event<FormPropertiesOpened> propertiesOpenedEvent, final FormsContainer formsContainer, final FormsFlushManager formsFlushManager, final TranslationService translationService); @PostConstruct @SuppressWarnings("unchecked") void init(); @Override HTMLElement getElement(); @Override HTMLElement getDisplayerElement(); FormsCanvasSessionHandler getFormSessionHandler(); @SuppressWarnings("unchecked") FormPropertiesWidget bind(final ClientSession session); @SuppressWarnings("unchecked") FormPropertiesWidget unbind(); @PreDestroy void destroy(); void show(); @SuppressWarnings("unchecked") void show(final Command callback); void resetLastElementRenderedCache(); boolean areLastPositionsForSameElementSame(final Element element); }### Answer: @Test public void testIsFiltered() { NodeImpl nodeNullContent = mock(NodeImpl.class); when(nodeNullContent.getContent()).thenReturn(null); assertFalse(FormPropertiesWidget.isFiltered(nodeNullContent)); Definition content = mock(Definition.class); NodeImpl nodeUnfiltered = mock(NodeImpl.class); Object unfilteredDefinition = mock(Object.class); when(nodeUnfiltered.getContent()).thenReturn(content); when(content.getDefinition()).thenReturn(unfilteredDefinition); assertFalse(FormPropertiesWidget.isFiltered(nodeUnfiltered)); NodeImpl nodeFiltered = mock(NodeImpl.class); when(nodeFiltered.getContent()).thenReturn(content); when(content.getDefinition()).thenReturn(CUSTOM_DEFINITION); assertTrue(FormPropertiesWidget.isFiltered(nodeFiltered)); }
### Question: FormsFlushManager { void setCurrentContainer(FormsContainer container) { this.container = container; } void flush(ClientSession session, String elementUUID); @PreDestroy void destroy(); }### Answer: @Test public void setCurrentContainer() { tested.container = formsContainer; tested.setCurrentContainer(formsContainer); assertEquals(formsContainer, tested.container); }
### Question: FormsFlushManager { public void flush(ClientSession session, String elementUUID) { if (container != null) { container.flush(session.getCanvasHandler().getDiagram().getGraph().getUUID(), elementUUID); } } void flush(ClientSession session, String elementUUID); @PreDestroy void destroy(); }### Answer: @Test public void flush() { tested.container = null; tested.flush(clientSession, ELEMENT_UUID); tested.container = formsContainer; tested.flush(clientSession, ELEMENT_UUID); verify(formsContainer, times(1)).flush(GRAPH_UUID, ELEMENT_UUID); }
### Question: FormsFlushManager { @PreDestroy public void destroy() { this.container = null; } void flush(ClientSession session, String elementUUID); @PreDestroy void destroy(); }### Answer: @Test public void destroy() { FormsContainer formsContainer = mock(FormsContainer.class); tested.container = formsContainer; tested.destroy(); assertEquals(null, tested.container); }
### Question: FormsContainer implements IsElement { public void clearDiagramDisplayers(final String graphUuid) { LOGGER.fine("Clearing properties forms for graph: " + graphUuid); List<FormDisplayerKey> keys = formDisplayers.keySet() .stream() .filter(entry -> entry.getGraphUuid().equals(graphUuid)).collect(Collectors.toList()); keys.forEach(this::clearDisplayer); LOGGER.fine("Cleared properties forms for graph: " + graphUuid); } @Inject FormsContainer(final FormsContainerView view, final @Any ManagedInstance<FormDisplayer> displayersInstance, final Event<FormFieldChanged> formFieldChangedEvent); void render(final String graphUuid, final String domainObjectUUID, final Object domainObject, final Path diagramPath, final FieldChangeHandler changeHandler, final RenderMode renderMode); void clearDiagramDisplayers(final String graphUuid); void clearFormDisplayer(final String graphUuid, final String elementUid); void flush(String graphUUID, String elementUUID); @Override HTMLElement getElement(); @PreDestroy void destroyAll(); }### Answer: @Test public void testDestroyDiagramDisplayers() { RenderMode renderMode = RenderMode.EDIT_MODE; FormDisplayer firstDisplayer = testRender(getNode(FIRST_ELEMENT_UUID), 1, 1, renderMode); FormDisplayer secondDisplayer = testRender(getNode(SECOND_ELEMENT_UUID), 2, 1, renderMode); formsContainer.clearDiagramDisplayers(GRAPH_UUID); verify(firstDisplayer, times(3)).hide(); verify(view, times(1)).removeDisplayer(firstDisplayer); verify(displayersInstance, times(1)).destroy(firstDisplayer); verify(secondDisplayer, times(2)).hide(); verify(view, times(1)).removeDisplayer(secondDisplayer); verify(displayersInstance, times(1)).destroy(secondDisplayer); }
### Question: FormsContainer implements IsElement { @PreDestroy public void destroyAll() { view.clear(); currentDisplayer = null; displayersInstance.destroyAll(); formDisplayers.clear(); currentDisplayer = null; } @Inject FormsContainer(final FormsContainerView view, final @Any ManagedInstance<FormDisplayer> displayersInstance, final Event<FormFieldChanged> formFieldChangedEvent); void render(final String graphUuid, final String domainObjectUUID, final Object domainObject, final Path diagramPath, final FieldChangeHandler changeHandler, final RenderMode renderMode); void clearDiagramDisplayers(final String graphUuid); void clearFormDisplayer(final String graphUuid, final String elementUid); void flush(String graphUUID, String elementUUID); @Override HTMLElement getElement(); @PreDestroy void destroyAll(); }### Answer: @Test public void testDestroyAllDisplayers() { RenderMode renderMode = RenderMode.EDIT_MODE; testRender(getNode(FIRST_ELEMENT_UUID), 1, 1, renderMode); testRender(getNode(SECOND_ELEMENT_UUID), 2, 1, renderMode); formsContainer.destroyAll(); verify(view, times(1)).clear(); verify(displayersInstance, times(1)).destroyAll(); }
### Question: FormsContainer implements IsElement { public void flush(String graphUUID, String elementUUID) { FormDisplayer displayer = getDisplayer(graphUUID, elementUUID); DynamicFormRenderer renderer = displayer.getRenderer(); renderer.flush(); } @Inject FormsContainer(final FormsContainerView view, final @Any ManagedInstance<FormDisplayer> displayersInstance, final Event<FormFieldChanged> formFieldChangedEvent); void render(final String graphUuid, final String domainObjectUUID, final Object domainObject, final Path diagramPath, final FieldChangeHandler changeHandler, final RenderMode renderMode); void clearDiagramDisplayers(final String graphUuid); void clearFormDisplayer(final String graphUuid, final String elementUid); void flush(String graphUUID, String elementUUID); @Override HTMLElement getElement(); @PreDestroy void destroyAll(); }### Answer: @Test public void testflush() { DynamicFormRenderer dynamicFormRenderer = mock(DynamicFormRenderer.class); FormDisplayer formDisplayer = mock(FormDisplayer.class); when(formDisplayer.getRenderer()).thenReturn(dynamicFormRenderer); FormsContainer formsContainer = mock(FormsContainer.class); when(formsContainer.getDisplayer(GRAPH_UUID, FIRST_ELEMENT_UUID)).thenReturn(formDisplayer); doCallRealMethod().when(formsContainer).flush(GRAPH_UUID, FIRST_ELEMENT_UUID); formsContainer.flush(GRAPH_UUID, FIRST_ELEMENT_UUID); verify(dynamicFormRenderer, times(1)).flush(); }
### Question: GenerateDiagramFormsSessionCommand extends AbstractClientSessionCommand<EditorSession> { @Override public <V> void execute(Callback<V> callback) { formGenerationManager.call(this::call); callback.onSuccess(); } protected GenerateDiagramFormsSessionCommand(); @Inject GenerateDiagramFormsSessionCommand(final ClientFormGenerationManager formGenerationManager); @Override void execute(Callback<V> callback); @Override boolean accepts(final ClientSession session); }### Answer: @Test @SuppressWarnings("unchecked") public void testGenerate() { final ClientSessionCommand.Callback callback = mock(ClientSessionCommand.Callback.class); tested.execute(callback); verify(formGenerationService, times(1)).generateAllForms(eq(diagram)); verify(callback, times(1)).onSuccess(); verify(callback, never()).onError(anyObject()); }
### Question: GenerateProcessFormsSessionCommand extends AbstractClientSessionCommand<EditorSession> { @Override public <V> void execute(Callback<V> callback) { formGenerationManager.call(this::call); callback.onSuccess(); } protected GenerateProcessFormsSessionCommand(); @Inject GenerateProcessFormsSessionCommand(final ClientFormGenerationManager formGenerationManager); @Override void execute(Callback<V> callback); @Override boolean accepts(final ClientSession session); }### Answer: @Test @SuppressWarnings("unchecked") public void testGenerate() { final ClientSessionCommand.Callback callback = mock(ClientSessionCommand.Callback.class); tested.execute(callback); verify(formGenerationService, times(1)).generateProcessForm(eq(diagram)); verify(callback, times(1)).onSuccess(); verify(callback, never()).onError(anyObject()); }
### Question: GenerateSelectedFormsSessionCommand extends AbstractClientSessionCommand<EditorSession> { @Override public <V> void execute(Callback<V> callback) { formGenerationManager.call(this::call); callback.onSuccess(); } protected GenerateSelectedFormsSessionCommand(); @Inject GenerateSelectedFormsSessionCommand(final ClientFormGenerationManager formGenerationManager, final FormGenerationNotifier formGenerationNotifier, final ClientTranslationService translationService); GenerateSelectedFormsSessionCommand setElementAcceptor(final Predicate<Element> acceptor); @Override void execute(Callback<V> callback); @Override boolean accepts(final ClientSession session); }### Answer: @Test @SuppressWarnings("unchecked") public void testGenerateSelected() { final ClientSessionCommand.Callback callback = mock(ClientSessionCommand.Callback.class); tested.execute(callback); ArgumentCaptor<String[]> idsCaptor = ArgumentCaptor.forClass(String[].class); verify(formGenerationService, times(1)).generateSelectedForms(eq(diagram), idsCaptor.capture()); final String[] ids = idsCaptor.getValue(); assertTrue(Arrays.asList(ids).contains(ID1)); assertTrue(Arrays.asList(ids).contains(ID2)); verify(acceptor, times(1)).test(eq(element1)); verify(acceptor, times(1)).test(eq(element2)); verify(callback, times(1)).onSuccess(); verify(callback, never()).onError(anyObject()); verify(translationService, never()).getValue(FormsClientConstants.FormsNoItemsSelectedForGeneration); verify(formGenerationNotifier, never()).showNotification(anyString()); }
### Question: ClientFormGenerationManager { public void call(final Consumer<FormGenerationService> service) { service.accept(formGenerationService.call(getRemoteCallback(), getErrorCallback())); } protected ClientFormGenerationManager(); @Inject ClientFormGenerationManager(final ClientTranslationService translationService, final FormGenerationNotifier formGenerationNotifier, final Caller<FormGenerationService> formGenerationService); void call(final Consumer<FormGenerationService> service); }### Answer: @Test @SuppressWarnings("unchecked") public void testCall() { final Consumer<FormGenerationService> consumer = mock(Consumer.class); tested.call(consumer); verify(consumer, times(1)).accept(eq(formGenerationService)); }
### Question: ClientFormGenerationManager { void onFormGeneratedEvent(@Observes FormGeneratedEvent event) { formGenerationNotifier.showNotification(translationService.getValue(FormsClientConstants.FormsGenerationSuccess, event.getName())); } protected ClientFormGenerationManager(); @Inject ClientFormGenerationManager(final ClientTranslationService translationService, final FormGenerationNotifier formGenerationNotifier, final Caller<FormGenerationService> formGenerationService); void call(final Consumer<FormGenerationService> service); }### Answer: @Test public void testOnFormGenerationSuccess() { final FormGeneratedEvent event = mock(FormGeneratedEvent.class); when(event.getName()).thenReturn("name1"); tested.onFormGeneratedEvent(event); verify(translationService, times(1)).getValue(eq(FormsClientConstants.FormsGenerationSuccess), eq("name1")); verify(formGenerationNotifier, times(1)).showNotification(anyString()); verify(formGenerationNotifier, never()).showError(anyString()); }
### Question: ClientFormGenerationManager { void onFormGenerationFailureEvent(@Observes FormGenerationFailureEvent event) { formGenerationNotifier.showError(translationService.getValue(FormsClientConstants.FormsGenerationFailure, event.getName())); } protected ClientFormGenerationManager(); @Inject ClientFormGenerationManager(final ClientTranslationService translationService, final FormGenerationNotifier formGenerationNotifier, final Caller<FormGenerationService> formGenerationService); void call(final Consumer<FormGenerationService> service); }### Answer: @Test public void testOnFormGenerationFailure() { final FormGenerationFailureEvent event = mock(FormGenerationFailureEvent.class); when(event.getName()).thenReturn("name1"); tested.onFormGenerationFailureEvent(event); verify(translationService, times(1)).getValue(eq(FormsClientConstants.FormsGenerationFailure), eq("name1")); verify(formGenerationNotifier, times(1)).showError(anyString()); verify(formGenerationNotifier, never()).showNotification(anyString()); }
### Question: RefreshFormPropertiesEvent implements UberFireEvent { public ClientSession getSession() { return session; } RefreshFormPropertiesEvent(final ClientSession session); RefreshFormPropertiesEvent(final ClientSession session, final String uuid); boolean hasUuid(); String getUuid(); ClientSession getSession(); }### Answer: @Test public void testGetSession() { assertThat(event.getSession()).isEqualTo(session); }
### Question: RefreshFormPropertiesEvent implements UberFireEvent { public String getUuid() { return uuid; } RefreshFormPropertiesEvent(final ClientSession session); RefreshFormPropertiesEvent(final ClientSession session, final String uuid); boolean hasUuid(); String getUuid(); ClientSession getSession(); }### Answer: @Test public void testGetUUID() { assertThat(event.getUuid()).isEqualTo(UUID); }
### Question: IntegrationHandlerProvider { public Optional<IntegrationHandler> getIntegrationHandler() { return integrationHandler; } IntegrationHandlerProvider(); @Inject IntegrationHandlerProvider(@Any final Instance<IntegrationHandler> integrationHandlerInstance); Optional<IntegrationHandler> getIntegrationHandler(); }### Answer: @Test public void testIntegrationHandlerProviderWhenIntegrationIsPresent() { IntegrationHandler integrationHandler = mock(IntegrationHandler.class); integrationHandlers.add(integrationHandler); when(integrationHandlerInstance.iterator()).thenReturn(integrationHandlers.iterator()); integrationHandlerProvider = new IntegrationHandlerProvider(integrationHandlerInstance); assertTrue(integrationHandlerProvider.getIntegrationHandler().isPresent()); assertEquals(integrationHandler, integrationHandlerProvider.getIntegrationHandler().get()); } @Test public void testIntegrationHandlerProviderWhenIntegrationIsNotPresent() { when(integrationHandlerInstance.iterator()).thenReturn(integrationHandlers.iterator()); integrationHandlerProvider = new IntegrationHandlerProvider(integrationHandlerInstance); assertFalse(integrationHandlerProvider.getIntegrationHandler().isPresent()); }
### Question: IntegrationHandlerImpl implements IntegrationHandler { @Override public void migrateFromStunnerToJBPMDesigner(Path path, PlaceRequest place, boolean isDirty, ParameterizedCommand<Consumer<Boolean>> saveCommand) { checkIfDirtyAndMigrate(isDirty, saveCommand, () -> fromStunnerToJBPMDesigner(path, place)); } IntegrationHandlerImpl(); @Inject IntegrationHandlerImpl(final Caller<IntegrationService> integrationService, final PlaceManager placeManger, final PopupUtil popupUtil, final ErrorPopupPresenter errorPopup, final MarshallingResponsePopup responsePopup, final ClientTranslationService translationService, final Event<NotificationEvent> notification); @Override void migrateFromJBPMDesignerToStunner(Path path, PlaceRequest place, boolean isDirty, ParameterizedCommand<Consumer<Boolean>> saveCommand); @Override void migrateFromStunnerToJBPMDesigner(Path path, PlaceRequest place, boolean isDirty, ParameterizedCommand<Consumer<Boolean>> saveCommand); }### Answer: @Test public void testMigrateFromStunnerToJBPMDesignerWithUnexpectedError() { prepareServiceCallerError(integrationService, integrationServiceCaller, new Throwable(ERROR)); handler.migrateFromStunnerToJBPMDesigner(stunnerPath, place, false, saveSuccessfulCommand); verifyUserWasAskedForStartingToJBPMMigrationAndRespond(true); String expectedMessage = MigrateActionUnexpectedErrorMessage + "\n" + ERROR; verify(errorPopup).showMessage(expectedMessage); }
### Question: SVGShapeProcessor extends AbstractErrorAbsorbingProcessor { @Override protected boolean processWithExceptions(Set<? extends TypeElement> set, RoundEnvironment roundEnv) throws Exception { if (roundEnv.processingOver()) { return processLastRound(set, roundEnv); } if (roundEnv.errorRaised()) { return false; } generator = SVGGeneratorFactory.newGenerator(); final Elements elementUtils = processingEnv.getElementUtils(); for (Element e : roundEnv.getElementsAnnotatedWith(elementUtils.getTypeElement(ANNOTATION_SVGSHAPE_VIEW_FACTORY))) { processSvgShapeViewFactory(set, e, roundEnv); } return true; } final static String ANNOTATION_SVGSHAPE_VIEW_FACTORY; }### Answer: @Test @SuppressWarnings("unchecked") public void testMultipleSVGViewFactories() throws Exception { types.add(makeTypeElement("Factory1")); types.add(makeTypeElement("Factory2")); when(roundEnvironment.errorRaised()).thenReturn(false); when(roundEnvironment.getElementsAnnotatedWith(SVGViewFactoryAnnotation)).thenReturn(types); when(elements.getTypeElement(SVGShapeProcessor.ANNOTATION_SVGSHAPE_VIEW_FACTORY)).thenReturn(SVGViewFactoryAnnotation); when(roundEnvironment.processingOver()).thenReturn(false); processor.processWithExceptions(elementTypes, roundEnvironment); when(roundEnvironment.processingOver()).thenReturn(true); processor.processWithExceptions(elementTypes, roundEnvironment); verify(filer, times(2)).createSourceFile(generatedSourceFileNames.capture()); assertContains(this.getClass().getPackage().getName() + ".Factory1Impl"); assertContains(this.getClass().getPackage().getName() + ".Factory2Impl"); }
### Question: SVGGeneratorFormatUtils { public static String format(final double value) { return DF.format(value); } static String getValidInstanceId(final PrimitiveDefinition<?> primitiveDefinition); static String getValidInstanceId(final String value); static String format(final double value); static String format(final String pattern, final double... values); }### Answer: @Test public void testFormatDoubleES() { Locale.setDefault(new Locale("es", "ES")); final String result = SVGGeneratorFormatUtils.format(45.675d); assertEquals("45.67", result); } @Test public void testFormatDoubleRU() { Locale.setDefault(new Locale("ru", "RU")); final String result = SVGGeneratorFormatUtils.format(45.675d); assertEquals("45.67", result); } @Test public void testFormatDoubleUS() { Locale.setDefault(new Locale("en", "US")); final String result = SVGGeneratorFormatUtils.format(45.675d); assertEquals("45.67", result); } @Test public void testFormatMessageES() { Locale.setDefault(new Locale("es", "ES")); final String result = SVGGeneratorFormatUtils.format("[%1s,%2s]", 45.675d, 23.4563d); assertEquals("[45.67,23.46]", result); } @Test public void testFormatMessageRU() { Locale.setDefault(new Locale("ru", "RU")); final String result = SVGGeneratorFormatUtils.format("[%1s,%2s]", 45.675d, 23.4563d); assertEquals("[45.67,23.46]", result); } @Test public void testFormatMessageUS() { Locale.setDefault(new Locale("en", "US")); final String result = SVGGeneratorFormatUtils.format("[%1s,%2s]", 45.675d, 23.4563d); assertEquals("[45.67,23.46]", result); }
### Question: GroupDefinitionGenerator extends AbstractPrimitiveDefinitionGenerator<GroupDefinition> implements PrimitiveDefinitionGenerator<GroupDefinition> { @Override public StringBuffer generate(final GroupDefinition input) throws GeneratorException { final StringBuffer wrapped = super.generate(input); final StringBuffer wrapper; try { wrapper = writeTemplate(new HashMap<>()); super.appendDraggable(wrapper, input); super.appendListening(wrapped, input); wrapper.append(formatString(ADD_WRAPPED, wrapped.toString())); } catch (final GenerationException e) { throw new GeneratorException(e); } return wrapper; } @Override StringBuffer generate(final GroupDefinition input); @Override Class<GroupDefinition> getDefinitionType(); }### Answer: @Test public void testGenerate() throws Exception { final GroupDefinition definition = new GroupDefinition(ID); definition.setX(X); definition.setY(Y); definition.setAlpha(ALPHA); definition.setTransformDefinition(new TransformDefinitionImpl(VBOX_WIDTH, VBOX_HEIGHT, VBOX_MIN_X, VBOX_MIN_Y)); final String generated = tested.generate(definition).toString(); assertTrue(generated.contains("new " + Group.class.getName() + "()")); GeneratorAssertions.assertDraggable(generated); GeneratorAssertions.assertID(generated, ID); GeneratorAssertions.assertX(generated, X); GeneratorAssertions.assertY(generated, Y); GeneratorAssertions.assertAlpha(generated, ALPHA); GeneratorAssertions.assertScale(generated, VBOX_WIDTH, VBOX_HEIGHT); GeneratorAssertions.assertListening(generated, LISTENING); }
### Question: SVGStyleTranslator { static List<Element> getElementsTree(final Element element) { final List<Element> tree = new LinkedList<>(); tree.add(element); Node parent = element.getParentNode(); while (null != parent) { if (parent instanceof Element) { tree.add((Element) parent); } parent = parent.getParentNode(); } return tree; } private SVGStyleTranslator(); static TransformDefinition parseTransformDefinition(final Element element); static StyleSheetDefinition parseStyleSheetDefinition(final String cssPath, final InputStream cssStream); static StyleDefinition parseStyleDefinition(final Element element, final String svgId, final StyleSheetDefinition styleSheetDefinition); static String[] getClassNames(final Element element); static final String ID; static final String OPACITY; static final String FILL; static final String FILL_OPACITY; static final String STROKE; static final String STROKE_OPACITY; static final String STROKE_WIDTH; static final String FONT_FAMILY; static final String STROKE_DASHARRAY; static final String FONT_SIZE; static final String STYLE; static final String CSS_CLASS; static final String TRANSFORM; static final String ATTR_VALUE_NONE; static final String[] ATTR_NAMES; }### Answer: @Test public void testGetParentsTree() { List<Element> tree = SVGStyleTranslator.getElementsTree(element); assertNotNull(tree); assertEquals(3, tree.size()); assertEquals(element, tree.get(0)); assertEquals(parent, tree.get(1)); assertEquals(root, tree.get(2)); }
### Question: SVGStyleTranslator { static List<String> parseAllSelectors(final Element element) { final List<Element> elements = getElementsTree(element); final List<String> result = new LinkedList<>(); for (final Element candidate : elements) { Collection<String> selectors = parseElementSelectors(candidate); if (result.isEmpty()) { result.addAll(selectors); } else { final List<String> parentSelectors = result.stream().collect(Collectors.toList()); for (String selector : selectors) { for (String parentSelector : parentSelectors) { result.add(selector + " " + parentSelector); } } } } return result; } private SVGStyleTranslator(); static TransformDefinition parseTransformDefinition(final Element element); static StyleSheetDefinition parseStyleSheetDefinition(final String cssPath, final InputStream cssStream); static StyleDefinition parseStyleDefinition(final Element element, final String svgId, final StyleSheetDefinition styleSheetDefinition); static String[] getClassNames(final Element element); static final String ID; static final String OPACITY; static final String FILL; static final String FILL_OPACITY; static final String STROKE; static final String STROKE_OPACITY; static final String STROKE_WIDTH; static final String FONT_FAMILY; static final String STROKE_DASHARRAY; static final String FONT_SIZE; static final String STYLE; static final String CSS_CLASS; static final String TRANSFORM; static final String ATTR_VALUE_NONE; static final String[] ATTR_NAMES; }### Answer: @Test public void testParseAllSelectors() { Collection<String> selectors = SVGStyleTranslator.parseAllSelectors(element); assertNotNull(selectors); assertEquals(48, selectors.size()); assertArrayEquals(selectors.stream().toArray(String[]::new), ALL_SELECTORS.stream().toArray(String[]::new)); }
### Question: SVGAttributeParser { public static double toPixelValue(final String value, final double defaultValue) { if (isEmpty(value)) { return defaultValue; } return toPixelValue(value); } static double toPixelValue(final String value, final double defaultValue); static double toPixelValue(final String value); static String toHexColorString(final String raw); static String rgbToHexString(final int r, final int g, final int b); static String rgbToHexString(final int r, final int g, final int b, final int a); static String rgbToHexString(int rgb); static int toRGB(final int r, final int g, final int b, final int a); }### Answer: @Test public void testPixelValues() { assertEquals(0d, SVGAttributeParser.toPixelValue("0"), 0d); assertEquals(0d, SVGAttributeParser.toPixelValue("0px"), 0d); assertEquals(10d, SVGAttributeParser.toPixelValue("10px"), 0d); assertEquals(1328.5d, SVGAttributeParser.toPixelValue("1328.5"), 0d); assertEquals(1328.5d, SVGAttributeParser.toPixelValue("1328.5px"), 0d); assertEquals(0d, SVGAttributeParser.toPixelValue("", 0d), 0d); assertEquals(12.3d, SVGAttributeParser.toPixelValue("", 12.3d), 0d); assertEquals(3d, SVGAttributeParser.toPixelValue(null, 3d), 0d); }
### Question: SVGAttributeParser { public static String rgbToHexString(final int r, final int g, final int b) { return rgbToHexString(r, g, b, 1); } static double toPixelValue(final String value, final double defaultValue); static double toPixelValue(final String value); static String toHexColorString(final String raw); static String rgbToHexString(final int r, final int g, final int b); static String rgbToHexString(final int r, final int g, final int b, final int a); static String rgbToHexString(int rgb); static int toRGB(final int r, final int g, final int b, final int a); }### Answer: @Test public void testRGBToHexString() { assertEquals("#000000", SVGAttributeParser.rgbToHexString(0, 0, 0, 1)); assertEquals("#0000ff", SVGAttributeParser.rgbToHexString(0, 0, 255, 1)); assertEquals("#ff0000", SVGAttributeParser.rgbToHexString(255, 0, 0, 1)); assertEquals("#ffffff", SVGAttributeParser.rgbToHexString(255, 255, 255, 1)); }
### Question: SVGAttributeParser { public static int toRGB(final int r, final int g, final int b, final int a) { return ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF) << 0); } static double toPixelValue(final String value, final double defaultValue); static double toPixelValue(final String value); static String toHexColorString(final String raw); static String rgbToHexString(final int r, final int g, final int b); static String rgbToHexString(final int r, final int g, final int b, final int a); static String rgbToHexString(int rgb); static int toRGB(final int r, final int g, final int b, final int a); }### Answer: @Test public void testToRGB() { assertEquals(16777216, SVGAttributeParser.toRGB(0, 0, 0, 1)); assertEquals(16777471, SVGAttributeParser.toRGB(0, 0, 255, 1)); assertEquals(33488896, SVGAttributeParser.toRGB(255, 0, 0, 1)); assertEquals(33554431, SVGAttributeParser.toRGB(255, 255, 255, 1)); }
### Question: AbstractSVGPrimitiveTranslator implements SVGElementTranslator<E, O> { protected void translateTransformDefinition(final E element, final O def) { boolean result = true; Node candidate = element; while (null != candidate) { if (candidate instanceof Element) { Optional<Boolean> scalable = isScalable((Element) candidate); if (scalable.isPresent()) { result = scalable.get(); break; } candidate = candidate.getParentNode(); } else { candidate = null; } } def.setScalable(result); } @Override O translate(final E element, final SVGTranslatorContext context); }### Answer: @Test public void testScalableFalse() { when(element.getAttributeNS(STUNNER_URI, STUNNER_ATTR_NS_TRANSFORM)) .thenReturn(STUNNER_ATTR_TRANSFORM_NON_SCALABLE); tested.translateTransformDefinition(element, def); verify(def).setScalable(false); } @Test public void testScalableTrue() { when(element.getAttributeNS(STUNNER_URI, STUNNER_ATTR_NS_TRANSFORM)) .thenReturn(STUNNER_ATTR_TRANSFORM_SCALABLE); tested.translateTransformDefinition(element, def); verify(def).setScalable(true); }
### Question: SVGViewBoxTranslator { public static ViewDefinition.ViewBoxDefinition translate(final String raw) throws TranslatorException { final String[] parsed = parse(raw); return build(parsed[0], parsed[1], parsed[2], parsed[3]); } static ViewDefinition.ViewBoxDefinition translate(final String raw); }### Answer: @Test public void testTranslate() throws Exception { ViewDefinition.ViewBoxDefinition definition = SVGViewBoxTranslator.translate("0 0 0 0"); assertDefinition(definition, 0, 0, 0, 0); definition = SVGViewBoxTranslator.translate("0px 0px 0px 0px"); assertDefinition(definition, 0, 0, 0, 0); definition = SVGViewBoxTranslator.translate("123.4 23 567.45 568.70"); assertDefinition(definition, 123.4, 23, 567.45, 568.70); definition = SVGViewBoxTranslator.translate("-123.4 -23.5 567.45 568.70"); assertDefinition(definition, -123.4, -23.5, 567.45, 568.70); } @Test(expected = TranslatorException.class) public void testTranslateException() throws Exception { ViewDefinition.ViewBoxDefinition definition = SVGViewBoxTranslator.translate("0 0 0"); assertDefinition(definition, 0, 0, 0, 0); }
### Question: SVGContainer extends SVGPrimitive<Group> { public String getId() { return id; } SVGContainer(final String id, final Group primitive, final boolean scalable, final LayoutContainer.Layout layout); @SuppressWarnings("unchecked") SVGContainer addPrimitive(final IPrimitive<?> primitive); SVGContainer add(final SVGPrimitiveShape primitive); @Override void destroy(); String getId(); List<SVGPrimitive<?>> getChildren(); IPrimitive getPrimitive(final String uuid); }### Answer: @Test public void testGetters() { assertEquals("cont1", tested.getId()); assertEquals(LayoutContainer.Layout.BOTTOM, tested.getLayout()); assertEquals(group, tested.get()); assertTrue(tested.isScalable()); }
### Question: SVGPrimitiveShape extends SVGPrimitive<Shape<?>> implements LienzoShapeView<SVGPrimitiveShape> { @Override public SVGPrimitiveShape removeShadow() { get().setShadow(null); return this; } SVGPrimitiveShape(Shape<?> shape); SVGPrimitiveShape(Shape<?> shape, boolean scalable, LayoutContainer.Layout layout); @Override SVGPrimitiveShape setUUID(final String uuid); @Override String getUUID(); @Override double getShapeX(); @Override double getShapeY(); @Override Point2D getShapeAbsoluteLocation(); @Override SVGPrimitiveShape setShapeLocation(final Point2D location); @Override double getAlpha(); @Override SVGPrimitiveShape setAlpha(final double alpha); @Override String getFillColor(); @Override SVGPrimitiveShape setFillColor(final String color); @Override double getFillAlpha(); @Override SVGPrimitiveShape setFillAlpha(final double alpha); @Override String getStrokeColor(); @Override SVGPrimitiveShape setStrokeColor(final String color); @Override double getStrokeAlpha(); @Override SVGPrimitiveShape setStrokeAlpha(final double alpha); @Override double getStrokeWidth(); @Override SVGPrimitiveShape setStrokeWidth(final double width); @Override SVGPrimitiveShape setDragEnabled(final boolean draggable); @Override SVGPrimitiveShape moveToTop(); @Override SVGPrimitiveShape moveToBottom(); @Override SVGPrimitiveShape moveUp(); @Override SVGPrimitiveShape moveDown(); @Override BoundingBox getBoundingBox(); @Override void removeFromParent(); @Override List<Shape<?>> getDecorators(); @Override SVGPrimitiveShape setShadow(final String color, final int blur, final double offx, final double offy); @Override SVGPrimitiveShape removeShadow(); @Override Object getUserData(); @Override void setUserData(Object userData); }### Answer: @Test public void testRemoveShadow() { Shape<?> instance = mock(Shape.class); tested = new SVGPrimitiveShape(instance); tested.removeShadow(); verify(instance, times(1)).setShadow(eq(null)); }
### Question: SVGShapeViewResource { public SVGShapeView build(final boolean resizable) { return build(new Arguments(resizable)); } SVGShapeViewResource(final Function<Arguments, SVGShapeView> builder); SVGShapeView build(final boolean resizable); SVGShapeView build(final Double width, final Double height, final boolean resizable); }### Answer: @Test public void testBuildSpecifyingSize() { tested.build(100d, 222d, true); final ArgumentCaptor<SVGShapeViewResource.Arguments> argumentCaptor = ArgumentCaptor.forClass(SVGShapeViewResource.Arguments.class); verify(builderFunction, times(1)).apply(argumentCaptor.capture()); final SVGShapeViewResource.Arguments arguments = argumentCaptor.getValue(); assertEquals(100d, arguments.width, 0d); assertEquals(222d, arguments.heigth, 0d); assertTrue(arguments.resizable); verify(view, times(1)).refresh(); } @Test public void testBuildDefaultSize() { tested.build(true); final ArgumentCaptor<SVGShapeViewResource.Arguments> argumentCaptor = ArgumentCaptor.forClass(SVGShapeViewResource.Arguments.class); verify(builderFunction, times(1)).apply(argumentCaptor.capture()); final SVGShapeViewResource.Arguments arguments = argumentCaptor.getValue(); assertTrue(arguments.resizable); verify(view, times(1)).refresh(); }