Author: brianf
Date: Mon Jan  1 19:52:04 2007
New Revision: 491740

URL: http://svn.apache.org/viewvc?view=rev&rev=491740
Log:
completed unpack/copy unit tests

Modified:
    
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractFromDependenciesMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolveDependencySourcesMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/DependencyTestUtils.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestDefaultMarkerFileHandler.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestSourcesMarkerFileHandler.java

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java?view=diff&rev=491740&r1=491739&r2=491740
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java
 Mon Jan  1 19:52:04 2007
@@ -176,7 +176,7 @@
      * @throws MojoExecutionException
      *             if an error occured.
      */
-    protected Set getDependencies( boolean stopOnFailure )
+    protected Set getResolvedDependencies( boolean stopOnFailure )
         throws MojoExecutionException
     {
         DependencyStatusSets status = getDependencySets( stopOnFailure );
@@ -268,6 +268,22 @@
         skippedArtifacts.removeAll( unMarkedArtifacts );
 
         return new DependencyStatusSets( unMarkedArtifacts, null, 
skippedArtifacts );
+    }
+
+    /**
+     * @return Returns the markersDirectory.
+     */
+    public File getMarkersDirectory()
+    {
+        return this.markersDirectory;
+    }
+
+    /**
+     * @param theMarkersDirectory The markersDirectory to set.
+     */
+    public void setMarkersDirectory( File theMarkersDirectory )
+    {
+        this.markersDirectory = theMarkersDirectory;
     }
 
     // TODO: Set marker files.

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractFromDependenciesMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractFromDependenciesMojo.java?view=diff&rev=491740&r1=491739&r2=491740
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractFromDependenciesMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractFromDependenciesMojo.java
 Mon Jan  1 19:52:04 2007
@@ -63,4 +63,52 @@
      */
     protected boolean useSubDirectoryPerArtifact;
 
+    /**
+     * @return Returns the outputDirectory.
+     */
+    public File getOutputDirectory()
+    {
+        return this.outputDirectory;
+    }
+
+    /**
+     * @param theOutputDirectory The outputDirectory to set.
+     */
+    public void setOutputDirectory( File theOutputDirectory )
+    {
+        this.outputDirectory = theOutputDirectory;
+    }
+
+    /**
+     * @return Returns the useSubDirectoryPerArtifact.
+     */
+    public boolean isUseSubDirectoryPerArtifact()
+    {
+        return this.useSubDirectoryPerArtifact;
+    }
+
+    /**
+     * @param theUseSubDirectoryPerArtifact The useSubDirectoryPerArtifact to 
set.
+     */
+    public void setUseSubDirectoryPerArtifact( boolean 
theUseSubDirectoryPerArtifact )
+    {
+        this.useSubDirectoryPerArtifact = theUseSubDirectoryPerArtifact;
+    }
+
+    /**
+     * @return Returns the useSubDirectoryPerType.
+     */
+    public boolean isUseSubDirectoryPerType()
+    {
+        return this.useSubDirectoryPerType;
+    }
+
+    /**
+     * @param theUseSubDirectoryPerType The useSubDirectoryPerType to set.
+     */
+    public void setUseSubDirectoryPerType( boolean theUseSubDirectoryPerType )
+    {
+        this.useSubDirectoryPerType = theUseSubDirectoryPerType;
+    }
+
 }

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolveDependencySourcesMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolveDependencySourcesMojo.java?view=diff&rev=491740&r1=491739&r2=491740
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolveDependencySourcesMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolveDependencySourcesMojo.java
 Mon Jan  1 19:52:04 2007
@@ -1,5 +1,4 @@
 package org.apache.maven.plugin.dependency.resolvers;
-
 /* 
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java?view=diff&rev=491740&r1=491739&r2=491740
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java
 Mon Jan  1 19:52:04 2007
@@ -655,7 +655,7 @@
     public void testGetDependencies()
         throws MojoExecutionException
     {
-        assertEquals( mojo.getDependencies( true ).toString(), 
mojo.getDependencySets( true ).getResolvedDependencies()
+        assertEquals( mojo.getResolvedDependencies( true ).toString(), 
mojo.getDependencySets( true ).getResolvedDependencies()
             .toString() );
     }
 }

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java?view=diff&rev=491740&r1=491739&r2=491740
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java
 Mon Jan  1 19:52:04 2007
@@ -1,4 +1,5 @@
 package org.apache.maven.plugin.dependency;
+
 /* 
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -19,6 +20,7 @@
  */
 
 import java.io.File;
