AbstractModuleRepositoriesServiceImpl implements ModuleRepositoriesService { @Override public ModuleRepositories create(final Path path) { final org.uberfire.java.nio.file.Path nioPath = Paths.convert(path); if (ioService.exists(nioPath)) { throw new FileAlreadyExistsException(path.toString()); } try { ioService.startBatch(nioPath.getFileSystem(), commentedOptionFactory.makeCommentedOption("Creating " + path.toString() + "...")); final T project = getModule(path); final Set<MavenRepositoryMetadata> content = new HashSet<MavenRepositoryMetadata>(); if (project == null) { content.addAll(repositoryResolver.getRemoteRepositoriesMetaData()); } else { content.addAll(repositoryResolver.getRemoteRepositoriesMetaData(project)); } final ModuleRepositories repositories = createProjectRepositories(content); ioService.write(Paths.convert(path), contentHandler.toString(repositories)); return repositories; } finally { ioService.endBatch(); } } AbstractModuleRepositoriesServiceImpl();  AbstractModuleRepositoriesServiceImpl(final IOService ioService,
                                                 final ModuleRepositoryResolver repositoryResolver,
                                                 final ModuleRepositoriesContentHandler contentHandler,
                                                 final CommentedOptionFactory commentedOptionFactory); @Override ModuleRepositories create(final Path path); @Override ModuleRepositories load(final Path path); @Override Path save(final Path resource,
                     final ModuleRepositories moduleRepositories,
                     final String comment);  }
@Test public void testCreateWithoutProject() { final String xml = "<project-repositories>\n" + " <repositories>\n" + " <repository>\n" + " <include>true</include>\n" + " <metadata>\n" + " <id>local</id>\n" + " <url>local-url</url>\n" + " <source>LOCAL</source>\n" + " </metadata>\n" + " </repository>\n" + " </repositories>\n" + "</project-repositories>"; final Path path = mock(Path.class); when(path.toURI()).thenReturn("file: final org.uberfire.java.nio.file.Path nioPath = Paths.convert(path); final Set<MavenRepositoryMetadata> metadata = new HashSet<MavenRepositoryMetadata>(); metadata.add(new MavenRepositoryMetadata("local", "local-url", MavenRepositorySource.LOCAL)); when(repositoryResolver.getRemoteRepositoriesMetaData()).thenReturn(metadata); when(resourceResolver.resolveModule(path)).thenReturn(null); service.create(path); verify(resourceResolver, times(1)).resolveModule(path); verify(repositoryResolver, times(1)).getRemoteRepositoriesMetaData(); verify(ioService, times(1)).startBatch(any(FileSystem.class), any(CommentedOption.class)); verify(ioService, times(1)).write(eq(nioPath), eq(xml)); verify(ioService, times(1)).endBatch(); }
@Test public void testCreateWithProject() { final String xml = "<project-repositories>\n" + " <repositories>\n" + " <repository>\n" + " <include>true</include>\n" + " <metadata>\n" + " <id>local</id>\n" + " <url>local-url</url>\n" + " <source>LOCAL</source>\n" + " </metadata>\n" + " </repository>\n" + " </repositories>\n" + "</project-repositories>"; final Path path = mock(Path.class); when(path.toURI()).thenReturn("file: final org.uberfire.java.nio.file.Path nioPath = Paths.convert(path); final Module module = mock(Module.class); final Set<MavenRepositoryMetadata> metadata = new HashSet<MavenRepositoryMetadata>(); metadata.add(new MavenRepositoryMetadata("local", "local-url", MavenRepositorySource.LOCAL)); when(repositoryResolver.getRemoteRepositoriesMetaData(eq(module))).thenReturn(metadata); when(resourceResolver.resolveModule(path)).thenReturn(module); service.create(path); verify(resourceResolver, times(1)).resolveModule(path); verify(repositoryResolver, times(1)).getRemoteRepositoriesMetaData(eq(module)); verify(ioService, times(1)).startBatch(any(FileSystem.class), any(CommentedOption.class)); verify(ioService, times(1)).write(eq(nioPath), eq(xml)); verify(ioService, times(1)).endBatch(); }