@Test void testCopyFailed() { ResourceCollection collection = mock(ResourceCollection.class); when(collection.getPackages()).thenReturn(singletonList(mock(Package.class))); when(resourceCollector.get(any())).thenReturn(collection); doThrow(new RecursiveCopyException()).when(packageCopier).copy(any(), any()); Exception exception = assertThrows( CopyFailedException.class, () -> copyService.copy(emptyList(), null, mock(Progress.class))); assertThat(exception.getMessage()) .containsPattern("The target package is a subpackage of the package being copied"); }
@Override @SuppressWarnings( "java:S1193") @Transactional(isolation = Isolation.SERIALIZABLE) public Void copy( List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetPackageId, Progress progress) { try { ResourceCollection resourceCollection = resourceCollector.get(resources); Package targetPackage = getPackage(targetPackageId); CopyState state = CopyState.create(targetPackage, progress); copyResources(resourceCollection, state); } catch (RuntimeException e) { if (e instanceof ErrorCoded) { throw e; } else { throw new UnknownCopyFailedException(e); } } return null; }
CopyServiceImpl implements CopyService { @Override @SuppressWarnings( "java:S1193") @Transactional(isolation = Isolation.SERIALIZABLE) public Void copy( List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetPackageId, Progress progress) { try { ResourceCollection resourceCollection = resourceCollector.get(resources); Package targetPackage = getPackage(targetPackageId); CopyState state = CopyState.create(targetPackage, progress); copyResources(resourceCollection, state); } catch (RuntimeException e) { if (e instanceof ErrorCoded) { throw e; } else { throw new UnknownCopyFailedException(e); } } return null; } }
CopyServiceImpl implements CopyService { @Override @SuppressWarnings( "java:S1193") @Transactional(isolation = Isolation.SERIALIZABLE) public Void copy( List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetPackageId, Progress progress) { try { ResourceCollection resourceCollection = resourceCollector.get(resources); Package targetPackage = getPackage(targetPackageId); CopyState state = CopyState.create(targetPackage, progress); copyResources(resourceCollection, state); } catch (RuntimeException e) { if (e instanceof ErrorCoded) { throw e; } else { throw new UnknownCopyFailedException(e); } } return null; } CopyServiceImpl(
      ResourceCollector resourceCollector,
      MetaDataService metadataService,
      PackageCopier packageCopier,
      EntityTypeCopier entityTypeCopier,
      ContextMessageSource contextMessageSource); }
CopyServiceImpl implements CopyService { @Override @SuppressWarnings( "java:S1193") @Transactional(isolation = Isolation.SERIALIZABLE) public Void copy( List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetPackageId, Progress progress) { try { ResourceCollection resourceCollection = resourceCollector.get(resources); Package targetPackage = getPackage(targetPackageId); CopyState state = CopyState.create(targetPackage, progress); copyResources(resourceCollection, state); } catch (RuntimeException e) { if (e instanceof ErrorCoded) { throw e; } else { throw new UnknownCopyFailedException(e); } } return null; } CopyServiceImpl(
      ResourceCollector resourceCollector,
      MetaDataService metadataService,
      PackageCopier packageCopier,
      EntityTypeCopier entityTypeCopier,
      ContextMessageSource contextMessageSource); @Override @SuppressWarnings( "java:S1193") // Exception types should not be tested using "instanceof" in catch blocks @Transactional(isolation = Isolation.SERIALIZABLE) Void copy(
      List<ResourceIdentifier> resources,
      @Nullable @CheckForNull String targetPackageId,
      Progress progress); }
CopyServiceImpl implements CopyService { @Override @SuppressWarnings( "java:S1193") @Transactional(isolation = Isolation.SERIALIZABLE) public Void copy( List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetPackageId, Progress progress) { try { ResourceCollection resourceCollection = resourceCollector.get(resources); Package targetPackage = getPackage(targetPackageId); CopyState state = CopyState.create(targetPackage, progress); copyResources(resourceCollection, state); } catch (RuntimeException e) { if (e instanceof ErrorCoded) { throw e; } else { throw new UnknownCopyFailedException(e); } } return null; } CopyServiceImpl(
      ResourceCollector resourceCollector,
      MetaDataService metadataService,
      PackageCopier packageCopier,
      EntityTypeCopier entityTypeCopier,
      ContextMessageSource contextMessageSource); @Override @SuppressWarnings( "java:S1193") // Exception types should not be tested using "instanceof" in catch blocks @Transactional(isolation = Isolation.SERIALIZABLE) Void copy(
      List<ResourceIdentifier> resources,
      @Nullable @CheckForNull String targetPackageId,
      Progress progress);  }