+import java.io.IOException;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
@@ -26,6 +28,7 @@
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.dependency.testUtils.ArtifactStubFactory;
 import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
 import 
org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactRepository;
 import org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactResolver;
@@ -38,6 +41,10 @@
     extends AbstractDependencyMojoTestCase
 {
 
+    private final String UNPACKABLE_FILE = "test.txt";
+
+    private final String UNPACKABLE_FILE_PATH = 
"target/test-classes/unit/unpack-dependencies-test/" + UNPACKABLE_FILE;
+
     UnpackDependenciesMojo mojo;
 
     protected void setUp()
@@ -55,8 +62,7 @@
         stubFactory.setUnpackableFile( mojo.getArchiverManager() );
         // i'm using one file repeatedly to archive so I can test the name
         // programmatically.
-        stubFactory.setSrcFile( new File( getBasedir() + File.separatorChar
-            + "target/test-classes/unit/unpack-dependencies-test/test.txt" ) );
+        stubFactory.setSrcFile( new File( getBasedir() + File.separatorChar + 
UNPACKABLE_FILE_PATH ) );
 
         assertNotNull( mojo );
         assertNotNull( mojo.getProject() );
@@ -380,115 +386,176 @@
         {
         }
     }
-    /*
-     * public void testDontOverWriteRelease() throws MojoExecutionException,
-     * InterruptedException, IOException {
-     * 
-     * Set artifacts = new HashSet(); Artifact release =
-     * stubFactory.getReleaseArtifact(); release.getFile().setLastModified(
-     * System.currentTimeMillis() - 2000 );
-     * 
-     * artifacts.add( release );
-     * 
-     * mojo.project.setArtifacts( artifacts );
-     * mojo.project.setDependencyArtifacts( artifacts );
-     * 
-     * mojo.overWriteIfNewer = false;
-     * 
-     * mojo.execute();
-     * 
-     * File copiedFile = new File( mojo.outputDirectory,
-     * DependencyUtil.getFormattedFileName( release, false ) );
-     * 
-     * Thread.sleep( 100 ); long time = System.currentTimeMillis();
-     * copiedFile.setLastModified( time ); Thread.sleep( 100 );
-     * 
-     * mojo.execute();
-     * 
-     * assertEquals( time, copiedFile.lastModified() ); }
-     * 
-     * public void testOverWriteRelease() throws MojoExecutionException,
-     * InterruptedException, IOException {
-     * 
-     * Set artifacts = new HashSet(); Artifact release =
-     * stubFactory.getReleaseArtifact(); release.getFile().setLastModified(
-     * System.currentTimeMillis() - 2000 );
-     * 
-     * artifacts.add( release );
-     * 
-     * mojo.project.setArtifacts( artifacts );
-     * mojo.project.setDependencyArtifacts( artifacts );
-     * 
-     * mojo.overWriteReleases = true; mojo.overWriteIfNewer = false;
-     * 
-     * mojo.execute();
-     * 
-     * File copiedFile = new File( mojo.outputDirectory,
-     * DependencyUtil.getFormattedFileName( release, false ) );
-     * 
-     * Thread.sleep( 100 ); long time = System.currentTimeMillis();
-     * copiedFile.setLastModified( time ); Thread.sleep( 100 );
-     * 
-     * mojo.execute();
-     * 
-     * assertTrue( time < copiedFile.lastModified() ); }
-     * 
-     * public void testDontOverWriteSnap() throws MojoExecutionException,
-     * InterruptedException, IOException {
-     * 
-     * Set artifacts = new HashSet(); Artifact snap =
-     * stubFactory.getSnapshotArtifact(); snap.getFile().setLastModified(
-     * System.currentTimeMillis() - 2000 );
-     * 
-     * artifacts.add( snap );
-     * 
-     * mojo.project.setArtifacts( artifacts );
-     * mojo.project.setDependencyArtifacts( artifacts );
-     * 
-     * mojo.overWriteReleases = false; mojo.overWriteSnapshots = false;
-     * mojo.overWriteIfNewer = false;
-     * 
-     * mojo.execute();
-     * 
-     * File copiedFile = new File( mojo.outputDirectory,
-     * DependencyUtil.getFormattedFileName( snap, false ) );
-     * 
-     * Thread.sleep( 100 ); long time = System.currentTimeMillis();
-     * copiedFile.setLastModified( time ); Thread.sleep( 100 );
-     * 
-     * mojo.execute();
-     * 
-     * assertEquals( time, copiedFile.lastModified() ); }
-     * 
-     * public void testOverWriteSnap() throws MojoExecutionException,
-     * InterruptedException, IOException {
-     * 
-     * Set artifacts = new HashSet(); Artifact snap =
-     * stubFactory.getSnapshotArtifact(); snap.getFile().setLastModified(
-     * System.currentTimeMillis() - 2000 );
-     * 
-     * artifacts.add( snap );
-     * 
-     * mojo.project.setArtifacts( artifacts );
-     * mojo.project.setDependencyArtifacts( artifacts );
-     * 
-     * mojo.overWriteReleases = false; mojo.overWriteSnapshots = true;
-     * mojo.overWriteIfNewer = false;
-     * 
-     * mojo.execute();
-     * 
-     * File copiedFile = new File( mojo.outputDirectory,
-     * DependencyUtil.getFormattedFileName( snap, false ) );
-     * 
-     * Thread.sleep( 100 ); long time = System.currentTimeMillis();
-     * copiedFile.setLastModified( time ); Thread.sleep( 100 );
-     * 
-     * mojo.execute();
-     * 
-     * assertTrue( time < copiedFile.lastModified() ); }
-     * 
-     * public void testGetDependencies() throws MojoExecutionException {
-     * assertSame( mojo.getDependencies( true ), mojo.getDependencySets( true
-     * ).getResolvedDependencies() ); }
-     */
+
+    public File getUnpackedFile( Artifact artifact )
+    {
+        File destDir = DependencyUtil.getFormattedOutputDirectory( 
mojo.isUseSubDirectoryPerType(), mojo
+            .isUseSubDirectoryPerArtifact(), mojo.getOutputDirectory(), 
artifact );
+        File unpacked = new File( destDir, 
ArtifactStubFactory.getUnpackableFileName( artifact ) );
+        assertTrue( unpacked.exists() );
+        return unpacked;
+    }
+
+    public DefaultFileMarkerHandler getUnpackedMarkerHandler( Artifact 
artifact )
+    {
+        return new DefaultFileMarkerHandler( artifact, 
mojo.getMarkersDirectory() );
+    }
+
+    public void testDontOverWriteRelease()
+        throws MojoExecutionException, InterruptedException, IOException
+    {
+
+        Set artifacts = new HashSet();
+        Artifact release = stubFactory.getReleaseArtifact();
+        release.getFile().setLastModified( System.currentTimeMillis() - 2000 );
+
+        artifacts.add( release );
+
+        mojo.project.setArtifacts( artifacts );
+        mojo.project.setDependencyArtifacts( artifacts );
+
+        mojo.overWriteIfNewer = false;
+
+        mojo.execute();
+
+        assertUnpacked( release, false );
+    }
+
+    public void testOverWriteRelease()
+        throws MojoExecutionException, InterruptedException, IOException
+    {
+
+        Set artifacts = new HashSet();
+        Artifact release = stubFactory.getReleaseArtifact();
+        release.getFile().setLastModified( System.currentTimeMillis() - 2000 );
+
+        artifacts.add( release );
+
+        mojo.project.setArtifacts( artifacts );
+        mojo.project.setDependencyArtifacts( artifacts );
+
+        mojo.overWriteReleases = true;
+        mojo.overWriteIfNewer = false;
+
+        mojo.execute();
+
+        assertUnpacked( release, true );
+    }
+
+    public void testDontOverWriteSnap()
+        throws MojoExecutionException, InterruptedException, IOException
+    {
+
+        Set artifacts = new HashSet();
+        Artifact snap = stubFactory.getSnapshotArtifact();
+        snap.getFile().setLastModified( System.currentTimeMillis() - 2000 );
+
+        artifacts.add( snap );
+
+        mojo.project.setArtifacts( artifacts );
+        mojo.project.setDependencyArtifacts( artifacts );
+
+        mojo.overWriteReleases = false;
+        mojo.overWriteSnapshots = false;
+        mojo.overWriteIfNewer = false;
+
+        mojo.execute();
+
+        assertUnpacked( snap, false );
+    }
+
+    public void testOverWriteSnap()
+        throws MojoExecutionException, InterruptedException, IOException
+    {
+
+        Set artifacts = new HashSet();
+        Artifact snap = stubFactory.getSnapshotArtifact();
+        snap.getFile().setLastModified( System.currentTimeMillis() - 2000 );
+
+        artifacts.add( snap );
+
+        mojo.project.setArtifacts( artifacts );
+        mojo.project.setDependencyArtifacts( artifacts );
+
+        mojo.overWriteReleases = false;
+        mojo.overWriteSnapshots = true;
+        mojo.overWriteIfNewer = false;
+
+        mojo.execute();
+
+        assertUnpacked( snap, true );
+
+    }
+
+    public void testOverWriteIfNewer()
+        throws MojoExecutionException, InterruptedException, IOException
+    {
+
+        Set artifacts = new HashSet();
+        Artifact snap = stubFactory.getSnapshotArtifact();
+        snap.getFile().setLastModified( System.currentTimeMillis() - 2000 );
+
+        artifacts.add( snap );
+
+        mojo.project.setArtifacts( artifacts );
+        mojo.project.setDependencyArtifacts( artifacts );
+
+        mojo.overWriteReleases = false;
+        mojo.overWriteSnapshots = false;
+        mojo.overWriteIfNewer = false;
+
+        mojo.execute();
+
+        File unpackedFile = getUnpackedFile( snap );
+
+        Thread.sleep( 100 );
+        // round down to the last second
+        long time = System.currentTimeMillis();
+        time = time - ( time % 1000 );
+        // set source to be newer and dest to be a known value.
+        snap.getFile().setLastModified( time + 3000 );
+        unpackedFile.setLastModified( time );
+        // wait at least a second for filesystems that only record to the
+        // nearest second.
+        Thread.sleep( 1000 );
+
+        assertEquals( time, unpackedFile.lastModified() );
+        mojo.execute();
+
+        // make sure it didn't overwrite
+        assertEquals( time, unpackedFile.lastModified() );
+
+        mojo.overWriteIfNewer = true;
+
+        mojo.execute();
+
+        assertTrue( time != unpackedFile.lastModified() );
+    }
+
+    public void assertUnpacked( Artifact artifact, boolean overWrite )
+        throws InterruptedException, MojoExecutionException
+    {
+        File unpackedFile = getUnpackedFile( artifact );
+
+        Thread.sleep( 100 );
+        // round down to the last second
+        long time = System.currentTimeMillis();
+        time = time - ( time % 1000 );
+        unpackedFile.setLastModified( time );
+        // wait at least a second for filesystems that only record to the
+        // nearest second.
+        Thread.sleep( 1000 );
+
+        assertEquals( time, unpackedFile.lastModified() );
+        mojo.execute();
+
+        if ( overWrite )
+        {
+            assertTrue( time != unpackedFile.lastModified() );
+        }
+        else
+        {
+            assertEquals( time, unpackedFile.lastModified() );
+        }
+    }
 }

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java?view=diff&rev=491740&r1=491739&r2=491740
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
 Mon Jan  1 19:52:04 2007
