Skip to content

Commit 388bc98

Browse files
plamentotevmichael-o
authored andcommitted
Test that EmptyArchiveException is thrown when creating archives with no files
This closes #63
1 parent de38885 commit 388bc98

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/test/java/org/codehaus/plexus/archiver/tar/TarArchiverTest.java

+17
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.codehaus.plexus.archiver.ArchiverException;
3939
import org.codehaus.plexus.archiver.UnixStat;
4040
import org.codehaus.plexus.archiver.bzip2.BZip2Compressor;
41+
import org.codehaus.plexus.archiver.exceptions.EmptyArchiveException;
4142
import org.codehaus.plexus.archiver.gzip.GZipCompressor;
4243
import org.codehaus.plexus.archiver.util.ArchiveEntryUtils;
4344
import org.codehaus.plexus.archiver.util.Compressor;
@@ -227,6 +228,22 @@ public void testCreateArchiveWithDetectedModes()
227228
}
228229
}
229230

231+
public void testCreateEmptyArchive()
232+
throws Exception
233+
{
234+
TarArchiver archiver = getPosixTarArchiver();
235+
archiver.setDestFile( getTestFile( "target/output/empty.tar" ) );
236+
try
237+
{
238+
archiver.createArchive();
239+
240+
fail( "Creating empty archive should throw EmptyArchiveException" );
241+
}
242+
catch ( EmptyArchiveException ignore )
243+
{
244+
}
245+
}
246+
230247
public void testUnicode() throws Exception
231248
{
232249
File tmpDir = getTestFile( "src/test/resources/utf8" );

src/test/java/org/codehaus/plexus/archiver/zip/ZipArchiverTest.java

+17
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.codehaus.plexus.archiver.BasePlexusArchiverTest;
4949
import org.codehaus.plexus.archiver.UnArchiver;
5050
import org.codehaus.plexus.archiver.UnixStat;
51+
import org.codehaus.plexus.archiver.exceptions.EmptyArchiveException;
5152
import org.codehaus.plexus.archiver.tar.TarArchiver;
5253
import org.codehaus.plexus.archiver.tar.TarFile;
5354
import org.codehaus.plexus.archiver.util.ArchiveEntryUtils;
@@ -284,6 +285,22 @@ public void testCreateArchiveWithDetectedModes()
284285
}
285286
}
286287

288+
public void testCreateEmptyArchive()
289+
throws Exception
290+
{
291+
ZipArchiver archiver = getZipArchiver();
292+
archiver.setDestFile( getTestFile( "target/output/empty.zip" ) );
293+
try
294+
{
295+
archiver.createArchive();
296+
297+
fail( "Creating empty archive should throw EmptyArchiveException" );
298+
}
299+
catch ( EmptyArchiveException ignore )
300+
{
301+
}
302+
}
303+
287304
private ZipArchiver getZipArchiver()
288305
{
289306
try

0 commit comments

Comments
 (0)