Skip to content

Commit

Permalink
Merge pull request #2850 from guwirth/td-24
Browse files Browse the repository at this point in the history
fix technical debt
  • Loading branch information
guwirth authored Jan 14, 2025
2 parents f1a27eb + a1351b4 commit 74e5db5
Show file tree
Hide file tree
Showing 40 changed files with 64 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class UndocumentedApiCheckTest {

public CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();
private final CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();

@SuppressWarnings("squid:S2699")
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class FileNameCheckTest {

public CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();
private final CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();
private final FileNameCheck check = new FileNameCheck();

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class FixmeTagPresenceCheckTest {

public CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();
private final CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();

@Test
@SuppressWarnings("squid:S2699") // ... verify contains the assertion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class TodoTagPresenceCheckTest {

public CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();
private final CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();

@Test
@SuppressWarnings("squid:S2699") // ... verify contains the assertion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
class FinalReportTest {

@RegisterExtension
public LogTesterJUnit5 logTester = new LogTesterJUnit5();
private final LogTesterJUnit5 logTester = new LogTesterJUnit5();

private PostJobContext postJobContext;

@BeforeEach
public void scanFile() {
public void setUp() {
postJobContext = Mockito.mock(PostJobContext.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
class XlstSensorTest {

@RegisterExtension
public LogTesterJUnit5 logTester = new LogTesterJUnit5();
private final LogTesterJUnit5 logTester = new LogTesterJUnit5();

private FileSystem fs;
private final MapSettings settings = new MapSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
class CxxCompilerSensorTest {

@RegisterExtension
public LogTesterJUnit5 logTester = new LogTesterJUnit5();
private final LogTesterJUnit5 logTester = new LogTesterJUnit5();

private DefaultFileSystem fs;
private final MapSettings settings = new MapSettings();
Expand Down Expand Up @@ -98,6 +98,7 @@ public CxxCompilerSensorMock(SensorContext context) {

@Override
public void describe(SensorDescriptor descriptor) {
// dummy
}

public void testExecuteReport(File report) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
class CxxCoberturaSensorTest {

@RegisterExtension
public LogTesterJUnit5 logTester = new LogTesterJUnit5();
private final LogTesterJUnit5 logTester = new LogTesterJUnit5();

private DefaultFileSystem fs;
private final Map<InputFile, Set<Integer>> linesOfCodeByFile = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
class CxxMSCoverageSensorTest {

@RegisterExtension
public LogTesterJUnit5 logTester = new LogTesterJUnit5();
private final LogTesterJUnit5 logTester = new LogTesterJUnit5();

private DefaultFileSystem fs;
private SensorContextTester context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
class CxxOtherSensorTest {

@RegisterExtension
public LogTesterJUnit5 logTester = new LogTesterJUnit5();
private final LogTesterJUnit5 logTester = new LogTesterJUnit5();

private CxxOtherSensor sensor;
private DefaultFileSystem fs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class NUnitTestResultsFileParserTest {
= "src/test/resources/org/sonar/cxx/sensors/reports-project/xunit-reports/nunit/";

@RegisterExtension
public LogTesterJUnit5 logTester = new LogTesterJUnit5();
private final LogTesterJUnit5 logTester = new LogTesterJUnit5();

@Test
void noCounters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static Set<File> listFiles(String pattern, File baseDir) {
}

@BeforeEach
public void init() throws Exception {
public void setUp() throws Exception {
Path root = tempDir.toPath();

Files.createFile(root.resolve("foo.txt"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CxxReportSensorTest {
private final MapSettings settings = new MapSettings();

@BeforeEach
public void init() {
public void setUp() {
TestUtils.mockFileSystem();
try {
baseDir = new File(getClass().getResource("/org/sonar/cxx/sensors/reports-project/").toURI());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import org.sonar.api.server.impl.RulesDefinitionContext;
import org.sonar.api.server.rule.RulesDefinition;

public class RulesDefinitionXmlLoaderTest {
class RulesDefinitionXmlLoaderTest {

RulesDefinitionXmlLoader underTest = new RulesDefinitionXmlLoader();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@
import com.google.common.collect.Sets;
import java.lang.annotation.Annotation;
import java.net.URL;
import java.util.*;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.server.rule.*;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.api.server.rule.RulesDefinition.NewRepository;
import org.sonar.api.server.rule.RulesDefinition.NewRule;
import org.sonar.api.server.rule.RulesDefinitionAnnotationLoader;
import org.sonar.api.utils.AnnotationUtils;
import org.sonar.check.Cardinality;
import org.sonar.check.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SourceCodeTest {
private SourceCode sourceClass2;

@BeforeEach
public void before() {
public void setUp() {
sourceProject = new SourceProject("ProjectKey", "Demo");
sourceFile1 = new SourceFile("src/test/FileName1.cpp", "FileName1.cpp");
sourceFile2 = new SourceFile("src/test/FileName2.cpp", "FileName2.cpp");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class AbstractCommentRegularExpressionCheckTest {

public CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();
private final CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();

private static class Check extends AbstractCommentRegularExpressionCheck<Grammar> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

class AbstractOneStatementPerLineCheckTest {

public CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();
private final CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();

private static class Check extends AbstractOneStatementPerLineCheck<Grammar> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class AbstractXPathCheckTest {

public CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();
private final CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();

private static class Check extends AbstractXPathCheck<Grammar> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SquidIndexTest {
private SourceCode sourceClass;

@BeforeEach
public void setup() {
public void setUp() {
indexer = new SquidIndex();
sourceProject = new SourceProject("ProjectKey", "Project Name");
indexer.index(sourceProject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class FakeCommentCheckTest {

public CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();
private final CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();

private class FakeCommentCheck extends SquidCheck<Grammar> implements AstAndTokenVisitor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ void shouldHandleSpecificCommonOptionsCorrectly() {
softly.assertAll();
}

public void shouldHandleSpecificCommonWin32OptionsCorrectly() {
@Test
void shouldHandleSpecificCommonWin32OptionsCorrectly() {
var squidConfig = new CxxSquidConfiguration();
var files = new ArrayList<File>();
files.add(new File("src/test/resources/msbuild/platformCommonWin32.txt"));
Expand All @@ -457,7 +458,7 @@ public void shouldHandleSpecificCommonWin32OptionsCorrectly() {
var softly = new SoftAssertions();
softly.assertThat(getIncludeDirectories(squidConfig)).isEmpty();
List<String> defines = getDefines(squidConfig);
softly.assertThat(defines).hasSize(3);
softly.assertThat(defines).hasSize(16);
ValidateDefaultAsserts(softly, defines);
softly.assertThat(defines).contains("_WIN32");
softly.assertAll();
Expand Down
6 changes: 3 additions & 3 deletions cxx-squid/src/test/java/org/sonar/cxx/config/MsBuildTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
*/
class MsBuildTest {

public static final String REFERENCE_DETAILED_LOG = "src/test/resources/msbuild/msbuild-detailed-en.txt";
public static final String UNIQUE_FILE = "C:\\Development\\Source\\Cpp\\Dummy\\src\\main.cpp";
private static final String REFERENCE_DETAILED_LOG = "src/test/resources/msbuild/msbuild-detailed-en.txt";
private static final String UNIQUE_FILE = "C:\\Development\\Source\\Cpp\\Dummy\\src\\main.cpp";
private static final String VC_CHARSET = "UTF8";

@BeforeAll
public static void init() {
public static void setUp() {
Assumptions.assumeTrue(SystemUtils.IS_OS_WINDOWS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CxxLexerTest {
private Lexer lexer;

@BeforeEach
public void init() {
public void setUp() {
var file = new File("snippet.cpp").getAbsoluteFile();
SquidAstVisitorContext<Grammar> context = mock(SquidAstVisitorContext.class);
when(context.getFile()).thenReturn(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CxxLexerWithPreprocessingTest {
private SquidAstVisitorContext<Grammar> context;

@BeforeEach
public void init() {
public void setUp() {
var file = new File("snippet.cpp").getAbsoluteFile();
context = mock(SquidAstVisitorContext.class);
when(context.getFile()).thenReturn(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CxxLexerWithoutPreprocessorTest {
private Lexer lexer;

@BeforeEach
public void init() {
public void setUp() {
lexer = CxxLexerPool.create().getLexer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,11 @@ void compoundRequirement() {
.matches("{ expression } noexcept returnTypeRequirement ;");
}

public void returnTypeRequirement() {
@Test
void returnTypeRequirement() {
setRootRule(CxxGrammarImpl.returnTypeRequirement);

mockRule(CxxGrammarImpl.typeConstraint);

assertThatParser()
.matches("-> typeConstraint");
assertThatParser().matches("-> typeConstraint");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;

public class CxxReportLocationTest {
class CxxReportLocationTest {

@Test
void testConstructor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CxxCpdVisitorTest {
private SourceFile sourceFile;

@BeforeEach
public void scanFile() throws IOException {
public void setUp() throws IOException {
var tester = CxxFileTesterHelper.create("src/test/resources/visitors/cpd.cc", ".", "");
var squidConfig = new CxxSquidConfiguration();
squidConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.sonar.api.testfixtures.log.LogTesterJUnit5;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTesterJUnit5;
import org.sonar.cxx.CxxAstScanner;
import org.sonar.cxx.CxxFileTesterHelper;

class CxxParseErrorLoggerVisitorTest {

@RegisterExtension
public LogTesterJUnit5 logTester = new LogTesterJUnit5();
private final LogTesterJUnit5 logTester = new LogTesterJUnit5();

@Test
void handleParseErrorTest() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AstWalkerTest {
private final AstAndTokenVisitor astAndTokenVisitor = mock(AstAndTokenVisitor.class);

@BeforeEach
public void init() {
public void setUp() {
token = mock(Token.class);
when(token.getType()).thenReturn(MockTokenType.WORD);
when(token.getValue()).thenReturn("word");
Expand Down Expand Up @@ -123,6 +123,12 @@ void testAddVisitor() {

walker1.addVisitor(visitor1);
walker1.addVisitor(visitor2);
walker1.walkAndVisit(astNodeWithToken);

verify(visitor1).visitFile(astNodeWithToken);
verify(visitor1).leaveFile(astNodeWithToken);
verify(visitor2).visitFile(astNodeWithToken);
verify(visitor2).leaveFile(astNodeWithToken);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ExpressionTest extends RuleTest {

@Override
@BeforeEach
public void init() {
public void setUp() {
p.setRootRule(g.rule(MiniCGrammar.EXPRESSION));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public final Rule getTestedRule() {
return p.getRootRule();
}

public abstract void init();
public abstract void setUp();

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class StructTest extends RuleTest {

@Override
@BeforeEach
public void init() {
public void setUp() {
p.setRootRule(g.rule(MiniCGrammar.STRUCT_DEFINITION));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BasicQueriesTest {
private AstNode fileNode;

@BeforeEach
public void init() {
public void setUp() {
fileNode = parseFile("/xpath/basicQueries.mc");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class IdentifiersTooLongTest {
private AstNode fileNode;

@BeforeEach
public void init() {
public void setUp() {
fileNode = parseFile("/xpath/identifiersTooLong.mc");
}

Expand Down
Loading

0 comments on commit 74e5db5

Please sign in to comment.