Skip to content

Commit 38db335

Browse files
committed
Added misc unicode stuff for testing
1 parent e7a2864 commit 38db335

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

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

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ public void testCreateArchiveWithDetectedModes()
149149

150150
File zipFile = getTestFile( "target/output/zip-with-modes.zip" );
151151

152-
ZipArchiver archiver = (ZipArchiver) lookup( Archiver.ROLE, "zip" );
153-
archiver.setDestFile( zipFile );
152+
ZipArchiver archiver = getZipArchiver(zipFile);
154153

155154
archiver.addDirectory( tmpDir );
156155
archiver.createArchive();
@@ -159,7 +158,7 @@ public void testCreateArchiveWithDetectedModes()
159158

160159
File zipFile2 = getTestFile( "target/output/zip-with-modes-L2.zip" );
161160

162-
archiver = (ZipArchiver) lookup( Archiver.ROLE, "zip" );
161+
archiver = getZipArchiver();
163162
archiver.setDestFile( zipFile2 );
164163

165164
archiver.addArchivedFileSet( zipFile );
@@ -206,7 +205,26 @@ public void testCreateArchiveWithDetectedModes()
206205
}
207206
}
208207
}
209-
208+
209+
private ZipArchiver getZipArchiver()
210+
{
211+
try
212+
{
213+
return (ZipArchiver) lookup( Archiver.ROLE, "zip" );
214+
}
215+
catch ( Exception e )
216+
{
217+
throw new RuntimeException( e );
218+
}
219+
}
220+
221+
private ZipArchiver getZipArchiver(File destFile)
222+
{
223+
final ZipArchiver zipArchiver = getZipArchiver();
224+
zipArchiver.setDestFile( destFile );
225+
return zipArchiver;
226+
}
227+
210228
private void writeFile( File dir, String fname, int mode )
211229
throws IOException, ArchiverException
212230
{
@@ -240,7 +258,7 @@ public void testCreateArchive()
240258
}
241259

242260
private ZipArchiver newArchiver( String name ) throws Exception {
243-
ZipArchiver archiver = (ZipArchiver) lookup( Archiver.ROLE, "zip" );
261+
ZipArchiver archiver = getZipArchiver(getTestFile( "target/output/" + name ));
244262

245263
archiver.setFileMode( 0640 );
246264
archiver.addFile( getTestFile( "src/test/resources/manifests/manifest1.mf" ), "one.txt" );
@@ -258,8 +276,6 @@ private ZipArchiver newArchiver( String name ) throws Exception {
258276
archiver.setFileMode( 0400 );
259277
archiver.addDirectory( getTestFile( "src" ) );
260278

261-
archiver.setDestFile( getTestFile( "target/output/" + name ) );
262-
263279
return archiver;
264280
}
265281

@@ -397,8 +413,7 @@ public void notestJustThatOne()
397413
final File zipFile = new File( "target/output/zz1.zip" );
398414

399415
final File zipFile2 = new File( "target/output/zz2.zip" );
400-
ZipArchiver zipArchiver2 = (ZipArchiver) lookup( Archiver.ROLE, "zip" );
401-
zipArchiver2.setDestFile( zipFile2 );
416+
ZipArchiver zipArchiver2 = getZipArchiver(zipFile2);
402417

403418
// Bugbug: This does not work on 1.8....?
404419
zipArchiver2.addArchivedFileSet( zipFile );
@@ -411,16 +426,14 @@ public void testCreateResourceCollection()
411426
{
412427
final File srcDir = new File("src");
413428
final File zipFile = new File( "target/output/src.zip" );
414-
ZipArchiver zipArchiver = (ZipArchiver) lookup( Archiver.ROLE, "zip" );
415-
zipArchiver.setDestFile( zipFile );
429+
ZipArchiver zipArchiver = getZipArchiver(zipFile);
416430
zipArchiver.addDirectory( srcDir, null, FileUtils.getDefaultExcludes() );
417431
zipArchiver.setEncoding( "UTF-8" );
418432
FileUtils.removePath( zipFile.getPath() );
419433
zipArchiver.createArchive();
420434

421435
final File zipFile2 = new File( "target/output/src2.zip" );
422-
ZipArchiver zipArchiver2 = (ZipArchiver) lookup( Archiver.ROLE, "zip" );
423-
zipArchiver2.setDestFile( zipFile2 );
436+
ZipArchiver zipArchiver2 = getZipArchiver(zipFile2);
424437
zipArchiver2.addArchivedFileSet( zipFile, "prfx/" );
425438
zipArchiver2.setEncoding( "UTF-8" );
426439
FileUtils.removePath( zipFile2.getPath() );
@@ -432,4 +445,21 @@ public void testCreateResourceCollection()
432445
cmp1.close();
433446
cmp2.close();
434447
}
448+
449+
public void testDefaultUTF8()
450+
throws IOException
451+
{
452+
final ZipArchiver zipArchiver = getZipArchiver( new File( "target/output/utf8-default.zip" ) );
453+
zipArchiver.addDirectory( new File("src/test/resources/miscUtf8") );
454+
zipArchiver.createArchive();
455+
}
456+
457+
public void testDefaultUTF8withUTF8()
458+
throws IOException
459+
{
460+
final ZipArchiver zipArchiver = getZipArchiver( new File( "target/output/utf8-with_utf.zip" ) );
461+
zipArchiver.setEncoding( "UTF-8" );
462+
zipArchiver.addDirectory( new File("src/test/resources/miscUtf8") );
463+
zipArchiver.createArchive();
464+
}
435465
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
A file with a hash
2+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a party trick
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a file with an umlaut
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
You need €uros for that

0 commit comments

Comments
 (0)