View Javadoc

1   package org.apache.maven.shared.runtime;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * Tests {@code MavenRuntimeVisitorUtils}.
34   * 
35   * @author <a href="mailto:markh@apache.org">Mark Hobson</a>
36   * @version $Id: MavenRuntimeVisitorUtilsTest.java 831910 2009-11-02 15:05:33Z markh $
37   * @see MavenRuntimeVisitorUtils
38   */
39  public class MavenRuntimeVisitorUtilsTest extends TestCase
40  {
41      // fields -----------------------------------------------------------------
42  
43      private IMocksControl mockVisitorControl;
44  
45      private MavenRuntimeVisitor mockVisitor;
46  
47      // TestCase methods -------------------------------------------------------
48  
49      /**
50       * {@inheritDoc}
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       * {@inheritDoc}
63       */
64      @Override
65      protected void tearDown() throws Exception
66      {
67          mockVisitorControl.verify();
68      }
69  
70      // tests ------------------------------------------------------------------
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      // private methods -------------------------------------------------------
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 }