From ba319d0af7c634c5d607cd9b979f21f0e475df9e Mon Sep 17 00:00:00 2001 From: Jonah Jeleniewski Date: Mon, 1 Jul 2024 17:06:29 +1000 Subject: [PATCH] Fix sonar issues in test code --- .../delphi/checks/ForbiddenIdentifierCheckTest.java | 2 +- .../com/integradev/delphi/antlr/ast/DelphiNodeUtils.java | 8 ++++---- .../delphi/symbol/resolve/InvocationResolverTest.java | 8 ++++---- .../symbol/resolve/OperatorOverloadResolutionTest.java | 2 ++ .../au/com/integradev/delphi/IntegrationTestSuite.java | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/delphi-checks/src/test/java/au/com/integradev/delphi/checks/ForbiddenIdentifierCheckTest.java b/delphi-checks/src/test/java/au/com/integradev/delphi/checks/ForbiddenIdentifierCheckTest.java index c180a4570..d8d333b2a 100644 --- a/delphi-checks/src/test/java/au/com/integradev/delphi/checks/ForbiddenIdentifierCheckTest.java +++ b/delphi-checks/src/test/java/au/com/integradev/delphi/checks/ForbiddenIdentifierCheckTest.java @@ -24,7 +24,7 @@ import org.sonar.plugins.communitydelphi.api.check.DelphiCheck; class ForbiddenIdentifierCheckTest { - private static String FORBIDDEN_IDENTIFIER = "BadName"; + private static final String FORBIDDEN_IDENTIFIER = "BadName"; private static DelphiCheck createCheck() { ForbiddenIdentifierCheck check = new ForbiddenIdentifierCheck(); diff --git a/delphi-frontend/src/test/java/au/com/integradev/delphi/antlr/ast/DelphiNodeUtils.java b/delphi-frontend/src/test/java/au/com/integradev/delphi/antlr/ast/DelphiNodeUtils.java index fb6fca99e..3e9e9007a 100644 --- a/delphi-frontend/src/test/java/au/com/integradev/delphi/antlr/ast/DelphiNodeUtils.java +++ b/delphi-frontend/src/test/java/au/com/integradev/delphi/antlr/ast/DelphiNodeUtils.java @@ -55,7 +55,7 @@ public final class DelphiNodeUtils { public static final DescribedPredicate IMPLEMENT_ACCEPT = new DescribedPredicate<>("have a method that implements accept(DelphiParserVisitor, T)") { - private final Class[] ACCEPT_PARAMETERS = {DelphiParserVisitor.class, Object.class}; + private final Class[] acceptParameters = {DelphiParserVisitor.class, Object.class}; @Override public boolean test(JavaClass javaClass) { @@ -65,14 +65,14 @@ public boolean test(JavaClass javaClass) { private boolean isAcceptMethodImplementation(JavaMethod javaMethod) { Method method = javaMethod.reflect(); return method.getName().equals("accept") - && Arrays.equals(method.getParameterTypes(), ACCEPT_PARAMETERS) + && Arrays.equals(method.getParameterTypes(), acceptParameters) && !Modifier.isAbstract(method.getModifiers()); } }; public static final ArchCondition HAVE_TOKEN_CONSTRUCTOR = new ArchCondition<>("have a public constructor(Token)") { - private final Class[] TOKEN_PARAMETER = {Token.class}; + private final Class[] tokenParameter = {Token.class}; @Override public void check(JavaClass javaClass, ConditionEvents events) { @@ -81,7 +81,7 @@ public void check(JavaClass javaClass, ConditionEvents events) { .map(JavaConstructor::reflect) .anyMatch( constructor -> - Arrays.equals(constructor.getParameterTypes(), TOKEN_PARAMETER)); + Arrays.equals(constructor.getParameterTypes(), tokenParameter)); String message = javaClass diff --git a/delphi-frontend/src/test/java/au/com/integradev/delphi/symbol/resolve/InvocationResolverTest.java b/delphi-frontend/src/test/java/au/com/integradev/delphi/symbol/resolve/InvocationResolverTest.java index ca0c2fada..f02fbf3e9 100644 --- a/delphi-frontend/src/test/java/au/com/integradev/delphi/symbol/resolve/InvocationResolverTest.java +++ b/delphi-frontend/src/test/java/au/com/integradev/delphi/symbol/resolve/InvocationResolverTest.java @@ -166,11 +166,11 @@ void testIntegerTypes() { assertResolved(type(INTEGER), type(WORD), type(BYTE)); assertResolved(type(SHORTINT), type(NATIVEINT), type(NATIVEUINT)); - Type HWND = FACTORY.strongAlias("HWND", type(NATIVEUINT)); + Type hwnd = FACTORY.strongAlias("HWND", type(NATIVEUINT)); assertResolved( - List.of(HWND, type(NATIVEUINT), type(SHORTINT), type(SHORTINT)), - List.of(HWND, type(NATIVEUINT), type(NATIVEINT), type(NATIVEINT)), - List.of(HWND, type(NATIVEUINT), type(NATIVEUINT), type(NATIVEINT))); + List.of(hwnd, type(NATIVEUINT), type(SHORTINT), type(SHORTINT)), + List.of(hwnd, type(NATIVEUINT), type(NATIVEINT), type(NATIVEINT)), + List.of(hwnd, type(NATIVEUINT), type(NATIVEUINT), type(NATIVEINT))); assertResolved(type(BYTE), type(INTEGER), type(DOUBLE)); diff --git a/delphi-frontend/src/test/java/au/com/integradev/delphi/symbol/resolve/OperatorOverloadResolutionTest.java b/delphi-frontend/src/test/java/au/com/integradev/delphi/symbol/resolve/OperatorOverloadResolutionTest.java index e4e7a94ce..97177245d 100644 --- a/delphi-frontend/src/test/java/au/com/integradev/delphi/symbol/resolve/OperatorOverloadResolutionTest.java +++ b/delphi-frontend/src/test/java/au/com/integradev/delphi/symbol/resolve/OperatorOverloadResolutionTest.java @@ -421,6 +421,8 @@ private static Type getType(String name) { return ((TypeFactoryImpl) TYPE_FACTORY).anonymousUInt31(); case "Extended": return TYPE_FACTORY.getIntrinsic(IntrinsicType.EXTENDED); + default: + // do nothing } if (name.endsWith("_Subrange")) { diff --git a/its/src/test/java/au/com/integradev/delphi/IntegrationTestSuite.java b/its/src/test/java/au/com/integradev/delphi/IntegrationTestSuite.java index 527143ec0..16ea25840 100644 --- a/its/src/test/java/au/com/integradev/delphi/IntegrationTestSuite.java +++ b/its/src/test/java/au/com/integradev/delphi/IntegrationTestSuite.java @@ -48,7 +48,7 @@ class IntegrationTestSuite { new File("../sonar-delphi-plugin/target"), "sonar-delphi-plugin-*.jar"); @RegisterExtension - static OrchestratorExtension ORCHESTRATOR = + static final OrchestratorExtension ORCHESTRATOR = OrchestratorExtension.builderEnv() .useDefaultAdminCredentialsForBuilds(true) .setSonarVersion(System.getProperty("sonar.runtimeVersion", "LATEST_RELEASE"))