Skip to content

Commit 49a84de

Browse files
ghislainpiotsonartech
authored andcommitted
SONARPY-3147 Remove deprecated method calls from RuffSensorTest (#358)
GitOrigin-RevId: f25333135cf6b464d7e646ce8936dc6c3811227b
1 parent 1504979 commit 49a84de

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

python-commons/src/test/java/org/sonar/plugins/python/ruff/RuffSensorTest.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,14 @@
1616
*/
1717
package org.sonar.plugins.python.ruff;
1818

19-
import static java.nio.charset.StandardCharsets.UTF_8;
20-
import static org.assertj.core.api.Assertions.assertThat;
21-
2219
import java.io.IOException;
2320
import java.nio.file.Files;
2421
import java.nio.file.Path;
2522
import java.nio.file.Paths;
2623
import java.util.ArrayList;
2724
import java.util.List;
2825
import java.util.stream.Stream;
29-
3026
import javax.annotation.Nullable;
31-
3227
import org.junit.jupiter.api.Test;
3328
import org.junit.jupiter.api.extension.RegisterExtension;
3429
import org.slf4j.event.Level;
@@ -46,7 +41,9 @@
4641
import org.sonar.api.rules.RuleType;
4742
import org.sonar.api.testfixtures.log.LogTesterJUnit5;
4843
import org.sonar.api.utils.Version;
49-
import org.sonar.api.utils.log.LoggerLevel;
44+
45+
import static java.nio.charset.StandardCharsets.UTF_8;
46+
import static org.assertj.core.api.Assertions.assertThat;
5047

5148
class RuffSensorTest {
5249

@@ -118,7 +115,7 @@ void issues_with_json_format() throws IOException {
118115
assertThat(secondTextRange.end().lineOffset()).isEqualTo(42);
119116

120117
assertNoErrorWarnLogs(logTester);
121-
assertThat(logTester.logs(LoggerLevel.DEBUG)).isEmpty();
118+
assertThat(logTester.logs(Level.DEBUG)).isEmpty();
122119

123120
}
124121

@@ -144,7 +141,7 @@ void issues_primary_location_check() throws IOException {
144141
assertThat(secondToLastPrimaryLoc.message()).isEqualTo("`try`-`except`-`pass` detected, consider logging the exception");
145142

146143
assertNoErrorWarnLogs(logTester);
147-
assertThat(logTester.logs(LoggerLevel.DEBUG)).isEmpty();
144+
assertThat(logTester.logs(Level.DEBUG)).isEmpty();
148145

149146
}
150147

@@ -169,7 +166,7 @@ void issues_multiline_check() throws IOException {
169166
assertThat(lastTextRange.end().lineOffset()).isEqualTo(5);
170167

171168
assertNoErrorWarnLogs(logTester);
172-
assertThat(logTester.logs(LoggerLevel.DEBUG)).isEmpty();
169+
assertThat(logTester.logs(Level.DEBUG)).isEmpty();
173170

174171
}
175172

@@ -220,7 +217,7 @@ void unknown_json_file_path() throws IOException {
220217
List<ExternalIssue> externalIssues = executeSensorImporting(7, 9, RUFF_REPORT_UNKNOWN_FILES);
221218
assertThat(externalIssues).hasSize(1);
222219

223-
assertThat(onlyOneLogElement(logTester.logs(LoggerLevel.WARN)))
220+
assertThat(onlyOneLogElement(logTester.logs(Level.WARN)))
224221
.isEqualTo(
225222
"Failed to resolve 1 file path(s) in Ruff report. No issues imported related to file(s): unknown/file.py");
226223
}
@@ -237,12 +234,12 @@ void missing_rule_key_file_name_or_message() throws IOException {
237234
List<ExternalIssue> externalIssues = executeSensorImporting(7, 9, "missing-fields.json");
238235
assertThat(externalIssues).hasSize(1);
239236

240-
assertThat(logTester.logs(LoggerLevel.DEBUG)).hasSize(3);
241-
assertThat(logTester.logs(LoggerLevel.DEBUG).get(0))
237+
assertThat(logTester.logs(Level.DEBUG)).hasSize(3);
238+
assertThat(logTester.logs(Level.DEBUG).get(0))
242239
.startsWith("Missing information for ruleKey:'null',");
243-
assertThat(logTester.logs(LoggerLevel.DEBUG).get(1))
240+
assertThat(logTester.logs(Level.DEBUG).get(1))
244241
.contains("filePath:'null'");
245-
assertThat(logTester.logs(LoggerLevel.DEBUG).get(2))
242+
assertThat(logTester.logs(Level.DEBUG).get(2))
246243
.contains("message:'null'");
247244
}
248245

@@ -251,7 +248,7 @@ void no_issues_with_invalid_report_path() throws IOException {
251248
List<ExternalIssue> externalIssues = executeSensorImporting(7, 9, "invalid-path.json");
252249
assertThat(externalIssues).isEmpty();
253250

254-
assertThat(onlyOneLogElement(logTester.logs(LoggerLevel.ERROR)))
251+
assertThat(onlyOneLogElement(logTester.logs(Level.ERROR)))
255252
.startsWith("No issues information will be saved as the report file '")
256253
.contains("invalid-path.json' can't be read.");
257254
}
@@ -264,7 +261,7 @@ void no_issues_with_empty_or_invalid_ruff_file() throws IOException {
264261

265262
externalIssues = executeSensorImporting(7, 9, "ruff-invalid-file.json");
266263
assertThat(externalIssues).isEmpty();
267-
assertThat(onlyOneLogElement(logTester.logs(LoggerLevel.ERROR)))
264+
assertThat(onlyOneLogElement(logTester.logs(Level.ERROR)))
268265
.startsWith("No issues information will be saved as the report file '")
269266
.contains("ruff-invalid-file.json' can't be read.");
270267
}
@@ -348,8 +345,8 @@ public static String onlyOneLogElement(List<String> elements) {
348345
}
349346

350347
public static void assertNoErrorWarnLogs(LogTesterJUnit5 logTester) {
351-
assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty();
352-
assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
348+
assertThat(logTester.logs(Level.ERROR)).isEmpty();
349+
assertThat(logTester.logs(Level.WARN)).isEmpty();
353350
}
354351

355352
}

0 commit comments

Comments
 (0)