You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2020/06/20 08:37:40 UTC

[maven-integration-testing] 04/04: Simplify test cases for --resume/-r

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-5760
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git

commit 37167a6bd969a6d037b7f94fd780c822c5954a50
Author: Maarten Mulders <ma...@infosupport.com>
AuthorDate: Fri May 22 15:32:55 2020 +0200

    Simplify test cases for --resume/-r
    
    Tests no longer verify whether a certain (implementation)
    file is there, and what its contents are. Instead, the test
    performs Maven invocations to verify the behaviour.
---
 .../maven/it/MavenITmng5760ResumeFeatureTest.java  | 75 ++++------------------
 1 file changed, 11 insertions(+), 64 deletions(-)

diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5760ResumeFeatureTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5760ResumeFeatureTest.java
index d6b3d5c..aa001a0 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5760ResumeFeatureTest.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5760ResumeFeatureTest.java
@@ -23,16 +23,7 @@ import org.apache.maven.it.util.ResourceExtractor;
 
 import java.io.File;
 import java.io.IOException;
-import java.io.Reader;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.List;
-import java.util.Properties;
-import java.util.stream.StreamSupport;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
 
 /**
  * This is a collection of test cases for <a href="https://issues.apache.org/jira/browse/MNG-5760">MNG-5760</a>,
@@ -80,10 +71,11 @@ public class MavenITmng5760ResumeFeatureTest extends AbstractMavenIntegrationTes
         }
     }
 
-    public void testShouldCreateResumptionFile() throws Exception
+    public void testShouldSkipSuccessfulProjects() throws Exception
     {
         final Verifier verifier = newVerifier( testDir.getAbsolutePath() );
-        verifier.addCliOption( "-Dmodule-b.fail=true" );
+        verifier.addCliOption( "-Dmodule-a.fail=true" );
+        verifier.addCliOption( "--fail-at-end");
 
         try
         {
@@ -92,43 +84,24 @@ public class MavenITmng5760ResumeFeatureTest extends AbstractMavenIntegrationTes
         }
         catch ( final VerificationException ve )
         {
-            final Path resumeProperties = Paths.get(testDir.getAbsolutePath(), "target", "resume.properties");
-            verifier.assertFilePresent( resumeProperties.toAbsolutePath().toString() );
-
-
-            Properties expected = new Properties();
-            expected.put( "resumeFrom", "org.apache.maven.its.mng5760:module-b");
-
-            verifyFileContainsProperties( resumeProperties, expected );
+            // Expected to fail.
         }
         finally
         {
             verifier.resetStreams();
         }
-    }
 
-    public void testShouldSkipSuccessfulProjects() throws Exception
-    {
-        final Verifier verifier = newVerifier( testDir.getAbsolutePath() );
-        verifier.addCliOption( "-Dmodule-a.fail=true" );
-        verifier.addCliOption( "--fail-at-end");
+        verifier.getCliOptions().clear();
 
+        // Let module-b and module-c fail, if they would have been built...
+        verifier.addCliOption( "-Dmodule-b.fail=true" );
+        verifier.addCliOption( "-Dmodule-c.fail=true" );
+        // ... but adding -r should exclude those two from the build because the previous Maven invocation
+        // marked them as successfully built.
+        verifier.addCliOption( "-r" );
         try
         {
             verifier.executeGoal( "test" );
-            fail( "Expected this invocation to fail" );
-        }
-        catch ( final VerificationException ve )
-        {
-            final Path resumeProperties = Paths.get(testDir.getAbsolutePath(), "target", "resume.properties");
-            verifier.assertFilePresent( resumeProperties.toAbsolutePath().toString() );
-
-
-            Properties expected = new Properties();
-            expected.put( "resumeFrom", "org.apache.maven.its.mng5760:module-a");
-            expected.put( "excludedProjects", "org.apache.maven.its.mng5760:module-b, org.apache.maven.its.mng5760:module-c");
-
-            verifyFileContainsProperties( resumeProperties, expected );
         }
         finally
         {
@@ -156,30 +129,4 @@ public class MavenITmng5760ResumeFeatureTest extends AbstractMavenIntegrationTes
             }
         }
     }
-
-    /**
-     * Throws an exception if the specified {@link Properties} are not present in the file. Checks for both key and
-     * value of the expected properties to be present.
-     * @param path Path the a file
-     * @param expectedProperties Expected properties inside the specified file
-     * @throws VerificationException When the specified file could not be read.
-     */
-    private void verifyFileContainsProperties( Path path, Properties expectedProperties )
-            throws VerificationException
-    {
-        Properties foundProperties = new Properties();
-        try ( Reader reader = Files.newBufferedReader( path ) )
-        {
-            foundProperties.load( reader );
-        }
-        catch ( IOException e )
-        {
-            throw new VerificationException( "Could not verify contents of " + path.toString(), e );
-        }
-
-        expectedProperties.forEach( ( key, value ) -> {
-            assertThat( foundProperties.containsKey( key ), is( true ) );
-            assertThat( foundProperties.get( key ), is( value ) );
-        });
-    }
 }