diff --git a/pom.xml b/pom.xml index 0c822a7dd..f9b3040e1 100644 --- a/pom.xml +++ b/pom.xml @@ -589,7 +589,7 @@ .*.PropertiesExpander5083 .*.PropertyCacheFile2218 .*.TreeWalker9083 - com.puppycrawl.tools.checkstyle.Utils6969 + com.puppycrawl.tools.checkstyle.Utils7871 .*.XMLLogger8697 @@ -616,7 +616,7 @@ .*.api.LocalizedMessage\$.*4166 .*.api.ScopeUtils9094 .*.api.SeverityLevelCounter5076 - .*.api.TokenTypes6272 + .*.api.TokenTypes6280 .*.checks.AbstractOptionCheck10080 @@ -764,7 +764,7 @@ .*.checks.javadoc.JavadocTag9285 .*.checks.javadoc.JavadocTagContinuationIndentationCheck8186 .*.checks.javadoc.JavadocTypeCheck9591 - .*.checks.javadoc.JavadocUtils8389 + .*.checks.javadoc.JavadocUtils8391 .*.checks.javadoc.JavadocVariableCheck9390 .*.checks.javadoc.SummaryJavadocCheck93100 .*.checks.javadoc.TagParser9298 diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/TestUtils.java b/src/test/java/com/puppycrawl/tools/checkstyle/TestUtils.java new file mode 100644 index 000000000..e1303f116 --- /dev/null +++ b/src/test/java/com/puppycrawl/tools/checkstyle/TestUtils.java @@ -0,0 +1,43 @@ +//////////////////////////////////////////////////////////////////////////////// +// checkstyle: Checks Java source code for adherence to a set of rules. +// Copyright (C) 2001-2015 the original author or authors. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//////////////////////////////////////////////////////////////////////////////// +package com.puppycrawl.tools.checkstyle; + +import org.junit.Assert; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +public class TestUtils { + + private TestUtils() { + } + + /** + * Verifies that utils class has private constructor and invokes it to satisfy code coverage. + */ + public static void assertUtilsClassHasPrivateConstructor(final Class utilClass) + throws ReflectiveOperationException { + final Constructor constructor = utilClass.getDeclaredConstructor(); + if (!Modifier.isPrivate(constructor.getModifiers())) { + Assert.fail("Constructor is not private"); + } + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/UtilsTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/UtilsTest.java index 25bcccd76..33563364a 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/UtilsTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/UtilsTest.java @@ -18,6 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle; +import static com.puppycrawl.tools.checkstyle.TestUtils.assertUtilsClassHasPrivateConstructor; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -77,4 +78,11 @@ public class UtilsTest file = new File("file.java"); assertTrue(fileExtensionMatches(file, fileExtensions)); } + + @Test + public void testIsProperUtilsClass() throws ReflectiveOperationException + { + assertUtilsClassHasPrivateConstructor(Utils.class); + } + } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/api/TokenTypesTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/api/TokenTypesTest.java index ae3f7cbdc..e50933f25 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/api/TokenTypesTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/api/TokenTypesTest.java @@ -18,6 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle.api; +import static com.puppycrawl.tools.checkstyle.TestUtils.assertUtilsClassHasPrivateConstructor; import static org.junit.Assert.assertEquals; import org.junit.Test; @@ -31,4 +32,10 @@ public class TokenTypesTest "The == (equal) operator.", TokenTypes .getShortDescription("EQUAL")); } + + @Test + public void testIsProperUtilsClass() throws ReflectiveOperationException + { + assertUtilsClassHasPrivateConstructor(TokenTypes.class); + } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocUtilsTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocUtilsTest.java index 9241c79ca..43c8f8752 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocUtilsTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocUtilsTest.java @@ -18,6 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle.checks.javadoc; +import static com.puppycrawl.tools.checkstyle.TestUtils.assertUtilsClassHasPrivateConstructor; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -188,4 +189,10 @@ public class JavadocUtilsTest assertTrue(JavadocUtils.isJavadocComment(commentBegin)); } + + @Test + public void testIsProperUtilsClass() throws ReflectiveOperationException + { + assertUtilsClassHasPrivateConstructor(JavadocUtils.class); + } }