From 1acf188111f6299bc3ac0e1133888b09d7b0c0d7 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Sun, 4 Apr 2021 16:55:24 +0200 Subject: [PATCH] [MNG-7138] Proper verify of plugin configuration Bean set method call --- .../maven/it/MavenITmng3827PluginConfigTest.java | 1 + .../it/MavenITmng3864PerExecPluginConfigTest.java | 1 + ...mng5013ConfigureParamBeanFromScalarValueTest.java | 3 ++- .../java/org/apache/maven/plugin/coreit/Bean.java | 12 ++++++++++-- .../org/apache/maven/plugin/coreit/ConfigMojo.java | 2 ++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3827PluginConfigTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3827PluginConfigTest.java index c7bf9a86f..839c3b8e2 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3827PluginConfigTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3827PluginConfigTest.java @@ -96,6 +96,7 @@ public void testitMNG3827() assertEquals( "field", props.getProperty( "beanParam.fieldParam" ) ); assertEquals( "setter", props.getProperty( "beanParam.setterParam" ) ); + assertEquals( "false", props.getProperty( "beanParam.setCalled" ) ); assertEquals( "true", props.getProperty( "beanParam.setterCalled" ) ); assertEquals( "4", props.getProperty( "domParam.children" ) ); diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3864PerExecPluginConfigTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3864PerExecPluginConfigTest.java index f5830cff6..3c78ee341 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3864PerExecPluginConfigTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3864PerExecPluginConfigTest.java @@ -96,6 +96,7 @@ public void testitMNG3864() assertEquals( "field", props.getProperty( "beanParam.fieldParam" ) ); assertEquals( "setter", props.getProperty( "beanParam.setterParam" ) ); + assertEquals( "false", props.getProperty( "beanParam.setCalled" ) ); assertEquals( "true", props.getProperty( "beanParam.setterCalled" ) ); assertEquals( "4", props.getProperty( "domParam.children" ) ); diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5013ConfigureParamBeanFromScalarValueTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5013ConfigureParamBeanFromScalarValueTest.java index 6983f44c8..c10e5c0eb 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5013ConfigureParamBeanFromScalarValueTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5013ConfigureParamBeanFromScalarValueTest.java @@ -55,7 +55,8 @@ public void testit() Properties props = verifier.loadProperties( "target/config.properties" ); assertEquals( "PASSED", props.getProperty( "beanParam.fieldParam" ) ); - assertEquals( "true", props.getProperty( "beanParam.setterCalled" ) ); + assertEquals( "true", props.getProperty( "beanParam.setCalled" ) ); + assertEquals( "false", props.getProperty( "beanParam.setterCalled" ) ); } } diff --git a/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/Bean.java b/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/Bean.java index 8529d3a8d..668d4adc4 100644 --- a/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/Bean.java +++ b/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/Bean.java @@ -32,12 +32,20 @@ public class Bean String setterParam; + /** + * default method of bean was called + */ + boolean setCalled; + + /** + * setter method of ben was called + */ boolean setterCalled; public void set( String value ) { fieldParam = value; - setterCalled = true; + setCalled = true; } public void setSetterParam( String value ) @@ -49,7 +57,7 @@ public void setSetterParam( String value ) public String toString() { return getClass().getName() + "[fieldParam=" + fieldParam + ", setterParam=" + setterParam - + ", setterCalled=" + setterCalled + "]"; + + ", setterCalled=" + setterCalled + ", setCalled=" + setCalled + "]"; } } diff --git a/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/ConfigMojo.java b/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/ConfigMojo.java index 01f9d933e..ddd8ef322 100644 --- a/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/ConfigMojo.java +++ b/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/ConfigMojo.java @@ -246,6 +246,7 @@ public class ConfigMojo * * @parameter */ + private Bean beanParam; /** @@ -335,6 +336,7 @@ private void dumpConfiguration( Properties props ) { PropertiesUtil.serialize( props, "beanParam.fieldParam", beanParam.fieldParam ); PropertiesUtil.serialize( props, "beanParam.setterParam", beanParam.setterParam ); + PropertiesUtil.serialize( props, "beanParam.setCalled", beanParam.setCalled ); PropertiesUtil.serialize( props, "beanParam.setterCalled", beanParam.setterCalled ); } }