From 854ca2fb8605ad4845d73a2bb3debb4c140b5ba1 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Wed, 16 Sep 2026 08:28:22 +0300 Subject: [PATCH] Fixed sonar warnings --- .../com/github/underscore/ArraysTest.java | 2 +- .../github/underscore/CollectionsTest.java | 14 ++++--- .../com/github/underscore/LodashTest.java | 37 ++++++++++--------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/test/java/com/github/underscore/ArraysTest.java b/src/test/java/com/github/underscore/ArraysTest.java index b2c9e051..416c366a 100644 --- a/src/test/java/com/github/underscore/ArraysTest.java +++ b/src/test/java/com/github/underscore/ArraysTest.java @@ -765,7 +765,7 @@ public Person(final String name, final Integer age) { } public int compareTo(Person person) { - return person.age - this.age; + return Integer.compare(person.age, this.age); } public String toString() { diff --git a/src/test/java/com/github/underscore/CollectionsTest.java b/src/test/java/com/github/underscore/CollectionsTest.java index d7e8f0b2..286835a7 100644 --- a/src/test/java/com/github/underscore/CollectionsTest.java +++ b/src/test/java/com/github/underscore/CollectionsTest.java @@ -1282,22 +1282,26 @@ void sortWith() { Underscore.sortWith( asList(1, 2, 3, 4, 5, 6), (item1, item2) -> - (int) (Math.sin(item1) * 1000) - (int) (Math.sin(item2) * 1000)); + Integer.compare( + (int) (Math.sin(item1) * 1000), + (int) (Math.sin(item2) * 1000))); assertEquals("[5, 4, 6, 3, 1, 2]", result.toString()); final List resultObj = new Underscore<>(asList(1, 2, 3, 4, 5, 6)) .sortWith( (item1, item2) -> - (int) (Math.sin(item1) * 1000) - - (int) (Math.sin(item2) * 1000)); + Integer.compare( + (int) (Math.sin(item1) * 1000), + (int) (Math.sin(item2) * 1000))); assertEquals("[5, 4, 6, 3, 1, 2]", resultObj.toString()); final List resultChain = Underscore.chain(asList(1, 2, 3, 4, 5, 6)) .sortWith( (Comparator) (item1, item2) -> - (int) (Math.sin(item1) * 1000) - - (int) (Math.sin(item2) * 1000)) + Integer.compare( + (int) (Math.sin(item1) * 1000), + (int) (Math.sin(item2) * 1000))) .value(); assertEquals("[5, 4, 6, 3, 1, 2]", resultChain.toString()); } diff --git a/src/test/java/com/github/underscore/LodashTest.java b/src/test/java/com/github/underscore/LodashTest.java index 40f16fb6..e86f1b2b 100644 --- a/src/test/java/com/github/underscore/LodashTest.java +++ b/src/test/java/com/github/underscore/LodashTest.java @@ -742,8 +742,7 @@ void fetchPut() { null); assertEquals(404, result2.getStatus()); U.Chain resultChain = - U.chain( - "http://www.w3schools.com/xml/note.xml") + U.chain("http://www.w3schools.com/xml/note.xml") .fetch( "PUT", "{" @@ -1180,20 +1179,22 @@ void xmpToJson7() { } @ParameterizedTest(name = "{0}") - @CsvSource(delimiter = '|', value = { - // input | expected (k=v,k=v) - "key=\"value\" | key=value", - "key='value' | key=value", - "a=\"1\" b='2' | a=1,b=2", - "key=\"it's a value\" | key=it's a value", - "key='say \"hi\"' | key=say \"hi\"", - "key=\"a=b=c\" | key=a=b=c", - "key=\"\" | key=", - " key =\"value\" | key=value", - "data-id=\"5\" | data-id=5", - "x==\"y\" | x=y", - "k=\"first\" k=\"second\" | k=second", - }) + @CsvSource( + delimiter = '|', + value = { + // input | expected (k=v,k=v) + "key=\"value\" | key=value", + "key='value' | key=value", + "a=\"1\" b='2' | a=1,b=2", + "key=\"it's a value\" | key=it's a value", + "key='say \"hi\"' | key=say \"hi\"", + "key=\"a=b=c\" | key=a=b=c", + "key=\"\" | key=", + " key =\"value\" | key=value", + "data-id=\"5\" | data-id=5", + "x==\"y\" | x=y", + "k=\"first\" k=\"second\" | k=second", + }) void parses(String input, String expected) { assertEquals(parse(expected), Xml.parseAttributes(input)); } @@ -1211,8 +1212,8 @@ void producesNothing(String input) { @Test void preservesInsertionOrder() { - assertEquals("[z, a, m]", - Xml.parseAttributes("z=\"1\" a=\"2\" m=\"3\"").keySet().toString()); + assertEquals( + "[z, a, m]", Xml.parseAttributes("z=\"1\" a=\"2\" m=\"3\"").keySet().toString()); } // builds expected map from "k=v,k=v"