@Test public void testSaveWhenResourceIsProjectDiagram() { final Path path = mock(Path.class); final Metadata metadata = mock(Metadata.class); final ProjectDiagramImpl projectDiagram = mock(ProjectDiagramImpl.class); final Path expectedPath = mock(Path.class); final ProjectDiagramResourceImpl resource = new ProjectDiagramResourceImpl(projectDiagram); final String comment = "comment"; when(projectDiagramService.save(path, projectDiagram, metadata, comment)).thenReturn(expectedPath); final Path actualPath = service.save(path, resource, metadata, comment); assertSame(expectedPath, actualPath); }
@Override public Path save(final Path path, final ProjectDiagramResource resource, final Metadata metadata, final String comment) { final DiagramType type = resource.getType(); final Map<DiagramType, Function<ProjectDiagramResource, Path>> saveOperations = new HashMap<>(); saveOperations.put(DiagramType.PROJECT_DIAGRAM, (r) -> projectDiagramService.save(path, getProjectDiagram(r), metadata, comment)); saveOperations.put(DiagramType.XML_DIAGRAM, (r) -> projectDiagramService.saveAsXml(path, getXmlDiagram(r), metadata, comment)); return saveOperations.get(type).apply(resource); }
ProjectDiagramResourceServiceImpl implements ProjectDiagramResourceService { @Override public Path save(final Path path, final ProjectDiagramResource resource, final Metadata metadata, final String comment) { final DiagramType type = resource.getType(); final Map<DiagramType, Function<ProjectDiagramResource, Path>> saveOperations = new HashMap<>(); saveOperations.put(DiagramType.PROJECT_DIAGRAM, (r) -> projectDiagramService.save(path, getProjectDiagram(r), metadata, comment)); saveOperations.put(DiagramType.XML_DIAGRAM, (r) -> projectDiagramService.saveAsXml(path, getXmlDiagram(r), metadata, comment)); return saveOperations.get(type).apply(resource); } }
ProjectDiagramResourceServiceImpl implements ProjectDiagramResourceService { @Override public Path save(final Path path, final ProjectDiagramResource resource, final Metadata metadata, final String comment) { final DiagramType type = resource.getType(); final Map<DiagramType, Function<ProjectDiagramResource, Path>> saveOperations = new HashMap<>(); saveOperations.put(DiagramType.PROJECT_DIAGRAM, (r) -> projectDiagramService.save(path, getProjectDiagram(r), metadata, comment)); saveOperations.put(DiagramType.XML_DIAGRAM, (r) -> projectDiagramService.saveAsXml(path, getXmlDiagram(r), metadata, comment)); return saveOperations.get(type).apply(resource); } ProjectDiagramResourceServiceImpl(); @Inject  ProjectDiagramResourceServiceImpl(final ProjectDiagramService projectDiagramService,
                                             final RenameService renameService,
                                             final SaveAndRenameServiceImpl<ProjectDiagramResource, Metadata> saveAndRenameService); }
ProjectDiagramResourceServiceImpl implements ProjectDiagramResourceService { @Override public Path save(final Path path, final ProjectDiagramResource resource, final Metadata metadata, final String comment) { final DiagramType type = resource.getType(); final Map<DiagramType, Function<ProjectDiagramResource, Path>> saveOperations = new HashMap<>(); saveOperations.put(DiagramType.PROJECT_DIAGRAM, (r) -> projectDiagramService.save(path, getProjectDiagram(r), metadata, comment)); saveOperations.put(DiagramType.XML_DIAGRAM, (r) -> projectDiagramService.saveAsXml(path, getXmlDiagram(r), metadata, comment)); return saveOperations.get(type).apply(resource); } 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); }
ProjectDiagramResourceServiceImpl implements ProjectDiagramResourceService { @Override public Path save(final Path path, final ProjectDiagramResource resource, final Metadata metadata, final String comment) { final DiagramType type = resource.getType(); final Map<DiagramType, Function<ProjectDiagramResource, Path>> saveOperations = new HashMap<>(); saveOperations.put(DiagramType.PROJECT_DIAGRAM, (r) -> projectDiagramService.save(path, getProjectDiagram(r), metadata, comment)); saveOperations.put(DiagramType.XML_DIAGRAM, (r) -> projectDiagramService.saveAsXml(path, getXmlDiagram(r), metadata, comment)); return saveOperations.get(type).apply(resource); } 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);  }