View Javadoc
1   package org.codehaus.plexus.archiver;
2   
3   import java.io.IOException;
4   import junit.framework.TestCase;
5   
6   public class AbstractArchiverTest extends TestCase
7   {
8   
9       private AbstractArchiver archiver;
10  
11      @Override
12      protected void setUp() throws Exception
13      {
14          super.setUp();
15          this.archiver = new AbstractArchiver()
16          {
17  
18              @Override
19              protected String getArchiveType()
20              {
21                  throw new UnsupportedOperationException();
22              }
23  
24              @Override
25              protected void execute() throws ArchiverException, IOException
26              {
27                  throw new UnsupportedOperationException();
28              }
29  
30              @Override
31              protected void close() throws IOException
32              {
33                  throw new UnsupportedOperationException();
34              }
35  
36          };
37      }
38  
39      public void testModesAndOverridesAreUnsetByDefault()
40      {
41          assertEquals( -1, archiver.getDefaultFileMode() );
42          assertEquals( -1, archiver.getOverrideFileMode() );
43  
44          assertEquals( Archiver.DEFAULT_DIR_MODE, archiver.getDefaultDirectoryMode() );
45          assertEquals( -1, archiver.getOverrideDirectoryMode() );
46      }
47  
48      public void testWhenUnsetModeUsesDefault()
49      {
50          assertEquals( Archiver.DEFAULT_FILE_MODE, archiver.getFileMode() );
51          assertEquals( Archiver.DEFAULT_DIR_MODE, archiver.getDirectoryMode() );
52      }
53  
54      public void testSetModeIsUsedWithFlagsForType()
55      {
56          archiver.setFileMode( 0400 );
57          assertEquals( 0100400, archiver.getFileMode() );
58  
59          archiver.setDirectoryMode( 0600 );
60          assertEquals( 040600, archiver.getDirectoryMode() );
61      }
62  
63      public void testSetDefaultIncludesFlagsForType()
64      {
65          archiver.setDefaultFileMode( 0400 );
66          assertEquals( 0100400, archiver.getDefaultFileMode() );
67  
68          archiver.setDefaultDirectoryMode( 0600 );
69          assertEquals( 040600, archiver.getDefaultDirectoryMode() );
70      }
71  
72      public void testDefaultIsUsedWhenModeIsUnset()
73      {
74          archiver.setDefaultFileMode( 0400 );
75          assertEquals( 0100400, archiver.getFileMode() );
76  
77          archiver.setDefaultDirectoryMode( 0600 );
78          assertEquals( 040600, archiver.getDirectoryMode() );
79      }
80  
81      public void testOverridesCanBeReset()
82      {
83          archiver.setFileMode( 0400 );
84          archiver.setFileMode( -1 );
85          assertEquals( -1, archiver.getOverrideFileMode() );
86  
87          archiver.setDirectoryMode( 0600 );
88          archiver.setDirectoryMode( -1 );
89          assertEquals( -1, archiver.getOverrideDirectoryMode() );
90      }
91  
92  }