View Javadoc
1   package org.apache.maven.plugins.assembly.utils;
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 junit.framework.TestCase;
23  import org.apache.maven.plugins.assembly.archive.ArchiveExpansionException;
24  import org.apache.maven.plugins.assembly.testutils.TestFileManager;
25  import org.codehaus.plexus.archiver.ArchiverException;
26  import org.codehaus.plexus.archiver.UnArchiver;
27  import org.codehaus.plexus.archiver.manager.ArchiverManager;
28  import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
29  import org.easymock.classextension.EasyMockSupport;
30  
31  import java.io.File;
32  import java.io.IOException;
33  
34  import static org.easymock.EasyMock.expect;
35  
36  public class AssemblyFileUtilsTest
37      extends TestCase
38  {
39  
40      private final TestFileManager fileManager = new TestFileManager( "file-utils.test.", "" );
41  
42      public void tearDown()
43          throws IOException
44      {
45          fileManager.cleanUp();
46      }
47  
48      public void testUnpack_ShouldSetSourceAndDestinationAndCallExtract()
49          throws IOException, ArchiveExpansionException, NoSuchArchiverException
50      {
51          EasyMockSupport mockManager = new EasyMockSupport();
52  
53          File source = fileManager.createTempFile();
54          File destDir = fileManager.createTempDir();
55  
56          UnArchiver unarchiver = mockManager.createMock( UnArchiver.class );
57  
58          ArchiverManager archiverManager = mockManager.createMock( ArchiverManager.class );
59  
60          try
61          {
62              expect( archiverManager.getUnArchiver( source ) ).andReturn( unarchiver );
63          }
64          catch ( NoSuchArchiverException e )
65          {
66              fail( "Should never happen." );
67          }
68  
69          unarchiver.setSourceFile( source );
70          unarchiver.setDestDirectory( destDir );
71  
72          try
73          {
74              unarchiver.extract();
75          }
76          catch ( ArchiverException e )
77          {
78              fail( "Should never happen." );
79          }
80  
81          mockManager.replayAll();
82  
83          AssemblyFileUtils.unpack( source, destDir, archiverManager );
84  
85          mockManager.verifyAll();
86      }
87  
88  }