diff --git a/pom.xml b/pom.xml index 3505cb5..5c74360 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ io.github.dgroup arch4u-pmd - 0.1.0 + 0.2.0 jar ${project.artifactId} diff --git a/src/main/resources/io/github/dgroup/arch4u/pmd/default-ruleset.xml b/src/main/resources/io/github/dgroup/arch4u/pmd/default-ruleset.xml index cfdc679..b2fda91 100644 --- a/src/main/resources/io/github/dgroup/arch4u/pmd/default-ruleset.xml +++ b/src/main/resources/io/github/dgroup/arch4u/pmd/default-ruleset.xml @@ -13,15 +13,15 @@ language="java" message="ObjectMapper is better to have as field than a local variable due to performance reasons." class="net.sourceforge.pmd.lang.rule.XPathRule"> - - ObjectMapper is better to have as field than a local variable due to performance reasons. - It is allowed to be declared in fields, constructors and initialization blocks. - - 3 - - - - + + ObjectMapper is better to have as field than a local variable due to performance reasons. + It is allowed to be declared in fields, constructors and initialization blocks. + + 3 + + + + - - - - + + + + - - + + + + + + Exception class must have at least one constructor with signature + `public Ctor(Throwable, String, Object...)` or `public Ctor(String, Object...)`. + + 3 + + + + + + + + + + + + diff --git a/src/test/java/io/github/dgroup/arch4u/pmd/NoMandatoryConstructorInExceptionClassTest.java b/src/test/java/io/github/dgroup/arch4u/pmd/NoMandatoryConstructorInExceptionClassTest.java new file mode 100644 index 0000000..5faed9d --- /dev/null +++ b/src/test/java/io/github/dgroup/arch4u/pmd/NoMandatoryConstructorInExceptionClassTest.java @@ -0,0 +1,44 @@ +/* + * MIT License + * + * Copyright (c) 2019-2022 Yurii Dubinka + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE + * OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package io.github.dgroup.arch4u.pmd; + +import net.sourceforge.pmd.testframework.SimpleAggregatorTst; + +/** + * Test case for {@code NoMandatoryConstructorInExceptionClass} rule. + * + * @since 0.2.0 + */ +@SuppressWarnings({"PMD.TestClassWithoutTestCases", "PMD.JUnit4TestShouldUseBeforeAnnotation"}) +public final class NoMandatoryConstructorInExceptionClassTest extends SimpleAggregatorTst { + + @Override + public void setUp() { + addRule( + "io/github/dgroup/arch4u/pmd/default-ruleset.xml", + "NoMandatoryConstructorInExceptionClass" + ); + } +} diff --git a/src/test/resources/io/github/dgroup/arch4u/pmd/xml/AvoidUsingObjectMapperAsALocalVariable.xml b/src/test/resources/io/github/dgroup/arch4u/pmd/xml/AvoidUsingObjectMapperAsALocalVariable.xml index ebbcfb9..ad8d95e 100644 --- a/src/test/resources/io/github/dgroup/arch4u/pmd/xml/AvoidUsingObjectMapperAsALocalVariable.xml +++ b/src/test/resources/io/github/dgroup/arch4u/pmd/xml/AvoidUsingObjectMapperAsALocalVariable.xml @@ -1,4 +1,28 @@ + + + + + + + + [GOOD]: all mandatory constructors are provided + 0 + + + + + + [GOOD]: mandatory constructor `MyException(String, Object...)` is provided + + 0 + + + + + + [GOOD]: mandatory constructor `MyException(Throwable, String, Object...)` is provided + + 0 + + + + + + [GOOD]: exception with mandatory constructor extends ArithmeticException + + 0 + + + + + [GOOD]: inner exception class with mandatory constructor + 0 + + + + + [BAD]: no constructors + 1 + 1 + + + + + [BAD]: no mandatory constructor: public MyException() + 1 + 1 + + + + + [BAD]: no mandatory constructor: public MyException(Throwable, Object...) + 1 + 1 + + + + + [BAD]: no mandatory constructor + 1 + 1 + + + + + [BAD]: no mandatory constructor + 1 + 1 + + + + + [BAD]: constructor has non-public modifier + 1 + 1 + + + + + [BAD]: inner exception class without mandatory constructor + 1 + 2 + + +