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

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


The following commit(s) were added to refs/heads/MNG-7063 by this push:
     new e8b328c  Improve test
e8b328c is described below

commit e8b328c7db526ab03171165a9fa669c932db3799
Author: rfscholte <rfscho...@apache.org>
AuthorDate: Sun Feb 14 16:43:04 2021 +0100

    Improve test
---
 .../project/DefaultMavenProjectBuilderTest.java    | 52 ++++++++--------------
 .../src/test/resources/projects/reread/pom1.xml    | 20 +++++++++
 .../src/test/resources/projects/reread/pom2.xml    | 20 +++++++++
 3 files changed, 59 insertions(+), 33 deletions(-)

diff --git 
a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
 
b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
index 18e2357..1996208 100644
--- 
a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
+++ 
b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
@@ -23,15 +23,14 @@ import static 
org.apache.maven.test.PlexusExtension.getTestFile;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.fail;
 
 import java.io.File;
+import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.StandardCopyOption;
@@ -110,7 +109,7 @@ public class DefaultMavenProjectBuilderTest
                 ProjectBuildingException.class,
                 () -> getProject( f1 ),
                 "Expected to fail for future versions" );
-        assertContains( "Building this project requires a newer version of 
Maven", e.getMessage() );
+        assertThat(  e.getMessage(), containsString( "Building this project 
requires a newer version of Maven" ) );
     }
 
     @Test
@@ -125,7 +124,7 @@ public class DefaultMavenProjectBuilderTest
                 ProjectBuildingException.class,
                 () -> getProject( f1 ),
                 "Expected to fail for past versions" );
-        assertContains( "Building this project requires an older version of 
Maven", e.getMessage() );
+        assertThat( e.getMessage(), containsString( "Building this project 
requires an older version of Maven" ) );
     }
 
     @Test
@@ -138,17 +137,7 @@ public class DefaultMavenProjectBuilderTest
                 ProjectBuildingException.class,
                 () -> getProject( f1 ),
                 "Expected to fail for future versions" );
-        assertContains( "Building this project requires a newer version of 
Maven", e.getMessage() );
-    }
-
-    private void assertContains( String expected, String actual )
-    {
-        if ( actual == null || !actual.contains( expected ) )
-        {
-            fail( "Expected: a string containing " + expected + "\nActual: " + 
( actual == null
-                ? "null"
-                : "'" + actual + "'" ) );
-        }
+        assertThat( e.getMessage(), containsString( "Building this project 
requires a newer version of Maven" ) );
     }
 
     @Test
@@ -179,16 +168,6 @@ public class DefaultMavenProjectBuilderTest
         return repositorySystem.createLocalRepository( 
getLocalRepositoryPath() );
     }
 
-    public void xtestLoop()
-        throws Exception
-    {
-        while ( true )
-        {
-            File f1 = getTestFile( 
"src/test/resources/projects/duplicate-plugins-merged-pom.xml" );
-            getProject( f1 );
-        }
-    }
-
     @Test
     public void testPartialResultUponBadDependencyDeclaration()
         throws Exception
@@ -248,7 +227,6 @@ public class DefaultMavenProjectBuilderTest
                 ProjectBuildingException.class,
                 () -> getProject( f1 ),
                 "Expected 'ProjectBuildingException' not thrown." );
-        assertNotNull( e.getMessage() );
         assertThat( e.getMessage(), containsString( "Version must be a 
constant" ) );
     }
 
@@ -268,7 +246,6 @@ public class DefaultMavenProjectBuilderTest
                 ProjectBuildingException.class,
                 () -> getProject( f1 ),
                 "Expected 'ProjectBuildingException' not thrown." );
-        assertNotNull( e.getMessage() );
         assertThat( e.getMessage(), containsString( "Version must be a 
constant" ) );
     }
 
@@ -308,7 +285,6 @@ public class DefaultMavenProjectBuilderTest
                 ProjectBuildingException.class,
                 () -> getProjectFromRemoteRepository( f1 ),
                 "Expected 'ProjectBuildingException' not thrown." );
-        assertNotNull( e.getMessage() );
         assertThat( e.getMessage(), containsString( "Version must be a 
constant" ) );
     }
 
@@ -328,23 +304,33 @@ public class DefaultMavenProjectBuilderTest
                 ProjectBuildingException.class,
                 () -> getProjectFromRemoteRepository( f1 ),
                 "Expected 'ProjectBuildingException' not thrown." );
-        assertNotNull( e.getMessage() );
         assertThat( e.getMessage(), containsString( "Version must be a 
constant" ) );
     }
     
+    /**
+     * Ensure that when re-reading a pom, it should not use the cached Model
+     * 
+     * @throws Exception
+     */
     @Test
     public void rereadPom_mng7063() throws Exception
     {
         final Path pom = projectRoot.resolve( "pom.xml" );
 
-        Files.copy( DefaultMavenProjectBuilderTest.class.getResourceAsStream( 
"/projects/reread/pom1.xml" ),
-                    pom, StandardCopyOption.REPLACE_EXISTING );
+        try ( InputStream pomResource =
+            DefaultMavenProjectBuilderTest.class.getResourceAsStream( 
"/projects/reread/pom1.xml" ) )
+        {
+            Files.copy( pomResource, pom, StandardCopyOption.REPLACE_EXISTING 
);
+        }
         
         MavenProject project = getProject( pom.toFile() );
         assertThat( project.getName(), is( "aid" ) ); // inherited from 
artifactId
         
-        Files.copy( DefaultMavenProjectBuilderTest.class.getResourceAsStream( 
"/projects/reread/pom2.xml" ),
-                    pom, StandardCopyOption.REPLACE_EXISTING );
+        try ( InputStream pomResource =
+            DefaultMavenProjectBuilderTest.class.getResourceAsStream( 
"/projects/reread/pom2.xml" ) )
+        {
+            Files.copy( pomResource, pom, StandardCopyOption.REPLACE_EXISTING 
);
+        }
 
         project = getProject( pom.toFile() );
         assertThat( project.getName(), is( "PROJECT NAME" ) );
diff --git a/maven-core/src/test/resources/projects/reread/pom1.xml 
b/maven-core/src/test/resources/projects/reread/pom1.xml
index c439214..724f2cc 100644
--- a/maven-core/src/test/resources/projects/reread/pom1.xml
+++ b/maven-core/src/test/resources/projects/reread/pom1.xml
@@ -1,3 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
 <project>
   <modelVersion>4.0.0</modelVersion>
   <groupId>gid</groupId>
diff --git a/maven-core/src/test/resources/projects/reread/pom2.xml 
b/maven-core/src/test/resources/projects/reread/pom2.xml
index b71b8a8..ebcafa1 100644
--- a/maven-core/src/test/resources/projects/reread/pom2.xml
+++ b/maven-core/src/test/resources/projects/reread/pom2.xml
@@ -1,3 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
 <project>
   <modelVersion>4.0.0</modelVersion>
   <groupId>gid</groupId>

Reply via email to