1 package org.apache.maven.shared.jar;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.zip.ZipException;
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 public class JarAnalyzerTest
30 extends AbstractJarAnalyzerTestCase
31 {
32 private JarAnalyzer jarAnalyzer;
33
34
35 protected void tearDown()
36 throws Exception
37 {
38 super.tearDown();
39
40 if ( jarAnalyzer != null )
41 {
42 jarAnalyzer.closeQuietly();
43 }
44 }
45
46 private JarData getJarData( String filename )
47 throws Exception
48 {
49 jarAnalyzer = getJarAnalyzer( filename );
50 return jarAnalyzer.getJarData();
51 }
52
53 private JarAnalyzer getJarAnalyzer( String filename )
54 throws IOException
55 {
56 return new JarAnalyzer( getSampleJar( filename ) );
57 }
58
59 public void testSealed()
60 throws Exception
61 {
62 JarData jarData = getJarData( "evil-sealed-regex-1.0.jar" );
63 assertTrue( jarData.isSealed() );
64 }
65
66 public void testNotSealed()
67 throws Exception
68 {
69 JarData jarData = getJarData( "codec.jar" );
70 assertFalse( jarData.isSealed() );
71 }
72
73 public void testMissingFile()
74 throws Exception
75 {
76 try
77 {
78 jarAnalyzer = new JarAnalyzer( new File( "foo-bar-this-should-not-exist.jar" ) );
79 fail( "Should not have succeeded to get the missing JAR" );
80 }
81 catch ( IOException e )
82 {
83 assertTrue( true );
84 }
85 }
86
87 public void testInvalidJarFile()
88 throws Exception
89 {
90 try
91 {
92 getJarAnalyzer( "invalid.jar" );
93 fail( "Should not have succeeded to get the invalid JAR" );
94 }
95 catch ( ZipException e )
96 {
97 assertTrue( true );
98 }
99 }
100
101 public void testCloseTwice()
102 throws Exception
103 {
104 JarAnalyzer jarAnalyzer = getJarAnalyzer( "codec.jar" );
105
106
107 jarAnalyzer.closeQuietly();
108 jarAnalyzer.closeQuietly();
109 assertTrue( true );
110 }
111 }