1 package org.apache.maven.shared.runtime;
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.net.URL;
25 import java.net.URLClassLoader;
26
27 import junit.framework.TestCase;
28
29 import org.easymock.EasyMock;
30 import org.easymock.IMocksControl;
31
32
33
34
35
36
37
38
39 public class MavenRuntimeVisitorUtilsTest extends TestCase
40 {
41
42
43 private IMocksControl mockVisitorControl;
44
45 private MavenRuntimeVisitor mockVisitor;
46
47
48
49
50
51
52 @Override
53 protected void setUp() throws Exception
54 {
55 mockVisitorControl = EasyMock.createStrictControl();
56 mockVisitor = mockVisitorControl.createMock( MavenRuntimeVisitor.class );
57
58 mockVisitorControl.replay();
59 }
60
61
62
63
64 @Override
65 protected void tearDown() throws Exception
66 {
67 mockVisitorControl.verify();
68 }
69
70
71
72 public void testWithEmptyJar() throws IOException, MavenRuntimeException
73 {
74 accept( createTempFile( "file", ".jar" ) );
75 }
76
77 public void testWithUnknownFileExtension() throws IOException, MavenRuntimeException
78 {
79 accept( createTempFile( "file", ".unknown" ) );
80 }
81
82
83
84 private URL createTempFile( String prefix, String suffix ) throws IOException
85 {
86 File file = File.createTempFile( prefix, suffix );
87 file.deleteOnExit();
88
89 return file.toURI().toURL();
90 }
91
92 private void accept( URL url ) throws MavenRuntimeException
93 {
94 accept( new URL[] { url } );
95 }
96
97 private void accept( URL[] urls ) throws MavenRuntimeException
98 {
99 ClassLoader classLoader = new URLClassLoader( urls, null );
100
101 MavenRuntimeVisitorUtils.accept( classLoader, mockVisitor );
102 }
103 }