Skip to content

Commit

Permalink
Remove test only method
Browse files Browse the repository at this point in the history
  • Loading branch information
zglicz committed Oct 30, 2024
1 parent caa496b commit 7c88723
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
*/
package org.sonar.plugins.javascript.sonarlint;

import javax.annotation.Nullable;
import org.sonar.api.batch.sensor.SensorContext;

public interface SonarLintTypeCheckingChecker {
void checkOnce(SensorContext context);
boolean isBeyondLimit(SensorContext context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ public boolean isBeyondLimit(SensorContext context) {
return beyondLimit;
}

public void checkOnce(SensorContext context) {
if (shouldCheck) {
checkLimit(context);
shouldCheck = false;
}
}

private void checkLimit(SensorContext context) {
try {
var typeCheckingLimit = getTypeCheckingLimit(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ void should_check_javascript_files() throws IOException {
inputFile("file.css");
inputFile("file.d.ts");
inputFile("node_modules", "dep.js");
var checker = sonarLintTypeCheckingChecker(2);

assertThat(checker.isBeyondLimit(SensorContextTester.create(baseDir))).isFalse();
var checker = new SonarLintTypeCheckingCheckerImpl();
assertThat(checker.isBeyondLimit(sensorContext(3))).isFalse();
assertThat(logTester.logs()).contains("Turning on type-checking of JavaScript files");
}

Expand All @@ -67,9 +67,9 @@ void should_detect_projects_with_too_many_files() throws IOException {
inputFile("file2.ts");
inputFile("file3.cjs");
inputFile("file4.cts");
var checker = sonarLintTypeCheckingChecker(3);
var checker = new SonarLintTypeCheckingCheckerImpl();

assertThat(checker.isBeyondLimit(SensorContextTester.create(baseDir))).isTrue();
assertThat(checker.isBeyondLimit(sensorContext(3))).isTrue();
assertThat(logTester.logs())
.contains(
"Turning off type-checking of JavaScript files due to the project size exceeding the limit (3 files)",
Expand All @@ -83,27 +83,15 @@ void should_detect_projects_with_too_many_files() throws IOException {
@Test
void should_detect_errors() {
logTester.setLevel(LoggerLevel.WARN);
var checker = sonarLintTypeCheckingChecker(new IllegalArgumentException());
var checker = new SonarLintTypeCheckingCheckerImpl();
var context = sensorContext();
when(context.fileSystem().baseDir()).thenThrow(new IllegalArgumentException());

assertThat(checker.isBeyondLimit(SensorContextTester.create(baseDir))).isTrue();
assertThat(checker.isBeyondLimit(context)).isTrue();
assertThat(logTester.logs())
.containsExactly("Turning off type-checking of JavaScript files due to unexpected error");
}

private SonarLintTypeCheckingChecker sonarLintTypeCheckingChecker(int maxFiles) {
var checker = new SonarLintTypeCheckingCheckerImpl();
checker.checkOnce(sensorContext(maxFiles));
return checker;
}

private SonarLintTypeCheckingChecker sonarLintTypeCheckingChecker(RuntimeException error) {
var checker = new SonarLintTypeCheckingCheckerImpl();
var context = sensorContext();
when(context.fileSystem().baseDir()).thenThrow(error);
checker.checkOnce(context);
return checker;
}

private SensorContext sensorContext() {
return sensorContext(DEFAULT_MAX_FILES_FOR_TYPE_CHECKING);
}
Expand Down

0 comments on commit 7c88723

Please sign in to comment.