From d62a56ecfd4cf2f183873900fd32cffc4743c7fb Mon Sep 17 00:00:00 2001 From: Matteo Mara Date: Mon, 4 Dec 2023 12:50:58 +0100 Subject: SONAR-21174 Fix code smells raised after dropping JDK11 support --- .../src/main/java/org/sonar/test/JsonComparison.java | 16 ++++++++-------- .../java/org/sonar/test/html/HtmlFragmentAssert.java | 3 +-- .../main/java/org/sonar/test/html/HtmlListAssert.java | 3 +-- .../java/org/sonar/test/html/HtmlParagraphAssert.java | 3 +-- 4 files changed, 11 insertions(+), 14 deletions(-) (limited to 'sonar-testing-harness') 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 { @@ -45,7 +44,7 @@ public class HtmlFragmentAssert extends AbstractAssert 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 { .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 { } 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; -- cgit v1.2.3