From 4a56989f8ea633b6dfacd1f1ef0a12f5ef6358ba Mon Sep 17 00:00:00 2001 From: Michal Kordas Date: Wed, 19 Aug 2015 22:25:47 +0200 Subject: [PATCH] Fix too broad scope of variables. #1555 Additionally, obsolete assertions were removed. Fixes `TooBroadScope` inspection violations. Description: >Reports any variable declarations of which the scope can be narrowed. Especially useful for "Pascal style" declarations at the start of a method, but variables with too broad a scope are also often left over after refactorings. --- .../google/checkstyle/test/base/ConfigurationBuilder.java | 6 +++--- .../test/base/IndentationConfigurationBuilder.java | 6 ++---- .../java/com/puppycrawl/tools/checkstyle/MainTest.java | 2 +- .../com/puppycrawl/tools/checkstyle/api/FileTextTest.java | 2 +- .../tools/checkstyle/api/LocalizedMessageTest.java | 2 +- .../checks/AvoidEscapedUnicodeCharactersCheckTest.java | 2 -- .../checkstyle/checks/OuterTypeFilenameCheckTest.java | 2 -- .../checks/annotation/AnnotationLocationCheckTest.java | 2 -- .../checks/annotation/AnnotationUseStyleTest.java | 1 - .../checks/annotation/PackageAnnotationTest.java | 1 - .../checks/blocks/AvoidNestedBlocksCheckTest.java | 2 -- .../checks/blocks/EmptyCatchBlockCheckTest.java | 2 -- .../checkstyle/checks/blocks/LeftCurlyCheckTest.java | 2 -- .../checkstyle/checks/header/RegexpHeaderCheckTest.java | 2 +- .../checks/indentation/IndentationCheckTest.java | 6 ++---- .../checkstyle/checks/javadoc/AtclauseOrderCheckTest.java | 8 ++++---- .../checks/metrics/CyclomaticComplexityCheckTest.java | 1 - .../checkstyle/checks/modifier/RedundantModifierTest.java | 2 -- .../checks/naming/AbstractClassNameCheckTest.java | 2 -- .../checks/naming/LocalFinalVariableNameCheckTest.java | 2 -- .../checkstyle/checks/naming/MemberNameCheckTest.java | 2 -- .../checkstyle/checks/naming/MethodNameCheckTest.java | 2 -- .../checkstyle/checks/naming/PackageNameCheckTest.java | 2 -- .../checkstyle/checks/naming/ParameterNameCheckTest.java | 2 -- .../checks/naming/StaticVariableNameCheckTest.java | 2 -- .../checkstyle/checks/naming/TypeParameterNameTest.java | 2 -- .../tools/checkstyle/checks/regexp/RegexpCheckTest.java | 6 +++--- .../checks/regexp/RegexpSinglelineCheckTest.java | 2 +- .../checks/regexp/RegexpSinglelineJavaCheckTest.java | 2 +- .../whitespace/EmptyForInitializerPadCheckTest.java | 1 - .../checks/whitespace/EmptyForIteratorPadCheckTest.java | 2 -- .../checks/whitespace/EmptyLineSeparatorCheckTest.java | 2 -- .../checks/whitespace/GenericWhitespaceCheckTest.java | 2 -- .../checks/whitespace/MethodParamPadCheckTest.java | 2 -- .../checks/whitespace/SeparatorWrapCheckTest.java | 1 - .../checks/whitespace/TypecastParenPadCheckTest.java | 1 - .../checks/whitespace/WhitespaceAroundTest.java | 2 -- 37 files changed, 20 insertions(+), 70 deletions(-) diff --git a/src/it/java/com/google/checkstyle/test/base/ConfigurationBuilder.java b/src/it/java/com/google/checkstyle/test/base/ConfigurationBuilder.java index 6b2bc2bdb..f3415cef7 100644 --- a/src/it/java/com/google/checkstyle/test/base/ConfigurationBuilder.java +++ b/src/it/java/com/google/checkstyle/test/base/ConfigurationBuilder.java @@ -100,10 +100,10 @@ public class ConfigurationBuilder extends BaseCheckTestSupport { } public Integer[] getLinesWithWarn(String aFileName) throws IOException { - int lineNumber = 1; - List result = new ArrayList<>(); + List result = new ArrayList<>(); try(BufferedReader br = new BufferedReader(new FileReader(aFileName))) { - while (true) { + int lineNumber = 1; + while (true) { String line = br.readLine(); if (line == null) { break; diff --git a/src/it/java/com/google/checkstyle/test/base/IndentationConfigurationBuilder.java b/src/it/java/com/google/checkstyle/test/base/IndentationConfigurationBuilder.java index f20e030d7..4be8921b7 100644 --- a/src/it/java/com/google/checkstyle/test/base/IndentationConfigurationBuilder.java +++ b/src/it/java/com/google/checkstyle/test/base/IndentationConfigurationBuilder.java @@ -50,9 +50,9 @@ public class IndentationConfigurationBuilder extends ConfigurationBuilder final int tabWidth) throws IOException { - int lineNumber = 1; List result = new ArrayList<>(); try (BufferedReader br = new BufferedReader(new FileReader(aFileName))) { + int lineNumber = 1; for (String line = br.readLine(); line != null; line = br.readLine()) { Matcher match = LINE_WITH_COMMENT_REGEX.matcher(line); if (match.matches()) { @@ -112,9 +112,7 @@ public class IndentationConfigurationBuilder extends ConfigurationBuilder final int indentInComment = getIndentFromComment(comment); final boolean isWarnComment = isWarnComment(comment); - Matcher match; - - match = MULTILEVEL_COMMENT_REGEX.matcher(comment); + Matcher match = MULTILEVEL_COMMENT_REGEX.matcher(comment); if (match.matches()) { final String[] levels = match.group(1).split(","); final String indentInCommentStr = String.valueOf(indentInComment); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java index 8256d22cc..6aebf3349 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java @@ -483,9 +483,9 @@ public class MainTest { String expectedPath = currentPath + "/src/test/resources/com/puppycrawl/tools/checkstyle/metrics/" .replace("/", File.separator); - String format = "%s.java:%s: warning: File length is %s lines (max allowed is 80)."; StringBuilder sb = new StringBuilder(); sb.append("Starting audit...").append(System.getProperty("line.separator")); + String format = "%s.java:%s: warning: File length is %s lines (max allowed is 80)."; for (String[] outputValue : outputValues) { String line = String.format(format, expectedPath + outputValue[0], outputValue[1], diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/api/FileTextTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/api/FileTextTest.java index 4f8b6521c..f84e9081d 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/api/FileTextTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/api/FileTextTest.java @@ -47,8 +47,8 @@ public class FileTextTest { @Test public void testSupportedCharset() throws IOException { // just to make UT coverage 100% - String charsetName = "ISO-8859-1"; try { + String charsetName = "ISO-8859-1"; FileText o = new FileText(new File("src/test/resources/com/puppycrawl/tools/" + "checkstyle/imports/import-control_complete.xml"), charsetName); assertEquals(o.getCharset().name(), charsetName); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/api/LocalizedMessageTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/api/LocalizedMessageTest.java index 80970fcd2..f57183f81 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/api/LocalizedMessageTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/api/LocalizedMessageTest.java @@ -72,12 +72,12 @@ public class LocalizedMessageTest { public void testBundleReload_UrlNotNull() throws IOException { ClassLoader classloader = mock(ClassLoader.class); - String resource = "com/puppycrawl/tools/checkstyle/checks/coding/messages_en.properties"; final URLConnection mockConnection = Mockito.mock(URLConnection.class); when(mockConnection.getInputStream()).thenReturn( new ByteArrayInputStream(new byte[]{})); URL url = getMockUrl(mockConnection); + String resource = "com/puppycrawl/tools/checkstyle/checks/coding/messages_en.properties"; when(classloader.getResource(resource)).thenReturn(url); LocalizedMessage.UTF8Control cntrl = new LocalizedMessage.UTF8Control(); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/AvoidEscapedUnicodeCharactersCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/AvoidEscapedUnicodeCharactersCheckTest.java index 4cce14d57..5a9804716 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/AvoidEscapedUnicodeCharactersCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/AvoidEscapedUnicodeCharactersCheckTest.java @@ -21,7 +21,6 @@ package com.puppycrawl.tools.checkstyle.checks; import static org.junit.Assert.assertArrayEquals; -import org.junit.Assert; import org.junit.Test; import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; @@ -185,7 +184,6 @@ public class AvoidEscapedUnicodeCharactersCheckTest extends BaseCheckTestSupport AvoidEscapedUnicodeCharactersCheck check = new AvoidEscapedUnicodeCharactersCheck(); int[] actual = check.getAcceptableTokens(); int[] expected = new int[] {TokenTypes.STRING_LITERAL, TokenTypes.CHAR_LITERAL }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/OuterTypeFilenameCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/OuterTypeFilenameCheckTest.java index be33934a6..4e4dfbfb0 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/OuterTypeFilenameCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/OuterTypeFilenameCheckTest.java @@ -23,7 +23,6 @@ import static org.junit.Assert.assertArrayEquals; import java.io.File; -import org.junit.Assert; import org.junit.Test; import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; @@ -70,7 +69,6 @@ public class OuterTypeFilenameCheckTest extends BaseCheckTestSupport { TokenTypes.ENUM_DEF, TokenTypes.ANNOTATION_DEF, }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheckTest.java index 3911ce047..a94ba5bc2 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheckTest.java @@ -24,7 +24,6 @@ import static com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationLocati import static org.junit.Assert.assertArrayEquals; import org.apache.commons.lang3.ArrayUtils; -import org.junit.Assert; import org.junit.Test; import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; @@ -96,7 +95,6 @@ public class AnnotationLocationCheckTest extends BaseCheckTestSupport { TokenTypes.DOT, TokenTypes.ANNOTATION_FIELD_DEF, }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationUseStyleTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationUseStyleTest.java index 0482e2d10..39316e9c6 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationUseStyleTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationUseStyleTest.java @@ -253,7 +253,6 @@ public class AnnotationUseStyleTest extends BaseCheckTestSupport { AnnotationUseStyleCheck constantNameCheckObj = new AnnotationUseStyleCheck(); int[] actual = constantNameCheckObj.getAcceptableTokens(); int[] expected = new int[] {TokenTypes.ANNOTATION }; - Assert.assertNotNull(actual); Assert.assertArrayEquals(expected, actual); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/annotation/PackageAnnotationTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/annotation/PackageAnnotationTest.java index ce241b6d6..e7741cfbb 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/annotation/PackageAnnotationTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/annotation/PackageAnnotationTest.java @@ -47,7 +47,6 @@ public class PackageAnnotationTest extends BaseCheckTestSupport { PackageAnnotationCheck constantNameCheckObj = new PackageAnnotationCheck(); int[] actual = constantNameCheckObj.getAcceptableTokens(); int[] expected = new int[] {TokenTypes.PACKAGE_DEF }; - Assert.assertNotNull(actual); Assert.assertArrayEquals(expected, actual); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/AvoidNestedBlocksCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/AvoidNestedBlocksCheckTest.java index 558e51678..9f859e4e4 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/AvoidNestedBlocksCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/AvoidNestedBlocksCheckTest.java @@ -22,7 +22,6 @@ package com.puppycrawl.tools.checkstyle.checks.blocks; import static com.puppycrawl.tools.checkstyle.checks.blocks.AvoidNestedBlocksCheck.MSG_KEY_BLOCK_NESTED; import static org.junit.Assert.assertArrayEquals; -import org.junit.Assert; import org.junit.Test; import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; @@ -73,7 +72,6 @@ public class AvoidNestedBlocksCheckTest AvoidNestedBlocksCheck constantNameCheckObj = new AvoidNestedBlocksCheck(); int[] actual = constantNameCheckObj.getAcceptableTokens(); int[] expected = new int[] {TokenTypes.SLIST }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/EmptyCatchBlockCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/EmptyCatchBlockCheckTest.java index 5d86adccc..d4899a74c 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/EmptyCatchBlockCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/EmptyCatchBlockCheckTest.java @@ -21,7 +21,6 @@ package com.puppycrawl.tools.checkstyle.checks.blocks; import static org.junit.Assert.assertArrayEquals; -import org.junit.Assert; import org.junit.Test; import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; @@ -77,7 +76,6 @@ public class EmptyCatchBlockCheckTest extends BaseCheckTestSupport { EmptyCatchBlockCheck constantNameCheckObj = new EmptyCatchBlockCheck(); int[] actual = constantNameCheckObj.getAcceptableTokens(); int[] expected = new int[] {TokenTypes.LITERAL_CATCH }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheckTest.java index 2c35965a0..baff1d041 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/LeftCurlyCheckTest.java @@ -26,7 +26,6 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import org.apache.commons.lang3.ArrayUtils; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -295,7 +294,6 @@ public class LeftCurlyCheckTest extends BaseCheckTestSupport { TokenTypes.LITERAL_ELSE, TokenTypes.LITERAL_FOR, TokenTypes.STATIC_INIT, }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/header/RegexpHeaderCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/header/RegexpHeaderCheckTest.java index 9666e234b..44cff2155 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/header/RegexpHeaderCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/header/RegexpHeaderCheckTest.java @@ -81,8 +81,8 @@ public class RegexpHeaderCheckTest extends BaseFileSetCheckTestSupport { public void testSetHeader() { // check invalid header passes RegexpHeaderCheck instance = new RegexpHeaderCheck(); - String header = "^/**\\n * Licensed to the Apache Software Foundation (ASF)"; try { + String header = "^/**\\n * Licensed to the Apache Software Foundation (ASF)"; instance.setHeader(header); fail(String.format("%s should have been thrown", ConversionException.class)); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java index 1489b26fa..b0a8ee839 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java @@ -68,9 +68,9 @@ public class IndentationCheckTest extends BaseCheckTestSupport { protected static Integer[] getLinesWithWarnAndCheckComments(String aFileName, final int tabWidth) throws IOException { - int lineNumber = 1; List result = new ArrayList<>(); try (BufferedReader br = new BufferedReader(new FileReader(aFileName))) { + int lineNumber = 1; for (String line = br.readLine(); line != null; line = br.readLine()) { Matcher match = LINE_WITH_COMMENT_REGEX.matcher(line); if (match.matches()) { @@ -126,9 +126,7 @@ public class IndentationCheckTest extends BaseCheckTestSupport { final int indentInComment = getIndentFromComment(comment); final boolean isWarnComment = isWarnComment(comment); - Matcher match; - - match = MULTILEVEL_COMMENT_REGEX.matcher(comment); + Matcher match = MULTILEVEL_COMMENT_REGEX.matcher(comment); if (match.matches()) { final String[] levels = match.group(1).split(","); final String indentInCommentStr = String.valueOf(indentInComment); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AtclauseOrderCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AtclauseOrderCheckTest.java index 4e0b96fd0..d2f979343 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AtclauseOrderCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AtclauseOrderCheckTest.java @@ -100,15 +100,15 @@ public class AtclauseOrderCheckTest extends BaseCheckTestSupport { @Test public void testIncorrectCustom() throws Exception { - final String tagOrder = "[@since, @version, @param, @return, @throws, @exception," - + " @deprecated, @see, @serial, @serialField, @serialData, @author]"; - final String customOrder = " @since, @version, @param,@return,@throws, @exception," - + "@deprecated, @see,@serial, @serialField, @serialData,@author"; DefaultConfiguration checkConfig = createCheckConfig(AtclauseOrderCheck.class); checkConfig.addAttribute("target", "CLASS_DEF"); + final String customOrder = " @since, @version, @param,@return,@throws, @exception," + + "@deprecated, @see,@serial, @serialField, @serialData,@author"; checkConfig.addAttribute("tagOrder", customOrder); + final String tagOrder = "[@since, @version, @param, @return, @throws, @exception," + + " @deprecated, @see, @serial, @serialField, @serialData, @author]"; final String[] expected = { "113: " + getCheckMessage(MSG_KEY, tagOrder), }; diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/metrics/CyclomaticComplexityCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/metrics/CyclomaticComplexityCheckTest.java index 27b0bdca7..6efda4ce6 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/metrics/CyclomaticComplexityCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/metrics/CyclomaticComplexityCheckTest.java @@ -72,7 +72,6 @@ public class CyclomaticComplexityCheckTest TokenTypes.LAND, TokenTypes.LOR, }; - Assert.assertNotNull(actual); Assert.assertArrayEquals(expected, actual); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierTest.java index eb82b7fe9..f190e1f9e 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierTest.java @@ -116,7 +116,6 @@ public class RedundantModifierTest TokenTypes.CLASS_DEF, TokenTypes.ENUM_DEF, }; - Assert.assertNotNull(actual); Assert.assertArrayEquals(expected, actual); } @@ -125,7 +124,6 @@ public class RedundantModifierTest RedundantModifierCheck redundantModifierCheckObj = new RedundantModifierCheck(); int[] actual = redundantModifierCheckObj.getRequiredTokens(); int[] expected = new int[] {}; - Assert.assertNotNull(actual); Assert.assertArrayEquals(expected, actual); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/AbstractClassNameCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/AbstractClassNameCheckTest.java index 5d34dd7d2..d16265a34 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/AbstractClassNameCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/AbstractClassNameCheckTest.java @@ -102,7 +102,6 @@ public class AbstractClassNameCheckTest extends BaseCheckTestSupport { int[] expected = new int[] { TokenTypes.CLASS_DEF, }; - Assert.assertNotNull(actual); Assert.assertArrayEquals(expected, actual); } @@ -113,7 +112,6 @@ public class AbstractClassNameCheckTest extends BaseCheckTestSupport { int[] expected = new int[] { TokenTypes.CLASS_DEF, }; - Assert.assertNotNull(actual); Assert.assertArrayEquals(expected, actual); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/LocalFinalVariableNameCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/LocalFinalVariableNameCheckTest.java index d0df4fb9c..bdfd6a044 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/LocalFinalVariableNameCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/LocalFinalVariableNameCheckTest.java @@ -23,7 +23,6 @@ import static com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck.MS import static org.junit.Assert.assertArrayEquals; import org.apache.commons.lang3.ArrayUtils; -import org.junit.Assert; import org.junit.Test; import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; @@ -86,7 +85,6 @@ public class LocalFinalVariableNameCheckTest TokenTypes.VARIABLE_DEF, TokenTypes.PARAMETER_DEF, }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/MemberNameCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/MemberNameCheckTest.java index 90dc57d0b..0ced4488a 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/MemberNameCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/MemberNameCheckTest.java @@ -24,7 +24,6 @@ import static org.junit.Assert.assertArrayEquals; import java.io.File; -import org.junit.Assert; import org.junit.Test; import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; @@ -256,7 +255,6 @@ public class MemberNameCheckTest int[] expected = new int[] { TokenTypes.VARIABLE_DEF, }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/MethodNameCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/MethodNameCheckTest.java index a386213da..7892a6953 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/MethodNameCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/MethodNameCheckTest.java @@ -23,7 +23,6 @@ import static com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck.MS import static com.puppycrawl.tools.checkstyle.checks.naming.MethodNameCheck.MSG_KEY; import static org.junit.Assert.assertArrayEquals; -import org.junit.Assert; import org.junit.Test; import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; @@ -154,7 +153,6 @@ public class MethodNameCheckTest int[] expected = new int[] { TokenTypes.METHOD_DEF, }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/PackageNameCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/PackageNameCheckTest.java index 3960618bf..3df77a488 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/PackageNameCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/PackageNameCheckTest.java @@ -22,7 +22,6 @@ package com.puppycrawl.tools.checkstyle.checks.naming; import static com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck.MSG_INVALID_PATTERN; import static org.junit.Assert.assertArrayEquals; -import org.junit.Assert; import org.junit.Test; import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; @@ -71,7 +70,6 @@ public class PackageNameCheckTest int[] expected = new int[] { TokenTypes.PACKAGE_DEF, }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/ParameterNameCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/ParameterNameCheckTest.java index 5d32b9a33..d9b7c0875 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/ParameterNameCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/ParameterNameCheckTest.java @@ -22,7 +22,6 @@ package com.puppycrawl.tools.checkstyle.checks.naming; import static com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck.MSG_INVALID_PATTERN; import static org.junit.Assert.assertArrayEquals; -import org.junit.Assert; import org.junit.Test; import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; @@ -84,7 +83,6 @@ public class ParameterNameCheckTest int[] expected = new int[] { TokenTypes.PARAMETER_DEF, }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/StaticVariableNameCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/StaticVariableNameCheckTest.java index 0db512eb3..1ce370a47 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/StaticVariableNameCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/StaticVariableNameCheckTest.java @@ -24,7 +24,6 @@ import static org.junit.Assert.assertArrayEquals; import java.io.File; -import org.junit.Assert; import org.junit.Test; import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; @@ -88,7 +87,6 @@ public class StaticVariableNameCheckTest int[] expected = new int[] { TokenTypes.VARIABLE_DEF, }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/TypeParameterNameTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/TypeParameterNameTest.java index 4528d65fd..b0b9082c9 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/TypeParameterNameTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/TypeParameterNameTest.java @@ -24,7 +24,6 @@ import static org.junit.Assert.assertArrayEquals; import java.io.File; -import org.junit.Assert; import org.junit.Test; import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; @@ -166,7 +165,6 @@ public class TypeParameterNameTest int[] expected = new int[] { TokenTypes.TYPE_PARAMETER, }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheckTest.java index dd9822a83..f46af6997 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheckTest.java @@ -128,13 +128,13 @@ public class RegexpCheckTest extends BaseCheckTestSupport { @Test public void testIllegalFailAboveErrorLimit() throws Exception { final String illegal = "^import"; - final String error = "The error limit has been exceeded, " - + "the check is aborting, there may be more unreported errors."; final DefaultConfiguration checkConfig = createCheckConfig(RegexpCheck.class); checkConfig.addAttribute("format", illegal); checkConfig.addAttribute("illegalPattern", "true"); checkConfig.addAttribute("errorLimit", "3"); + final String error = "The error limit has been exceeded, " + + "the check is aborting, there may be more unreported errors."; final String[] expected = { "7: " + getCheckMessage(MSG_ILLEGAL_REGEXP, illegal), "8: " + getCheckMessage(MSG_ILLEGAL_REGEXP, illegal), @@ -147,11 +147,11 @@ public class RegexpCheckTest extends BaseCheckTestSupport { public void testMessagePropertyGood() throws Exception { final String illegal = "System\\.(out)|(err)\\.print(ln)?\\("; - final String message = "Bad line :("; final DefaultConfiguration checkConfig = createCheckConfig(RegexpCheck.class); checkConfig.addAttribute("format", illegal); checkConfig.addAttribute("illegalPattern", "true"); + final String message = "Bad line :("; checkConfig.addAttribute("message", message); final String[] expected = { "69: " + getCheckMessage(MSG_ILLEGAL_REGEXP, message), diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpSinglelineCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpSinglelineCheckTest.java index 5c75d00c9..c7b2c0ed5 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpSinglelineCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpSinglelineCheckTest.java @@ -50,8 +50,8 @@ public class RegexpSinglelineCheckTest extends BaseFileSetCheckTestSupport { public void testMessageProperty() throws Exception { final String illegal = "System\\.(out)|(err)\\.print(ln)?\\("; - final String message = "Bad line :("; checkConfig.addAttribute("format", illegal); + final String message = "Bad line :("; checkConfig.addAttribute("message", message); final String[] expected = { "69: " + message, diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpSinglelineJavaCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpSinglelineJavaCheckTest.java index f19172ae7..313f87d01 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpSinglelineJavaCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpSinglelineJavaCheckTest.java @@ -58,8 +58,8 @@ public class RegexpSinglelineJavaCheckTest extends BaseCheckTestSupport { public void testMessageProperty() throws Exception { final String illegal = "System\\.(out)|(err)\\.print(ln)?\\("; - final String message = "Bad line :("; checkConfig.addAttribute("format", illegal); + final String message = "Bad line :("; checkConfig.addAttribute("message", message); final String[] expected = { "69: " + message, diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyForInitializerPadCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyForInitializerPadCheckTest.java index 631f21e9b..83499d712 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyForInitializerPadCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyForInitializerPadCheckTest.java @@ -72,7 +72,6 @@ public class EmptyForInitializerPadCheckTest int[] expected = new int[] { TokenTypes.FOR_INIT, }; - Assert.assertNotNull(actual); Assert.assertArrayEquals(expected, actual); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyForIteratorPadCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyForIteratorPadCheckTest.java index d6dec4bd9..6381e2e95 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyForIteratorPadCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyForIteratorPadCheckTest.java @@ -23,7 +23,6 @@ import static com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyForIterator import static com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyForIteratorPadCheck.WS_NOT_FOLLOWED; import static org.junit.Assert.assertArrayEquals; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -73,7 +72,6 @@ public class EmptyForIteratorPadCheckTest int[] expected = new int[] { TokenTypes.FOR_ITERATOR, }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyLineSeparatorCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyLineSeparatorCheckTest.java index fe48974e8..1c26fc015 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyLineSeparatorCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/EmptyLineSeparatorCheckTest.java @@ -24,7 +24,6 @@ import static com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparat import static org.junit.Assert.assertArrayEquals; import org.apache.commons.lang3.ArrayUtils; -import org.junit.Assert; import org.junit.Test; import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; @@ -139,7 +138,6 @@ public class EmptyLineSeparatorCheckTest TokenTypes.CTOR_DEF, TokenTypes.VARIABLE_DEF, }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/GenericWhitespaceCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/GenericWhitespaceCheckTest.java index 2fa56a66f..c06c6fe5c 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/GenericWhitespaceCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/GenericWhitespaceCheckTest.java @@ -28,7 +28,6 @@ import static org.junit.Assert.assertArrayEquals; import java.io.File; import java.util.Map; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -140,7 +139,6 @@ public class GenericWhitespaceCheckTest TokenTypes.GENERIC_START, TokenTypes.GENERIC_END, }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/MethodParamPadCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/MethodParamPadCheckTest.java index 370da89b0..f795ad391 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/MethodParamPadCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/MethodParamPadCheckTest.java @@ -25,7 +25,6 @@ import static com.puppycrawl.tools.checkstyle.checks.whitespace.MethodParamPadCh import static org.junit.Assert.assertArrayEquals; import org.apache.commons.lang3.ArrayUtils; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -136,7 +135,6 @@ public class MethodParamPadCheckTest TokenTypes.METHOD_DEF, TokenTypes.SUPER_CTOR_CALL, }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/SeparatorWrapCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/SeparatorWrapCheckTest.java index 9b246c3cc..a94436fab 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/SeparatorWrapCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/SeparatorWrapCheckTest.java @@ -68,7 +68,6 @@ public class SeparatorWrapCheckTest TokenTypes.DOT, TokenTypes.COMMA, }; - Assert.assertNotNull(actual); Assert.assertArrayEquals(expected, actual); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/TypecastParenPadCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/TypecastParenPadCheckTest.java index a236f0622..a3e04a1bc 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/TypecastParenPadCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/TypecastParenPadCheckTest.java @@ -83,7 +83,6 @@ public class TypecastParenPadCheckTest TokenTypes.RPAREN, TokenTypes.TYPECAST, }; - Assert.assertNotNull(actual); Assert.assertArrayEquals(expected, actual); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/WhitespaceAroundTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/WhitespaceAroundTest.java index 5e581c794..130d58466 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/WhitespaceAroundTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/WhitespaceAroundTest.java @@ -24,7 +24,6 @@ import static com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAround import static org.junit.Assert.assertArrayEquals; import org.apache.commons.lang3.ArrayUtils; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -281,7 +280,6 @@ public class WhitespaceAroundTest TokenTypes.TYPE_EXTENSION_AND, TokenTypes.WILDCARD_TYPE, }; - Assert.assertNotNull(actual); assertArrayEquals(expected, actual); } }