@@ -30,6 +30,7 @@
 import org.apache.maven.model.Dependency;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase;
+import org.apache.maven.plugin.dependency.testUtils.ArtifactStubFactory;
 import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
 import 
org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactRepository;
 import org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactResolver;
@@ -140,7 +141,7 @@
         assertMarkerFiles( list, true );
     }
 
-    public void testCopyToLocation()
+    public void testUnpackToLocation()
         throws IOException, MojoExecutionException
     {
         ArrayList list = stubFactory.getArtifactItems( 
stubFactory.getClassifiedArtifacts() );
@@ -397,8 +398,8 @@
         }
 
     }
-/*
-    public void testCopyDontOverWriteReleases()
+
+    public void testUnpackDontOverWriteReleases()
         throws IOException, MojoExecutionException, InterruptedException
     {
         stubFactory.setCreateFiles( true );
@@ -415,21 +416,10 @@
 
         mojo.execute();
 
-        File copiedFile = new File( item.getOutputDirectory(), 
item.getDestFileName() );
-
-        Thread.sleep( 100 );
-        // round up to the next second
-        long time = System.currentTimeMillis() + 1000;
-        time = time - ( time % 1000 );
-        copiedFile.setLastModified( time );
-        Thread.sleep( 100 );
-
-        mojo.execute();
-
-        assertEquals( time, copiedFile.lastModified() );
+        assertUnpacked( item, false );
     }
 
-    public void testCopyDontOverWriteSnapshots()
+    public void testUnpackDontOverWriteSnapshots()
         throws IOException, MojoExecutionException, InterruptedException
     {
         stubFactory.setCreateFiles( true );
@@ -446,21 +436,10 @@
 
         mojo.execute();
 
-        File copiedFile = new File( item.getOutputDirectory(), 
item.getDestFileName() );
-
-        Thread.sleep( 100 );
-        // round up to the next second
-        long time = System.currentTimeMillis() + 1000;
-        time = time - ( time % 1000 );
-        copiedFile.setLastModified( time );
-        Thread.sleep( 100 );
-
-        mojo.execute();
-
-        assertEquals( time, copiedFile.lastModified() );
+        assertUnpacked( item, false );
     }
 
-    public void testCopyOverWriteReleases()
+    public void testUnpackOverWriteReleases()
         throws IOException, MojoExecutionException, InterruptedException
     {
         stubFactory.setCreateFiles( true );
@@ -477,18 +456,10 @@
         mojo.setOverWriteReleases( true );
         mojo.execute();
 
-        File copiedFile = new File( item.getOutputDirectory(), 
item.getDestFileName() );
-
-        // round up to the next second
-        long time = System.currentTimeMillis() - 2000;
-        copiedFile.setLastModified( time );
-
-        mojo.execute();
-
-        assertTrue( time < copiedFile.lastModified() );
+        assertUnpacked( item, true );
     }
 
-    public void testCopyOverWriteSnapshot()
+    public void testUnpackOverWriteSnapshot()
         throws IOException, MojoExecutionException, InterruptedException
     {
         stubFactory.setCreateFiles( true );
@@ -506,18 +477,10 @@
         mojo.setOverWriteSnapshots( true );
         mojo.execute();
 
-        File copiedFile = new File( item.getOutputDirectory(), 
item.getDestFileName() );
-
-        // round up to the next second
-        long time = System.currentTimeMillis() - 2000;
-        copiedFile.setLastModified( time );
-
-        mojo.execute();
-
-        assertTrue( time < copiedFile.lastModified() );
+        assertUnpacked( item, true );
     }
 
-    public void testCopyOverWriteIfNewer()
+    public void testUnpackOverWriteIfNewer()
         throws IOException, MojoExecutionException, InterruptedException
     {
         stubFactory.setCreateFiles( true );
@@ -532,20 +495,56 @@
         mojo.setOverWriteIfNewer( true );
         mojo.execute();
 
-        File copiedFile = new File( item.getOutputDirectory(), 
item.getDestFileName() );
+        Thread.sleep( 100 );
+        File unpackedFile = getUnpackedFile( item );
+
+        // round down to the last second
+        long time = System.currentTimeMillis();
+        time = time - ( time % 1000 );
 
-        // set dest to be old
-        long time = System.currentTimeMillis() - 10000;
-        copiedFile.setLastModified( time );
+        // set to known value
+        unpackedFile.setLastModified( time );
 
         // set source to be newer
         artifact.getFile().setLastModified( time + 4000 );
+        assertTrue( time == unpackedFile.lastModified() );
         mojo.execute();
 
-        assertTrue( time < copiedFile.lastModified() );
+        assertTrue( time != unpackedFile.lastModified() );
     }
-    */
-}
-// TODO: test overwrite / overwrite if newer / overwrite release / overwrite
-// snapshot
 
