You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/09/06 07:11:48 UTC
[GitHub] [maven-enforcer] slawekjaranowski commented on a diff in pull request #183: [MENFORCER-430] Allow one of many files in RequireFiles rules to pass
slawekjaranowski commented on code in PR #183:
URL: https://github.com/apache/maven-enforcer/pull/183#discussion_r963331915
##########
enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFilesDontExist.java:
##########
@@ -136,6 +136,34 @@ public void testFileDoesNotExist()
rule.execute( EnforcerTestUtils.getHelper() );
}
+ @Test
+ public void testFileDoesNotExistSatisfyAny()
+ throws IOException
+ {
+ File f = File.createTempFile( "junit", null, temporaryFolder );
+ f.delete();
Review Comment:
Instead of creating and deleting file we can simply create File object with a wrong path
##########
enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFilesDontExist.java:
##########
@@ -136,6 +136,34 @@ public void testFileDoesNotExist()
rule.execute( EnforcerTestUtils.getHelper() );
}
+ @Test
+ public void testFileDoesNotExistSatisfyAny()
+ throws IOException
+ {
+ File f = File.createTempFile( "junit", null, temporaryFolder );
+ f.delete();
+
+ assertFalse( f.exists() );
+
+ File g = File.createTempFile( "junit", null, temporaryFolder );
+
+ assertTrue( g.exists() );
+
+ rule.setFiles( new File[] { f, g.getCanonicalFile() } );
+ rule.setSatisfyAny(true);
+
+ try
+ {
+ rule.execute( EnforcerTestUtils.getHelper() );
+ }
+ catch ( EnforcerRuleException e )
+ {
+ fail( "Unexpected Exception:" + e.getLocalizedMessage() );
+ }
Review Comment:
We can simply add this exception to test method signature
##########
enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFilesDontExist.java:
##########
@@ -136,6 +136,34 @@ public void testFileDoesNotExist()
rule.execute( EnforcerTestUtils.getHelper() );
}
+ @Test
+ public void testFileDoesNotExistSatisfyAny()
+ throws IOException
+ {
+ File f = File.createTempFile( "junit", null, temporaryFolder );
+ f.delete();
+
+ assertFalse( f.exists() );
+
+ File g = File.createTempFile( "junit", null, temporaryFolder );
+
+ assertTrue( g.exists() );
+
+ rule.setFiles( new File[] { f, g.getCanonicalFile() } );
+ rule.setSatisfyAny(true);
+
+ try
+ {
+ rule.execute( EnforcerTestUtils.getHelper() );
+ }
+ catch ( EnforcerRuleException e )
+ {
+ fail( "Unexpected Exception:" + e.getLocalizedMessage() );
+ }
+
+ g.delete();
Review Comment:
File was created in `@TempDir` so I hope that `junit` will remove it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org