@Test void testCopyPackage() { setupPredictableIdGeneratorMock(idGenerator); EntityType entityType1 = mock(EntityType.class); EntityType entityType2 = mock(EntityType.class); EntityType entityType3 = mock(EntityType.class); Package packageA = mock(Package.class); Package packageAa = mock(Package.class); Package packageAb = mock(Package.class); Package packageAba = mock(Package.class); Package packageC = mock(Package.class); when(packageA.getChildren()).thenReturn(asList(packageAa, packageAb)); when(packageAb.getChildren()).thenReturn(singletonList(packageAba)); when(packageAba.getEntityTypes()).thenReturn(asList(entityType1, entityType2)); when(packageC.getEntityTypes()).thenReturn(singletonList(entityType3)); when(packageA.getId()).thenReturn("A"); when(packageAa.getId()).thenReturn("Aa"); when(packageAb.getId()).thenReturn("Ab"); when(packageAba.getId()).thenReturn("Aba"); when(packageC.getId()).thenReturn("C"); when(packageA.getLabel()).thenReturn("labelA"); when(packageC.getLabel()).thenReturn("labelC"); Package targetPackage = mock(Package.class); when(dataService.getMeta()).thenReturn(metaDataService); setupMetadataServiceAnswers(asList(packageA, packageAa, packageAb, packageAba, packageC)); Progress progress = mock(Progress.class); CopyState state = CopyState.create(targetPackage, progress); copier.copy(asList(packageA, packageC), state); verify(packageA).setParent(targetPackage); verify(packageA).setId("id1"); verify(packageAa).setId("id2"); verify(packageAb).setId("id3"); verify(packageAba).setId("id4"); verify(packageC).setId("id5"); verify(dataService).add(PACKAGE, packageA); verify(dataService).add(PACKAGE, packageAa); verify(dataService).add(PACKAGE, packageAb); verify(dataService).add(PACKAGE, packageAba); verify(dataService).add(PACKAGE, packageC); verify(progress, times(5)).increment(1); assertEquals( of("A", packageA, "Aa", packageAa, "Ab", packageAb, "Aba", packageAba, "C", packageC), state.copiedPackages()); assertEquals(asList(entityType1, entityType2, entityType3), state.entityTypesInPackages()); }
private void copyPackage(Package pack, CopyState state) { validateNotContainsItself(pack, state.targetPackage()); assignUniqueLabel(pack, state.targetPackage()); copyPackageRecursive(pack, state.targetPackage(), state); }
PackageCopier { private void copyPackage(Package pack, CopyState state) { validateNotContainsItself(pack, state.targetPackage()); assignUniqueLabel(pack, state.targetPackage()); copyPackageRecursive(pack, state.targetPackage(), state); } }
PackageCopier { private void copyPackage(Package pack, CopyState state) { validateNotContainsItself(pack, state.targetPackage()); assignUniqueLabel(pack, state.targetPackage()); copyPackageRecursive(pack, state.targetPackage(), state); } PackageCopier(DataService dataService, IdGenerator idGenerator); }
PackageCopier { private void copyPackage(Package pack, CopyState state) { validateNotContainsItself(pack, state.targetPackage()); assignUniqueLabel(pack, state.targetPackage()); copyPackageRecursive(pack, state.targetPackage(), state); } PackageCopier(DataService dataService, IdGenerator idGenerator); void copy(List<Package> packages, CopyState state); }
PackageCopier { private void copyPackage(Package pack, CopyState state) { validateNotContainsItself(pack, state.targetPackage()); assignUniqueLabel(pack, state.targetPackage()); copyPackageRecursive(pack, state.targetPackage(), state); } PackageCopier(DataService dataService, IdGenerator idGenerator); void copy(List<Package> packages, CopyState state);  }