From cc18f7f2e1698fdbf7457112f7df885461faac7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20Pfl=C3=BCgner?= Date: Mon, 15 Dec 2025 13:08:02 +0100 Subject: [PATCH] #4: recognition of org.assertj.core.api.Assertions.fail as assertion --- .../resources/META-INF/jqassistant-rules/assertj.xml | 7 ++++++- .../plugin/java_testing/concept/AssertExample.java | 2 ++ .../plugin/java_testing/concept/AssertJIT.java | 12 +++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/resources/META-INF/jqassistant-rules/assertj.xml b/src/main/resources/META-INF/jqassistant-rules/assertj.xml index 68e2ddd..97a1e27 100644 --- a/src/main/resources/META-INF/jqassistant-rules/assertj.xml +++ b/src/main/resources/META-INF/jqassistant-rules/assertj.xml @@ -12,11 +12,16 @@ (assertType:Type)-[:DECLARES]->(assertMethod) WHERE assertType.fqn =~ 'org\\.assertj\\.core\\.api\\..*Assertions.*' - AND assertMethod.signature =~ '.* assert.*' + AND ( + assertMethod.signature =~ '.* assert.*' OR + assertMethod.signature =~ '.* fail.*' + ) SET assertMethod:AssertJ:Assert RETURN assertMethod + ORDER BY + assertMethod.signature ]]> diff --git a/src/test/java/org/jqassistant/plugin/java_testing/concept/AssertExample.java b/src/test/java/org/jqassistant/plugin/java_testing/concept/AssertExample.java index 49f31a1..c457af6 100644 --- a/src/test/java/org/jqassistant/plugin/java_testing/concept/AssertExample.java +++ b/src/test/java/org/jqassistant/plugin/java_testing/concept/AssertExample.java @@ -20,6 +20,8 @@ void assertjAssertExampleMethod() { Assertions.assertThat(true).isTrue(); } + void assertjFailExampleMethod() { Assertions.fail("fail"); } + void xmlAssertExampleMethod() { XmlAssert.assertThat("").and("").normalizeWhitespace().areSimilar(); } diff --git a/src/test/java/org/jqassistant/plugin/java_testing/concept/AssertJIT.java b/src/test/java/org/jqassistant/plugin/java_testing/concept/AssertJIT.java index 0761ac1..7695457 100644 --- a/src/test/java/org/jqassistant/plugin/java_testing/concept/AssertJIT.java +++ b/src/test/java/org/jqassistant/plugin/java_testing/concept/AssertJIT.java @@ -31,12 +31,18 @@ void assertjAssertMethod() throws Exception { store.beginTransaction(); - assertThat(conceptResult.getRows().size()).isEqualTo(1); + assertThat(conceptResult.getRows().size()).isEqualTo(2); assertThat(conceptResult.getRows() .get(0) .getColumns() .get("assertMethod") .getValue()).asInstanceOf(type(MethodDescriptor.class)) + .is(methodDescriptor(Assertions.class, "fail", String.class)); + assertThat(conceptResult.getRows() + .get(1) + .getColumns() + .get("assertMethod") + .getValue()).asInstanceOf(type(MethodDescriptor.class)) .is(methodDescriptor(Assertions.class, "assertThat", boolean.class)); verifyResultGraph(); @@ -74,8 +80,12 @@ private void verifyResultGraph() throws NoSuchMethodException { + "RETURN testMethod, assertMethod"); assertThat(methodQueryResult.getColumn("testMethod")) .haveExactly(1, methodDescriptor(AssertExample.class, "assertjAssertExampleMethod")); + assertThat(methodQueryResult.getColumn("testMethod")) + .haveExactly(1, methodDescriptor(AssertExample.class, "assertjFailExampleMethod")); assertThat(methodQueryResult.getColumn("assertMethod")) .haveExactly(1, methodDescriptor(Assertions.class, "assertThat", boolean.class)); + assertThat(methodQueryResult.getColumn("assertMethod")) + .haveExactly(1, methodDescriptor(Assertions.class, "fail", String.class)); } }