You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by st...@apache.org on 2011/08/07 08:28:09 UTC

svn commit: r1154662 - /maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExpandTest.java

Author: struberg
Date: Sun Aug  7 06:28:09 2011
New Revision: 1154662

URL: http://svn.apache.org/viewvc?rev=1154662&view=rev
Log:
MSANDBOX-51 Expand TCK finished

Modified:
    maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExpandTest.java

Modified: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExpandTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExpandTest.java?rev=1154662&r1=1154661&r2=1154662&view=diff
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExpandTest.java (original)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExpandTest.java Sun Aug  7 06:28:09 2011
@@ -202,7 +202,7 @@ public class ExpandTest extends Assert
 
             expand.execute();
 
-            verifyExpandedFileAndContent( targetDir, TEST_UNZIPPED_CONTENT );
+            verifyExpandedFileAndContent(targetDir, TEST_UNZIPPED_CONTENT);
         }
         finally
         {
@@ -210,6 +210,105 @@ public class ExpandTest extends Assert
         }
     }
 
+    @Test
+    public void testExecute_Overwrite() throws Exception
+    {
+        File targetDir = getTestTargetDir();
+        File expandedFile = null;
+
+        {
+            // part1: expand
+
+            Expand expand = new Expand();
+
+            File source = getSourceFile();
+            expand.setSrc( source );
+
+            expand.setDest( targetDir );
+
+            expand.execute();
+
+            expandedFile = verifyExpandedFileAndContent(targetDir, TEST_UNZIPPED_CONTENT);
+        }
+
+        // turn the clock back 10 seconds
+        long time = System.currentTimeMillis() - 10000L;
+
+        // round down to 1s;
+        time = time - time % 1000L;
+
+        expandedFile.setLastModified( time );
+        assertEquals( time, expandedFile.lastModified() );
+
+        {
+            // part2: expand in non-overwrite mode
+
+            Expand expand = new Expand();
+
+            File source = getSourceFile();
+            expand.setSrc( source );
+            expand.setDest( targetDir );
+
+            expand.setOverwrite( false );
+
+            expand.execute();
+
+            expandedFile = verifyExpandedFileAndContent(targetDir, TEST_UNZIPPED_CONTENT);
+
+            assertEquals( "file must still have the old lastModified timestamp"
+                        , time, expandedFile.lastModified() );
+
+        }
+
+        {
+            // part3: expand in overwrite mode but local file is still newer than the one in the archive
+
+            Expand expand = new Expand();
+
+            File source = getSourceFile();
+            expand.setSrc( source );
+            expand.setDest( targetDir );
+
+            expand.setOverwrite( true );
+
+            expand.execute();
+
+            expandedFile = verifyExpandedFileAndContent(targetDir, TEST_UNZIPPED_CONTENT);
+
+            // obviously the file will be overwritten anyway
+            assertTrue( "file must now have newer lastModified timestamp, but was: time=" + time
+                        + " expandedFile.lastModified()= " + expandedFile.lastModified()
+                        , time > expandedFile.lastModified() );
+        }
+
+        // turn the clock back a loooong time!
+        time = 100000000L;
+
+        expandedFile.setLastModified(time);
+        assertEquals(time, expandedFile.lastModified());
+
+        {
+            // part3: expand in overwrite mode but local file is now older than the one in the archive
+
+            Expand expand = new Expand();
+
+            File source = getSourceFile();
+            expand.setSrc( source );
+            expand.setDest( targetDir );
+
+            expand.setOverwrite( true );
+
+            expand.execute();
+
+            expandedFile = verifyExpandedFileAndContent(targetDir, TEST_UNZIPPED_CONTENT);
+
+            assertTrue( "file must now have newer lastModified timestamp, but was: time=" + time
+                        + " expandedFile.lastModified()= " + expandedFile.lastModified()
+                        , time < expandedFile.lastModified() );
+
+        }
+    }
+
 
     private File verifyExpandedFile( File targetDir )
     {