@Test public void testProjectImportsLoad_Exists() throws URISyntaxException { when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true); final ProjectImports projectImports = projectImportsService.load(pathToImports); verify(ioService, never()).write(any(org.uberfire.java.nio.file.Path.class), any(String.class)); verify(ioService, times(1)).readAllString(any(org.uberfire.java.nio.file.Path.class)); assertTrue(projectImports.getImports().contains(new Import(Number.class))); }
@Override public ProjectImports load(final Path path) { try { final org.uberfire.java.nio.file.Path nioPath = Paths.convert(path); if (!ioService.exists(nioPath)) { saveProjectImports(path); } final String content = ioService.readAllString(Paths.convert(path)); final ProjectImports projectImports = projectConfigurationContentHandler.toModel(content); final Import javaLangNumber = new Import(Number.class); if (projectImports.getImports().getImports().stream().noneMatch(anImport -> Objects.equals(anImport, javaLangNumber))) { projectImports.getImports().addImport(javaLangNumber); } return projectImports; } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
ProjectImportsServiceImpl extends KieService<ProjectImportsContent> implements ProjectImportsService { @Override public ProjectImports load(final Path path) { try { final org.uberfire.java.nio.file.Path nioPath = Paths.convert(path); if (!ioService.exists(nioPath)) { saveProjectImports(path); } final String content = ioService.readAllString(Paths.convert(path)); final ProjectImports projectImports = projectConfigurationContentHandler.toModel(content); final Import javaLangNumber = new Import(Number.class); if (projectImports.getImports().getImports().stream().noneMatch(anImport -> Objects.equals(anImport, javaLangNumber))) { projectImports.getImports().addImport(javaLangNumber); } return projectImports; } catch (Exception e) { throw ExceptionUtilities.handleException(e); } } }
ProjectImportsServiceImpl extends KieService<ProjectImportsContent> implements ProjectImportsService { @Override public ProjectImports load(final Path path) { try { final org.uberfire.java.nio.file.Path nioPath = Paths.convert(path); if (!ioService.exists(nioPath)) { saveProjectImports(path); } final String content = ioService.readAllString(Paths.convert(path)); final ProjectImports projectImports = projectConfigurationContentHandler.toModel(content); final Import javaLangNumber = new Import(Number.class); if (projectImports.getImports().getImports().stream().noneMatch(anImport -> Objects.equals(anImport, javaLangNumber))) { projectImports.getImports().addImport(javaLangNumber); } return projectImports; } catch (Exception e) { throw ExceptionUtilities.handleException(e); } } ProjectImportsServiceImpl(); @Inject  ProjectImportsServiceImpl(final @Named("ioStrategy") IOService ioService,
                                     final ProjectConfigurationContentHandler projectConfigurationContentHandler,
                                     final RenameService renameService,
                                     final SaveAndRenameServiceImpl<ProjectImports, Metadata> saveAndRenameService); }
ProjectImportsServiceImpl extends KieService<ProjectImportsContent> implements ProjectImportsService { @Override public ProjectImports load(final Path path) { try { final org.uberfire.java.nio.file.Path nioPath = Paths.convert(path); if (!ioService.exists(nioPath)) { saveProjectImports(path); } final String content = ioService.readAllString(Paths.convert(path)); final ProjectImports projectImports = projectConfigurationContentHandler.toModel(content); final Import javaLangNumber = new Import(Number.class); if (projectImports.getImports().getImports().stream().noneMatch(anImport -> Objects.equals(anImport, javaLangNumber))) { projectImports.getImports().addImport(javaLangNumber); } return projectImports; } catch (Exception e) { throw ExceptionUtilities.handleException(e); } } ProjectImportsServiceImpl(); @Inject  ProjectImportsServiceImpl(final @Named("ioStrategy") IOService ioService,
                                     final ProjectConfigurationContentHandler projectConfigurationContentHandler,
                                     final RenameService renameService,
                                     final SaveAndRenameServiceImpl<ProjectImports, Metadata> saveAndRenameService); @PostConstruct void init(); void saveProjectImports(final Path path); @Override ProjectImportsContent loadContent(Path path); @Override ProjectImports load(final Path path); @Override Path save(final Path resource,
                     final ProjectImports projectImports,
                     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 ProjectImports content,
                              final String comment); }
ProjectImportsServiceImpl extends KieService<ProjectImportsContent> implements ProjectImportsService { @Override public ProjectImports load(final Path path) { try { final org.uberfire.java.nio.file.Path nioPath = Paths.convert(path); if (!ioService.exists(nioPath)) { saveProjectImports(path); } final String content = ioService.readAllString(Paths.convert(path)); final ProjectImports projectImports = projectConfigurationContentHandler.toModel(content); final Import javaLangNumber = new Import(Number.class); if (projectImports.getImports().getImports().stream().noneMatch(anImport -> Objects.equals(anImport, javaLangNumber))) { projectImports.getImports().addImport(javaLangNumber); } return projectImports; } catch (Exception e) { throw ExceptionUtilities.handleException(e); } } ProjectImportsServiceImpl(); @Inject  ProjectImportsServiceImpl(final @Named("ioStrategy") IOService ioService,
                                     final ProjectConfigurationContentHandler projectConfigurationContentHandler,
                                     final RenameService renameService,
                                     final SaveAndRenameServiceImpl<ProjectImports, Metadata> saveAndRenameService); @PostConstruct void init(); void saveProjectImports(final Path path); @Override ProjectImportsContent loadContent(Path path); @Override ProjectImports load(final Path path); @Override Path save(final Path resource,
                     final ProjectImports projectImports,
                     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 ProjectImports content,
                              final String comment);  }