+    public void assertUnpacked( ArtifactItem item, boolean overWrite )
+        throws InterruptedException, MojoExecutionException
+    {
+
+        File unpackedFile = getUnpackedFile( item );
+
+        Thread.sleep( 100 );
+        // round down to the last second
+        long time = System.currentTimeMillis();
+        time = time - ( time % 1000 );
+        unpackedFile.setLastModified( time );
+
+        assertEquals( time, unpackedFile.lastModified() );
+        mojo.execute();
+
+        if ( overWrite )
+        {
+            assertTrue( time != unpackedFile.lastModified() );
+        }
+        else
+        {
+            assertEquals( time, unpackedFile.lastModified() );
+        }
+    }
+
+    public File getUnpackedFile( ArtifactItem item )
+    {
+        File unpackedFile = new File( item.getOutputDirectory(), 
ArtifactStubFactory.getUnpackableFileName( item
+            .getArtifact() ) );
+        
+        assertTrue(unpackedFile.exists());
+        return unpackedFile;
+
+    }
+}

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java?view=diff&rev=491740&r1=491739&r2=491740
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java
 Mon Jan  1 19:52:04 2007
@@ -145,7 +145,7 @@
         artifact.setFile( theFile );
     }
 
-    public String getUnpackableFileName( Artifact artifact )
+    static public String getUnpackableFileName( Artifact artifact )
     {
         return "" + artifact.getGroupId() + "-" + artifact.getArtifactId() + 
"-" + artifact.getVersion() + "-"
             + artifact.getClassifier() + "-" + artifact.getType() + ".txt";

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/DependencyTestUtils.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/DependencyTestUtils.java?view=diff&rev=491740&r1=491739&r2=491740
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/DependencyTestUtils.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/DependencyTestUtils.java
 Mon Jan  1 19:52:04 2007
@@ -90,5 +90,17 @@
 
         field.set( object, value );
     }
