Skip to content

Commit 867eee8

Browse files
committed
Added roundtrip testcase for zip files with UTF8
1 parent 803e956 commit 867eee8

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package org.codehaus.plexus.archiver.zip;
22

33
import java.io.File;
4+
import java.io.IOException;
45
import java.lang.reflect.Method;
56
import org.codehaus.plexus.PlexusTestCase;
7+
import org.codehaus.plexus.archiver.Archiver;
68
import org.codehaus.plexus.archiver.UnArchiver;
79
import org.codehaus.plexus.components.io.fileselectors.FileSelector;
810
import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector;
@@ -69,6 +71,25 @@ public void testZeroFileModeInZip()
6971
{
7072
}
7173
}
74+
75+
public void testUnarchiveUtf8()
76+
throws Exception
77+
{
78+
File dest = new File("target/output/unzip/utf8");
79+
dest.mkdirs();
80+
81+
final File zipFile = new File( "target/output/unzip/utf8-default.zip" );
82+
final ZipArchiver zipArchiver = getZipArchiver( zipFile );
83+
zipArchiver.addDirectory( new File( "src/test/resources/miscUtf8" ) );
84+
zipArchiver.createArchive();
85+
final ZipUnArchiver unarchiver = getZipUnArchiver(zipFile);
86+
unarchiver.setDestFile( dest );
87+
unarchiver.extract();
88+
assertTrue( new File( dest, "aPi\u00F1ata.txt" ).exists() );
89+
assertTrue( new File( dest, "an\u00FCmlaut.txt").exists());
90+
assertTrue( new File( dest, "\u20acuro.txt").exists());
91+
}
92+
7293
private void runUnarchiver( String path, FileSelector[] selectors, boolean[] results )
7394
throws Exception
7495
{
@@ -124,4 +145,36 @@ public void testSelectors()
124145
fileSelector.setExcludes( new String[]{ "resources/artifactId/directory/test.properties" } );
125146
runUnarchiver( "", new FileSelector[]{ fileSelector }, new boolean[]{ true, false, false } );
126147
}
148+
149+
private ZipArchiver getZipArchiver()
150+
{
151+
try
152+
{
153+
return (ZipArchiver) lookup( Archiver.ROLE, "zip" );
154+
}
155+
catch ( Exception e )
156+
{
157+
throw new RuntimeException( e );
158+
}
159+
}
160+
161+
private ZipArchiver getZipUnArchiver()
162+
{
163+
try
164+
{
165+
return (ZipArchiver) lookup( UnArchiver.ROLE, "zip" );
166+
}
167+
catch ( Exception e )
168+
{
169+
throw new RuntimeException( e );
170+
}
171+
}
172+
173+
private ZipArchiver getZipArchiver( File destFile )
174+
{
175+
final ZipArchiver zipArchiver = getZipArchiver();
176+
zipArchiver.setDestFile( destFile );
177+
return zipArchiver;
178+
}
179+
127180
}

0 commit comments

Comments
 (0)