1 package org.apache.maven.plugins.repository.testutil;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.Collections;
25 import java.util.HashSet;
26 import java.util.Set;
27 import java.util.zip.ZipFile;
28
29 import junit.framework.Assert;
30
31 public final class Assertions
32 {
33
34 public static final Set<String> EMPTY_ENTRY_NAMES = Collections.emptySet();
35
36 public static void assertZipContents( Iterable<String> requiredNames, Iterable<String> bannedNames, File bundleSource )
37 throws IOException
38 {
39 ZipFile zf = new ZipFile( bundleSource );
40
41 Set<String> missing = new HashSet<String>();
42 for ( String name : requiredNames )
43 {
44 if ( zf.getEntry( name ) == null )
45 {
46 missing.add( name );
47 }
48 }
49
50 Set<String> banned = new HashSet<String>();
51 for ( String name : bannedNames )
52 {
53 if ( zf.getEntry( name ) != null )
54 {
55 banned.add( name );
56 }
57 }
58
59 zf.close();
60 if ( !missing.isEmpty() || !banned.isEmpty() )
61 {
62 StringBuilder msg = new StringBuilder();
63 msg.append( "The following REQUIRED entries were missing from the bundle archive:\n" );
64
65 if ( missing.isEmpty() )
66 {
67 msg.append( "\nNone." );
68 }
69 else
70 {
71 for ( String name : missing )
72 {
73 msg.append( "\n" ).append( name );
74 }
75 }
76
77 msg.append( "\n\nThe following BANNED entries were present from the bundle archive:\n" );
78
79 if ( banned.isEmpty() )
80 {
81 msg.append( "\nNone.\n" );
82 }
83 else
84 {
85 for ( String name : banned )
86 {
87 msg.append( "\n" ).append( name );
88 }
89 }
90
91 Assert.fail( msg.toString() );
92 }
93 }
94 }