+    
+    public static void setFileModifiedTime(File file) throws 
InterruptedException
+    {
+        Thread.sleep( 100 );
+        // round down to the last second
+        long time = System.currentTimeMillis();
+        time = time - ( time % 1000 );
+        file.setLastModified( time );
+        // wait at least a second for filesystems that only record to the
+        // nearest second.
+        Thread.sleep( 1000 );
+    }
 
 }

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestDefaultMarkerFileHandler.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestDefaultMarkerFileHandler.java?view=diff&rev=491740&r1=491739&r2=491740
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestDefaultMarkerFileHandler.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestDefaultMarkerFileHandler.java
 Mon Jan  1 19:52:04 2007
@@ -179,9 +179,13 @@
     
     public void testNullParent() throws MojoExecutionException
     {
+        //the parent isn't set so this will create the marker in the local 
folder. We must clear the
+        //marker to avoid leaving test droppings in root.
         DefaultFileMarkerHandler handler = new 
DefaultFileMarkerHandler(null,null);
         handler.setArtifact( (Artifact) artifacts.get( 0 ) );
         handler.setMarker();
         assertTrue(handler.isMarkerSet());
+        handler.clearMarker();
+        assertFalse(handler.isMarkerSet());
     }
 }

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestSourcesMarkerFileHandler.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestSourcesMarkerFileHandler.java?view=diff&rev=491740&r1=491739&r2=491740
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestSourcesMarkerFileHandler.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestSourcesMarkerFileHandler.java
 Mon Jan  1 19:52:04 2007
