From 004cfe32945bf2d5baef4607d5fb192e9a8b26b6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?No=C3=A9mie=20B=C3=A9nard?=
Date: Tue, 14 Apr 2026 10:55:56 +0200
Subject: [PATCH 1/7] add assertion detection for ApproveJ testing library
---
.../AssertionsInTestsCheck/ApproveJ.java | 32 +++++++++++++++++++
.../java/checks/helpers/UnitTestUtils.java | 2 +-
.../tests/AssertionsInTestsCheckTest.java | 1 +
3 files changed, 34 insertions(+), 1 deletion(-)
create mode 100644 java-checks-test-sources/default/src/test/java/checks/tests/AssertionsInTestsCheck/ApproveJ.java
diff --git a/java-checks-test-sources/default/src/test/java/checks/tests/AssertionsInTestsCheck/ApproveJ.java b/java-checks-test-sources/default/src/test/java/checks/tests/AssertionsInTestsCheck/ApproveJ.java
new file mode 100644
index 00000000000..e7e0987e600
--- /dev/null
+++ b/java-checks-test-sources/default/src/test/java/checks/tests/AssertionsInTestsCheck/ApproveJ.java
@@ -0,0 +1,32 @@
+package checks.tests.AssertionsInTestsCheck;
+
+import java.time.LocalDate;
+import org.junit.jupiter.api.Test;
+
+import static org.approvej.ApprovalBuilder.approve;
+import static org.approvej.print.MultiLineStringPrintFormat.multiLineString;
+
+class ApproveJTest {
+
+ @Test
+ void contains_no_assertions() { // Noncompliant
+ }
+
+ public String hello() {return "hello";}
+
+ @Test
+ void approve_string() {
+ String result = hello();
+ approve(result)
+ .byFile();
+ }
+
+ public record Person(String name, LocalDate birthDate) {}
+
+ @Test
+ void approve_person() {
+ Person jane = new Person("Jane Doe", LocalDate.of(1990, 1, 1));
+ approve(jane).named("jane").printedAs(multiLineString()).byFile();
+ }
+
+}
diff --git a/java-checks/src/main/java/org/sonar/java/checks/helpers/UnitTestUtils.java b/java-checks/src/main/java/org/sonar/java/checks/helpers/UnitTestUtils.java
index c3df052ded2..cc1444a8e2c 100644
--- a/java-checks/src/main/java/org/sonar/java/checks/helpers/UnitTestUtils.java
+++ b/java-checks/src/main/java/org/sonar/java/checks/helpers/UnitTestUtils.java
@@ -41,7 +41,7 @@ public final class UnitTestUtils {
private static final String ORG_JUNIT_TEST = "org.junit.Test";
public static final Pattern ASSERTION_METHODS_PATTERN = Pattern.compile(
- "(assert|verify|fail|should|check|expect|validate|andExpect).*" +
+ "(assert|verify|fail|should|check|expect|validate|andExpect|approve).*" +
// Eclipse Vert.x with JUnit 5 (VertxTestContext)
"|laxCheckpoint|succeedingThenComplete");
private static final Pattern TEST_METHODS_PATTERN = Pattern.compile("test.*|.*Test");
diff --git a/java-checks/src/test/java/org/sonar/java/checks/tests/AssertionsInTestsCheckTest.java b/java-checks/src/test/java/org/sonar/java/checks/tests/AssertionsInTestsCheckTest.java
index 590363b3eda..e54a82a2b61 100644
--- a/java-checks/src/test/java/org/sonar/java/checks/tests/AssertionsInTestsCheckTest.java
+++ b/java-checks/src/test/java/org/sonar/java/checks/tests/AssertionsInTestsCheckTest.java
@@ -64,6 +64,7 @@ void setup() {
"JMockit",
"Awaitility",
"AssertJ",
+ "ApproveJ",
"Custom"
})
void test(String framework) {
From ac0b218ee856cc705d91a041dff068364b15eb8f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?No=C3=A9mie=20B=C3=A9nard?=
Date: Tue, 14 Apr 2026 10:56:21 +0200
Subject: [PATCH 2/7] add ApproveJ dependency
---
java-checks-test-sources/default/pom.xml | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/java-checks-test-sources/default/pom.xml b/java-checks-test-sources/default/pom.xml
index dded3d0343a..3fee4f3396f 100644
--- a/java-checks-test-sources/default/pom.xml
+++ b/java-checks-test-sources/default/pom.xml
@@ -1016,6 +1016,18 @@
junit-platform-suite
provided
+
+ org.approvej
+ core
+ 1.6.0
+ test
+
+
+ com.approvaltests
+ approvaltests
+ 30.1.0
+ test
+
From c8fc8e3c5d973a47ddc32e2d92aa4f889bbf3c81 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?No=C3=A9mie=20B=C3=A9nard?=
<163140136+NoemieBenard@users.noreply.github.com>
Date: Tue, 14 Apr 2026 13:07:47 +0200
Subject: [PATCH 3/7] Update java-checks-test-sources/default/pom.xml
Co-authored-by: sonar-review-alpha[bot] <266116024+sonar-review-alpha[bot]@users.noreply.github.com>
---
java-checks-test-sources/default/pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/java-checks-test-sources/default/pom.xml b/java-checks-test-sources/default/pom.xml
index 3fee4f3396f..fe5cccfb43b 100644
--- a/java-checks-test-sources/default/pom.xml
+++ b/java-checks-test-sources/default/pom.xml
@@ -1016,16 +1016,16 @@
junit-platform-suite
provided
+
+ org.approvej
+ core
+ 1.6.0
org.approvej
core
1.6.0
test
-
- com.approvaltests
- approvaltests
- 30.1.0
test
From e0e7d196057cd8d2f6d143dce17bf5a1dfc1fb74 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?No=C3=A9mie=20B=C3=A9nard?=
Date: Tue, 14 Apr 2026 13:12:18 +0200
Subject: [PATCH 4/7] fix pom.xml after removing dependency
---
java-checks-test-sources/default/pom.xml | 6 ------
1 file changed, 6 deletions(-)
diff --git a/java-checks-test-sources/default/pom.xml b/java-checks-test-sources/default/pom.xml
index fe5cccfb43b..5aca68eed1e 100644
--- a/java-checks-test-sources/default/pom.xml
+++ b/java-checks-test-sources/default/pom.xml
@@ -1020,12 +1020,6 @@
org.approvej
core
1.6.0
-
- org.approvej
- core
- 1.6.0
- test
-
test
From 68c5e8fcc492c23f785174a77a2b19d3c355be12 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?No=C3=A9mie=20B=C3=A9nard?=
Date: Tue, 14 Apr 2026 14:45:12 +0200
Subject: [PATCH 5/7] fix autoscan
---
its/autoscan/src/test/resources/autoscan/diffs/diff_S2699.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/its/autoscan/src/test/resources/autoscan/diffs/diff_S2699.json b/its/autoscan/src/test/resources/autoscan/diffs/diff_S2699.json
index ce6b9db1c45..998602e4cec 100644
--- a/its/autoscan/src/test/resources/autoscan/diffs/diff_S2699.json
+++ b/its/autoscan/src/test/resources/autoscan/diffs/diff_S2699.json
@@ -1,6 +1,6 @@
{
"ruleKey": "S2699",
"hasTruePositives": true,
- "falseNegatives": 157,
+ "falseNegatives": 158,
"falsePositives": 1
}
From 58da571e2a8e83600cac73edca5fba33da12582c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?No=C3=A9mie=20B=C3=A9nard?=
Date: Tue, 14 Apr 2026 17:18:47 +0200
Subject: [PATCH 6/7] modify rule S2699 documentation
---
.../src/main/resources/org/sonar/l10n/java/rules/java/S2699.html | 1 +
1 file changed, 1 insertion(+)
diff --git a/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2699.html b/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2699.html
index 19832c2b2aa..b567b1b2a32 100644
--- a/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2699.html
+++ b/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2699.html
@@ -3,6 +3,7 @@ Why is this an issue?
code under test.
This rule raises an exception when no assertions from any of the following known frameworks are found in a test:
+ - ApproveJ
- AssertJ
- Awaitility
- EasyMock
From 87b18ebe95010c728bf95c40a8e78213a3f7f521 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?No=C3=A9mie=20B=C3=A9nard?=
Date: Wed, 15 Apr 2026 09:26:10 +0200
Subject: [PATCH 7/7] fix formatting
---
java-checks-test-sources/default/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/java-checks-test-sources/default/pom.xml b/java-checks-test-sources/default/pom.xml
index 5aca68eed1e..8da45f87738 100644
--- a/java-checks-test-sources/default/pom.xml
+++ b/java-checks-test-sources/default/pom.xml
@@ -1020,8 +1020,8 @@
org.approvej
core
1.6.0
- test
-
+ test
+