DomainBundlePackageBuilder implements PackageBuilder { @Override public void createPackage(Path originFolderPath, Path destinationPath) throws ArchiverException, IOException { checkArgument(originFolderPath != null, "The origin path must not be null"); checkArgument(originFolderPath.toFile().exists(), "The origin path must exist"); Path metaInfPath = originFolderPath.resolve(META_INF.value()); this.withDomain(originFolderPath.resolve(DOMAIN.value()).toFile()) .withApplications(originFolderPath.resolve(APPLICATIONS.value()).toFile()) .withMaven(metaInfPath.resolve(MAVEN.value()).toFile()); this.createArchive(destinationPath); }  DomainBundlePackageBuilder withMaven(File folder); DomainBundlePackageBuilder withDomain(File folder); DomainBundlePackageBuilder withApplications(File folder); DomainBundlePackageBuilder withArchiver(AbstractArchiver archiver); @Override void createPackage(Path originFolderPath, Path destinationPath); @Override void createPackage(Path destinationPath);  }
@Test public void createPackageNullOriginalFolderPath() throws IOException { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("The origin path must not be null"); builder.createPackage(null, destinationFile.toPath()); }
@Test public void createPackageNonExistentOriginalFolderPath() throws IOException { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("The origin path must exist"); File fileMock = mock(File.class); when(fileMock.exists()).thenReturn(false); builder.createPackage(new File("fake").toPath(), destinationFile.toPath()); }
@Test public void createPackageNullDestinationPath() throws IOException { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("The destination path must not be null"); builder.createPackage(fakeTargetFolder.getRoot().toPath(), null); }
@Test public void createPackageAlreadyExistentNullDestinationPath() throws IOException { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("The destination file must not be duplicated"); destinationFile.createNewFile(); builder.createPackage(fakeTargetFolder.getRoot().toPath(), destinationFile.toPath()); }
@Test public void createPackage() throws IOException { builder.createPackage(fakeTargetFolder.getRoot().toPath(), destinationFile.toPath()); Path targetPath = fakeTargetFolder.getRoot().toPath(); verify(archiverMock, times(1)).addDomain(targetPath.resolve(DOMAIN.value()).toFile(), null, null); verify(archiverMock, times(1)).addApplications(targetPath.resolve(APPLICATIONS.value()).toFile(), null, null); verify(archiverMock, times(1)).addMaven(targetPath.resolve(META_INF.value()).resolve(MAVEN.value()).toFile(), null, null); verify(archiverMock, times(1)).setDestFile(destinationFile); verify(archiverMock, times(1)).createArchive(); }