@@ -1,4 +1,5 @@
 package org.apache.maven.plugin.dependency.utils.markers;
+
 /* 
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -271,19 +272,33 @@
         handler.setResolved( false );
         assertFalse( handler.isResolved() );
     }
-    
-    public void testNullParent() throws MojoExecutionException
+
+    public void testNullParent()
+        throws MojoExecutionException
     {
-        DefaultFileMarkerHandler handler = new 
SourcesFileMarkerHandler(null,null,false);
+        // the parent isn't set so this will create the marker in the local
+        // folder. We must clear the
+        // marker to avoid leaving test droppings in root.
+        DefaultFileMarkerHandler handler = new SourcesFileMarkerHandler( null, 
null, false );
         handler.setArtifact( (Artifact) artifacts.get( 0 ) );
         handler.setMarker();
-        assertTrue(handler.isMarkerSet());
+        assertTrue( handler.isMarkerSet() );
+        handler.clearMarker();
+        assertFalse( handler.isMarkerSet() );
     }
-    public void testNullParentResolved() throws MojoExecutionException
+
+    public void testNullParentResolved()
+        throws MojoExecutionException
     {
-        DefaultFileMarkerHandler handler = new 
SourcesFileMarkerHandler(null,null,true);
+        // the parent isn't set so this will create the marker in the local
+        // folder. We must clear the
+        // marker to avoid leaving test droppings in root.
+        DefaultFileMarkerHandler handler = new SourcesFileMarkerHandler( null, 
null, true );
         handler.setArtifact( (Artifact) artifacts.get( 0 ) );
         handler.setMarker();
-        assertTrue(handler.isMarkerSet());
+        assertTrue( handler.isMarkerSet() );
+        handler.clearMarker();
+        assertFalse( handler.isMarkerSet() );
+
     }
 }


Reply via email to