diff options
author | Matteo Mara <matteo.mara@sonarsource.com> | 2023-12-04 12:50:58 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-12-04 20:03:22 +0000 |
commit | d62a56ecfd4cf2f183873900fd32cffc4743c7fb (patch) | |
tree | 552481ceb8b8cab34f74b59563b58278ffa62f69 /sonar-testing-harness | |
parent | cdda3dbcdd4e4b5f4a2e7471a37fa66877e26aad (diff) | |
download | sonarqube-d62a56ecfd4cf2f183873900fd32cffc4743c7fb.tar.gz sonarqube-d62a56ecfd4cf2f183873900fd32cffc4743c7fb.zip |
SONAR-21174 Fix code smells raised after dropping JDK11 support
Diffstat (limited to 'sonar-testing-harness')
4 files changed, 11 insertions, 14 deletions
diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/JsonComparison.java b/sonar-testing-harness/src/main/java/org/sonar/test/JsonComparison.java index d242008e947..37f1b6a98cb 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/JsonComparison.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/JsonComparison.java @@ -93,17 +93,17 @@ class JsonComparison { if (expectedObject.getClass() != actualObject.getClass()) { return false; } - if (expectedObject instanceof JSONArray) { - return compareArrays((JSONArray) expectedObject, (JSONArray) actualObject); + if (expectedObject instanceof JSONArray jsonArray) { + return compareArrays(jsonArray, (JSONArray) actualObject); } - if (expectedObject instanceof JSONObject) { - return compareObjects((JSONObject) expectedObject, (JSONObject) actualObject); + if (expectedObject instanceof JSONObject jsonObject) { + return compareObjects(jsonObject, (JSONObject) actualObject); } - if (expectedObject instanceof String) { - return compareStrings((String) expectedObject, (String) actualObject); + if (expectedObject instanceof String string) { + return compareStrings(string, (String) actualObject); } - if (expectedObject instanceof Number) { - return compareNumbers((Number) expectedObject, (Number) actualObject); + if (expectedObject instanceof Number number) { + return compareNumbers(number, (Number) actualObject); } return compareBooleans((Boolean) expectedObject, (Boolean) actualObject); } diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/html/HtmlFragmentAssert.java b/sonar-testing-harness/src/main/java/org/sonar/test/html/HtmlFragmentAssert.java index 7f460b60a60..09bc63b804b 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/html/HtmlFragmentAssert.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/html/HtmlFragmentAssert.java @@ -26,7 +26,6 @@ import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; -import static java.util.stream.Collectors.toList; import static org.sonar.test.html.HtmlParagraphAssert.verifyIsParagraph; public class HtmlFragmentAssert extends AbstractAssert<HtmlFragmentAssert, String> { @@ -45,7 +44,7 @@ public class HtmlFragmentAssert extends AbstractAssert<HtmlFragmentAssert, Strin Document document = Jsoup.parseBodyFragment(actual); Iterator<Element> blockIt = document.body().children().stream() .filter(Element::isBlock) - .collect(toList()) + .toList() .iterator(); Assertions.assertThat(blockIt.hasNext()) .describedAs("no bloc in fragment") diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/html/HtmlListAssert.java b/sonar-testing-harness/src/main/java/org/sonar/test/html/HtmlListAssert.java index b1bf37e209f..cbb9e21dada 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/html/HtmlListAssert.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/html/HtmlListAssert.java @@ -22,7 +22,6 @@ package org.sonar.test.html; import java.util.Arrays; import java.util.Iterator; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.assertj.core.api.Assertions; import org.jsoup.nodes.Element; @@ -53,7 +52,7 @@ public class HtmlListAssert extends HtmlBlockAssert<HtmlListAssert> { .stream() .filter(t -> t.tagName().equals("li")) .map(Element::text) - .collect(Collectors.toList()); + .toList(); String[] itemTexts = Stream.concat( Stream.of(firstItemText), diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/html/HtmlParagraphAssert.java b/sonar-testing-harness/src/main/java/org/sonar/test/html/HtmlParagraphAssert.java index f00d1d46deb..0e2d59d11c1 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/html/HtmlParagraphAssert.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/html/HtmlParagraphAssert.java @@ -153,8 +153,7 @@ public class HtmlParagraphAssert extends HtmlBlockAssert<HtmlParagraphAssert> { } else { currentLine.append(node.toString()); } - } else if (node instanceof Element) { - Element element = (Element) node; + } else if (node instanceof Element element) { if (element.tagName().equals("br")) { actualLines.add(currentLine == null ? "" : currentLine.toString()); currentLine = null; |