1 package org.apache.maven.shared.jar;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.AssertionFailedError;
23 import org.codehaus.plexus.PlexusTestCase;
24
25 import java.io.File;
26 import java.io.UnsupportedEncodingException;
27 import java.net.MalformedURLException;
28 import java.net.URLDecoder;
29 import java.util.ArrayList;
30 import java.util.Collection;
31 import java.util.Iterator;
32 import java.util.List;
33 import java.util.regex.Matcher;
34 import java.util.regex.Pattern;
35
36
37
38
39 public abstract class AbstractJarAnalyzerTestCase
40 extends PlexusTestCase
41 {
42 public File getSampleJar( String filename )
43 throws MalformedURLException, UnsupportedEncodingException
44 {
45 String path = getClass().getResource( "/jars/" + filename ).getPath();
46
47 return new File( URLDecoder.decode( path, "UTF-8" ) );
48 }
49
50 public void assertNotContainsRegex( String msg, String regex, Collection coll )
51 {
52 List failures = new ArrayList();
53 Pattern pat = Pattern.compile( regex );
54 Iterator it = coll.iterator();
55 while ( it.hasNext() )
56 {
57 String value = (String) it.next();
58 Matcher mat = pat.matcher( value );
59 if ( mat.find() )
60 {
61 failures.add( value );
62 }
63 }
64
65 if ( !failures.isEmpty() )
66 {
67 StringBuffer sb = new StringBuffer();
68 sb.append( msg ).append( " collection has illegal regex \"" ).append( regex ).append( "\"" );
69 it = failures.iterator();
70 while ( it.hasNext() )
71 {
72 sb.append( "\n - \"" ).append( it.next() ).append( "\"" );
73 }
74 throw new AssertionFailedError( sb.toString() );
75 }
76 }
77 }