ProjectConfigDtoMerger { public FactoryDto merge(FactoryDto factory, Supplier<ProjectConfigDto> configSupplier) { if (factory.getWorkspace() == null) { return factory; } final List<ProjectConfigDto> projects = factory.getWorkspace().getProjects(); if (projects == null || projects.isEmpty()) { factory.getWorkspace().setProjects(singletonList(configSupplier.get())); return factory; } if (projects.size() == 1) { ProjectConfigDto projectConfig = projects.get(0); if (projectConfig.getSource() == null) projectConfig.setSource(configSupplier.get().getSource()); } return factory; }  FactoryDto merge(FactoryDto factory, Supplier<ProjectConfigDto> configSupplier);  }
@Test public void mergeWithoutAnyProject() { Assert.assertTrue(factory.getWorkspace().getProjects().isEmpty()); projectConfigDtoMerger.merge(factory, () -> computedProjectConfig); assertEquals(factory.getWorkspace().getProjects().size(), 1); assertEquals(factory.getWorkspace().getProjects().get(0), computedProjectConfig); }
@Test public void mergeWithoutOneProjectWithoutSource() { ProjectConfigDto projectConfigDto = newDto(ProjectConfigDto.class); factory.getWorkspace().setProjects(Collections.singletonList(projectConfigDto)); Assert.assertNull(projectConfigDto.getSource()); projectConfigDtoMerger.merge(factory, () -> computedProjectConfig); assertEquals(factory.getWorkspace().getProjects().size(), 1); SourceStorageDto sourceStorageDto = factory.getWorkspace().getProjects().get(0).getSource(); assertEquals(sourceStorageDto.getLocation(), DUMMY_LOCATION); }